1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/drivers/video_gl.c Fri Mar 28 12:32:25 2008 +0000
1.7 + * Common GL code that doesn't depend on a specific implementation
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.22 +#include <sys/time.h>
1.24 +#include "display.h"
1.25 +#include "pvr2/pvr2.h"
1.26 +#include "drivers/video_gl.h"
1.28 +extern uint32_t video_width, video_height;
1.31 + * Reset the gl state to simple orthographic projection with
1.32 + * texturing, alpha/depth/scissor/cull tests disabled.
1.34 +void gl_reset_state()
1.36 + glViewport( 0, 0, video_width, video_height );
1.37 + glMatrixMode(GL_PROJECTION);
1.39 + glOrtho( 0, video_width, video_height, 0, 0, 65535 );
1.40 + glMatrixMode(GL_MODELVIEW);
1.42 + glDisable( GL_TEXTURE_2D );
1.43 + glDisable( GL_ALPHA_TEST );
1.44 + glDisable( GL_DEPTH_TEST );
1.45 + glDisable( GL_SCISSOR_TEST );
1.46 + glDisable( GL_CULL_FACE );
1.47 + glDrawBuffer( GL_FRONT );
1.50 +void gl_display_render_buffer( render_buffer_t buffer )
1.52 + gl_texture_window( buffer->width, buffer->height, buffer->buf_id, buffer->inverted );
1.55 +void gl_texture_window( int width, int height, int tex_id, gboolean inverted )
1.57 + float top, bottom;
1.59 + top = ((float)height);
1.63 + bottom = ((float)height);
1.66 + /* Reset display parameters */
1.68 + glColor3f( 0,0,0 );
1.70 + int x1=0,y1=0,x2=video_width,y2=video_height;
1.72 + int ah = video_width * 0.75;
1.74 + if( ah > video_height ) {
1.75 + int w = (video_height/0.75);
1.76 + x1 = (video_width - w)/2;
1.79 + glBegin( GL_QUADS );
1.80 + glVertex2f( 0, 0 );
1.81 + glVertex2f( x1, 0 );
1.82 + glVertex2f( x1, video_height );
1.83 + glVertex2f( 0, video_height);
1.84 + glVertex2f( x2, 0 );
1.85 + glVertex2f( video_width, 0 );
1.86 + glVertex2f( video_width, video_height );
1.87 + glVertex2f( x2, video_height);
1.89 + } else if( ah < video_height ) {
1.90 + y1 = (video_height - ah)/2;
1.92 + glBegin( GL_QUADS );
1.93 + glVertex2f( 0, 0 );
1.94 + glVertex2f( video_width, 0 );
1.95 + glVertex2f( video_width, y1 );
1.96 + glVertex2f( 0, y1 );
1.97 + glVertex2f( 0, y2 );
1.98 + glVertex2f( video_width, y2 );
1.99 + glVertex2f( video_width, video_height );
1.100 + glVertex2f( 0, video_height );
1.104 + /* Render the textured rectangle */
1.105 + glEnable( GL_TEXTURE_RECTANGLE_ARB );
1.106 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex_id );
1.107 + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1.108 + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1.109 + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1.110 + glEnable( GL_BLEND );
1.111 + glBlendFunc( GL_ONE, GL_ZERO );
1.112 + glBegin( GL_QUADS );
1.113 + glTexCoord2f( 0, top );
1.114 + glVertex2f( x1, y1 );
1.115 + glTexCoord2f( ((float)width), top );
1.116 + glVertex2f( x2, y1 );
1.117 + glTexCoord2f( ((float)width), bottom );
1.118 + glVertex2f( x2, y2 );
1.119 + glTexCoord2f( 0, bottom );
1.120 + glVertex2f( x1, y2 );
1.122 + glDisable( GL_TEXTURE_RECTANGLE_ARB );
1.126 +gboolean gl_load_frame_buffer( frame_buffer_t frame, int tex_id )
1.128 + GLenum type = colour_formats[frame->colour_format].type;
1.129 + GLenum format = colour_formats[frame->colour_format].format;
1.130 + int bpp = colour_formats[frame->colour_format].bpp;
1.131 + int rowstride = (frame->rowstride / bpp) - frame->width;
1.133 + glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
1.134 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex_id );
1.135 + glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0,0,
1.136 + frame->width, frame->height, format, type, frame->data );
1.140 +gboolean gl_display_blank( uint32_t colour )
1.142 + gl_reset_state();
1.143 + glColor3ub( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
1.144 + glRecti(0,0, video_width, video_height );
1.150 + * Generic GL read_render_buffer. This function assumes that the caller
1.151 + * has already set the appropriate glReadBuffer(); in other words, unless
1.152 + * there's only one buffer this needs to be wrapped.
1.154 +gboolean gl_read_render_buffer( unsigned char *target, render_buffer_t buffer,
1.155 + int rowstride, int colour_format )
1.158 + GLenum type = colour_formats[colour_format].type;
1.159 + GLenum format = colour_formats[colour_format].format;
1.160 + // int line_size = buffer->width * colour_formats[colour_format].bpp;
1.161 + // int size = line_size * buffer->height;
1.162 + int glrowstride = (rowstride / colour_formats[colour_format].bpp) - buffer->width;
1.163 + glPixelStorei( GL_PACK_ROW_LENGTH, glrowstride );
1.165 + glReadPixels( 0, 0, buffer->width, buffer->height, format, type, target );