Search
lxdream.org :: lxdream/src/pvr2/render.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 429:e581b90c3fb3
prev352:f0df7a6d4703
next477:9a373f2ff009
author nkeynes
date Mon Oct 08 11:52:13 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix compilation warnings
file annotate diff log raw
nkeynes@100
     1
/**
nkeynes@429
     2
 * $Id: render.c,v 1.25 2007-10-08 11:52:13 nkeynes Exp $
nkeynes@100
     3
 *
nkeynes@189
     4
 * PVR2 Renderer support. This part is primarily
nkeynes@100
     5
 *
nkeynes@100
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@100
     7
 *
nkeynes@100
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@100
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@100
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@100
    11
 * (at your option) any later version.
nkeynes@100
    12
 *
nkeynes@100
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@100
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@100
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@100
    16
 * GNU General Public License for more details.
nkeynes@100
    17
 */
nkeynes@100
    18
nkeynes@429
    19
#include <sys/time.h>
nkeynes@429
    20
#include <time.h>
nkeynes@100
    21
#include "pvr2/pvr2.h"
nkeynes@100
    22
#include "asic.h"
nkeynes@103
    23
nkeynes@103
    24
nkeynes@132
    25
int pvr2_render_trace = 0;
nkeynes@108
    26
nkeynes@429
    27
#if 0
nkeynes@429
    28
int pvr2_render_font_list = -1;
nkeynes@132
    29
int glPrintf( int x, int y, const char *fmt, ... )
nkeynes@108
    30
{
nkeynes@108
    31
    va_list ap;     /* our argument pointer */
nkeynes@108
    32
    char buf[256];
nkeynes@108
    33
    int len;
nkeynes@108
    34
    if (fmt == NULL)    /* if there is no string to draw do nothing */
nkeynes@429
    35
        return 0;
nkeynes@108
    36
    va_start(ap, fmt); 
nkeynes@108
    37
    len = vsnprintf(buf, sizeof(buf), fmt, ap);
nkeynes@108
    38
    va_end(ap);
nkeynes@108
    39
nkeynes@108
    40
nkeynes@108
    41
    glPushAttrib(GL_LIST_BIT);
nkeynes@132
    42
    glDisable( GL_DEPTH_TEST );
nkeynes@132
    43
    glDisable( GL_BLEND );
nkeynes@132
    44
    glDisable( GL_TEXTURE_2D );
nkeynes@132
    45
    glDisable( GL_ALPHA_TEST );
nkeynes@189
    46
    glDisable( GL_CULL_FACE );
nkeynes@108
    47
    glListBase(pvr2_render_font_list - 32);
nkeynes@132
    48
    glColor3f( 1.0, 1.0, 1.0 );
nkeynes@132
    49
    glRasterPos2i( x, y );
nkeynes@108
    50
    glCallLists(len, GL_UNSIGNED_BYTE, buf);
nkeynes@108
    51
    glPopAttrib();
nkeynes@108
    52
nkeynes@108
    53
    return len;
nkeynes@108
    54
}
nkeynes@429
    55
#endif
nkeynes@108
    56
nkeynes@189
    57
void glDrawGrid( int width, int height )
nkeynes@189
    58
{
nkeynes@189
    59
    int i;
nkeynes@189
    60
    glDisable( GL_DEPTH_TEST );
nkeynes@189
    61
    glLineWidth(1);
nkeynes@189
    62
    
nkeynes@189
    63
    glBegin( GL_LINES );
nkeynes@189
    64
    glColor4f( 1.0, 1.0, 1.0, 1.0 );
nkeynes@189
    65
    for( i=32; i<width; i+=32 ) {
nkeynes@189
    66
	glVertex3f( i, 0.0, 3.0 );
nkeynes@189
    67
	glVertex3f( i,height-1, 3.0 );
nkeynes@189
    68
    }
nkeynes@189
    69
nkeynes@189
    70
    for( i=32; i<height; i+=32 ) {
nkeynes@189
    71
	glVertex3f( 0.0, i, 3.0 );
nkeynes@189
    72
	glVertex3f( width, i, 3.0 );
nkeynes@189
    73
    }
nkeynes@189
    74
    glEnd();
nkeynes@189
    75
	
nkeynes@189
    76
}
nkeynes@189
    77
