Search
lxdream.org :: lxdream/src/drivers/gl_common.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/gl_common.c
changeset 477:9a373f2ff009
prev444:74c38d57eb11
next481:3b2d6c5a19ad
author nkeynes
date Wed Oct 31 09:10:23 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add save/restore of render buffers in save states
Gzip memory blocks in save states
Move front-buffer management back to pvr2
Add screenshot preview when loading save states
Various minor fixes and cleanups
file annotate diff log raw
1.1 --- a/src/drivers/gl_common.c Sun Oct 14 09:30:16 2007 +0000
1.2 +++ b/src/drivers/gl_common.c Wed Oct 31 09:10:23 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gl_common.c,v 1.5 2007-10-14 09:30:16 nkeynes Exp $
1.6 + * $Id: gl_common.c,v 1.6 2007-10-31 09:10:23 nkeynes Exp $
1.7 *
1.8 * Common GL code that doesn't depend on a specific implementation
1.9 *
1.10 @@ -23,13 +23,7 @@
1.11 #include "drivers/gl_common.h"
1.12
1.13 extern uint32_t video_width, video_height;
1.14 -static GLuint frame_last_texid = 0, fbuf_id = 0;
1.15 -static uint32_t frame_width = 0;
1.16 -static uint32_t frame_height = 0;
1.17 static uint32_t frame_colour = 0;
1.18 -static gboolean frame_inverted = FALSE;
1.19 -
1.20 -
1.21
1.22 char *required_extensions[] = { "GL_EXT_framebuffer_object", NULL };
1.23
1.24 @@ -80,28 +74,15 @@
1.25 return isOK;
1.26 }
1.27
1.28 -void gl_frame_buffer_to_tex_rectangle( frame_buffer_t frame, GLuint texid )
1.29 -{
1.30 - GLenum type = colour_formats[frame->colour_format].type;
1.31 - GLenum format = colour_formats[frame->colour_format].format;
1.32 - int bpp = colour_formats[frame->colour_format].bpp;
1.33 - int rowstride = (frame->rowstride / bpp) - frame->width;
1.34 -
1.35 - glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
1.36 - glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texid );
1.37 - glTexImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
1.38 - frame->width, frame->height, 0, format, type, frame->data );
1.39 -}
1.40 -
1.41 -void gl_display_tex_rectangle( GLuint texid, uint32_t tex_width, uint32_t tex_height, gboolean invert )
1.42 +void gl_display_render_buffer( render_buffer_t buffer )
1.43 {
1.44 float top, bottom;
1.45 - if( invert ) {
1.46 - top = ((float)tex_height) - 0.5;
1.47 + if( buffer->inverted ) {
1.48 + top = ((float)buffer->height) - 0.5;
1.49 bottom = 0.5;
1.50 } else {
1.51 top = 0.5;
1.52 - bottom = ((float)tex_height) - 0.5;
1.53 + bottom = ((float)buffer->height) - 0.5;
1.54 }
1.55
1.56 /* Reset display parameters */
1.57 @@ -155,7 +136,7 @@
1.58
1.59 /* Render the textured rectangle */
1.60 glEnable( GL_TEXTURE_RECTANGLE_ARB );
1.61 - glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texid );
1.62 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, buffer->buf_id );
1.63 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1.64 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1.65 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1.66 @@ -164,29 +145,28 @@
1.67 glBegin( GL_QUADS );
1.68 glTexCoord2f( 0.5, top );
1.69 glVertex2f( x1, y1 );
1.70 - glTexCoord2f( ((float)tex_width)-0.5, top );
1.71 + glTexCoord2f( ((float)buffer->width)-0.5, top );
1.72 glVertex2f( x2, y1 );
1.73 - glTexCoord2f( ((float)tex_width)-0.5, bottom );
1.74 + glTexCoord2f( ((float)buffer->width)-0.5, bottom );
1.75 glVertex2f( x2, y2 );
1.76 glTexCoord2f( 0.5, bottom );
1.77 glVertex2f( x1, y2 );
1.78 glEnd();
1.79 glDisable( GL_TEXTURE_RECTANGLE_ARB );
1.80 glFlush();
1.81 - frame_last_texid = texid;
1.82 - frame_width = tex_width;
1.83 - frame_height = tex_height;
1.84 - frame_inverted = invert;
1.85 }
1.86
1.87 -gboolean gl_display_frame_buffer( frame_buffer_t frame )
1.88 +gboolean gl_load_frame_buffer( frame_buffer_t frame, render_buffer_t render )
1.89 {
1.90 - if( fbuf_id == 0 ) {
1.91 - glGenTextures( 1, &fbuf_id );
1.92 - }
1.93 - gl_frame_buffer_to_tex_rectangle( frame, fbuf_id );
1.94 - gl_display_tex_rectangle( fbuf_id, frame->width, frame->height, FALSE );
1.95 - return TRUE;
1.96 + GLenum type = colour_formats[frame->colour_format].type;
1.97 + GLenum format = colour_formats[frame->colour_format].format;
1.98 + int bpp = colour_formats[frame->colour_format].bpp;
1.99 + int rowstride = (frame->rowstride / bpp) - frame->width;
1.100 +
1.101 + glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
1.102 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, render->buf_id );
1.103 + glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0,0,
1.104 + frame->width, frame->height, format, type, frame->data );
1.105 }
1.106
1.107 gboolean gl_display_blank( uint32_t colour )
1.108 @@ -201,16 +181,16 @@
1.109 glRecti(0,0, video_width, video_height );
1.110 glFlush();
1.111 frame_colour = colour;
1.112 - frame_last_texid = 0;
1.113 return TRUE;
1.114 }
1.115
1.116 void gl_redisplay_last()
1.117 {
1.118 - if( frame_last_texid == 0 ) {
1.119 + render_buffer_t buffer = pvr2_get_front_buffer();
1.120 + if( buffer == NULL ) {
1.121 gl_display_blank( frame_colour );
1.122 } else {
1.123 - gl_display_tex_rectangle( frame_last_texid, frame_width, frame_height, frame_inverted );
1.124 + gl_display_render_buffer( buffer );
1.125 }
1.126 }
1.127
1.128 @@ -219,17 +199,16 @@
1.129 * has already set the appropriate glReadBuffer(); in other words, unless
1.130 * there's only one buffer this needs to be wrapped.
1.131 */
1.132 -gboolean gl_read_render_buffer( render_buffer_t buffer, unsigned char *target )
1.133 +gboolean gl_read_render_buffer( unsigned char *target, render_buffer_t buffer,
1.134 + int rowstride, int colour_format )
1.135 {
1.136 - if( buffer->address == -1 )
1.137 - return FALSE;
1.138 glFinish();
1.139 - GLenum type = colour_formats[buffer->colour_format].type;
1.140 - GLenum format = colour_formats[buffer->colour_format].format;
1.141 - // int line_size = buffer->width * colour_formats[buffer->colour_format].bpp;
1.142 + GLenum type = colour_formats[colour_format].type;
1.143 + GLenum format = colour_formats[colour_format].format;
1.144 + // int line_size = buffer->width * colour_formats[colour_format].bpp;
1.145 // int size = line_size * buffer->height;
1.146 - // int rowstride = (buffer->rowstride / colour_formats[buffer->colour_format].bpp) - buffer->width;
1.147 - // glPixelStorei( GL_PACK_ROW_LENGTH, rowstride );
1.148 + int glrowstride = (rowstride / colour_formats[colour_format].bpp) - buffer->width;
1.149 + glPixelStorei( GL_PACK_ROW_LENGTH, glrowstride );
1.150
1.151 glReadPixels( 0, 0, buffer->width, buffer->height, format, type, target );
1.152 return TRUE;
.