filename | src/pvr2/render.c |
changeset | 352:f0df7a6d4703 |
prev | 338:8c68d9097846 |
next | 429:e581b90c3fb3 |
author | nkeynes |
date | Sun Feb 11 10:09:32 2007 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Bug 27: Implement opengl framebuffer objects Rewrite much of the final video output stage. Now uses generic "render buffers", implemented on GL using framebuffer objects + textures. |
view | annotate | diff | log | raw |
1 /**
2 * $Id: render.c,v 1.24 2007-02-11 10:09:32 nkeynes Exp $
3 *
4 * PVR2 Renderer support. This part is primarily
5 *
6 * Copyright (c) 2005 Nathan Keynes.
7 *
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.
12 *
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.
17 */
19 #include "pvr2/pvr2.h"
20 #include "asic.h"
23 int pvr2_render_font_list = -1;
24 int pvr2_render_trace = 0;
26 int glPrintf( int x, int y, const char *fmt, ... )
27 {
28 va_list ap; /* our argument pointer */
29 char buf[256];
30 int len;
31 if (fmt == NULL) /* if there is no string to draw do nothing */
32 return;
33 va_start(ap, fmt);
34 len = vsnprintf(buf, sizeof(buf), fmt, ap);
35 va_end(ap);
38 glPushAttrib(GL_LIST_BIT);
39 glDisable( GL_DEPTH_TEST );
40 glDisable( GL_BLEND );
41 glDisable( GL_TEXTURE_2D );
42 glDisable( GL_ALPHA_TEST );
43 glDisable( GL_CULL_FACE );
44 glListBase(pvr2_render_font_list - 32);
45 glColor3f( 1.0, 1.0, 1.0 );
46 glRasterPos2i( x, y );
47 glCallLists(len, GL_UNSIGNED_BYTE, buf);
48 glPopAttrib();
50 return len;
51 }
53 void glDrawGrid( int width, int height )
54 {
55 int i;
56 glDisable( GL_DEPTH_TEST );
57 glLineWidth(1);
59 glBegin( GL_LINES );
60 glColor4f( 1.0, 1.0, 1.0, 1.0 );
61 for( i=32; i<width; i+=32 ) {
62 glVertex3f( i, 0.0, 3.0 );
63 glVertex3f( i,height-1, 3.0 );
64 }
66 for( i=32; i<height; i+=32 ) {
67 glVertex3f( 0.0, i, 3.0 );
68 glVertex3f( width, i, 3.0 );
69 }
70 glEnd();
72 }
74 /**
75 * Prepare the OpenGL context to receive instructions for a new frame.
76 */
77 static void pvr2_render_prepare_context( render_buffer_t buffer,
78 float bgplanez, float nearz )
79 {
80 /* Select and initialize the render context */
81 display_driver->set_render_target(buffer);
83 if( pvr2_render_font_list == -1 ) {
84 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
85 }
87 pvr2_check_palette_changed();
89 /* Setup the display model */
90 glShadeModel(GL_SMOOTH);
91 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
92 glMatrixMode(GL_PROJECTION);
93 glLoadIdentity();
94 glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
95 glMatrixMode(GL_MODELVIEW);
96 glLoadIdentity();
97 glCullFace( GL_BACK );
98 glEnable( GL_BLEND );
100 /* Clear out the buffers */
101 glDisable( GL_SCISSOR_TEST );
102 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
103 glClearDepth(0);
104 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
105 }
107 /**
108 * Render a complete scene into the OpenGL back buffer.
109 * Note: this will probably need to be broken up eventually once timings are
110 * determined.
111 */
112 void pvr2_render_scene( render_buffer_t buffer )
113 {
114 struct tile_descriptor *tile_desc =
115 (struct tile_descriptor *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_TILEBASE ));
117 float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
118 pvr2_render_prepare_context( buffer, bgplanez, 0 );
120 int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
121 int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
122 int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
123 int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
125 /* Fog setup goes here? */
127 /* Render the background plane */
129 uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
130 uint32_t *display_list =
131 (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
133 uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
134 render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
136 pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y,
137 clip_x + clip_width, clip_y + clip_height );
139 DEBUG( "Rendered frame %d to %08X", pvr2_get_frame_count(), buffer->address );
140 }
.