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 443:1163eb5c0590
prev429:e581b90c3fb3
next444:74c38d57eb11
author nkeynes
date Sat Oct 13 04:01:02 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add ability to track the last displayed buffer, and handle expose/resize
events appropriately
file annotate diff log raw
1.1 --- a/src/drivers/gl_common.c Mon Oct 08 11:52:13 2007 +0000
1.2 +++ b/src/drivers/gl_common.c Sat Oct 13 04:01:02 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gl_common.c,v 1.3 2007-10-08 11:49:35 nkeynes Exp $
1.6 + * $Id: gl_common.c,v 1.4 2007-10-13 04:01:02 nkeynes Exp $
1.7 *
1.8 * Common GL code that doesn't depend on a specific implementation
1.9 *
1.10 @@ -16,11 +16,20 @@
1.11 * GNU General Public License for more details.
1.12 */
1.13
1.14 +#include <sys/time.h>
1.15 +
1.16 #include <GL/gl.h>
1.17 #include "dream.h"
1.18 #include "drivers/gl_common.h"
1.19
1.20 extern uint32_t video_width, video_height;
1.21 +static GLuint frame_last_texid = 0, fbuf_id = 0;
1.22 +static uint32_t frame_width = 0;
1.23 +static uint32_t frame_height = 0;
1.24 +static uint32_t frame_colour = 0;
1.25 +static gboolean frame_inverted = FALSE;
1.26 +
1.27 +
1.28
1.29 char *required_extensions[] = { "GL_EXT_framebuffer_object", NULL };
1.30
1.31 @@ -71,55 +80,76 @@
1.32 return isOK;
1.33 }
1.34
1.35 -
1.36 -gboolean gl_display_frame_buffer( frame_buffer_t frame )
1.37 +void gl_frame_buffer_to_tex_rectangle( frame_buffer_t frame, GLuint texid )
1.38 {
1.39 GLenum type = colour_formats[frame->colour_format].type;
1.40 GLenum format = colour_formats[frame->colour_format].format;
1.41 int bpp = colour_formats[frame->colour_format].bpp;
1.42 + int rowstride = (frame->rowstride / bpp) - frame->width;
1.43 +
1.44 + glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
1.45 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texid );
1.46 + glTexImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
1.47 + frame->width, frame->height, 0, format, type, frame->data );
1.48 +}
1.49
1.50 +void gl_display_tex_rectangle( GLuint texid, uint32_t tex_width, uint32_t tex_height, gboolean invert )
1.51 +{
1.52 + float top, bottom;
1.53 + if( invert ) {
1.54 + top = ((float)tex_height) - 0.5;
1.55 + bottom = 0.5;
1.56 + } else {
1.57 + top = 0.5;
1.58 + bottom = ((float)tex_height) - 0.5;
1.59 + }
1.60 +
1.61 + /* Reset display parameters */
1.62 glViewport( 0, 0, video_width, video_height );
1.63 glMatrixMode(GL_PROJECTION);
1.64 glLoadIdentity();
1.65 glOrtho( 0, video_width, video_height, 0, 0, -65535 );
1.66 glMatrixMode(GL_MODELVIEW);
1.67 glLoadIdentity();
1.68 -
1.69 - /* Disable everything */
1.70 glDisable( GL_TEXTURE_2D );
1.71 glDisable( GL_ALPHA_TEST );
1.72 glDisable( GL_DEPTH_TEST );
1.73 glDisable( GL_SCISSOR_TEST );
1.74 glDisable( GL_CULL_FACE );
1.75
1.76 - float scale = ((float)video_height) / frame->height;
1.77 - int rowstride = (frame->rowstride / bpp) - frame->width;
1.78 -
1.79 -
1.80 - /*
1.81 - glGenTextures( 1, &texid );
1.82 - glBindTexture( GL_TEXTURE_2D, texid );
1.83 - glTexImage2D( GL_TEXTURE_2D, 0, colour_formats[frame->colour_format].int_format,
1.84 - frame->width, frame->height, 0, format, type, frame->data );
1.85 + /* Render the textured rectangle */
1.86 + glEnable( GL_TEXTURE_RECTANGLE_ARB );
1.87 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texid );
1.88 + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1.89 + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1.90 + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1.91 + glEnable( GL_BLEND );
1.92 + glBlendFunc( GL_ONE, GL_ZERO );
1.93 glBegin( GL_QUADS );
1.94 - glTexCoord2i( 0, 1.0 );
1.95 + glTexCoord2f( 0.5, top );
1.96 glVertex2f( 0.0, 0.0 );
1.97 - glTexCoord2i( 1.0, 1.0 );
1.98 - glVertex2f( frame->width, 0.0 );
1.99 - glTexCoord2i( 1.0, 0.0 );
1.100 - glVertex2f( frame->width, frame->height );
1.101 - glTexCoord2i( 0, 0.0 );
1.102 - glVertex2f( 0.0, frame->height );
1.103 + glTexCoord2f( ((float)tex_width)-0.5, top );
1.104 + glVertex2f( video_width, 0.0 );
1.105 + glTexCoord2f( ((float)tex_width)-0.5, bottom );
1.106 + glVertex2f( video_width, video_height );
1.107 + glTexCoord2f( 0.5, bottom );
1.108 + glVertex2f( 0.0, video_height );
1.109 glEnd();
1.110 - glDeleteTextures( 1, &texid );
1.111 - */
1.112 - glRasterPos2i( 0, 0 );
1.113 - glPixelZoom( 1.0f, -scale );
1.114 - glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
1.115 - glDrawPixels( frame->width, frame->height, format, type,
1.116 - frame->data );
1.117 -
1.118 + glDisable( GL_TEXTURE_RECTANGLE_ARB );
1.119 glFlush();
1.120 + frame_last_texid = texid;
1.121 + frame_width = tex_width;
1.122 + frame_height = tex_height;
1.123 + frame_inverted = invert;
1.124 +}
1.125 +
1.126 +gboolean gl_display_frame_buffer( frame_buffer_t frame )
1.127 +{
1.128 + if( fbuf_id == 0 ) {
1.129 + glGenTextures( 1, &fbuf_id );
1.130 + }
1.131 + gl_frame_buffer_to_tex_rectangle( frame, fbuf_id );
1.132 + gl_display_tex_rectangle( fbuf_id, frame->width, frame->height, FALSE );
1.133 return TRUE;
1.134 }
1.135
1.136 @@ -134,9 +164,20 @@
1.137 glColor3b( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
1.138 glRecti(0,0, video_width, video_height );
1.139 glFlush();
1.140 + frame_colour = colour;
1.141 + frame_last_texid = 0;
1.142 return TRUE;
1.143 }
1.144
1.145 +void gl_redisplay_last()
1.146 +{
1.147 + if( frame_last_texid == 0 ) {
1.148 + gl_display_blank( frame_colour );
1.149 + } else {
1.150 + gl_display_tex_rectangle( frame_last_texid, frame_width, frame_height, frame_inverted );
1.151 + }
1.152 +}
1.153 +
1.154 /**
1.155 * Generic GL read_render_buffer. This function assumes that the caller
1.156 * has already set the appropriate glReadBuffer(); in other words, unless
.