nkeynes@103
    78
/**
nkeynes@103
    79
 * Prepare the OpenGL context to receive instructions for a new frame.
nkeynes@103
    80
 */
nkeynes@352
    81
static void pvr2_render_prepare_context( render_buffer_t buffer,
nkeynes@352
    82
					 float bgplanez, float nearz ) 
nkeynes@103
    83
{
nkeynes@103
    84
    /* Select and initialize the render context */
nkeynes@352
    85
    display_driver->set_render_target(buffer);
nkeynes@429
    86
#if 0
nkeynes@132
    87
    if( pvr2_render_font_list == -1 ) {
nkeynes@132
    88
	pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
nkeynes@132
    89
    }
nkeynes@429
    90
#endif
nkeynes@337
    91
    pvr2_check_palette_changed();
nkeynes@337
    92
nkeynes@103
    93
    /* Setup the display model */
nkeynes@103
    94
    glShadeModel(GL_SMOOTH);
nkeynes@103
    95
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
nkeynes@103
    96
    glMatrixMode(GL_PROJECTION);
nkeynes@103
    97
    glLoadIdentity();
nkeynes@352
    98
    glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
nkeynes@103
    99
    glMatrixMode(GL_MODELVIEW);
nkeynes@103
   100
    glLoadIdentity();
nkeynes@108
   101
    glCullFace( GL_BACK );
nkeynes@308
   102
    glEnable( GL_BLEND );
nkeynes@103
   103
nkeynes@103
   104
    /* Clear out the buffers */
nkeynes@189
   105
    glDisable( GL_SCISSOR_TEST );
nkeynes@103
   106
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
nkeynes@299
   107
    glClearDepth(0);
nkeynes@103
   108
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
nkeynes@103
   109
}
nkeynes@103
   110
nkeynes@128
   111
/**
nkeynes@103
   112
 * Render a complete scene into the OpenGL back buffer.
nkeynes@103
   113
 * Note: this will probably need to be broken up eventually once timings are
nkeynes@100
   114
 * determined.
nkeynes@100
   115
 */
nkeynes@352
   116
void pvr2_render_scene( render_buffer_t buffer )
nkeynes@100
   117
{
nkeynes@429
   118
    struct timeval tva, tvb;
nkeynes@429
   119
nkeynes@429
   120
    gettimeofday(&tva, NULL);
nkeynes@100
   121
nkeynes@331
   122
    float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
nkeynes@352
   123
    pvr2_render_prepare_context( buffer, bgplanez, 0 );
nkeynes@103
   124
nkeynes@191
   125
    int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
nkeynes@191
   126
    int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
nkeynes@191
   127
    int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
nkeynes@191
   128
    int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
nkeynes@103
   129
nkeynes@352
   130
    /* Fog setup goes here? */
nkeynes@103
   131
nkeynes@128
   132
    /* Render the background plane */
nkeynes@352
   133
nkeynes@191
   134
    uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
nkeynes@189
   135
    uint32_t *display_list = 
nkeynes@191
   136
	(uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
nkeynes@189
   137
nkeynes@189
   138
    uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
nkeynes@352
   139
    render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
nkeynes@352
   140
    
nkeynes@352
   141
    pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y, 
nkeynes@189
   142
			    clip_x + clip_width, clip_y + clip_height );
nkeynes@429
   143
nkeynes@429
   144
    gettimeofday( &tvb, NULL );
nkeynes@429
   145
    uint32_t ms = (tvb.tv_sec - tva.tv_sec) * 1000 + 
nkeynes@429
   146
	(tvb.tv_usec - tva.tv_usec)/1000;
nkeynes@429
   147
    DEBUG( "Rendered frame %d to %08X in %dms", pvr2_get_frame_count(), buffer->address, ms );
nkeynes@100
   148
}
.