Search
lxdream.org :: lxdream/src/drivers/gl_fbo.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/gl_fbo.c
changeset 477:9a373f2ff009
prev445:75c668cdfdc0
next540:a3767018a96d
author nkeynes
date Wed Oct 31 09:10:23 2007 +0000 (13 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_fbo.c Tue Oct 16 12:27:28 2007 +0000
1.2 +++ b/src/drivers/gl_fbo.c Wed Oct 31 09:10:23 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gl_fbo.c,v 1.6 2007-10-16 12:27:28 nkeynes Exp $
1.6 + * $Id: gl_fbo.c,v 1.7 2007-10-31 09:10:23 nkeynes Exp $
1.7 *
1.8 * GL framebuffer-based driver shell. This requires the EXT_framebuffer_object
1.9 * extension, but is much nicer/faster/etc than pbuffers when it's available.
1.10 @@ -26,6 +26,8 @@
1.11
1.12 #include <GL/gl.h>
1.13 #include <GL/glext.h>
1.14 +#include <stdlib.h>
1.15 +#include "lxdream.h"
1.16 #include "display.h"
1.17 #include "drivers/video_x11.h"
1.18 #include "drivers/gl_common.h"
1.19 @@ -37,9 +39,9 @@
1.20 static void gl_fbo_destroy_render_buffer( render_buffer_t buffer );
1.21 static gboolean gl_fbo_set_render_target( render_buffer_t buffer );
1.22 static gboolean gl_fbo_display_render_buffer( render_buffer_t buffer );
1.23 -static gboolean gl_fbo_display_frame_buffer( frame_buffer_t buffer );
1.24 +static void gl_fbo_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer );
1.25 static gboolean gl_fbo_display_blank( uint32_t colour );
1.26 -static gboolean gl_fbo_read_render_buffer( render_buffer_t buffer, unsigned char *target );
1.27 +static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer, int rowstride, int format );
1.28
1.29 extern uint32_t video_width, video_height;
1.30
1.31 @@ -93,7 +95,7 @@
1.32 driver->destroy_render_buffer = gl_fbo_destroy_render_buffer;
1.33 driver->set_render_target = gl_fbo_set_render_target;
1.34 driver->display_render_buffer = gl_fbo_display_render_buffer;
1.35 - driver->display_frame_buffer = gl_fbo_display_frame_buffer;
1.36 + driver->load_frame_buffer = gl_fbo_load_frame_buffer;
1.37 driver->display_blank = gl_fbo_display_blank;
1.38 driver->read_render_buffer = gl_fbo_read_render_buffer;
1.39
1.40 @@ -218,6 +220,7 @@
1.41 for( i=0; i<MAX_FRAMEBUFFERS; i++ ) {
1.42 for( j=0; j < MAX_TEXTURES_PER_FB; j++ ) {
1.43 if( fbo[i].tex_ids[j] == buffer->buf_id ) {
1.44 + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[i].fb_id);
1.45 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, ATTACHMENT_POINTS[j],
1.46 GL_TEXTURE_RECTANGLE_ARB, GL_NONE, 0 );
1.47 fbo[i].tex_ids[j] = -1;
1.48 @@ -232,6 +235,7 @@
1.49
1.50 static gboolean gl_fbo_set_render_target( render_buffer_t buffer )
1.51 {
1.52 + glFinish();
1.53 glGetError();
1.54 int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
1.55 gl_fbo_attach_texture( fb, buffer->buf_id );
1.56 @@ -248,66 +252,37 @@
1.57 static gboolean gl_fbo_display_render_buffer( render_buffer_t buffer )
1.58 {
1.59 glFinish();
1.60 - glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); // real window
1.61 - glDrawBuffer( GL_FRONT );
1.62 - glReadBuffer( GL_FRONT );
1.63 - gl_display_tex_rectangle( buffer->buf_id, buffer->width, buffer->height, TRUE );
1.64 - /*
1.65 - glViewport( 0, 0, video_width, video_height );
1.66 - glEnable( GL_TEXTURE_RECTANGLE_ARB );
1.67 - glBindTexture( GL_TEXTURE_RECTANGLE_ARB, buffer->buf_id );
1.68 - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1.69 - glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1.70 - glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
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 - glMatrixMode(GL_PROJECTION);
1.77 - glLoadIdentity();
1.78 - glOrtho( 0, buffer->width, buffer->height, 0, 0, -65535 );
1.79 - glMatrixMode(GL_MODELVIEW);
1.80 - glLoadIdentity();
1.81 - glEnable( GL_BLEND );
1.82 - glBlendFunc( GL_ONE, GL_ZERO );
1.83 - glDisable( GL_DEPTH_TEST );
1.84 - glBegin( GL_QUADS );
1.85 - glTexCoord2i( 0.5, buffer->height-0.5 );
1.86 - glVertex2f( 0.0, 0.0 );
1.87 - glTexCoord2i( buffer->width-0.5, buffer->height-0.5 );
1.88 - glVertex2f( buffer->width, 0.0 );
1.89 - glTexCoord2i( buffer->width-0.5, 0 );
1.90 - glVertex2f( buffer->width, buffer->height );
1.91 - glTexCoord2i( 0.5, 0.5 );
1.92 - glVertex2f( 0.0, buffer->height );
1.93 - glEnd();
1.94 - glDisable( GL_TEXTURE_RECTANGLE_ARB );
1.95 - glFlush();
1.96 - */
1.97 + gl_fbo_detach();
1.98 + gl_display_render_buffer( buffer );
1.99 return TRUE;
1.100 }
1.101
1.102 -static gboolean gl_fbo_display_frame_buffer( frame_buffer_t buffer )
1.103 +static void gl_fbo_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer )
1.104 +{
1.105 + glFinish();
1.106 + gl_fbo_detach();
1.107 + gl_load_frame_buffer( frame, buffer );
1.108 +}
1.109 +
1.110 +static gboolean gl_fbo_display_blank( uint32_t colour )
1.111 +{
1.112 + glFinish();
1.113 + gl_fbo_detach();
1.114 + return gl_display_blank( colour );
1.115 +}
1.116 +
1.117 +void gl_fbo_detach()
1.118 {
1.119 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
1.120 glDrawBuffer( GL_FRONT );
1.121 glReadBuffer( GL_FRONT );
1.122 - return gl_display_frame_buffer( buffer );
1.123 -}
1.124 +}
1.125
1.126 -static gboolean gl_fbo_display_blank( uint32_t colour )
1.127 -{
1.128 - glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
1.129 - glDrawBuffer( GL_FRONT );
1.130 - glReadBuffer( GL_FRONT );
1.131 - return gl_display_blank( colour );
1.132 -}
1.133 -
1.134 -static gboolean gl_fbo_read_render_buffer( render_buffer_t buffer, unsigned char *target )
1.135 +static gboolean gl_fbo_read_render_buffer( unsigned char *target, render_buffer_t buffer,
1.136 + int rowstride, int format )
1.137 {
1.138 int fb = gl_fbo_get_framebuffer( buffer->width, buffer->height );
1.139 gl_fbo_attach_texture( fb, buffer->buf_id );
1.140 - return gl_read_render_buffer( buffer, target );
1.141 + return gl_read_render_buffer( target, buffer, rowstride, format );
1.142 }
1.143
.