Search
lxdream.org :: lxdream/src/drivers/video_gl.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gl.c
changeset 1236:d93175c36387
prev1222:a4545699a82b
next1239:be3121267597
author nkeynes
date Fri Feb 24 21:17:47 2012 +1000 (7 years ago)
permissions -rw-r--r--
last change Factor video_width/video_height out into video_gl.c
Convert immediate-mode bits in video_gl.c into a structure for glDrawArray
Move setOrtho into defineOrthoMatrix in glutil.c
Rearrange various GL settings to keep a consistent state
file annotate diff log raw
1.1 --- a/src/drivers/video_gl.c Wed Feb 15 17:54:51 2012 +1000
1.2 +++ b/src/drivers/video_gl.c Fri Feb 24 21:17:47 2012 +1000
1.3 @@ -20,28 +20,90 @@
1.4
1.5 #include "display.h"
1.6 #include "pvr2/pvr2.h"
1.7 +#include "pvr2/glutil.h"
1.8 #include "drivers/video_gl.h"
1.9
1.10 -extern uint32_t video_width, video_height;
1.11 +uint32_t video_width, video_height;
1.12 +struct video_vertex {
1.13 + float x,y;
1.14 + float u,v;
1.15 + float r,g,b;
1.16 +};
1.17 +
1.18 +static struct video_box_t {
1.19 + float viewMatrix[16];
1.20 + struct video_vertex gap1[4];
1.21 + struct video_vertex gap2[4];
1.22 + struct video_vertex video_view[4];
1.23 + struct video_vertex invert_view[4];
1.24 +} video_box;
1.25 +
1.26 +void gl_set_video_size( uint32_t width, uint32_t height )
1.27 +{
1.28 + video_width = width;
1.29 + video_height = height;
1.30 +
1.31 + int x1=0,y1=0,x2=video_width,y2=video_height;
1.32 +
1.33 + int ah = video_width * 0.75;
1.34 +
1.35 + if( ah > video_height ) {
1.36 + int w = (video_height/0.75);
1.37 + x1 = (video_width - w)/2;
1.38 + x2 -= x1;
1.39 + video_box.gap1[0].x = 0; video_box.gap1[0].y = 0;
1.40 + video_box.gap1[1].x = x1; video_box.gap1[1].y = 0;
1.41 + video_box.gap1[2].x = 0; video_box.gap1[2].y = video_height;
1.42 + video_box.gap1[3].x = x2; video_box.gap1[3].y = video_height;
1.43 + video_box.gap2[0].x = x2; video_box.gap2[0].y = 0;
1.44 + video_box.gap2[1].x = video_width; video_box.gap2[1].y = 0;
1.45 + video_box.gap2[2].x = x2; video_box.gap2[2].y = video_height;
1.46 + video_box.gap2[3].x = video_width; video_box.gap2[3].y = video_height;
1.47 + } else if( ah < video_height ) {
1.48 + y1 = (video_height - ah)/2;
1.49 + y2 -= y1;
1.50 +
1.51 + video_box.gap1[0].x = 0; video_box.gap1[0].y = 0;
1.52 + video_box.gap1[1].x = video_width; video_box.gap1[1].y = 0;
1.53 + video_box.gap1[2].x = 0; video_box.gap1[2].y = y1;
1.54 + video_box.gap1[3].x = video_width; video_box.gap1[3].y = y1;
1.55 + video_box.gap2[0].x = 0; video_box.gap2[0].y = y2;
1.56 + video_box.gap2[1].x = video_width; video_box.gap2[1].y = y2;
1.57 + video_box.gap2[2].x = 0; video_box.gap2[2].y = video_height;
1.58 + video_box.gap2[3].x = video_width; video_box.gap2[3].y = video_height;
1.59 + }
1.60 +
1.61 + video_box.video_view[0].x = x1; video_box.video_view[0].y = y1;
1.62 + video_box.video_view[0].u = 0; video_box.video_view[0].v = 0;
1.63 + video_box.video_view[1].x = x2; video_box.video_view[1].y = y1;
1.64 + video_box.video_view[1].u = 1; video_box.video_view[1].v = 0;
1.65 + video_box.video_view[2].x = x1; video_box.video_view[2].y = y2;
1.66 + video_box.video_view[2].u = 0; video_box.video_view[2].v = 1;
1.67 + video_box.video_view[3].x = x2; video_box.video_view[3].y = y2;
1.68 + video_box.video_view[3].u = 1; video_box.video_view[3].v = 1;
1.69 +
1.70 + memcpy( &video_box.invert_view, &video_box.video_view, sizeof(video_box.video_view) );
1.71 + video_box.invert_view[0].v = 1; video_box.invert_view[1].v = 1;
1.72 + video_box.invert_view[2].v = 0; video_box.invert_view[3].v = 0;
1.73 +
1.74 + defineOrthoMatrix(video_box.viewMatrix, video_width, video_height, 0, 65535);
1.75 +}
1.76
1.77 /**
1.78 - * Reset the gl state to simple orthographic projection with
1.79 - * texturing, alpha/depth/scissor/cull tests disabled.
1.80 + * Setup the gl context for writes to the display output.
1.81 */
1.82 -void gl_reset_state()
1.83 +void gl_framebuffer_setup()
1.84 {
1.85 + glLoadMatrixf(video_box.viewMatrix);
1.86 + glBlendFunc( GL_ONE, GL_ZERO );
1.87 + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1.88 glViewport( 0, 0, video_width, video_height );
1.89 - glMatrixMode(GL_PROJECTION);
1.90 - glLoadIdentity();
1.91 - glOrtho( 0, video_width, video_height, 0, 0, 65535 );
1.92 - glMatrixMode(GL_MODELVIEW);
1.93 - glLoadIdentity();
1.94 - glEnable( GL_BLEND );
1.95 - glDisable( GL_TEXTURE_2D );
1.96 - glDisable( GL_ALPHA_TEST );
1.97 - glDisable( GL_DEPTH_TEST );
1.98 - glDisable( GL_SCISSOR_TEST );
1.99 - glDisable( GL_CULL_FACE );
1.100 + glVertexPointer(2, GL_FLOAT, sizeof(struct video_vertex), &video_box.gap1[0].x);
1.101 + glColorPointer(3, GL_FLOAT, sizeof(struct video_vertex), &video_box.gap1[0].r);
1.102 + glTexCoordPointer(2, GL_FLOAT, sizeof(struct video_vertex), &video_box.gap1[0].u);
1.103 + glEnableClientState( GL_VERTEX_ARRAY );
1.104 + glEnableClientState( GL_COLOR_ARRAY );
1.105 + glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1.106 }
1.107
1.108 void gl_display_render_buffer( render_buffer_t buffer )
1.109 @@ -79,72 +141,16 @@
1.110
1.111 void gl_texture_window( int width, int height, int tex_id, gboolean inverted )
1.112 {
1.113 - float top, bottom;
1.114 - if( inverted ) {
1.115 - top = 1;
1.116 - bottom = 0;
1.117 - } else {
1.118 - top = 0;
1.119 - bottom = 1;
1.120 - }
1.121 -
1.122 /* Reset display parameters */
1.123 - gl_reset_state();
1.124 - glColor3f( 0,0,0 );
1.125 -
1.126 - int x1=0,y1=0,x2=video_width,y2=video_height;
1.127 -
1.128 - int ah = video_width * 0.75;
1.129 -
1.130 - if( ah > video_height ) {
1.131 - int w = (video_height/0.75);
1.132 - x1 = (video_width - w)/2;
1.133 - x2 -= x1;
1.134 -
1.135 - glBegin( GL_QUADS );
1.136 - glVertex2f( 0, 0 );
1.137 - glVertex2f( x1, 0 );
1.138 - glVertex2f( x1, video_height );
1.139 - glVertex2f( 0, video_height);
1.140 - glVertex2f( x2, 0 );
1.141 - glVertex2f( video_width, 0 );
1.142 - glVertex2f( video_width, video_height );
1.143 - glVertex2f( x2, video_height);
1.144 - glEnd();
1.145 - } else if( ah < video_height ) {
1.146 - y1 = (video_height - ah)/2;
1.147 - y2 -= y1;
1.148 - glBegin( GL_QUADS );
1.149 - glVertex2f( 0, 0 );
1.150 - glVertex2f( video_width, 0 );
1.151 - glVertex2f( video_width, y1 );
1.152 - glVertex2f( 0, y1 );
1.153 - glVertex2f( 0, y2 );
1.154 - glVertex2f( video_width, y2 );
1.155 - glVertex2f( video_width, video_height );
1.156 - glVertex2f( 0, video_height );
1.157 - glEnd();
1.158 - }
1.159 -
1.160 - /* Render the textured rectangle */
1.161 - glEnable( GL_TEXTURE_2D );
1.162 - glBindTexture( GL_TEXTURE_2D, tex_id );
1.163 - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1.164 + gl_framebuffer_setup();
1.165 + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1.166 + glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
1.167 + glEnable(GL_TEXTURE_2D);
1.168 + glBindTexture(GL_TEXTURE_2D,tex_id);
1.169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1.170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1.171 - glEnable( GL_BLEND );
1.172 - glBlendFunc( GL_ONE, GL_ZERO );
1.173 - glBegin( GL_QUADS );
1.174 - glTexCoord2f( 0, top );
1.175 - glVertex2f( x1, y1 );
1.176 - glTexCoord2f( 1, top );
1.177 - glVertex2f( x2, y1 );
1.178 - glTexCoord2f( 1, bottom );
1.179 - glVertex2f( x2, y2 );
1.180 - glTexCoord2f( 0, bottom );
1.181 - glVertex2f( x1, y2 );
1.182 - glEnd();
1.183 - glDisable( GL_TEXTURE_2D );
1.184 + glDrawArrays(GL_TRIANGLE_STRIP, inverted ? 12 : 8, 4);
1.185 + glDisable(GL_TEXTURE_2D);
1.186 glFlush();
1.187 }
1.188
1.189 @@ -159,14 +165,25 @@
1.190 glBindTexture( GL_TEXTURE_2D, tex_id );
1.191 glTexSubImage2D( GL_TEXTURE_2D, 0, 0,0,
1.192 frame->width, frame->height, format, type, frame->data );
1.193 + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
1.194 return TRUE;
1.195 }
1.196
1.197 void gl_display_blank( uint32_t colour )
1.198 {
1.199 - gl_reset_state();
1.200 - glColor3ub( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
1.201 - glRecti(0,0, video_width, video_height );
1.202 + /* Set the video_box background colour */
1.203 + video_box.video_view[0].r = ((float)(((colour >> 16) & 0xFF) + 1)) / 256.0;
1.204 + video_box.video_view[0].g = ((float)(((colour >> 8) & 0xFF) + 1)) / 256.0;
1.205 + video_box.video_view[0].b = ((float)((colour & 0xFF) + 1)) / 256.0;
1.206 + memcpy( &video_box.video_view[1].r, &video_box.video_view[0].r, sizeof(float)*3 );
1.207 + memcpy( &video_box.video_view[2].r, &video_box.video_view[0].r, sizeof(float)*3 );
1.208 + memcpy( &video_box.video_view[3].r, &video_box.video_view[0].r, sizeof(float)*3 );
1.209 +
1.210 + /* And render */
1.211 + gl_framebuffer_setup();
1.212 + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1.213 + glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
1.214 + glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
1.215 glFlush();
1.216 }
1.217
1.218 @@ -185,7 +202,7 @@
1.219 // int size = line_size * buffer->height;
1.220 int glrowstride = (rowstride / colour_formats[colour_format].bpp) - buffer->width;
1.221 glPixelStorei( GL_PACK_ROW_LENGTH, glrowstride );
1.222 -
1.223 glReadPixels( 0, 0, buffer->width, buffer->height, format, type, target );
1.224 + glPixelStorei( GL_PACK_ROW_LENGTH, 0 );
1.225 return TRUE;
1.226 }
.