(PS3) Committed RGL v2 - PS3 build should now compile again

This commit is contained in:
twinaphex 2012-11-06 09:23:20 +01:00
parent 330e724f34
commit 5580c201b1
66 changed files with 27091 additions and 16149 deletions

View File

@ -1,10 +1,10 @@
#which compiler to build with - GCC or SNC
#set to GCC for debug builds for use with debugger
CELL_BUILD_TOOLS = SNC
CELL_BUILD_TOOLS = GCC
CELL_GPU_TYPE = RSX
DEBUG = 0
STRIPPING_ENABLE = 0
STRIPPING_ENABLE = 1
PC_DEVELOPMENT_IP_ADDRESS = "192.168.1.7"
PC_DEVELOPMENT_UDP_PORT = 3490
@ -15,12 +15,19 @@ include $(CELL_MK_DIR)/sdk.makedef.mk
PPU_LIB_TARGET = librgl_ps3.a
LDDIRS = -L.
INCDIRS = -I.
INCDIRS = -I. -Iconsole/rgl/include
RGL_DIR = console/rgl/src
PPU_SRCS = $(RGL_DIR)/Utils/NameSpace.cpp \
$(RGL_DIR)/Utils/TexNameSpace.cpp \
$(RGL_DIR)/Utils/EnumMap.cpp \
$(RGL_DIR)/libelf/readelf.cpp \
$(RGL_DIR)/rgl.cpp \
$(RGL_DIR)/rgl_cg.cpp \
$(RGL_DIR)/ps3/rgl_ps3.cpp \
$(RGL_DIR)/ps3/rgl_ps3_raster.cpp
PPU_SRCS = console/rgl/ps3/device_ctx.cpp \
console/rgl/ps3/rgl.cpp \
console/rgl/ps3/cgbio.cpp \
console/rgl/ps3/cgnv2rt.cpp
ifeq ($(CELL_BUILD_TOOLS), SNC)
PPU_CXXLD = $(CELL_SDK)/host-win32/sn/bin/ps3ppuld.exe
@ -37,9 +44,9 @@ endif
PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe
PPU_LDLIBS = -lio_stub
PPU_LDLIBS = -lio_stub
DEFINES += -D__CELLOS_LV2__
DEFINES += -D__CELLOS_LV2__ -DJS_PLATFORM_CELL
ifeq ($(DEBUG), 1)
PPU_OPTIMIZE_LV := -O0 -g

View File

@ -1,63 +0,0 @@
#which compiler to build with - GCC or SNC
#set to GCC for debug builds for use with debugger
CELL_BUILD_TOOLS = GCC
CELL_GPU_TYPE = RSX
DEBUG = 0
STRIPPING_ENABLE = 0
PC_DEVELOPMENT_IP_ADDRESS = "192.168.1.7"
PC_DEVELOPMENT_UDP_PORT = 3490
CELL_MK_DIR ?= $(CELL_SDK)/samples/mk
include $(CELL_MK_DIR)/sdk.makedef.mk
PPU_LIB_TARGET = librgl_ps3.a
LDDIRS = -L.
INCDIRS = -I. -Iconsole/rglv2/include
RGL_DIR = console/rglv2/src
PPU_SRCS = $(RGL_DIR)/Utils/Log.cpp \
$(RGL_DIR)/Utils/NameSpace.cpp \
$(RGL_DIR)/Utils/TexNameSpace.cpp \
$(RGL_DIR)/Utils/Report.cpp \
$(RGL_DIR)/Utils/EnumMap.cpp \
$(RGL_DIR)/Utils/rbtree.cpp \
$(RGL_DIR)/libelf/readelf.cpp \
$(RGL_DIR)/rgl.cpp \
$(RGL_DIR)/rgl_cg.cpp \
$(RGL_DIR)/ps3/rgl_ps3.cpp \
$(RGL_DIR)/ps3/rgl_ps3_raster.cpp
ifeq ($(CELL_BUILD_TOOLS), SNC)
PPU_CXXLD = $(CELL_SDK)/host-win32/sn/bin/ps3ppuld.exe
PPU_CXX = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
PPU_CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
SNC_PPU_AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
else
PPU_CXX = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-g++.exe
PPU_CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe
PPU_CXXLD = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ld.exe
PPU_AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
endif
PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe
PPU_LDLIBS = -lio_stub
DEFINES += -D__CELLOS_LV2__ -DJS_PLATFORM_CELL -DJS_LIBRARY_VERSION=\"2.00\" -DJS_LIBRARY_VERSION_NUMBER=200
ifeq ($(DEBUG), 1)
PPU_OPTIMIZE_LV := -O0 -g
else
PPU_OPTIMIZE_LV := -O3
endif
PPU_CFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES)
PPU_CXXFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES)
include $(CELL_MK_DIR)/sdk.target.mk

View File

@ -0,0 +1,569 @@
#ifndef _cg_common_h
#define _cg_common_h
#include <Cg/cg.h>
#include "../export/RGL/rgl.h"
#include "../RGL/private.h"
#include <vector>
#include <string>
#include "Cg/CgInternal.h"
#include "Cg/CgProgramGroup.h"
// [YLIN]
#include <string.h> // for memcpy16
#if (CELL_SDK_VERSION<=0x210001)
using _CSTD memcpy16; // fixed at SDK 220
#endif // (CELL_SDK_VERSION<=0x210001)
#ifdef __cplusplus
extern "C"
{
#endif
#define RGL_MAX_VP_SHARED_CONSTANTS 256
#define RGL_MAX_FP_SHARED_CONSTANTS 1024
#define RGL_BOOLEAN_REGISTERS_COUNT 32
// parameter setter, prototype of functions called when a uniform is set.
typedef void( *_cgSetFunction )( struct CgRuntimeParameter* _RGL_RESTRICT, const void* _RGL_RESTRICT );
typedef void( *_cgSetArrayIndexFunction )( struct CgRuntimeParameter* _RGL_RESTRICT, const void* _RGL_RESTRICT, const int index );
typedef struct _CgUniform
{
void *pushBufferPtr;
}
_CgUniform;
typedef struct _CGprogram _CGprogram;
typedef struct CgRuntimeParameter
{
// sampler
_cgSetArrayIndexFunction samplerSetter;
/*cgSetFunction*/
//vector
_cgSetArrayIndexFunction setterIndex;
// matrices
_cgSetArrayIndexFunction settercIndex;
_cgSetArrayIndexFunction setterrIndex;
void *pushBufferPointer;
const CgParameterEntry *parameterEntry;
_CGprogram *program;
int glType; //tmp...
CGparameter id;//tmp
}
CgRuntimeParameter;
typedef struct
{
CgRuntimeParameter* child;
CgRuntimeParameter* parent;
CgRuntimeParameter* top;
_cgSetArrayIndexFunction childOnBindSetter;
}
CgParameterConnection;
typedef struct
{
CgRuntimeParameter* param;
std::vector<char> semantic;
}
CgRuntimeSemantic;
struct _CGprogram
{
struct _CGprogram* next; // link to next in NULL-terminated singly linked list of programs
CGprogram id; // numerical id for this program object
struct _CGcontext* parentContext; // parent context for this program
void* parentEffect; // parent effect for this program (only used for default program of an effect, containing effect parameters)
bool inLocalMemory; // only pertains to fragment programs which can be in location local, the default, or location main via cgb interfaces
// parameters in the CG_PROGRAM namespace
unsigned int constantPushBufferWordSize;
unsigned int* constantPushBuffer;
unsigned int lastConstantUpdate;
// executable program image
void* platformProgram;
// entire binary program image from compiler
void* platformProgramBinary;
// extra information to ease the coding of the rgl runtime
// the following are used to know which parameters are samplers, so that we can walk them in a quick way.
unsigned int samplerCount;
unsigned int * samplerIndices;
unsigned int * samplerUnits;
unsigned int controlFlowBools;
//binary format additions
//info previously contained in platformProgram ( loadAddress + nvBinary )
CgProgramHeader header;
const char *name;
const void *ucode;
GLuint loadProgramId;
// offset into the allocation id above, normally zero for internal use.
// But for psglSetFragmentProgramConfiguration it's possible for
// users to manage sub-heap in allocation and put multiple
// program in each allocation.
GLuint loadProgramOffset;
int version; //contained a boolean indicating if the structure pointers have been patched or not
char *parameterResources;
int rtParametersCount;
CgRuntimeParameter *runtimeParameters;
const CgParameterEntry *parametersEntries;
unsigned short *resources;
unsigned short *pushBufferPointers;
int defaultValuesIndexCount;
const CgParameterDefaultValue *defaultValuesIndices;
int semanticCount;
const CgParameterSemantic *semanticIndices;
int defaultValueCount;
const float *defaultValues;
const char *stringTable;
unsigned int **constantPushBufferPointers;
//tmp
unsigned int *samplerValuesLocation;
void *memoryBlock;
_CGprogramGroup *programGroup;
int programIndexInGroup;
// supports runtime created parameters
std::vector<CgRuntimeParameter*> runtimeCreatedParameters;
// supports parameter connections
std::vector<CgParameterConnection> connectionTable;
// supports runtime allocation of semantics
std::vector<CgRuntimeSemantic> parameterSemantics;
//runtime compilation / conversion
void *runtimeElf;
};
typedef struct _CGcontext
{
struct _CGcontext* next; // for global linked list of CGcontexts
CGcontext id; // numerical handle for this object
unsigned int programCount; // number of programs in the list
struct _CGprogram* programList; // head of singly linked list of programs
CGenum compileType; // compile manual, immediate or lazy (unused so far)
// implementation data for GL
CGbool GLmanageTextures;
unsigned int controlFlowBoolsSharedMask;
unsigned int controlFlowBoolsShared;
// default program, fake owner of the context parameters
_CGprogram defaultProgram;
//groups
CGprogramGroup groupList;
//"static" variable used to store the values of the last parameter for which getParameterValue has been called
double currentParameterValue[16];
char currentParameterName[128];
}
_CGcontext;
// prototypes --------------------------------
// internal error handling
RGL_EXPORT void rglCgRaiseError( CGerror error );
// interface between object types
extern void rglCgProgramDestroyAll( _CGcontext* c );
extern void rglCgDestroyContextParam( CgRuntimeParameter* p );
RGL_EXPORT CgRuntimeParameter*rglCgCreateParameterInternal( _CGprogram *program, const char* name, CGtype type );
RGL_EXPORT void rglCgProgramErase( _CGprogram* prog );
// default setters
void _cgRaiseInvalidParam( CgRuntimeParameter*p, const void*v );
void _cgRaiseNotMatrixParam( CgRuntimeParameter*p, const void*v );
void _cgIgnoreSetParam( CgRuntimeParameter*p, const void*v );
void _cgRaiseInvalidParamIndex( CgRuntimeParameter*p, const void*v, const int index );
void _cgRaiseNotMatrixParamIndex( CgRuntimeParameter*p, const void*v, const int index );
void _cgIgnoreSetParamIndex( CgRuntimeParameter*p, const void*v, const int index );
// cg helpers
// Is macros
#define CG_IS_CONTEXT(_ctx) rglIsName(&_CurrentContext->cgContextNameSpace, (unsigned int)_ctx)
#define CG_IS_PROGRAM(_program) rglIsName(&_CurrentContext->cgProgramNameSpace, (unsigned int)_program)
#define CG_IS_PARAMETER(_param) rglIsName(&_CurrentContext->cgParameterNameSpace, (unsigned int)(((unsigned int)_param)&CG_PARAMETERMASK))
//array indices
#define CG_PARAMETERSIZE 22 //22 bits == 4 millions parameters
#define CG_PARAMETERMASK ((1<<CG_PARAMETERSIZE)-1)
#define CG_GETINDEX(param) (int)((unsigned int)(param)>>CG_PARAMETERSIZE)
inline static bool isMatrix( CGtype type )
{
if (( type >= CG_FLOAT1x1 && type <= CG_FLOAT4x4 ) ||
( type >= CG_HALF1x1 && type <= CG_HALF4x4 ) ||
( type >= CG_INT1x1 && type <= CG_INT4x4 ) ||
( type >= CG_BOOL1x1 && type <= CG_BOOL4x4 ) ||
( type >= CG_FIXED1x1 && type <= CG_FIXED4x4 ))
return true;
return false;
}
inline static bool isSampler( CGtype type )
{
return ( type >= CG_SAMPLER1D && type <= CG_SAMPLERCUBE );
}
unsigned int rglCountFloatsInCgType( CGtype type );
CGbool _cgMatrixDimensions( CGtype type, unsigned int* nrows, unsigned int* ncols );
unsigned int rglGetTypeRowCount( CGtype parameterType );
unsigned int rglGetTypeColCount( CGtype parameterType );
// the internal cg conversions
inline static CgRuntimeParameter* _cgGetParamPtr( CGparameter p )
{
return ( CgRuntimeParameter* )rglGetNamedValue( &_CurrentContext->cgParameterNameSpace, ( unsigned int )((( unsigned int )p )&CG_PARAMETERMASK ) );
}
inline static _CGprogram* _cgGetProgPtr( CGprogram p )
{
return ( _CGprogram* )rglGetNamedValue( &_CurrentContext->cgProgramNameSpace, (unsigned int)p );
}
inline static _CGcontext* _cgGetContextPtr( CGcontext c )
{
return ( _CGcontext* )rglGetNamedValue( &_CurrentContext->cgContextNameSpace, (unsigned int)c );
}
inline static CgRuntimeParameter* rglCgGLTestParameter( CGparameter param )
{
return _cgGetParamPtr( param );
}
CgRuntimeParameter* _cgGLTestArrayParameter( CGparameter paramIn, long offset, long nelements );
CgRuntimeParameter* _cgGLTestTextureParameter( CGparameter param );
#ifdef RGL_DEBUG
void rglCgDumpState();
void rglCgPrintSpaces( unsigned int n );
#endif
inline static int rglGetSizeofSubArray( const unsigned short *dimensions, unsigned short count )
{
int res = 1;
for ( int i = 0;i < count;i++ )
res *= ( int )( *( dimensions++ ) );
return res;
}
inline static CGresource rglGetBaseResource( CGresource resource )
{
switch ( resource )
{
case CG_ATTR0: case CG_ATTR1: case CG_ATTR2: case CG_ATTR3:
case CG_ATTR4: case CG_ATTR5: case CG_ATTR6: case CG_ATTR7:
case CG_ATTR8: case CG_ATTR9: case CG_ATTR10: case CG_ATTR11:
case CG_ATTR12: case CG_ATTR13: case CG_ATTR14: case CG_ATTR15:
return CG_ATTR0;
case CG_HPOS:
return CG_HPOS;
case CG_COL0: case CG_COL1: case CG_COL2: case CG_COL3:
return CG_COL0;
case CG_TEXCOORD0: case CG_TEXCOORD1: case CG_TEXCOORD2: case CG_TEXCOORD3:
case CG_TEXCOORD4: case CG_TEXCOORD5: case CG_TEXCOORD6: case CG_TEXCOORD7:
case CG_TEXCOORD8: case CG_TEXCOORD9:
return CG_TEXCOORD0;
case CG_TEXUNIT0: case CG_TEXUNIT1: case CG_TEXUNIT2: case CG_TEXUNIT3:
case CG_TEXUNIT4: case CG_TEXUNIT5: case CG_TEXUNIT6: case CG_TEXUNIT7:
case CG_TEXUNIT8: case CG_TEXUNIT9: case CG_TEXUNIT10: case CG_TEXUNIT11:
case CG_TEXUNIT12: case CG_TEXUNIT13: case CG_TEXUNIT14: case CG_TEXUNIT15:
return CG_TEXUNIT0;
case CG_FOGCOORD:
return CG_FOGCOORD;
case CG_PSIZ:
return CG_PSIZ;
case CG_WPOS:
return CG_WPOS;
case CG_COLOR0: case CG_COLOR1: case CG_COLOR2: case CG_COLOR3:
return CG_COLOR0;
case CG_DEPTH0:
return CG_DEPTH0;
case CG_C:
return CG_C;
case CG_B:
return CG_B;
case CG_CLP0: case CG_CLP1: case CG_CLP2: case CG_CLP3: case CG_CLP4: case CG_CLP5:
return CG_CLP0;
case CG_UNDEFINED:
return CG_UNDEFINED;
default:
return CG_UNDEFINED;
}
}
// platform API
CGprofile rglPlatformGetLatestProfile( CGGLenum profile_type );
int rglPlatformCopyProgram( _CGprogram* source, _CGprogram* destination );
void rglPlatformProgramErase( void* platformProgram );
int rglPlatformGenerateVertexProgram( _CGprogram *program, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues );
CGbool rglPlatformSupportsVertexProgram( CGprofile p );
int rglPlatformGenerateFragmentProgram( _CGprogram *program, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues );
CGbool rglPlatformSupportsFragmentProgram( CGprofile p );
void rglPlatformSetVertexRegister4fv( unsigned int reg, const float * _RGL_RESTRICT v );
void rglPlatformSetVertexRegisterBlock( unsigned int reg, unsigned int count, const float * _RGL_RESTRICT v );
void rglPlatformSetFragmentRegister4fv( unsigned int reg, const float * _RGL_RESTRICT v );
void rglPlatformSetFragmentRegisterBlock( unsigned int reg, unsigned int count, const float * _RGL_RESTRICT v );
void rglPlatformSetBoolVertexRegisters( unsigned int values );
// names API
RGL_EXPORT unsigned int _cgHashString( const char *str );
inline static void _pullConnectedParameterValues( _CGprogram* ptr )
{
// we now use a pull method to get the data into the children parameters
// when their program is bound they pull the data from their parents
std::vector<CgParameterConnection>::iterator connectionIter = ptr->connectionTable.begin();
while ( connectionIter != ptr->connectionTable.end() )
{
// pull data into connectionIter->child from connectionIter->top
connectionIter->childOnBindSetter( connectionIter->child, connectionIter->top->pushBufferPointer, 0 );
connectionIter++;
}
}
inline static void _cgGLBindVertexProgram( _CGprogram* program )
{
// the program is a vertex program, just update the GL state
_CurrentContext->BoundVertexProgram = program;
// and inform the GL state to re-upload the vertex program
_CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM;
// This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine
_pullConnectedParameterValues( program );
CGbool is_managed = program->parentContext->GLmanageTextures;
// enable texture parameters if the managed flag is set.
if ( is_managed )
{
for ( GLuint index = 0; index < program->samplerCount; ++index )
{
// walk the array of sampler parameters
CgRuntimeParameter *rtParameter = program->runtimeParameters + program->samplerIndices[index];
rtParameter->samplerSetter( rtParameter, NULL, 0 );
}
}
}
inline static void _cgGLBindFragmentProgram( _CGprogram* program )
{
_CurrentContext->BoundFragmentProgram = program;
// need to revalidate the textures in order to update which targets to fetch from
_CurrentContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS;
// This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine
_pullConnectedParameterValues( program );
// TODO: push texture state
// Needs to be done per profile. Can't use glPushAttrib.
CGbool is_managed = program->parentContext->GLmanageTextures;
// deal with the texture parameters now.
for ( GLuint index = 0; index < program->samplerCount; ++index )
{
// walk the array of sampler parameters
CgRuntimeParameter *rtParameter = program->runtimeParameters + program->samplerIndices[index];
CgParameterResource *parameter = ( CgParameterResource * )( program->parameterResources + rtParameter->parameterEntry->typeIndex );
// find out which texture unit this parameter has been assigned to
unsigned int unit = parameter->resource - CG_TEXUNIT0;
_CurrentContext->TextureImageUnits[unit].fragmentTarget = rtParameter->glType;
// enable texture parameters if the managed flag is set.
if ( is_managed )
{
//tmp
rtParameter->samplerSetter( rtParameter, NULL, 0 );
}
else
{
rglUpdateCurrentTextureCache( &_CurrentContext->TextureImageUnits[unit] );
}
}
}
inline static void _cgGLUnbindVertexProgram()
{
_CurrentContext->BoundVertexProgram = NULL;
_CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM;
}
// XXX this should not be here.
inline static void rglLeaveFFXFP( RGLcontext*LContext )
{
LContext->FragmentProgram = GL_TRUE;
struct _CGprogram* current = LContext->BoundFragmentProgram;
if ( current )
{
for ( GLuint i = 0; i < current->samplerCount; ++i )
{
int unit = current->samplerUnits[i];
rglUpdateCurrentTextureCache( &_CurrentContext->TextureImageUnits[unit] );
}
}
LContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS;
}
inline static void _cgGLUnbindFragmentProgram()
{
_CurrentContext->BoundFragmentProgram = NULL;
}
static inline GLenum rglCgGetSamplerGLTypeFromCgType( CGtype type )
{
switch ( type )
{
case CG_SAMPLER1D:
case CG_SAMPLER2D:
case CG_SAMPLERRECT:
return GL_TEXTURE_2D;
case CG_SAMPLER3D:
return GL_TEXTURE_3D;
case CG_SAMPLERCUBE:
return GL_TEXTURE_CUBE_MAP;
default:
return 0;
}
}
static inline int is_created_param( CgRuntimeParameter* ptr )
{
if ( ptr->parameterEntry->flags & CGP_RTCREATED )
return 1;
return 0;
}
struct rglNameSpace;
#define VERTEX_PROFILE_INDEX 0
#define FRAGMENT_PROFILE_INDEX 1
int rglNVGenerateProgram( _CGprogram *program, int profileIndex, const CgProgramHeader *programHeader, const void *ucode,
const CgParameterTableHeader *parameterHeader, const CgParameterEntry *parameterEntries,
const char *stringTable, const float *defaultValues );
//
// these functions return the statically allocated table of function pointers originally
// written for NV unshared vertex parameter setters, but now also used by runtime
// created parameters cause these setters just do straight copies into the pushbuffer memory
//
_cgSetArrayIndexFunction getVectorTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d );
_cgSetArrayIndexFunction getMatrixTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d, unsigned short e, unsigned short f );
// -------------------------------------------
typedef void( * CgcontextHookFunction )( _CGcontext *context );
extern RGL_EXPORT CgcontextHookFunction _cgContextCreateHook;
extern RGL_EXPORT CgcontextHookFunction _cgContextDestroyHook;
typedef void( * CgparameterHookFunction )( CgRuntimeParameter *parameter );
extern RGL_EXPORT CgparameterHookFunction _cgParameterCreateHook;
extern RGL_EXPORT CgparameterHookFunction _cgParameterDestroyHook;
typedef void( * CgprogramHookFunction )( _CGprogram *program );
typedef void( * CgprogramCopyHookFunction )( _CGprogram *newprogram, _CGprogram *oldprogram );
extern RGL_EXPORT CgprogramHookFunction _cgProgramCreateHook;
extern RGL_EXPORT CgprogramHookFunction _cgProgramDestroyHook;
extern RGL_EXPORT CgprogramCopyHookFunction _cgProgramCopyHook;
typedef int( * cgRTCgcCompileHookFunction )( const char*, const char *, const char*, const char**, char** );
typedef void( * cgRTCgcFreeHookFunction )( char* );
extern RGL_EXPORT cgRTCgcCompileHookFunction _cgRTCgcCompileProgramHook;
extern RGL_EXPORT cgRTCgcFreeHookFunction _cgRTCgcFreeCompiledProgramHook;
//-----------------------------------------------
//inlined helper functions
static inline int rglGetParameterType( const CGprogram *program, const CgParameterEntry *entry )
{
return ( entry->flags & CGP_TYPE_MASK );
}
static inline const CgParameterResource *rglGetParameterResource( const _CGprogram *program, const CgParameterEntry *entry )
{
return ( CgParameterResource * )( program->parameterResources + entry->typeIndex );
}
static inline CGtype rglGetParameterCGtype( const _CGprogram *program, const CgParameterEntry *entry )
{
if ( entry->flags & CGP_RTCREATED )
{
return ( CGtype )entry->typeIndex;
}
else
{
const CgParameterResource *parameterResource = rglGetParameterResource( program, entry );
if ( parameterResource )
{
return ( CGtype )parameterResource->type;
}
}
return CG_UNKNOWN_TYPE;
}
static inline const CgParameterArray *rglGetParameterArray( const _CGprogram *program, const CgParameterEntry *entry )
{
return ( CgParameterArray* )( program->parameterResources + entry->typeIndex );
}
static inline const CgParameterStructure *rglGetParameterStructure( const _CGprogram *program, const CgParameterEntry *entry )
{
return ( CgParameterStructure* )( program->parameterResources + entry->typeIndex );
}
inline int rglGetProgramProfileIndex( CGprofile profile )
{
if ( profile == CG_PROFILE_SCE_FP_TYPEB || profile == CG_PROFILE_SCE_FP_TYPEC || profile == CG_PROFILE_SCE_FP_RSX )
return FRAGMENT_PROFILE_INDEX;
else if ( profile == CG_PROFILE_SCE_VP_TYPEB || profile == CG_PROFILE_SCE_VP_TYPEC || profile == CG_PROFILE_SCE_VP_RSX )
return VERTEX_PROFILE_INDEX;
else
return -1;
}
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration that encloses file.
#endif
#endif

View File

@ -0,0 +1,158 @@
#ifndef _cg_internal_h
#define _cg_internal_h
#ifdef __cplusplus
extern "C"
{
#endif
//Hardware shader settings
#define CGF_OUTPUTFROMH0 0x01
#define CGF_DEPTHREPLACE 0x02
#define CGF_PIXELKILL 0x04
//CgParameterEntry flags
//variability
#define CGPV_MASK 0x03
#define CGPV_VARYING 0x00
#define CGPV_UNIFORM 0x01
#define CGPV_CONSTANT 0x02
#define CGPV_MIXED 0x03
//direction
#define CGPD_MASK 0x0C
#define CGPD_IN 0x00
#define CGPD_OUT 0x04
#define CGPD_INOUT 0x08
//is_referenced
#define CGPF_REFERENCED 0x10
//is_shared
#define CGPF_SHARED 0x20
//is_global
#define CGPF_GLOBAL 0x40
//internal parameter
#define CGP_INTERNAL 0x80
//type
#define CGP_INTRINSIC 0x0000
#define CGP_STRUCTURE 0x100
#define CGP_ARRAY 0x200
#define CGP_TYPE_MASK (CGP_STRUCTURE + CGP_ARRAY)
//storage
#define CGP_UNROLLED 0x400
#define CGP_UNPACKED 0x800
#define CGP_CONTIGUOUS 0x1000
#define CGP_NORMALIZE 0x2000 // (attrib) if the usual cgGLSetParameterPointer should normalize the attrib
#define CGP_RTCREATED 0x4000 // indicates that the parameter was created at runtime
//static control flow boolean type
#define CGP_SCF_BOOL (CG_TYPE_START_ENUM + 1024)
//data types
typedef struct _CgParameterTableHeader
{
unsigned short entryCount;
unsigned short resourceTableOffset;
unsigned short defaultValueIndexTableOffset;
unsigned short defaultValueIndexCount;
unsigned short semanticIndexTableOffset;
unsigned short semanticIndexCount;
}
CgParameterTableHeader;
typedef struct _CgParameterEntry
{
unsigned int nameOffset;
unsigned short typeIndex;
unsigned short flags;
}
CgParameterEntry;
#ifdef MSVC
#pragma warning( push )
#pragma warning ( disable : 4200 )
#endif
typedef struct _CgParameterArray
{
unsigned short arrayType;
unsigned short dimensionCount;
unsigned short dimensions[];
}
CgParameterArray; //padded to 4 bytes
#ifdef MSVC
#pragma warning( pop )
#endif
typedef struct _CgParameterStructure
{
unsigned short memberCount;
unsigned short reserved;
}
CgParameterStructure;
typedef struct _CgParameterResource
{
unsigned short type;
unsigned short resource;
}
CgParameterResource;
typedef struct _CgParameterSemantic
{
unsigned short entryIndex;
unsigned short reserved;
unsigned int semanticOffset;
}
CgParameterSemantic;
typedef struct _CgParameterDefaultValue
{
unsigned short entryIndex;
unsigned short defaultValueIndex;
}
CgParameterDefaultValue;
typedef struct CgProgramHeader
{
//28 bytes
unsigned short profile; // Vertex / Fragment
unsigned short compilerVersion;
unsigned int instructionCount;
unsigned int attributeInputMask;
union
{
struct
{
//16 bytes
unsigned int instructionSlot;
unsigned int registerCount;
unsigned int attributeOutputMask;
}
vertexProgram;
struct
{
//12 bytes
unsigned int partialTexType;
unsigned short texcoordInputMask;
unsigned short texcoord2d;
unsigned short texcoordCentroid;
unsigned char registerCount;
unsigned char flags; //combination of CGF_OUTPUTFROMH0,CGF_DEPTHREPLACE,CGF_PIXELKILL
}
fragmentProgram;
};
}
CgProgramHeader;
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration that encloses file.
#endif
#endif

View File

@ -0,0 +1,42 @@
#ifndef CGPROGRAMGROUP_HEADER
#define CGPROGRAMGROUP_HEADER
#include "Cg/cgBinary.h"
typedef struct _CGnamedProgram
{
const char *name;
CGprogram program;
int refCount;
}
_CGnamedProgram;
typedef struct _CGprogramGroup
{
struct _CGprogramGroup *next;
CGcontext ctx;
unsigned int *constantTable;
unsigned int *stringTable;
unsigned int programCount;
_CGnamedProgram *programs;
int refCount; //total number of program refCounted
bool userCreated;
char *filedata;
char *name;
}
_CGprogramGroup;
/* Program groups */
typedef struct _CGprogramGroup *CGprogramGroup;
CGprogramGroup rglCgCreateProgramGroup( CGcontext ctx, const char *name, void *ptr, int size );
CGprogramGroup rglCgCreateProgramGroupFromFile( CGcontext ctx, const char *group_file );
void rglCgDestroyProgramGroup( CGprogramGroup group );
int rglCgGetProgramCount( CGprogramGroup group );
CGprogram rglCgGetProgram( CGprogramGroup group, const char *name );
int rglCgGetProgramIndex( CGprogramGroup group, const char *name );
CGprogram rglCgGetProgramAtIndex( CGprogramGroup group, unsigned int index );
const char *rglCgGetProgramGroupName( CGprogramGroup group );
#endif

View File

@ -0,0 +1,115 @@
#if !defined(_H_CG_BINARY_H_)
#define _H_CG_BINARY_H_
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************************/
/*** CgBinaryGL binary data/file format ***/
/*************************************************************************/
#define CG_BINARY_FORMAT_REVISION 0x00000006
// we don't encode pointers in the binary file so cross compiling
// with differnt pointer sizes works.
typedef unsigned int CgBinaryOffset;
typedef CgBinaryOffset CgBinaryEmbeddedConstantOffset;
typedef CgBinaryOffset CgBinaryFloatOffset;
typedef CgBinaryOffset CgBinaryStringOffset;
typedef CgBinaryOffset CgBinaryParameterOffset;
// a few typedefs
typedef struct CgBinaryParameter CgBinaryParameter;
typedef struct CgBinaryEmbeddedConstant CgBinaryEmbeddedConstant;
typedef struct CgBinaryVertexProgram CgBinaryVertexProgram;
typedef struct CgBinaryFragmentProgram CgBinaryFragmentProgram;
typedef struct CgBinaryProgram CgBinaryProgram;
// fragment programs have their constants embedded in the microcode
struct CgBinaryEmbeddedConstant
{
unsigned int ucodeCount; // occurances
unsigned int ucodeOffset[1]; // offsets that need to be patched follow
};
// describe a binary program parameter (CgParameter is opaque)
struct CgBinaryParameter
{
CGtype type; // cgGetParameterType()
CGresource res; // cgGetParameterResource()
CGenum var; // cgGetParameterVariability()
int resIndex; // cgGetParameterResourceIndex()
CgBinaryStringOffset name; // cgGetParameterName()
CgBinaryFloatOffset defaultValue; // default constant value
CgBinaryEmbeddedConstantOffset embeddedConst; // embedded constant information
CgBinaryStringOffset semantic; // cgGetParameterSemantic()
CGenum direction; // cgGetParameterDirection()
int paramno; // 0..n: cgGetParameterIndex() -1: globals
CGbool isReferenced; // cgIsParameterReferenced()
CGbool isShared; // cgIsParameterShared()
};
// attributes needed for vshaders
struct CgBinaryVertexProgram
{
unsigned int instructionCount; // #instructions
unsigned int instructionSlot; // load address (indexed reads!)
unsigned int registerCount; // R registers count
unsigned int attributeInputMask; // attributes vs reads from
unsigned int attributeOutputMask; // attributes vs writes (uses SET_VERTEX_ATTRIB_OUTPUT_MASK bits)
};
typedef enum {
CgBinaryPTTNone = 0,
CgBinaryPTT2x16 = 1,
CgBinaryPTT1x32 = 2,
} CgBinaryPartialTexType;
// attributes needed for pshaders
struct CgBinaryFragmentProgram
{
unsigned int instructionCount; // #instructions
unsigned int attributeInputMask; // attributes fp reads (uses SET_VERTEX_ATTRIB_OUTPUT_MASK bits)
unsigned int partialTexType; // texid 0..15 use two bits each marking whether the texture format requires partial load: see CgBinaryPartialTexType
unsigned short texCoordsInputMask; // tex coords used by frag prog. (tex<n> is bit n)
unsigned short texCoords2D; // tex coords that are 2d (tex<n> is bit n)
unsigned short texCoordsCentroid; // tex coords that are centroid (tex<n> is bit n)
unsigned char registerCount; // R registers count
unsigned char outputFromH0; // final color from R0 or H0
unsigned char depthReplace; // fp generated z epth value
unsigned char pixelKill; // fp uses kill operations
};
// defines a binary program -- *all* address/offsets are relative to the begining of CgBinaryProgram
struct CgBinaryProgram
{
// vertex/pixel shader identification (BE/LE as well)
CGprofile profile;
// binary revision (used to verify binary and driver structs match)
unsigned int binaryFormatRevision;
// total size of this struct including profile and totalSize field!
unsigned int totalSize;
// parameter usually queried using cgGet[First/Next]LeafParameter
unsigned int parameterCount;
CgBinaryParameterOffset parameterArray;
// depending on profile points to a CgBinaryVertexProgram or CgBinaryFragmentProgram struct
CgBinaryOffset program;
// raw ucode data
unsigned int ucodeSize;
CgBinaryOffset ucode;
// variable length data follows
unsigned char data[1];
};
#ifdef __cplusplus
}
#endif
#endif // !_H_CG_BINARY_H_

View File

@ -0,0 +1,78 @@
#ifndef _BASE_H_
#define _BASE_H_
#include <stdlib.h>
#include <new>
namespace RGL
{
template<class T> class Vector
{
T* array;
unsigned int count;
unsigned int capacity;
unsigned int increment;
public:
void * operator new( size_t size ) { return malloc( size ); }
void * operator new( size_t /*size*/, void *p ) { return p; }
void operator delete( void * /*ptr*/, void * /*p*/ ) { }
Vector(): array( 0 ), count( 0 ), capacity( 0 ), increment( 4 ) {}
~Vector() { clear(); reallocArray( 0 ); }
inline void setIncrement( unsigned int i ) { increment = i; }
inline unsigned int getCount() { return count; }
inline void reallocArray( unsigned int newCapacity )
{
if ( newCapacity == capacity ) return;
if ( newCapacity > capacity ) newCapacity = ( newCapacity > capacity + increment ) ? newCapacity : ( capacity + increment );
if ( newCapacity == 0 )
{
free( array );
array = 0;
}
else array = static_cast<T*>( realloc( static_cast<void *>( array ), sizeof( T ) * newCapacity ) );
capacity = newCapacity;
}
inline void clear()
{
if ( !array ) return;
for ( unsigned int i = 0;i < count;++i )( array + i )->~T();
count = 0;
}
inline unsigned int pushBack( const T &element )
{
if ( count + 1 > capacity ) reallocArray( count + 1 );
new(( void * )( array + count ) ) T( element );
return ++count;
}
inline void removeElement( const T &element )
{
for ( unsigned int i = count; i > 0; --i )
{
if ( array[i-1] == element )
{
remove( i - 1 );
return;
}
}
}
inline void remove( unsigned int index )
{
( array + index )->~T();
--count;
if ( count > index ) memmove( array + index, array + index + 1, ( count - index )*sizeof( T ) );
}
inline T *getArray() const { return array; }
inline T& operator []( int i ) const { return array[i]; }
};
}
#endif

View File

@ -0,0 +1,29 @@
#ifndef _RGLReportInternal_h
#define _RGLReportInternal_h
#include "../export/RGL/rgl.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
GLenum e;
const char *s;
}RGLenumMap;
const char *rglMapLookupEnum( const RGLenumMap* map, unsigned int count, GLenum e );
GLenum rglMapLookupString( const RGLenumMap* map, unsigned int count, const char *s );
#define _RGL_MAP_LOOKUP_ENUM(MAP,ENUM) rglMapLookupEnum(MAP,sizeof(MAP)/sizeof(MAP[0]),ENUM)
#define _RGL_MAP_LOOKUP_STRING(MAP,STRING) rglMapLookupString(MAP,sizeof(MAP)/sizeof(MAP[0]),STRING)
const char *rglGetGLEnumName( GLenum e );
const char *rglGetGLErrorName( GLenum e );
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration that encloses file.
#endif
#endif

View File

@ -0,0 +1,88 @@
#ifndef _TYPE_UTILS_H
#define _TYPE_UTILS_H
/* Following NV_half_float specification
* The half data type is a floating-point
* data type encoded in an unsigned scalar data type. If the unsigned scalar
* holding a half has a value of N, the corresponding floating point number
* is
* (-1)^S * 0.0, if E == 0 and M == 0,
* (-1)^S * 2^-14 * (M / 2^10), if E == 0 and M != 0,
* (-1)^S * 2^(E-15) * (1 + M/2^10), if 0 < E < 31,
* (-1)^S * INF, if E == 31 and M == 0, or
* NaN, if E == 31 and M != 0,
*
* where
*
* S = floor((N mod 65536) / 32768),
* E = floor((N mod 32768) / 1024), and
* M = N mod 1024.
*
* INF (Infinity) is a special representation indicating numerical overflow.
* NaN (Not a Number) is a special representation indicating the result of
* illegal arithmetic operations, such as division by zero. Note that all
* normal values, zero, and INF have an associated sign. -0.0 and +0.0
* should be considered equivalent for the purposes of comparisons. Note
* also that half is not a native type in most CPUs, so some special
* processing may be required to generate or interpret half data.
*
* That is SEEEEEMMMMMMMMMM
*/
typedef union
{
unsigned int i;
float f;
} rglIntAndFloat;
static const rglIntAndFloat rglNan = {i: 0x7fc00000U};
static const rglIntAndFloat rglInfinity = {i: 0x7f800000U};
#define RGL_NAN (rglNan.f)
#define RGL_INFINITY (rglInfinity.f)
static inline GLhalfARB rglFloatToHalf( float v )
{
rglIntAndFloat V = {f: v};
// extract float components
unsigned int S = ( V.i >> 31 ) & 1;
int E = (( V.i >> 23 ) & 0xff ) - 0x7f;
unsigned int M = V.i & 0x007fffff;
if (( E == 0x80 ) && ( M ) ) return 0x7fff; // NaN
else if ( E >= 15 ) return( S << 15 ) | 0x7c00; // Inf
else if ( E <= -14 ) return( S << 15 ) | (( 0x800000 + M ) >> ( -14 - E ) ); // Denorm or zero. Works for input denorms and zero
else return( S << 15 ) | ((( E + 15 )&0x1f ) << 10 ) | ( M >> 13 );
}
static inline float rglHalfToFloat( GLhalfARB v )
{
unsigned int S = v >> 15;
unsigned int E = ( v & 0x7C00 ) >> 10;
unsigned int M = v & 0x03ff;
float f;
if ( E == 31 )
{
if ( M == 0 ) f = RGL_INFINITY;
else f = RGL_NAN;
}
else if ( E == 0 )
{
if ( M == 0 ) f = 0.f;
else f = M * 1.f / ( 1 << 24 );
}
else f = ( 0x400 + M ) * 1.f / ( 1 << 25 ) * ( 1 << E );
return S ? -f : f;
}
//----------------------------------------
// Fixed Point Conversion Macros
// FixedPoint.c
//----------------------------------------
#define rglFixedToFloat 1.f/65536.f
#define rglFloatToFixed 65536.f
#define X2F(X) (((float)(X))*rglFixedToFloat)
#define F2X(A) ((int)((A)*rglFloatToFixed))
#endif // _TYPE_UTILS_H

View File

@ -0,0 +1,439 @@
#ifndef _RGLTypes_h
#define _RGLTypes_h
#include <stdlib.h>
#include <float.h>
#include "../export/RGL/rgl.h"
#include "Base.h"
#include <Cg/cg.h>
struct rglFramebufferAttachment
{
GLenum type; // renderbuffer or texture
GLuint name;
// only valid for texture attachment
GLenum textureTarget;
rglFramebufferAttachment(): type( GL_NONE ), name( 0 ), textureTarget( GL_NONE )
{};
};
#define RGL_MAX_COLOR_ATTACHMENTS 4
struct rglFramebuffer
{
rglFramebufferAttachment color[RGL_MAX_COLOR_ATTACHMENTS];
GLboolean needValidate;
rglFramebuffer(): needValidate( GL_TRUE )
{};
virtual ~rglFramebuffer()
{};
};
#ifdef __cplusplus
extern "C"
{
#endif
typedef float RGLFColorComponent;
typedef float RGLCoordinate;
typedef unsigned int rglBitfield;
#define RGLBIT_GET(f,n) ((f) & (1<<(n)))
#define RGLBIT_TRUE(f,n) ((f) |= (1<<(n)))
#define RGLBIT_FALSE(f,n) ((f) &= ~(1<<(n)))
#define RGLBIT_ASSIGN(f,n,val) do { if(val) RGLBIT_TRUE(f,n); else RGLBIT_FALSE(f,n); } while(0)
#define ALIGN16 __attribute__((aligned (16)))
#define _RGL_RESTRICT __restrict
typedef struct
{
GLfloat R, G, B, A;
} rglColorRGBAf;
typedef struct
{
int X, Y, XSize, YSize;
} rglViewPort;
// image location flags
// These are flag bits that indicate where the valid image data is. Data
// can be valid nowhere, on the host, on the GPU, or in both places.
enum {
RGL_IMAGE_DATASTATE_UNSET = 0x0, // not a flag, just a meaningful 0
RGL_IMAGE_DATASTATE_HOST = 0x1,
RGL_IMAGE_DATASTATE_GPU = 0x2
};
// Image data structure
typedef struct rglImage_
{
// isSet indicates whether a gl*TexImage* call has been made on that image,
// to know whether calling gl*TexSubImage* is valid or not.
GLboolean isSet;
GLenum internalFormat;
GLenum format;
GLenum type;
GLsizei width;
GLsizei height;
GLsizei depth;
GLsizei alignment;
// image storage
// For raster
// storage, the platform driver sets strides (in bytes) between
// lines and layers and the library takes care of the rest.
// These values are initially zero, but may be set by the platform
// rglPlatformChooseInternalStorage to specify custom storage
// (compressed, swizzled, etc.). They should be considered
// read-only except by the platform driver.
GLsizei storageSize; // minimum allocation
GLsizei xstride, ystride, zstride; // strides
GLuint xblk, yblk; // block storage size
char *data;
char *mallocData;
GLsizei mallocStorageSize;
GLenum dataState; // valid data location (see enum above)
}
rglImage;
// Raster data structure
// This struct is used internally to define 3D raster data for writing
// to or reading from a rglImage. The GL-level interface for pixel/texel
// level operations always uses a raster, even though the underlying
// platform-specific storage may not be a raster (e.g. compressed
// blocks). The internal routines rglRasterToImage and rglImageToRaster
// convert between the two.
//
// A clean alternative would have been to use rglImage for everything and
// implement a single rglImageToImage copying function. However, given
// that one side will always be a raster, the implementation cost was
// not seen as worth the generality.
typedef struct
{
GLenum format;
GLenum type;
GLsizei width;
GLsizei height;
GLsizei depth;
GLsizei xstride;
GLsizei ystride;
GLsizei zstride;
void* data;
} rglRaster;
#define RGL_TEXTURE_REVALIDATE_LAYOUT 0x01
#define RGL_TEXTURE_REVALIDATE_IMAGES 0x02
#define RGL_TEXTURE_REVALIDATE_PARAMETERS 0x04
typedef struct rglBufferObject rglBufferObject;
// Texture data structure
typedef struct
{
GLuint revalidate;
GLuint target;
GLuint minFilter;
GLuint magFilter;
GLfloat minLod;
GLfloat maxLod;
GLuint baseLevel;
GLuint maxLevel;
GLuint wrapS;
GLuint wrapT;
GLuint wrapR;
GLfloat lodBias;
GLfloat maxAnisotropy;
GLenum compareMode;
GLenum compareFunc;
GLuint gammaRemap;
GLenum usage;
rglColorRGBAf borderColor;
GLboolean vertexEnable;
GLboolean isRenderTarget;
// this is valid when the revalidate bits do not have any resource bit set.
// the validation of the resources update the bit.
GLboolean isComplete;
rglBufferObject *referenceBuffer;
intptr_t offset;
RGL::Vector<rglFramebuffer *> framebuffers;
GLuint imageCount;
GLuint faceCount;
rglImage* image;
void * platformTexture[]; // C99 flexible array member
} rglTexture;
typedef struct
{
GLboolean isSet;
void* platformFenceObject[];
} rglFenceObject;
// For now, we'll use a static array for lights
//
#define RGL_MAX_TEXTURE_IMAGE_UNITS 16
#define RGL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 4
#define RGL_MAX_VERTEX_ATTRIBS 16
// Texture image unit data structure
typedef struct
{
GLuint bound2D;
rglTexture* default2D;
GLboolean enable2D;
// the current fragment program's target for this unit, if in use.
// this is invalid otherwise
GLenum fragmentTarget;
GLfloat lodBias;
rglTexture* currentTexture;
} rglTextureImageUnit;
enum
{
RGL_FRAMEBUFFER_ATTACHMENT_NONE,
RGL_FRAMEBUFFER_ATTACHMENT_RENDERBUFFER,
RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE,
};
struct RGLdevice
{
PSGLdeviceParameters deviceParameters;
GLvoid* rasterDriver;
char platformDevice[]; // C99 flexible array member
};
typedef struct
{
// parameters to glDraw* calls
GLenum mode;
GLint firstVertex;
GLsizei vertexCount;
GLuint indexMin;
GLuint indexMax; // 0==glDrawElements; 0!=glDrawRangeElements
GLsizei indexCount;
// internal draw parameters (set by rglPlatformRequiresSlowPath):
// client-side array transfer buffer params
GLuint xferTotalSize;
GLuint indexXferOffset;
GLuint indexXferSize;
GLuint attribXferTotalSize;
GLuint attribXferOffset[RGL_MAX_VERTEX_ATTRIBS];
GLuint attribXferSize[RGL_MAX_VERTEX_ATTRIBS];
} rglDrawParams;
// define mapping of vertex semantics to attributes
// These indices specify the aliasing of vertex attributes with
// conventional per-vertex parameters. This mapping is the same as
// specified in the NV_vertex_program extension.
#define RGL_ATTRIB_POSITION_INDEX 0
#define RGL_ATTRIB_WEIGHT_INDEX 1
#define RGL_ATTRIB_NORMAL_INDEX 2
#define RGL_ATTRIB_PRIMARY_COLOR_INDEX 3
#define RGL_ATTRIB_SECONDARY_COLOR_INDEX 4
#define RGL_ATTRIB_FOG_COORD_INDEX 5
#define RGL_ATTRIB_POINT_SIZE_INDEX 6
#define RGL_ATTRIB_BLEND_INDICES_INDEX 7
#define RGL_ATTRIB_TEX_COORD0_INDEX 8
#define RGL_ATTRIB_TEX_COORD1_INDEX 9
#define RGL_ATTRIB_TEX_COORD2_INDEX 10
#define RGL_ATTRIB_TEX_COORD3_INDEX 11
#define RGL_ATTRIB_TEX_COORD4_INDEX 12
#define RGL_ATTRIB_TEX_COORD5_INDEX 13
#define RGL_ATTRIB_TEX_COORD6_INDEX 14
#define RGL_ATTRIB_TEX_COORD7_INDEX 15
// per-attribute descriptor and data
typedef struct
{
// GL state
GLvoid* clientData; // client-side array pointer or VBO offset
GLuint clientSize; // number of components 1-4
GLenum clientType; // GL_SHORT, GL_INT, GL_FLOAT
GLsizei clientStride; // element-to-element distance [bytes]
GLuint arrayBuffer; // name of buffer object; 0==none (ie client-side)
GLfloat value[4]; // constant attribute value
GLuint frequency; // instancing divisor
GLboolean normalized;
} ALIGN16 rglAttribute;
// state for the entire set of vertex attributes, plus
// other AttribSet-encapsulated state.
// (this is the block of state applied en mass during glBindAttribSetSCE())
typedef struct
{
// Vertex attribute descriptors and data are stored in this array.
// The fixed function attributes are aliased to the array via the
// indices defined by _RGL_ATTRIB_*_INDEX.
rglAttribute attrib[RGL_MAX_VERTEX_ATTRIBS];
// bitfields corresponding to the attrib[] array elements:
rglBitfield DirtyMask; // 1 == attribute has changed & needs updating
rglBitfield EnabledMask; // 1 == attribute is enabled for drawing
rglBitfield HasVBOMask; // 1 == attribute is in a VBO (ie server-side)
} ALIGN16 rglAttributeState;
struct rglBufferObject
{
GLuint refCount;
GLsizeiptr size;
GLboolean mapped;
GLenum internalFormat;
GLuint width;
GLuint height;
RGL::Vector<rglTexture *> textureReferences;
void *platformBufferObject[];
};
#define RGL_CONTEXT_RED_MASK 0x01
#define RGL_CONTEXT_GREEN_MASK 0x02
#define RGL_CONTEXT_BLUE_MASK 0x04
#define RGL_CONTEXT_ALPHA_MASK 0x08
#define RGL_CONTEXT_DEPTH_MASK 0x10
#define RGL_CONTEXT_COLOR_MASK 0x0F
enum
{
RGL_CONTEXT_ACTIVE_SURFACE_COLOR0,
RGL_CONTEXT_ACTIVE_SURFACE_COLOR1,
RGL_CONTEXT_ACTIVE_SURFACE_COLOR2,
RGL_CONTEXT_ACTIVE_SURFACE_COLOR3,
RGL_CONTEXT_ACTIVE_SURFACE_DEPTH,
RGL_CONTEXT_ACTIVE_SURFACE_STENCIL,
RGL_CONTEXT_ACTIVE_SURFACES
};
#define rglELEMENTS_IN_MATRIX 16 // 4x4
typedef struct rglNameSpace
{
void** data;
void** firstFree;
unsigned long capacity;
} rglNameSpace;
typedef void *( *rglTexNameSpaceCreateFunction )( void );
typedef void( *rglTexNameSpaceDestroyFunction )( void * );
typedef struct rglTexNameSpace
{
void** data;
GLuint capacity;
rglTexNameSpaceCreateFunction create;
rglTexNameSpaceDestroyFunction destroy;
} rglTexNameSpace;
// There are 6 clock domains, each with a maximum of 4 experiments, plus 4 elapsed exp.
#define RGL_MAX_DPM_QUERIES (4 * 6 + 4)
struct RGLcontext
{
GLenum error;
rglViewPort ViewPort;
GLclampf DepthNear;
GLclampf DepthFar;
GLenum PerspectiveCorrectHint;
rglAttributeState defaultAttribs0; // a default rglAttributeState, for bind = 0
rglAttributeState *attribs; // ptr to current rglAttributeState
// Frame buffer-related fields
//
GLenum DrawBuffer, ReadBuffer;
GLboolean ShaderSRGBRemap;
GLboolean Blending; // enable for mrt color target 0
GLenum BlendEquationRGB;
GLenum BlendEquationAlpha;
GLenum BlendFactorSrcRGB;
GLenum BlendFactorDestRGB;
GLenum BlendFactorSrcAlpha;
GLenum BlendFactorDestAlpha;
rglColorRGBAf BlendColor;
GLboolean ColorLogicOp;
GLenum LogicOp;
GLboolean Dithering;
GLuint TexCoordReplaceMask;
rglTexNameSpace textureNameSpace;
GLuint ActiveTexture;
rglTextureImageUnit TextureImageUnits[RGL_MAX_TEXTURE_IMAGE_UNITS];
rglTextureImageUnit* CurrentImageUnit;
GLsizei packAlignment;
GLsizei unpackAlignment;
rglTexNameSpace bufferObjectNameSpace;
GLuint ArrayBuffer;
GLuint PixelUnpackBuffer;
GLuint TextureBuffer;
// synchronization objects
rglTexNameSpace fenceObjectNameSpace;
// framebuffer objects
GLuint framebuffer; // GL_FRAMEBUFFER_OES binding
rglTexNameSpace framebufferNameSpace;
GLboolean VertexProgram;
struct _CGprogram* BoundVertexProgram;
GLboolean FragmentProgram;
struct _CGprogram* BoundFragmentProgram;
unsigned int LastFPConstantModification;
GLboolean AllowTXPDemotion;
GLboolean VSync;
GLboolean SkipFirstVSync;
GLuint needValidate;
GLboolean everAttached;
CGerror RGLcgLastError;
CGerrorCallbackFunc RGLcgErrorCallbackFunction;
// Cg containers
CGcontext RGLcgContextHead;
rglNameSpace cgContextNameSpace;
rglNameSpace cgProgramNameSpace;
rglNameSpace cgParameterNameSpace;
};
#if defined(MSVC)
#pragma warning ( pop )
#endif
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration which encloses file.
#endif
#endif // _RGLTypes_h

View File

@ -0,0 +1,126 @@
#ifndef _RGLUTILS_H_
#define _RGLUTILS_H_
#include "Types.h"
#include "../export/RGL/export.h"
#include "platform.h"
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef MSVC
// MAX that works with side effects. Just in case.
#define MAX(A,B) ({ \
__typeof__(A) At=(A); \
__typeof__(B) Bt=(B); \
At>Bt?At:Bt; })
#define MIN(A,B) ({ \
__typeof__(A) At=(A); \
__typeof__(B) Bt=(B); \
At<Bt?At:Bt; })
#define RGL_LIKELY(COND) __builtin_expect((COND),1)
#define RGL_UNLIKELY(COND) __builtin_expect((COND),0)
#else
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define RGL_LIKELY(COND) (COND)
#define RGL_UNLIKELY(COND) (COND)
#endif
#define _RGL_FLOAT_AS_UINT(x) ({union {float f; unsigned int i;} u; u.f=(x); u.i;})
static inline float rglClampf( const float value )
{
return MAX( MIN( value, 1.f ), 0.f );
}
static inline unsigned short endianSwapHalf( unsigned short v )
{
return ( v >> 8 & 0x00ff ) | ( v << 8 & 0xff00 );
}
static inline unsigned int endianSwapWord( unsigned int v )
{
return ( v&0xff ) << 24 | ( v&0xff00 ) << 8 |
( v&0xff0000 ) >> 8 | ( v&0xff000000 ) >> 24;
}
static inline unsigned int endianSwapWordByHalf( unsigned int v )
{
return ( v&0xffff ) << 16 | v >> 16;
}
static inline int rglLog2( unsigned int i )
{
int l = 0;
while ( i )
{
++l;
i >>= 1;
}
return l -1;
}
static inline int rglIsPow2( unsigned int i )
{
return ( i&( i - 1 ) ) == 0;
}
// Pad argument x to the next multiple of argument pad.
static inline unsigned long rglPad( unsigned long x, unsigned long pad )
{
return ( x + pad - 1 ) / pad*pad;
}
// Pad pointer x to the next multiple of argument pad.
static inline char* rglPadPtr( const char* p, unsigned int pad )
{
intptr_t x = (intptr_t)p;
x = ( x + pad - 1 ) / pad * pad;
return ( char* )x;
}
// names API
RGL_EXPORT void rglInitNameSpace( struct rglNameSpace * name );
RGL_EXPORT void rglFreeNameSpace( struct rglNameSpace * name );
RGL_EXPORT unsigned int rglCreateName( struct rglNameSpace * ns, void* object );
RGL_EXPORT unsigned int rglIsName( struct rglNameSpace* ns, unsigned int name );
RGL_EXPORT void rglEraseName( struct rglNameSpace* ns, unsigned int name );
static inline void * rglGetNamedValue( struct rglNameSpace* ns, unsigned int name )
{
return ns->data[name - 1];
}
void rglTexNameSpaceInit( rglTexNameSpace *ns, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy );
void rglTexNameSpaceFree( rglTexNameSpace *ns );
void rglTexNameSpaceResetNames( rglTexNameSpace *ns );
GLuint rglTexNameSpaceGetFree( rglTexNameSpace *ns );
GLboolean rglTexNameSpaceCreateNameLazy( rglTexNameSpace *ns, GLuint name );
GLboolean rglTexNameSpaceIsName( rglTexNameSpace *ns, GLuint name );
void rglTexNameSpaceGenNames( rglTexNameSpace *ns, GLsizei n, GLuint *names );
void rglTexNameSpaceDeleteNames( rglTexNameSpace *ns, GLsizei n, const GLuint *names );
void rglTexNameSpaceReinit( rglTexNameSpace * saved, rglTexNameSpace * active );
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration that encloses file.
#endif
#ifndef RGLT_UNUSED
#ifdef MSVC
#define RGL_UNUSED(value) value;
#else
#define RGL_UNUSED(value) do { \
__typeof__(value) rglUnused = value; \
(void)rglUnused; \
} while(false)
#endif
#endif
#endif // _RGL_UTILS_H_

View File

@ -0,0 +1,12 @@
#ifndef _PLATFORM_H
#define _PLATFORM_H
#include "../export/RGL/rgl.h"
#define RGL_LITTLE_ENDIAN 0x1234
#define RGL_BIG_ENDIAN 0x4321
#define RGL_ENDIAN RGL_BIG_ENDIAN
#define RGL_ALIGN_FAST_TRANSFER 128
#endif

View File

@ -0,0 +1,329 @@
#ifndef _RGLPrivate_h
#define _RGLPrivate_h
#include "../export/RGL/rgl.h"
#include "Types.h"
#include "Utils.h"
#include "ReportInternal.h"
#ifndef OS_VERSION_NUMERIC
#define OS_VERSION_NUMERIC 0x160
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __cplusplus
#define _RGL_EXTERN_C extern "C"
#else
#define _RGL_EXTERN_C
#endif
extern RGL_EXPORT RGLcontext* _CurrentContext;
extern RGLdevice* _CurrentDevice;
extern RGL_EXPORT char* rglVersion;
// only for internal purpose
#define GL_UNSIGNED_BYTE_4_4 0x4A00
#define GL_UNSIGNED_BYTE_4_4_REV 0x4A01
#define GL_UNSIGNED_BYTE_6_2 0x4A02
#define GL_UNSIGNED_BYTE_2_6_REV 0x4A03
#define GL_UNSIGNED_SHORT_12_4 0x4A04
#define GL_UNSIGNED_SHORT_4_12_REV 0x4A05
#define GL_UNSIGNED_BYTE_2_2_2_2 0x4A06
#define GL_UNSIGNED_BYTE_2_2_2_2_REV 0x4A07
#define GL_FLOAT_RGBA32 0x888B
//------------------------------------------------------------------------
// Function prototypes
//------------------------------------------------------------------------
//----------------------------------------
// RGL.c
//----------------------------------------
typedef void( * RGLcontextHookFunction )( RGLcontext *context );
extern RGL_EXPORT RGLcontextHookFunction rglContextCreateHook;
extern RGL_EXPORT RGLcontextHookFunction rglContextDestroyHook;
extern RGLcontext* rglContextCreate();
extern void rglContextFree( RGLcontext* LContext );
extern void rglSetError( GLenum error );
extern GLuint rglValidateStates( GLuint mask );
void rglAttachContext( RGLdevice *device, RGLcontext* context );
void rglDetachContext( RGLdevice *device, RGLcontext* context );
void rglInvalidateAllStates( RGLcontext* context );
void rglResetAttributeState( rglAttributeState* as );
void rglSetFlipHandler(void (*handler)(const GLuint head), RGLdevice *device);
void rglSetVBlankHandler(void (*handler)(const GLuint head), RGLdevice *device);
//----------------------------------------
// Texture.c
//----------------------------------------
rglTexture *rglAllocateTexture();
void rglFreeTexture( rglTexture *texture );
void rglTextureUnbind( RGLcontext* context, GLuint name );
extern int rglTextureInit( RGLcontext* context, GLuint name );
extern void rglTextureDelete( RGLcontext* context, GLuint name );
extern GLboolean rglTextureHasValidLevels( const rglTexture *texture, int levels, int width, int height, int depth, GLenum format, GLenum type, GLenum internalFormat );
extern GLboolean rglTextureIsValid( const rglTexture* texture );
GLenum rglGetEnabledTextureMode( const rglTextureImageUnit *unit );
extern rglTexture *rglGetCurrentTexture( const rglTextureImageUnit *unit, GLenum target );
RGL_EXPORT void rglUpdateCurrentTextureCache( rglTextureImageUnit *unit );
void rglReallocateImages( rglTexture *texture, GLint level, GLsizei dimension );
extern int rglGetImage( GLenum target, GLint level, rglTexture **texture, rglImage **image, GLsizei reallocateSize );
static inline rglTexture* rglGetTexture( RGLcontext *LContext, GLuint name )
{
return ( rglTexture* )LContext->textureNameSpace.data[name];
}
static inline rglTexture* rglGetTextureSafe( RGLcontext *LContext, GLuint name )
{
return rglTexNameSpaceIsName( &LContext->textureNameSpace, name ) ? ( rglTexture* )LContext->textureNameSpace.data[name] : NULL;
}
static inline rglFramebuffer *rglGetFramebuffer( RGLcontext *LContext, GLuint name );
inline static void rglTextureTouchFBOs( rglTexture *texture )
{
RGLcontext *LContext = _CurrentContext;
if ( !LContext ) return; // may be called in psglDestroyContext
// check if bound to any framebuffer
GLuint fbCount = texture->framebuffers.getCount();
if ( fbCount > 0 )
{
rglFramebuffer *contextFramebuffer = LContext->framebuffer ? rglGetFramebuffer( LContext, LContext->framebuffer ) : NULL;
for ( GLuint i = 0;i < fbCount;++i )
{
rglFramebuffer* framebuffer = texture->framebuffers[i];
framebuffer->needValidate = GL_TRUE;
if ( RGL_UNLIKELY( framebuffer == contextFramebuffer ) ) LContext->needValidate |= PSGL_VALIDATE_SCISSOR_BOX | PSGL_VALIDATE_FRAMEBUFFER;
}
}
}
//----------------------------------------
// Image.c
//----------------------------------------
GLboolean rglIsType( GLenum type );
GLboolean rglIsFormat( GLenum format );
GLboolean rglIsValidPair( GLenum format, GLenum type );
void rglImageAllocCPUStorage( rglImage *image );
void rglImageFreeCPUStorage( rglImage *image );
extern void rglSetImage( rglImage* image, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const GLvoid* pixels );
extern void rglSetSubImage( GLenum target, GLint level, rglTexture *texture, rglImage* image, GLint x, GLint y, GLint z, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const GLvoid* pixels );
extern int rglGetPixelSize( GLenum format, GLenum type );
static inline int rglGetStorageSize( GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth )
{
return rglGetPixelSize( format, type )*width*height*depth;
}
extern int rglGetTypeSize( GLenum type );
extern int rglGetMaxBitSize( GLenum type );
extern int rglGetStorageSize( GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth );
extern void rglImageToRaster( const rglImage* image, rglRaster* raster, GLuint x, GLuint y, GLuint z );
extern void rglRasterToImage( const rglRaster* raster, rglImage* image, GLuint x, GLuint y, GLuint z );
extern void rglRawRasterToImage( const rglRaster* raster, rglImage* image, GLuint x, GLuint y, GLuint z );
void rglResampleImage3D( rglImage* src, rglImage* dst );
//----------------------------------------
// Sync.c
//----------------------------------------
rglFenceObject *rglCreateFenceObject();
void rglFreeFenceObject( rglFenceObject *fence );
static inline rglFenceObject *rglGetFenceObject( RGLcontext *LContext, GLuint name )
{
return ( rglFenceObject * )LContext->fenceObjectNameSpace.data[name];
}
//----------------------------------------
// FramebufferObject.c
//----------------------------------------
rglFramebuffer *rglCreateFramebuffer( void );
void rglDestroyFramebuffer( rglFramebuffer *framebuffer );
static inline rglFramebuffer *rglGetFramebuffer( RGLcontext *LContext, GLuint name )
{
return ( rglFramebuffer * )LContext->framebufferNameSpace.data[name];
}
static inline rglFramebuffer *rglGetFramebufferSafe( RGLcontext *LContext, GLuint name )
{
return rglTexNameSpaceIsName( &LContext->framebufferNameSpace, name ) ? ( rglFramebuffer * )LContext->framebufferNameSpace.data[name] : NULL;
}
void rglFramebufferGetAttachmentTexture( RGLcontext* LContext, const rglFramebufferAttachment* attachment, rglTexture** texture, GLuint* face );
GLenum rglPlatformFramebufferCheckStatus( rglFramebuffer* framebuffer );
GLboolean rglPlatformGenerateMipmap( rglTexture* texture, GLuint face );
void rglPlatformFramebufferGetParameteriv( GLenum pname, GLint* params );
void rglPlatformResolveFramebuffer();
void rglGetFramebufferSize( GLuint* width, GLuint* height );
//----------------------------------------
// VertexArray.c
//----------------------------------------
void rglVertexAttrib1fNV( GLuint index, GLfloat x );
void rglVertexAttrib1fvNV( GLuint index, const GLfloat* v );
void rglVertexAttrib2fNV( GLuint index, GLfloat x, GLfloat y );
void rglVertexAttrib2fvNV( GLuint index, const GLfloat* v );
void rglVertexAttrib3fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z );
void rglVertexAttrib3fvNV( GLuint index, const GLfloat* v );
void rglVertexAttrib4fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w );
void rglVertexAttrib4fvNV( GLuint index, const GLfloat* v );
void rglVertexAttribPointerNV( GLuint index, GLint fsize, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer );
void rglVertexAttribElementFunc( GLuint index, GLenum func, GLuint frequency );
void rglEnableVertexAttribArrayNV( GLuint index );
void rglDisableVertexAttribArrayNV( GLuint index );
GLint rglConvertStream( rglAttributeState* asDst, const rglAttributeState* asSrc, GLuint index,
GLint skip, GLint first, GLint count,
const void* indices, GLenum indexType );
void rglComputeMinMaxIndices( RGLcontext* LContext, GLuint* min, GLuint* max, const void* indices, GLenum indexType, GLsizei count );
//----------------------------------------
// Platform/Init.c
//----------------------------------------
extern void rglPlatformInit( PSGLinitOptions* options );
extern void rglPlatformExit();
//----------------------------------------
// Device/Device.c
//----------------------------------------
extern void rglDeviceInit( PSGLinitOptions* options );
extern void rglDeviceExit();
extern PSGLdeviceParameters * rglShadowDeviceParameters( void );
//----------------------------------------
// Device/.../PlatformDevice.c
//----------------------------------------
extern GLboolean rglPlatformDeviceInit( PSGLinitOptions* options );
extern void rglPlatformDeviceExit();
extern int rglPlatformDeviceSize();
extern int rglPlatformCreateDevice( RGLdevice* device );
extern void rglPlatformDestroyDevice( RGLdevice* device );
extern void rglPlatformMakeCurrent( void* device );
extern void rglPlatformSwapBuffers( RGLdevice* device );
extern const GLvoid* rglPlatformGetProcAddress( const char *funcName );
//----------------------------------------
// Raster/.../PlatformRaster.c
//----------------------------------------
void* rglPlatformRasterInit();
void rglPlatformRasterExit( void* driver );
void rglPlatformRasterDestroyResources();
void rglPlatformDraw( rglDrawParams* dparams );
GLboolean rglPlatformNeedsConversion( const rglAttributeState* as, GLuint index );
// [YLIN] Try to avoid LHS inside this function.
// In oringinal implementation, indexType and indexCount will be stored right before this function
// and since we will load them right after enter this function, there are LHS.
GLboolean rglPlatformRequiresSlowPath( rglDrawParams* dparams, const GLenum indexType, uint32_t indexCount);
void rglPlatformRasterGetIntegerv( GLenum pname, GLint* params );
void rglPlatformRasterFlush();
void rglPlatformRasterFinish();
void rglValidateFragmentProgram();
void rglValidateFragmentProgramSharedConstants();
void rglValidateClipPlanes();
void rglInvalidateAttributes();
GLuint rglValidateAttributes( const GLvoid* indices, GLboolean *isMain );
GLuint rglValidateAttributesSlow( rglDrawParams *dparams, GLboolean *isMain );
//----------------------------------------
// Raster/.../PlatformTexture.c
//----------------------------------------
extern int rglPlatformTextureSize();
extern int rglPlatformTextureMaxUnits();
extern void rglPlatformCreateTexture( rglTexture* texture );
extern void rglPlatformDestroyTexture( rglTexture* texture );
extern void rglPlatformValidateTextureStage( int unit, rglTexture*texture );
void rglPlatformValidateVertexTextures();
extern GLenum rglPlatformChooseInternalStorage( rglImage* image, GLenum internalformat );
extern GLenum rglPlatformTranslateTextureFormat( GLenum internalFormat );
extern void rglPlatformCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
GLenum rglPlatformChooseInternalFormat( GLenum internalformat );
void rglPlatformExpandInternalFormat( GLenum internalformat, GLenum *format, GLenum *type );
void rglPlatformGetImageData( GLenum target, GLint level, rglTexture *texture, rglImage *image );
extern void rglPlatformSetCompressedTexture(
GLenum target,
GLint level,
GLenum internalformat,
GLsizei width, GLsizei height, GLsizei depth,
GLint border,
GLsizei imageSize,
const GLvoid* data );
extern void rglPlatformSetCompressedTextureSub(
GLenum target,
GLint level,
GLint xoffset, GLint yoffset, GLint zoffset,
GLsizei width, GLsizei height, GLsizei depth,
GLenum format,
GLsizei imageSize,
const GLvoid* data );
extern GLboolean rglPlatformTexturePBOImage(
rglTexture* texture,
rglImage* image,
GLint level,
GLint internalformat,
GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type,
const GLvoid *offset );
extern GLboolean rglPlatformTexturePBOSubImage(
rglTexture* texture,
rglImage* image,
GLint level,
GLint xoffset, GLint yoffset, GLint zoffset,
GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type,
const GLvoid *pixels );
GLboolean rglPlatformTextureReference( rglTexture *texture, GLuint pitch, rglBufferObject *bufferObject, GLintptr offset );
//----------------------------------------
// Raster/.../PlatformFBops.c
//----------------------------------------
extern void rglFBClear( GLbitfield mask );
extern void rglValidateFramebuffer( void );
extern void rglValidateFFXVertexProgram();
extern void rglValidateFFXFragmentProgram();
extern void rglPlatformReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLboolean flip, GLenum format, GLenum type, GLvoid *pixels );
extern GLboolean rglPlatformReadPBOPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLboolean flip, GLenum format, GLenum type, GLvoid *pixels );
//----------------------------------------
// Raster/.../PlatformTNL.c
//----------------------------------------
void rglValidateNormalize();
void rglValidateVertexProgram();
void rglValidateVertexConstants();
//----------------------------------------
// Raster/.../PlatformBuffer.c
//----------------------------------------
int rglPlatformBufferObjectSize();
GLboolean rglPlatformCreateBufferObject( rglBufferObject* bufferObject );
void rglPlatformDestroyBufferObject( rglBufferObject* bufferObject );
void rglPlatformBufferObjectSetData( rglBufferObject* bufferObject, GLintptr offset, GLsizeiptr size, const GLvoid *data, GLboolean tryImmediateCopy );
GLvoid rglPlatformBufferObjectCopyData( rglBufferObject* bufferObjectDst, rglBufferObject* bufferObjectSrc );
// map / unmap buffers. Internally refcounted
char *rglPlatformBufferObjectMap( rglBufferObject* bufferObject, GLenum access );
GLboolean rglPlatformBufferObjectUnmap( rglBufferObject* bufferObject );
void rglPlatformGetBufferParameteriv( rglBufferObject *bufferObject, GLenum pname, int *params );
// this is shared in glBindTexture and cgGL code
RGL_EXPORT void rglBindTextureInternal( rglTextureImageUnit *unit, GLuint name, GLenum target );
void rglBindVertexTextureInternal( GLuint unit, GLuint name );
//----------------------------------------
// Raster/.../PlatformSync.c
//----------------------------------------
int rglPlatformFenceObjectSize();
GLboolean rglPlatformCreateFenceObject( rglFenceObject* fenceObject );
void rglPlatformDestroyFenceObject( rglFenceObject* fenceObject );
void rglPlatformSetFence( rglFenceObject* fenceObject );
GLboolean rglPlatformTestFence( rglFenceObject* fenceObject );
void rglPlatformFinishFence( rglFenceObject* fenceObject );
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration that encloses file.
#endif
#endif // _RGLPrivate_h

View File

@ -0,0 +1,551 @@
#ifndef __gl_h_
#define __gl_h_
#ifdef __cplusplus
extern "C"
{
#endif
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.0 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
#ifdef RGL_EXPORT
#define GLAPI RGL_EXPORT
#endif
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SYMBIAN32__)
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef GLAPI
#define GLAPI extern
#endif
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef int GLsizei;
typedef unsigned char GLubyte;
typedef unsigned short GLushort;
typedef unsigned int GLuint;
typedef float GLfloat;
typedef float GLclampf;
typedef void GLvoid;
typedef int GLfixed;
typedef int GLclampx;
/* Internal convenience typedefs */
typedef void( *_GLfuncptr )();
/*************************************************************/
/* Extensions */
#define GL_OES_VERSION_1_0 1
#define GL_OES_read_format 1
#define GL_OES_compressed_paletted_texture 1
/* ClearBufferMask */
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_STENCIL_BUFFER_BIT 0x00000400
#define GL_COLOR_BUFFER_BIT 0x00004000
/* Boolean */
#define GL_FALSE 0
#define GL_TRUE 1
/* BeginMode */
#define GL_POINTS 0x0000
#define GL_LINES 0x0001
#define GL_LINE_LOOP 0x0002
#define GL_LINE_STRIP 0x0003
#define GL_TRIANGLES 0x0004
#define GL_TRIANGLE_STRIP 0x0005
#define GL_TRIANGLE_FAN 0x0006
/* AlphaFunction */
#define GL_NEVER 0x0200
#define GL_LESS 0x0201
#define GL_EQUAL 0x0202
#define GL_LEQUAL 0x0203
#define GL_GREATER 0x0204
#define GL_NOTEQUAL 0x0205
#define GL_GEQUAL 0x0206
#define GL_ALWAYS 0x0207
/* BlendingFactorDest */
#define GL_ZERO 0
#define GL_ONE 1
#define GL_SRC_COLOR 0x0300
#define GL_ONE_MINUS_SRC_COLOR 0x0301
#define GL_SRC_ALPHA 0x0302
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
#define GL_DST_ALPHA 0x0304
#define GL_ONE_MINUS_DST_ALPHA 0x0305
/* BlendingFactorSrc */
/* GL_ZERO */
/* GL_ONE */
#define GL_DST_COLOR 0x0306
#define GL_ONE_MINUS_DST_COLOR 0x0307
#define GL_SRC_ALPHA_SATURATE 0x0308
/* GL_SRC_ALPHA */
/* GL_ONE_MINUS_SRC_ALPHA */
/* GL_DST_ALPHA */
/* GL_ONE_MINUS_DST_ALPHA */
/* ColorMaterialFace */
/* GL_FRONT_AND_BACK */
/* ColorMaterialParameter */
/* GL_AMBIENT_AND_DIFFUSE */
/* ColorPointerType */
/* GL_UNSIGNED_BYTE */
/* GL_FLOAT */
/* GL_FIXED */
/* CullFaceMode */
#define GL_FRONT 0x0404
#define GL_BACK 0x0405
#define GL_FRONT_AND_BACK 0x0408
/* DepthFunction */
/* GL_NEVER */
/* GL_LESS */
/* GL_EQUAL */
/* GL_LEQUAL */
/* GL_GREATER */
/* GL_NOTEQUAL */
/* GL_GEQUAL */
/* GL_ALWAYS */
/* EnableCap */
#define GL_FOG 0x0B60
#define GL_LIGHTING 0x0B50
#define GL_TEXTURE_2D 0x0DE1
#define GL_CULL_FACE 0x0B44
#define GL_BLEND 0x0BE2
#define GL_COLOR_LOGIC_OP 0x0BF2
#define GL_DITHER 0x0BD0
#define GL_STENCIL_TEST 0x0B90
#define GL_DEPTH_TEST 0x0B71
/* GL_LIGHT0 */
/* GL_LIGHT1 */
/* GL_LIGHT2 */
/* GL_LIGHT3 */
/* GL_LIGHT4 */
/* GL_LIGHT5 */
/* GL_LIGHT6 */
/* GL_LIGHT7 */
#define GL_POINT_SMOOTH 0x0B10
#define GL_LINE_SMOOTH 0x0B20
#define GL_SCISSOR_TEST 0x0C11
#define GL_COLOR_MATERIAL 0x0B57
#define GL_NORMALIZE 0x0BA1
#define GL_RESCALE_NORMAL 0x803A
#define GL_POLYGON_OFFSET_FILL 0x8037
#define GL_VERTEX_ARRAY 0x8074
#define GL_NORMAL_ARRAY 0x8075
#define GL_COLOR_ARRAY 0x8076
#define GL_TEXTURE_COORD_ARRAY 0x8078
#define GL_MULTISAMPLE 0x809D
#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
#define GL_SAMPLE_COVERAGE 0x80A0
/* ErrorCode */
#define GL_NO_ERROR 0
#define GL_INVALID_ENUM 0x0500
#define GL_INVALID_VALUE 0x0501
#define GL_INVALID_OPERATION 0x0502
#define GL_STACK_OVERFLOW 0x0503
#define GL_STACK_UNDERFLOW 0x0504
#define GL_OUT_OF_MEMORY 0x0505
/* FogMode */
/* GL_LINEAR */
#define GL_EXP 0x0800
#define GL_EXP2 0x0801
/* FogParameter */
#define GL_FOG_DENSITY 0x0B62
#define GL_FOG_START 0x0B63
#define GL_FOG_END 0x0B64
#define GL_FOG_MODE 0x0B65
#define GL_FOG_COLOR 0x0B66
/* FrontFaceDirection */
#define GL_CW 0x0900
#define GL_CCW 0x0901
/* GetPName */
#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A
#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B
#define GL_MAX_LIGHTS 0x0D31
#define GL_MAX_TEXTURE_SIZE 0x0D33
#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
#define GL_MAX_VIEWPORT_DIMS 0x0D3A
#define GL_MAX_ELEMENTS_VERTICES 0x80E8
#define GL_MAX_ELEMENTS_INDICES 0x80E9
#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
#define GL_SUBPIXEL_BITS 0x0D50
/* HintMode */
#define GL_DONT_CARE 0x1100
#define GL_FASTEST 0x1101
#define GL_NICEST 0x1102
/* HintTarget */
#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
#define GL_POINT_SMOOTH_HINT 0x0C51
#define GL_LINE_SMOOTH_HINT 0x0C52
#define GL_POLYGON_SMOOTH_HINT 0x0C53
#define GL_FOG_HINT 0x0C54
/* LightModelParameter */
#define GL_LIGHT_MODEL_AMBIENT 0x0B53
#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
/* LightParameter */
#define GL_AMBIENT 0x1200
#define GL_DIFFUSE 0x1201
#define GL_SPECULAR 0x1202
#define GL_POSITION 0x1203
#define GL_SPOT_DIRECTION 0x1204
#define GL_SPOT_EXPONENT 0x1205
#define GL_SPOT_CUTOFF 0x1206
#define GL_CONSTANT_ATTENUATION 0x1207
#define GL_LINEAR_ATTENUATION 0x1208
#define GL_QUADRATIC_ATTENUATION 0x1209
/* DataType */
#define GL_BYTE 0x1400
#define GL_UNSIGNED_BYTE 0x1401
#define GL_SHORT 0x1402
#define GL_UNSIGNED_SHORT 0x1403
#define GL_FLOAT 0x1406
#define GL_FIXED 0x140C
/* LogicOp */
#define GL_CLEAR 0x1500
#define GL_AND 0x1501
#define GL_AND_REVERSE 0x1502
#define GL_COPY 0x1503
#define GL_AND_INVERTED 0x1504
#define GL_NOOP 0x1505
#define GL_XOR 0x1506
#define GL_OR 0x1507
#define GL_NOR 0x1508
#define GL_EQUIV 0x1509
#define GL_INVERT 0x150A
#define GL_OR_REVERSE 0x150B
#define GL_COPY_INVERTED 0x150C
#define GL_OR_INVERTED 0x150D
#define GL_NAND 0x150E
#define GL_SET 0x150F
/* MaterialFace */
/* GL_FRONT_AND_BACK */
/* MaterialParameter */
#define GL_EMISSION 0x1600
#define GL_SHININESS 0x1601
#define GL_AMBIENT_AND_DIFFUSE 0x1602
/* GL_AMBIENT */
/* GL_DIFFUSE */
/* GL_SPECULAR */
/* MatrixMode */
#define GL_MODELVIEW 0x1700
#define GL_PROJECTION 0x1701
#define GL_TEXTURE 0x1702
/* NormalPointerType */
/* GL_BYTE */
/* GL_SHORT */
/* GL_FLOAT */
/* GL_FIXED */
/* PixelFormat */
#define GL_ALPHA 0x1906
#define GL_RGB 0x1907
#define GL_RGBA 0x1908
/* PixelStoreParameter */
#define GL_UNPACK_ALIGNMENT 0x0CF5
#define GL_PACK_ALIGNMENT 0x0D05
/* PixelType */
/* GL_UNSIGNED_BYTE */
#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
/* ShadingModel */
#define GL_FLAT 0x1D00
#define GL_SMOOTH 0x1D01
/* StencilFunction */
/* GL_NEVER */
/* GL_LESS */
/* GL_EQUAL */
/* GL_LEQUAL */
/* GL_GREATER */
/* GL_NOTEQUAL */
/* GL_GEQUAL */
/* GL_ALWAYS */
/* StencilOp */
/* GL_ZERO */
#define GL_KEEP 0x1E00
#define GL_REPLACE 0x1E01
#define GL_INCR 0x1E02
#define GL_DECR 0x1E03
/* GL_INVERT */
/* StringName */
#define GL_VENDOR 0x1F00
#define GL_RENDERER 0x1F01
#define GL_VERSION 0x1F02
#define GL_EXTENSIONS 0x1F03
/* TexCoordPointerType */
/* GL_SHORT */
/* GL_FLOAT */
/* GL_FIXED */
/* GL_BYTE */
/* TextureEnvMode */
#define GL_MODULATE 0x2100
#define GL_DECAL 0x2101
/* GL_BLEND */
#define GL_ADD 0x0104
/* GL_REPLACE */
/* TextureEnvParameter */
#define GL_TEXTURE_ENV_MODE 0x2200
#define GL_TEXTURE_ENV_COLOR 0x2201
/* TextureEnvTarget */
#define GL_TEXTURE_ENV 0x2300
/* TextureMagFilter */
#define GL_NEAREST 0x2600
#define GL_LINEAR 0x2601
/* TextureMinFilter */
/* GL_NEAREST */
/* GL_LINEAR */
#define GL_NEAREST_MIPMAP_NEAREST 0x2700
#define GL_LINEAR_MIPMAP_NEAREST 0x2701
#define GL_NEAREST_MIPMAP_LINEAR 0x2702
#define GL_LINEAR_MIPMAP_LINEAR 0x2703
/* TextureParameterName */
#define GL_TEXTURE_MAG_FILTER 0x2800
#define GL_TEXTURE_MIN_FILTER 0x2801
#define GL_TEXTURE_WRAP_S 0x2802
#define GL_TEXTURE_WRAP_T 0x2803
/* TextureTarget */
/* GL_TEXTURE_2D */
/* TextureUnit */
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
#define GL_TEXTURE5 0x84C5
#define GL_TEXTURE6 0x84C6
#define GL_TEXTURE7 0x84C7
#define GL_TEXTURE8 0x84C8
#define GL_TEXTURE9 0x84C9
#define GL_TEXTURE10 0x84CA
#define GL_TEXTURE11 0x84CB
#define GL_TEXTURE12 0x84CC
#define GL_TEXTURE13 0x84CD
#define GL_TEXTURE14 0x84CE
#define GL_TEXTURE15 0x84CF
#define GL_TEXTURE16 0x84D0
#define GL_TEXTURE17 0x84D1
#define GL_TEXTURE18 0x84D2
#define GL_TEXTURE19 0x84D3
#define GL_TEXTURE20 0x84D4
#define GL_TEXTURE21 0x84D5
#define GL_TEXTURE22 0x84D6
#define GL_TEXTURE23 0x84D7
#define GL_TEXTURE24 0x84D8
#define GL_TEXTURE25 0x84D9
#define GL_TEXTURE26 0x84DA
#define GL_TEXTURE27 0x84DB
#define GL_TEXTURE28 0x84DC
#define GL_TEXTURE29 0x84DD
#define GL_TEXTURE30 0x84DE
#define GL_TEXTURE31 0x84DF
/* TextureWrapMode */
#define GL_REPEAT 0x2901
#define GL_CLAMP_TO_EDGE 0x812F
/* PixelInternalFormat */
#define GL_PALETTE4_RGB8_OES 0x8B90
#define GL_PALETTE4_RGBA8_OES 0x8B91
#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
#define GL_PALETTE4_RGBA4_OES 0x8B93
#define GL_PALETTE4_RGB5_A1_OES 0x8B94
#define GL_PALETTE8_RGB8_OES 0x8B95
#define GL_PALETTE8_RGBA8_OES 0x8B96
#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
#define GL_PALETTE8_RGBA4_OES 0x8B98
#define GL_PALETTE8_RGB5_A1_OES 0x8B99
/* VertexPointerType */
/* GL_SHORT */
/* GL_FLOAT */
/* GL_FIXED */
/* GL_BYTE */
/* LightName */
#define GL_LIGHT0 0x4000
#define GL_LIGHT1 0x4001
#define GL_LIGHT2 0x4002
#define GL_LIGHT3 0x4003
#define GL_LIGHT4 0x4004
#define GL_LIGHT5 0x4005
#define GL_LIGHT6 0x4006
#define GL_LIGHT7 0x4007
/*************************************************************/
GLAPI void APIENTRY glActiveTexture( GLenum texture );
GLAPI void APIENTRY glAlphaFunc( GLenum func, GLclampf ref );
GLAPI void APIENTRY glAlphaFuncx( GLenum func, GLclampx ref );
GLAPI void APIENTRY glBindTexture( GLenum target, GLuint texture );
GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor );
GLAPI void APIENTRY glClear( GLbitfield mask );
GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
GLAPI void APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha );
GLAPI void APIENTRY glClearDepthf( GLclampf depth );
GLAPI void APIENTRY glClearDepthx( GLclampx depth );
GLAPI void APIENTRY glClearStencil( GLint s );
GLAPI void APIENTRY glClientActiveTexture( GLenum texture );
GLAPI void APIENTRY glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha );
GLAPI void APIENTRY glColor4x( GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha );
GLAPI void APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha );
GLAPI void APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border );
GLAPI void APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height );
GLAPI void APIENTRY glCullFace( GLenum mode );
GLAPI void APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures );
GLAPI void APIENTRY glDepthFunc( GLenum func );
GLAPI void APIENTRY glDepthMask( GLboolean flag );
GLAPI void APIENTRY glDepthRangef( GLclampf zNear, GLclampf zFar );
GLAPI void APIENTRY glDepthRangex( GLclampx zNear, GLclampx zFar );
GLAPI void APIENTRY glDisable( GLenum cap );
GLAPI void APIENTRY glDisableClientState( GLenum array );
GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count );
GLAPI void APIENTRY glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices );
GLAPI void APIENTRY glEnable( GLenum cap );
GLAPI void APIENTRY glEnableClientState( GLenum array );
GLAPI void APIENTRY glFinish( void );
GLAPI void APIENTRY glFlush( void );
GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures );
GLAPI GLenum APIENTRY glGetError( void );
GLAPI void APIENTRY glGetIntegerv( GLenum pname, GLint *params );
GLAPI const GLubyte * APIENTRY glGetString( GLenum name );
GLAPI void APIENTRY glHint( GLenum target, GLenum mode );
GLAPI void APIENTRY glLineWidth( GLfloat width );
GLAPI void APIENTRY glLineWidthx( GLfixed width );
GLAPI void APIENTRY glLoadIdentity( void );
GLAPI void APIENTRY glLogicOp( GLenum opcode );
GLAPI void APIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param );
GLAPI void APIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params );
GLAPI void APIENTRY glMaterialx( GLenum face, GLenum pname, GLfixed param );
GLAPI void APIENTRY glMaterialxv( GLenum face, GLenum pname, const GLfixed *params );
GLAPI void APIENTRY glMatrixMode( GLenum mode );
GLAPI void APIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q );
GLAPI void APIENTRY glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q );
GLAPI void APIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz );
GLAPI void APIENTRY glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz );
GLAPI void APIENTRY glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar );
GLAPI void APIENTRY glOrthox( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar );
GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param );
GLAPI void APIENTRY glPointSize( GLfloat size );
GLAPI void APIENTRY glPointSizex( GLfixed size );
GLAPI void APIENTRY glPolygonOffset( GLfloat factor, GLfloat units );
GLAPI void APIENTRY glPolygonOffsetx( GLfixed factor, GLfixed units );
GLAPI void APIENTRY glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels );
GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z );
GLAPI void APIENTRY glRotatex( GLfixed angle, GLfixed x, GLfixed y, GLfixed z );
GLAPI void APIENTRY glSampleCoverage( GLclampf value, GLboolean invert );
GLAPI void APIENTRY glSampleCoveragex( GLclampx value, GLboolean invert );
GLAPI void APIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z );
GLAPI void APIENTRY glScalex( GLfixed x, GLfixed y, GLfixed z );
GLAPI void APIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height );
GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param );
GLAPI void APIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params );
GLAPI void APIENTRY glTexEnvx( GLenum target, GLenum pname, GLfixed param );
GLAPI void APIENTRY glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params );
GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels );
GLAPI void APIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param );
GLAPI void APIENTRY glTexParameterx( GLenum target, GLenum pname, GLfixed param );
GLAPI void APIENTRY glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels );
GLAPI void APIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z );
GLAPI void APIENTRY glTranslatex( GLfixed x, GLfixed y, GLfixed z );
GLAPI void APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height );
#ifdef __cplusplus
}
#endif
#endif /* __gl_h_ */

View File

@ -0,0 +1,421 @@
#ifndef __gl_ext_h_
#define __gl_ext_h_
#ifndef _MSC_VER
#include <stdint.h>
#else
#include <stddef.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
typedef intptr_t GLintptr;
typedef intptr_t GLsizeiptr;
typedef unsigned short GLhalfARB;
#define GL_QUADS 0x0007
#define GL_QUAD_STRIP 0x0008
#define GL_INT 0x1404
#define GL_UNSIGNED_INT 0x1405
/* Image types */
#define GL_UNSIGNED_BYTE_3_3_2 0x8032
#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
#define GL_UNSIGNED_INT_8_8_8_8 0x8035
#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
#define GL_UNSIGNED_INT_10_10_10_2 0x8036
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
#define GL_UNSIGNED_INT_24_8_SCE 0x6008
#define GL_UNSIGNED_INT_8_24_REV_SCE 0x6009
#define GL_HALF_FLOAT_ARB 0x140B
/* Image internal formats */
#define GL_ALPHA4 0x803B
#define GL_ALPHA12 0x803D
#define GL_ALPHA16 0x803E
#define GL_R3_G3_B2 0x2A10
#define GL_RGB4 0x804F
#define GL_RGB5 0x8050
#define GL_RGB8 0x8051
#define GL_RGBA2 0x8055
#define GL_RGBA4 0x8056
#define GL_RGB5_A1 0x8057
#define GL_RGBA12 0x805A
#define GL_RGBA16 0x805B
#define GL_BGR 0x80E0
#define GL_BGRA 0x80E1
#define GL_ABGR 0x8000
#define GL_RED 0x1903
#define GL_GREEN 0x1904
#define GL_BLUE 0x1905
#define GL_ARGB_SCE 0x6007
#define GL_RGBA32F_ARB 0x8814
#define GL_RGB32F_ARB 0x8815
#define GL_ALPHA32F_ARB 0x8816
#define GL_RGBA16F_ARB 0x881A
#define GL_RGB16F_ARB 0x881B
#define GL_ALPHA16F_ARB 0x881C
#define GL_UNSIGNED_SHORT_8_8_SCE 0x600B
#define GL_UNSIGNED_SHORT_8_8_REV_SCE 0x600C
#define GL_UNSIGNED_INT_16_16_SCE 0x600D
#define GL_UNSIGNED_INT_16_16_REV_SCE 0x600E
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
/* TexGen */
#define GL_EYE_LINEAR 0x2400
#define GL_OBJECT_LINEAR 0x2401
#define GL_SPHERE_MAP 0x2402
#define GL_NORMAL_MAP 0x8511
#define GL_REFLECTION_MAP 0x8512
#define GL_S 0x2000
#define GL_T 0x2001
#define GL_R 0x2002
#define GL_Q 0x2003
#define GL_OBJECT_PLANE 0x2501
#define GL_EYE_PLANE 0x2502
#define GL_TEXTURE_GEN_MODE 0x2500
#define GL_TEXTURE_GEN_S 0x0C60
#define GL_TEXTURE_GEN_T 0x0C61
#define GL_TEXTURE_GEN_R 0x0C62
#define GL_TEXTURE_GEN_Q 0x0C63
/* Blending */
#define GL_CONSTANT_COLOR 0x8001
#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
#define GL_CONSTANT_ALPHA 0x8003
#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
#define GL_BLEND_EQUATION 0x8009
#define GL_FUNC_ADD 0x8006
#define GL_MIN 0x8007
#define GL_MAX 0x8008
#define GL_FUNC_SUBTRACT 0x800A
#define GL_FUNC_REVERSE_SUBTRACT 0x800B
/* Texture3D */
#define GL_TEXTURE_3D 0x806F
#define GL_TEXTURE_WRAP_R 0x8072
#define GL_MAX_3D_TEXTURE_SIZE 0x8073
/* CubeMap */
#define GL_TEXTURE_CUBE_MAP 0x8513
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
/* PolygonMode */
#define GL_POINT 0x1B00
#define GL_LINE 0x1B01
#define GL_FILL 0x1B02
/* PolygonOffset for GL_LINE */
#define GL_POLYGON_OFFSET_LINE 0x2A02
/* Filter Control */
#define GL_TEXTURE_FILTER_CONTROL 0x8500
#define GL_TEXTURE_LOD_BIAS 0x8501
#define GL_TEXTURE_MIN_LOD 0x813A
#define GL_TEXTURE_MAX_LOD 0x813B
#define GL_TEXTURE_MAX_LEVEL 0x813D
#define GL_TEXTURE_BORDER_COLOR 0x1004
/* depth/shadow */
#define GL_NONE 0x0
#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
/* Wrap modes */
#define GL_CLAMP 0x2900
#define GL_MIRRORED_REPEAT 0x8370
#define GL_MIRROR_CLAMP_EXT 0x8742
#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743
#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912
#define GL_CLAMP_TO_BORDER 0x812D
/* Fog Coordinate Source */
#define GL_FOG_COORDINATE_SOURCE 0x8450
#define GL_FOG_COORDINATE 0x8451
#define GL_FRAGMENT_DEPTH 0x8452
/* Fragment Control TXP */
#define GL_FRAGMENT_PROGRAM_CONTROL_CONTROLTXP_SCE 0x8453
/* Gets */
#define GL_MODELVIEW_MATRIX 0x0BA6
#define GL_TEXTURE_MATRIX 0x0BA8
#define GL_PROJECTION_MATRIX 0x0BA7
#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872
/* Surface targets */
#define GL_MAX_DRAW_BUFFERS_ATI 0x8824
#define GL_DRAW_BUFFER0_ATI 0x8825
#define GL_DRAW_BUFFER1_ATI 0x8826
#define GL_DRAW_BUFFER2_ATI 0x8827
#define GL_DRAW_BUFFER3_ATI 0x8828
#define GL_DRAW_BUFFER4_ATI 0x8829
#define GL_DRAW_BUFFER5_ATI 0x882A
#define GL_DRAW_BUFFER6_ATI 0x882B
#define GL_DRAW_BUFFER7_ATI 0x882C
#define GL_DRAW_BUFFER8_ATI 0x882D
#define GL_DRAW_BUFFER9_ATI 0x882E
#define GL_DRAW_BUFFER10_ATI 0x882F
#define GL_DRAW_BUFFER11_ATI 0x8830
#define GL_DRAW_BUFFER12_ATI 0x8831
#define GL_DRAW_BUFFER13_ATI 0x8832
#define GL_DRAW_BUFFER14_ATI 0x8833
#define GL_DRAW_BUFFER15_ATI 0x8834
#define GL_DRAW_DEPTH_SCE 0x6004
#define GL_DRAW_STENCIL_SCE 0x6005
#define GL_RGBA8 0x8058
#define GL_FLOAT_DEPTH_COMPONENT16_SCE 0x6000
#define GL_FLOAT_DEPTH_COMPONENT32_SCE 0x6001
#define GL_DEPTH24_STENCIL8_SCE 0x6002
#define GL_STENCIL8_SCE 0x6003
#define GL_DEPTH_COMPONENT 0x1902
#define GL_DEPTH_COMPONENT16 0x81A5
#define GL_DEPTH_COMPONENT24 0x81A6
#define GL_DEPTH_COMPONENT32 0x81A7
#define GL_STENCIL_INDEX 0x1901
#define GL_DRAWABLE_BIT_SCE 0x0001
#define GL_ALLOW_SCAN_OUT_BIT_SCE 0x0002
#define GL_TEXTURE_READ_BIT_SCE 0x0004
#define GL_ANTIALIASED_BIT_SCE 0x0008
/* VBO & PBO */
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
#define GL_STREAM_DRAW 0x88E0
#define GL_STREAM_READ 0x88E1
#define GL_STREAM_COPY 0x88E2
#define GL_STATIC_DRAW 0x88E4
#define GL_STATIC_READ 0x88E5
#define GL_STATIC_COPY 0x88E6
#define GL_DYNAMIC_DRAW 0x88E8
#define GL_DYNAMIC_READ 0x88E9
#define GL_DYNAMIC_COPY 0x88EA
#define GL_SYSTEM_DRAW 0x6020
/* Map/Unmap */
#define GL_READ_ONLY 0x88B8
#define GL_WRITE_ONLY 0x88B9
#define GL_READ_WRITE 0x88BA
/* VSYNC */
#define GL_VSYNC_SCE 0x6006
#define GL_TEXTURE_GAMMA_REMAP_R_SCE 0x6010
#define GL_TEXTURE_GAMMA_REMAP_G_SCE 0x6011
#define GL_TEXTURE_GAMMA_REMAP_B_SCE 0x6012
#define GL_TEXTURE_GAMMA_REMAP_A_SCE 0x6013
#define GL_SHADER_SRGB_REMAP_SCE 0x6014
#define GL_DIVIDE_SCE 0x6015
#define GL_MODULO_SCE 0x6016
#define GL_TEXTURE_FROM_VERTEX_PROGRAM_SCE 0x6017
/* Primitive restart */
#define GL_PRIMITIVE_RESTART_NV 0x8558
/* Anisotropic filtering */
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
/* Sync */
#define GL_ALL_COMPLETED_NV 0x84F2
#define GL_FENCE_STATUS_NV 0x84F3
#define GL_FENCE_CONDITION_NV 0x84F4
/* User clip planes */
#define GL_MAX_CLIP_PLANES 0x0D32
#define GL_CLIP_PLANE0 0x3000
#define GL_CLIP_PLANE1 0x3001
#define GL_CLIP_PLANE2 0x3002
#define GL_CLIP_PLANE3 0x3003
#define GL_CLIP_PLANE4 0x3004
#define GL_CLIP_PLANE5 0x3005
/* Point Sprites */
#define GL_POINT_SPRITE_OES 0x8861
#define GL_COORD_REPLACE_OES 0x8862
#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
/* Framebuffer object */
#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506
#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8
#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6
#define GL_RENDERBUFFER_BINDING_OES 0x8CA7
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7
#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_OES 0x8CD8
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9
#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA
#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD
#define GL_MAX_COLOR_ATTACHMENTS_OES 0x8CDF
#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
#define GL_DEPTH_ATTACHMENT_OES 0x8D00
#define GL_STENCIL_ATTACHMENT_OES 0x8D20
#define GL_FRAMEBUFFER_OES 0x8D40
#define GL_RENDERBUFFER_OES 0x8D41
#define GL_RENDERBUFFER_WIDTH_OES 0x8D42
#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43
#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44
#define GL_STENCIL_INDEX_OES 0x8D45
#define GL_STENCIL_INDEX4_OES 0x8D47
#define GL_STENCIL_INDEX8_OES 0x8D48
/* multiple render target blend enable enums */
#define GL_BLEND_MRT0_SCE GL_COLOR_ATTACHMENT0_EXT
#define GL_BLEND_MRT1_SCE GL_COLOR_ATTACHMENT1_EXT
#define GL_BLEND_MRT2_SCE GL_COLOR_ATTACHMENT2_EXT
#define GL_BLEND_MRT3_SCE GL_COLOR_ATTACHMENT3_EXT
/* Texture usage hint */
#define GL_TEXTURE_ALLOCATION_HINT_SCE 0x6018
#define GL_TEXTURE_TILED_GPU_SCE 0x6019
#define GL_TEXTURE_LINEAR_GPU_SCE 0x601A
#define GL_TEXTURE_SWIZZLED_GPU_SCE 0x601B
#define GL_TEXTURE_LINEAR_SYSTEM_SCE 0x601C
#define GL_TEXTURE_SWIZZLED_SYSTEM_SCE 0x601D
/* Occlusion query & Conditional rendering */
#define GL_SAMPLES_PASSED_ARB 0x8914
#define GL_QUERY_COUNTER_BITS_ARB 0x8864
#define GL_CURRENT_QUERY_ARB 0x8865
#define GL_QUERY_RESULT_ARB 0x8866
#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867
/* Two-sided stencil, Stencil wrap */
#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910
#define GL_INCR_WRAP 0x8507
#define GL_DECR_WRAP 0x8508
/* depth clamp */
#define GL_DEPTH_CLAMP_NV 0x864F
/* 32-bit 3-component attributes (11/11/10) */
#define GL_FIXED_11_11_10_SCE 0x6020
/* Anti-aliasing */
#define GL_REDUCE_DST_COLOR_SCE 0x6021
#define GL_TEXTURE_MULTISAMPLING_HINT_SCE 0x6022
#define GL_FRAMEBUFFER_MULTISAMPLING_MODE_SCE 0x6023
#define GL_MULTISAMPLING_NONE_SCE 0x6030
#define GL_MULTISAMPLING_2X_DIAGONAL_CENTERED_SCE 0x6031
#define GL_MULTISAMPLING_4X_SQUARE_CENTERED_SCE 0x6032
#define GL_MULTISAMPLING_4X_SQUARE_ROTATED_SCE 0x6033
/* Texture reference buffer */
#define GL_TEXTURE_REFERENCE_BUFFER_SCE 0x6040
#define GL_BUFFER_SIZE 0x8764
#define GL_BUFFER_PITCH_SCE 0x6041
/******************************************************************************/
GLAPI void APIENTRY glBlendEquation( GLenum mode );
GLAPI void APIENTRY glBlendEquationSeparate( GLenum modeRGB, GLenum modeAlpha );
GLAPI void APIENTRY glBlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha );
GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
GLAPI void APIENTRY glNormal3fv( const GLfloat* v );
GLAPI void APIENTRY glColor4fv( const GLfloat* v );
GLAPI void APIENTRY glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha );
GLAPI void APIENTRY glGetBooleanv( GLenum pname, GLboolean* params );
GLAPI void APIENTRY glGetFloatv( GLenum pname, GLfloat* params );
GLAPI void APIENTRY glTexParameterfv( GLenum target, GLenum pname, const GLfloat* params );
GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param );
GLAPI void APIENTRY glTexParameteriv( GLenum target, GLenum pname, const GLint* params );
GLAPI void APIENTRY glTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels );
/* VBO & PBO */
GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name );
GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers );
GLAPI void APIENTRY glGenBuffers( GLsizei n, GLuint *buffers );
GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage );
GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data );
GLAPI void APIENTRY glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params );
/* VBO & PBO map/unmap */
GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access );
GLAPI GLboolean APIENTRY glUnmapBuffer( GLenum target );
/* Sync */
GLAPI void APIENTRY glDeleteFencesNV( GLsizei n, const GLuint *fences );
GLAPI void APIENTRY glGenFencesNV( GLsizei n, GLuint *fences );
GLAPI GLboolean APIENTRY glIsFenceNV( GLuint fence );
GLAPI GLboolean APIENTRY glTestFenceNV( GLuint fence );
GLAPI void APIENTRY glGetFenceivNV( GLuint fence, GLenum pname, GLint *params );
GLAPI void APIENTRY glFinishFenceNV( GLuint fence );
GLAPI void APIENTRY glSetFenceNV( GLuint fence, GLenum condition );
/* Framebuffer object */
GLAPI GLboolean APIENTRY glIsRenderbufferOES( GLuint );
GLAPI void APIENTRY glBindRenderbufferOES( GLenum, GLuint );
GLAPI void APIENTRY glDeleteRenderbuffersOES( GLsizei, const GLuint * );
GLAPI void APIENTRY glGenRenderbuffersOES( GLsizei, GLuint * );
GLAPI void APIENTRY glRenderbufferStorageOES( GLenum, GLenum, GLsizei, GLsizei );
GLAPI void APIENTRY glGetRenderbufferParameterivOES( GLenum, GLenum, GLint * );
GLAPI GLboolean APIENTRY glIsFramebufferOES( GLuint );
GLAPI void APIENTRY glBindFramebufferOES( GLenum, GLuint );
GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei, const GLuint * );
GLAPI void APIENTRY glGenFramebuffersOES( GLsizei, GLuint * );
GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum );
GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum, GLenum, GLenum, GLuint, GLint );
GLAPI void APIENTRY glFramebufferRenderbufferOES( GLenum, GLenum, GLenum, GLuint );
GLAPI void APIENTRY glGetFramebufferAttachmentParameterivOES( GLenum, GLenum, GLenum, GLint * );
GLAPI void APIENTRY glGenerateMipmapOES( GLenum );
/* Texture Reference */
GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,7 @@
#ifndef _RGL_EXPORT_DEFINE_H
#define _RGL_EXPORT_DEFINE_H
#define PSGL_EXPORT
#define RGL_EXPORT
#endif

View File

@ -0,0 +1,366 @@
#ifndef _RGL_EXPORT_H
#define _RGL_EXPORT_H
#include <stdlib.h>
#include "export.h"
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <cell/cgb/cgb_struct.h>
#include <cell/resc.h>
#include <sdk_version.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct PSGLdevice PSGLdevice;
typedef struct PSGLcontext PSGLcontext;
typedef enum PSGLtvStandard
{
PSGL_TV_STANDARD_NONE,
PSGL_TV_STANDARD_NTSC_M,
PSGL_TV_STANDARD_NTSC_J,
PSGL_TV_STANDARD_PAL_M,
PSGL_TV_STANDARD_PAL_B,
PSGL_TV_STANDARD_PAL_D,
PSGL_TV_STANDARD_PAL_G,
PSGL_TV_STANDARD_PAL_H,
PSGL_TV_STANDARD_PAL_I,
PSGL_TV_STANDARD_PAL_N,
PSGL_TV_STANDARD_PAL_NC,
PSGL_TV_STANDARD_HD480I,
PSGL_TV_STANDARD_HD480P,
PSGL_TV_STANDARD_HD576I,
PSGL_TV_STANDARD_HD576P,
PSGL_TV_STANDARD_HD720P,
PSGL_TV_STANDARD_HD1080I,
PSGL_TV_STANDARD_HD1080P,
PSGL_TV_STANDARD_1280x720_ON_VESA_1280x768 = 128,
PSGL_TV_STANDARD_1280x720_ON_VESA_1280x1024,
PSGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200,
} PSGLtvStandard;
#define RGL_TV_STANDARD_NONE (PSGL_TV_STANDARD_NONE)
#define RGL_TV_STANDARD_NTSC_M 1
#define RGL_TV_STANDARD_NTSC_J 2
#define RGL_TV_STANDARD_PAL_M 3
#define RGL_TV_STANDARD_PAL_B 4
#define RGL_TV_STANDARD_PAL_D 5
#define RGL_TV_STANDARD_PAL_G 6
#define RGL_TV_STANDARD_PAL_H 7
#define RGL_TV_STANDARD_PAL_I 8
#define RGL_TV_STANDARD_PAL_N 9
#define RGL_TV_STANDARD_PAL_NC 10
#define RGL_TV_STANDARD_HD480I 11
#define RGL_TV_STANDARD_HD480P 12
#define RGL_TV_STANDARD_HD576I 13
#define RGL_TV_STANDARD_HD576P 14
#define RGL_TV_STANDARD_HD720P 15
#define RGL_TV_STANDARD_HD1080I 16
#define RGL_TV_STANDARD_HD1080P 17
#define RGL_TV_STANDARD_1280x720_ON_VESA_1280x768 128
#define RGL_TV_STANDARD_1280x720_ON_VESA_1280x1024 129
#define RGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200 130
typedef enum PSGLbufferingMode
{
PSGL_BUFFERING_MODE_SINGLE = 1,
PSGL_BUFFERING_MODE_DOUBLE = 2,
PSGL_BUFFERING_MODE_TRIPLE = 3,
} PSGLbufferingMode;
/* spoof as PSGL */
#define RGL_BUFFERING_MODE_SINGLE (PSGL_BUFFERING_MODE_SINGLE)
#define RGL_BUFFERING_MODE_DOUBLE (PSGL_BUFFERING_MODE_DOUBLE)
#define RGL_BUFFERING_MODE_TRIPLE (PSGL_BUFFERING_MODE_TRIPLE)
typedef enum PSGLdeviceConnector
{
PSGL_DEVICE_CONNECTOR_NONE,
PSGL_DEVICE_CONNECTOR_VGA,
PSGL_DEVICE_CONNECTOR_DVI,
PSGL_DEVICE_CONNECTOR_HDMI,
PSGL_DEVICE_CONNECTOR_COMPOSITE,
PSGL_DEVICE_CONNECTOR_SVIDEO,
PSGL_DEVICE_CONNECTOR_COMPONENT,
} PSGLdeviceConnector;
#define RGL_DEVICE_CONNECTOR_NONE (PSGL_DEVICE_CONNECTOR_NONE)
#define RGL_DEVICE_CONNECTOR_VGA 1
#define RGL_DEVICE_CONNECTOR_DVI 2
#define RGL_DEVICE_CONNECTOR_HDMI 3
#define RGL_DEVICE_CONNECTOR_COMPOSITE 4
#define RGL_DEVICE_CONNECTOR_SVIDEO 5
#define RGL_DEVICE_CONNECTOR_COMPONENT 6
typedef enum RescRatioMode
{
RESC_RATIO_MODE_FULLSCREEN,
RESC_RATIO_MODE_LETTERBOX, // default
RESC_RATIO_MODE_PANSCAN,
} RescRatioMode;
typedef enum RescPalTemporalMode
{
RESC_PAL_TEMPORAL_MODE_50_NONE, // default - no conversion
RESC_PAL_TEMPORAL_MODE_60_DROP,
RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE,
RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_30_DROP,
RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_DROP_FLEXIBLE,
} RescPalTemporalMode;
typedef enum RescInterlaceMode
{
RESC_INTERLACE_MODE_NORMAL_BILINEAR,
RESC_INTERLACE_MODE_INTERLACE_FILTER,
} RescInterlaceMode;
#define PSGL_DEVICE_PARAMETERS_COLOR_FORMAT 0x0001
#define PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT 0x0002
#define PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE 0x0004
#define PSGL_DEVICE_PARAMETERS_TV_STANDARD 0x0008
#define PSGL_DEVICE_PARAMETERS_CONNECTOR 0x0010
#define PSGL_DEVICE_PARAMETERS_BUFFERING_MODE 0x0020
#define PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT 0x0040
#define PSGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT 0x0080
#define PSGL_DEVICE_PARAMETERS_RESC_RATIO_MODE 0x0100
#define PSGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE 0x0200
#define PSGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE 0x0400
#define PSGL_DEVICE_PARAMETERS_RESC_ADJUST_ASPECT_RATIO 0x0800
/* spoof as PSGL */
#define RGL_DEVICE_PARAMETERS_COLOR_FORMAT 0x0001
#define RGL_DEVICE_PARAMETERS_DEPTH_FORMAT 0x0002
#define RGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE 0x0004
#define RGL_DEVICE_PARAMETERS_TV_STANDARD 0x0008
#define RGL_DEVICE_PARAMETERS_CONNECTOR 0x0010
#define RGL_DEVICE_PARAMETERS_BUFFERING_MODE 0x0020
#define RGL_DEVICE_PARAMETERS_WIDTH_HEIGHT 0x0040
#define RGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT 0x0080
#define RGL_DEVICE_PARAMETERS_RESC_RATIO_MODE 0x0100
#define RGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE 0x0200
#define RGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE 0x0400
#define RGL_DEVICE_PARAMETERS_RESC_ADJUST_ASPECT_RATIO 0x0800
// mask for validation
#define PSGL_VALIDATE_NONE 0x00000000
#define PSGL_VALIDATE_FRAMEBUFFER 0x00000001
#define PSGL_VALIDATE_TEXTURES_USED 0x00000002
#define PSGL_VALIDATE_VERTEX_PROGRAM 0x00000004
#define PSGL_VALIDATE_VERTEX_CONSTANTS 0x00000008
#define PSGL_VALIDATE_VERTEX_TEXTURES_USED 0x00000010
#define PSGL_VALIDATE_FFX_VERTEX_PROGRAM 0x00000020
#define PSGL_VALIDATE_FRAGMENT_PROGRAM 0x00000040
#define PSGL_VALIDATE_FFX_FRAGMENT_PROGRAM 0x00000080
#define PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS 0x00000100
#define PSGL_VALIDATE_VIEWPORT 0x00000200
#define PSGL_VALIDATE_DEPTH_TEST 0x00000800
#define PSGL_VALIDATE_WRITE_MASK 0x00001000
#define PSGL_VALIDATE_STENCIL_TEST 0x00002000
#define PSGL_VALIDATE_STENCIL_OP_AND_MASK 0x00004000
#define PSGL_VALIDATE_SCISSOR_BOX 0x00008000
#define PSGL_VALIDATE_FACE_CULL 0x00010000
#define PSGL_VALIDATE_BLENDING 0x00020000
#define PSGL_VALIDATE_POINT_RASTER 0x00040000
#define PSGL_VALIDATE_LINE_RASTER 0x00080000
#define PSGL_VALIDATE_POLYGON_OFFSET 0x00100000
#define PSGL_VALIDATE_SHADE_MODEL 0x00200000
#define PSGL_VALIDATE_LOGIC_OP 0x00400000
#define PSGL_VALIDATE_MULTISAMPLING 0x00800000
#define PSGL_VALIDATE_POLYGON_MODE 0x01000000
#define PSGL_VALIDATE_PRIMITIVE_RESTART 0x02000000
#define PSGL_VALIDATE_CLIP_PLANES 0x04000000
#define PSGL_VALIDATE_SHADER_SRGB_REMAP 0x08000000
#define PSGL_VALIDATE_POINT_SPRITE 0x10000000
#define PSGL_VALIDATE_TWO_SIDE_COLOR 0x20000000
#define PSGL_VALIDATE_ALL 0x3FFFFFFF
/* spoof as PSGL */
#define RGL_VALIDATE_NONE 0x00000000
#define RGL_VALIDATE_FRAMEBUFFER 0x00000001
#define RGL_VALIDATE_TEXTURES_USED 0x00000002
#define RGL_VALIDATE_VERTEX_PROGRAM 0x00000004
#define RGL_VALIDATE_VERTEX_CONSTANTS 0x00000008
#define RGL_VALIDATE_VERTEX_TEXTURES_USED 0x00000010
#define RGL_VALIDATE_FFX_VERTEX_PROGRAM 0x00000020
#define RGL_VALIDATE_FRAGMENT_PROGRAM 0x00000040
#define RGL_VALIDATE_FFX_FRAGMENT_PROGRAM 0x00000080
#define RGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS 0x00000100
#define RGL_VALIDATE_VIEWPORT 0x00000200
#define RGL_VALIDATE_DEPTH_TEST 0x00000800
#define RGL_VALIDATE_WRITE_MASK 0x00001000
#define RGL_VALIDATE_STENCIL_TEST 0x00002000
#define RGL_VALIDATE_STENCIL_OP_AND_MASK 0x00004000
#define RGL_VALIDATE_SCISSOR_BOX 0x00008000
#define RGL_VALIDATE_FACE_CULL 0x00010000
#define RGL_VALIDATE_BLENDING 0x00020000
#define RGL_VALIDATE_POINT_RASTER 0x00040000
#define RGL_VALIDATE_LINE_RASTER 0x00080000
#define RGL_VALIDATE_POLYGON_OFFSET 0x00100000
#define RGL_VALIDATE_SHADE_MODEL 0x00200000
#define RGL_VALIDATE_LOGIC_OP 0x00400000
#define RGL_VALIDATE_MULTISAMPLING 0x00800000
#define RGL_VALIDATE_POLYGON_MODE 0x01000000
#define RGL_VALIDATE_PRIMITIVE_RESTART 0x02000000
#define RGL_VALIDATE_CLIP_PLANES 0x04000000
#define RGL_VALIDATE_SHADER_SRGB_REMAP 0x08000000
#define RGL_VALIDATE_POINT_SPRITE 0x10000000
#define RGL_VALIDATE_TWO_SIDE_COLOR 0x20000000
#define RGL_VALIDATE_ALL 0x3FFFFFFF
#define RGLdevice PSGLdevice
#define RGLdeviceParameters PSGLdeviceParameters
#define RGLcontext PSGLcontext
typedef struct
{
GLuint enable;
GLenum colorFormat;
GLenum depthFormat;
GLenum multisamplingMode;
PSGLtvStandard TVStandard;
PSGLdeviceConnector connector;
PSGLbufferingMode bufferingMode;
GLuint width; // dimensions of display device (scanout buffer)
GLuint height;
// dimensions of render buffer. Only set explicitly if the render target buffer
// needs to be different size than display scanout buffer (resolution scaling required).
// These can only be set if PSGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT is set in the "enable" mask,
// otherwise, render buffer dimensions are set to device dimensions (width/height).
GLuint renderWidth;
GLuint renderHeight;
RescRatioMode rescRatioMode; // RESC aspect ratio rescaling mode: full screen, letterbox, or pan & scan
RescPalTemporalMode rescPalTemporalMode; // RESC pal frame rate conversion mode: none, drop frame, interpolate
RescInterlaceMode rescInterlaceMode; // RESC interlace filter mode: normal bilinear or use the anti-flicker interlace filter
// horizontal and vertical scaling to adjust for the difference in overscan rates for each SD/HD mode or TV
GLfloat horizontalScale;
GLfloat verticalScale;
} PSGLdeviceParameters;
#define PSGL_INIT_MAX_SPUS 0x0001
#define PSGL_INIT_INITIALIZE_SPUS 0x0002
#define PSGL_INIT_PERSISTENT_MEMORY_SIZE 0x0004
#define PSGL_INIT_TRANSIENT_MEMORY_SIZE 0x0008
#define PSGL_INIT_ERROR_CONSOLE 0x0010
#define PSGL_INIT_FIFO_SIZE 0x0020
#define PSGL_INIT_HOST_MEMORY_SIZE 0x0040
#define PSGL_INIT_USE_PMQUERIES 0x0080
/* spoof as PSGL */
#define RGL_INIT_MAX_SPUS 0x0001
#define RGL_INIT_INITIALIZE_SPUS 0x0002
#define RGL_INIT_PERSISTENT_MEMORY_SIZE 0x0004
#define RGL_INIT_TRANSIENT_MEMORY_SIZE 0x0008
#define RGL_INIT_ERROR_CONSOLE 0x0010
#define RGL_INIT_FIFO_SIZE 0x0020
#define RGL_INIT_HOST_MEMORY_SIZE 0x0040
#define RGL_INIT_USE_PMQUERIES 0x0080
typedef struct PSGLinitOptions
{
GLuint enable; // bitfield of options to set
GLuint maxSPUs;
GLboolean initializeSPUs;
GLuint persistentMemorySize;
GLuint transientMemorySize;
int errorConsole;
GLuint fifoSize;
GLuint hostMemorySize;
} PSGLinitOptions;
#define RGLinitOptions PSGLinitOptions
typedef void*( *PSGLmallocFunc )( size_t LSize ); // expected to return 16-byte aligned
typedef void*( *PSGLmemalignFunc )( size_t align, size_t LSize );
typedef void*( *PSGLreallocFunc )( void* LBlock, size_t LSize );
typedef void( *PSGLfreeFunc )( void* LBlock );
extern PSGL_EXPORT void psglInit( PSGLinitOptions* options );
extern PSGL_EXPORT void psglExit();
PSGL_EXPORT PSGLdevice* psglCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode );
PSGL_EXPORT PSGLdevice* psglCreateDeviceExtended( const PSGLdeviceParameters *parameters );
PSGL_EXPORT GLfloat psglGetDeviceAspectRatio( const PSGLdevice * device );
PSGL_EXPORT void psglGetDeviceDimensions( const PSGLdevice * device, GLuint *width, GLuint *height );
PSGL_EXPORT void psglGetRenderBufferDimensions( const PSGLdevice * device, GLuint *width, GLuint *height );
PSGL_EXPORT void psglDestroyDevice( PSGLdevice* device );
PSGL_EXPORT void psglMakeCurrent( PSGLcontext* context, PSGLdevice* device );
PSGL_EXPORT PSGLcontext* psglCreateContext();
PSGL_EXPORT void psglDestroyContext( PSGLcontext* LContext );
PSGL_EXPORT void psglResetCurrentContext();
PSGL_EXPORT PSGLcontext* psglGetCurrentContext();
PSGL_EXPORT PSGLdevice* psglGetCurrentDevice();
PSGL_EXPORT void psglSwap( void );
PSGL_EXPORT void psglLoadShaderLibrary( const char *filename );
PSGL_EXPORT void psglSetFlipHandler( void( *handler )( const GLuint head ) );
PSGL_EXPORT void psglSetVBlankHandler( void( *handler )( const GLuint head ) );
PSGL_EXPORT GLboolean psglSetAllocatorFuncs( PSGLmallocFunc mallocFunc, PSGLmemalignFunc memalignFunc, PSGLreallocFunc reallocFunc, PSGLfreeFunc freeFunc );
PSGL_EXPORT void psglAddressToOffset(const void *address, GLuint *offset);
PSGL_EXPORT void psglSetVertexProgramRegister(GLuint reg, const void * __restrict value);
PSGL_EXPORT void psglSetVertexProgramRegisterBlock(GLuint reg, GLuint count, const void * __restrict value);
PSGL_EXPORT void psglSetVertexProgramTransformBranchBits(GLuint values);
PSGL_EXPORT void psglSetVertexProgramConfiguration(const CellCgbVertexProgramConfiguration *conf, const void *ucodeStorageAddress);
PSGL_EXPORT void psglSetFragmentProgramEmbeddedConstant(const GLuint offset, const GLfloat *value, const GLuint sizeInWords);
PSGL_EXPORT void psglSetFragmentProgramConfiguration(const CellCgbFragmentProgramConfiguration *conf);
PSGL_EXPORT void psglSetFragmentProgramEmbeddedConstantMemoryLocation(const GLuint offset, const GLfloat *value, const GLuint sizeInWords, bool inLocalMemory);
PSGL_EXPORT void psglSetFragmentProgramConfigurationMemoryLocation(const CellCgbFragmentProgramConfiguration *conf, bool inLocalMemory);
PSGL_EXPORT void psglSetUserClipPlanes( const GLuint userClipControlMask, const GLuint vertexOutputAttributeMask );
static inline PSGL_EXPORT void psglRescAdjustAspectRatio( const float horizontalScale, const float verticalScale )
{ cellRescAdjustAspectRatio( horizontalScale, verticalScale ); }
#define PSGL_ADD_RETURN true
#define PSGL_DO_NOT_ADD_RETURN false
#define PSGL_STALL true
#define PSGL_DO_NOT_STALL false
// This funciton validates states specified in mask
// mask - specify states to be validated
// returns mask of states which was NOT validated
PSGL_EXPORT GLuint psglValidateStates( GLuint mask );
// This function invalidates states specified in mask
// mask - specify states to be invalidateted
PSGL_EXPORT void psglInvalidateStates( GLuint mask );
// This funciton validates attributes with index buffer at specified offset
// indices - specify offset to index buffer object
// isMain - true will be set if index buffer object is on main memory, false for local memory
// returns RSX offset of index buffer
PSGL_EXPORT GLuint psglValidateAttributes( const GLvoid* indices, GLboolean *isMain );
// This function invalidates all attributes
PSGL_EXPORT void psglInvalidateAttributes();
/* hw cursor error code */
#define PSGL_HW_CURSOR_OK CELL_OK
#define PSGL_HW_CURSOR_ERROR_FAILURE CELL_GCM_ERROR_FAILURE
#define PSGL_HW_CURSOR_ERROR_INVALID_VALUE CELL_GCM_ERROR_INVALID_VALUE
#ifdef __cplusplus
} // Close scope of 'extern "C"' declaration which encloses file.
#endif
#endif /* RGL_EXPORT_H */

View File

@ -1,87 +0,0 @@
#ifndef _BASE_H_
#define _BASE_H_
#include <stdlib.h>
#include <string.h>
#include <new>
namespace RGL
{
class Base
{
public:
void * operator new( size_t size ) { return malloc( size ); }
void * operator new( size_t /*size*/, void *p ) { return p; }
void operator delete( void *ptr ) { return free( ptr ); }
void operator delete( void * /*ptr*/, void * /*p*/ ) { }};
template<class T> class Vector: public Base
{
T* array;
unsigned int count;
unsigned int capacity;
unsigned int increment;
public:
Vector(): array( 0 ), count( 0 ), capacity( 0 ), increment( 4 ) {}
~Vector() { clear(); reallocArray( 0 ); }
inline unsigned int getCount() { return count; }
inline void reallocArray( unsigned int newCapacity )
{
if ( newCapacity == capacity ) return;
if ( newCapacity > capacity ) newCapacity = ( newCapacity > capacity + increment ) ? newCapacity : ( capacity + increment );
if ( newCapacity == 0 )
{
free( array );
array = 0;
}
else array = static_cast<T*>( realloc( static_cast<void *>( array ), sizeof( T ) * newCapacity ) );
capacity = newCapacity;
}
inline void clear()
{
if ( !array ) return;
for ( unsigned int i = 0;i < count;++i )( array + i )->~T();
count = 0;
}
inline unsigned int pushBack( const T &element )
{
if ( count + 1 > capacity )
reallocArray( count + 1 );
new(( void * )( array + count ) ) T( element );
return ++count;
}
inline unsigned int appendUnique( const T &element )
{
for ( unsigned int i = 0;i < count;++i ) if ( array[i] == element ) return i;
return pushBack( element );
}
inline void removeElement( const T &element )
{
for ( unsigned int i = count; i > 0; --i )
{
if ( array[i-1] == element )
{
remove( i - 1 );
return;
}
}
}
inline void remove( unsigned int index )
{
( array + index )->~T();
--count;
if ( count > index ) memmove( array + index, array + index + 1, ( count - index )*sizeof( T ) );
}
inline T& operator []( int i ) const { return array[i]; }
};
}
#endif

View File

@ -1,448 +0,0 @@
#ifndef _cg_common_h
#define _cg_common_h
#include <vector>
#include <string>
#include <Cg/cgGL.h>
#include "rgl.h"
#include "private.h"
#include <string.h>
#define RGL_BOOLEAN_REGISTERS_COUNT 32
#define VERTEX_PROFILE_INDEX 0
#define FRAGMENT_PROFILE_INDEX 1
#define CGF_OUTPUTFROMH0 0x01
#define CGF_DEPTHREPLACE 0x02
#define CGF_PIXELKILL 0x04
#define CGPV_MASK 0x03
#define CGPV_VARYING 0x00
#define CGPV_UNIFORM 0x01
#define CGPV_CONSTANT 0x02
#define CGPV_MIXED 0x03
#define CGPF_REFERENCED 0x10
#define CGPF_SHARED 0x20
#define CGPF_GLOBAL 0x40
#define CGP_INTERNAL 0x80
#define CGP_INTRINSIC 0x0000
#define CGP_STRUCTURE 0x100
#define CGP_ARRAY 0x200
#define CGP_TYPE_MASK (CGP_STRUCTURE + CGP_ARRAY)
#define CGP_UNROLLED 0x400
#define CGP_UNPACKED 0x800
#define CGP_CONTIGUOUS 0x1000
#define CGP_NORMALIZE 0x2000
#define CGP_RTCREATED 0x4000
#define CGP_SCF_BOOL (CG_TYPE_START_ENUM + 1024)
#define CG_BINARY_FORMAT_REVISION 0x00000006
#ifdef __cplusplus
extern "C"
{
#endif
typedef unsigned int CgBinaryOffset;
typedef CgBinaryOffset CgBinaryEmbeddedConstantOffset;
typedef CgBinaryOffset CgBinaryFloatOffset;
typedef CgBinaryOffset CgBinaryStringOffset;
typedef CgBinaryOffset CgBinaryParameterOffset;
typedef struct CgBinaryVertexProgram CgBinaryVertexProgram;
typedef struct CgBinaryFragmentProgram CgBinaryFragmentProgram;
typedef struct CgBinaryProgram CgBinaryProgram;
typedef struct _CGnamedProgram
{
const char *name;
CGprogram program;
int refCount;
} _CGnamedProgram;
typedef struct _CGprogramGroup
{
struct _CGprogramGroup *next;
CGcontext ctx;
unsigned int *constantTable;
unsigned int *stringTable;
unsigned int programCount;
_CGnamedProgram *programs;
int refCount;
bool userCreated;
char *filedata;
char *name;
} _CGprogramGroup;
typedef struct _CGprogramGroup *CGprogramGroup;
CGprogramGroup _RGLCgCreateProgramGroup( CGcontext ctx, const char *name, void *ptr, int size );
CGprogramGroup _RGLCgCreateProgramGroupFromFile( CGcontext ctx, const char *group_file );
void _RGLCgDestroyProgramGroup( CGprogramGroup group );
int _RGLCgGetProgramCount( CGprogramGroup group );
CGprogram _RGLCgGetProgram( CGprogramGroup group, const char *name );
int _RGLCgGetProgramIndex( CGprogramGroup group, const char *name );
CGprogram _RGLCgGetProgramAtIndex( CGprogramGroup group, unsigned int index );
const char *_RGLCgGetProgramGroupName( CGprogramGroup group );
typedef struct _CgParameterTableHeader
{
unsigned short entryCount;
unsigned short resourceTableOffset;
unsigned short defaultValueIndexTableOffset;
unsigned short defaultValueIndexCount;
unsigned short semanticIndexTableOffset;
unsigned short semanticIndexCount;
} CgParameterTableHeader;
typedef struct _CgParameterEntry
{
unsigned int nameOffset;
unsigned short typeIndex;
unsigned short flags;
} CgParameterEntry;
typedef struct _CgParameterArray
{
unsigned short arrayType;
unsigned short dimensionCount;
unsigned short dimensions[];
} CgParameterArray;
typedef struct _CgParameterStructure
{
unsigned short memberCount;
unsigned short reserved;
} CgParameterStructure;
typedef struct _CgParameterResource
{
unsigned short type;
unsigned short resource;
} CgParameterResource;
typedef struct _CgParameterSemantic
{
unsigned short entryIndex;
unsigned short reserved;
unsigned int semanticOffset;
} CgParameterSemantic;
typedef struct _CgParameterDefaultValue
{
unsigned short entryIndex;
unsigned short defaultValueIndex;
} CgParameterDefaultValue;
typedef struct CgProgramHeader
{
unsigned short profile;
unsigned short compilerVersion;
unsigned int instructionCount;
unsigned int attributeInputMask;
union
{
struct
{
unsigned int instructionSlot;
unsigned int registerCount;
unsigned int attributeOutputMask;
} vertexProgram;
struct
{
unsigned int partialTexType;
unsigned short texcoordInputMask;
unsigned short texcoord2d;
unsigned short texcoordCentroid;
unsigned char registerCount;
unsigned char flags;
} fragmentProgram;
};
}
CgProgramHeader;
typedef void( *_cgSetFunction )( struct CgRuntimeParameter* __restrict, const void* __restrict);
typedef void( *_cgSetArrayIndexFunction )( struct CgRuntimeParameter* __restrict, const void* __restrict, const int index );
typedef struct _CgUniform
{
void *pushBufferPtr;
} _CgUniform;
typedef struct _CGprogram _CGprogram;
typedef struct CgRuntimeParameter
{
_cgSetArrayIndexFunction samplerSetter;
_cgSetArrayIndexFunction setterIndex;
_cgSetArrayIndexFunction settercIndex;
_cgSetArrayIndexFunction setterrIndex;
void *pushBufferPointer;
const CgParameterEntry *parameterEntry;
_CGprogram *program;
int glType;
CGparameter id;
} CgRuntimeParameter;
struct _CGprogram
{
struct _CGprogram* next;
CGprogram id;
struct _CGcontext* parentContext;
void* parentEffect;
bool inLocalMemory;
unsigned int constantPushBufferWordSize;
unsigned int* constantPushBuffer;
void* platformProgram;
void* platformProgramBinary;
unsigned int samplerCount;
unsigned int * samplerIndices;
unsigned int * samplerUnits;
unsigned int controlFlowBools;
CgProgramHeader header;
const char *name;
const void *ucode;
GLuint loadProgramId;
GLuint loadProgramOffset;
int version;
char *parameterResources;
int rtParametersCount;
CgRuntimeParameter *runtimeParameters;
const CgParameterEntry *parametersEntries;
unsigned short *resources;
unsigned short *pushBufferPointers;
int defaultValuesIndexCount;
const CgParameterDefaultValue *defaultValuesIndices;
int defaultValueCount;
const float *defaultValues;
const char *stringTable;
unsigned int **constantPushBufferPointers;
unsigned int *samplerValuesLocation;
void *memoryBlock;
_CGprogramGroup *programGroup;
int programIndexInGroup;
void *runtimeElf;
};
typedef struct _CGcontext
{
struct _CGcontext* next;
CGcontext id;
unsigned int programCount;
struct _CGprogram* programList;
CGenum compileType;
unsigned int controlFlowBoolsSharedMask;
unsigned int controlFlowBoolsShared;
_CGprogram defaultProgram;
CGprogramGroup groupList;
double currentParameterValue[16];
char currentParameterName[128];
} _CGcontext;
void _RGLCgRaiseError( CGerror error );
extern void _RGLCgProgramDestroyAll( _CGcontext* c );
extern void _RGLCgDestroyContextParam( CgRuntimeParameter* p );
CgRuntimeParameter*_RGLCgCreateParameterInternal( _CGprogram *program, const char* name, CGtype type );
void _RGLCgProgramErase( _CGprogram* prog );
void _cgRaiseInvalidParam( CgRuntimeParameter*p, const void*v );
void _cgRaiseNotMatrixParam( CgRuntimeParameter*p, const void*v );
void _cgIgnoreSetParam( CgRuntimeParameter*p, const void*v );
void _cgRaiseInvalidParamIndex( CgRuntimeParameter*p, const void*v, const int index );
void _cgRaiseNotMatrixParamIndex( CgRuntimeParameter*p, const void*v, const int index );
void _cgIgnoreSetParamIndex( CgRuntimeParameter*p, const void*v, const int index );
#define CG_IS_CONTEXT(_ctx) _RGLIsName(&_CurrentContext->cgContextNameSpace, (jsName)_ctx)
#define CG_IS_PROGRAM(_program) _RGLIsName(&_CurrentContext->cgProgramNameSpace, (jsName)_program)
#define CG_IS_PARAMETER(_param) _RGLIsName(&_CurrentContext->cgParameterNameSpace, (jsName)(((unsigned int)_param)&CG_PARAMETERMASK))
#define CG_PARAMETERSIZE 22
#define CG_PARAMETERMASK ((1 << CG_PARAMETERSIZE)-1)
#define CG_GETINDEX(param) (int)((unsigned int)(param)>>CG_PARAMETERSIZE)
static inline bool isMatrix( CGtype type )
{
if (( type >= CG_FLOAT1x1 && type <= CG_FLOAT4x4 ) ||
( type >= CG_HALF1x1 && type <= CG_HALF4x4 ) ||
( type >= CG_INT1x1 && type <= CG_INT4x4 ) ||
( type >= CG_BOOL1x1 && type <= CG_BOOL4x4 ) ||
( type >= CG_FIXED1x1 && type <= CG_FIXED4x4 ))
return true;
return false;
}
unsigned int _RGLCountFloatsInCgType( CGtype type );
CGbool _cgMatrixDimensions( CGtype type, unsigned int* nrows, unsigned int* ncols );
unsigned int _RGLGetTypeRowCount( CGtype parameterType );
unsigned int _RGLGetTypeColCount( CGtype parameterType );
inline static CgRuntimeParameter* _cgGetParamPtr( CGparameter p )
{
return ( CgRuntimeParameter* )_RGLGetNamedValue( &_CurrentContext->cgParameterNameSpace, ( jsName )((( unsigned int )p )&CG_PARAMETERMASK ) );
}
inline static _CGprogram* _cgGetProgPtr( CGprogram p )
{
return ( _CGprogram* )_RGLGetNamedValue( &_CurrentContext->cgProgramNameSpace, ( jsName )p );
}
inline static _CGcontext* _cgGetContextPtr( CGcontext c )
{
return ( _CGcontext* )_RGLGetNamedValue( &_CurrentContext->cgContextNameSpace, ( jsName )c );
}
inline static int _RGLGetSizeofSubArray( const unsigned short *dimensions, unsigned short count )
{
int res = 1;
for ( int i = 0;i < count;i++ )
res *= ( int )( *( dimensions++ ) );
return res;
}
inline static CGresource _RGLGetBaseResource( CGresource resource )
{
switch ( resource )
{
case CG_ATTR0: case CG_ATTR1: case CG_ATTR2: case CG_ATTR3:
case CG_ATTR4: case CG_ATTR5: case CG_ATTR6: case CG_ATTR7:
case CG_ATTR8: case CG_ATTR9: case CG_ATTR10: case CG_ATTR11:
case CG_ATTR12: case CG_ATTR13: case CG_ATTR14: case CG_ATTR15:
return CG_ATTR0;
case CG_HPOS:
return CG_HPOS;
case CG_COL0: case CG_COL1: case CG_COL2: case CG_COL3:
return CG_COL0;
case CG_TEXCOORD0: case CG_TEXCOORD1: case CG_TEXCOORD2: case CG_TEXCOORD3:
case CG_TEXCOORD4: case CG_TEXCOORD5: case CG_TEXCOORD6: case CG_TEXCOORD7:
case CG_TEXCOORD8: case CG_TEXCOORD9:
return CG_TEXCOORD0;
case CG_TEXUNIT0: case CG_TEXUNIT1: case CG_TEXUNIT2: case CG_TEXUNIT3:
case CG_TEXUNIT4: case CG_TEXUNIT5: case CG_TEXUNIT6: case CG_TEXUNIT7:
case CG_TEXUNIT8: case CG_TEXUNIT9: case CG_TEXUNIT10: case CG_TEXUNIT11:
case CG_TEXUNIT12: case CG_TEXUNIT13: case CG_TEXUNIT14: case CG_TEXUNIT15:
return CG_TEXUNIT0;
case CG_FOGCOORD:
return CG_FOGCOORD;
case CG_PSIZ:
return CG_PSIZ;
case CG_WPOS:
return CG_WPOS;
case CG_COLOR0: case CG_COLOR1: case CG_COLOR2: case CG_COLOR3:
return CG_COLOR0;
case CG_DEPTH0:
return CG_DEPTH0;
case CG_C:
return CG_C;
case CG_B:
return CG_B;
case CG_CLP0: case CG_CLP1: case CG_CLP2: case CG_CLP3: case CG_CLP4: case CG_CLP5:
return CG_CLP0;
case CG_UNDEFINED:
return CG_UNDEFINED;
default:
//RARCH_WARN("Resource 0x%d is unknown here.\n", resource );
return CG_UNDEFINED;
}
}
CGprofile _RGLPlatformGetLatestProfile( CGGLenum profile_type );
int _RGLPlatformCopyProgram( _CGprogram* source, _CGprogram* destination );
void _RGLPlatformProgramErase( void* platformProgram );
CGbool _RGLPlatformSupportsFragmentProgram( CGprofile p );
void _RGLPlatformSetVertexRegister4fv( unsigned int reg, const float * __restrict v );
void _RGLPlatformSetVertexRegisterBlock( unsigned int reg, unsigned int count, const float * __restrict v );
void _RGLPlatformSetFragmentRegister4fv( unsigned int reg, const float * __restrict v );
void _RGLPlatformSetFragmentRegisterBlock( unsigned int reg, unsigned int count, const float * __restrict v );
unsigned int _cgHashString( const char *str );
static inline GLenum _RGLCgGetSamplerGLTypeFromCgType( CGtype type )
{
switch ( type )
{
case CG_SAMPLER1D:
case CG_SAMPLER2D:
case CG_SAMPLERRECT:
return GL_TEXTURE_2D;
default:
return 0;
}
}
struct jsNameSpace;
int _RGLNVGenerateProgram( _CGprogram *program, int profileIndex, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const CgParameterEntry *parameterEntries,
const char *stringTable, const float *defaultValues );
_cgSetArrayIndexFunction getVectorTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d );
_cgSetArrayIndexFunction getMatrixTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d, unsigned short e, unsigned short f );
// -------------------------------------------
typedef void( * CgcontextHookFunction )( _CGcontext *context );
extern CgcontextHookFunction _cgContextCreateHook;
extern CgcontextHookFunction _cgContextDestroyHook;
typedef void( * CgparameterHookFunction )( CgRuntimeParameter *parameter );
extern CgparameterHookFunction _cgParameterCreateHook;
extern CgparameterHookFunction _cgParameterDestroyHook;
typedef void( * CgprogramHookFunction )( _CGprogram *program );
typedef void( * CgprogramCopyHookFunction )( _CGprogram *newprogram, _CGprogram *oldprogram );
extern CgprogramHookFunction _cgProgramCreateHook;
extern CgprogramHookFunction _cgProgramDestroyHook;
extern CgprogramCopyHookFunction _cgProgramCopyHook;
typedef int( * cgRTCgcCompileHookFunction )( const char*, const char *, const char*, const char**, char** );
typedef void( * cgRTCgcFreeHookFunction )( char* );
extern cgRTCgcCompileHookFunction _cgRTCgcCompileProgramHook;
extern cgRTCgcFreeHookFunction _cgRTCgcFreeCompiledProgramHook;
static inline const CgParameterResource *_RGLGetParameterResource( const _CGprogram *program, const CgParameterEntry *entry )
{
return ( CgParameterResource * )( program->parameterResources + entry->typeIndex );
}
static inline const CgParameterArray *_RGLGetParameterArray( const _CGprogram *program, const CgParameterEntry *entry )
{
return ( CgParameterArray* )( program->parameterResources + entry->typeIndex );
}
static inline const CgParameterStructure *_RGLGetParameterStructure( const _CGprogram *program, const CgParameterEntry *entry )
{
return ( CgParameterStructure* )( program->parameterResources + entry->typeIndex );
}
inline int _RGLGetProgramProfileIndex( CGprofile profile )
{
if ( profile == CG_PROFILE_SCE_FP_TYPEB || profile == CG_PROFILE_SCE_FP_TYPEC || profile == CG_PROFILE_SCE_FP_RSX )
return FRAGMENT_PROFILE_INDEX;
else if ( profile == CG_PROFILE_SCE_VP_TYPEB || profile == CG_PROFILE_SCE_VP_TYPEC || profile == CG_PROFILE_SCE_VP_RSX )
return VERTEX_PROFILE_INDEX;
else
return -1;
}
CGGL_API void cgGLSetMatrixParameterfc( CGparameter param, const float *matrix );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,368 +0,0 @@
#include <string>
#include <cstddef>
#include <Cg/cgc.h>
#include <Cg/cgGL.h>
#include <Cg/cgBinary.h>
#include "cgbio.hpp"
using std::fill_n;
namespace cgc {
namespace bio {
bin_io* bin_io::instance_ = 0;
bin_io::bin_io()
{
}
bin_io::bin_io( const bin_io& )
{
}
const bin_io* bin_io::instance()
{
if ( 0 == instance_ )
{
instance_ = new bin_io;
}
return instance_;
}
void bin_io::delete_instance()
{
if ( 0 != instance_ )
{
delete instance_;
instance_ = 0;
}
}
CGBIO_ERROR bin_io::new_elf_reader( elf_reader** obj ) const
{
CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR;
*obj = new elf_reader_impl;
if ( 0 == *obj )
ret = CGBIO_ERROR_MEMORY;
return ret;
}
const char*
bin_io::error_string( CGBIO_ERROR error ) const
{
switch ( error )
{
case CGBIO_ERROR_NO_ERROR:
return "No error";
case CGBIO_ERROR_LOADED:
return "Binary file has been loaded earlier";
case CGBIO_ERROR_FILEIO:
return "File input output error";
case CGBIO_ERROR_FORMAT:
return "File format error";
case CGBIO_ERROR_INDEX:
return "Index is out of range";
case CGBIO_ERROR_MEMORY:
return "Can't allocate memory";
case CGBIO_ERROR_RELOC:
return "Relocation error";
case CGBIO_ERROR_SYMBOL:
return "Symbol error";
case CGBIO_ERROR_UNKNOWN_TYPE:
return "Uknown type";
default:
return "Unknown error";
}
return "Unknown error";
}
CGBIO_ERROR
bin_io::new_nvb_reader( nvb_reader** obj ) const
{
CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR;
*obj = new nvb_reader_impl;
if ( *obj == 0 )
ret = CGBIO_ERROR_MEMORY;
return ret;
}
nvb_reader_impl::nvb_reader_impl()
{
ref_count_ = 1;
offset_ = 0;
image_ = 0;
owner_ = false;
loaded_ = false;
endianness_ = host_endianness();
std::fill_n( reinterpret_cast<char*>( &header_ ), sizeof( header_ ), '\0' );
}
nvb_reader_impl::~nvb_reader_impl()
{
if ( image_ != 0 )
delete [] image_;
}
ptrdiff_t
nvb_reader_impl::reference() const
{
return ++ref_count_;
}
ptrdiff_t
nvb_reader_impl::release() const
{
ptrdiff_t ret = --ref_count_;
if ( ref_count_ == 0 )
delete this;
return ret;
}
CGBIO_ERROR
nvb_reader_impl::loadFromString( const char* source, size_t length)
{
if ( loaded_ )
{
return CGBIO_ERROR_LOADED;
}
CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR;
while (1)
{
if (length < sizeof( header_ ))
{
ret = CGBIO_ERROR_FORMAT;
break;
}
memcpy(&header_ ,source,sizeof( header_ ));
if ( CG_BINARY_FORMAT_REVISION != header_.binaryFormatRevision )
{
endianness_ = ( CGBIODATALSB == endianness_ ) ? CGBIODATAMSB : CGBIODATALSB;
int binaryRevision = convert_endianness( header_.binaryFormatRevision, endianness_ );
if ( CG_BINARY_FORMAT_REVISION != binaryRevision )
{
ret = CGBIO_ERROR_FORMAT;
break;
}
}
size_t sz = length;
image_ = new char[sz];
memcpy(image_,source,sz);
loaded_ = true;
ret = CGBIO_ERROR_NO_ERROR;
break;
}
return ret;
}
bool
nvb_reader_impl::is_loaded() const
{
return loaded_;
}
unsigned char
nvb_reader_impl::endianness() const
{
return endianness_;
}
CGprofile
nvb_reader_impl::profile() const
{
return (CGprofile) convert_endianness( (unsigned int) header_.profile, endianness() );
}
unsigned int
nvb_reader_impl::revision() const
{
return convert_endianness( header_.binaryFormatRevision, endianness() );
}
unsigned int nvb_reader_impl::size() const
{
return convert_endianness( header_.totalSize, endianness() );
}
unsigned int nvb_reader_impl::number_of_params() const
{
return convert_endianness( header_.parameterCount, endianness() );
}
unsigned int nvb_reader_impl::ucode_size() const
{
return convert_endianness( header_.ucodeSize, endianness() );
}
const char* nvb_reader_impl::ucode() const
{
if ( 0 == image_ || 0 == ucode_size() )
return 0;
return ( image_ + convert_endianness( header_.ucode, endianness() ) );
}
const CgBinaryFragmentProgram*
nvb_reader_impl::fragment_program() const
{
if ( 0 == image_ )
return 0;
return reinterpret_cast<CgBinaryFragmentProgram*>( &image_[convert_endianness( header_.program, endianness_ )] );
}
const CgBinaryVertexProgram* nvb_reader_impl::vertex_program() const
{
if ( 0 == image_ )
return 0;
return reinterpret_cast<CgBinaryVertexProgram*>( &image_[convert_endianness( header_.program, endianness_ )] );
}
CGBIO_ERROR nvb_reader_impl::get_param_name( unsigned int index, const char **name, bool& is_referenced ) const
{
if ( index >= number_of_params() )
return CGBIO_ERROR_INDEX;
if ( 0 == image_ )
return CGBIO_ERROR_NO_ERROR;
const CgBinaryParameter* params = reinterpret_cast<CgBinaryParameter*>( &image_[convert_endianness( header_.parameterArray, endianness_ )] );
const CgBinaryParameter& pp = params[index];
is_referenced = convert_endianness( pp.isReferenced, endianness() ) != 0;
CgBinaryStringOffset nm_offset = convert_endianness( pp.name,endianness() );
if ( nm_offset != 0 )
*name = &image_[nm_offset];
else
*name = "";
return CGBIO_ERROR_NO_ERROR;
}
CGBIO_ERROR
nvb_reader_impl::get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char ** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char ** semantic,
int& paramno,
bool& is_referenced,
bool& is_shared ) const
{
if ( index >= number_of_params() )
return CGBIO_ERROR_INDEX;
if ( 0 == image_ )
return CGBIO_ERROR_NO_ERROR;
const CgBinaryParameter* params = reinterpret_cast<CgBinaryParameter*>( &image_[convert_endianness( header_.parameterArray, endianness_ )] );
const CgBinaryParameter& pp = params[index];
type = static_cast<CGtype>(convert_endianness( static_cast<unsigned int>( pp.type ), endianness() ) );
resource = static_cast<CGresource>(convert_endianness( static_cast<unsigned int>( pp.res ), endianness() ) );
variability = static_cast<CGenum>(convert_endianness( static_cast<unsigned int>( pp.var ),endianness() ) );
resource_index = convert_endianness( pp.resIndex,endianness() );
paramno = convert_endianness( pp.paramno, endianness() );
is_referenced = convert_endianness( pp.isReferenced,endianness() ) != 0;
is_shared = convert_endianness( pp.isShared,endianness() ) != 0;
CgBinaryStringOffset nm_offset = convert_endianness( pp.name,endianness() );
CgBinaryFloatOffset dv_offset = convert_endianness( pp.defaultValue,endianness() );
CgBinaryEmbeddedConstantOffset ec_offset = convert_endianness( pp.embeddedConst,endianness() );
CgBinaryStringOffset sm_offset = convert_endianness( pp.semantic,endianness() );
if ( 0 != nm_offset )
{
*name = &image_[nm_offset];
}
else
*name = "";
if ( 0 != sm_offset )
{
*semantic = &image_[sm_offset];
}
else
*semantic = "";
if ( 0 != dv_offset )
{
char *vp = &image_[dv_offset];
for (int ii = 0; ii < 4; ++ii)
{
int tmp;
memcpy(&tmp,vp+4*ii,4);
tmp = convert_endianness(tmp,endianness());
float tmp2;
memcpy(&tmp2,&tmp,4);
default_value.push_back( tmp2 );
}
}
if ( 0 != ec_offset )
{
void *vp = &image_[ec_offset];
CgBinaryEmbeddedConstant& ec = *(static_cast<CgBinaryEmbeddedConstant*>( vp ));
for (unsigned int ii = 0; ii < convert_endianness( ec.ucodeCount, endianness() ); ++ii)
{
unsigned int offset = convert_endianness( ec.ucodeOffset[ii], endianness() );
embedded_constants.push_back( offset );
}
}
return CGBIO_ERROR_NO_ERROR;
}
elf_reader_impl::elf_reader_impl()
{
ref_count_ = 1;
initialized_ = false;
fill_n( reinterpret_cast<char*>( &header_ ), sizeof( header_ ), '\0' );
}
elf_reader_impl::~elf_reader_impl()
{
}
CGBIO_ERROR
elf_reader_impl::load( const char* filename )
{
return CGBIO_ERROR_NO_ERROR;
}
CGBIO_ERROR
elf_reader_impl::load( std::istream* stream, int start )
{
return CGBIO_ERROR_NO_ERROR;
}
bool
elf_reader_impl::is_initialized() const
{
return initialized_;
}
ptrdiff_t
elf_reader_impl::reference() const
{
return ++ref_count_;
}
ptrdiff_t
elf_reader_impl::release() const
{
ptrdiff_t ret = --ref_count_;
if ( 0 == ref_count_ )
{
delete this;
}
return ret;
}
}
}

View File

@ -1,552 +0,0 @@
#ifndef CGC_CGBIO_CGBDEFS_HPP
#define CGC_CGBIO_CGBDEFS_HPP
#include <vector>
#define CGF_OUTPUTFROMH0 0x01
#define CGF_DEPTHREPLACE 0x02
#define CGF_PIXELKILL 0x04
typedef size_t ptrdiff_t;
typedef size_t ptrdiff_t;
typedef struct _Elf32_cgParameter
{
unsigned int cgp_name;
unsigned int cgp_semantic;
unsigned short cgp_default;
unsigned short cgp_reloc;
unsigned short cgp_resource;
unsigned short cgp_resource_index;
unsigned char cgp_type;
unsigned short cgp_info;
unsigned char unused;
} Elf32_cgParameter;
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_LOOS 0xFE00
#define ET_HIOS 0xFEFF
#define ET_LOPROC 0xFF00
#define ET_HIPROC 0xFFFF
#define EM_NONE 0
#define EM_RSX 0x528e
#define EM_RSX_NONE 0
#define EI_ABIVERSION_RSX 1
#define EV_NONE 0
#define EV_CURRENT 1
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_ABIVERSION 8
#define EI_PAD 9
#define EI_NIDENT 16
#define ELFMAG0 0x7F
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFOSABI_NONE 0
#define ELFOSABI_HPUX 1
#define ELFOSABI_NETBSD 2
#define ELFOSABI_LINUX 3
#define ELFOSABI_SOLARIS 6
#define ELFOSABI_AIX 7
#define ELFOSABI_IRIX 8
#define ELFOSABI_FREEBSD 9
#define ELFOSABI_TRU64 10
#define ELFOSABI_MODESTO 11
#define ELFOSABI_OPENBSD 12
#define ELFOSABI_CGRUNTIME 19
#define SHN_UNDEF 0
#define SHN_LORESERVE 0xFF00
#define SHN_LOPROC 0xFF00
#define SHN_HIPROC 0xFF1F
#define SHN_LOOS 0xFF20
#define SHN_HIOS 0xFF3F
#define SHN_ABS 0xFFF1
#define SHN_COMMON 0xFFF2
#define SHN_XINDEX 0xFFFF
#define SHN_HIRESERVE 0xFFFF
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHT_INIT_ARRAY 14
#define SHT_FINI_ARRAY 15
#define SHT_PREINIT_ARRAY 16
#define SHT_GROUP 17
#define SHT_SYMTAB_SHNDX 18
#define SHT_LOOS 0x60000000
#define SHT_HIOS 0x6fffffff
#define SHT_LOPROC 0x70000000
#define SHT_RSX_PARAM 0x70000000
#define SHT_RSX_SHADERTAB 0x70000001
#define SHT_RSX_FXTAB 0x70000002
#define SHT_RSX_ANNOTATE 0x70000003
#define SHT_HIPROC 0x7FFFFFFF
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xFFFFFFFF
#define SHF_WRITE 0x1
#define SHF_ALLOC 0x2
#define SHF_EXECINSTR 0x4
#define SHF_MERGE 0x10
#define SHF_STRINGS 0x20
#define SHF_INFO_LINK 0x40
#define SHF_LINK_ORDER 0x80
#define SHF_OS_NONCONFORMING 0x100
#define SHF_GROUP 0x200
#define SHF_TLS 0x400
#define SHF_MASKOS 0x0ff00000
#define SHF_MASKPROC 0xF0000000
#define GRP_COMDAT 0x1
#define GRP_MASKOS 0x0ff00000
#define GRP_MASKPROC 0xf0000000
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_LOOS 10
#define STB_HIOS 12
#define STB_LOPROC 13
#define STB_HIPROC 15
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_COMMON 5
#define STT_TLS 6
#define STT_LOOS 10
#define STT_HIOS 12
#define STT_LOPROC 13
#define STT_HIPROC 15
#define STV_DEFAULT 0
#define STV_INTERNAL 1
#define STV_HIDDEN 2
#define STV_PROTECTED 3
#define STO_RSX_SHADER 0
#define STO_RSX_EFFECT 1
#define STN_UNDEF 0
#define R_RSX_NONE 0
#define R_RSX_FLOAT4 1
struct Elf32_Ehdr
{
unsigned char e_ident[EI_NIDENT];
unsigned short e_type;
unsigned short e_machine;
unsigned int e_version;
unsigned int e_entry;
unsigned int e_phoff;
unsigned int e_shoff;
unsigned int e_flags;
unsigned short e_ehsize;
unsigned short e_phentsize;
unsigned short e_phnum;
unsigned short e_shentsize;
unsigned short e_shnum;
unsigned short e_shstrndx;
};
struct Elf32_Shdr {
unsigned int sh_name;
unsigned int sh_type;
unsigned int sh_flags;
unsigned int sh_addr;
unsigned int sh_offset;
unsigned int sh_size;
unsigned int sh_link;
unsigned int sh_info;
unsigned int sh_addralign;
unsigned int sh_entsize;
};
struct Elf32_Phdr {
unsigned int p_type;
unsigned int p_offset;
unsigned int p_vaddr;
unsigned int p_paddr;
unsigned int p_filesz;
unsigned int p_memsz;
unsigned int p_flags;
unsigned int p_align;
};
struct Elf32_Sym {
unsigned int st_name;
unsigned int st_value;
unsigned int st_size;
unsigned char st_info;
unsigned char st_other;
unsigned short st_shndx;
};
struct Elf32_Note
{
unsigned int n_namesz; /* Name size */
unsigned int n_descsz; /* Content size */
unsigned int n_type; /* Content type */
};
struct Elf32_Rel {
unsigned int r_offset;
unsigned int r_info;
};
struct Elf32_Rela {
unsigned int r_offset;
unsigned int r_info;
signed int r_addend;
};
struct Elf32_Dyn {
signed int d_tag;
union {
unsigned int d_val;
unsigned int d_ptr;
} d_un;
};
using std::istream;
namespace cgc {
namespace bio {
enum CGBIO_ERROR {
CGBIO_ERROR_NO_ERROR,
CGBIO_ERROR_LOADED,
CGBIO_ERROR_FILEIO,
CGBIO_ERROR_FORMAT,
CGBIO_ERROR_INDEX,
CGBIO_ERROR_MEMORY,
CGBIO_ERROR_RELOC,
CGBIO_ERROR_SYMBOL,
CGBIO_ERROR_UNKNOWN_TYPE
};
typedef enum {
CGBIODATANONE = ELFDATANONE,
CGBIODATALSB = ELFDATA2LSB,
CGBIODATAMSB = ELFDATA2MSB
} HOST_ENDIANNESS;
class elf_reader
{
public:
virtual ptrdiff_t reference() const = 0;
virtual ptrdiff_t release() const = 0;
virtual CGBIO_ERROR load( const char * filename ) = 0;
virtual CGBIO_ERROR load( istream* stream, int start ) = 0;
virtual bool is_initialized() const = 0;
virtual ~elf_reader() {}
};
class nvb_reader
{
public:
virtual ~nvb_reader() {}
virtual ptrdiff_t
reference() const = 0;
virtual ptrdiff_t
release() const = 0;
virtual CGBIO_ERROR
loadFromString( const char* source, size_t length ) = 0;
virtual bool
is_loaded() const = 0;
virtual unsigned char
endianness() const = 0;
virtual CGprofile
profile() const = 0;
virtual unsigned int
revision() const = 0;
virtual unsigned int
size() const = 0;
virtual unsigned int
number_of_params() const = 0;
virtual unsigned int
ucode_size() const = 0;
virtual const char*
ucode() const = 0;
virtual const CgBinaryFragmentProgram*
fragment_program() const = 0;
virtual const CgBinaryVertexProgram*
vertex_program() const = 0;
virtual CGBIO_ERROR
get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char** semantic,
int& paramno,
bool& is_referenced,
bool& is_shared ) const = 0;
virtual CGBIO_ERROR get_param_name( unsigned int index, const char** name, bool& is_referenced) const = 0;
};
class bin_io
{
public:
static const bin_io* instance();
static void delete_instance();
CGBIO_ERROR new_elf_reader( elf_reader** obj ) const;
CGBIO_ERROR new_nvb_reader( nvb_reader** obj ) const;
const char *error_string( CGBIO_ERROR error ) const;
private:
bin_io();
bin_io( const bin_io& );
static bin_io* instance_;
};
class isection
{
public:
virtual ~isection() = 0;
virtual int reference() const = 0;
virtual int release() const = 0;
virtual unsigned short index() const = 0;
virtual char *name() const = 0;
virtual unsigned int type() const = 0;
virtual unsigned int flags() const = 0;
virtual unsigned int addr() const = 0;
virtual unsigned int size() const = 0;
virtual unsigned int link() const = 0;
virtual unsigned int info() const = 0;
virtual unsigned int addralign() const = 0;
virtual unsigned int entsize() const = 0;
virtual const char* data() const = 0;
};
class elf_reader_impl : public elf_reader
{
public:
elf_reader_impl();
virtual ~elf_reader_impl();
virtual CGBIO_ERROR load( const char* filename );
virtual CGBIO_ERROR load( istream* stream, int start );
virtual bool is_initialized() const;
virtual ptrdiff_t reference() const;
virtual ptrdiff_t release() const;
private:
mutable ptrdiff_t ref_count_;
istream* stream_;
bool initialized_;
Elf32_Ehdr header_;
std::vector<const isection*> sections_;
};
inline HOST_ENDIANNESS host_endianness()
{
const int ii = 1;
const char* cp = (const char*) &ii;
return ( 1 == cp[0] ) ? CGBIODATALSB : CGBIODATAMSB;
}
template< typename T > inline T
convert_endianness( const T value, unsigned char endianness )
{
if ( host_endianness() == endianness )
{
return value;
}
if ( sizeof( T ) == 1 )
{
return value;
}
if ( sizeof( T ) == 2 )
{
return ( ((value & 0x00FF) << 8)
| ((value & 0xFF00) >> 8) );
}
if ( sizeof( T ) == 4 )
{
return ( ((value & 0x000000FF) << 24)
| ((value & 0x0000FF00) << 8)
| ((value & 0x00FF0000) >> 8)
| ((value & 0xFF000000) >> 24) );
}
if ( sizeof( T ) == 8 )
{
T result = value;
for ( int ii = 0; ii < 4; ++ii )
{
char ch = *( (( char* ) &result) + ii );
*( (( char* ) &result) + ii ) = *( (( char* ) &result) + (7 - ii) );
*( (( char* ) &result) + (7 - ii) ) = ch;
}
return result;
}
return value;
}
template< typename T > inline T
ELF32_ST_BIND( const T idx )
{
return ( idx >> 4 );
}
template< typename T > inline T
ELF32_ST_TYPE( const T idx )
{
return ( idx & 0xf );
}
template< typename T > inline T
ELF32_ST_INFO( const T b, const T t )
{
return ( ( b << 4 ) + ( t & 0xf ) );
}
template< typename T > inline T
ELF32_ST_VISIBILITY( const T o )
{
return ( o & 0x3 );
}
class nvb_reader_impl : public nvb_reader
{
public:
nvb_reader_impl();
virtual
~nvb_reader_impl();
virtual ptrdiff_t
reference() const;
virtual ptrdiff_t
release() const;
virtual CGBIO_ERROR
loadFromString( const char* source, size_t length);
virtual bool
is_loaded() const;
virtual unsigned char
endianness() const;
virtual CGprofile
profile() const;
virtual unsigned int
revision() const;
virtual unsigned int
size() const;
virtual unsigned int
number_of_params() const;
virtual unsigned int
ucode_size() const;
virtual const char*
ucode() const;
virtual const CgBinaryFragmentProgram*
fragment_program() const;
virtual const CgBinaryVertexProgram*
vertex_program() const;
virtual CGBIO_ERROR
get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char ** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char ** semantic,
int& paramno,
bool& is_referenced,
bool& is_shared ) const;
virtual CGBIO_ERROR get_param_name( unsigned int index, const char ** name , bool& is_referenced) const;
private:
mutable ptrdiff_t ref_count_;
int offset_;
bool loaded_;
bool owner_;
bool strStream_;
CgBinaryProgram header_;
unsigned char endianness_;
char* image_;
};
}
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,153 +0,0 @@
#ifndef ELF_H
#define ELF_H 1
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_ABIVERSION 8
#define EI_PAD 9
#define EI_NIDENT 16
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define EV_NONE 0
#define EV_CURRENT 1
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define EM_PPC 20
#define EM_PPC64 21
typedef struct {
unsigned char e_ident[EI_NIDENT];
unsigned short e_type;
unsigned short e_machine;
unsigned int e_version;
unsigned int e_entry;
unsigned int e_phoff;
unsigned int e_shoff;
unsigned int e_flags;
unsigned short e_ehsize;
unsigned short e_phentsize;
unsigned short e_phnum;
unsigned short e_shentsize;
unsigned short e_shnum;
unsigned short e_shstrndx;
} Elf32_Ehdr;
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_LOOS 0x60000000
#define PT_HIOS 0x6fffffff
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
typedef struct {
unsigned int p_type;
unsigned int p_offset;
unsigned int p_vaddr;
unsigned int p_paddr;
unsigned int p_filesz;
unsigned int p_memsz;
unsigned int p_flags;
unsigned int p_align;
} Elf32_Phdr;
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHF_WRITE (1 << 0)
#define SHF_ALLOC (1 << 1)
#define SHF_EXECINSTR (1 << 2)
#define SHF_MERGE (1 << 4)
#define SHF_STRINGS (1 << 5)
#define SHF_INFO_LINK (1 << 6)
#define SHF_LINK_ORDER (1 << 7)
#define SHF_OS_NONCONFORMING (1 << 8)
#define SHF_MASKOS 0x0ff00000
#define SHF_MASKPROC 0xf0000000
typedef struct {
unsigned int sh_name;
unsigned int sh_type;
unsigned int sh_flags;
unsigned int sh_addr;
unsigned int sh_offset;
unsigned int sh_size;
unsigned int sh_link;
unsigned int sh_info;
unsigned int sh_addralign;
unsigned int sh_entsize;
} Elf32_Shdr;
#define SHN_UNDEF 0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC 0xff00
#define SHN_HIPROC 0xff1f
#define SHN_LOOS 0xff20
#define SHN_HIOS 0xff3f
#define SHN_ABS 0xfff1
#define SHN_COMMON 0xfff2
#define SHN_XINDEX 0xffff
#define SHN_HIRESERVE 0xffff
typedef struct {
unsigned int st_name;
unsigned int st_value;
unsigned int st_size;
unsigned char st_info;
unsigned char st_other;
unsigned short st_shndx;
} Elf32_Sym;
typedef struct
{
unsigned int r_offset;
unsigned int r_info;
} Elf32_Rel;
typedef struct
{
unsigned int r_offset;
unsigned int r_info;
int r_addend;
} Elf32_Rela;
#endif /* ELF_H */

View File

@ -1,323 +0,0 @@
#ifndef __gl_h_
#define __gl_h_
#ifdef __cplusplus
extern "C"
{
#endif
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.0 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
#ifdef PSGL_EXPORT
#define GLAPI PSGL_EXPORT
#endif
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SYMBIAN32__)
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef GLAPI
#define GLAPI extern
#endif
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef int GLsizei;
typedef unsigned char GLubyte;
typedef unsigned short GLushort;
typedef unsigned int GLuint;
typedef float GLfloat;
typedef float GLclampf;
typedef void GLvoid;
typedef int GLfixed;
typedef int GLclampx;
typedef void( *_GLfuncptr )();
#define GL_OES_VERSION_1_0 1
#define GL_OES_read_format 1
#define GL_OES_compressed_paletted_texture 1
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_STENCIL_BUFFER_BIT 0x00000400
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_FALSE 0
#define GL_TRUE 1
#define GL_POINTS 0x0000
#define GL_LINES 0x0001
#define GL_LINE_LOOP 0x0002
#define GL_LINE_STRIP 0x0003
#define GL_TRIANGLES 0x0004
#define GL_TRIANGLE_STRIP 0x0005
#define GL_TRIANGLE_FAN 0x0006
#define GL_NEVER 0x0200
#define GL_LESS 0x0201
#define GL_EQUAL 0x0202
#define GL_LEQUAL 0x0203
#define GL_GREATER 0x0204
#define GL_NOTEQUAL 0x0205
#define GL_GEQUAL 0x0206
#define GL_ALWAYS 0x0207
#define GL_ZERO 0
#define GL_ONE 1
#define GL_SRC_COLOR 0x0300
#define GL_ONE_MINUS_SRC_COLOR 0x0301
#define GL_SRC_ALPHA 0x0302
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
#define GL_DST_ALPHA 0x0304
#define GL_ONE_MINUS_DST_ALPHA 0x0305
#define GL_DST_COLOR 0x0306
#define GL_ONE_MINUS_DST_COLOR 0x0307
#define GL_SRC_ALPHA_SATURATE 0x0308
#define GL_FRONT 0x0404
#define GL_BACK 0x0405
#define GL_FRONT_AND_BACK 0x0408
#define GL_TEXTURE_2D 0x0DE1
#define GL_BLEND 0x0BE2
#define GL_DITHER 0x0BD0
#define GL_POINT_SMOOTH 0x0B10
#define GL_LINE_SMOOTH 0x0B20
#define GL_SCISSOR_TEST 0x0C11
#define GL_COLOR_MATERIAL 0x0B57
#define GL_NORMALIZE 0x0BA1
#define GL_RESCALE_NORMAL 0x803A
#define GL_POLYGON_OFFSET_FILL 0x8037
#define GL_VERTEX_ARRAY 0x8074
#define GL_NORMAL_ARRAY 0x8075
#define GL_COLOR_ARRAY 0x8076
#define GL_TEXTURE_COORD_ARRAY 0x8078
#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
#define GL_SAMPLE_COVERAGE 0x80A0
#define GL_NO_ERROR 0
#define GL_INVALID_ENUM 0x0500
#define GL_INVALID_VALUE 0x0501
#define GL_INVALID_OPERATION 0x0502
#define GL_STACK_OVERFLOW 0x0503
#define GL_STACK_UNDERFLOW 0x0504
#define GL_OUT_OF_MEMORY 0x0505
#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A
#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B
#define GL_MAX_LIGHTS 0x0D31
#define GL_MAX_TEXTURE_SIZE 0x0D33
#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
#define GL_MAX_VIEWPORT_DIMS 0x0D3A
#define GL_MAX_ELEMENTS_VERTICES 0x80E8
#define GL_MAX_ELEMENTS_INDICES 0x80E9
#define GL_MAX_TEXTURE_UNITS 0x84E2
#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
#define GL_SUBPIXEL_BITS 0x0D50
#define GL_RED_BITS 0x0D52
#define GL_GREEN_BITS 0x0D53
#define GL_BLUE_BITS 0x0D54
#define GL_ALPHA_BITS 0x0D55
#define GL_DEPTH_BITS 0x0D56
#define GL_STENCIL_BITS 0x0D57
#define GL_DONT_CARE 0x1100
#define GL_FASTEST 0x1101
#define GL_NICEST 0x1102
#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
#define GL_POINT_SMOOTH_HINT 0x0C51
#define GL_LINE_SMOOTH_HINT 0x0C52
#define GL_POLYGON_SMOOTH_HINT 0x0C53
#define GL_FOG_HINT 0x0C54
#define GL_BYTE 0x1400
#define GL_UNSIGNED_BYTE 0x1401
#define GL_SHORT 0x1402
#define GL_UNSIGNED_SHORT 0x1403
#define GL_FLOAT 0x1406
#define GL_FIXED 0x140C
#define GL_CLEAR 0x1500
#define GL_AND 0x1501
#define GL_AND_REVERSE 0x1502
#define GL_COPY 0x1503
#define GL_AND_INVERTED 0x1504
#define GL_NOOP 0x1505
#define GL_XOR 0x1506
#define GL_OR 0x1507
#define GL_NOR 0x1508
#define GL_EQUIV 0x1509
#define GL_INVERT 0x150A
#define GL_OR_REVERSE 0x150B
#define GL_COPY_INVERTED 0x150C
#define GL_OR_INVERTED 0x150D
#define GL_NAND 0x150E
#define GL_SET 0x150F
#define GL_EMISSION 0x1600
#define GL_SHININESS 0x1601
#define GL_AMBIENT_AND_DIFFUSE 0x1602
#define GL_MODELVIEW 0x1700
#define GL_PROJECTION 0x1701
#define GL_TEXTURE 0x1702
#define GL_ALPHA 0x1906
#define GL_RGB 0x1907
#define GL_RGBA 0x1908
#define GL_LUMINANCE 0x1909
#define GL_LUMINANCE_ALPHA 0x190A
#define GL_UNPACK_ALIGNMENT 0x0CF5
#define GL_PACK_ALIGNMENT 0x0D05
#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
#define GL_FLAT 0x1D00
#define GL_SMOOTH 0x1D01
#define GL_KEEP 0x1E00
#define GL_REPLACE 0x1E01
#define GL_INCR 0x1E02
#define GL_DECR 0x1E03
#define GL_VENDOR 0x1F00
#define GL_RENDERER 0x1F01
#define GL_VERSION 0x1F02
#define GL_EXTENSIONS 0x1F03
#define GL_MODULATE 0x2100
#define GL_DECAL 0x2101
#define GL_ADD 0x0104
#define GL_TEXTURE_ENV_MODE 0x2200
#define GL_TEXTURE_ENV_COLOR 0x2201
#define GL_TEXTURE_ENV 0x2300
#define GL_NEAREST 0x2600
#define GL_LINEAR 0x2601
#define GL_NEAREST_MIPMAP_NEAREST 0x2700
#define GL_LINEAR_MIPMAP_NEAREST 0x2701
#define GL_NEAREST_MIPMAP_LINEAR 0x2702
#define GL_LINEAR_MIPMAP_LINEAR 0x2703
#define GL_TEXTURE_MAG_FILTER 0x2800
#define GL_TEXTURE_MIN_FILTER 0x2801
#define GL_TEXTURE_WRAP_S 0x2802
#define GL_TEXTURE_WRAP_T 0x2803
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
#define GL_TEXTURE5 0x84C5
#define GL_TEXTURE6 0x84C6
#define GL_TEXTURE7 0x84C7
#define GL_TEXTURE8 0x84C8
#define GL_TEXTURE9 0x84C9
#define GL_TEXTURE10 0x84CA
#define GL_TEXTURE11 0x84CB
#define GL_TEXTURE12 0x84CC
#define GL_TEXTURE13 0x84CD
#define GL_TEXTURE14 0x84CE
#define GL_TEXTURE15 0x84CF
#define GL_TEXTURE16 0x84D0
#define GL_TEXTURE17 0x84D1
#define GL_TEXTURE18 0x84D2
#define GL_TEXTURE19 0x84D3
#define GL_TEXTURE20 0x84D4
#define GL_TEXTURE21 0x84D5
#define GL_TEXTURE22 0x84D6
#define GL_TEXTURE23 0x84D7
#define GL_TEXTURE24 0x84D8
#define GL_TEXTURE25 0x84D9
#define GL_TEXTURE26 0x84DA
#define GL_TEXTURE27 0x84DB
#define GL_TEXTURE28 0x84DC
#define GL_TEXTURE29 0x84DD
#define GL_TEXTURE30 0x84DE
#define GL_TEXTURE31 0x84DF
#define GL_REPEAT 0x2901
#define GL_CLAMP_TO_EDGE 0x812F
GLAPI void APIENTRY glActiveTexture( GLenum texture );
GLAPI void APIENTRY glBindTexture( GLenum target, GLuint texture );
GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor );
GLAPI void APIENTRY glClear( GLbitfield mask );
GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
GLAPI void APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha );
GLAPI void APIENTRY glClientActiveTexture( GLenum texture );
GLAPI void APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height );
GLAPI void APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures );
GLAPI void APIENTRY glDisable( GLenum cap );
GLAPI void APIENTRY glDisableClientState( GLenum array );
GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count );
GLAPI void APIENTRY glEnable( GLenum cap );
GLAPI void APIENTRY glEnableClientState( GLenum array );
GLAPI void APIENTRY glFinish( void );
GLAPI void APIENTRY glFlush( void );
GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures );
GLAPI GLenum APIENTRY glGetError( void );
GLAPI const GLubyte * APIENTRY glGetString( GLenum name );
GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param );
GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels );
GLAPI void APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height );
#ifdef __cplusplus
}
#endif
#endif /* __gl_h_ */

View File

@ -1,274 +0,0 @@
#ifndef __gl_ext_h_
#define __gl_ext_h_
#ifndef _MSC_VER
#include <stdint.h>
#else
#include <stddef.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
typedef intptr_t GLintptr;
typedef intptr_t GLsizeiptr;
typedef unsigned short GLhalfARB;
#define GL_QUADS 0x0007
#define GL_QUAD_STRIP 0x0008
#define GL_INT 0x1404
#define GL_UNSIGNED_INT 0x1405
#define GL_UNSIGNED_BYTE_3_3_2 0x8032
#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
#define GL_UNSIGNED_INT_8_8_8_8 0x8035
#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
#define GL_UNSIGNED_INT_10_10_10_2 0x8036
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
#define GL_UNSIGNED_INT_24_8_SCE 0x6008
#define GL_UNSIGNED_INT_8_24_REV_SCE 0x6009
#define GL_HALF_FLOAT_ARB 0x140B
#define GL_ALPHA4 0x803B
#define GL_ALPHA8 0x803C
#define GL_ALPHA12 0x803D
#define GL_ALPHA16 0x803E
#define GL_LUMINANCE4 0x803F
#define GL_LUMINANCE8 0x8040
#define GL_LUMINANCE12 0x8041
#define GL_LUMINANCE16 0x8042
#define GL_LUMINANCE4_ALPHA4 0x8043
#define GL_LUMINANCE6_ALPHA2 0x8044
#define GL_LUMINANCE8_ALPHA8 0x8045
#define GL_LUMINANCE12_ALPHA4 0x8046
#define GL_LUMINANCE12_ALPHA12 0x8047
#define GL_LUMINANCE16_ALPHA16 0x8048
#define GL_INTENSITY 0x8049
#define GL_INTENSITY4 0x804A
#define GL_INTENSITY8 0x804B
#define GL_INTENSITY12 0x804C
#define GL_INTENSITY16 0x804D
#define GL_R3_G3_B2 0x2A10
#define GL_RGB4 0x804F
#define GL_RGB5 0x8050
#define GL_RGB8 0x8051
#define GL_RGB10 0x8052
#define GL_RGB12 0x8053
#define GL_RGB16 0x8054
#define GL_RGBA2 0x8055
#define GL_RGBA4 0x8056
#define GL_RGB5_A1 0x8057
#define GL_RGB10_A2 0x8059
#define GL_RGBA12 0x805A
#define GL_RGBA16 0x805B
#define GL_BGR 0x80E0
#define GL_BGRA 0x80E1
#define GL_ABGR 0x8000
#define GL_RED 0x1903
#define GL_GREEN 0x1904
#define GL_BLUE 0x1905
#define GL_ARGB_SCE 0x6007
#define GL_UNSIGNED_SHORT_8_8_SCE 0x600B
#define GL_UNSIGNED_SHORT_8_8_REV_SCE 0x600C
#define GL_UNSIGNED_INT_16_16_SCE 0x600D
#define GL_UNSIGNED_INT_16_16_REV_SCE 0x600E
#define GL_CONSTANT_COLOR 0x8001
#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
#define GL_CONSTANT_ALPHA 0x8003
#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
#define GL_BLEND_EQUATION 0x8009
#define GL_FUNC_ADD 0x8006
#define GL_MIN 0x8007
#define GL_MAX 0x8008
#define GL_FUNC_SUBTRACT 0x800A
#define GL_FUNC_REVERSE_SUBTRACT 0x800B
#define GL_TEXTURE_WRAP_R 0x8072
#define GL_MAX_3D_TEXTURE_SIZE 0x8073
#define GL_POINT 0x1B00
#define GL_LINE 0x1B01
#define GL_FILL 0x1B02
#define GL_TEXTURE_FILTER_CONTROL 0x8500
#define GL_TEXTURE_LOD_BIAS 0x8501
#define GL_TEXTURE_MIN_LOD 0x813A
#define GL_TEXTURE_MAX_LOD 0x813B
#define GL_TEXTURE_MAX_LEVEL 0x813D
#define GL_TEXTURE_BORDER_COLOR 0x1004
#define GL_NONE 0x0
#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
#define GL_CLAMP 0x2900
#define GL_MIRRORED_REPEAT 0x8370
#define GL_MIRROR_CLAMP_EXT 0x8742
#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743
#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912
#define GL_CLAMP_TO_BORDER 0x812D
/* Fragment Control TXP */
#define GL_FRAGMENT_PROGRAM_CONTROL_CONTROLTXP_SCE 0x8453
/* Gets */
#define GL_MODELVIEW_MATRIX 0x0BA6
#define GL_TEXTURE_MATRIX 0x0BA8
#define GL_PROJECTION_MATRIX 0x0BA7
#define GL_MAX_TEXTURE_COORDS_ARB 0x8871
#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872
#define GL_RGBA8 0x8058
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
#define GL_STREAM_DRAW 0x88E0
#define GL_STREAM_READ 0x88E1
#define GL_STREAM_COPY 0x88E2
#define GL_STATIC_DRAW 0x88E4
#define GL_STATIC_READ 0x88E5
#define GL_STATIC_COPY 0x88E6
#define GL_DYNAMIC_DRAW 0x88E8
#define GL_DYNAMIC_READ 0x88E9
#define GL_DYNAMIC_COPY 0x88EA
#define GL_SYSTEM_DRAW_SCE 0x6020
#define GL_READ_ONLY 0x88B8
#define GL_WRITE_ONLY 0x88B9
#define GL_READ_WRITE 0x88BA
#define GL_VSYNC_SCE 0x6006
#define GL_SKIP_FIRST_VSYNC_SCE 0x6100
#define GL_TEXTURE_GAMMA_REMAP_R_SCE 0x6010
#define GL_TEXTURE_GAMMA_REMAP_G_SCE 0x6011
#define GL_TEXTURE_GAMMA_REMAP_B_SCE 0x6012
#define GL_TEXTURE_GAMMA_REMAP_A_SCE 0x6013
#define GL_SHADER_SRGB_REMAP_SCE 0x6014
#define GL_TEXTURE_FROM_VERTEX_PROGRAM_SCE 0x6017
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
#define GL_ALL_COMPLETED_NV 0x84F2
#define GL_FENCE_STATUS_NV 0x84F3
#define GL_FENCE_CONDITION_NV 0x84F4
#define GL_MAX_CLIP_PLANES 0x0D32
#define GL_CLIP_PLANE0 0x3000
#define GL_CLIP_PLANE1 0x3001
#define GL_CLIP_PLANE2 0x3002
#define GL_CLIP_PLANE3 0x3003
#define GL_CLIP_PLANE4 0x3004
#define GL_CLIP_PLANE5 0x3005
#define GL_POINT_SPRITE_OES 0x8861
#define GL_COORD_REPLACE_OES 0x8862
#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506
#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8
#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6
#define GL_RENDERBUFFER_BINDING_OES 0x8CA7
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7
#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_OES 0x8CD8
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9
#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA
#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD
#define GL_MAX_COLOR_ATTACHMENTS_OES 0x8CDF
#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
#define GL_DEPTH_ATTACHMENT_OES 0x8D00
#define GL_STENCIL_ATTACHMENT_OES 0x8D20
#define GL_FRAMEBUFFER_OES 0x8D40
#define GL_RENDERBUFFER_OES 0x8D41
#define GL_RENDERBUFFER_WIDTH_OES 0x8D42
#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43
#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44
#define GL_STENCIL_INDEX_OES 0x8D45
#define GL_STENCIL_INDEX4_OES 0x8D47
#define GL_STENCIL_INDEX8_OES 0x8D48
#define GL_BLEND_MRT0_SCE GL_COLOR_ATTACHMENT0_EXT
#define GL_BLEND_MRT1_SCE GL_COLOR_ATTACHMENT1_EXT
#define GL_BLEND_MRT2_SCE GL_COLOR_ATTACHMENT2_EXT
#define GL_BLEND_MRT3_SCE GL_COLOR_ATTACHMENT3_EXT
#define GL_TEXTURE_ALLOCATION_HINT_SCE 0x6018
#define GL_TEXTURE_LINEAR_GPU_SCE 0x601A
#define GL_INCR_WRAP 0x8507
#define GL_DECR_WRAP 0x8508
#define GL_DEPTH_CLAMP_NV 0x864F
#define GL_FIXED_11_11_10_SCE 0x6020
#define GL_REDUCE_DST_COLOR_SCE 0x6021
#define GL_MULTISAMPLING_NONE_SCE 0x6030
#define GL_TEXTURE_REFERENCE_BUFFER_SCE 0x6040
#define GL_BUFFER_SIZE 0x8764
#define GL_BUFFER_PITCH_SCE 0x6041
GLAPI void APIENTRY glBlendEquation( GLenum mode );
GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
GLAPI void APIENTRY glGetFloatv( GLenum pname, GLfloat* params );
GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param );
GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name );
GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers );
GLAPI void APIENTRY glGenBuffers( GLsizei n, GLuint *buffers );
GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage );
GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data );
GLAPI void APIENTRY glBindFramebufferOES( GLenum, GLuint );
GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei, const GLuint * );
GLAPI void APIENTRY glGenFramebuffersOES( GLsizei, GLuint * );
GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum );
GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum, GLenum, GLenum, GLuint, GLint );
GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,387 +0,0 @@
#ifndef _RGL_PRIVATE_H
#define _RGL_PRIVATE_H
#include "rgl.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern PSGLcontext *_CurrentContext;
extern PSGLdevice *_CurrentDevice;
#define GL_UNSIGNED_BYTE_4_4 0x4A00
#define GL_UNSIGNED_BYTE_4_4_REV 0x4A01
#define GL_UNSIGNED_BYTE_6_2 0x4A02
#define GL_UNSIGNED_BYTE_2_6_REV 0x4A03
#define GL_UNSIGNED_SHORT_12_4 0x4A04
#define GL_UNSIGNED_SHORT_4_12_REV 0x4A05
#define GL_UNSIGNED_BYTE_2_2_2_2 0x4A06
#define GL_UNSIGNED_BYTE_2_2_2_2_REV 0x4A07
#define GL_FLOAT_RGBA32 0x888B
#define RGL_SETRENDERTARGET_MAXCOUNT 4
#define NOP (0x00000000)
#define DEFAULT_FIFO_BLOCK_SIZE (0x10000)
#define RGL_F0_DOT_0 12582912.0f
#define RGL_CLAMPF_01(x) ((x) >= 0.0f ? ((x) > 1.0f ? 1.0f : (x)) : 0.0f)
#define ENDIAN_32(X, F) ((F) ? endianSwapWord(X) : (X))
#define VERTEX_PROFILE_INDEX 0
#define FRAGMENT_PROFILE_INDEX 1
typedef union
{
unsigned int i;
float f;
} jsIntAndFloat;
static const jsIntAndFloat _RGLNan = {i: 0x7fc00000U};
static const jsIntAndFloat _RGLInfinity = {i: 0x7f800000U};
typedef struct RGLRenderTargetEx RGLRenderTargetEx;
struct RGLRenderTargetEx
{
RGLEnum colorFormat;
GLuint colorBufferCount;
GLuint colorId[RGL_SETRENDERTARGET_MAXCOUNT];
GLuint colorIdOffset[RGL_SETRENDERTARGET_MAXCOUNT];
GLuint colorPitch[RGL_SETRENDERTARGET_MAXCOUNT];
GLboolean yInverted;
GLuint xOffset;
GLuint yOffset;
GLuint width;
GLuint height;
};
struct jsPlatformFramebuffer: public jsFramebuffer
{
RGLRenderTargetEx rt;
GLuint colorBufferMask;
GLboolean complete;
jsPlatformFramebuffer(): jsFramebuffer() { memset( &rt, 0, sizeof( rt ) ); };
virtual ~jsPlatformFramebuffer() {};
};
typedef struct _RGLDriver_
{
RGLRenderTargetEx rt;
GLuint colorBufferMask;
GLboolean rtValid;
GLboolean invalidateVertexCache;
GLuint flushBufferCount;
GLuint fpLoadProgramId;
GLuint fpLoadProgramOffset;
}
RGLDriver;
typedef struct
{
GLuint SET_TEXTURE_CONTROL3;
GLuint SET_TEXTURE_OFFSET;
GLuint SET_TEXTURE_FORMAT;
GLuint SET_TEXTURE_ADDRESS;
GLuint SET_TEXTURE_CONTROL0;
GLuint SET_TEXTURE_CONTROL1;
GLuint SET_TEXTURE_FILTER;
GLuint SET_TEXTURE_IMAGE_RECT;
} RGLTextureMethods;
struct RGLTextureAddress
{
GLuint gamma;
};
struct RGLTextureFilter
{
GLuint min;
GLuint mag;
GLint bias;
};
struct RGLTextureMethodParams
{
RGLTextureAddress address;
RGLTextureFilter filter;
};
typedef struct
{
GLuint baseWidth;
GLuint baseHeight;
RGLEnum internalFormat;
GLuint pixelBits;
GLuint pitch;
} RGLTextureLayout;
typedef struct
{
GLenum pool;
RGLTextureMethodParams gcmMethods;
CellGcmTexture gcmTexture;
GLuint gpuAddressId;
GLuint gpuAddressIdOffset;
GLuint gpuSize;
RGLTextureLayout gpuLayout;
jsBufferObject* pbo;
} RGLTexture;
typedef struct _tagMODESTRUC
{
GLushort wHorizVisible;
GLushort wVertVisible;
GLushort wInterlacedMode;
GLushort wRefresh;
GLushort wHorizTotal;
GLushort wHorizBlankStart;
GLushort wHorizSyncStart;
GLushort wHorizSyncEnd;
GLushort wHorizBlankEnd;
GLushort wVertTotal;
GLushort wVertBlankStart;
GLushort wVertSyncStart;
GLushort wVertSyncEnd;
GLushort wVertBlankEnd;
GLuint dwDotClock;
GLushort wHSyncPolarity;
GLushort wVSyncPolarity;
}
MODESTRUC;
enum
{
SURFACE_SOURCE_TEMPORARY,
SURFACE_SOURCE_DEVICE,
SURFACE_SOURCE_TEXTURE,
SURFACE_SOURCE_PBO,
};
enum
{
SURFACE_POOL_NONE,
SURFACE_POOL_LINEAR,
SURFACE_POOL_SYSTEM,
};
typedef struct
{
GLenum source;
GLuint width, height;
GLuint bpp;
GLuint pitch;
RGLEnum format;
GLenum pool;
char* ppuData;
GLuint dataId;
GLuint dataIdOffset;
} RGLSurface;
typedef struct
{
RGLRenderTargetEx rt;
RGLSurface color[3];
GLuint drawBuffer;
GLuint scanBuffer;
GLuint RescColorBuffersId;
GLuint RescVertexArrayId;
GLuint RescFragmentShaderId;
const MODESTRUC *ms;
GLboolean vsync;
GLenum deviceType;
GLenum TVStandard;
GLenum TVFormat;
GLuint swapFifoRef;
GLuint swapFifoRef2;
GLboolean setOffset;
GLboolean signal;
GLuint semaValue;
unsigned int syncMethod;
} RGLDevice;
int32_t _RGLOutOfSpaceCallback( struct CellGcmContextData *con, uint32_t space );
typedef struct _RGLShader_
{
GLuint loadAddressId;
CgBinaryProgram __attribute__(( aligned( 16 ) ) ) program;
} RGLShader;
void _RGLFifoFinish( RGLFifo *fifo );
#define _RGLFifoFlush(fifo) \
{ \
uint32_t offsetInBytes = 0; \
cellGcmAddressToOffset( fifo->current, &offsetInBytes ); \
cellGcmFlush( &_RGLState.fifo); \
fifo->dmaControl->Put = offsetInBytes; \
fifo->lastPutWritten = fifo->current; \
fifo->lastSWReferenceFlushed = fifo->lastSWReferenceWritten; \
}
#define LM_MAX_TOTAL_QUERIES 800
typedef struct RGLTextureState RGLTextureState;
struct RGLTextureState
{
GLuint hwTexAddress;
GLuint hwTexFilter;
GLuint hwTexControl0;
};
void _RGLDestroy( void );
typedef void( * RGLcontextHookFunction )( PSGLcontext *context );
extern RGLcontextHookFunction _RGLContextCreateHook;
extern RGLcontextHookFunction _RGLContextDestroyHook;
extern PSGLcontext* _RGLContextCreate (void);
extern void _RGLContextFree( PSGLcontext* LContext );
extern void _RGLSetError( GLenum error );
void _RGLAttachContext( PSGLdevice *device, PSGLcontext* context );
extern jsTexture *_RGLGetCurrentTexture( const jsTextureImageUnit *unit, GLenum target );
void _RGLVertexAttribPointerNV( GLuint index, GLint fsize, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer );
void _RGLEnableVertexAttribArrayNV( GLuint index );
void _RGLDisableVertexAttribArrayNV( GLuint index );
void _RGLFifoGlSetRenderTarget( RGLRenderTargetEx const * const args );
extern void _RGLDeviceInit( PSGLinitOptions* options );
extern void _RGLDeviceExit (void);
static inline GLuint RGL_QUICK_FLOAT2UINT( const GLfloat f )
{
union
{
GLfloat f;
GLuint ui;
} t;
t.f = f + RGL_F0_DOT_0;
return t.ui & 0xffff;
}
static inline void RGL_CALC_COLOR_LE_ARGB8( GLuint *color0, const GLfloat r,
const GLfloat g, const GLfloat b, const GLfloat a )
{
GLuint r2 = RGL_QUICK_FLOAT2UINT( r * 255.0f );
GLuint g2 = RGL_QUICK_FLOAT2UINT( g * 255.0f );
GLuint b2 = RGL_QUICK_FLOAT2UINT( b * 255.0f );
GLuint a2 = RGL_QUICK_FLOAT2UINT( a * 255.0f );
*color0 = ( a2 << 24 ) | ( r2 << 16 ) | ( g2 << 8 ) | ( b2 << 0 );
}
static inline GLuint _RGLMapMinTextureFilter( GLenum filter )
{
switch ( filter )
{
case GL_NEAREST:
return CELL_GCM_TEXTURE_NEAREST;
case GL_LINEAR:
return CELL_GCM_TEXTURE_LINEAR;
case GL_NEAREST_MIPMAP_NEAREST:
return CELL_GCM_TEXTURE_NEAREST_NEAREST;
case GL_NEAREST_MIPMAP_LINEAR:
return CELL_GCM_TEXTURE_NEAREST_LINEAR;
case GL_LINEAR_MIPMAP_NEAREST:
return CELL_GCM_TEXTURE_LINEAR_NEAREST;
case GL_LINEAR_MIPMAP_LINEAR:
return CELL_GCM_TEXTURE_LINEAR_LINEAR;
}
return filter;
}
static inline GLuint _RGLMapMagTextureFilter( GLenum filter )
{
switch ( filter )
{
case GL_NEAREST:
return CELL_GCM_TEXTURE_NEAREST;
case GL_LINEAR:
return CELL_GCM_TEXTURE_LINEAR;
}
return filter;
}
static inline void _RGLMapTextureFormat( GLuint internalFormat, uint8_t & gcmFormat, uint32_t & remap )
{
gcmFormat = 0;
switch ( internalFormat )
{
case RGL_ALPHA8: // in_rgba = xxAx, out_rgba = 000A
gcmFormat = CELL_GCM_TEXTURE_B8;
remap = CELL_GCM_REMAP_MODE(
CELL_GCM_TEXTURE_REMAP_ORDER_XYXY,
CELL_GCM_TEXTURE_REMAP_FROM_B,
CELL_GCM_TEXTURE_REMAP_FROM_R,
CELL_GCM_TEXTURE_REMAP_FROM_B,
CELL_GCM_TEXTURE_REMAP_FROM_B,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_ZERO,
CELL_GCM_TEXTURE_REMAP_ZERO,
CELL_GCM_TEXTURE_REMAP_ZERO );
break;
case RGL_ARGB8: // in_rgba = RGBA, out_rgba = RGBA
gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8;
remap = CELL_GCM_REMAP_MODE(
CELL_GCM_TEXTURE_REMAP_ORDER_XYXY,
CELL_GCM_TEXTURE_REMAP_FROM_A,
CELL_GCM_TEXTURE_REMAP_FROM_R,
CELL_GCM_TEXTURE_REMAP_FROM_G,
CELL_GCM_TEXTURE_REMAP_FROM_B,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP );
break;
case RGL_RGB5_A1_SCE: // in_rgba = RGBA, out_rgba = RGBA
gcmFormat = CELL_GCM_TEXTURE_A1R5G5B5;
remap = CELL_GCM_REMAP_MODE(
CELL_GCM_TEXTURE_REMAP_ORDER_XXXY,
CELL_GCM_TEXTURE_REMAP_FROM_A,
CELL_GCM_TEXTURE_REMAP_FROM_R,
CELL_GCM_TEXTURE_REMAP_FROM_G,
CELL_GCM_TEXTURE_REMAP_FROM_B,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP );
break;
case RGL_RGB565_SCE: // in_rgba = RGBA, out_rgba = RGBA
gcmFormat = CELL_GCM_TEXTURE_R5G6B5;
remap = CELL_GCM_REMAP_MODE(
CELL_GCM_TEXTURE_REMAP_ORDER_XXXY,
CELL_GCM_TEXTURE_REMAP_FROM_A,
CELL_GCM_TEXTURE_REMAP_FROM_R,
CELL_GCM_TEXTURE_REMAP_FROM_G,
CELL_GCM_TEXTURE_REMAP_FROM_B,
CELL_GCM_TEXTURE_REMAP_ONE,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP,
CELL_GCM_TEXTURE_REMAP_REMAP );
break;
};
return;
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,66 +0,0 @@
#ifndef READELF_H
#define READELF_H
#include "elf.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _ELF_section_t
{
Elf32_Shdr header;
const char *name;
char *data;
} ELF_section_t;
typedef struct _ELF_segment_t
{
Elf32_Phdr header;
unsigned char *pointer;
unsigned char *data;
} ELF_segment_t;
typedef struct
{
const char *name;
unsigned int vma;
unsigned int size;
int section;
unsigned char resolved;
unsigned char foreign;
} ELF_symbol_t;
typedef struct _ELF_t
{
unsigned int endian;
unsigned int relocatable;
unsigned int sectionCount;
unsigned int segmentCount;
unsigned int symbolCount;
unsigned int entrypoint;
ELF_section_t *sections;
ELF_segment_t *segments;
ELF_symbol_t *symbols;
unsigned int symbolsSection;
unsigned int symbolNamesSection;
unsigned int paramSection;
} ELF_t;
typedef struct
{
unsigned int relative;
unsigned int shift;
unsigned int size;
unsigned int position;
unsigned int mask;
} ELF_rel_type_t;
ELF_section_t *findSection(const ELF_t *elf, const char *name);
int lookupSymbol(const ELF_t *elf, const char *name);
#ifdef __cplusplus
}
#endif
#endif // READELF_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,23 @@
#include "../../include/export/RGL/rgl.h"
#include "../../include/RGL/private.h"
#include <string.h>
const char *rglMapLookupEnum( const RGLenumMap* map, unsigned int count, GLenum e )
{
for (GLuint i = 0; i < count; ++i)
if (map[i].e == e)
return map[i].s;
return NULL;
}
GLenum rglMapLookupString( const RGLenumMap* map, unsigned int count, const char *s )
{
if (s != NULL)
for (GLuint i = 0;i < count;++i)
if ( strcmp( map[i].s, s) == 0)
return map[i].e;
return -1U;
}

View File

@ -0,0 +1,106 @@
#include <RGL/Types.h>
#include <RGL/Utils.h>
#include <RGL/private.h>
#include <Cg/CgCommon.h>
#include <string.h>
void rglInitNameSpace( rglNameSpace * name )
{
name->data = NULL;
name->firstFree = NULL;
name->capacity = 0;
}
void rglFreeNameSpace( rglNameSpace * ns )
{
// XXX should we verify all names were freed ?
if ( ns->data ) { free( ns->data ); };
ns->data = NULL;
ns->capacity = 0;
ns->firstFree = NULL;
}
static const int NAME_INCREMENT = 4;
unsigned int rglCreateName( rglNameSpace * ns, void* object )
{
// NULL is reserved for the guard of the linked list.
if (ns->firstFree == NULL)
{
// need to allocate more pointer space
int newCapacity = ns->capacity + NAME_INCREMENT;
// realloc the block of pointers
void** newData = ( void** )malloc( newCapacity * sizeof( void* ) );
if ( newData == NULL )
{
// XXX what should we generally do here ?
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return 0;
}
memcpy( newData, ns->data, ns->capacity * sizeof( void* ) );
if ( ns->data != NULL ) free( ns->data );
ns->data = newData;
// initialize the pointers to the next free elements.
// (effectively build a linked list of free elements in place)
// treat the last item differently, by linking it to NULL
for ( int index = ns->capacity; index < newCapacity - 1; ++index )
ns->data[index] = ns->data + index + 1;
ns->data[newCapacity - 1] = NULL;
// update the first free element to the new data pointer.
ns->firstFree = ns->data + ns->capacity;
// update the new capacity.
ns->capacity = newCapacity;
}
// firstFree is a pointer, compute the index of it
unsigned int result = ns->firstFree - ns->data;
// update the first free to the next free element.
ns->firstFree = ( void** ) * ns->firstFree;
// store the object in data.
ns->data[result] = object;
// offset the index by 1 to avoid the name 0
return result + 1;
}
unsigned int rglIsName( rglNameSpace* ns, unsigned int name )
{
// there should always be a namesepace
// 0 is never valid.
if (RGL_UNLIKELY(name == 0))
return 0;
// names start numbering from 1, so convert from a name to an index
--name;
// test whether it is in the namespace range
if ( RGL_UNLIKELY( name >= ns->capacity ) )
return 0;
// test whether the pointer is inside the data block.
// if so, it means it is free.
// if it points to NULL, it means it is the last free name in the linked list.
void** value = ( void** )ns->data[name];
if ( RGL_UNLIKELY(value == NULL ||
( value >= ns->data && value < ns->data + ns->capacity ) ) )
return 0;
// The pointer is not free and allocated, so name is a real name.
return 1;
}
void rglEraseName( rglNameSpace* ns, unsigned int name )
{
if (rglIsName(ns, name))
{
--name;
ns->data[name] = ns->firstFree;
ns->firstFree = ns->data + name;
}
}

View File

@ -0,0 +1,103 @@
#include <string.h>
#include "../../include/export/RGL/rgl.h"
#include "../../include/RGL/Types.h"
#include "../../include/RGL/Utils.h"
#include "../../include/RGL/private.h"
static const unsigned int capacityIncr = 16;
// Initialize texture namespace ns with creation and destruction functions
void rglTexNameSpaceInit( rglTexNameSpace *ns, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy )
{
ns->capacity = capacityIncr;
ns->data = (void **)malloc( ns->capacity * sizeof( void* ) );
memset( ns->data, 0, ns->capacity*sizeof( void* ) );
ns->create = create;
ns->destroy = destroy;
}
// Free texture namespace ns
void rglTexNameSpaceFree( rglTexNameSpace *ns )
{
for ( GLuint i = 1;i < ns->capacity;++i )
if ( ns->data[i] ) ns->destroy( ns->data[i] );
free( ns->data );
ns->data = NULL;
}
// Reset all names in namespace ns to NULL
void rglTexNameSpaceResetNames( rglTexNameSpace *ns )
{
for ( GLuint i = 1;i < ns->capacity;++i )
{
if ( ns->data[i] )
{
ns->destroy( ns->data[i] );
ns->data[i] = NULL;
}
}
}
// Get an index of the first free name in namespace ns
GLuint rglTexNameSpaceGetFree( rglTexNameSpace *ns )
{
GLuint i;
for (i = 1;i < ns->capacity;++i)
if (!ns->data[i])
break;
return i;
}
// Add name to namespace by increasing capacity and calling creation call back function
// Return GL_TRUE for success, GL_FALSE for failure
GLboolean rglTexNameSpaceCreateNameLazy( rglTexNameSpace *ns, GLuint name )
{
if (name >= ns->capacity)
{
int newCapacity = name >= ns->capacity + capacityIncr ? name + 1 : ns->capacity + capacityIncr;
void **newData = ( void ** )realloc( ns->data, newCapacity * sizeof( void * ) );
memset( newData + ns->capacity, 0, ( newCapacity - ns->capacity )*sizeof( void * ) );
ns->data = newData;
ns->capacity = newCapacity;
}
if ( !ns->data[name] )
{
ns->data[name] = ns->create();
if ( ns->data[name] ) return GL_TRUE;
}
return GL_FALSE;
}
// Check if name is a valid name in namespace ns
// Return GL_TRUE if so, GL_FALSE otherwise
GLboolean rglTexNameSpaceIsName( rglTexNameSpace *ns, GLuint name )
{
if (( name > 0 ) && ( name < ns->capacity ) ) return( ns->data[name] != 0 );
else return GL_FALSE;
}
// Generate new n names in namespace ns
void rglTexNameSpaceGenNames( rglTexNameSpace *ns, GLsizei n, GLuint *names )
{
for ( int i = 0;i < n;++i )
{
GLuint name = rglTexNameSpaceGetFree( ns );
names[i] = name;
if (name)
rglTexNameSpaceCreateNameLazy( ns, name );
}
}
// Delete n names from namespace ns
void rglTexNameSpaceDeleteNames( rglTexNameSpace *ns, GLsizei n, const GLuint *names )
{
for ( int i = 0;i < n;++i )
{
GLuint name = names[i];
if (!rglTexNameSpaceIsName(ns, name))
continue;
ns->destroy( ns->data[name] );
ns->data[name] = NULL;
}
}

View File

@ -0,0 +1,275 @@
#ifndef _CGC_CGBIO_CGBDEFS_HPP
#define _CGC_CGBIO_CGBDEFS_HPP
// Platform depended definitions:
typedef unsigned int Elf32_Addr;
typedef unsigned short Elf32_Half;
typedef short Elf32_Shalf;
typedef unsigned int Elf32_Off;
typedef signed int Elf32_Sword;
typedef unsigned int Elf32_Word;
typedef unsigned short Elf64_Half;
typedef short Elf64_Shalf;
#ifdef __CELLOS_LV2__
typedef size_t ptrdiff_t;
typedef size_t ptrdiff_t;
#endif
///////////////////////
// ELF Header Constants
// File type
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_LOOS 0xFE00
#define ET_HIOS 0xFEFF
#define ET_LOPROC 0xFF00
#define ET_HIPROC 0xFFFF
// Machine/Architecture
#define EM_NONE 0 // No machine
#define EM_RSX 0x528e // RSX
// Machine/Architecture flags
#define EM_RSX_NONE 0
// Machine/Architecture ABI version
#define EI_ABIVERSION_RSX 1
// ELF File version
#define EV_NONE 0
#define EV_CURRENT 1
// Identification index
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_ABIVERSION 8
#define EI_PAD 9
#define EI_NIDENT 16
// Magic number
#ifndef ELFMAG0
#define ELFMAG0 0x7F
#endif
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
// File class
#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2
// Encoding
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
// OS extensions
#define ELFOSABI_NONE 0 // No extensions or unspecified
#define ELFOSABI_HPUX 1 // Hewlett-Packard HP-UX
#define ELFOSABI_NETBSD 2 // NetBSD
#define ELFOSABI_LINUX 3 // Linux
#define ELFOSABI_SOLARIS 6 // Sun Solaris
#define ELFOSABI_AIX 7 // AIX
#define ELFOSABI_IRIX 8 // IRIX
#define ELFOSABI_FREEBSD 9 // FreeBSD
#define ELFOSABI_TRU64 10 // Compaq TRU64 UNIX
#define ELFOSABI_MODESTO 11 // Novell Modesto
#define ELFOSABI_OPENBSD 12 // Open BSD
#define ELFOSABI_CGRUNTIME 19 // Cg Run-Time
/////////////////////
// Sections constants
// Section indexes
#ifndef SHN_UNDEF
#define SHN_UNDEF 0
#endif
#ifndef SHN_LORESERVE
#define SHN_LORESERVE 0xFF00
#endif
#ifndef SHN_LOPROC
#define SHN_LOPROC 0xFF00
#endif
#ifndef SHN_HIPROC
#define SHN_HIPROC 0xFF1F
#endif
#ifndef SHN_LOOS
#define SHN_LOOS 0xFF20
#endif
#ifndef SHN_HIOS
#define SHN_HIOS 0xFF3F
#endif
#ifndef SHN_ABS
#define SHN_ABS 0xFFF1
#endif
#ifndef SHN_COMMON
#define SHN_COMMON 0xFFF2
#endif
#ifndef SHN_XINDEX
#define SHN_XINDEX 0xFFFF
#endif
#ifndef SHN_HIRESERVE
#define SHN_HIRESERVE 0xFFFF
#endif
// Section types
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHT_INIT_ARRAY 14
#define SHT_FINI_ARRAY 15
#define SHT_PREINIT_ARRAY 16
#define SHT_GROUP 17
#define SHT_SYMTAB_SHNDX 18
#define SHT_LOOS 0x60000000
#define SHT_HIOS 0x6fffffff
#define SHT_LOPROC 0x70000000
#define SHT_RSX_PARAM 0x70000000
#define SHT_RSX_SHADERTAB 0x70000001
#define SHT_RSX_FXTAB 0x70000002
#define SHT_RSX_ANNOTATE 0x70000003
#define SHT_HIPROC 0x7FFFFFFF
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xFFFFFFFF
// Section flags
#ifndef SHF_WRITE
#define SHF_WRITE 0x1
#endif
#ifndef SHF_ALLOC
#define SHF_ALLOC 0x2
#endif
#ifndef SHF_EXECINSTR
#define SHF_EXECINSTR 0x4
#endif
#ifndef SHF_MERGE
#define SHF_MERGE 0x10
#endif
#ifndef SHF_STRINGS
#define SHF_STRINGS 0x20
#endif
#ifndef SHF_INFO_LINK
#define SHF_INFO_LINK 0x40
#endif
#ifndef SHF_LINK_ORDER
#define SHF_LINK_ORDER 0x80
#endif
#ifndef SHF_OS_NONCONFORMING
#define SHF_OS_NONCONFORMING 0x100
#endif
#define SHF_GROUP 0x200
#define SHF_TLS 0x400
#define SHF_MASKOS 0x0ff00000
#ifndef SHF_MASKPROC
#define SHF_MASKPROC 0xF0000000
#endif
// Section group flags
#define GRP_COMDAT 0x1
#define GRP_MASKOS 0x0ff00000
#define GRP_MASKPROC 0xf0000000
// Symbol binding
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_LOOS 10
#define STB_HIOS 12
#define STB_LOPROC 13
#define STB_HIPROC 15
// Symbol types
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_COMMON 5
#define STT_TLS 6
#define STT_LOOS 10
#define STT_HIOS 12
#define STT_LOPROC 13
#define STT_HIPROC 15
// Symbol visibility
#define STV_DEFAULT 0
#define STV_INTERNAL 1
#define STV_HIDDEN 2
#define STV_PROTECTED 3
// Shader Function type (st_other field)
#define STO_RSX_SHADER 0
#define STO_RSX_EFFECT 1
// Undefined name
#define STN_UNDEF 0
// Relocation types
#define R_RSX_NONE 0
#define R_RSX_FLOAT4 1
/* Note header in a PT_NOTE section */
struct Elf32_Note {
Elf32_Word n_namesz; /* Name size */
Elf32_Word n_descsz; /* Content size */
Elf32_Word n_type; /* Content type */
};
// Relocation entries
// Dynamic structure
struct Elf32_Dyn {
Elf32_Sword d_tag;
union {
Elf32_Word d_val;
Elf32_Addr d_ptr;
} d_un;
};
#endif // CGC_CGBIO_CGBDEFS_HPP

View File

@ -0,0 +1,53 @@
#ifndef _CGC_CGBIO_CGBI_HPP
#define _CGC_CGBIO_CGBI_HPP
#include <iostream>
#include <string>
#include <cstddef>
#include "cgbdefs.hpp"
using std::istream;
namespace cgc {
namespace bio {
class elf_reader {
public:
virtual ptrdiff_t reference() const = 0;
virtual ptrdiff_t release() const = 0;
virtual CGBIO_ERROR load( const char * filename ) = 0;
virtual CGBIO_ERROR load( istream* stream, int start ) = 0;
virtual bool is_initialized() const = 0;
virtual ~elf_reader() {}
}; // elf_reader
class isection
{
public:
virtual ~isection() = 0;
virtual int reference() const = 0;
virtual int release() const = 0;
// Section info functions
virtual Elf32_Half index() const = 0;
virtual char *name() const = 0;
virtual Elf32_Word type() const = 0;
virtual Elf32_Word flags() const = 0;
virtual Elf32_Addr addr() const = 0;
virtual Elf32_Word size() const = 0;
virtual Elf32_Word link() const = 0;
virtual Elf32_Word info() const = 0;
virtual Elf32_Word addralign() const = 0;
virtual Elf32_Word entsize() const = 0;
virtual const char* data() const = 0;
};
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_CGBI_HPP

View File

@ -0,0 +1,40 @@
#if !defined(CGC_CGBIO_CGBIIMPL_HPP)
#define CGC_CGBIO_CGBIIMPL_HPP 1
#include <iostream>
#include <string>
#include <vector>
#include <cstddef>
#include "cgbio.hpp"
using std::istream;
namespace cgc {
namespace bio {
class elf_reader_impl : public elf_reader
{
public:
elf_reader_impl();
virtual ~elf_reader_impl();
virtual CGBIO_ERROR load( const char* filename );
virtual CGBIO_ERROR load( istream* stream, int start );
virtual bool is_initialized() const;
virtual ptrdiff_t reference() const;
virtual ptrdiff_t release() const;
// virtual int get_revision() const;
private:
mutable ptrdiff_t ref_count_;
istream* stream_;
bool initialized_;
Elf32_Ehdr header_;
std::vector<const isection*> sections_;
}; // CGBIImpl
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_CGBIIMPL_HPP

View File

@ -0,0 +1,9 @@
LIBRARY cgbu
EXPORTS
;?CreateCGBI@CGBIO@@QBE?AW4CGBIO_Err@@PAPAVCGBI@@@Z
;?instance@CGBIO@@SAPBV1@XZ
;?get_revision@CGBIImpl@@UBEHXZ
get_revision
instance
CreateCGBI

View File

@ -0,0 +1,66 @@
/* cgbio.hpp -- interface to the whole cg binary input/output library.
*
* This is the only header file, that an application need to include
* in order to manipulate both elf and nvidia original cg binary
* format.
*/
#if !defined(CGC_CGBIO_CGBIO_HPP)
#define CGC_CGBIO_CGBIO_HPP 1
#include "cgbdefs.hpp"
#include <string>
namespace cgc {
namespace bio {
enum CGBIO_ERROR {
CGBIO_ERROR_NO_ERROR,
CGBIO_ERROR_LOADED,
CGBIO_ERROR_FILEIO,
CGBIO_ERROR_FORMAT,
CGBIO_ERROR_INDEX,
CGBIO_ERROR_MEMORY,
CGBIO_ERROR_RELOC,
CGBIO_ERROR_SYMBOL,
CGBIO_ERROR_UNKNOWN_TYPE
};
} // bio namespace
} // cgc namespace
#include "cgbi.hpp"
#include "cgbo.hpp"
#include "nvbi.hpp"
#include "nvbo.hpp"
namespace cgc {
namespace bio {
class bin_io
{
public:
static const bin_io* instance();
static void delete_instance();
CGBIO_ERROR new_elf_reader( elf_reader** obj ) const;
CGBIO_ERROR new_elf_writer( elf_writer** obj ) const;
CGBIO_ERROR new_nvb_reader( nvb_reader** obj ) const;
CGBIO_ERROR new_nvb_writer( nvb_writer** obj ) const;
const char *error_string( CGBIO_ERROR error ) const;
private:
bin_io();
bin_io( const bin_io& );
static bin_io* instance_;
}; // bin_io
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_CGBIO_HPP

334
console/rgl/src/cg/cgbo.hpp Normal file
View File

@ -0,0 +1,334 @@
#if !defined(CGC_CGBIO_CGBO_HPP)
#define CGC_CGBIO_CGBO_HPP 1
#include <cstddef>
#include <fstream>
#include <string>
#include "cgbdefs.hpp"
#include "cgbtypes.h"
using std::ofstream;
using std::streampos;
namespace cgc {
namespace bio {
class osection;
class elf_writer {
public:
enum PRODUCER
{
CGBO_HASH,
CGBO_STR,
CGBO_SYM,
CGBO_REL,
CGBO_PARAM,
CGBO_CONST,
CGBO_VP,
CGBO_FP
};
virtual ~elf_writer() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual CGBIO_ERROR
save( ofstream& ofs ) = 0;
virtual CGBIO_ERROR
save( const char* filename ) = 0;
virtual CGBIO_ERROR
set_attr( unsigned char file_class,
unsigned char endianness,
unsigned char ELFversion,
unsigned char abi,
unsigned char ABIversion,
Elf32_Half type,
Elf32_Half machine,
Elf32_Word version,
Elf32_Word flags ) = 0;
virtual Elf32_Addr
get_entry() const = 0;
virtual CGBIO_ERROR
set_entry( Elf32_Addr entry ) = 0;
virtual unsigned char
endianness() const = 0;
virtual Elf32_Half
num_of_sections() const = 0;
virtual osection*
get_section( Elf32_Half index ) const = 0;
virtual osection*
get_section( const char* name ) const = 0;
virtual osection*
add_section( const char *name,
Elf32_Word type,
Elf32_Word flags,
Elf32_Word info,
Elf32_Word align,
Elf32_Word esize ) = 0;
virtual streampos
section_offset( Elf32_Half index ) const = 0;
virtual CGBIO_ERROR
new_section_out( PRODUCER producer,
osection* sec,
void** obj ) const = 0;
}; // elf_writer interface class
class osection
{
public:
virtual ~osection() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual CGBIO_ERROR
save( ofstream& of,
streampos header,
streampos data) = 0;
virtual Elf32_Half
index() const = 0;
virtual const char*
name() const = 0;
virtual Elf32_Word
type() const = 0;
virtual Elf32_Word
flags() const = 0;
virtual Elf32_Word
info() const = 0;
virtual Elf32_Word
addralign() const = 0;
virtual Elf32_Word
entsize() const = 0;
virtual Elf32_Word
size() const = 0;
virtual Elf32_Word
get_name_index() const = 0;
virtual void
set_name_index( Elf32_Word index ) = 0;
virtual Elf32_Addr
get_address() const = 0;
virtual void
set_address( Elf32_Addr addr ) = 0;
virtual Elf32_Word
get_link() const = 0;
virtual void
set_link( Elf32_Word link ) = 0;
virtual char*
get_data() const = 0;
virtual CGBIO_ERROR
set_data( const char* data, Elf32_Word size ) = 0;
virtual CGBIO_ERROR
add_data( const char* data, Elf32_Word size ) = 0;
}; // osection interface class
class ostring_table
{
public:
virtual ~ostring_table() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual const char*
get( Elf32_Word index ) const = 0;
//search the string table for a given string
virtual Elf32_Word
find( const char *) const = 0;
//add the string to the table if it's not already there, return the index of the string
virtual Elf32_Word
addUnique( const char* str ) = 0;
virtual Elf32_Word
add( const char* str ) = 0;
}; // ostring_table
class oconst_table
{
public:
virtual ~oconst_table() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual const Elf32_Word*
get( Elf32_Word index ) const = 0;
virtual Elf32_Word
add( const Elf32_Word *data, Elf32_Word size ) = 0;
};
class osymbol_table
{
public:
virtual ~osymbol_table() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual Elf32_Word
add_entry( Elf32_Word name,
Elf32_Addr value,
Elf32_Word size,
unsigned char info,
unsigned char other,
Elf32_Half shndx ) = 0;
virtual Elf32_Word
add_entry( Elf32_Word name,
Elf32_Addr value,
Elf32_Word size,
unsigned char bind,
unsigned char type,
unsigned char other,
Elf32_Half shndx ) = 0;
virtual Elf32_Word
add_entry( ostring_table* strtab,
const char* str,
Elf32_Addr value,
Elf32_Word size,
unsigned char info,
unsigned char other,
Elf32_Half shndx ) = 0;
virtual Elf32_Word
add_entry( ostring_table* strtab,
const char* str,
Elf32_Addr value,
Elf32_Word size,
unsigned char bind,
unsigned char type,
unsigned char other,
Elf32_Half shndx ) = 0;
}; // osymbol_table
class orelocation_table
{
public:
virtual ~orelocation_table() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word info ) = 0;
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word symbol,
unsigned char type ) = 0;
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word info,
Elf32_Sword addend ) = 0;
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word symbol,
unsigned char type,
Elf32_Sword addend ) = 0;
virtual CGBIO_ERROR
add_entry( ostring_table* strtab,
const char* str,
osymbol_table* symtab,
Elf32_Addr value,
Elf32_Word size,
unsigned char symInfo,
unsigned char other,
Elf32_Half shndx,
Elf32_Addr offset,
unsigned char type ) = 0;
virtual CGBIO_ERROR
add_entry( ostring_table* strtab,
const char* str,
osymbol_table* symtab,
Elf32_Addr value,
Elf32_Word size,
unsigned char symInfo,
unsigned char other,
Elf32_Half shndx,
Elf32_Addr offset,
unsigned char type,
Elf32_Sword addend ) = 0;
}; // orelocation_table
class oparam_table
{
public:
virtual ~oparam_table() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual CGBIO_ERROR
add_entry( Elf32_cgParameter& cgparam ) = 0;
}; // oparam_table
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_CGBO_HPP

View File

@ -0,0 +1,378 @@
#if !defined(CGC_CGBIO_CGBOIMPL_HPP)
#define CGC_CGBIO_CGBOIMPL_HPP 1
#include <cstddef>
#include <iostream>
#include <string>
#include <vector>
#include "cgbio.hpp"
namespace cgc {
namespace bio {
class osection_impl;
class elf_writer_impl : public elf_writer
{
public:
elf_writer_impl();
virtual
~elf_writer_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual CGBIO_ERROR
save( ofstream& ofs );
virtual CGBIO_ERROR
save( const char* filename );
virtual CGBIO_ERROR
set_attr( unsigned char file_class,
unsigned char endianness,
unsigned char ELFversion,
unsigned char abi,
unsigned char ABIversion,
Elf32_Half type,
Elf32_Half machine,
Elf32_Word version,
Elf32_Word flags );
virtual Elf32_Addr
get_entry() const;
virtual CGBIO_ERROR
set_entry( Elf32_Addr entry );
virtual unsigned char
endianness() const;
virtual Elf32_Half
num_of_sections() const;
virtual osection*
get_section( Elf32_Half index ) const;
virtual osection*
get_section( const char * name ) const;
virtual osection*
add_section( const char * name,
Elf32_Word type,
Elf32_Word flags,
Elf32_Word info,
Elf32_Word align,
Elf32_Word esize );
virtual streampos
section_offset( Elf32_Half index ) const;
virtual CGBIO_ERROR
new_section_out( PRODUCER, osection*, void** ) const;
private:
ptrdiff_t ref_count_;
Elf32_Ehdr header_;
std::vector<osection_impl*> sections_;
}; // elf_writer_impl
class osection_impl : public osection
{
public:
osection_impl( Elf32_Half index,
elf_writer* cgbo,
const char * name,
Elf32_Word type,
Elf32_Word flags,
Elf32_Word info,
Elf32_Word addrAlign,
Elf32_Word entrySize );
virtual
~osection_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual CGBIO_ERROR
save( ofstream& of,
streampos header,
streampos data);
virtual Elf32_Half
index() const;
virtual const char *
name() const;
virtual Elf32_Word
type() const;
virtual Elf32_Word
flags() const;
virtual Elf32_Word
info() const;
virtual Elf32_Word
addralign() const;
virtual Elf32_Word
entsize() const;
virtual Elf32_Word
size() const;
virtual Elf32_Word
get_name_index() const;
virtual void
set_name_index( Elf32_Word index );
virtual Elf32_Addr
get_address() const;
virtual void
set_address( Elf32_Addr addr );
virtual Elf32_Word
get_link() const;
virtual void
set_link( Elf32_Word link );
virtual char*
get_data() const;
virtual CGBIO_ERROR
set_data( const char* data, Elf32_Word size );
virtual CGBIO_ERROR
add_data( const char* data, Elf32_Word size );
private:
Elf32_Half index_;
elf_writer* cgbo_;
Elf32_Shdr sh_;
char name_[512];
char* data_;
};
class ostring_table_impl : public ostring_table
{
public:
ostring_table_impl( elf_writer* cgbo, osection* section );
virtual
~ostring_table_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual const char*
get( Elf32_Word index ) const;
//search the string table for a given string
virtual Elf32_Word
find( const char *) const;
//add the string to the table if it's not already there, return the index of the string
virtual Elf32_Word
addUnique( const char* str );
virtual Elf32_Word
add( const char* str );
private:
ptrdiff_t ref_count_;
elf_writer* cgbo_;
osection* section_;
std::vector<char> data_;
};
class oconst_table_impl : public oconst_table
{
public:
oconst_table_impl( elf_writer* cgbo, osection* section );
virtual
~oconst_table_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual const Elf32_Word*
get( Elf32_Word index ) const;
virtual Elf32_Word
add( const Elf32_Word *data, Elf32_Word count );
private:
ptrdiff_t ref_count_;
elf_writer* cgbo_;
osection* section_;
std::vector <Elf32_Word> data_;
};
class osymbol_table_impl : public osymbol_table
{
public:
osymbol_table_impl( elf_writer* cgbo, osection* sec );
virtual
~osymbol_table_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual Elf32_Word
add_entry( Elf32_Word name,
Elf32_Addr value,
Elf32_Word size,
unsigned char info,
unsigned char other,
Elf32_Half shndx );
virtual Elf32_Word
add_entry( Elf32_Word name,
Elf32_Addr value,
Elf32_Word size,
unsigned char bind,
unsigned char type,
unsigned char other,
Elf32_Half shndx );
virtual Elf32_Word
add_entry( ostring_table* strtab,
const char* str,
Elf32_Addr value,
Elf32_Word size,
unsigned char info,
unsigned char other,
Elf32_Half shndx );
virtual Elf32_Word
add_entry( ostring_table* strtab,
const char* str,
Elf32_Addr value,
Elf32_Word size,
unsigned char bind,
unsigned char type,
unsigned char other,
Elf32_Half shndx );
private:
ptrdiff_t ref_count_;
elf_writer* cgbo_;
osection* section_;
};
class orelocation_table_impl : public orelocation_table
{
public:
orelocation_table_impl( elf_writer* cgbo, osection* sec );
virtual
~orelocation_table_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word info );
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word symbol,
unsigned char type );
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word info,
Elf32_Sword addend );
virtual CGBIO_ERROR
add_entry( Elf32_Addr offset,
Elf32_Word symbol,
unsigned char type,
Elf32_Sword addend );
virtual CGBIO_ERROR
add_entry( ostring_table* pStrWriter,
const char* str,
osymbol_table* pSymWriter,
Elf32_Addr value,
Elf32_Word size,
unsigned char symInfo,
unsigned char other,
Elf32_Half shndx,
Elf32_Addr offset,
unsigned char type );
virtual CGBIO_ERROR
add_entry( ostring_table* pStrWriter,
const char* str,
osymbol_table* pSymWriter,
Elf32_Addr value,
Elf32_Word size,
unsigned char symInfo,
unsigned char other,
Elf32_Half shndx,
Elf32_Addr offset,
unsigned char type,
Elf32_Sword addend );
private:
ptrdiff_t ref_count_;
elf_writer* cgbo_;
osection* section_;
}; // CGBORelocationTableImpl
class oparam_table_impl : public oparam_table
{
public:
oparam_table_impl( elf_writer* cgbo, osection* sec );
virtual
~oparam_table_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual CGBIO_ERROR
add_entry( Elf32_cgParameter& cgparam );
private:
ptrdiff_t ref_count_;
elf_writer* cgbo_;
osection* section_;
};
} } // bio namespace cgc namespace
#endif // CGC_CGBIO_CGBOIMPL_HPP

View File

@ -0,0 +1,21 @@
#ifndef CGBTYPES_HEADER
#define CGBTYPES_HEADER
// parameter structure
typedef struct _Elf32_cgParameter {
uint32_t cgp_name; // index of name in strtab
uint32_t cgp_semantic; // index of semantic string in strtab
uint16_t cgp_default; // index of default data in const //Reduced to half
uint16_t cgp_reloc; // index of reloc indices in rel
uint16_t cgp_resource; // index of hardware resource assigned
uint16_t cgp_resource_index; // index of hardware resource assigned
unsigned char cgp_type;
uint16_t cgp_info;
unsigned char unused;
} Elf32_cgParameter; //20 bytes
#define CGF_OUTPUTFROMH0 0x01
#define CGF_DEPTHREPLACE 0x02
#define CGF_PIXELKILL 0x04
#endif

View File

@ -0,0 +1,103 @@
#if !defined(CGC_CGBIO_CGBUTILS_HPP)
#define CGC_CGBIO_CGBUTILS_HPP 1
#include "cgbdefs.hpp"
namespace cgc {
namespace bio {
typedef enum {
CGBIODATANONE = ELFDATANONE,
CGBIODATALSB = ELFDATA2LSB,
CGBIODATAMSB = ELFDATA2MSB
} HOST_ENDIANNESS; // endianness
inline HOST_ENDIANNESS
host_endianness()
{
const int ii = 1;
const char* cp = (const char*) &ii;
return ( 1 == cp[0] ) ? CGBIODATALSB : CGBIODATAMSB;
}
template< typename T > inline T
convert_endianness( const T value, unsigned char endianness )
{
if ( host_endianness() == endianness )
{
return value;
}
if ( sizeof( T ) == 1 )
{
return value;
}
if ( sizeof( T ) == 2 )
{
return ( ((value & 0x00FF) << 8)
| ((value & 0xFF00) >> 8) );
}
if ( sizeof( T ) == 4 )
{
return ( ((value & 0x000000FF) << 24)
| ((value & 0x0000FF00) << 8)
| ((value & 0x00FF0000) >> 8)
| ((value & 0xFF000000) >> 24) );
}
if ( sizeof( T ) == 8 )
{
T result = value;
for ( int ii = 0; ii < 4; ++ii )
{
char ch = *( (( char* ) &result) + ii );
*( (( char* ) &result) + ii ) = *( (( char* ) &result) + (7 - ii) );
*( (( char* ) &result) + (7 - ii) ) = ch;
}
return result;
}
// exception
return value;
}
template< typename T > inline T
ELF32_ST_BIND( const T idx )
{
return ( idx >> 4 );
}
template< typename T > inline T
ELF32_ST_TYPE( const T idx )
{
return ( idx & 0xf );
}
template< typename T > inline T
ELF32_ST_INFO( const T b, const T t )
{
return ( ( b << 4 ) + ( t & 0xf ) );
}
template< typename T > inline T
ELF32_ST_VISIBILITY( const T o )
{
return ( o & 0x3 );
}
// these are not used in our relocations, will be replaced by the ones
// we design, will be defined as templates.
#ifndef ELF32_R_SYM
#define ELF32_R_SYM(i) ((i)>>8)
#endif
#ifndef ELF32_R_TYPE
#define ELF32_R_TYPE(i) ((unsigned char)(i))
#endif
#ifndef ELF32_R_INFO
#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t))
#endif
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_CGBUTILS_HPP

View File

@ -0,0 +1,5 @@
#ifndef CGNV2ELF_VERSION
#define CGNV2ELF_VERSION 6365
#define CGNV2ELF_PRODUCT_STRING "SCE cgnv2elf"
#define CGNV2ELF_VERSION_NOTE_TYPE 0
#endif

View File

@ -3,19 +3,14 @@
#include <stdio.h>
#include <vector>
#include <string.h>
#ifndef CGNV2ELF_VERSION
#define CGNV2ELF_VERSION 6365
#define CGNV2ELF_PRODUCT_STRING "cgnv2elf"
#define CGNV2ELF_VERSION_NOTE_TYPE 0
#endif
#define CNV2END(val) convert_endianness((val), elfEndianness)
#define ENDSWAP(val) convert_endianness((val), (host_endianness() == 1) ? 2 : 1)
int convertNvToElfFromFile(const char *sourceFile, int endianness, int constTableOffset, void **binaryShader, int *size, std::vector<char> &stringTable, std::vector<float> &defaultValues);
int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize, std::vector<char> &stringTable, std::vector<float> &defaultValues);
int convertNvToElfFromFile(const char *sourceFile, int endianness, int constTableOffset, void **binaryShader, int *size,
std::vector<char> &stringTable, std::vector<float> &defaultValues);
int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize,
std::vector<char> &stringTable, std::vector<float> &defaultValues);
int convertNvToElfFreeBinaryShader(void *binaryShader);

View File

@ -0,0 +1,92 @@
#if !defined(CGC_CGBIO_NVBI_HPP)
#define CGC_CGBIO_NVBI_HPP 1
#include "cgbdefs.hpp"
#include <iostream>
#include <string>
#include <vector>
#include <cstddef>
#include <Cg/cg.h>
#include <Cg/cgBinary.h>
namespace cgc {
namespace bio {
class nvb_reader {
public:
virtual ~nvb_reader() {}
virtual ptrdiff_t
reference() const = 0;
virtual ptrdiff_t
release() const = 0;
#ifndef __CELLOS_LV2__
virtual CGBIO_ERROR
load( std::istream* stream, int start, bool owner = false ) = 0;
virtual CGBIO_ERROR
load( const char *filename ) = 0;
#endif
virtual CGBIO_ERROR
loadFromString( const char* source, size_t length ) = 0;
virtual bool
is_loaded() const = 0;
virtual unsigned char
endianness() const = 0;
virtual CGprofile
profile() const = 0;
virtual unsigned int
revision() const = 0;
virtual unsigned int
size() const = 0;
virtual unsigned int
number_of_params() const = 0;
virtual unsigned int
ucode_size() const = 0;
virtual const char*
ucode() const = 0;
virtual const CgBinaryFragmentProgram*
fragment_program() const = 0;
virtual const CgBinaryVertexProgram*
vertex_program() const = 0;
virtual CGBIO_ERROR
get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char** semantic,
CGenum& direction,
int& paramno,
bool& is_referenced,
bool& is_shared ) const = 0;
virtual CGBIO_ERROR get_param_name( unsigned int index, const char** name, bool& is_referenced) const = 0;
}; // nvb_reader
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_NVBI_HPP

View File

@ -0,0 +1,103 @@
#if !defined(CGC_CGBIO_NVBIIMPL_HPP)
#define CGC_CGBIO_NVBIIMPL_HPP 1
#include <iostream>
#include <string>
#include <vector>
#include <cstddef>
#include <Cg/cg.h>
#include <Cg/cgBinary.h>
#include "cgbio.hpp"
namespace cgc {
namespace bio {
class nvb_reader_impl : public nvb_reader
{
public:
nvb_reader_impl();
virtual
~nvb_reader_impl();
virtual ptrdiff_t
reference() const;
virtual ptrdiff_t
release() const;
#ifndef __CELLOS_LV2__
virtual CGBIO_ERROR
load( std::istream* stream, int start ,bool owner = false);
virtual CGBIO_ERROR
load( const char* filename );
#endif
virtual CGBIO_ERROR
loadFromString( const char* source, size_t length);
virtual bool
is_loaded() const;
virtual unsigned char
endianness() const;
virtual CGprofile
profile() const;
virtual unsigned int
revision() const;
virtual unsigned int
size() const;
virtual unsigned int
number_of_params() const;
virtual unsigned int
ucode_size() const;
virtual const char*
ucode() const;
virtual const CgBinaryFragmentProgram*
fragment_program() const;
virtual const CgBinaryVertexProgram*
vertex_program() const;
virtual CGBIO_ERROR
get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char ** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char ** semantic,
CGenum& direction,
int& paramno,
bool& is_referenced,
bool& is_shared ) const;
virtual CGBIO_ERROR get_param_name( unsigned int index, const char ** name , bool& is_referenced) const;
private:
mutable ptrdiff_t ref_count_;
int offset_;
bool loaded_;
bool owner_;
bool strStream_;
CgBinaryProgram header_;
unsigned char endianness_;
char* image_;
}; // nvb_reader_impl
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_NVBIIMPL_HPP

View File

@ -0,0 +1,83 @@
#if !defined(CGC_CGBIO_NVBO_HPP)
#define CGC_CGBIO_NVBO_HPP 1
#include <cstddef>
#include <fstream>
#include <string>
#include "cgbdefs.hpp"
using std::ofstream;
using std::streampos;
namespace cgc {
namespace bio {
class nvb_writer {
public:
enum PRODUCER
{
CGBO_HASH,
CGBO_STR,
CGBO_SYM,
CGBO_REL,
CGBO_PARAM,
CGBO_VP,
CGBO_FP
};
virtual ~nvb_writer () {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual CGBIO_ERROR
save( ofstream& ofs ) = 0;
virtual CGBIO_ERROR
save( const char* filename ) = 0;
virtual CGBIO_ERROR
set_attr( unsigned char file_class,
unsigned char endianness,
unsigned char ELFversion,
unsigned char abi,
unsigned char ABIversion,
Elf32_Half type,
Elf32_Half machine,
Elf32_Word version,
Elf32_Word flags ) = 0;
virtual Elf32_Addr
get_entry() const = 0;
virtual CGBIO_ERROR
set_entry( Elf32_Addr entry ) = 0;
virtual unsigned char
endianness() const = 0;
}; // elf_writer interface class
class oparam_array
{
public:
virtual ~oparam_array() {}
virtual ptrdiff_t
reference() = 0;
virtual ptrdiff_t
release() = 0;
virtual CGBIO_ERROR
add_entry() = 0;
}; // oparam_table
} // bio namespace
} // cgc namespace
#endif // CGC_CGBIO_NVBO_HPP

View File

@ -0,0 +1,85 @@
#if !defined(CGC_CGBIO_NVBOIMPL_HPP)
#define CGC_CGBIO_NVBOIMPL_HPP 1
#include <cstddef>
#include <iostream>
#include <string>
#include <vector>
#include "cgbio.hpp"
namespace cgc {
namespace bio {
class nvb_writer_impl : public nvb_writer
{
public:
nvb_writer_impl();
virtual
~nvb_writer_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual CGBIO_ERROR
save( ofstream& ofs );
virtual CGBIO_ERROR
save( const char* filename );
virtual CGBIO_ERROR
set_attr( unsigned char file_class,
unsigned char endianness,
unsigned char ELFversion,
unsigned char abi,
unsigned char ABIversion,
Elf32_Half type,
Elf32_Half machine,
Elf32_Word version,
Elf32_Word flags );
virtual Elf32_Addr
get_entry() const;
virtual CGBIO_ERROR
set_entry( Elf32_Addr entry );
virtual unsigned char
endianness() const;
private:
ptrdiff_t ref_count_;
Elf32_Ehdr header_;
}; // elf_writer_impl
class oparam_array_impl : public oparam_array
{
public:
oparam_array_impl( nvb_writer* cgbo );
virtual
~oparam_array_impl();
virtual ptrdiff_t
reference();
virtual ptrdiff_t
release();
virtual CGBIO_ERROR
add_entry();
private:
ptrdiff_t ref_count_;
nvb_writer* cgbo_;
};
} } // bio namespace cgc namespace
#endif // CGC_CGBIO_NVBOIMPL_HPP

View File

@ -0,0 +1,254 @@
#ifndef ELF_H
#define ELF_H
/*
* Data Representation
*/
/*
* ELF header
*/
/* e_ident[] Identification Indexes */
#define EI_MAG0 0 /* File identification */
#define EI_MAG1 1 /* File identification */
#define EI_MAG2 2 /* File identification */
#define EI_MAG3 3 /* File identification */
#define EI_CLASS 4 /* File class */
#define EI_DATA 5 /* Data encoding */
#define EI_VERSION 6 /* File version */
#define EI_OSABI 7 /* Operating system/ABI identification */
#define EI_ABIVERSION 8 /* ABI version */
#define EI_PAD 9 /* Start of padding bytes */
#define EI_NIDENT 16 /* Size of e_ident[] */
/* e_ident[EI_MAG0] to e_ident[EI_MAG3] */
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
/* e_ident[EI_CLASS] */
#define ELFCLASSNONE 0 /* Invalid class */
#define ELFCLASS32 1 /* 32-bit objects */
#define ELFCLASS64 2 /* 64-bit objects */
/* e_ident[EI_DATA] */
#define ELFDATANONE 0 /* Invalid data encoding */
#define ELFDATA2LSB 1 /* little endian */
#define ELFDATA2MSB 2 /* big endian */
/* e_ident[EI_VERSION] */
#define EV_NONE 0 /* Invalid version */
#define EV_CURRENT 1 /* Current version */
/* e_type */
#define ET_NONE 0 /* No file type */
#define ET_REL 1 /* Relocatable file */
#define ET_EXEC 2 /* Executable file */
#define ET_DYN 3 /* Shared object file */
#define ET_CORE 4 /* Core file */
/* e_machine */
#define EM_PPC 20 /* PowerPC 32-bit */
#define EM_PPC64 21 /* PowerPC 64-bit */
typedef struct {
unsigned char e_ident[EI_NIDENT];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
uint32_t e_entry;
int32_t e_phoff;
int32_t e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} Elf32_Ehdr;
typedef struct {
unsigned char e_ident[EI_NIDENT];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
uint64_t e_entry;
uint64_t e_phoff;
uint64_t e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} Elf64_Ehdr;
/*
* Program Header
*/
/* Segment Types, p_type */
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_LOOS 0x60000000
#define PT_HIOS 0x6fffffff
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
typedef struct {
uint32_t p_type;
int32_t p_offset;
uint32_t p_vaddr;
uint32_t p_paddr;
uint32_t p_filesz;
uint32_t p_memsz;
uint32_t p_flags;
uint32_t p_align;
} Elf32_Phdr;
typedef struct {
uint32_t p_type;
uint32_t p_flags;
uint64_t p_offset;
uint64_t p_vaddr;
uint64_t p_paddr;
uint64_t p_filesz;
uint64_t p_memsz;
uint64_t p_align;
} Elf64_Phdr;
/*
* Section Header
*/
/* sh_type */
#define SHT_NULL 0 /* Section header table entry unused */
#define SHT_PROGBITS 1 /* Program data */
#define SHT_SYMTAB 2 /* Symbol table */
#define SHT_STRTAB 3 /* String table */
#define SHT_RELA 4 /* Relocation entries with addends */
#define SHT_HASH 5 /* Symbol hash table */
#define SHT_DYNAMIC 6 /* Dynamic linking information */
#define SHT_NOTE 7 /* Notes */
#define SHT_NOBITS 8 /* Program space with no data (bss) */
#define SHT_REL 9 /* Relocation entries, no addends */
#define SHT_SHLIB 10 /* Reserved */
#define SHT_DYNSYM 11 /* Dynamic linker symbol table */
#define SHF_WRITE (1 << 0) /* Writable */
#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
#define SHF_EXECINSTR (1 << 2) /* Executable */
#define SHF_MERGE (1 << 4) /* Might be merged */
#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */
#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */
#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling
required */
#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
typedef struct {
uint32_t sh_name;
uint32_t sh_type;
uint32_t sh_flags;
uint32_t sh_addr;
int32_t sh_offset;
uint32_t sh_size;
uint32_t sh_link;
uint32_t sh_info;
uint32_t sh_addralign;
uint32_t sh_entsize;
} Elf32_Shdr;
/* Special section indices. */
#define SHN_UNDEF 0 /* Undefined section */
#define SHN_LORESERVE 0xff00 /* Start of reserved indices */
#define SHN_LOPROC 0xff00 /* Start of processor-specific */
#define SHN_HIPROC 0xff1f /* End of processor-specific */
#define SHN_LOOS 0xff20 /* Start of OS-specific */
#define SHN_HIOS 0xff3f /* End of OS-specific */
#define SHN_ABS 0xfff1 /* Associated symbol is absolute */
#ifndef SHN_COMMON
#define SHN_COMMON 0xfff2 /* Associated symbol is common */
#endif
#ifndef SHN_XINDEX
#define SHN_XINDEX 0xffff /* Index is in extra table. */
#endif
#ifndef SHN_HIRESERVE
#define SHN_HIRESERVE 0xffff /* End of reserved indices */
#endif
/*
* Symbol Header
*/
typedef struct {
uint32_t st_name;
uint32_t st_value;
uint32_t st_size;
unsigned char st_info;
unsigned char st_other;
uint16_t st_shndx;
} Elf32_Sym;
/* Relocation table entry without addend (in section of type SHT_REL). */
typedef struct
{
uint32_t r_offset; /* Address */
uint32_t r_info; /* Relocation type and symbol index */
} Elf32_Rel;
/* I have seen two different definitions of the Elf64_Rel and
Elf64_Rela structures, so we'll leave them out until Novell (or
whoever) gets their act together. */
/* The following, at least, is used on Sparc v9, MIPS, and Alpha. */
typedef struct
{
uint64_t r_offset; /* Address */
uint64_t r_info; /* Relocation type and symbol index */
} Elf64_Rel;
/* Relocation table entry with addend (in section of type SHT_RELA). */
typedef struct
{
uint32_t r_offset; /* Address */
uint32_t r_info; /* Relocation type and symbol index */
int32_t r_addend; /* Addend */
} Elf32_Rela;
typedef struct
{
uint64_t r_offset; /* Address */
uint64_t r_info; /* Relocation type and symbol index */
int64_t r_addend; /* Addend */
} Elf64_Rela;
/* How to extract and insert information held in the r_info field. */
#define ELF32_R_SYM(val) ((val) >> 8)
#define ELF32_R_TYPE(val) ((val) & 0xff)
#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
#define ELF64_R_SYM(i) ((i) >> 32)
#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
#define ELF64_R_INFO(sym,type)((((uint64_t) (sym)) << 32) + (type))
#endif /* ELF_H */

View File

@ -0,0 +1,125 @@
/*
* Spu simulator library - ELF reader.
* AUTHORS: Antoine Labour, Robin Green
* DATE: 2003-Oct-16
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "readelf.h"
const Elf32_Sym *getSymbolByIndex(const ELF_t *elf,int idx)
{
if(!elf)
return NULL;
if(elf->symbolsSection<=0)
return NULL;
ELF_section_t *section=elf->sections+elf->symbolsSection;
if(!section->data)
return NULL;
if ((idx<0) || (idx>=(int)elf->symbolCount))
return NULL;
return(Elf32_Sym *)(section->data+section->header.sh_entsize*idx);
}
int lookupSymbol(const ELF_t *elf,const char *name)
{
unsigned int i;
if(!elf||!name)
return -1;
ELF_symbol_t *symbol=elf->symbols;
if(!symbol)
return -1;
for (i = 0; i < elf->symbolCount; ++i, ++symbol)
if (strcmp(name,symbol->name)==0)
return i;
return -1;
}
static const char *_getStringTable(const Elf32_Ehdr *ehdr)
{
const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff;
const Elf32_Shdr *shstrtabHeader = (const Elf32_Shdr*)sectionHeaderStart + ehdr->e_shstrndx;
return (const char*)ehdr + shstrtabHeader->sh_offset;
}
const char *findSectionInPlace(const char* memory, const char *name, size_t *sectionSize)
{
const Elf32_Ehdr *ehdr = (const Elf32_Ehdr*)memory;
//first get the string section header
const char *shstrtab = _getStringTable(ehdr);
//find the section
size_t sectionCount = ehdr->e_shnum;
const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff;
for (size_t i=0;i<sectionCount;i++)
{
const Elf32_Shdr *sectionHeader = (const Elf32_Shdr *)sectionHeaderStart + i;
const char *sectionName = shstrtab + sectionHeader->sh_name;
if (!strcmp(name,sectionName))
{
*sectionSize = sectionHeader->sh_size;
return (const char*)ehdr + sectionHeader->sh_offset;
}
}
return NULL;
}
const char *findSymbolSectionInPlace(const char *memory, size_t *symbolSize, size_t *symbolCount, const char **symbolstrtab)
{
const Elf32_Ehdr *ehdr = (const Elf32_Ehdr*)memory;
//find the section
size_t sectionCount = ehdr->e_shnum;
const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff;
for (size_t i = 0; i < sectionCount; i++)
{
const Elf32_Shdr *sectionHeader = (const Elf32_Shdr *)sectionHeaderStart + i;
if (sectionHeader->sh_type == SHT_SYMTAB)
{
*symbolSize = sectionHeader->sh_entsize;
*symbolCount = sectionHeader->sh_size / sectionHeader->sh_entsize;
const Elf32_Shdr *symbolStrHeader = (const Elf32_Shdr *)sectionHeaderStart + sectionHeader->sh_link;
*symbolstrtab = (const char*)ehdr + symbolStrHeader->sh_offset;
return (const char*)ehdr + sectionHeader->sh_offset;
}
}
return NULL;
}
int lookupSymbolValueInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, const char *name)
{
for (size_t i=0;i<symbolCount;i++)
{
Elf32_Sym* elf_sym = (Elf32_Sym*)symbolSection;
if (!strcmp(symbolstrtab + elf_sym->st_name, name))
return elf_sym->st_value;
symbolSection+= symbolSize;
}
return -1;
}
const char *getSymbolByIndexInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, int index)
{
Elf32_Sym* elf_sym = (Elf32_Sym*)symbolSection + index;
return symbolstrtab + elf_sym->st_name;
}

View File

@ -0,0 +1,91 @@
#ifndef READELF_H
#define READELF_H
#include "elf.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _ELF_section_t
{
Elf32_Shdr header;
const char* name;
char* data;
} ELF_section_t;
typedef struct _ELF_segment_t
{
Elf32_Phdr header;
unsigned char* pointer;
unsigned char* data;
} ELF_segment_t;
typedef struct
{
const char* name;
unsigned int vma;
unsigned int size;
int section;
unsigned char resolved;
unsigned char foreign;
} ELF_symbol_t;
typedef struct _ELF_t
{
unsigned int endian;
unsigned int relocatable;
unsigned int sectionCount;
unsigned int segmentCount;
unsigned int symbolCount;
unsigned int entrypoint;
ELF_section_t* sections;
ELF_segment_t* segments;
ELF_symbol_t* symbols;
unsigned int symbolsSection;
unsigned int symbolNamesSection;
unsigned int paramSection;
} ELF_t;
typedef struct
{
unsigned int relative;
unsigned int shift;
unsigned int size;
unsigned int position;
unsigned int mask;
} ELF_rel_type_t;
ELF_t* readElfFromFile(const char* filename);
ELF_t* readElfFromMemory(const char* memory,unsigned int size);
ELF_section_t* findSection(const ELF_t* elf,const char* name);
int lookupSymbol(const ELF_t* elf,const char* name);
int lookupResolvedSymbol(const ELF_t* elf,const char* name);
const Elf32_Sym* getSymbolByIndex(const ELF_t* elf,int idx);
int resolveElf(ELF_t* main_elf,ELF_t* elf);
int relocateSymbols(ELF_t* elf,unsigned int origin);
int loadSectionsToMemory(ELF_t* elf,char* memory,int memorySize,unsigned int origin);
void doRelocations(ELF_t* elf,char* memory,int memorySize,int origin,const ELF_rel_type_t* rel_types,unsigned int rel_types_count);
int loadElfToMemory(unsigned char* memory, unsigned int size, unsigned int load_address, ELF_t* elf);
void freeElf(ELF_t* elf);
//in place API
const char *findSectionInPlace(const char* memory, const char *name,size_t *sectionSize);
const char *findSymbolSectionInPlace(const char *memory, size_t *symbolSize, size_t *symbolCount, const char **symbolstrtab);
int lookupSymbolValueInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, const char *name);
const char *getSymbolByIndexInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, int index);
void spuDoRelocations(ELF_t* elf,char* memory,int memorySize,int origin);
uint16_t endian_half(int endian, uint16_t v);
uint32_t endian_word(int endian, uint32_t v);
#define endian_addr(e, v) endian_word(e, v)
#define endian_off(e, v) endian_word(e, v)
#define endian_size(e, v) endian_half(e, v)
#ifdef __cplusplus
}
#endif
#endif // READELF_H

View File

@ -0,0 +1,189 @@
#ifndef _GMM_ALLOC_H_
#define _GMM_ALLOC_H_
void gmmPrintState(); // print out all blocks and their current states
#define GMM_ASSERT(cond) ((void)0)
#define GMM_ERROR 0xFFFFFFFF
#define GMM_TILE_ALIGNMENT 0x10000 // 16K
#define GMM_ALIGNMENT 128 // non-tile is 128 byte
#define GMM_RSX_WAIT_INDEX 254 // label index
#define GMM_PPU_WAIT_INDEX 255 // label index
#define GMM_BLOCK_COUNT 512 // initial memory block pool
#define GMM_TILE_BLOCK_COUNT 16 // initial tile memory block pool
#define GMM_NUM_FREE_BINS 22
#define GMM_FREE_BIN_0 0x80 // 0x00 - 0x80
#define GMM_FREE_BIN_1 0x100 // 0x80 - 0x100
#define GMM_FREE_BIN_2 0x180 // ...
#define GMM_FREE_BIN_3 0x200
#define GMM_FREE_BIN_4 0x280
#define GMM_FREE_BIN_5 0x300
#define GMM_FREE_BIN_6 0x380
#define GMM_FREE_BIN_7 0x400
#define GMM_FREE_BIN_8 0x800
#define GMM_FREE_BIN_9 0x1000
#define GMM_FREE_BIN_10 0x2000
#define GMM_FREE_BIN_11 0x4000
#define GMM_FREE_BIN_12 0x8000
#define GMM_FREE_BIN_13 0x10000
#define GMM_FREE_BIN_14 0x20000
#define GMM_FREE_BIN_15 0x40000
#define GMM_FREE_BIN_16 0x80000
#define GMM_FREE_BIN_17 0x100000
#define GMM_FREE_BIN_18 0x200000
#define GMM_FREE_BIN_19 0x400000
#define GMM_FREE_BIN_20 0x800000
#define GMM_FREE_BIN_21 0x1000000
// data structure for the fixed allocater
typedef struct GmmFixedAllocData{
char **ppBlockList[2]; // pre-allocated list of block descriptors
uint16_t **ppFreeBlockList[2];
uint16_t *pBlocksUsed[2];
uint16_t BlockListCount[2];
}GmmFixedAllocData;
// common shared block descriptor for tile and non-tile block
// "base class" for GmmBlock and GmmTileBlock
typedef struct GmmBaseBlock{
uint8_t isTile;
//uint8_t isMain;
uint32_t address;
uint32_t size;
}GmmBaseBlock;
typedef struct GmmBlock{
GmmBaseBlock base; // inheritence
struct GmmBlock *pPrev;
struct GmmBlock *pNext;
uint8_t isPinned;
// these would only be valid if the block is in
// pending free list or free list
struct GmmBlock *pPrevFree;
struct GmmBlock *pNextFree;
uint32_t fence;
}GmmBlock;
typedef struct GmmTileBlock{
GmmBaseBlock base; // inheritence
struct GmmTileBlock *pPrev;
struct GmmTileBlock *pNext;
uint32_t tileTag;
void *pData;
}GmmTileBlock;
typedef struct GmmAllocator{
uint32_t memoryBase;
uint32_t startAddress;
uint32_t size;
uint32_t freeAddress;
GmmBlock *pHead;
GmmBlock *pTail;
GmmBlock *pSweepHead;
uint32_t freedSinceSweep;
uint32_t tileStartAddress;
uint32_t tileSize;
GmmTileBlock *pTileHead;
GmmTileBlock *pTileTail;
GmmBlock *pPendingFreeHead;
GmmBlock *pPendingFreeTail;
// Acceleration data structure for free blocks
GmmBlock *pFreeHead[GMM_NUM_FREE_BINS];
GmmBlock *pFreeTail[GMM_NUM_FREE_BINS];
uint32_t totalSize; // == size + tileSize
}GmmAllocator;
uint32_t gmmInit(
const void *localMemoryBase,
const void *localStartAddress,
const uint32_t localSize,
const void *mainMemoryBase,
const void *mainStartAddress,
const uint32_t mainSize
);
uint32_t gmmDestroy();
uint32_t gmmIdToOffset(
const uint32_t id
);
char *gmmIdToAddress(
const uint32_t id
);
uint32_t gmmFPOffsetToId(
const uint32_t offset,
uint32_t *pOutOffset,
bool bLocalMemory
);
void gmmPinId(
const uint32_t id
);
void gmmUnpinId(
const uint32_t id
);
uint32_t gmmFree(
const uint32_t freeId
);
void gmmUpdateFreeList(
const uint8_t location
);
uint32_t gmmAlloc(
CellGcmContextData *thisContext,
const uint8_t location,
const uint8_t isTile,
const uint32_t size
);
uint32_t gmmAllocExtendedTileBlock(
const uint8_t location,
const uint32_t size,
const uint32_t tag
);
uint32_t gmmGetBlockSize(
const uint32_t id
);
void gmmSetTileAttrib(
const uint32_t id,
const uint32_t tag,
void *pData
);
void *gmmGetTileData(
const uint32_t id
);
void gmmPinAllocations();
void gmmUnpinAllocations();
static inline uint8_t gmmIdIsMain(
const uint32_t id
)
{
return false;
}
#endif

View File

@ -0,0 +1,464 @@
// This is used to make sure the pass the gpu the
// right endianness. RS
#define RGLGCM_BIG_ENDIAN
#if RGL_ENDIAN == RGL_BIG_ENDIAN
#define ENDIAN_32(X, F) ((F) ? endianSwapWord(X) : (X))
#else
#define ENDIAN_32(X, F) (X)
#endif
#define FRAGMENT_PROFILE_INDEX 1
#define RGLP_MAX_TEXTURE_SIZE 4096
// GCM RESERVE and no RGLGCM post fifo SKID Check
#define GCM_RESERVE_NO_SKID
#ifdef GCM_RESERVE_NO_SKID
#define GCM_FUNC_RESERVE( count )\
CELL_GCM_RESERVE(count);
#define GCM_FUNC_SAFE( GCM_FUNCTION, ...) \
{ \
GCM_FUNCTION( (CellGcmContextData*)&rglGcmState_i.fifo, __VA_ARGS__ ); \
}
#define GCM_FUNC_SAFE_NO_ARGS( GCM_FUNCTION, ...) \
{ \
GCM_FUNCTION( (CellGcmContextData*)&rglGcmState_i.fifo ); \
}
#define GCM_FUNC( GCM_FUNCTION, ...) \
{ \
GCM_FUNCTION ## Inline( (CellGcmContextData*)&rglGcmState_i.fifo, __VA_ARGS__ ); \
}
#define GCM_FUNC_NO_ARGS( GCM_FUNCTION ) \
{ \
GCM_FUNCTION ## Inline( (CellGcmContextData*)&rglGcmState_i.fifo ); \
}
#endif
/* [RSTENSON] To be able to build up buffered push buffers with GCM we need to use the
// cellGcmSetCurrentBuffer and reset the buffer with cellGcmDefualtCommandBuffer afterwards.
// Buffer size checks are not handled by these macros because they operate on pointers
// to data and not cellGcmContextDmas, thus the use of UnsafeInline versions vs Inline as above */
// This for pushing in to a memory buffer verses the actual active fifo
#define GCM_FUNC_BUFFERED_UNSAFE_INLINED
#ifdef GCM_FUNC_BUFFERED_UNSAFE_INLINED
#define GCM_FUNC_BUFFERED( GCM_FUNCTION, COMMAND_BUFFER, ...) \
{ \
CellGcmContextData gcmContext; \
gcmContext.current = (uint32_t *)COMMAND_BUFFER; \
GCM_FUNCTION ## UnsafeInline( &gcmContext, __VA_ARGS__ ); \
COMMAND_BUFFER = (typeof(COMMAND_BUFFER))gcmContext.current; \
}
#endif
typedef enum rglGcmEnum
{
// gleSetRenderTarget
RGLGCM_NONE = 0x0000,
// glDrawArrays, glDrawElements, glBegin
RGLGCM_POINTS = 0x0000,
RGLGCM_LINES = 0x0001,
RGLGCM_LINE_LOOP = 0x0002,
RGLGCM_LINE_STRIP = 0x0003,
RGLGCM_TRIANGLES = 0x0004,
RGLGCM_TRIANGLE_STRIP = 0x0005,
RGLGCM_TRIANGLE_FAN = 0x0006,
RGLGCM_QUADS = 0x0007,
RGLGCM_QUAD_STRIP = 0x0008,
RGLGCM_POLYGON = 0x0009,
// glClear
RGLGCM_DEPTH_BUFFER_BIT = 0x0100,
RGLGCM_STENCIL_BUFFER_BIT = 0x0400,
RGLGCM_COLOR_BUFFER_BIT = 0x4000,
// glBlendFunc, glStencilFunc
RGLGCM_ZERO = 0,
RGLGCM_ONE = 1,
RGLGCM_SRC_COLOR = 0x0300,
RGLGCM_ONE_MINUS_SRC_COLOR = 0x0301,
RGLGCM_SRC_ALPHA = 0x0302,
RGLGCM_ONE_MINUS_SRC_ALPHA = 0x0303,
RGLGCM_DST_ALPHA = 0x0304,
RGLGCM_ONE_MINUS_DST_ALPHA = 0x0305,
RGLGCM_DST_COLOR = 0x0306,
RGLGCM_ONE_MINUS_DST_COLOR = 0x0307,
RGLGCM_SRC_ALPHA_SATURATE = 0x0308,
// glAlphaFunc, glDepthFunc, glStencilFunc
RGLGCM_NEVER = 0x0200,
RGLGCM_LESS = 0x0201,
RGLGCM_EQUAL = 0x0202,
RGLGCM_LEQUAL = 0x0203,
RGLGCM_GREATER = 0x0204,
RGLGCM_NOTEQUAL = 0x0205,
RGLGCM_GEQUAL = 0x0206,
RGLGCM_ALWAYS = 0x0207,
// glLogicOp
RGLGCM_CLEAR = 0x1500,
RGLGCM_AND = 0x1501,
RGLGCM_AND_REVERSE = 0x1502,
RGLGCM_COPY = 0x1503,
RGLGCM_AND_INVERTED = 0x1504,
RGLGCM_NOOP = 0x1505,
RGLGCM_XOR = 0x1506,
RGLGCM_OR = 0x1507,
RGLGCM_NOR = 0x1508,
RGLGCM_EQUIV = 0x1509,
RGLGCM_INVERT = 0x150A,
RGLGCM_OR_REVERSE = 0x150B,
RGLGCM_COPY_INVERTED = 0x150C,
RGLGCM_OR_INVERTED = 0x150D,
RGLGCM_NAND = 0x150E,
RGLGCM_SET = 0x150F,
// BlendFunc
RGLGCM_CONSTANT_COLOR = 0x8001,
RGLGCM_ONE_MINUS_CONSTANT_COLOR = 0x8002,
RGLGCM_CONSTANT_ALPHA = 0x8003,
RGLGCM_ONE_MINUS_CONSTANT_ALPHA = 0x8004,
RGLGCM_BLEND_COLOR = 0x8005,
RGLGCM_FUNC_ADD = 0x8006,
RGLGCM_MIN = 0x8007,
RGLGCM_MAX = 0x8008,
RGLGCM_BLEND_EQUATION = 0x8009,
RGLGCM_FUNC_SUBTRACT = 0x800A,
RGLGCM_FUNC_REVERSE_SUBTRACT = 0x800B,
// glTexImage binary formats -- keep in sync with glTexImage tables!
RGLGCM_ALPHA8 = 0x803C,
RGLGCM_ALPHA16 = 0x803E,
RGLGCM_HILO8 = 0x885E,
RGLGCM_HILO16 = 0x86F8,
RGLGCM_ARGB8 = 0x6007, // does not exist in classic OpenGL
RGLGCM_BGRA8 = 0xff01, // does not exist in classic OpenGL
RGLGCM_RGBA8 = 0x8058,
RGLGCM_ABGR8 = 0xff02, // does not exist in classic OpenGL
RGLGCM_XBGR8 = 0xff03, // does not exist in classic OpenGL
RGLGCM_RGBX8 = 0xff07, // does not exist in classic OpenGL
RGLGCM_COMPRESSED_RGB_S3TC_DXT1 = 0x83F0,
RGLGCM_COMPRESSED_RGBA_S3TC_DXT1 = 0x83F1,
RGLGCM_COMPRESSED_RGBA_S3TC_DXT3 = 0x83F2,
RGLGCM_COMPRESSED_RGBA_S3TC_DXT5 = 0x83F3,
RGLGCM_DEPTH_COMPONENT16 = 0x81A5,
RGLGCM_DEPTH_COMPONENT24 = 0x81A6,
RGLGCM_FLOAT_R32 = 0x8885,
RGLGCM_RGB5_A1_SCE = 0x600C,
RGLGCM_RGB565_SCE = 0x600D,
// glEnable/glDisable
RGLGCM_BLEND = 0x0be0,
RGLGCM_COLOR_LOGIC_OP = 0x0bf2,
RGLGCM_DITHER = 0x0bd0,
RGLGCM_PSHADER_SRGB_REMAPPING = 0xff06,
// glVertexAttribPointer
RGLGCM_VERTEX_ATTRIB_ARRAY0 = 0x8650,
RGLGCM_VERTEX_ATTRIB_ARRAY1 = 0x8651,
RGLGCM_VERTEX_ATTRIB_ARRAY2 = 0x8652,
RGLGCM_VERTEX_ATTRIB_ARRAY3 = 0x8653,
RGLGCM_VERTEX_ATTRIB_ARRAY4 = 0x8654,
RGLGCM_VERTEX_ATTRIB_ARRAY5 = 0x8655,
RGLGCM_VERTEX_ATTRIB_ARRAY6 = 0x8656,
RGLGCM_VERTEX_ATTRIB_ARRAY7 = 0x8657,
RGLGCM_VERTEX_ATTRIB_ARRAY8 = 0x8658,
RGLGCM_VERTEX_ATTRIB_ARRAY9 = 0x8659,
RGLGCM_VERTEX_ATTRIB_ARRAY10 = 0x865a,
RGLGCM_VERTEX_ATTRIB_ARRAY11 = 0x865b,
RGLGCM_VERTEX_ATTRIB_ARRAY12 = 0x865c,
RGLGCM_VERTEX_ATTRIB_ARRAY13 = 0x865d,
RGLGCM_VERTEX_ATTRIB_ARRAY14 = 0x865e,
RGLGCM_VERTEX_ATTRIB_ARRAY15 = 0x865f,
// glTexImage
RGLGCM_TEXTURE_3D = 0x806F,
RGLGCM_TEXTURE_CUBE_MAP = 0x8513,
RGLGCM_TEXTURE_1D = 0x0DE0,
RGLGCM_TEXTURE_2D = 0x0DE1,
// glTexParameter/TextureMagFilter
RGLGCM_NEAREST = 0x2600,
RGLGCM_LINEAR = 0x2601,
// glTexParameter/TextureMinFilter
RGLGCM_NEAREST_MIPMAP_NEAREST = 0x2700,
RGLGCM_LINEAR_MIPMAP_NEAREST = 0x2701,
RGLGCM_NEAREST_MIPMAP_LINEAR = 0x2702,
RGLGCM_LINEAR_MIPMAP_LINEAR = 0x2703,
// glTexParameter/TextureWrapMode
RGLGCM_CLAMP = 0x2900,
RGLGCM_REPEAT = 0x2901,
RGLGCM_CLAMP_TO_EDGE = 0x812F,
RGLGCM_CLAMP_TO_BORDER = 0x812D,
RGLGCM_MIRRORED_REPEAT = 0x8370,
RGLGCM_MIRROR_CLAMP = 0x8742,
RGLGCM_MIRROR_CLAMP_TO_EDGE = 0x8743,
RGLGCM_MIRROR_CLAMP_TO_BORDER = 0x8912,
// glTexParameter/GammaRemap
RGLGCM_GAMMA_REMAP_RED_BIT = 0x0001,
RGLGCM_GAMMA_REMAP_GREEN_BIT = 0x0002,
RGLGCM_GAMMA_REMAP_BLUE_BIT = 0x0004,
RGLGCM_GAMMA_REMAP_ALPHA_BIT = 0x0008,
// glTexParameter
RGLGCM_TEXTURE_WRAP_S = 0x2802,
RGLGCM_TEXTURE_WRAP_T = 0x2803,
RGLGCM_TEXTURE_WRAP_R = 0x8072,
RGLGCM_TEXTURE_MIN_FILTER = 0x2801,
RGLGCM_TEXTURE_MAG_FILTER = 0x2800,
RGLGCM_TEXTURE_MAX_ANISOTROPY = 0x84FE,
RGLGCM_TEXTURE_COMPARE_FUNC = 0x884D,
RGLGCM_TEXTURE_MIN_LOD = 0x813A,
RGLGCM_TEXTURE_MAX_LOD = 0x813B,
RGLGCM_TEXTURE_LOD_BIAS = 0x8501,
RGLGCM_TEXTURE_BORDER_COLOR = 0x1004,
RGLGCM_TEXTURE_GAMMA_REMAP = 0xff30,
// ARB_vertex_program
RGLGCM_VERTEX_PROGRAM = 0x8620,
RGLGCM_FRAGMENT_PROGRAM = 0x8804,
// glVertexAttribPointer
RGLGCM_FLOAT = 0x1406,
RGLGCM_HALF_FLOAT = 0x140B,
RGLGCM_SHORT = 0x1402,
RGLGCM_UNSIGNED_BYTE = 0x1401,
RGLGCM_UNSIGNED_SHORT = 0x1403,
RGLGCM_UNSIGNED_INT = 0x1405,
RGLGCM_BYTE = 0x1400,
RGLGCM_INT = 0x1404,
// query support
RGLGCM_SAMPLES_PASSED = 0xff10,
// semaphore support
RGLGCM_SEMAPHORE_USING_GPU = 0xff20,
RGLGCM_SEMAPHORE_USING_CPU = 0xff21,
RGLGCM_SEMAPHORE_USING_GPU_NO_WRITE_FLUSH = 0xff22,
// depth clamp
RGLGCM_DEPTH_CLAMP = 0x864F,
// 11/11/10 bit 3-component attributes
RGLGCM_CMP = 0x6020,
} rglGcmEnum;
#define RGLGCM_LINEAR_BUFFER_ALIGNMENT 128
#define RGLGCM_HOST_BUFFER_ALIGNMENT 128
#define RGLGCM_TRANSIENT_MEMORY_DEFAULT (32 << 20)
#define RGLGCM_PERSISTENT_MEMORY_DEFAULT (160 << 20)
#define RGLGCM_FIFO_SIZE_DEFAULT (256 * 1024)
#define RGLGCM_HOST_SIZE_DEFAULT (0)
#define RGLGCM_TRANSIENT_ENTRIES_DEFAULT 64
// RSX semaphore allocation
// 64-191 events
// 192 fence implementation (independent of nv_glFence)
// 253 used in RGLGcmFifoUtils.h
#define RGLGCM_SEMA_NEVENTS 128
#define RGLGCM_SEMA_BASE 64 // libgcm uses 0-63
#define RGLGCM_SEMA_FENCE (RGLGCM_SEMA_BASE+RGLGCM_SEMA_NEVENTS+0)
// synchronization
// rglGcmSync enables GPU waiting by sending nv_glAcquireSemaphore to the
// GPU and returning a memory mapped pointer to the semaphore. The GPU
// will be released when 0 is written to the memory location.
//
// rglGcm{Inc,Test,Finish}FenceRef are intended to be drop-in replacements
// for the corresponding RGLGCM routines, using a semaphore instead of the
// fence mechanism (so IncFence uses the 3D class).
#define RGLGCM_FALSE 0
#define RGLGCM_MAX_COLOR_SURFACES 4
#define RGLGCM_TRUE 1
// allocation unit for buffer objects
// Each buffer object is allocated to a multiple of this block size. This
// must be at least 64 so that nv_glTransferDataVidToVid() can be used to
// copy buffer objects within video memory. This function performs a 2D
// blit, and there is a 64-byte minimum pitch constraint.
//
// Swizzled textures require 128-byte alignment, so this takes precedence.
#define RGL_BUFFER_OBJECT_BLOCK_SIZE 128
#define VERTEX_PROFILE_INDEX 0
// GCM can render to 4 color buffers at once.
#define RGLGCM_SETRENDERTARGET_MAXCOUNT 4
// max amount of semaphore we allocate space for
#define RGLGCM_MAX_USER_SEMAPHORES 256
#define RGLGCM_PAGE_SIZE 0x1000 // 4KB
#define RGLGCM_LM_MAX_TOTAL_QUERIES 800
#define RGLGCM_LM_MAX_ZPASS_REPORTS (RGLGCM_LM_MAX_TOTAL_QUERIES - 10)
#define RGLGCM_LM_MAX_USER_QUERIES (RGLGCM_LM_MAX_ZPASS_REPORTS)
// For main memory query PSGL is going to enable 5000 at any given time
// compared to the 800 currently for the Local memory queries
// However, if you really need more than 5k then change the line below
// and recompile [RSTENSON]
// Maximum value for RGLGCM_MM_MAX_TOTAL_QUERIES is 65,000
#define RGLGCM_MM_MAX_TOTAL_QUERIES 5000 // Should be plenty.
#define RGLGCM_MM_MAX_ZPASS_REPORTS (RGLGCM_MM_MAX_TOTAL_QUERIES - 10)
#define RGLGCM_MM_MAX_USER_QUERIES (RGLGCM_MM_MAX_ZPASS_REPORTS)
// For 2.50 PSGL will use reports in main memory by default
// To revert to reports in local memory comment out this define
#define RGLGCM_USE_MAIN_MEMORY_REPORTS
#ifdef RGLGCM_USE_MAIN_MEMORY_REPORTS
#define RGLGCM_MAX_USER_QUERIES RGLGCM_MM_MAX_USER_QUERIES
#else
#define RGLGCM_MAX_USER_QUERIES RGLGCM_LM_MAX_USER_QUERIES
#endif
#define RGLGCM_357C_NOTIFIERS_MAXCOUNT 11
enum
{
// dma contexts
RGLGCM_CHANNEL_DMA_SCRATCH_NOTIFIER,
RGLGCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER,
RGLGCM_CONTEXT_DMA_TO_MEMORY_GET_REPORT,
RGLGCM_CONTEXT_DMA_MEMORY_HOST_BUFFER,
RGLGCM_CONTEXT_DMA_MEMORY_SEMAPHORE_RW,
RGLGCM_CONTEXT_DMA_MEMORY_SEMAPHORE_RO,
// classes
RGLGCM_CURIE_PRIMITIVE,
RGLGCM_MEM2MEM_HOST_TO_VIDEO,
RGLGCM_IMAGEFROMCPU,
RGLGCM_SCALEDIMAGE,
RGLGCM_CONTEXT_2D_SURFACE,
RGLGCM_CONTEXT_SWIZ_SURFACE,
RGLGCM_HANDLE_COUNT
};
// For quick float->int conversions
#define RGLGCM_F0_DOT_0 12582912.0f
// some other useful push buf defines/commands
#define RGLGCM_NON_INCREMENT (0x40000000)
#define RGLGCM_NOP() (0x00000000)
#define RGLGCM_JUMP(addr) (0x20000000 | (addr))
#define RGLGCM_CALL(addr) (0x00000002 | (addr))
#define RGLGCM_RETURN() (0x00020000)
#define RGLGCM_MAX_METHOD_COUNT (2047)
#define RGLGCM_COUNT_SHIFT (18)
#define RGLGCM_SUBCHANNEL_SHIFT (13)
#define RGLGCM_METHOD_SHIFT (0)
#define DEFAULT_FIFO_BLOCK_SIZE (0x10000) // 64KB
#define FIFO_RESERVE_SIZE 8 // reserved words needed at the beginning of the fifo
#define BUFFER_HSYNC_NEGATIVE 0
#define BUFFER_HSYNC_POSITIVE 1
#define BUFFER_VSYNC_NEGATIVE 0
#define BUFFER_VSYNC_POSITIVE 1
// This is the format that the mode timing parameters are handed back
enum {
RGLGCM_SURFACE_SOURCE_TEMPORARY,
RGLGCM_SURFACE_SOURCE_DEVICE,
RGLGCM_SURFACE_SOURCE_TEXTURE,
RGLGCM_SURFACE_SOURCE_RENDERBUFFER,
RGLGCM_SURFACE_SOURCE_PBO,
};
enum {
RGLGCM_SURFACE_POOL_NONE,
RGLGCM_SURFACE_POOL_TILED_COLOR,
RGLGCM_SURFACE_POOL_TILED_DEPTH,
RGLGCM_SURFACE_POOL_LINEAR,
RGLGCM_SURFACE_POOL_SYSTEM, // GPU accessible host memory
RGLGCM_SURFACE_POOL_PPU, // generic EA
RGLGCM_SURFACE_POOL_SYSTEM_TILED_COLOR, // tiled color GPU accessible XDR
RGLGCM_SURFACE_POOL_SYSTEM_TILED_DEPTH, // tiled depth GPU accessible XDR
};
#define RGLGCM_DEVICE_SYNC_FENCE 1
#define RGLGCM_DEVICE_SYNC_COND 2
// max surface/scissor/viewport dimension
#define RGLGCM_MAX_RT_DIMENSION (CELL_GCM_MAX_RT_DIMENSION)
// a few texture consts
#define RGLGCM_MAX_SHADER_TEXCOORD_COUNT (CELL_GCM_MAX_SHADER_TEXCOORD_COUNT)
#define RGLGCM_MAX_TEXIMAGE_COUNT (CELL_GCM_MAX_TEXIMAGE_COUNT)
#define RGLGCM_MAX_LOD_COUNT (CELL_GCM_MAX_LOD_COUNT)
#define RGLGCM_MAX_TEX_DIMENSION (CELL_GCM_MAX_TEX_DIMENSION)
// max attrib count
#define RGLGCM_ATTRIB_COUNT 16
// Names for each of the vertex attributes
#define RGLGCM_ATTRIB_POSITION 0
#define RGLGCM_ATTRIB_VERTEX_WEIGHT 1
#define RGLGCM_ATTRIB_NORMAL 2
#define RGLGCM_ATTRIB_COLOR 3
#define RGLGCM_ATTRIB_SECONDARY_C OLOR 4
#define RGLGCM_ATTRIB_FOG_COORD 5
#define RGLGCM_ATTRIB_PSIZE 6
#define RGLGCM_ATTRIB_UNUSED1 7
#define RGLGCM_ATTRIB_TEXCOORD0 8
#define RGLGCM_ATTRIB_TEXCOORD1 9
#define RGLGCM_ATTRIB_TEXCOORD2 10
#define RGLGCM_ATTRIB_TEXCOORD3 11
#define RGLGCM_ATTRIB_TEXCOORD4 12
#define RGLGCM_ATTRIB_TEXCOORD5 13
#define RGLGCM_ATTRIB_TEXCOORD6 14
#define RGLGCM_ATTRIB_TEXCOORD7 15
// Names for the vertex output components:
#define RGLGCM_ATTRIB_OUTPUT_HPOS 0
#define RGLGCM_ATTRIB_OUTPUT_COL0 1
#define RGLGCM_ATTRIB_OUTPUT_COL1 2
#define RGLGCM_ATTRIB_OUTPUT_BFC0 3
#define RGLGCM_ATTRIB_OUTPUT_BFC1 4
#define RGLGCM_ATTRIB_OUTPUT_FOGC 5
#define RGLGCM_ATTRIB_OUTPUT_PSIZ 6
#define RGLGCM_ATTRIB_OUTPUT_TEX0 7
#define RGLGCM_ATTRIB_OUTPUT_TEX1 8
#define RGLGCM_ATTRIB_OUTPUT_TEX2 9
#define RGLGCM_ATTRIB_OUTPUT_TEX3 10
#define RGLGCM_ATTRIB_OUTPUT_TEX4 11
#define RGLGCM_ATTRIB_OUTPUT_TEX5 12
#define RGLGCM_ATTRIB_OUTPUT_TEX6 13
#define RGLGCM_ATTRIB_OUTPUT_TEX7 14
// viewport adjusting
#define RGLGCM_SUBPIXEL_ADJUST (0.5/(1<<12))
#define RGLGCM_VIEWPORT_EPSILON 0.0f
// max vertex program constant slots
#define RGLGCM_VTXPRG_MAX_CONST (CELL_GCM_VTXPRG_MAX_CONST)
#define RGLGCM_VTXPRG_MAX_INST (CELL_GCM_VTXPRG_MAX_INST)
#define RGLGCM_HAS_INVALIDATE_TILE
#define RGLGCM_TILED_BUFFER_ALIGNMENT 0x10000 // 64KB
#define RGLGCM_TILED_BUFFER_HEIGHT_ALIGNMENT 64
#define RGLGCM_MAX_TILED_REGIONS 15
#define RGLP_BUFFER_OBJECT_SIZE() (sizeof(rglGcmBufferObject))

View File

@ -0,0 +1,41 @@
void rglGcmFifoFinish(rglGcmFifo *fifo);
GLboolean rglGcmFifoReferenceInUse( rglGcmFifo *fifo, GLuint reference );
GLuint rglGcmFifoPutReference( rglGcmFifo *fifo );
void rglGcmFifoFlush( rglGcmFifo *fifo );
uint32_t * rglGcmFifoWaitForFreeSpace( rglGcmFifo *fifo, GLuint spaceInWords );
void rglGcmGetTileRegionInfo( void* data, GLuint *address, GLuint *size );
GLboolean rglGcmTryResizeTileRegion( GLuint address, GLuint size, void* data );
void rglGcmTransferData
(
GLuint dstId,
GLuint dstIdOffset,
GLint dstPitch,
GLuint srcId,
GLuint srcIdOffset,
GLint srcPitch,
GLint bytesPerRow,
GLint rowCount
);
int32_t rglOutOfSpaceCallback( struct CellGcmContextData* fifoContext, uint32_t spaceInWords );
void rglGcmFifoGlSetRenderTarget( rglGcmRenderTargetEx const * const args );
void rglpFifoGlFinish( void );
void rglCreatePushBuffer( _CGprogram *program );
void rglSetDefaultValuesFP( _CGprogram *program );
void rglSetDefaultValuesVP( _CGprogram *program );
void rglGcmSend( unsigned int dstId, unsigned dstOffset, unsigned int pitch, const char *src, unsigned int size );
void rglGcmMemcpy( const GLuint dstId, unsigned dstOffset, unsigned int pitch, const GLuint srcId, GLuint srcOffset, unsigned int size );
void rglPlatformValidateTextureResources( rglTexture *texture );
GLuint rglGetGcmImageOffset( rglGcmTextureLayout *layout, GLuint face, GLuint level );
void rglSetNativeCgFragmentProgram( const GLvoid *header );
void rglGcmFreeTiledSurface( GLuint bufferId );
void rglGcmCopySurface(
const rglGcmSurface* src,
GLuint srcX, GLuint srcY,
const rglGcmSurface* dst,
GLuint dstX, GLuint dstY,
GLuint width, GLuint height,
GLboolean writeSync);
void rglSetNativeCgVertexProgram( const void *header );

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,490 @@
#include "../../../include/export/RGL/rgl.h"
#include "../../../include/RGL/Types.h"
using namespace cell::Gcm;
typedef struct _tagMODESTRUC
{
GLushort wHorizVisible;
GLushort wVertVisible;
GLushort wInterlacedMode;
GLushort wRefresh;
GLushort wHorizTotal;
GLushort wHorizBlankStart;
GLushort wHorizSyncStart;
GLushort wHorizSyncEnd;
GLushort wHorizBlankEnd;
GLushort wVertTotal;
GLushort wVertBlankStart;
GLushort wVertSyncStart;
GLushort wVertSyncEnd;
GLushort wVertBlankEnd;
GLuint dwDotClock; // In 10K Hertz
GLushort wHSyncPolarity;
GLushort wVSyncPolarity;
} MODESTRUC;
// descriptor for 2D data
typedef struct
{
GLenum source; // device, texture, renderbuffer
GLuint width, height;
GLuint bpp; // bytes per pixel, derived from format
GLuint pitch; // 0 if swizzled
rglGcmEnum format; // e.g. RGLGCM_ARGB8
GLenum pool; // type of memory
char* ppuData; // generic EA that's not RSX mem
GLuint dataId; // id to get address and offset
GLuint dataIdOffset;
} rglGcmSurface;
// gleSetRenderTarget has enough arguments to define its own struct
typedef struct rglGcmRenderTargetEx rglGcmRenderTargetEx;
struct rglGcmRenderTargetEx
{
// color buffers
rglGcmEnum colorFormat;
GLuint colorBufferCount;
GLuint colorId[RGLGCM_SETRENDERTARGET_MAXCOUNT];
GLuint colorIdOffset[RGLGCM_SETRENDERTARGET_MAXCOUNT];
GLuint colorPitch[RGLGCM_SETRENDERTARGET_MAXCOUNT];
// (0,0) is in the lower left
GLboolean yInverted;
// window offset
GLuint xOffset;
GLuint yOffset;
// render dimensions
GLuint width;
GLuint height;
};
typedef struct
{
// TODO: get rid of this member
rglGcmRenderTargetEx rt;
// framebuffers
rglGcmSurface color[3];
// double/triple buffering management
GLuint drawBuffer; // 0, 1, or 2
GLuint scanBuffer; // 0, 1, or 2
// resc buffers (maintain pointers for freeing in rglPlatformDestroyDevice)
GLuint RescColorBuffersId;
GLuint RescVertexArrayId;
GLuint RescFragmentShaderId;
const MODESTRUC *ms;
GLboolean vsync;
GLboolean skipFirstVsync;
GLenum deviceType;
GLenum TVStandard;
GLenum TVFormat;
GLuint swapFifoRef;
GLuint swapFifoRef2; // Added for supporting Triple buffering [RSTENSON]
GLboolean setOffset;
GLboolean signal;
GLuint semaValue;
unsigned int syncMethod;
} rglGcmDevice;
typedef struct rglGcmDriver_
{
rglGcmRenderTargetEx rt;
GLboolean rtValid;
GLboolean invalidateVertexCache;
int xSuperSampling; // supersampling factor in X
int ySuperSampling; // supersampling factor in Y
GLuint flushBufferCount; // # of mapped buffer objects in bounce buffer
GLuint fpLoadProgramId; // address of the currently bound fragment program
GLuint fpLoadProgramOffset;
GLuint sharedFPConstantsId;
char *sharedVPConstants;
} rglGcmDriver;
struct rglPlatformFramebuffer: public rglFramebuffer
{
rglGcmRenderTargetEx rt;
GLboolean complete;
rglPlatformFramebuffer(): rglFramebuffer()
{
memset( &rt, 0, sizeof( rt ) );
};
virtual ~rglPlatformFramebuffer() {};
void validate( PSGLcontext *LContext );
};
typedef struct
{
GLuint SET_TEXTURE_CONTROL3; // pitch and depth
GLuint SET_TEXTURE_OFFSET; // gpu addr (from dma ctx)
GLuint SET_TEXTURE_FORMAT; // which dma ctx, [123]D, border source, mem layout, mip levels
GLuint SET_TEXTURE_ADDRESS; // wrap, signed and unsigned remap control, gamma, zfunc
GLuint SET_TEXTURE_CONTROL0; // enable, lod clamp, aniso, image field, alpha kill, colorkey
GLuint SET_TEXTURE_CONTROL1; // remap and crossbar setup.
GLuint SET_TEXTURE_FILTER; // lod bias, convol filter, min/mag filter, component signedness
GLuint SET_TEXTURE_IMAGE_RECT; // texture width/height
} rglGcmTextureMethods;
// Gcm Specific function parameter mappings.
// for cellGcmSetControl
struct rglGcmTextureControl0
{
GLuint minLOD;
GLuint maxLOD;
GLuint maxAniso;
};
// for cellGcmSetAddress
struct rglGcmTextureAddress
{
GLuint wrapS;
GLuint wrapT;
GLuint wrapR;
GLuint unsignedRemap;
GLuint zfunc;
GLuint gamma;
};
// for cellGcmSetTextureFilter
struct rglGcmTextureFilter
{
GLuint min;
GLuint mag;
GLuint conv;
GLint bias;
};
// Structure to contain Gcm Function Parameters for setting later.
// Control1 and Control3 will be set by cellGcmSetTexture
struct rglGcmTextureMethodParams
{
rglGcmTextureControl0 control0;
rglGcmTextureAddress address;
rglGcmTextureFilter filter;
GLuint borderColor; // texture border color
};
typedef struct
{
// These are enough to describe the GPU format
GLuint faces;
GLuint levels;
GLuint baseWidth;
GLuint baseHeight;
GLuint baseDepth;
rglGcmEnum internalFormat;
GLuint pixelBits;
GLuint pitch;
} rglGcmTextureLayout;
// GCM texture data structure
typedef struct
{
GLenum pool;
rglGcmTextureMethods methods; // [RSTENSON] soon to be legacy
rglGcmTextureMethodParams gcmMethods;
CellGcmTexture gcmTexture;
GLuint gpuAddressId;
GLuint gpuAddressIdOffset;
GLuint gpuSize;
rglGcmTextureLayout gpuLayout;
} rglGcmTexture;
/* pio flow control data structure */
typedef volatile struct
{
GLuint Ignored00[0x010];
GLuint Put; /* put offset, write only 0040-0043*/
GLuint Get; /* get offset, read only 0044-0047*/
GLuint Reference; /* reference value, read only 0048-004b*/
GLuint Ignored01[0x1];
GLuint SetReference; /* set reference value 0050-0053*/
GLuint TopLevelGet; /* top level get offset, read only 0054-0057*/
GLuint Ignored02[0x2];
GLuint SetContextDmaSemaphore; /* set sema ctxdma, write only 0060-0063*/
GLuint SetSemaphoreOffset; /* set sema offset, write only 0064-0067*/
GLuint SetSemaphoreAcquire; /* set sema acquire, write only 0068-006b*/
GLuint SetSemaphoreRelease; /* set sema release, write only 006c-006f*/
GLuint Ignored03[0x7e4];
} rglGcmControlDma;
// all fifo related data is kept here
struct rglGcmFifo: public CellGcmContextData
{
// dmaControl for allocated channel
rglGcmControlDma *dmaControl;
// for storing the start of the push buffer
// begin will be moving around
uint32_t *dmaPushBufferBegin;
uint32_t *dmaPushBufferEnd;
// Fifo block size
GLuint fifoBlockSize;
// pushbuffer location etc.
// members around here were moved up
unsigned long dmaPushBufferOffset;
GLuint dmaPushBufferSizeInWords;
// the last Put value we wrote
uint32_t *lastPutWritten;
// the last Get value we know of
uint32_t *lastGetRead;
// cached value of last reference write
GLuint lastSWReferenceWritten;
// cached value of lastSWReferenceWritten at most
// recent fifo flush
GLuint lastSWReferenceFlushed;
// cached value of last reference read
GLuint lastHWReferenceRead;
uint32_t *dmaPushBufferGPU;
int spuid;
public:
inline void updateLastGetRead()
{
uint32_t* tmp = (uint32_t*)(( char* )dmaPushBufferBegin - dmaPushBufferOffset + ( *(( volatile GLuint* ) & dmaControl->Get ) ) );
// _only_ update lastGetRead if the Get is in our pushbuffer
if (( tmp >= begin ) && ( tmp <= end ) ) lastGetRead = tmp;
}
};
typedef volatile struct
{
struct
{
GLuint nanoseconds[2]; /* nanoseconds since Jan. 1, 1970 0- 7*/
}
timeStamp; /* -0007*/
GLuint value; /* info returned depends on method 0008-000b*/
GLuint zero; /* always written to zero 000c-000f*/
}
rglGcmGetReport;
/* memory data structures */
typedef volatile struct
{
struct
{ /* 0000- */
GLuint nanoseconds[2]; /* nanoseconds since Jan. 1, 1970 0- 7*/
}
timeStamp; /* -0007*/
GLuint info32; /* info returned depends on method 0008-000b*/
GLushort info16; /* info returned depends on method 000c-000d*/
GLushort status; /* user sets bit 15, NV sets status 000e-000f*/
}
rglGcmNotification;
// notifiers in host memory
struct rglGcmHostNotifierMemory
{
// signals channel errors
rglGcmNotification channelDmaError[2];
};
// 16 byte aligned semaphores
struct rglGcmSemaphore
{
GLuint val;
GLuint pad0;
GLuint pad1;
GLuint pad2;
};
// semaphore storage
struct rglGcmSemaphoreMemory
{
rglGcmSemaphore userSemaphores[RGLGCM_MAX_USER_SEMAPHORES];
};
struct rglGcmResource
{
char *localAddress;
GLuint localSize;
GLuint MemoryClock;
GLuint GraphicsClock;
unsigned long long ioifMappings[32];
char * linearMemory;
unsigned int persistentMemorySize;
// host memory window the gpu can access
char * hostMemoryBase;
GLuint hostMemorySize;
GLuint hostMemoryReserved;
// offset of dmaPushBuffer relative to its DMA CONTEXT
unsigned long dmaPushBufferOffset;
char * dmaPushBuffer;
GLuint dmaPushBufferSize;
void* dmaControl;
// all kind of notifers
rglGcmHostNotifierMemory *hostNotifierBuffer;
// semaphores
rglGcmSemaphoreMemory *semaphores;
};
typedef struct
{
GLuint fence;
}
rglGcmFenceObject;
typedef struct
{
GLint sema; // NV semaphore index
}
rglGcmEventObject;
typedef struct
{
GLenum pool; // LINEAR, SYSTEM, or NONE
unsigned int bufferId; // allocated Id
unsigned int bufferSize;
unsigned int pitch;
GLuint mapCount; // map reference count
GLenum mapAccess; // READ_ONLY, WRITE_ONLY, or READ_WRITE
}
rglGcmBufferObject;
typedef struct rglGcmShader_
{
GLuint loadAddressId;
CgBinaryProgram __attribute__(( aligned( 16 ) ) ) program;
} rglGcmShader;
// the current rendering surface/target
typedef struct rglGcmRenderTarget rglGcmRenderTarget;
struct rglGcmRenderTarget
{
GLuint colorFormat;
GLuint colorBufferCount;
// (0,0) is in the lower left
GLuint yInverted;
// gcm render target structure [RSTENSON]
CellGcmSurface gcmRenderTarget;
};
// cached state: texture
typedef struct rglGcmTextureState rglGcmTextureState;
struct rglGcmTextureState
{
// unforunately to many pieces of state have been put into single
// 32bit registers -- so we need to cache some of them...
GLuint hwTexAddress;
GLuint hwTexFilter;
GLuint hwTexControl0;
//GLuint hwTexCoordCtrl;
};
// cached state: viewport
typedef struct rglGcmViewportState rglGcmViewportState;
struct rglGcmViewportState
{
// user values given as input to glViewport
GLint x, y, w, h;
// from glViewport
GLfloat xScale, xCenter;
GLfloat yScale, yCenter;
};
// cached state: blend
typedef struct rglGcmBlendState rglGcmBlendState;
struct rglGcmBlendState
{
// current blend color
GLfloat r, g, b, a;
// alpha blend reference
GLuint alphaFunc;
GLfloat alphaRef;
};
typedef struct rglGcmInterpolantState rglGcmInterpolantState;
struct rglGcmInterpolantState
{
// mask of inputs used by programs
// Uses bits from SET_VERTEX_ATTRIB_OUTPUT_MASK.
GLuint vertexProgramAttribMask;
GLuint fragmentProgramAttribMask;
};
// cached state (because no dedecated method exist)
typedef struct rglGcmCachedState rglGcmCachedState;
struct rglGcmCachedState
{
// our hw<->ogl mapping is ...let's say strange...
//rglGcmTextureState tex[RGLGCM_MAX_TEXIMAGE_COUNT];
//[RSTENSON] Removing this above. Texturing is all GCM now.
// we need to track blending color, too
rglGcmBlendState blend;
// need to cache viewport values, because of yInverted
rglGcmViewportState viewport;
// all interpolants are enabled/disabled with a single mask
rglGcmInterpolantState interpolant;
};
// ** the master instance representing a channel/context **
struct rglGcmState
{
char *localAddress;
// host memory window the gpu can access
void *hostMemoryBase;
GLuint hostMemorySize;
// all kind of notifers
rglGcmHostNotifierMemory *hostNotifierBuffer;
// semaphores
rglGcmSemaphoreMemory *semaphores;
// -- context state --
// fifo
rglGcmFifo fifo;
// rendering target
rglGcmRenderTarget renderTarget;
// state
rglGcmCachedState state;
// Cell Gcm Config
CellGcmConfig config;
// to use as the back end label value when syncing before cellGcmSetTile, SetZCull, and SetInvalidateTile.
GLuint labelValue;
};
extern rglGcmState rglGcmState_i;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,522 @@
/* RetroArch - A frontend for libretro.
* RGL - An OpenGL subset wrapper library.
* Copyright (C) 2012 - Hans-Kristian Arntzen
* Copyright (C) 2012 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../rgl_cg.h"
CGbool rglpSupportsVertexProgram( CGprofile p )
{
if ( p == CG_PROFILE_SCE_VP_TYPEB )
return CG_TRUE;
if ( p == CG_PROFILE_SCE_VP_TYPEC )
return CG_TRUE;
if ( p == CG_PROFILE_SCE_VP_RSX )
return CG_TRUE;
return CG_FALSE;
}
CGbool rglpSupportsFragmentProgram( CGprofile p )
{
if ( p == CG_PROFILE_SCE_FP_TYPEB )
return CG_TRUE;
if ( CG_PROFILE_SCE_FP_RSX == p )
return CG_TRUE;
return CG_FALSE;
}
CGprofile rglpGetLatestProfile( CGGLenum profile_type )
{
switch ( profile_type )
{
case CG_GL_VERTEX:
return CG_PROFILE_SCE_VP_RSX;
case CG_GL_FRAGMENT:
return CG_PROFILE_SCE_FP_RSX;
default:
break;
}
return CG_PROFILE_UNKNOWN;
}
// uploads the given fp shader to gpu memory. Allocates if needed.
// This also builds the shared constants push buffer if needed, since it depends on the load address
static int rglpsLoadFPShader( _CGprogram *program )
{
unsigned int ucodeSize = program->header.instructionCount * 16;
if ( program->loadProgramId == GMM_ERROR )
{
program->loadProgramId = gmmAlloc((CellGcmContextData*)&rglGcmState_i.fifo,
CELL_GCM_LOCATION_LOCAL, 0, ucodeSize);
program->loadProgramOffset = 0;
}
// always upload shader
rglGcmSend( program->loadProgramId, program->loadProgramOffset, 0, ( char* )program->ucode, ucodeSize );
return GL_TRUE;
}
static void rglpsUnloadFPShader(_CGprogram *program)
{
if ( program->loadProgramId != GMM_ERROR )
{
gmmFree( program->loadProgramId );
program->loadProgramId = GMM_ERROR;
program->loadProgramOffset = 0;
}
}
//new binary addition
int rglGcmGenerateProgram( _CGprogram *program, int profileIndex, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader,
const CgParameterEntry *parameterEntries, const char *stringTable, const float *defaultValues )
{
// validate the input
CGprofile profile = ( CGprofile )programHeader->profile;
int need_swapping = 0;
//hack to counter removal of TypeC during beta
if ( profile == ( CGprofile )7005 )
profile = CG_PROFILE_SCE_VP_RSX;
if ( profile == ( CGprofile )7006 )
profile = CG_PROFILE_SCE_FP_RSX;
// if can't match a known profile, the data may be in wrong endianness
if (( profile != CG_PROFILE_SCE_FP_TYPEB ) && ( profile != CG_PROFILE_SCE_VP_TYPEB ) &&
( profile != CG_PROFILE_SCE_FP_RSX ) && ( profile != CG_PROFILE_SCE_VP_RSX ) )
{
need_swapping = 1;
}
// check that this program block is of the right revision
// i.e. that the cgBinary.h header hasn't changed since it was
// compiled.
// validate the profile
int invalidProfile = 0;
switch ( ENDIAN_32( profile, need_swapping ) )
{
case CG_PROFILE_SCE_VP_TYPEB:
if ( profileIndex != VERTEX_PROFILE_INDEX ) invalidProfile = 1;
break;
case CG_PROFILE_SCE_FP_TYPEB:
if ( profileIndex != FRAGMENT_PROFILE_INDEX ) invalidProfile = 1;
break;
case CG_PROFILE_SCE_VP_RSX:
if ( profileIndex != VERTEX_PROFILE_INDEX ) invalidProfile = 1;
break;
case CG_PROFILE_SCE_FP_RSX:
if ( profileIndex != FRAGMENT_PROFILE_INDEX ) invalidProfile = 1;
break;
default:
invalidProfile = 1;
break;
}
if ( invalidProfile )
{
rglCgRaiseError( CG_UNKNOWN_PROFILE_ERROR );
return 0;
}
memcpy( &program->header, programHeader, sizeof( program->header ) );
program->ucode = ucode;
program->loadProgramId = GMM_ERROR;
program->loadProgramOffset = 0;
program->inLocalMemory = true;
size_t parameterSize = parameterHeader->entryCount * sizeof( CgRuntimeParameter );
void *memoryBlock;
if ( parameterSize )
memoryBlock = memalign( 16, parameterSize );
else
memoryBlock = NULL;
program->rtParametersCount = parameterHeader->entryCount;
program->runtimeParameters = ( CgRuntimeParameter* )memoryBlock;
if ( parameterEntries == NULL ) // the param entry can be supplied if not right after parameterHeader in memory, it happens when there's a program copy
parameterEntries = ( CgParameterEntry* )( parameterHeader + 1 );
program->parametersEntries = parameterEntries;
program->parameterResources = ( char* )( program->parametersEntries + program->rtParametersCount );
program->resources = ( unsigned short* )(( char* )program->parametersEntries + ( parameterHeader->resourceTableOffset - sizeof( CgParameterTableHeader ) ) );
program->defaultValuesIndexCount = parameterHeader->defaultValueIndexCount;
program->defaultValuesIndices = ( CgParameterDefaultValue* )(( char* )program->parametersEntries + ( parameterHeader->defaultValueIndexTableOffset - sizeof( CgParameterTableHeader ) ) );
program->semanticCount = parameterHeader->semanticIndexCount;
program->semanticIndices = ( CgParameterSemantic* )( program->defaultValuesIndices + program->defaultValuesIndexCount );
program->defaultValues = NULL;
memset( program->runtimeParameters, 0, parameterHeader->entryCount*sizeof( CgRuntimeParameter ) );
//string table
program->stringTable = stringTable;
//default values
program->defaultValues = defaultValues;
rglCreatePushBuffer( program );
if ( profileIndex == FRAGMENT_PROFILE_INDEX )
rglSetDefaultValuesFP( program ); // modifies the ucode
else
rglSetDefaultValuesVP( program ); // modifies the push buffer
// not loaded yet
program->loadProgramId = GMM_ERROR;
program->loadProgramOffset = 0;
if ( profileIndex == FRAGMENT_PROFILE_INDEX )
{
// always load fragment shaders.
int loaded = rglpsLoadFPShader( program );
if ( ! loaded )
{
//TODO: what do we need to delete here ?
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return 0;
}
}
program->programGroup = NULL;
program->programIndexInGroup = -1;
return 1;
}
CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refcount )
{
if ( index < ( int )group->programCount )
{
//index can be < 0 , in that case refcount update on the group only, used when destroying a copied program
if ( index >= 0 )
{
//if it has already been referenced duplicate instead of returning the same index, until the API offer a native support for
//group of programs ( //fixed bug 13007 )
if ( refcount == 1 && group->programs[index].refCount == 1 )
{
//it will handle the refcounting
CGprogram res = cgCopyProgram( group->programs[index].program );
return res;
}
group->programs[index].refCount += refcount;
}
group->refCount += refcount;
if ( refcount < 0 )
{
if ( group->refCount == 0 && !group->userCreated )
{
rglCgDestroyProgramGroup( group );
}
return NULL;
}
else
return group->programs[index].program;
}
else
return NULL;
}
//add the group to the context:
static void rglCgAddGroup( CGcontext ctx, CGprogramGroup group )
{
_CGcontext *context = _cgGetContextPtr( ctx );
if ( !context->groupList )
context->groupList = group;
else
{
_CGprogramGroup *current = context->groupList;
while ( current->next )
current = current->next;
current->next = group;
}
}
static void rglCgRemoveGroup( CGcontext ctx, CGprogramGroup group )
{
_CGcontext *context = _cgGetContextPtr( ctx );
_CGprogramGroup *current = context->groupList;
_CGprogramGroup *previous = NULL;
while ( current && current != group )
{
previous = current;
current = current->next;
}
if ( current )
{
if ( !previous )
context->groupList = current->next;
else
previous->next = current->next;
}
}
CGprogramGroup rglCgCreateProgramGroupFromFile( CGcontext ctx, const char *group_file )
{
// check that file exists
FILE* fp = fopen( group_file, "rb" );
if ( NULL == fp )
{
rglCgRaiseError( CG_FILE_READ_ERROR );
return ( CGprogramGroup )NULL;
}
// find the file length
size_t file_size = 0;
fseek( fp, 0, SEEK_END );
file_size = ftell( fp );
rewind( fp );
// alloc memory for new binary program and read the data
char* ptr = ( char* )malloc( file_size + 1 );
if ( NULL == ptr )
{
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return ( CGprogramGroup )NULL;
}
// read the entire file into memory then close the file
// TODO ********* just loading the file is a bit lame really. We can do better.
fread( ptr, file_size, 1, fp );
fclose( fp );
CGprogramGroup group = rglCgCreateProgramGroup( ctx, group_file, ptr, file_size );
if ( !group )
free( ptr );
return group;
}
CGprogramGroup rglCgCreateProgramGroup( CGcontext ctx, const char *name, void *ptr, int size )
{
_CGprogramGroup *group = NULL;
CGELFBinary elfBinary;
elfBinary.elfFile = NULL;
while ( 1 )
{
bool res = cgOpenElf( ptr, size, &elfBinary );
if ( !res )
break;
size_t elfConstTableSize = ( size_t )elfBinary.consttabSize;
size_t elfStringTableSize = ( size_t )elfBinary.strtabSize;
//first pass to get the size of each item ( could be faster if the embedded constants index table size was in the header
int programCount = elfBinary.shadertabSize / sizeof( CgProgramHeader );
int i;
//structure of the memory buffer storing the group
size_t nvProgramNamesOffset = rglPad( sizeof( _CGprogramGroup ), sizeof( _CGnamedProgram ) ); //program name offset
size_t nvDefaultValuesTableOffset = rglPad( nvProgramNamesOffset + programCount * sizeof( _CGnamedProgram ), 16 );//shared default value table
size_t nvStringTableOffset = nvDefaultValuesTableOffset + elfConstTableSize; //shared string table
size_t structureSize = nvStringTableOffset + elfStringTableSize;//total structure size
//create the program group
group = ( CGprogramGroup )malloc( structureSize );
if ( !group ) //out of memory
break;
//fill the group structure
group->ctx = ctx;
group->next = NULL;
group->programCount = ( unsigned int )programCount;
group->constantTable = ( unsigned int * )(( char* )group + nvDefaultValuesTableOffset );
group->stringTable = ( unsigned int * )(( char* )group + nvStringTableOffset );
group->programs = ( _CGnamedProgram * )(( char* )group + nvProgramNamesOffset );
group->userCreated = true;
group->refCount = 0;
group->filedata = ( char* )ptr;
if ( name )
{
int len = strlen( name );
group->name = ( char* )malloc( len + 1 );
if ( !group->name )//out of memory
break;
strcpy( group->name, name );
}
else
group->name = NULL;
//copy the default values
if ( elfConstTableSize )
memcpy(( char* )group + nvDefaultValuesTableOffset, elfBinary.consttab, elfConstTableSize );
//copy the string table
if ( elfStringTableSize )
memcpy(( char* )group + nvStringTableOffset, elfBinary.strtab, elfStringTableSize );
//add the group to the context:
rglCgAddGroup( ctx, group );
//create all the shaders contained in the package and add them to the group
for ( i = 0;i < ( int )group->programCount;i++ )
{
CgProgramHeader *cgShader = ( CgProgramHeader* )elfBinary.shadertab + i;
//hack to counter removal of TypeC during beta
if ( cgShader->profile == ( CGprofile )7005 )
cgShader->profile = CG_PROFILE_SCE_VP_RSX;
if ( cgShader->profile == ( CGprofile )7006 )
cgShader->profile = CG_PROFILE_SCE_FP_RSX;
CGELFProgram elfProgram;
bool res = cgGetElfProgramByIndex( &elfBinary, i, &elfProgram );
if ( !res )
return false;
//I reference the buffer passed as parameter here, so it will have to stay around
CgProgramHeader *programHeader = cgShader;
char *ucode = ( char * )elfProgram.texttab;
CgParameterTableHeader *parameterHeader = ( CgParameterTableHeader * )elfProgram.paramtab;
const char *programName = getSymbolByIndexInPlace( elfBinary.symtab, elfBinary.symbolSize, elfBinary.symbolCount, elfBinary.symbolstrtab, i + 1 );
group->programs[i].name = programName;
group->programs[i].program = rglCgCreateProgram( ctx, ( CGprofile )cgShader->profile, programHeader, ucode, parameterHeader, ( const char* )group->stringTable, ( const float* )group->constantTable );
_CGprogram *cgProgram = _cgGetProgPtr( group->programs[i].program );
cgProgram->programGroup = group;
cgProgram->programIndexInGroup = i;
group->programs[i].refCount = 0;
}
break;
}
return group;
}
void rglCgDestroyProgramGroup( CGprogramGroup group )
{
_CGprogramGroup *_group = ( _CGprogramGroup * )group;
for ( int i = 0;i < ( int )_group->programCount;i++ )
{
//unlink the program
_CGprogram *cgProgram = _cgGetProgPtr( group->programs[i].program );
cgProgram->programGroup = NULL;
cgDestroyProgram( _group->programs[i].program );
}
free( _group->filedata );
if ( _group->name )
free( _group->name );
//remove the group from the group list
rglCgRemoveGroup( group->ctx, group );
free( _group );
}
const char *rglCgGetProgramGroupName( CGprogramGroup group )
{
_CGprogramGroup *_group = ( _CGprogramGroup * )group;
return _group->name;
}
int rglCgGetProgramIndex( CGprogramGroup group, const char *name )
{
int i;
for ( i = 0;i < ( int )group->programCount;i++ )
{
if ( !strcmp( name, group->programs[i].name ) )
return i;
}
return -1;
}
void rglpProgramErase( _CGprogram* platformProgram )
{
_CGprogram* program = ( _CGprogram* )platformProgram;
if ( program->loadProgramId != GMM_ERROR )
rglpsUnloadFPShader( program );
//free the runtime parameters
if ( program->runtimeParameters )
{
//need to erase all the program parameter "names"
int i;
int count = ( int )program->rtParametersCount;
for ( i = 0; i < count;i++ )
rglEraseName( &_CurrentContext->cgParameterNameSpace, (unsigned int)program->runtimeParameters[i].id );
free( program->runtimeParameters );
}
//free the push buffer block
if ( program->memoryBlock )
free( program->memoryBlock );
//free the samplers lookup tables
if ( program->samplerIndices )
{
free( program->samplerValuesLocation );
free( program->samplerIndices );
free( program->samplerUnits );
}
//free the "pointers" on the push buffer used for fast access
if ( program->constantPushBufferPointers )
free( program->constantPushBufferPointers );
}
//TODO: use a ref mechanism for the string table or duplicate it !
int rglpCopyProgram( _CGprogram* source, _CGprogram* destination )
{
//extract the layout of the parameter buffers from the source
CgParameterTableHeader parameterHeader;
parameterHeader.entryCount = source->rtParametersCount;
parameterHeader.resourceTableOffset = ( uintptr_t )(( char* )source->resources - ( char* )source->parametersEntries + sizeof( CgParameterTableHeader ) );
parameterHeader.defaultValueIndexCount = source->defaultValuesIndexCount;
parameterHeader.defaultValueIndexTableOffset = ( uintptr_t )(( char* )source->defaultValuesIndices - ( char* )source->parametersEntries + sizeof( CgParameterTableHeader ) );
parameterHeader.semanticIndexCount = source->semanticCount;
parameterHeader.semanticIndexTableOffset = ( uintptr_t )(( char* )source->defaultValuesIndices - ( char* )source->parametersEntries + sizeof( CgParameterTableHeader ) );
int profileIndex;
//allocate the copy of the program
switch ( source->header.profile )
{
case CG_PROFILE_SCE_VP_TYPEB:
case CG_PROFILE_SCE_VP_RSX:
profileIndex = VERTEX_PROFILE_INDEX;
break;
case CG_PROFILE_SCE_FP_TYPEB:
case CG_PROFILE_SCE_FP_RSX:
profileIndex = FRAGMENT_PROFILE_INDEX;
break;
default:
return 0;
}
return rglGcmGenerateProgram( destination, profileIndex, &source->header, source->ucode, &parameterHeader, source->parametersEntries, source->stringTable, source->defaultValues );
}
int rglpGenerateVertexProgram( _CGprogram *program,
const CgProgramHeader *programHeader, const void *ucode,
const CgParameterTableHeader *parameterHeader, const char *stringTable,
const float *defaultValues )
{
// we currently have the same interface for vertex and fragment programs.
return rglGcmGenerateProgram( program, VERTEX_PROFILE_INDEX, programHeader,
ucode, parameterHeader, NULL, stringTable, defaultValues );
}
int rglpGenerateFragmentProgram( _CGprogram *program, const CgProgramHeader *programHeader, const void *ucode,
const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues )
{
// we currently have the same interface for vertex and fragment programs.
return rglGcmGenerateProgram( program, FRAGMENT_PROFILE_INDEX, programHeader, ucode, parameterHeader, NULL, stringTable, defaultValues );
}

File diff suppressed because it is too large Load Diff

1986
console/rgl/src/rgl.cpp Normal file

File diff suppressed because it is too large Load Diff

39
console/rgl/src/rgl.h Normal file
View File

@ -0,0 +1,39 @@
/* RetroArch - A frontend for libretro.
* RGL - An OpenGL subset wrapper library.
* Copyright (C) 2012 - Hans-Kristian Arntzen
* Copyright (C) 2012 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _RGL_H
#define _RGL_H
#include "../include/export/RGL/rgl.h"
#include "../include/RGL/Types.h"
#include "../include/RGL/TypeUtils.h"
#include "../include/RGL/private.h"
#include "../include/RGL/Utils.h"
#include <string.h>
#include <math.h>
#include <limits.h>
#include <Cg/CgCommon.h>
void rglPsglPlatformInit( RGLinitOptions* options );
void rglPsglPlatformExit(void);
RGL_EXPORT RGLdevice* rglPlatformCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode );
RGL_EXPORT RGLdevice* rglPlatformCreateDeviceExtended( const RGLdeviceParameters *parameters );
RGL_EXPORT GLfloat rglPlatformGetDeviceAspectRatio( const RGLdevice * device );
#endif

9787
console/rgl/src/rgl_cg.cpp Normal file

File diff suppressed because it is too large Load Diff

105
console/rgl/src/rgl_cg.h Normal file
View File

@ -0,0 +1,105 @@
/* RetroArch - A frontend for libretro.
* RGL - An OpenGL subset wrapper library.
* Copyright (C) 2012 - Hans-Kristian Arntzen
* Copyright (C) 2012 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _RGL_CG_H
#define _RGL_CG_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <Cg/CgCommon.h>
#include <Cg/cgBinary.h>
#include <Cg/CgInternal.h>
#include <Cg/CgProgramGroup.h>
#include <Cg/cgc.h>
#include "../include/export/RGL/rgl.h"
#include "../include/RGL/private.h"
#include "../include/RGL/Types.h"
#include "../include/RGL/Utils.h"
#include "libelf/readelf.h"
#include "cg/cgbtypes.h"
#include "cg/cgnv2rt.h"
#include "cg/cgnv2elfversion.h"
#include "cg/cgbio.hpp"
#include "cg/cgbiimpl.hpp"
#include "cg/cgboimpl.hpp"
#include "cg/nvbiimpl.hpp"
#include "cg/nvboimpl.hpp"
#include "cg/cgbutils.hpp"
#include "cg/cgbtypes.h"
typedef struct
{
const char* elfFile;
size_t elfFileSize;
const char *symtab;
size_t symbolSize;
size_t symbolCount;
const char *symbolstrtab;
const char* shadertab;
size_t shadertabSize;
const char* strtab;
size_t strtabSize;
const char* consttab;
size_t consttabSize;
} CGELFBinary;
typedef struct
{
const char *texttab;
size_t texttabSize;
const char *paramtab;
size_t paramtabSize;
int index;
} CGELFProgram;
extern CGbool rglpSupportsVertexProgram( CGprofile p );
extern CGbool rglpSupportsFragmentProgram( CGprofile p );
extern CGprofile rglpGetLatestProfile( CGGLenum profile_type );
extern int rglpCopyProgram( _CGprogram* source, _CGprogram* destination );
extern int rglpGenerateFragmentProgram( _CGprogram *program,
const CgProgramHeader *programHeader, const void *ucode,
const CgParameterTableHeader *parameterHeader,
const char *stringTable, const float *defaultValues );
extern int rglpGenerateVertexProgram( _CGprogram *program,
const CgProgramHeader *programHeader, const void *ucode,
const CgParameterTableHeader *parameterHeader, const char *stringTable,
const float *defaultValues );
extern CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index,
int refcount );
extern void rglpProgramErase( _CGprogram* prog );
extern bool cgOpenElf( const void *ptr, size_t size, CGELFBinary *elfBinary );
extern bool cgGetElfProgramByIndex( CGELFBinary *elfBinary, int index, CGELFProgram *elfProgram );
extern CGprogram rglCgCreateProgram( CGcontext ctx, CGprofile profile, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues );
#endif

34
console/rgl/src/rglp.h Normal file
View File

@ -0,0 +1,34 @@
/* RetroArch - A frontend for libretro.
* RGL - An OpenGL subset wrapper library.
* Copyright (C) 2012 - Hans-Kristian Arntzen
* Copyright (C) 2012 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _RGLP_H_
#define _RGLP_H_
#if defined(__CELLOS_LV2__)
#include "ps3/include/rgl-constants.h"
#endif
extern void rglpValidateViewport(void);
extern void rglpValidateBlending(void);
extern void rglpValidateShaderSRGBRemap(void);
extern int rglpBufferObjectSize(void);
extern GLboolean rglpCreateBufferObject(rglBufferObject* bufferObject);
void rglpFifoGlFinish( void );
#endif