mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-08 21:31:46 +08:00
ref_gu: refactoring
This commit is contained in:
@@ -17,9 +17,6 @@ GNU General Public License for more details.
|
||||
#if !XASH_DEDICATED
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspgu.h>
|
||||
#include <pspgum.h>
|
||||
#include "vram_psp.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "client.h"
|
||||
@@ -27,31 +24,19 @@ GNU General Public License for more details.
|
||||
#include "input.h"
|
||||
#include "vid_common.h"
|
||||
|
||||
// Set gu list
|
||||
#define PSP_GU_STATIC_LIST 1
|
||||
#define PSP_GU_LIST_SIZE 0x40000
|
||||
|
||||
// Set frame buffer
|
||||
#define PSP_FB_WIDTH 480
|
||||
#define PSP_FB_HEIGHT 272
|
||||
#define PSP_FB_BWIDTH 512
|
||||
#define PSP_FB_FORMAT 5650 //4444,5551,5650,8888
|
||||
#define PSP_FB_FORMAT PSP_DISPLAY_PIXEL_FORMAT_565 //4444,5551,565,8888
|
||||
|
||||
#if PSP_FB_FORMAT == 4444
|
||||
#define PSP_FB_HW_FORMAT GU_PSM_4444
|
||||
#define PSP_FB_SW_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444
|
||||
#if PSP_FB_FORMAT == PSP_DISPLAY_PIXEL_FORMAT_4444
|
||||
#define PSP_FB_BPP 2
|
||||
#elif PSP_FB_FORMAT == 5551
|
||||
#define PSP_FB_HW_FORMAT GU_PSM_5551
|
||||
#define PSP_FB_SW_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551
|
||||
#elif PSP_FB_FORMAT == PSP_DISPLAY_PIXEL_FORMAT_5551
|
||||
#define PSP_FB_BPP 2
|
||||
#elif PSP_FB_FORMAT == 5650
|
||||
#define PSP_FB_HW_FORMAT GU_PSM_5650
|
||||
#define PSP_FB_SW_FORMAT PSP_DISPLAY_PIXEL_FORMAT_565
|
||||
#elif PSP_FB_FORMAT == PSP_DISPLAY_PIXEL_FORMAT_565
|
||||
#define PSP_FB_BPP 2
|
||||
#elif PSP_FB_FORMAT == 8888
|
||||
#define PSP_FB_HW_FORMAT GU_PSM_8888
|
||||
#define PSP_FB_SW_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888
|
||||
#elif PSP_FB_FORMAT == PSP_DISPLAY_PIXEL_FORMAT_8888
|
||||
#define PSP_FB_BPP 4
|
||||
#endif
|
||||
|
||||
@@ -84,12 +69,6 @@ static struct
|
||||
#endif
|
||||
void *draw_buffer;
|
||||
void *disp_buffer;
|
||||
void *depth_buffer;
|
||||
#if PSP_GU_STATIC_LIST
|
||||
unsigned int gu_list[PSP_GU_LIST_SIZE] __attribute__( ( aligned( 64 ) ) );
|
||||
#else
|
||||
unsigned int *gu_list;
|
||||
#endif
|
||||
}vid_psp;
|
||||
|
||||
qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b )
|
||||
@@ -100,16 +79,16 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
|
||||
*b = 31 << 11;
|
||||
*bpp = 2;
|
||||
|
||||
vid_psp.draw_buffer = (void*)valloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
vid_psp.draw_buffer = (void*)malloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
if( !vid_psp.draw_buffer )
|
||||
Host_Error( "Memory allocation failled! (vid_psp.draw_buffer)\n");
|
||||
|
||||
vid_psp.disp_buffer = (void*)valloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
vid_psp.disp_buffer = (void*)malloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
if( !vid_psp.disp_buffer )
|
||||
Host_Error( "Memory allocation failled! (vid_psp.disp_buffer)\n");
|
||||
|
||||
sceDisplaySetMode(0, PSP_FB_WIDTH, PSP_FB_HEIGHT);
|
||||
sceDisplaySetFrameBuf(vid_psp.disp_buffer, PSP_FB_WIDTH, PSP_FB_SW_FORMAT, 1);
|
||||
sceDisplaySetFrameBuf(vid_psp.disp_buffer, PSP_FB_WIDTH, PSP_FB_FORMAT, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -126,7 +105,7 @@ void SW_UnlockBuffer( void )
|
||||
vid_psp.draw_buffer = p_swap;
|
||||
|
||||
sceKernelDcacheWritebackInvalidateAll();
|
||||
sceDisplaySetFrameBuf(vid_psp.disp_buffer, PSP_FB_BWIDTH, PSP_FB_SW_FORMAT, PSP_DISPLAY_SETBUF_NEXTFRAME);
|
||||
sceDisplaySetFrameBuf(vid_psp.disp_buffer, PSP_FB_BWIDTH, PSP_FB_FORMAT, PSP_DISPLAY_SETBUF_NEXTFRAME);
|
||||
|
||||
if ( vsync )
|
||||
{
|
||||
@@ -134,146 +113,6 @@ void SW_UnlockBuffer( void )
|
||||
}
|
||||
}
|
||||
|
||||
_inline void GU_Init( void )
|
||||
{
|
||||
vid_psp.draw_buffer = ( void* )valloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
if( !vid_psp.draw_buffer )
|
||||
Host_Error( "Memory allocation failled! (vid_psp.draw_buffer)\n");
|
||||
|
||||
vid_psp.disp_buffer = ( void* )valloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
if( !vid_psp.disp_buffer )
|
||||
Host_Error( "Memory allocation failled! (vid_psp.disp_buffer)\n");
|
||||
|
||||
vid_psp.depth_buffer = ( void* )valloc( PSP_FB_HEIGHT * PSP_FB_BWIDTH * PSP_FB_BPP );
|
||||
if( !vid_psp.depth_buffer )
|
||||
Host_Error( "Memory allocation failled! (vid_psp.depth_buffer)\n");
|
||||
|
||||
#if !PSP_GU_STATIC_LIST
|
||||
vid_psp.gu_list = ( unsigned int* )valloc( PSP_GU_LIST_SIZE * sizeof ( unsigned int ) );
|
||||
if( !vid_psp.gu_list )
|
||||
Host_Error( "Memory allocation failled! (vid_psp.gu_list)\n");
|
||||
#endif
|
||||
|
||||
// Initialise the GU.
|
||||
sceGuInit();
|
||||
|
||||
// Set up the GU.
|
||||
sceGuStart( GU_DIRECT, vid_psp.gu_list );
|
||||
|
||||
sceGuDrawBuffer( PSP_FB_HW_FORMAT, vrelptr( vid_psp.draw_buffer ), PSP_FB_BWIDTH);
|
||||
sceGuDispBuffer( PSP_FB_WIDTH, PSP_FB_HEIGHT, vrelptr( vid_psp.disp_buffer ), PSP_FB_BWIDTH);
|
||||
sceGuDepthBuffer( vrelptr( vid_psp.depth_buffer ), PSP_FB_BWIDTH);
|
||||
|
||||
// Set the rendering offset and viewport.
|
||||
sceGuOffset( 2048 - ( PSP_FB_WIDTH / 2 ), 2048 - ( PSP_FB_HEIGHT / 2 ) );
|
||||
sceGuViewport( 2048, 2048, PSP_FB_WIDTH, PSP_FB_HEIGHT );
|
||||
|
||||
// Set up scissoring.
|
||||
sceGuEnable( GU_SCISSOR_TEST );
|
||||
sceGuScissor( 0, 0, PSP_FB_WIDTH, PSP_FB_HEIGHT );
|
||||
|
||||
// Set up texturing.
|
||||
sceGuEnable( GU_TEXTURE_2D );
|
||||
|
||||
// Set up clearing.
|
||||
sceGuClearDepth( 65535 );
|
||||
sceGuClearColor( GU_RGBA( 0x10, 0x20, 0x40, 0xff ) );
|
||||
|
||||
// Set up depth.
|
||||
sceGuDepthOffset( 0 );
|
||||
sceGuDepthRange( 0, 65535 );
|
||||
sceGuDepthFunc( GU_LEQUAL );
|
||||
sceGuEnable( GU_DEPTH_TEST );
|
||||
|
||||
// Set up fog
|
||||
// sceGuFog( 100.0f, 500.0f, 0xffffffff );
|
||||
// sceGuDisable( GU_FOG );
|
||||
|
||||
// Set the default matrices.
|
||||
sceGumMatrixMode( GU_PROJECTION );
|
||||
sceGumLoadIdentity();
|
||||
sceGumMatrixMode( GU_VIEW );
|
||||
sceGumLoadIdentity();
|
||||
sceGumMatrixMode( GU_MODEL );
|
||||
sceGumLoadIdentity();
|
||||
sceGumMatrixMode( GU_TEXTURE );
|
||||
sceGumLoadIdentity();
|
||||
|
||||
sceGumUpdateMatrix();
|
||||
|
||||
// Set up culling.
|
||||
sceGuFrontFace( GU_CW );
|
||||
sceGuEnable( GU_CULL_FACE );
|
||||
sceGuEnable( GU_CLIP_PLANES );
|
||||
|
||||
// Set up blending.
|
||||
sceGuBlendFunc( GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
|
||||
|
||||
sceGuFinish();
|
||||
sceGuSync( GU_SYNC_FINISH, GU_SYNC_WHAT_DONE );
|
||||
|
||||
// Turn on the display.
|
||||
sceDisplayWaitVblankStart();
|
||||
sceGuDisplay(GU_TRUE);
|
||||
|
||||
// Start a new render.
|
||||
sceGuStart( GU_DIRECT, vid_psp.gu_list );
|
||||
|
||||
Con_Printf( "Vram available: %i\n", vmemavail() );
|
||||
}
|
||||
|
||||
_inline void GU_Shutdown( void )
|
||||
{
|
||||
// Finish rendering.
|
||||
sceGuFinish();
|
||||
sceGuSync( GU_SYNC_FINISH, GU_SYNC_WHAT_DONE );
|
||||
|
||||
// Shut down the display.
|
||||
sceGuTerm();
|
||||
|
||||
// Free the buffers.
|
||||
vfree( vid_psp.draw_buffer );
|
||||
vid_psp.draw_buffer = NULL;
|
||||
vfree( vid_psp.disp_buffer );
|
||||
vid_psp.disp_buffer = NULL;
|
||||
vfree( vid_psp.depth_buffer );
|
||||
vid_psp.depth_buffer = NULL;
|
||||
#if !PSP_GU_STATIC_LIST
|
||||
vfree( vid_psp.gu_list );
|
||||
vid_psp.gu_list = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
_inline void GU_SwapBuffers( void )
|
||||
{
|
||||
/*
|
||||
// Don't forget writeback the cache
|
||||
sceKernelDcacheWritebackAll();
|
||||
*/
|
||||
// Finish rendering.
|
||||
size_t list_size = sceGuFinish();
|
||||
/*
|
||||
if( list_size > sizeof( gu_list ) - 1000 )
|
||||
printf( "Display list size (%i) %i!\n", list_size, sizeof( gu_list ) );
|
||||
*/
|
||||
sceGuSync( GU_SYNC_FINISH, GU_SYNC_WHAT_DONE );
|
||||
|
||||
if ( vsync )
|
||||
{
|
||||
sceDisplayWaitVblankStart();
|
||||
}
|
||||
|
||||
// Swap the buffers.
|
||||
sceGuSwapBuffers();
|
||||
|
||||
void* p_swap = vid_psp.disp_buffer;
|
||||
vid_psp.disp_buffer = vid_psp.draw_buffer;
|
||||
vid_psp.draw_buffer = p_swap;
|
||||
|
||||
// Start a new render.
|
||||
sceGuStart( GU_DIRECT, vid_psp.gu_list );
|
||||
}
|
||||
|
||||
int R_MaxVideoModes( void )
|
||||
{
|
||||
return num_vidmodes;
|
||||
@@ -384,7 +223,7 @@ static qboolean VID_SetScreenResolution( int width, int height )
|
||||
|
||||
void GL_SwapBuffers( void )
|
||||
{
|
||||
GU_SwapBuffers();
|
||||
if ( vsync ) sceDisplayWaitVblankStart();
|
||||
}
|
||||
|
||||
int GL_SetAttribute( int attr, int val )
|
||||
@@ -435,7 +274,6 @@ qboolean R_Init_Video( const int type )
|
||||
case REF_GL:
|
||||
// refdll also can check extensions
|
||||
ref.dllFuncs.GL_InitExtensions();
|
||||
GU_Init();
|
||||
break;
|
||||
case REF_SOFTWARE:
|
||||
default:
|
||||
@@ -530,8 +368,16 @@ void R_Free_Video( void )
|
||||
R_FreeVideoModes();
|
||||
#endif
|
||||
ref.dllFuncs.GL_ClearExtensions();
|
||||
if( !glw_state.software )
|
||||
GU_Shutdown();
|
||||
if( glw_state.software )
|
||||
{
|
||||
if( vid_psp.draw_buffer )
|
||||
free( vid_psp.draw_buffer );
|
||||
if( vid_psp.disp_buffer )
|
||||
free( vid_psp.disp_buffer );
|
||||
|
||||
vid_psp.draw_buffer = NULL;
|
||||
vid_psp.disp_buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // XASH_DEDICATED
|
||||
|
||||
@@ -15,7 +15,6 @@ GNU General Public License for more details.
|
||||
*/
|
||||
#include <malloc.h>
|
||||
#include <pspsuspend.h>
|
||||
#include "vram_psp.h"
|
||||
#include "gu_local.h"
|
||||
#include "crclib.h"
|
||||
|
||||
@@ -251,26 +250,28 @@ GL_SetTextureDimensions
|
||||
*/
|
||||
static void GL_SetTextureDimensions( gl_texture_t *tex, int width, int height )
|
||||
{
|
||||
int maxTextureSize;
|
||||
int stepWidth, stepHeight;
|
||||
int maxTextureSize = glConfig.max_texture_size;
|
||||
int step = (int)gl_round_down->value;
|
||||
int scaled_width, scaled_height;
|
||||
|
||||
Assert( tex != NULL );
|
||||
|
||||
maxTextureSize = glConfig.max_texture_size;
|
||||
|
||||
// store original sizes
|
||||
tex->srcWidth = width;
|
||||
tex->srcHeight = height;
|
||||
|
||||
#if 0 // scale up
|
||||
stepWidth = ( int )ceilf( logf( width ) * 1.0f / logf( 2.0f ) );
|
||||
stepHeight = ( int )ceilf( logf( height ) * 1.0f / logf( 2.0f ) );
|
||||
#else // scale down
|
||||
stepWidth = ( int )floorf( logf( width ) * 1.0f / logf( 2.0f ) );
|
||||
stepHeight = ( int )floorf( logf( height ) * 1.0f / logf( 2.0f ) );
|
||||
#endif
|
||||
width = ( 1 << stepWidth );
|
||||
height = ( 1 << stepHeight );
|
||||
for( scaled_width = 1; scaled_width < width; scaled_width <<= 1 );
|
||||
|
||||
if( step > 0 && width < scaled_width && ( step == 1 || ( scaled_width - width ) > ( scaled_width >> step ) ) )
|
||||
scaled_width >>= 1;
|
||||
|
||||
for( scaled_height = 1; scaled_height < height; scaled_height <<= 1 );
|
||||
|
||||
if( step > 0 && height < scaled_height && ( step == 1 || ( scaled_height - height ) > ( scaled_height >> step ) ) )
|
||||
scaled_height >>= 1;
|
||||
|
||||
width = scaled_width;
|
||||
height = scaled_height;
|
||||
|
||||
if( width > maxTextureSize || height > maxTextureSize )
|
||||
{
|
||||
|
||||
@@ -16,11 +16,12 @@ GNU General Public License for more details.
|
||||
|
||||
#ifndef GL_LOCAL_H
|
||||
#define GL_LOCAL_H
|
||||
#if 1
|
||||
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspgu.h>
|
||||
#include <pspgum.h>
|
||||
#endif
|
||||
|
||||
#include "port.h"
|
||||
#include "xash3d_types.h"
|
||||
#include "cvardef.h"
|
||||
@@ -40,6 +41,7 @@ GNU General Public License for more details.
|
||||
//#include "cvar.h"
|
||||
#include "gu_helper.h"
|
||||
#include "gu_extension.h"
|
||||
#include "gu_vram.h"
|
||||
#include "wadfile.h"
|
||||
|
||||
#ifndef offsetof
|
||||
@@ -686,18 +688,7 @@ void GU_Clip( gu_vert_t *uv, size_t uvc, gu_vert_t **cv, size_t* cvc );
|
||||
typedef struct
|
||||
{
|
||||
int max_texture_size;
|
||||
int color_bits;
|
||||
int alpha_bits;
|
||||
int depth_bits;
|
||||
int stencil_bits;
|
||||
|
||||
gl_context_type_t context;
|
||||
gles_wrapper_t wrapper;
|
||||
|
||||
qboolean softwareGammaUpdate;
|
||||
qboolean fCustomRenderer;
|
||||
int prev_width;
|
||||
int prev_height;
|
||||
} glconfig_t;
|
||||
|
||||
typedef struct
|
||||
@@ -727,8 +718,23 @@ typedef struct
|
||||
qboolean extended; // extended context allows to GL_Debug
|
||||
} glwstate_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int screen_width;
|
||||
int screen_height;
|
||||
int buffer_width;
|
||||
int buffer_format;
|
||||
int buffer_bpp;
|
||||
void *draw_buffer;
|
||||
void *disp_buffer;
|
||||
void *depth_buffer;
|
||||
void *context_list;
|
||||
size_t context_list_size;
|
||||
}gurender_t;
|
||||
|
||||
extern glconfig_t glConfig;
|
||||
extern glstate_t glState;
|
||||
extern gurender_t guRender;
|
||||
// move to engine
|
||||
extern glwstate_t glw_state;
|
||||
extern ref_api_t gEngfuncs;
|
||||
@@ -751,11 +757,9 @@ extern cvar_t *gl_round_down;
|
||||
extern cvar_t *gl_detailscale;
|
||||
extern cvar_t *gl_wireframe;
|
||||
extern cvar_t *gl_depthoffset;
|
||||
extern cvar_t *gl_finish;
|
||||
extern cvar_t *gl_nosort;
|
||||
extern cvar_t *gl_clear;
|
||||
extern cvar_t *gl_test; // cvar to testify new effects
|
||||
extern cvar_t *gl_stencilbits;
|
||||
extern cvar_t *gl_subdivide_size;
|
||||
|
||||
extern cvar_t *r_speeds;
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
/*
|
||||
gu_render.c - render initialization
|
||||
Copyright (C) 2010 Uncle Mike
|
||||
Copyright (C) 2022 Sergey Galushko
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
#include "gu_local.h"
|
||||
|
||||
cvar_t *gl_texture_lodfunc;
|
||||
@@ -12,12 +26,10 @@ cvar_t *gl_emboss_scale;
|
||||
cvar_t *gl_detailscale;
|
||||
cvar_t *gl_depthoffset;
|
||||
cvar_t *gl_wireframe;
|
||||
cvar_t *gl_finish;
|
||||
cvar_t *gl_nosort;
|
||||
cvar_t *gl_vsync;
|
||||
cvar_t *gl_clear;
|
||||
cvar_t *gl_test;
|
||||
cvar_t *gl_stencilbits;
|
||||
cvar_t *gl_subdivide_size;
|
||||
cvar_t *r_speeds;
|
||||
cvar_t *r_fullbright;
|
||||
@@ -54,6 +66,155 @@ gl_globals_t tr;
|
||||
glconfig_t glConfig;
|
||||
glstate_t glState;
|
||||
glwstate_t glw_state;
|
||||
gurender_t guRender;
|
||||
|
||||
// Set frame buffer
|
||||
#define PSP_FB_WIDTH 480
|
||||
#define PSP_FB_HEIGHT 272
|
||||
#define PSP_FB_BWIDTH 512
|
||||
#define PSP_FB_FORMAT GU_PSM_5650 //4444,5551,5650,8888
|
||||
|
||||
#if PSP_FB_FORMAT == GU_PSM_4444
|
||||
#define PSP_FB_BPP 2
|
||||
#elif PSP_FB_FORMAT == GU_PSM_5551
|
||||
#define PSP_FB_BPP 2
|
||||
#elif PSP_FB_FORMAT == GU_PSM_5650
|
||||
#define PSP_FB_BPP 2
|
||||
#elif PSP_FB_FORMAT == GU_PSM_8888
|
||||
#define PSP_FB_BPP 4
|
||||
#endif
|
||||
|
||||
#define PSP_GU_LIST_SIZE 0x100000 // 1Mb
|
||||
|
||||
static byte context_list[PSP_GU_LIST_SIZE] __attribute__( ( aligned( 64 ) ) );
|
||||
|
||||
/*
|
||||
===============
|
||||
GU_Init
|
||||
===============
|
||||
*/
|
||||
static void GU_Init( void )
|
||||
{
|
||||
memset( &guRender, 0, sizeof( guRender ));
|
||||
|
||||
guRender.screen_width = PSP_FB_WIDTH;
|
||||
guRender.screen_height = PSP_FB_HEIGHT;
|
||||
guRender.buffer_width = PSP_FB_BWIDTH;
|
||||
guRender.buffer_format = PSP_FB_FORMAT;
|
||||
guRender.buffer_bpp = PSP_FB_BPP;
|
||||
|
||||
guRender.draw_buffer = ( void* )valloc( guRender.buffer_width * guRender.screen_height * guRender.buffer_bpp );
|
||||
if( !guRender.draw_buffer )
|
||||
gEngfuncs.Host_Error( "Memory allocation failled! (guRender.draw_buffer)\n" );
|
||||
|
||||
guRender.disp_buffer = ( void* )valloc( guRender.buffer_width * guRender.screen_height * guRender.buffer_bpp );
|
||||
if( !guRender.disp_buffer )
|
||||
gEngfuncs.Host_Error( "Memory allocation failled! (guRender.disp_buffer)\n" );
|
||||
|
||||
guRender.depth_buffer = ( void* )valloc( guRender.buffer_width * guRender.screen_height * guRender.buffer_bpp );
|
||||
if( !guRender.depth_buffer )
|
||||
gEngfuncs.Host_Error( "Memory allocation failled! (guRender.depth_buffer)\n" );
|
||||
|
||||
guRender.context_list = context_list;
|
||||
guRender.context_list_size = sizeof( context_list );
|
||||
|
||||
// Initialise the GU.
|
||||
sceGuInit();
|
||||
|
||||
// Set up the GU.
|
||||
sceGuStart( GU_DIRECT, guRender.context_list );
|
||||
|
||||
sceGuDrawBuffer( guRender.buffer_format, vrelptr( guRender.draw_buffer ), guRender.buffer_width );
|
||||
sceGuDispBuffer( guRender.screen_width, guRender.screen_height, vrelptr( guRender.disp_buffer ), guRender.buffer_width );
|
||||
sceGuDepthBuffer( vrelptr( guRender.depth_buffer ), guRender.buffer_width );
|
||||
|
||||
// Set the rendering offset and viewport.
|
||||
sceGuOffset( 2048 - ( guRender.screen_width / 2 ), 2048 - ( guRender.screen_height / 2 ) );
|
||||
sceGuViewport( 2048, 2048, guRender.screen_width, guRender.screen_height );
|
||||
|
||||
// Set up scissoring.
|
||||
sceGuEnable( GU_SCISSOR_TEST );
|
||||
sceGuScissor( 0, 0, guRender.screen_width, guRender.screen_height );
|
||||
|
||||
// Xash default
|
||||
sceGuClearColor( GU_COLOR( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
||||
|
||||
sceGuDisable( GU_DEPTH_TEST );
|
||||
sceGuDisable( GU_CULL_FACE );
|
||||
sceGuEnable( GU_CLIP_PLANES );
|
||||
sceGuDepthFunc( GU_LEQUAL );
|
||||
sceGuColor( 0xffffffff );
|
||||
|
||||
// Set up stencil
|
||||
if( glState.stencilEnabled )
|
||||
{
|
||||
sceGuDisable( GU_STENCIL_TEST );
|
||||
/*pglStencilMask( ( GLuint ) ~0 );*/ // alpha color sceGuPixelMask
|
||||
sceGuStencilFunc( GU_EQUAL, 0, ~0 );
|
||||
sceGuStencilOp( GU_KEEP, GU_INCR, GU_INCR );
|
||||
}
|
||||
|
||||
sceGuDepthRange( 0, 65535 );
|
||||
sceGuDepthOffset( 0 );
|
||||
|
||||
sceGuDisable( GU_BLEND );
|
||||
sceGuDisable( GU_ALPHA_TEST );
|
||||
|
||||
sceGuBlendFunc( GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
|
||||
sceGuAlphaFunc( GU_GREATER, DEFAULT_ALPHATEST, 0xff );
|
||||
sceGuEnable( GU_TEXTURE_2D );
|
||||
sceGuShadeModel( GU_SMOOTH );
|
||||
sceGuFrontFace( GU_CW ); // reversed
|
||||
|
||||
// Set the default matrices.
|
||||
sceGumMatrixMode( GU_PROJECTION );
|
||||
sceGumLoadIdentity();
|
||||
sceGumMatrixMode( GU_VIEW );
|
||||
sceGumLoadIdentity();
|
||||
sceGumMatrixMode( GU_MODEL );
|
||||
sceGumLoadIdentity();
|
||||
sceGumMatrixMode( GU_TEXTURE );
|
||||
sceGumLoadIdentity();
|
||||
|
||||
sceGumUpdateMatrix();
|
||||
|
||||
sceGuFinish();
|
||||
sceGuSync( GU_SYNC_FINISH, GU_SYNC_WAIT );
|
||||
|
||||
// Turn on the display.
|
||||
sceDisplayWaitVblankStart();
|
||||
sceGuDisplay(GU_TRUE);
|
||||
|
||||
// Start a new render.
|
||||
sceGuStart( GU_DIRECT, guRender.context_list );
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
GU_Shutdown
|
||||
===============
|
||||
*/
|
||||
static void GU_Shutdown( void )
|
||||
{
|
||||
// Finish rendering.
|
||||
sceGuFinish();
|
||||
sceGuSync( GU_SYNC_FINISH, GU_SYNC_WAIT );
|
||||
|
||||
// Shut down the display.
|
||||
sceGuTerm();
|
||||
|
||||
// Free the buffers.
|
||||
if( guRender.draw_buffer )
|
||||
vfree( guRender.draw_buffer );
|
||||
if( guRender.disp_buffer )
|
||||
vfree( guRender.disp_buffer );
|
||||
if( guRender.depth_buffer )
|
||||
vfree( guRender.depth_buffer );
|
||||
|
||||
guRender.draw_buffer = NULL;
|
||||
guRender.disp_buffer = NULL;
|
||||
guRender.depth_buffer = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
@@ -88,46 +249,14 @@ static void GL_SetDefaultState( void )
|
||||
glState.fogStart = 100.0f;
|
||||
glState.fogEnd = 1000.0f;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
===============
|
||||
GL_SetDefaults
|
||||
===============
|
||||
*/
|
||||
static void GL_SetDefaults( void )
|
||||
static void GU_SetDefaults( void )
|
||||
{
|
||||
#if 1
|
||||
/*
|
||||
sceGuFinish();
|
||||
sceGuSync(0,0);
|
||||
*/
|
||||
sceGuClearColor( GU_COLOR( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
||||
|
||||
sceGuDisable( GU_DEPTH_TEST );
|
||||
sceGuDisable( GU_CULL_FACE );
|
||||
//sceGuDisable( GU_SCISSOR_TEST );
|
||||
sceGuDepthFunc( GU_LEQUAL );
|
||||
sceGuColor( 0xffffffff );
|
||||
|
||||
if( glState.stencilEnabled )
|
||||
{
|
||||
sceGuDisable( GU_STENCIL_TEST );
|
||||
/*pglStencilMask( ( GLuint ) ~0 );*/
|
||||
sceGuStencilFunc( GU_EQUAL, 0, ~0 );
|
||||
sceGuStencilOp( GU_KEEP, GU_INCR, GU_INCR );
|
||||
}
|
||||
sceGuDepthOffset( 0 );
|
||||
|
||||
GL_CleanupAllTextureUnits();
|
||||
|
||||
sceGuDisable( GU_BLEND );
|
||||
sceGuDisable( GU_ALPHA_TEST );
|
||||
|
||||
sceGuAlphaFunc( GU_GREATER, DEFAULT_ALPHATEST, 0xff );
|
||||
sceGuEnable( GU_TEXTURE_2D );
|
||||
sceGuShadeModel( GU_SMOOTH );
|
||||
sceGuFrontFace( GU_CCW );
|
||||
#else
|
||||
pglFinish();
|
||||
|
||||
pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f );
|
||||
@@ -161,10 +290,10 @@ static void GL_SetDefaults( void )
|
||||
|
||||
pglPointSize( 1.2f );
|
||||
pglLineWidth( 1.2f );
|
||||
#endif
|
||||
|
||||
GL_Cull( GL_NONE );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================
|
||||
@@ -178,17 +307,11 @@ void R_RenderInfo_f( void )
|
||||
gEngfuncs.Con_Printf( "MAX_TEXTURE_SIZE: %i\n", glConfig.max_texture_size );
|
||||
gEngfuncs.Con_Printf( "MODE: %ix%i\n", gpGlobals->width, gpGlobals->height );
|
||||
gEngfuncs.Con_Printf( "VERTICAL SYNC: %s\n", gl_vsync->value ? "enabled" : "disabled" );
|
||||
gEngfuncs.Con_Printf( "Color %d bits, Alpha %d bits, Depth %d bits, Stencil %d bits\n", glConfig.color_bits,
|
||||
glConfig.alpha_bits, glConfig.depth_bits, glConfig.stencil_bits );
|
||||
gEngfuncs.Con_Printf( "VRAM AVAILABLE: %i\n", vmemavail() );
|
||||
}
|
||||
|
||||
void GL_InitExtensions( void )
|
||||
{
|
||||
// int colorBits[3];
|
||||
|
||||
glConfig.color_bits = 5 + 5 + 5;
|
||||
glConfig.alpha_bits = 1;
|
||||
glConfig.stencil_bits = ( int )gl_stencilbits->value;
|
||||
glState.stencilEnabled = true;
|
||||
glConfig.max_texture_size = 256;
|
||||
|
||||
@@ -248,14 +371,12 @@ void GL_InitCommands( void )
|
||||
gl_keeptjunctions = gEngfuncs.Cvar_Get( "gl_keeptjunctions", "1", FCVAR_GLCONFIG, "removing tjuncs causes blinking pixels" );
|
||||
gl_emboss_scale = gEngfuncs.Cvar_Get( "gl_emboss_scale", "0", FCVAR_GLCONFIG|FCVAR_LATCH, "fake bumpmapping scale" );
|
||||
gl_showtextures = gEngfuncs.pfnGetCvarPointer( "r_showtextures", 0 );
|
||||
gl_finish = gEngfuncs.Cvar_Get( "gl_finish", "0", FCVAR_GLCONFIG, "use glFinish instead of glFlush" );
|
||||
gl_nosort = gEngfuncs.Cvar_Get( "gl_nosort", "1", FCVAR_GLCONFIG, "disable sorting of translucent surfaces" );
|
||||
gl_clear = gEngfuncs.pfnGetCvarPointer( "gl_clear", 0 );
|
||||
gl_test = gEngfuncs.Cvar_Get( "gl_test", "0", 0, "engine developer cvar for quick testing new features" );
|
||||
gl_wireframe = gEngfuncs.Cvar_Get( "gl_wireframe", "0", FCVAR_GLCONFIG|FCVAR_SPONLY, "show wireframe overlay" );
|
||||
gl_stencilbits = gEngfuncs.Cvar_Get( "gl_stencilbits", "8", FCVAR_GLCONFIG|FCVAR_READ_ONLY, "pixelformat stencil bits (0 - auto)" );
|
||||
gl_subdivide_size = gEngfuncs.Cvar_Get( "gl_subdivide_size", "256.0", FCVAR_GLCONFIG, "the division value for the sky brushes" );
|
||||
gl_round_down = gEngfuncs.Cvar_Get( "gl_round_down", "2", FCVAR_GLCONFIG|FCVAR_READ_ONLY, "round texture sizes to nearest POT value" );
|
||||
gl_round_down = gEngfuncs.Cvar_Get( "gl_round_down", "1", FCVAR_GLCONFIG, "round texture sizes to nearest POT value" );
|
||||
// these cvar not used by engine but some mods requires this
|
||||
gl_depthoffset = gEngfuncs.Cvar_Get( "gl_depthoffset", "256.0", FCVAR_GLCONFIG, "depth offset for decals" );
|
||||
|
||||
@@ -313,7 +434,7 @@ qboolean R_Init( void )
|
||||
|
||||
r_temppool = Mem_AllocPool( "Render Zone" );
|
||||
|
||||
GL_SetDefaults();
|
||||
GU_Init();
|
||||
R_InitImages();
|
||||
R_SpriteInit();
|
||||
R_StudioInit();
|
||||
@@ -336,6 +457,7 @@ void R_Shutdown( void )
|
||||
|
||||
GL_RemoveCommands();
|
||||
R_ShutdownImages();
|
||||
GU_Shutdown();
|
||||
|
||||
Mem_FreePool( &r_temppool );
|
||||
|
||||
@@ -1091,11 +1091,7 @@ void R_BeginFrame( qboolean clearScene )
|
||||
if(( gl_clear->value || ENGINE_GET_PARM( PARM_DEV_OVERVIEW )) &&
|
||||
clearScene && ENGINE_GET_PARM( PARM_CONNSTATE ) != ca_cinematic )
|
||||
{
|
||||
#if 1
|
||||
sceGuClear( GU_COLOR_BUFFER_BIT );
|
||||
#else
|
||||
pglClear( GL_COLOR_BUFFER_BIT );
|
||||
#endif
|
||||
}
|
||||
|
||||
R_CheckGamma();
|
||||
@@ -1157,10 +1153,6 @@ void R_RenderFrame( const ref_viewpass_t *rvp )
|
||||
|
||||
// setup the initial render params
|
||||
R_SetupRefParams( rvp );
|
||||
#if 0
|
||||
if( gl_finish->value && RI.drawWorld )
|
||||
pglFinish();
|
||||
#endif
|
||||
|
||||
// completely override rendering
|
||||
if( gEngfuncs.drawFuncs->GL_RenderFrame != NULL )
|
||||
@@ -1195,7 +1187,22 @@ void R_EndFrame( void )
|
||||
{
|
||||
// flush any remaining 2D bits
|
||||
R_Set2DMode( false );
|
||||
gEngfuncs.GL_SwapBuffers();
|
||||
|
||||
// finish rendering.
|
||||
sceGuFinish();
|
||||
sceGuSync( GU_SYNC_FINISH, GU_SYNC_WAIT );
|
||||
|
||||
// swap the buffers.
|
||||
sceGuSwapBuffers();
|
||||
|
||||
void* p_swap = guRender.disp_buffer;
|
||||
guRender.disp_buffer = guRender.draw_buffer;
|
||||
guRender.draw_buffer = p_swap;
|
||||
|
||||
gEngfuncs.GL_SwapBuffers(); // vsync
|
||||
|
||||
// start a new render.
|
||||
sceGuStart( GU_DIRECT, guRender.context_list );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||
* http://wordpress.fx-world.org
|
||||
*/
|
||||
#include "vram.h"
|
||||
#include "gu_vram.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// Configure the memory to be managed
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||
* -----------------------------------------------------------------------
|
||||
* Licensed as 'free to use and modify as long as credited appropriately'
|
||||
*
|
||||
* vram.h - Standard C high performance VRAM allocation routines.
|
||||
*
|
||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||
* http://wordpress.fx-world.org
|
||||
*/
|
||||
#ifndef vram_h__
|
||||
#define vram_h__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void* vrelptr( void *ptr ); // make a pointer relative to memory base address (ATTENTION: A NULL rel ptr is not illegal/invalid!)
|
||||
void* vabsptr( void *ptr ); // make a pointer absolute (default return type of valloc)
|
||||
|
||||
void* valloc( size_t size );
|
||||
void vfree( void* ptr );
|
||||
size_t vmemavail();
|
||||
size_t vlargestblock();
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Debug printf (to stdout) a trace of the current Memblocks
|
||||
void __memwalk();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ifdef vram_h__
|
||||
Reference in New Issue
Block a user