Search
lxdream.org :: lxdream/src/pvr2/render.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 477:9a373f2ff009
prev429:e581b90c3fb3
next561:533f6b478071
author nkeynes
date Thu Nov 22 11:10:15 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Re-add "Load Binary" menu item (misplaced in GUI rewrite)
Prevent running with no code loaded
view annotate diff log raw
     1 /**
     2  * $Id: render.c,v 1.26 2007-10-31 09:10:23 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 <sys/time.h>
    20 #include <time.h>
    21 #include "pvr2/pvr2.h"
    22 #include "asic.h"
    25 int pvr2_render_trace = 0;
    27 #if 0
    28 int pvr2_render_font_list = -1;
    29 int glPrintf( int x, int y, const char *fmt, ... )
    30 {
    31     va_list ap;     /* our argument pointer */
    32     char buf[256];
    33     int len;
    34     if (fmt == NULL)    /* if there is no string to draw do nothing */
    35         return 0;
    36     va_start(ap, fmt); 
    37     len = vsnprintf(buf, sizeof(buf), fmt, ap);
    38     va_end(ap);
    41     glPushAttrib(GL_LIST_BIT);
    42     glDisable( GL_DEPTH_TEST );
    43     glDisable( GL_BLEND );
    44     glDisable( GL_TEXTURE_2D );
    45     glDisable( GL_ALPHA_TEST );
    46     glDisable( GL_CULL_FACE );
    47     glListBase(pvr2_render_font_list - 32);
    48     glColor3f( 1.0, 1.0, 1.0 );
    49     glRasterPos2i( x, y );
    50     glCallLists(len, GL_UNSIGNED_BYTE, buf);
    51     glPopAttrib();
    53     return len;
    54 }
    55 #endif
    57 void glDrawGrid( int width, int height )
    58 {
    59     int i;
    60     glDisable( GL_DEPTH_TEST );
    61     glLineWidth(1);
    63     glBegin( GL_LINES );
    64     glColor4f( 1.0, 1.0, 1.0, 1.0 );
    65     for( i=32; i<width; i+=32 ) {
    66 	glVertex3f( i, 0.0, 3.0 );
    67 	glVertex3f( i,height-1, 3.0 );
    68     }
    70     for( i=32; i<height; i+=32 ) {
    71 	glVertex3f( 0.0, i, 3.0 );
    72 	glVertex3f( width, i, 3.0 );
    73     }
    74     glEnd();
    76 }
    78 /**
    79  * Prepare the OpenGL context to receive instructions for a new frame.
    80  */
    81 static void pvr2_render_prepare_context( render_buffer_t buffer,
    82 					 float bgplanez, float nearz ) 
    83 {
    84     /* Select and initialize the render context */
    85     display_driver->set_render_target(buffer);
    86 #if 0
    87     if( pvr2_render_font_list == -1 ) {
    88 	pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
    89     }
    90 #endif
    91     pvr2_check_palette_changed();
    93     /* Setup the display model */
    94     glShadeModel(GL_SMOOTH);
    95     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    96     glMatrixMode(GL_PROJECTION);
    97     glLoadIdentity();
    98     glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
    99     glMatrixMode(GL_MODELVIEW);
   100     glLoadIdentity();
   101     glCullFace( GL_BACK );
   102     glEnable( GL_BLEND );
   104     /* Clear out the buffers */
   105     glDisable( GL_SCISSOR_TEST );
   106     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   107     glClearDepth(0);
   108     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
   109     glEnableClientState( GL_COLOR_ARRAY );
   110     glEnableClientState( GL_VERTEX_ARRAY );
   111 }
   113 /**
   114  * Render a complete scene into the OpenGL back buffer.
   115  * Note: this will probably need to be broken up eventually once timings are
   116  * determined.
   117  */
   118 void pvr2_render_scene( render_buffer_t buffer )
   119 {
   120     struct timeval tva, tvb;
   122     gettimeofday(&tva, NULL);
   124     float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
   125     pvr2_render_prepare_context( buffer, bgplanez, 0 );
   127     int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
   128     int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
   129     int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
   130     int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
   132     /* Fog setup goes here? */
   134     /* Render the background plane */
   136     uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
   137     uint32_t *display_list = 
   138 	(uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
   140     uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
   141     render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
   143     pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y, 
   144 			    clip_x + clip_width, clip_y + clip_height );
   146     gettimeofday( &tvb, NULL );
   147     uint32_t ms = (tvb.tv_sec - tva.tv_sec) * 1000 + 
   148 	(tvb.tv_usec - tva.tv_usec)/1000;
   149     DEBUG( "Rendered frame %d to %08X in %dms", pvr2_get_frame_count(), buffer->address, ms );
   150 }
.