(RGL) More cleanups, pt. 7
This commit is contained in:
parent
7550a03688
commit
7e426d171b
|
@ -12,54 +12,37 @@
|
|||
#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"
|
||||
{
|
||||
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) (void *, const void* _RGL_RESTRICT);
|
||||
|
||||
typedef void(*_cgSetArrayIndexFunction) (void *, const void*, const int index);
|
||||
|
||||
typedef struct _CgUniform
|
||||
{
|
||||
void *pushBufferPtr;
|
||||
}
|
||||
_CgUniform;
|
||||
} _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;
|
||||
int glType;
|
||||
CGparameter id;
|
||||
} CgRuntimeParameter;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -67,15 +50,13 @@ extern "C"
|
|||
CgRuntimeParameter* parent;
|
||||
CgRuntimeParameter* top;
|
||||
_cgSetArrayIndexFunction childOnBindSetter;
|
||||
}
|
||||
CgParameterConnection;
|
||||
} CgParameterConnection;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CgRuntimeParameter* param;
|
||||
std::vector<char> semantic;
|
||||
}
|
||||
CgRuntimeSemantic;
|
||||
} CgRuntimeSemantic;
|
||||
|
||||
struct _CGprogram
|
||||
{
|
||||
|
@ -168,8 +149,6 @@ extern "C"
|
|||
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;
|
||||
|
@ -184,12 +163,9 @@ extern "C"
|
|||
//"static" variable used to store the values of the last parameter for which getParameterValue has been called
|
||||
double currentParameterValue[16];
|
||||
char currentParameterName[128];
|
||||
}
|
||||
_CGcontext;
|
||||
} _CGcontext;
|
||||
|
||||
|
||||
// prototypes --------------------------------
|
||||
|
||||
// internal error handling
|
||||
RGL_EXPORT void rglCgRaiseError( CGerror error );
|
||||
// interface between object types
|
||||
|
@ -219,7 +195,7 @@ extern "C"
|
|||
#define CG_GETINDEX(param) (int)((unsigned int)(param)>>CG_PARAMETERSIZE)
|
||||
|
||||
|
||||
inline static bool isMatrix( CGtype type )
|
||||
static inline bool isMatrix (CGtype type)
|
||||
{
|
||||
if (( type >= CG_FLOAT1x1 && type <= CG_FLOAT4x4 ) ||
|
||||
( type >= CG_HALF1x1 && type <= CG_HALF4x4 ) ||
|
||||
|
@ -230,7 +206,7 @@ extern "C"
|
|||
return false;
|
||||
}
|
||||
|
||||
inline static bool isSampler( CGtype type )
|
||||
static inline bool isSampler (CGtype type)
|
||||
{
|
||||
return ( type >= CG_SAMPLER1D && type <= CG_SAMPLERCUBE );
|
||||
}
|
||||
|
@ -266,12 +242,7 @@ extern "C"
|
|||
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 )
|
||||
static inline int rglGetSizeofSubArray( const unsigned short *dimensions, unsigned short count )
|
||||
{
|
||||
int res = 1;
|
||||
for (int i = 0;i < count;i++)
|
||||
|
@ -279,7 +250,7 @@ extern "C"
|
|||
return res;
|
||||
}
|
||||
|
||||
inline static CGresource rglGetBaseResource( CGresource resource )
|
||||
static inline CGresource rglGetBaseResource( CGresource resource )
|
||||
{
|
||||
switch ( resource )
|
||||
{
|
||||
|
@ -328,16 +299,14 @@ extern "C"
|
|||
CGprofile rglPlatformGetLatestProfile( CGGLenum profile_type );
|
||||
int rglPlatformCopyProgram( _CGprogram* source, _CGprogram* destination );
|
||||
|
||||
void rglPlatformProgramErase( void* platformProgram );
|
||||
void rglPlatformProgramErase (void *data);
|
||||
|
||||
int rglPlatformGenerateVertexProgram( _CGprogram *program, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues );
|
||||
int rglPlatformGenerateVertexProgram (void *data, 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 );
|
||||
int rglPlatformGenerateFragmentProgram (void *data, 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 );
|
||||
|
@ -348,8 +317,9 @@ extern "C"
|
|||
// names API
|
||||
RGL_EXPORT unsigned int _cgHashString (const char *str);
|
||||
|
||||
inline static void _pullConnectedParameterValues( _CGprogram* ptr )
|
||||
inline static void _pullConnectedParameterValues (void *data)
|
||||
{
|
||||
_CGprogram *ptr = (_CGprogram*)data;
|
||||
// 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();
|
||||
|
@ -361,8 +331,9 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
inline static void _cgGLBindVertexProgram( _CGprogram* program )
|
||||
static inline void _cgGLBindVertexProgram (void *data)
|
||||
{
|
||||
_CGprogram *program = (_CGprogram*)data;
|
||||
// the program is a vertex program, just update the GL state
|
||||
_CurrentContext->BoundVertexProgram = program;
|
||||
|
||||
|
@ -385,8 +356,9 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
inline static void _cgGLBindFragmentProgram( _CGprogram* program )
|
||||
static inline void _cgGLBindFragmentProgram (void *data)
|
||||
{
|
||||
_CGprogram *program = (_CGprogram*)data;
|
||||
_CurrentContext->BoundFragmentProgram = program;
|
||||
|
||||
// need to revalidate the textures in order to update which targets to fetch from
|
||||
|
@ -424,15 +396,15 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
inline static void _cgGLUnbindVertexProgram()
|
||||
static inline void _cgGLUnbindVertexProgram (void)
|
||||
{
|
||||
_CurrentContext->BoundVertexProgram = NULL;
|
||||
_CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM;
|
||||
}
|
||||
|
||||
// XXX this should not be here.
|
||||
inline static void rglLeaveFFXFP( RGLcontext*LContext )
|
||||
static inline void rglLeaveFFXFP (void *data)
|
||||
{
|
||||
RGLcontext *LContext = (RGLcontext*)data;
|
||||
LContext->FragmentProgram = GL_TRUE;
|
||||
struct _CGprogram* current = LContext->BoundFragmentProgram;
|
||||
if ( current )
|
||||
|
@ -446,7 +418,7 @@ extern "C"
|
|||
LContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS;
|
||||
}
|
||||
|
||||
inline static void _cgGLUnbindFragmentProgram()
|
||||
static inline void _cgGLUnbindFragmentProgram (void)
|
||||
{
|
||||
_CurrentContext->BoundFragmentProgram = NULL;
|
||||
}
|
||||
|
@ -479,11 +451,7 @@ extern "C"
|
|||
|
||||
#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
|
||||
|
@ -515,40 +483,42 @@ extern "C"
|
|||
|
||||
//-----------------------------------------------
|
||||
//inlined helper functions
|
||||
static inline int rglGetParameterType( const CGprogram *program, const CgParameterEntry *entry )
|
||||
static inline int rglGetParameterType (const void *data, const CgParameterEntry *entry)
|
||||
{
|
||||
const CGprogram *program = (const CGprogram*)data;
|
||||
return (entry->flags & CGP_TYPE_MASK);
|
||||
}
|
||||
|
||||
static inline const CgParameterResource *rglGetParameterResource( const _CGprogram *program, const CgParameterEntry *entry )
|
||||
static inline const CgParameterResource *rglGetParameterResource (const void *data, const CgParameterEntry *entry )
|
||||
{
|
||||
const _CGprogram *program = (const _CGprogram*)data;
|
||||
return (CgParameterResource *)(program->parameterResources + entry->typeIndex);
|
||||
}
|
||||
|
||||
static inline CGtype rglGetParameterCGtype( const _CGprogram *program, const CgParameterEntry *entry )
|
||||
static inline CGtype rglGetParameterCGtype (const void *data, const CgParameterEntry *entry)
|
||||
{
|
||||
const _CGprogram *program = (const _CGprogram*)data;
|
||||
|
||||
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 )
|
||||
static inline const CgParameterArray *rglGetParameterArray (const void *data, const CgParameterEntry *entry)
|
||||
{
|
||||
const _CGprogram *program = (const _CGprogram*)data;
|
||||
return (CgParameterArray*)(program->parameterResources + entry->typeIndex);
|
||||
}
|
||||
|
||||
static inline const CgParameterStructure *rglGetParameterStructure( const _CGprogram *program, const CgParameterEntry *entry )
|
||||
static inline const CgParameterStructure *rglGetParameterStructure (const void *data, const CgParameterEntry *entry )
|
||||
{
|
||||
const _CGprogram *program = (const _CGprogram*)data;
|
||||
return (CgParameterStructure*)(program->parameterResources + entry->typeIndex);
|
||||
}
|
||||
|
||||
|
@ -563,7 +533,7 @@ extern "C"
|
|||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // Close scope of 'extern "C"' declaration that encloses file.
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue