Search
lxdream.org :: lxdream :: r1240:190df8a791ca
lxdream 0.9.1
released Jun 29
Download Now
changeset1240:190df8a791ca
parent1239:be3121267597
child1241:74f8e11ab4b8
child1242:67909902ede9
authornkeynes
dateTue Feb 28 17:25:26 2012 +1000 (12 years ago)
Implement display output for the GLES2 case (no fixed function
rendering)
src/drivers/video_gl.c
src/pvr2/gl_sl.c
src/pvr2/glrender.c
src/pvr2/scene.c
src/pvr2/shaders.glsl
src/tools/genglsl.c
1.1 --- a/src/drivers/video_gl.c Sat Feb 25 21:30:49 2012 +1000
1.2 +++ b/src/drivers/video_gl.c Tue Feb 28 17:25:26 2012 +1000
1.3 @@ -21,6 +21,7 @@
1.4 #include "display.h"
1.5 #include "pvr2/pvr2.h"
1.6 #include "pvr2/glutil.h"
1.7 +#include "pvr2/shaders.h"
1.8 #include "drivers/video_gl.h"
1.9
1.10 /* FIXME: Need to actually handle this case */
1.11 @@ -32,7 +33,7 @@
1.12 struct video_vertex {
1.13 float x,y;
1.14 float u,v;
1.15 - float r,g,b;
1.16 + float r,g,b,a;
1.17 };
1.18
1.19 static struct video_box_t {
1.20 @@ -98,7 +99,7 @@
1.21 /**
1.22 * Setup the gl context for writes to the display output.
1.23 */
1.24 -void gl_framebuffer_setup()
1.25 +static void gl_framebuffer_setup()
1.26 {
1.27 glViewport( 0, 0, video_width, video_height );
1.28 glLoadMatrixf(video_box.viewMatrix);
1.29 @@ -112,10 +113,28 @@
1.30 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1.31 }
1.32
1.33 +static void gl_framebuffer_cleanup()
1.34 +{
1.35 + glDisableClientState( GL_VERTEX_ARRAY );
1.36 + glDisableClientState( GL_COLOR_ARRAY );
1.37 + glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1.38 +}
1.39 #else
1.40 -void gl_framebuffer_setup()
1.41 +static void gl_framebuffer_setup()
1.42 {
1.43 - /* TODO */
1.44 + glViewport( 0, 0, video_width, video_height );
1.45 + glBlendFunc( GL_ONE, GL_ZERO );
1.46 + glsl_use_basic_shader();
1.47 + glsl_set_basic_shader_view_matrix(video_box.viewMatrix);
1.48 + glsl_set_basic_shader_in_vertex_pointer(&video_box.gap1[0].x, sizeof(struct video_vertex));
1.49 + glsl_set_basic_shader_in_colour_pointer(&video_box.gap1[0].r, sizeof(struct video_vertex));
1.50 + glsl_set_basic_shader_in_texcoord_pointer(&video_box.gap1[0].u, sizeof(struct video_vertex));
1.51 + glsl_set_basic_shader_primary_texture(0);
1.52 +}
1.53 +
1.54 +static void gl_framebuffer_cleanup()
1.55 +{
1.56 + glsl_clear_shader();
1.57 }
1.58 #endif
1.59
1.60 @@ -154,6 +173,9 @@
1.61
1.62 void gl_texture_window( int width, int height, int tex_id, gboolean inverted )
1.63 {
1.64 + /* Set video box tex alpha to 1 */
1.65 + video_box.video_view[0].a = video_box.video_view[1].a = video_box.video_view[2].a = video_box.video_view[3].a = 1;
1.66 +
1.67 /* Reset display parameters */
1.68 gl_framebuffer_setup();
1.69 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1.70 @@ -165,6 +187,7 @@
1.71 glDrawArrays(GL_TRIANGLE_STRIP, inverted ? 12 : 8, 4);
1.72 glDisable(GL_TEXTURE_2D);
1.73 glFlush();
1.74 + gl_framebuffer_cleanup();
1.75 }
1.76
1.77 gboolean gl_load_frame_buffer( frame_buffer_t frame, int tex_id )
1.78 @@ -188,6 +211,7 @@
1.79 video_box.video_view[0].r = ((float)(((colour >> 16) & 0xFF) + 1)) / 256.0;
1.80 video_box.video_view[0].g = ((float)(((colour >> 8) & 0xFF) + 1)) / 256.0;
1.81 video_box.video_view[0].b = ((float)((colour & 0xFF) + 1)) / 256.0;
1.82 + video_box.video_view[0].a = 0;
1.83 memcpy( &video_box.video_view[1].r, &video_box.video_view[0].r, sizeof(float)*3 );
1.84 memcpy( &video_box.video_view[2].r, &video_box.video_view[0].r, sizeof(float)*3 );
1.85 memcpy( &video_box.video_view[3].r, &video_box.video_view[0].r, sizeof(float)*3 );
1.86 @@ -198,6 +222,7 @@
1.87 glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
1.88 glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
1.89 glFlush();
1.90 + gl_framebuffer_cleanup();
1.91 }
1.92
1.93 /**
2.1 --- a/src/pvr2/gl_sl.c Sat Feb 25 21:30:49 2012 +1000
2.2 +++ b/src/pvr2/gl_sl.c Tue Feb 28 17:25:26 2012 +1000
2.3 @@ -168,9 +168,11 @@
2.4 #define glsl_set_uniform_sampler1D(id,v) glUniform1iARB(id,v)
2.5 #define glsl_set_uniform_sampler2D(id,v) glUniform1iARB(id,v)
2.6 #define glsl_set_uniform_float(id,v) glUniform1fARB(id,v)
2.7 +#define glsl_set_uniform_vec2(id,v) glUniform2fvARB(id,1,v)
2.8 #define glsl_set_uniform_vec3(id,v) glUniform3fvARB(id,1,v)
2.9 #define glsl_set_uniform_vec4(id,v) glUniform4fvARB(id,1,v)
2.10 #define glsl_set_uniform_mat4(id,v) glUniformMatrix4fvARB(id,1,GL_FALSE,v)
2.11 +#define glsl_set_attrib_vec2(id,stride,v) glVertexAttribPointerARB(id, 2, GL_FLOAT, GL_FALSE, stride, v)
2.12 #define glsl_set_attrib_vec3(id,stride,v) glVertexAttribPointerARB(id, 3, GL_FLOAT, GL_FALSE, stride, v)
2.13 #define glsl_set_attrib_vec4(id,stride,v) glVertexAttribPointerARB(id, 4, GL_FLOAT, GL_FALSE, stride, v)
2.14 #define glsl_enable_attrib(id) glEnableVertexAttribArrayARB(id)
2.15 @@ -296,9 +298,11 @@
2.16 #define glsl_set_uniform_sampler1D(id,v) glUniform1i(id,v)
2.17 #define glsl_set_uniform_sampler2D(id,v) glUniform1i(id,v)
2.18 #define glsl_set_uniform_float(id,v) glUniform1f(id,v)
2.19 +#define glsl_set_uniform_vec2(id,v) glUniform2fv(id,1,v)
2.20 #define glsl_set_uniform_vec3(id,v) glUniform3fv(id,1,v)
2.21 #define glsl_set_uniform_vec4(id,v) glUniform4fv(id,1,v)
2.22 #define glsl_set_uniform_mat4(id,v) glUniformMatrix4fv(id,1,GL_FALSE,v)
2.23 +#define glsl_set_attrib_vec2(id,stride,v) glVertexAttribPointer(id, 2, GL_FLOAT, GL_FALSE, stride, v)
2.24 #define glsl_set_attrib_vec3(id,stride,v) glVertexAttribPointer(id, 3, GL_FLOAT, GL_FALSE, stride, v)
2.25 #define glsl_set_attrib_vec4(id,stride,v) glVertexAttribPointer(id, 4, GL_FLOAT, GL_FALSE, stride, v)
2.26 #define glsl_enable_attrib(id) glEnableVertexAttribArray(id)
2.27 @@ -356,9 +360,11 @@
2.28 #define glsl_set_uniform_sampler1D(id,v)
2.29 #define glsl_set_uniform_sampler2D(id,v)
2.30 #define glsl_set_uniform_float(id,v)
2.31 +#define glsl_set_uniform_vec2(id,v)
2.32 #define glsl_set_uniform_vec3(id,v)
2.33 #define glsl_set_uniform_vec4(id,v)
2.34 #define glsl_set_uniform_mat4(id,v)
2.35 +#define glsl_set_attrib_vec2(id,stride,v)
2.36 #define glsl_set_attrib_vec3(id,stride,v)
2.37 #define glsl_set_attrib_vec4(id,stride,v)
2.38 #define glsl_enable_attrib(id)
3.1 --- a/src/pvr2/glrender.c Sat Feb 25 21:30:49 2012 +1000
3.2 +++ b/src/pvr2/glrender.c Tue Feb 28 17:25:26 2012 +1000
3.3 @@ -137,7 +137,7 @@
3.4 }
3.5 #endif
3.6
3.7 -#ifdef HAVE_OPENGL_FIXEDFUNC
3.8 +#ifndef HAVE_OPENGL_FIXEDFUNC
3.9 /* Setup defaults for perspective correction + matrices */
3.10 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
3.11 glMatrixMode(GL_MODELVIEW);
4.1 --- a/src/pvr2/scene.c Sat Feb 25 21:30:49 2012 +1000
4.2 +++ b/src/pvr2/scene.c Tue Feb 28 17:25:26 2012 +1000
4.3 @@ -552,6 +552,11 @@
4.4 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
4.5 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
4.6 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
4.7 + if( !POLY1_GOURAUD_SHADED(context[0]) ) {
4.8 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index].rgba, &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3].rgba, sizeof(float)*8 );
4.9 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+1].rgba, &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3].rgba, sizeof(float)*8 );
4.10 + }
4.11 +
4.12 pvr2_scene.vertex_index += 4;
4.13
4.14 if( is_modified ) {
4.15 @@ -568,6 +573,10 @@
4.16 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
4.17 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
4.18 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
4.19 + if( !POLY1_GOURAUD_SHADED(context[0]) ) {
4.20 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index].rgba, &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3].rgba, sizeof(float)*8 );
4.21 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+1].rgba, &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3].rgba, sizeof(float)*8 );
4.22 + }
4.23 } else {
4.24 scene_add_cheap_shadow_vertexes( &pvr2_scene.vertex_array[poly->vertex_index],
4.25 &pvr2_scene.vertex_array[poly->mod_vertex_index], poly->vertex_count );
5.1 --- a/src/pvr2/shaders.glsl Sat Feb 25 21:30:49 2012 +1000
5.2 +++ b/src/pvr2/shaders.glsl Tue Feb 28 17:25:26 2012 +1000
5.3 @@ -63,7 +63,7 @@
5.4 * float gl_FragDepth;
5.5
5.6 */
5.7 -
5.8 +#include "../config.h"
5.9
5.10 #vertex DEFAULT_VERTEX_SHADER
5.11 uniform mat4 view_matrix;
5.12 @@ -130,3 +130,36 @@
5.13 }
5.14
5.15 #program pvr2_shader = DEFAULT_VERTEX_SHADER DEFAULT_FRAGMENT_SHADER
5.16 +
5.17 +#ifndef HAVE_OPENGL_FIXEDFUNC
5.18 +/* In this case we also need a basic shader to actually display the output */
5.19 +#vertex BASIC_VERTEX_SHADER
5.20 +uniform mat4 view_matrix;
5.21 +attribute vec2 in_vertex;
5.22 +attribute vec4 in_colour;
5.23 +attribute vec2 in_texcoord; /* uv = coord, z = palette, w = mode */
5.24 +
5.25 +varying vec4 frag_colour;
5.26 +varying vec2 frag_texcoord;
5.27 +void main()
5.28 +{
5.29 + gl_Position = view_matrix * vec4(in_vertex.x,in_vertex.y,0,1);
5.30 + frag_colour = in_colour;
5.31 + frag_texcoord = in_texcoord;
5.32 +}
5.33 +
5.34 +#fragment BASIC_FRAGMENT_SHADER
5.35 +
5.36 +uniform sampler2D primary_texture;
5.37 +varying vec4 frag_colour;
5.38 +varying vec2 frag_texcoord;
5.39 +
5.40 +void main()
5.41 +{
5.42 + vec4 tex = texture2D( primary_texture, frag_texcoord.xy );
5.43 + gl_FragColor.rgb = mix( frag_colour.rgb, tex.rgb, frag_colour.a );
5.44 + gl_FragDepth = gl_FragCoord.z;
5.45 +}
5.46 +
5.47 +#program basic_shader = BASIC_VERTEX_SHADER BASIC_FRAGMENT_SHADER
5.48 +#endif
6.1 --- a/src/tools/genglsl.c Sat Feb 25 21:30:49 2012 +1000
6.2 +++ b/src/tools/genglsl.c Tue Feb 28 17:25:26 2012 +1000
6.3 @@ -382,6 +382,7 @@
6.4 } else {
6.5 fprintf( f, "void glsl_set_%s_%s_pointer(%s ptr, GLint stride); /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
6.6 if( strcmp(var->type,"vec4") == 0 ) { /* Special case */
6.7 + fprintf( f, "void glsl_set_%s_%s_vec2_pointer(%s ptr, GLint stride); /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
6.8 fprintf( f, "void glsl_set_%s_%s_vec3_pointer(%s ptr, GLint stride); /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
6.9 }
6.10 }
6.11 @@ -472,6 +473,8 @@
6.12 if( strcmp(var->type,"vec4") == 0 ) { /* Special case to load vec3 arrays into a vec4 */
6.13 fprintf( f, "void glsl_set_%s_%s_vec3_pointer(%s ptr, GLsizei stride){ /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
6.14 fprintf( f, " glsl_set_attrib_vec3(var_%s_%s_loc,stride, ptr);\n}\n", program->name, var->name );
6.15 + fprintf( f, "void glsl_set_%s_%s_vec2_pointer(%s ptr, GLsizei stride){ /* attribute %s %s */ \n", program->name, var->name, getCType(var->type,var->uniform), var->type, var->name);
6.16 + fprintf( f, " glsl_set_attrib_vec2(var_%s_%s_loc,stride, ptr);\n}\n", program->name, var->name );
6.17 }
6.18 }
6.19 }
.