(RGL PS3) Cleanups #2

This commit is contained in:
twinaphex 2014-02-18 00:30:15 +01:00
parent 38d4626f6e
commit ab8221a258
6 changed files with 76 additions and 106 deletions

View File

@ -10,23 +10,32 @@ namespace RGL
template<class T> class Vector template<class T> class Vector
{ {
T* array; T* array;
unsigned int count;
unsigned int capacity; unsigned int capacity;
unsigned int increment; unsigned int increment;
public: public:
unsigned int count;
void * operator new( size_t size ) { return malloc( size ); } void * operator new( size_t size ) { return malloc( size ); }
void * operator new( size_t /*size*/, void *p ) { return p; } void * operator new( size_t /*size*/, void *p ) { return p; }
void operator delete( void * /*ptr*/, void * /*p*/ ) { } void operator delete( void * /*ptr*/, void * /*p*/ ) { }
Vector(): array( 0 ), count( 0 ), capacity( 0 ), increment( 4 ) {} Vector(): array( 0 ), count( 0 ), capacity( 0 ), increment( 4 ) {}
~Vector() { clear(); reallocArray( 0 ); } ~Vector()
{
if (array)
{
for ( unsigned int i = 0;i < count;++i )
( array + i )->~T();
count = 0;
}
inline void setIncrement( unsigned int i ) { increment = i; } reallocArray( 0 );
inline unsigned int getCount() { return count; } }
inline void reallocArray( unsigned int newCapacity ) inline void reallocArray( unsigned int newCapacity )
{ {
if ( newCapacity == capacity ) return; if ( newCapacity == capacity )
if ( newCapacity > capacity ) newCapacity = ( newCapacity > capacity + increment ) ? newCapacity : ( capacity + increment ); return;
if ( newCapacity > capacity )
newCapacity = ( newCapacity > capacity + increment ) ? newCapacity : ( capacity + increment );
if ( newCapacity == 0 ) if ( newCapacity == 0 )
{ {
free( array ); free( array );
@ -36,13 +45,6 @@ namespace RGL
capacity = 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 ) inline unsigned int pushBack( const T &element )
{ {
if ( count + 1 > capacity ) reallocArray( count + 1 ); if ( count + 1 > capacity ) reallocArray( count + 1 );
@ -56,19 +58,15 @@ namespace RGL
{ {
if ( array[i-1] == element ) if ( array[i-1] == element )
{ {
remove( i - 1 ); unsigned int index = i - 1;
( array + index )->~T();
--count;
if ( count > index ) memmove( array + index, array + index + 1, ( count - index )*sizeof( T ) );
return; 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 *getArray() const { return array; }
inline T& operator []( int i ) const { return array[i]; } inline T& operator []( int i ) const { return array[i]; }
}; };

View File

@ -56,21 +56,29 @@ static inline GLhalfARB rglFloatToHalf( float v )
static inline float rglHalfToFloat( GLhalfARB v ) static inline float rglHalfToFloat( GLhalfARB v )
{ {
unsigned int S = v >> 15; unsigned int S, E, M;
unsigned int E = ( v & 0x7C00 ) >> 10;
unsigned int M = v & 0x03ff;
float f; float f;
S = v >> 15;
E = ( v & 0x7C00 ) >> 10;
M = v & 0x03ff;
if ( E == 31 ) if ( E == 31 )
{ {
if ( M == 0 ) f = RGL_INFINITY; if ( M == 0 )
else f = RGL_NAN; f = RGL_INFINITY;
else
f = RGL_NAN;
} }
else if ( E == 0 ) else if ( E == 0 )
{ {
if ( M == 0 ) f = 0.f; if ( M == 0 )
else f = M * 1.f / ( 1 << 24 ); f = 0.f;
else
f = M * 1.f / ( 1 << 24 );
} }
else f = ( 0x400 + M ) * 1.f / ( 1 << 25 ) * ( 1 << E ); else
f = ( 0x400 + M ) * 1.f / ( 1 << 25 ) * ( 1 << E );
return S ? -f : f; return S ? -f : f;
} }
@ -79,10 +87,7 @@ static inline float rglHalfToFloat( GLhalfARB v )
// FixedPoint.c // FixedPoint.c
//---------------------------------------- //----------------------------------------
#define rglFixedToFloat 1.f/65536.f #define X2F(X) (((float)(X))* 1.f/65536.f)
#define rglFloatToFixed 65536.f #define F2X(A) ((int)((A)* 65536.f))
#define X2F(X) (((float)(X))*rglFixedToFloat)
#define F2X(A) ((int)((A)*rglFloatToFixed))
#endif // _TYPE_UTILS_H #endif // _TYPE_UTILS_H

View File

@ -9,13 +9,12 @@
extern "C" { extern "C" {
#endif #endif
#ifndef MSVC #ifdef MSVC
#define RGL_LIKELY(COND) __builtin_expect((COND),1)
#define RGL_UNLIKELY(COND) __builtin_expect((COND),0)
#else
#define RGL_LIKELY(COND) (COND) #define RGL_LIKELY(COND) (COND)
#define RGL_UNLIKELY(COND) (COND) #define RGL_UNLIKELY(COND) (COND)
#else
#define RGL_LIKELY(COND) __builtin_expect((COND),1)
#define RGL_UNLIKELY(COND) __builtin_expect((COND),0)
#endif #endif
#define MAX(A,B) ((A)>(B)?(A):(B)) #define MAX(A,B) ((A)>(B)?(A):(B))
@ -23,26 +22,10 @@ extern "C" {
#define _RGL_FLOAT_AS_UINT(x) ({union {float f; unsigned int i;} u; u.f=(x); u.i;}) #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 ) #define rglClampf(value) (MAX( MIN((value), 1.f ), 0.f ))
{ #define endianSwapHalf(v) (((v) >> 8 & 0x00ff) | ((v) << 8 & 0xff00))
return MAX( MIN( value, 1.f ), 0.f ); #define endianSwapWord(v) (((v) & 0xff ) << 24 | ((v) & 0xff00 ) << 8 | ((v) & 0xff0000 ) >> 8 | ((v) & 0xff000000 ) >> 24)
} #define endianSwapWordByHalf(v) (((v) & 0xffff ) << 16 | (v) >> 16)
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 ) static inline int rglLog2( unsigned int i )
{ {
@ -55,56 +38,38 @@ extern "C" {
return l -1; return l -1;
} }
static inline int rglIsPow2( unsigned int i ) #define rglIsPow2(i) (((i) & ((i) - 1 )) == 0)
{ // Pad argument x to the next multiple of argument pad.
return ( i&( i - 1 ) ) == 0; #define rglPad(x, pad) (((x) + (pad) - 1 ) / (pad) * (pad))
}
// Pad argument x to the next multiple of argument pad. // Pad pointer x to the next multiple of argument pad.
static inline unsigned long rglPad( unsigned long x, unsigned long pad ) static inline char* rglPadPtr( const char* p, unsigned int pad )
{ {
return ( x + pad - 1 ) / pad*pad; intptr_t x = (intptr_t)p;
} x = ( x + pad - 1 ) / pad * pad;
return ( char* )x;
}
// Pad pointer x to the next multiple of argument pad. // names API
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 unsigned int rglCreateName (void *data, void* object);
RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name);
RGL_EXPORT void rglEraseName (void *data, unsigned int name);
RGL_EXPORT unsigned int rglCreateName (void *data, void* object); static inline void *rglGetNamedValue(void *data, unsigned int name )
RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name); {
RGL_EXPORT void rglEraseName (void *data, unsigned int name); return ((struct rglNameSpace*)data)->data[name - 1];
}
static inline void *rglGetNamedValue(void *data, unsigned int name ) void rglTexNameSpaceResetNames(void *data);
{ GLboolean rglTexNameSpaceCreateNameLazy(void *data, GLuint name );
return ((struct rglNameSpace*)data)->data[name - 1]; GLboolean rglTexNameSpaceIsName(void *data, GLuint name );
} void rglTexNameSpaceDeleteNames(void *data, GLsizei n, const GLuint *names );
void rglTexNameSpaceReinit(void *saved, void *active);
void rglTexNameSpaceResetNames(void *data);
GLboolean rglTexNameSpaceCreateNameLazy(void *data, GLuint name );
GLboolean rglTexNameSpaceIsName(void *data, GLuint name );
void rglTexNameSpaceDeleteNames(void *data, GLsizei n, const GLuint *names );
void rglTexNameSpaceReinit(void *saved, void *active);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #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_ #endif // _RGL_UTILS_H_

View File

@ -33,7 +33,7 @@ typedef void( * RGLcontextHookFunction )( RGLcontext *context );
extern RGL_EXPORT RGLcontextHookFunction rglContextCreateHook; extern RGL_EXPORT RGLcontextHookFunction rglContextCreateHook;
extern RGL_EXPORT RGLcontextHookFunction rglContextDestroyHook; extern RGL_EXPORT RGLcontextHookFunction rglContextDestroyHook;
extern RGLcontext* rglContextCreate(); extern RGLcontext* rglContextCreate(void);
extern void rglContextFree( RGLcontext* LContext ); extern void rglContextFree( RGLcontext* LContext );
extern void rglSetError( GLenum error ); extern void rglSetError( GLenum error );
void rglDetachContext( RGLdevice *device, RGLcontext* context ); void rglDetachContext( RGLdevice *device, RGLcontext* context );
@ -59,13 +59,14 @@ static inline rglFramebuffer *rglGetFramebuffer( RGLcontext *LContext, GLuint na
static inline void rglTextureTouchFBOs (void *data) static inline void rglTextureTouchFBOs (void *data)
{ {
rglTexture *texture = (rglTexture*)data; rglTexture *texture = (rglTexture*)data;
RGLcontext *LContext = _CurrentContext; RGLcontext *LContext = (RGLcontext*)_CurrentContext;
if (!LContext ) if (!LContext )
return; // may be called in psglDestroyContext return; // may be called in psglDestroyContext
// check if bound to any framebuffer // check if bound to any framebuffer
GLuint fbCount = texture->framebuffers.getCount(); GLuint fbCount = texture->framebuffers.count;
if ( fbCount > 0 ) if ( fbCount > 0 )
{ {
rglFramebuffer *contextFramebuffer = LContext->framebuffer ? rglGetFramebuffer( LContext, LContext->framebuffer ) : NULL; rglFramebuffer *contextFramebuffer = LContext->framebuffer ? rglGetFramebuffer( LContext, LContext->framebuffer ) : NULL;

View File

@ -3568,8 +3568,8 @@ static void rglSetImage(void *data, GLint internalFormat, GLsizei width, GLsizei
image->format = 0; image->format = 0;
image->type = 0; image->type = 0;
image->internalFormat = 0; image->internalFormat = 0;
const GLenum status = rglPlatformChooseInternalStorage( image, internalFormat );
(( void )status ); rglPlatformChooseInternalStorage( image, internalFormat);
image->data = NULL; image->data = NULL;
image->mallocData = NULL; image->mallocData = NULL;

View File

@ -763,7 +763,8 @@ static void rglpsAllocateBuffer (void *data)
if ( rglBuffer->bufferId == GMM_ERROR ) if ( rglBuffer->bufferId == GMM_ERROR )
rglBuffer->pool = RGLGCM_SURFACE_POOL_NONE; rglBuffer->pool = RGLGCM_SURFACE_POOL_NONE;
GLuint referenceCount = bufferObject->textureReferences.getCount(); GLuint referenceCount = bufferObject->textureReferences.count;
if ( referenceCount > 0 ) if ( referenceCount > 0 )
{ {
for ( GLuint i = 0;i < referenceCount;++i ) for ( GLuint i = 0;i < referenceCount;++i )