4 * Common GL code that doesn't depend on a specific implementation
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
22 #include "pvr2/pvr2.h"
23 #include "drivers/video_gl.h"
25 extern uint32_t video_width, video_height;
28 * Reset the gl state to simple orthographic projection with
29 * texturing, alpha/depth/scissor/cull tests disabled.
33 glViewport( 0, 0, video_width, video_height );
34 glMatrixMode(GL_PROJECTION);
36 glOrtho( 0, video_width, video_height, 0, 0, 65535 );
37 glMatrixMode(GL_MODELVIEW);
40 glDisable( GL_TEXTURE_2D );
41 glDisable( GL_TEXTURE_RECTANGLE_ARB );
42 glDisable( GL_ALPHA_TEST );
43 glDisable( GL_DEPTH_TEST );
44 glDisable( GL_SCISSOR_TEST );
45 glDisable( GL_CULL_FACE );
46 glDrawBuffer( GL_FRONT );
49 void gl_display_render_buffer( render_buffer_t buffer )
51 gl_texture_window( buffer->width, buffer->height, buffer->buf_id, buffer->inverted );
54 void gl_texture_window( int width, int height, int tex_id, gboolean inverted )
58 top = ((float)height);
62 bottom = ((float)height);
65 /* Reset display parameters */
69 int x1=0,y1=0,x2=video_width,y2=video_height;
71 int ah = video_width * 0.75;
73 if( ah > video_height ) {
74 int w = (video_height/0.75);
75 x1 = (video_width - w)/2;
81 glVertex2f( x1, video_height );
82 glVertex2f( 0, video_height);
84 glVertex2f( video_width, 0 );
85 glVertex2f( video_width, video_height );
86 glVertex2f( x2, video_height);
88 } else if( ah < video_height ) {
89 y1 = (video_height - ah)/2;
93 glVertex2f( video_width, 0 );
94 glVertex2f( video_width, y1 );
97 glVertex2f( video_width, y2 );
98 glVertex2f( video_width, video_height );
99 glVertex2f( 0, video_height );
103 /* Render the textured rectangle */
104 glEnable( GL_TEXTURE_RECTANGLE_ARB );
105 glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex_id );
106 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
107 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
108 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
109 glEnable( GL_BLEND );
110 glBlendFunc( GL_ONE, GL_ZERO );
112 glTexCoord2f( 0, top );
113 glVertex2f( x1, y1 );
114 glTexCoord2f( ((float)width), top );
115 glVertex2f( x2, y1 );
116 glTexCoord2f( ((float)width), bottom );
117 glVertex2f( x2, y2 );
118 glTexCoord2f( 0, bottom );
119 glVertex2f( x1, y2 );
121 glDisable( GL_TEXTURE_RECTANGLE_ARB );
125 gboolean gl_load_frame_buffer( frame_buffer_t frame, int tex_id )
127 GLenum type = colour_formats[frame->colour_format].type;
128 GLenum format = colour_formats[frame->colour_format].format;
129 int bpp = colour_formats[frame->colour_format].bpp;
130 int rowstride = (frame->rowstride / bpp) - frame->width;
132 glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
133 glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex_id );
134 glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0,0,
135 frame->width, frame->height, format, type, frame->data );
139 void gl_display_blank( uint32_t colour )
142 glColor3ub( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
143 glRecti(0,0, video_width, video_height );
148 * Generic GL read_render_buffer. This function assumes that the caller
149 * has already set the appropriate glReadBuffer(); in other words, unless
150 * there's only one buffer this needs to be wrapped.
152 gboolean gl_read_render_buffer( unsigned char *target, render_buffer_t buffer,
153 int rowstride, int colour_format )
156 GLenum type = colour_formats[colour_format].type;
157 GLenum format = colour_formats[colour_format].format;
158 // int line_size = buffer->width * colour_formats[colour_format].bpp;
159 // int size = line_size * buffer->height;
160 int glrowstride = (rowstride / colour_formats[colour_format].bpp) - buffer->width;
161 glPixelStorei( GL_PACK_ROW_LENGTH, glrowstride );
163 glReadPixels( 0, 0, buffer->width, buffer->height, format, type, target );
.