Search
lxdream.org :: lxdream/src/pvr2/render.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 639:162ee7614b60
prev635:76c63aac3590
author nkeynes
date Mon Feb 18 09:21:43 2008 +0000 (12 years ago)
branchlxdream-render
permissions -rw-r--r--
last change More render WIP - initial glrender.c
view annotate diff log raw
     1 /**
     2  * $Id$
     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 <math.h>
    22 #include "pvr2/pvr2.h"
    23 #include "asic.h"
    26 int pvr2_render_trace = 0;
    28 #if 0
    29 int pvr2_render_font_list = -1;
    30 int glPrintf( int x, int y, const char *fmt, ... )
    31 {
    32     va_list ap;     /* our argument pointer */
    33     char buf[256];
    34     int len;
    35     if (fmt == NULL)    /* if there is no string to draw do nothing */
    36         return 0;
    37     va_start(ap, fmt); 
    38     len = vsnprintf(buf, sizeof(buf), fmt, ap);
    39     va_end(ap);
    42     glPushAttrib(GL_LIST_BIT);
    43     glDisable( GL_DEPTH_TEST );
    44     glDisable( GL_BLEND );
    45     glDisable( GL_TEXTURE_2D );
    46     glDisable( GL_ALPHA_TEST );
    47     glDisable( GL_CULL_FACE );
    48     glListBase(pvr2_render_font_list - 32);
    49     glColor3f( 1.0, 1.0, 1.0 );
    50     glRasterPos2i( x, y );
    51     glCallLists(len, GL_UNSIGNED_BYTE, buf);
    52     glPopAttrib();
    54     return len;
    55 }
    56 #endif
    58 void glDrawGrid( int width, int height )
    59 {
    60     int i;
    61     glDisable( GL_DEPTH_TEST );
    62     glLineWidth(1);
    64     glBegin( GL_LINES );
    65     glColor4f( 1.0, 1.0, 1.0, 1.0 );
    66     for( i=32; i<width; i+=32 ) {
    67 	glVertex3f( i, 0.0, 3.0 );
    68 	glVertex3f( i,height-1, 3.0 );
    69     }
    71     for( i=32; i<height; i+=32 ) {
    72 	glVertex3f( 0.0, i, 3.0 );
    73 	glVertex3f( width, i, 3.0 );
    74     }
    75     glEnd();
    77 }
    79 /**
    80  * Prepare the OpenGL context to receive instructions for a new frame.
    81  */
    82 static void pvr2_render_prepare_context( render_buffer_t buffer,
    83 					 float nearz, float farz )
    84 {
    85     /* Select and initialize the render context */
    86     display_driver->set_render_target(buffer);
    87 #if 0
    88     if( pvr2_render_font_list == -1 ) {
    89 	pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
    90     }
    91 #endif
    92     pvr2_check_palette_changed();
    94     /* Setup the display model */
    95     glShadeModel(GL_SMOOTH);
    96     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    97     glMatrixMode(GL_PROJECTION);
    98     glLoadIdentity();
    99     glOrtho( 0, buffer->width, buffer->height, 0, -nearz, -farz );
   100     glMatrixMode(GL_MODELVIEW);
   101     glLoadIdentity();
   102     glCullFace( GL_BACK );
   103     glEnable( GL_BLEND );
   105     /* Clear out the buffers */
   106     glDisable( GL_SCISSOR_TEST );
   107     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   108     glClearDepth(0);
   109     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
   110     glEnableClientState( GL_COLOR_ARRAY );
   111     glEnableClientState( GL_VERTEX_ARRAY );
   112 }
   114 /**
   115  * Render a complete scene into the OpenGL back buffer.
   116  * Note: this will probably need to be broken up eventually once timings are
   117  * determined.
   118  */
   119 void pvr2_render_scene( render_buffer_t buffer )
   120 {
   121     struct timeval tva, tvb;
   123     gettimeofday(&tva, NULL);
   125     float farz, nearz;
   126     pvr2_render_find_z_range( &nearz, &farz );
   127     float bgplanez = MMIO_READF( PVR2, RENDER_FARCLIP );
   128     pvr2_render_prepare_context( buffer, nearz, farz );
   130     int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
   131     int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
   132     int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
   133     int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
   135     /* Fog setup goes here? */
   137     /* Render the background plane */
   139     uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
   140     uint32_t *display_list = 
   141 	(uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
   143     uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
   144     render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
   146     pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y, 
   147 			    clip_x + clip_width, clip_y + clip_height );
   149     gettimeofday( &tvb, NULL );
   150     uint32_t ms = (tvb.tv_sec - tva.tv_sec) * 1000 + 
   151 	(tvb.tv_usec - tva.tv_usec)/1000;
   152     DEBUG( "Rendered frame %d to %08X in %dms", pvr2_get_frame_count(), buffer->address, ms );
   153 }
.