(RGL) More cleanups, pt. 8

This commit is contained in:
twinaphex 2013-01-05 20:29:38 +01:00
parent 8d0fbe53ab
commit f27e7e4943
9 changed files with 184 additions and 117 deletions

View File

@ -5,6 +5,7 @@ CELL_GPU_TYPE = RSX
DEBUG = 0 DEBUG = 0
STRIPPING_ENABLE = 1 STRIPPING_ENABLE = 1
RGL_2D = 1
PC_DEVELOPMENT_IP_ADDRESS = "192.168.1.7" PC_DEVELOPMENT_IP_ADDRESS = "192.168.1.7"
PC_DEVELOPMENT_UDP_PORT = 3490 PC_DEVELOPMENT_UDP_PORT = 3490
@ -54,6 +55,10 @@ else
PPU_OPTIMIZE_LV := -O3 PPU_OPTIMIZE_LV := -O3
endif endif
ifeq ($(RGL_2D), 1)
PPU_OPTIMIZE_LV += -DHAVE_RGL_2D
endif
PPU_CFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES) PPU_CFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES)
PPU_CXXFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES) PPU_CXXFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES)

View File

@ -13,14 +13,14 @@ typedef struct
const char *s; const char *s;
} RGLenumMap; } RGLenumMap;
const char *rglMapLookupEnum( const RGLenumMap* map, unsigned int count, GLenum e ); const char *rglMapLookupEnum(const void *data, unsigned int count, GLenum e);
GLenum rglMapLookupString( const RGLenumMap* map, unsigned int count, const char *s ); GLenum rglMapLookupString(const void *data, 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_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) #define _RGL_MAP_LOOKUP_STRING(MAP,STRING) rglMapLookupString(MAP,sizeof(MAP)/sizeof(MAP[0]),STRING)
const char *rglGetGLEnumName( GLenum e ); const char *rglGetGLEnumName(GLenum e);
const char *rglGetGLErrorName( GLenum e ); const char *rglGetGLErrorName(GLenum e);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -91,20 +91,22 @@ extern "C" {
RGL_EXPORT unsigned int rglCreateName (void *data, void* object); RGL_EXPORT unsigned int rglCreateName (void *data, void* object);
RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name); RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name);
RGL_EXPORT void rglEraseName (void *data, unsigned int name); RGL_EXPORT void rglEraseName (void *data, unsigned int name);
static inline void * rglGetNamedValue( struct rglNameSpace* ns, unsigned int name )
static inline void *rglGetNamedValue(void *data, unsigned int name )
{ {
struct rglNameSpace *ns = (struct rglNameSpace*)data;
return ns->data[name - 1]; return ns->data[name - 1];
} }
void rglTexNameSpaceInit( rglTexNameSpace *ns, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy ); void rglTexNameSpaceInit(void *data, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy );
void rglTexNameSpaceFree( rglTexNameSpace *ns ); void rglTexNameSpaceFree(void *data);
void rglTexNameSpaceResetNames( rglTexNameSpace *ns ); void rglTexNameSpaceResetNames(void *data);
GLuint rglTexNameSpaceGetFree( rglTexNameSpace *ns ); GLuint rglTexNameSpaceGetFree(void *data);
GLboolean rglTexNameSpaceCreateNameLazy( rglTexNameSpace *ns, GLuint name ); GLboolean rglTexNameSpaceCreateNameLazy(void *data, GLuint name );
GLboolean rglTexNameSpaceIsName( rglTexNameSpace *ns, GLuint name ); GLboolean rglTexNameSpaceIsName(void *data, GLuint name );
void rglTexNameSpaceGenNames( rglTexNameSpace *ns, GLsizei n, GLuint *names ); void rglTexNameSpaceGenNames(void *data, GLsizei n, GLuint *names );
void rglTexNameSpaceDeleteNames( rglTexNameSpace *ns, GLsizei n, const GLuint *names ); void rglTexNameSpaceDeleteNames(void *data, GLsizei n, const GLuint *names );
void rglTexNameSpaceReinit( rglTexNameSpace * saved, rglTexNameSpace * active ); void rglTexNameSpaceReinit(void *saved, void *active);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -41,7 +41,7 @@ extern GLuint rglValidateStates( GLuint mask );
void rglAttachContext( RGLdevice *device, RGLcontext* context ); void rglAttachContext( RGLdevice *device, RGLcontext* context );
void rglDetachContext( RGLdevice *device, RGLcontext* context ); void rglDetachContext( RGLdevice *device, RGLcontext* context );
void rglInvalidateAllStates (void *data); void rglInvalidateAllStates (void *data);
void rglResetAttributeState( rglAttributeState* as ); void rglResetAttributeState(void *data);
void rglSetFlipHandler(void (*handler)(const GLuint head), RGLdevice *device); void rglSetFlipHandler(void (*handler)(const GLuint head), RGLdevice *device);
void rglSetVBlankHandler(void (*handler)(const GLuint head), RGLdevice *device); void rglSetVBlankHandler(void (*handler)(const GLuint head), RGLdevice *device);
@ -104,7 +104,7 @@ GLboolean rglIsFormat( GLenum format );
GLboolean rglIsValidPair( GLenum format, GLenum type ); GLboolean rglIsValidPair( GLenum format, GLenum type );
void rglImageAllocCPUStorage (void *data); void rglImageAllocCPUStorage (void *data);
void rglImageFreeCPUStorage (void *data); void rglImageFreeCPUStorage (void *data);
extern void rglSetImage( rglImage* image, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const GLvoid* pixels ); extern void rglSetImage(void *data, 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 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 ); extern int rglGetPixelSize( GLenum format, GLenum type );

View File

@ -2,8 +2,10 @@
#include "../../include/RGL/private.h" #include "../../include/RGL/private.h"
#include <string.h> #include <string.h>
const char *rglMapLookupEnum( const RGLenumMap* map, unsigned int count, GLenum e ) const char *rglMapLookupEnum(const void *data, unsigned int count, GLenum e )
{ {
const RGLenumMap *map = (const RGLenumMap*)data;
for (GLuint i = 0; i < count; ++i) for (GLuint i = 0; i < count; ++i)
if (map[i].e == e) if (map[i].e == e)
return map[i].s; return map[i].s;
@ -11,8 +13,10 @@ const char *rglMapLookupEnum( const RGLenumMap* map, unsigned int count, GLenum
return NULL; return NULL;
} }
GLenum rglMapLookupString( const RGLenumMap* map, unsigned int count, const char *s ) GLenum rglMapLookupString(const void *data, unsigned int count, const char *s )
{ {
const RGLenumMap *map = (const RGLenumMap*)data;
if (s != NULL) if (s != NULL)
for (GLuint i = 0;i < count;++i) for (GLuint i = 0;i < count;++i)
if ( strcmp( map[i].s, s) == 0) if ( strcmp( map[i].s, s) == 0)

View File

@ -7,8 +7,10 @@
static const unsigned int capacityIncr = 16; static const unsigned int capacityIncr = 16;
// Initialize texture namespace ns with creation and destruction functions // Initialize texture namespace ns with creation and destruction functions
void rglTexNameSpaceInit( rglTexNameSpace *ns, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy ) void rglTexNameSpaceInit(void *data, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy)
{ {
rglTexNameSpace *ns = (rglTexNameSpace*)data;
ns->capacity = capacityIncr; ns->capacity = capacityIncr;
ns->data = (void **)malloc( ns->capacity * sizeof( void* ) ); ns->data = (void **)malloc( ns->capacity * sizeof( void* ) );
memset( ns->data, 0, ns->capacity*sizeof( void* ) ); memset( ns->data, 0, ns->capacity*sizeof( void* ) );
@ -17,18 +19,23 @@ void rglTexNameSpaceInit( rglTexNameSpace *ns, rglTexNameSpaceCreateFunction cre
} }
// Free texture namespace ns // Free texture namespace ns
void rglTexNameSpaceFree( rglTexNameSpace *ns ) void rglTexNameSpaceFree(void *data)
{ {
for ( GLuint i = 1;i < ns->capacity;++i ) rglTexNameSpace *ns = (rglTexNameSpace*)data;
if ( ns->data[i] ) ns->destroy( ns->data[i] );
for (GLuint i = 1;i < ns->capacity; ++i)
if (ns->data[i])
ns->destroy( ns->data[i] );
free( ns->data ); free( ns->data );
ns->data = NULL; ns->data = NULL;
} }
// Reset all names in namespace ns to NULL // Reset all names in namespace ns to NULL
void rglTexNameSpaceResetNames( rglTexNameSpace *ns ) void rglTexNameSpaceResetNames(void *data)
{ {
rglTexNameSpace *ns = (rglTexNameSpace*)data;
for ( GLuint i = 1;i < ns->capacity;++i ) for ( GLuint i = 1;i < ns->capacity;++i )
{ {
if ( ns->data[i] ) if ( ns->data[i] )
@ -40,9 +47,11 @@ void rglTexNameSpaceResetNames( rglTexNameSpace *ns )
} }
// Get an index of the first free name in namespace ns // Get an index of the first free name in namespace ns
GLuint rglTexNameSpaceGetFree( rglTexNameSpace *ns ) GLuint rglTexNameSpaceGetFree(void *data)
{ {
rglTexNameSpace *ns = (rglTexNameSpace*)data;
GLuint i; GLuint i;
for (i = 1;i < ns->capacity;++i) for (i = 1;i < ns->capacity;++i)
if (!ns->data[i]) if (!ns->data[i])
break; break;
@ -51,8 +60,10 @@ GLuint rglTexNameSpaceGetFree( rglTexNameSpace *ns )
// Add name to namespace by increasing capacity and calling creation call back function // Add name to namespace by increasing capacity and calling creation call back function
// Return GL_TRUE for success, GL_FALSE for failure // Return GL_TRUE for success, GL_FALSE for failure
GLboolean rglTexNameSpaceCreateNameLazy( rglTexNameSpace *ns, GLuint name ) GLboolean rglTexNameSpaceCreateNameLazy(void *data, GLuint name )
{ {
rglTexNameSpace *ns = (rglTexNameSpace*)data;
if (name >= ns->capacity) if (name >= ns->capacity)
{ {
int newCapacity = name >= ns->capacity + capacityIncr ? name + 1 : ns->capacity + capacityIncr; int newCapacity = name >= ns->capacity + capacityIncr ? name + 1 : ns->capacity + capacityIncr;
@ -71,15 +82,20 @@ GLboolean rglTexNameSpaceCreateNameLazy( rglTexNameSpace *ns, GLuint name )
// Check if name is a valid name in namespace ns // Check if name is a valid name in namespace ns
// Return GL_TRUE if so, GL_FALSE otherwise // Return GL_TRUE if so, GL_FALSE otherwise
GLboolean rglTexNameSpaceIsName( rglTexNameSpace *ns, GLuint name ) GLboolean rglTexNameSpaceIsName(void *data, GLuint name )
{ {
if (( name > 0 ) && ( name < ns->capacity ) ) return( ns->data[name] != 0 ); rglTexNameSpace *ns = (rglTexNameSpace*)data;
if ((name > 0) && (name < ns->capacity))
return( ns->data[name] != 0 );
else return GL_FALSE; else return GL_FALSE;
} }
// Generate new n names in namespace ns // Generate new n names in namespace ns
void rglTexNameSpaceGenNames( rglTexNameSpace *ns, GLsizei n, GLuint *names ) void rglTexNameSpaceGenNames(void *data, GLsizei n, GLuint *names )
{ {
rglTexNameSpace *ns = (rglTexNameSpace*)data;
for ( int i = 0;i < n;++i ) for ( int i = 0;i < n;++i )
{ {
GLuint name = rglTexNameSpaceGetFree( ns ); GLuint name = rglTexNameSpaceGetFree( ns );
@ -90,8 +106,10 @@ void rglTexNameSpaceGenNames( rglTexNameSpace *ns, GLsizei n, GLuint *names )
} }
// Delete n names from namespace ns // Delete n names from namespace ns
void rglTexNameSpaceDeleteNames( rglTexNameSpace *ns, GLsizei n, const GLuint *names ) void rglTexNameSpaceDeleteNames(void *data, GLsizei n, const GLuint *names )
{ {
rglTexNameSpace *ns = (rglTexNameSpace*)data;
for ( int i = 0;i < n;++i ) for ( int i = 0;i < n;++i )
{ {
GLuint name = names[i]; GLuint name = names[i];

View File

@ -201,14 +201,14 @@ int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramHeader *
CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refcount ) CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refcount )
{ {
if ( index < ( int )group->programCount ) if (index < ( int )group->programCount)
{ {
//index can be < 0 , in that case refcount update on the group only, used when destroying a copied program //index can be < 0 , in that case refcount update on the group only, used when destroying a copied program
if ( index >= 0 ) if (index >= 0)
{ {
//if it has already been referenced duplicate instead of returning the same index, until the API offer a native support for //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 ) //group of programs ( //fixed bug 13007 )
if ( refcount == 1 && group->programs[index].refCount == 1 ) if (refcount == 1 && group->programs[index].refCount == 1)
{ {
//it will handle the refcounting //it will handle the refcounting
CGprogram res = cgCopyProgram( group->programs[index].program ); CGprogram res = cgCopyProgram( group->programs[index].program );
@ -218,12 +218,10 @@ CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refco
} }
group->refCount += refcount; group->refCount += refcount;
if ( refcount < 0 ) if (refcount < 0)
{ {
if ( group->refCount == 0 && !group->userCreated ) if (group->refCount == 0 && !group->userCreated)
{
rglCgDestroyProgramGroup( group ); rglCgDestroyProgramGroup( group );
}
return NULL; return NULL;
} }
else else
@ -236,7 +234,7 @@ CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refco
//add the group to the context: //add the group to the context:
static void rglCgAddGroup( CGcontext ctx, CGprogramGroup group ) static void rglCgAddGroup( CGcontext ctx, CGprogramGroup group )
{ {
_CGcontext *context = _cgGetContextPtr( ctx ); _CGcontext *context = _cgGetContextPtr(ctx);
if ( !context->groupList ) if ( !context->groupList )
context->groupList = group; context->groupList = group;
else else

View File

@ -2166,7 +2166,7 @@ void rglPlatformChooseGPUFormatAndLayout(
const rglTexture *texture = (const rglTexture*)data; const rglTexture *texture = (const rglTexture*)data;
rglImage *image = texture->image + texture->baseLevel; rglImage *image = texture->image + texture->baseLevel;
#if 0 #ifndef HAVE_RGL_2D
GLuint levels = rglLog2( MAX( MAX( image->width, image->height ), image->depth ) ) + 1; GLuint levels = rglLog2( MAX( MAX( image->width, image->height ), image->depth ) ) + 1;
levels = MIN( levels, texture->maxLevel + 1 ); levels = MIN( levels, texture->maxLevel + 1 );
@ -2512,7 +2512,7 @@ static inline void rglGcmUpdateGcmTexture (void *data_tex, void *data_layout, vo
platformTexture->gcmTexture.pitch = layout->pitch; platformTexture->gcmTexture.pitch = layout->pitch;
platformTexture->gcmTexture.mipmap = layout->levels; platformTexture->gcmTexture.mipmap = layout->levels;
platformTexture->gcmTexture.cubemap = CELL_GCM_FALSE; platformTexture->gcmTexture.cubemap = CELL_GCM_FALSE;
#if 0 #ifndef HAVE_RGL_2D
// set dimension, swizzled implies P2 width/height/depth // set dimension, swizzled implies P2 width/height/depth
switch ( texture->target ) switch ( texture->target )
{ {
@ -2543,7 +2543,7 @@ void rglGcmUpdateMethods (void *data)
// XXX make sure that REVALIDATE_PARAMETERS is set if the format of the texture changes // XXX make sure that REVALIDATE_PARAMETERS is set if the format of the texture changes
// revalidate the texture registers cache just to ensure we are in the correct filtering mode // revalidate the texture registers cache just to ensure we are in the correct filtering mode
// based on the internal format. // based on the internal format.
#if 0 #ifndef HAVE_RGL_2D
switch ( layout->internalFormat ) switch ( layout->internalFormat )
{ {
case RGLGCM_FLOAT_R32: case RGLGCM_FLOAT_R32:
@ -2862,7 +2862,7 @@ GLboolean rglPlatformTextureReference (void *data, GLuint pitch, void *data_buf,
if (rglIsDrawableColorFormat( newLayout.internalFormat)) if (rglIsDrawableColorFormat( newLayout.internalFormat))
isRenderTarget = GL_TRUE; isRenderTarget = GL_TRUE;
#if 0 #ifndef HAVE_RGL_2D
switch (newLayout.internalFormat) switch (newLayout.internalFormat)
{ {
case GL_FLOAT_RGBA32: case GL_FLOAT_RGBA32:

View File

@ -52,8 +52,12 @@ static void rglFreeBufferObject (void *data)
static void rglUnbindBufferObject (void *data, GLuint name) static void rglUnbindBufferObject (void *data, GLuint name)
{ {
RGLcontext *LContext = (RGLcontext*)data; RGLcontext *LContext = (RGLcontext*)data;
if ( LContext->ArrayBuffer == name ) LContext->ArrayBuffer = 0;
if ( LContext->PixelUnpackBuffer == name ) LContext->PixelUnpackBuffer = 0; if (LContext->ArrayBuffer == name)
LContext->ArrayBuffer = 0;
if (LContext->PixelUnpackBuffer == name)
LContext->PixelUnpackBuffer = 0;
for ( int i = 0;i < RGL_MAX_VERTEX_ATTRIBS;++i ) for ( int i = 0;i < RGL_MAX_VERTEX_ATTRIBS;++i )
{ {
if ( LContext->attribs->attrib[i].arrayBuffer == name ) if ( LContext->attribs->attrib[i].arrayBuffer == name )
@ -67,7 +71,9 @@ static void rglUnbindBufferObject (void *data, GLuint name)
GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name ) GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name )
{ {
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = _CurrentContext;
if ( name ) rglTexNameSpaceCreateNameLazy( &LContext->bufferObjectNameSpace, name );
if (name)
rglTexNameSpaceCreateNameLazy( &LContext->bufferObjectNameSpace, name );
switch ( target ) switch ( target )
{ {
@ -89,6 +95,7 @@ GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access )
{ {
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = _CurrentContext;
GLuint name = 0; GLuint name = 0;
switch ( target ) switch ( target )
{ {
case GL_ARRAY_BUFFER: case GL_ARRAY_BUFFER:
@ -106,7 +113,7 @@ GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access )
} }
rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name];
#ifndef HAVE_RGL_2D
switch ( access ) switch ( access )
{ {
case GL_READ_ONLY: case GL_READ_ONLY:
@ -117,6 +124,9 @@ GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access )
rglSetError( GL_INVALID_ENUM ); rglSetError( GL_INVALID_ENUM );
return NULL; return NULL;
} }
#else
(void)0;
#endif
bufferObject->mapped = GL_TRUE; bufferObject->mapped = GL_TRUE;
void *result = rglPlatformBufferObjectMap( bufferObject, access ); void *result = rglPlatformBufferObjectMap( bufferObject, access );
@ -124,12 +134,11 @@ GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access )
return result; return result;
} }
GLAPI GLboolean APIENTRY glUnmapBuffer( GLenum target ) GLAPI GLboolean APIENTRY glUnmapBuffer( GLenum target )
{ {
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = _CurrentContext;
GLuint name = 0; GLuint name = 0;
switch ( target ) switch ( target )
{ {
case GL_ARRAY_BUFFER: case GL_ARRAY_BUFFER:
@ -154,9 +163,10 @@ GLAPI GLboolean APIENTRY glUnmapBuffer( GLenum target )
GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers ) GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers )
{ {
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = _CurrentContext;
for ( int i = 0;i < n;++i ) for (int i = 0; i < n; ++i)
{ {
if(!rglTexNameSpaceIsName( &LContext->bufferObjectNameSpace, buffers[i] ) ) continue; if(!rglTexNameSpaceIsName(&LContext->bufferObjectNameSpace, buffers[i]))
continue;
if (buffers[i]) if (buffers[i])
rglUnbindBufferObject( LContext, buffers[i] ); rglUnbindBufferObject( LContext, buffers[i] );
} }
@ -174,6 +184,7 @@ GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid *
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = _CurrentContext;
GLuint name = 0; GLuint name = 0;
switch ( target ) switch ( target )
{ {
case GL_ARRAY_BUFFER: case GL_ARRAY_BUFFER:
@ -199,7 +210,9 @@ GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid *
bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name];
} }
if ( bufferObject->size > 0 ) rglPlatformDestroyBufferObject( bufferObject ); if (bufferObject->size > 0)
rglPlatformDestroyBufferObject( bufferObject );
bufferObject->size = size; bufferObject->size = size;
bufferObject->width = 0; bufferObject->width = 0;
bufferObject->height = 0; bufferObject->height = 0;
@ -213,7 +226,8 @@ GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid *
rglSetError( GL_OUT_OF_MEMORY ); rglSetError( GL_OUT_OF_MEMORY );
return; return;
} }
if ( data ) rglPlatformBufferObjectSetData( bufferObject, 0, size, data, GL_TRUE ); if (data)
rglPlatformBufferObjectSetData( bufferObject, 0, size, data, GL_TRUE );
} }
} }
@ -221,6 +235,7 @@ GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr
{ {
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = _CurrentContext;
GLuint name = 0; GLuint name = 0;
switch ( target ) switch ( target )
{ {
case GL_ARRAY_BUFFER: case GL_ARRAY_BUFFER:
@ -272,7 +287,6 @@ GLAPI void APIENTRY glClear( GLbitfield mask )
if ( LContext->needValidate & RGL_VALIDATE_FRAMEBUFFER ) if ( LContext->needValidate & RGL_VALIDATE_FRAMEBUFFER )
rglValidateFramebuffer(); rglValidateFramebuffer();
rglFBClear( mask ); rglFBClear( mask );
} }
GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
@ -339,8 +353,10 @@ void rglFramebufferGetAttachmentTexture(
} }
} }
rglFramebufferAttachment* rglFramebufferGetAttachment( rglFramebuffer *framebuffer, GLenum attachment ) rglFramebufferAttachment* rglFramebufferGetAttachment(void *data, GLenum attachment)
{ {
rglFramebuffer *framebuffer = (rglFramebuffer*)data;
switch ( attachment ) switch ( attachment )
{ {
case GL_COLOR_ATTACHMENT0_EXT: case GL_COLOR_ATTACHMENT0_EXT:
@ -364,7 +380,7 @@ void rglGetFramebufferSize( GLuint* width, GLuint* height )
{ {
rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer ); rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer );
if ( rglPlatformFramebufferCheckStatus( framebuffer ) != GL_FRAMEBUFFER_COMPLETE_OES ) if (rglPlatformFramebufferCheckStatus(framebuffer) != GL_FRAMEBUFFER_COMPLETE_OES)
return; return;
for ( int i = 0; i < RGL_MAX_COLOR_ATTACHMENTS; ++i ) for ( int i = 0; i < RGL_MAX_COLOR_ATTACHMENTS; ++i )
@ -433,7 +449,7 @@ GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum target )
{ {
RGLcontext* LContext = _CurrentContext; RGLcontext* LContext = _CurrentContext;
if ( LContext->framebuffer ) if (LContext->framebuffer)
{ {
rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer ); rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer );
@ -448,22 +464,26 @@ GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum target, GLenum attachment,
RGLcontext* LContext = _CurrentContext; RGLcontext* LContext = _CurrentContext;
rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer ); rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer );
rglFramebufferAttachment* attach = rglFramebufferGetAttachment( framebuffer, attachment ); rglFramebufferAttachment* attach = rglFramebufferGetAttachment( framebuffer, attachment );
if ( !attach ) return;
if (!attach)
return;
rglTexture *textureObject = NULL; rglTexture *textureObject = NULL;
GLuint face; GLuint face;
rglFramebufferGetAttachmentTexture( LContext, attach, &textureObject, &face ); rglFramebufferGetAttachmentTexture( LContext, attach, &textureObject, &face );
if ( textureObject ) textureObject->framebuffers.removeElement( framebuffer );
if ( texture ) if (textureObject)
textureObject->framebuffers.removeElement( framebuffer );
if (texture)
{ {
attach->type = RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE; attach->type = RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE;
textureObject = rglGetTexture( LContext, texture ); textureObject = rglGetTexture( LContext, texture );
textureObject->framebuffers.pushBack( framebuffer ); textureObject->framebuffers.pushBack( framebuffer );
} }
else attach->type = RGL_FRAMEBUFFER_ATTACHMENT_NONE; else
attach->type = RGL_FRAMEBUFFER_ATTACHMENT_NONE;
attach->name = texture; attach->name = texture;
attach->textureTarget = textarget; attach->textureTarget = textarget;
@ -540,12 +560,27 @@ DECLARE_C_TYPES
#undef DECLARE_TYPE #undef DECLARE_TYPE
typedef GLfloat type_GL_FLOAT; typedef GLfloat type_GL_FLOAT;
static inline type_GL_FLOAT rglFloatTo_GL_FLOAT( float v ) {return v;}
static inline float rglFloatFrom_GL_FLOAT( type_GL_FLOAT v ) {return v;}
typedef GLhalfARB type_GL_HALF_FLOAT_ARB; typedef GLhalfARB type_GL_HALF_FLOAT_ARB;
static inline type_GL_HALF_FLOAT_ARB rglFloatTo_GL_HALF_FLOAT_ARB( float x ) {return rglFloatToHalf( x );}
static inline float rglFloatFrom_GL_HALF_FLOAT_ARB( type_GL_HALF_FLOAT_ARB x ) {return rglHalfToFloat( x );} static inline type_GL_FLOAT rglFloatTo_GL_FLOAT(float v)
{
return v;
}
static inline float rglFloatFrom_GL_FLOAT(type_GL_FLOAT v)
{
return v;
}
static inline type_GL_HALF_FLOAT_ARB rglFloatTo_GL_HALF_FLOAT_ARB(float x)
{
return rglFloatToHalf(x);
}
static inline float rglFloatFrom_GL_HALF_FLOAT_ARB(type_GL_HALF_FLOAT_ARB x)
{
return rglHalfToFloat(x);
}
#define DECLARE_PACKED_TYPE_AND_REV_2(REALTYPE,S1,S2) \ #define DECLARE_PACKED_TYPE_AND_REV_2(REALTYPE,S1,S2) \
DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S1##_##S2,2,S1,S2,0,0,) \ DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S1##_##S2,2,S1,S2,0,0,) \
@ -643,38 +678,34 @@ void rglRawRasterToImage(const void *in_data,
const GLuint size = pixelBits / 8; const GLuint size = pixelBits / 8;
if ( raster->xstride == image->xstride &&
raster->ystride == image->ystride &&
raster->zstride == image->zstride )
{ {
if ( raster->xstride == image->xstride && memcpy((char*)image->data +
raster->ystride == image->ystride && x*image->xstride + y*image->ystride + z*image->zstride,
raster->zstride == image->zstride ) raster->data, raster->depth*raster->zstride );
{
memcpy(
( char * )image->data +
x*image->xstride + y*image->ystride + z*image->zstride,
raster->data,
raster->depth*raster->zstride );
return; return;
} }
else if ( raster->xstride == image->xstride ) else if ( raster->xstride == image->xstride )
{
const GLuint lineBytes = raster->width * raster->xstride;
for ( int i = 0; i < raster->depth; ++i )
{ {
const GLuint lineBytes = raster->width * raster->xstride; for ( int j = 0; j < raster->height; ++j )
for ( int i = 0; i < raster->depth; ++i )
{ {
for ( int j = 0; j < raster->height; ++j ) const char *src = ( const char * )raster->data +
{ i * raster->zstride + j * raster->ystride;
const char *src = ( const char * )raster->data + char *dst = ( char * )image->data +
i * raster->zstride + j * raster->ystride; ( i + z ) * image->zstride +
char *dst = ( char * )image->data + ( j + y ) * image->ystride +
( i + z ) * image->zstride + x * image->xstride;
( j + y ) * image->ystride + memcpy( dst, src, lineBytes );
x * image->xstride;
memcpy( dst, src, lineBytes );
}
} }
return;
} }
return;
} }
for ( int i = 0; i < raster->depth; ++i ) for ( int i = 0; i < raster->depth; ++i )
@ -717,6 +748,7 @@ void rglImageAllocCPUStorage (void *data)
void rglImageFreeCPUStorage(void *data) void rglImageFreeCPUStorage(void *data)
{ {
rglImage *image = (rglImage*)data; rglImage *image = (rglImage*)data;
if (!image->mallocData) if (!image->mallocData)
return; return;
@ -727,8 +759,10 @@ void rglImageFreeCPUStorage(void *data)
image->dataState &= ~RGL_IMAGE_DATASTATE_HOST; image->dataState &= ~RGL_IMAGE_DATASTATE_HOST;
} }
static inline void rglSetImageTexRef( rglImage *image, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment) static inline void rglSetImageTexRef(void *data, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment)
{ {
rglImage *image = (rglImage*)data;
image->width = width; image->width = width;
image->height = height; image->height = height;
image->depth = depth; image->depth = depth;
@ -753,20 +787,20 @@ static inline void rglSetImageTexRef( rglImage *image, GLint internalFormat, GLs
image->isSet = GL_TRUE; image->isSet = GL_TRUE;
{ if ( image->xstride == 0 )
if ( image->xstride == 0 ) image->xstride = rglGetPixelSize( image->format, image->type );
image->xstride = rglGetPixelSize( image->format, image->type ); if ( image->ystride == 0 )
if ( image->ystride == 0 ) image->ystride = image->width * image->xstride;
image->ystride = image->width * image->xstride; if ( image->zstride == 0 )
if ( image->zstride == 0 ) image->zstride = image->height * image->ystride;
image->zstride = image->height * image->ystride;
}
image->dataState = RGL_IMAGE_DATASTATE_UNSET; image->dataState = RGL_IMAGE_DATASTATE_UNSET;
} }
void rglSetImage( rglImage *image, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const GLvoid *pixels ) void rglSetImage(void *data, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const void *pixels )
{ {
rglImage *image = (rglImage*)data;
image->width = width; image->width = width;
image->height = height; image->height = height;
image->depth = depth; image->depth = depth;
@ -800,7 +834,7 @@ void rglSetImage( rglImage *image, GLint internalFormat, GLsizei width, GLsizei
image->zstride = image->height * image->ystride; image->zstride = image->height * image->ystride;
} }
if ( pixels ) if (pixels)
{ {
rglImageAllocCPUStorage( image ); rglImageAllocCPUStorage( image );
if ( !image->data ) if ( !image->data )
@ -812,10 +846,10 @@ void rglSetImage( rglImage *image, GLint internalFormat, GLsizei width, GLsizei
raster.width = width; raster.width = width;
raster.height = height; raster.height = height;
raster.depth = depth; raster.depth = depth;
raster.data = ( void * )pixels; raster.data = (void*)pixels;
raster.xstride = rglGetPixelSize( raster.format, raster.type ); raster.xstride = rglGetPixelSize( raster.format, raster.type );
raster.ystride = ( raster.width * raster.xstride + alignment - 1 ) / alignment * alignment; raster.ystride = (raster.width * raster.xstride + alignment - 1) / alignment * alignment;
raster.zstride = raster.height * raster.ystride; raster.zstride = raster.height * raster.ystride;
rglRawRasterToImage( &raster, image, 0, 0, 0 ); rglRawRasterToImage( &raster, image, 0, 0, 0 );
@ -837,7 +871,6 @@ static char* rglExtensionsString = "";
static char* rglVersionNumber = "2.00"; static char* rglVersionNumber = "2.00";
char* rglVersion = "2.00"; char* rglVersion = "2.00";
RGLcontext* _CurrentContext = NULL; RGLcontext* _CurrentContext = NULL;
RGL_EXPORT RGLcontextHookFunction rglContextCreateHook = NULL; RGL_EXPORT RGLcontextHookFunction rglContextCreateHook = NULL;
@ -895,13 +928,13 @@ GLuint rglValidateStates (GLuint mask)
GLuint needValidate = LContext->needValidate; GLuint needValidate = LContext->needValidate;
if ( RGL_UNLIKELY( needValidate & RGL_VALIDATE_FRAMEBUFFER ) ) if (RGL_UNLIKELY( needValidate & RGL_VALIDATE_FRAMEBUFFER))
{ {
rglValidateFramebuffer(); rglValidateFramebuffer();
needValidate = LContext->needValidate; needValidate = LContext->needValidate;
} }
if ( RGL_UNLIKELY( needValidate & RGL_VALIDATE_TEXTURES_USED ) ) if (RGL_UNLIKELY( needValidate & RGL_VALIDATE_TEXTURES_USED))
{ {
long unitInUseCount = LContext->BoundFragmentProgram->samplerCount; long unitInUseCount = LContext->BoundFragmentProgram->samplerCount;
const GLuint* unitsInUse = LContext->BoundFragmentProgram->samplerUnits; const GLuint* unitsInUse = LContext->BoundFragmentProgram->samplerUnits;
@ -910,22 +943,22 @@ GLuint rglValidateStates (GLuint mask)
long unit = unitsInUse[i]; long unit = unitsInUse[i];
rglTexture* texture = LContext->TextureImageUnits[unit].currentTexture; rglTexture* texture = LContext->TextureImageUnits[unit].currentTexture;
if ( texture ) if (texture)
rglPlatformValidateTextureStage( unit, texture ); rglPlatformValidateTextureStage( unit, texture );
} }
} }
if ( RGL_UNLIKELY( needValidate & RGL_VALIDATE_VERTEX_PROGRAM ) ) if (RGL_UNLIKELY(needValidate & RGL_VALIDATE_VERTEX_PROGRAM))
{ {
rglValidateVertexProgram(); rglValidateVertexProgram();
} }
if ( RGL_LIKELY( needValidate & RGL_VALIDATE_VERTEX_CONSTANTS ) ) if (RGL_LIKELY(needValidate & RGL_VALIDATE_VERTEX_CONSTANTS))
{ {
rglValidateVertexConstants(); rglValidateVertexConstants();
} }
if ( RGL_UNLIKELY( needValidate & RGL_VALIDATE_FRAGMENT_PROGRAM ) ) if (RGL_UNLIKELY(needValidate & RGL_VALIDATE_FRAGMENT_PROGRAM))
{ {
rglValidateFragmentProgram(); rglValidateFragmentProgram();
} }
@ -952,8 +985,10 @@ GLuint rglValidateStates (GLuint mask)
return dirty; return dirty;
} }
void rglResetAttributeState( rglAttributeState* as ) void rglResetAttributeState(void *data)
{ {
rglAttributeState *as = (rglAttributeState*)data;
for ( int i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i ) for ( int i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i )
{ {
as->attrib[i].clientSize = 4; as->attrib[i].clientSize = 4;
@ -1074,12 +1109,12 @@ static void rglResetContext (void *data)
RGLcontext* psglCreateContext(void) RGLcontext* psglCreateContext(void)
{ {
RGLcontext* LContext = ( RGLcontext* )malloc( sizeof( RGLcontext ) ); RGLcontext* LContext = (RGLcontext*)malloc(sizeof(RGLcontext));
if (!LContext) if (!LContext)
return NULL; return NULL;
memset( LContext, 0, sizeof( RGLcontext ) ); memset(LContext, 0, sizeof(RGLcontext));
LContext->error = GL_NO_ERROR; LContext->error = GL_NO_ERROR;
@ -1424,15 +1459,18 @@ void rglTextureUnbind (void *data, GLuint name )
GLboolean rglTextureIsValid (const void *data) GLboolean rglTextureIsValid (const void *data)
{ {
const rglTexture *texture = (const rglTexture*)data; const rglTexture *texture = (const rglTexture*)data;
if ( texture->imageCount < 1 + texture->baseLevel )
if (texture->imageCount < 1 + texture->baseLevel)
return GL_FALSE; return GL_FALSE;
if ( !texture->image ) if ( !texture->image )
return GL_FALSE; return GL_FALSE;
const rglImage* image = texture->image + texture->baseLevel; const rglImage* image = texture->image + texture->baseLevel;
GLenum format = image->format; GLenum format = image->format;
GLenum type = image->type; GLenum type = image->type;
GLenum internalFormat = image->internalFormat; GLenum internalFormat = image->internalFormat;
if (( texture->vertexEnable ) && ( internalFormat != GL_FLOAT_RGBA32 ) if (( texture->vertexEnable ) && ( internalFormat != GL_FLOAT_RGBA32 )
&& ( internalFormat != GL_RGBA32F_ARB )) && ( internalFormat != GL_RGBA32F_ARB ))
return GL_FALSE; return GL_FALSE;
@ -1551,7 +1589,7 @@ void rglBindTextureInternal (void *data, GLuint name, GLenum target )
} }
} }
#if 0 #ifndef HAVE_RGL_2D
switch ( target ) switch ( target )
{ {
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
@ -1843,7 +1881,7 @@ void rglVertexAttrib1fNV (GLuint index, GLfloat x)
RGLBIT_TRUE( LContext->attribs->DirtyMask, index ); RGLBIT_TRUE( LContext->attribs->DirtyMask, index );
} }
void rglVertexAttrib2fNV( GLuint index, GLfloat x, GLfloat y ) void rglVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y)
{ {
RGLcontext* LContext = _CurrentContext; RGLcontext* LContext = _CurrentContext;
@ -2014,6 +2052,8 @@ RGLdevice *psglGetCurrentDevice (void)
GLAPI void RGL_EXPORT psglSwap (void) GLAPI void RGL_EXPORT psglSwap (void)
{ {
#ifndef HAVE_RGL_2D
if ( _CurrentDevice != NULL) if ( _CurrentDevice != NULL)
#endif
rglPlatformSwapBuffers( _CurrentDevice ); rglPlatformSwapBuffers( _CurrentDevice );
} }