mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +00:00
(RGL PS3) Cleanups #2
This commit is contained in:
parent
38d4626f6e
commit
ab8221a258
@ -10,23 +10,32 @@ namespace RGL
|
||||
template<class T> class Vector
|
||||
{
|
||||
T* array;
|
||||
unsigned int count;
|
||||
unsigned int capacity;
|
||||
unsigned int increment;
|
||||
public:
|
||||
unsigned int count;
|
||||
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 ); }
|
||||
~Vector()
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
for ( unsigned int i = 0;i < count;++i )
|
||||
( array + i )->~T();
|
||||
count = 0;
|
||||
}
|
||||
|
||||
inline void setIncrement( unsigned int i ) { increment = i; }
|
||||
inline unsigned int getCount() { return count; }
|
||||
reallocArray( 0 );
|
||||
}
|
||||
|
||||
inline void reallocArray( unsigned int newCapacity )
|
||||
{
|
||||
if ( newCapacity == capacity ) return;
|
||||
if ( newCapacity > capacity ) newCapacity = ( newCapacity > capacity + increment ) ? newCapacity : ( capacity + increment );
|
||||
if ( newCapacity == capacity )
|
||||
return;
|
||||
if ( newCapacity > capacity )
|
||||
newCapacity = ( newCapacity > capacity + increment ) ? newCapacity : ( capacity + increment );
|
||||
if ( newCapacity == 0 )
|
||||
{
|
||||
free( array );
|
||||
@ -36,13 +45,6 @@ namespace RGL
|
||||
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 );
|
||||
@ -56,19 +58,15 @@ namespace RGL
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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]; }
|
||||
};
|
||||
|
@ -56,21 +56,29 @@ static inline GLhalfARB rglFloatToHalf( float v )
|
||||
|
||||
static inline float rglHalfToFloat( GLhalfARB v )
|
||||
{
|
||||
unsigned int S = v >> 15;
|
||||
unsigned int E = ( v & 0x7C00 ) >> 10;
|
||||
unsigned int M = v & 0x03ff;
|
||||
unsigned int S, E, M;
|
||||
float f;
|
||||
|
||||
S = v >> 15;
|
||||
E = ( v & 0x7C00 ) >> 10;
|
||||
M = v & 0x03ff;
|
||||
|
||||
if ( E == 31 )
|
||||
{
|
||||
if ( M == 0 ) f = RGL_INFINITY;
|
||||
else f = RGL_NAN;
|
||||
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 );
|
||||
if ( M == 0 )
|
||||
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;
|
||||
}
|
||||
|
||||
@ -79,10 +87,7 @@ static inline float rglHalfToFloat( GLhalfARB v )
|
||||
// FixedPoint.c
|
||||
//----------------------------------------
|
||||
|
||||
#define rglFixedToFloat 1.f/65536.f
|
||||
#define rglFloatToFixed 65536.f
|
||||
|
||||
#define X2F(X) (((float)(X))*rglFixedToFloat)
|
||||
#define F2X(A) ((int)((A)*rglFloatToFixed))
|
||||
#define X2F(X) (((float)(X))* 1.f/65536.f)
|
||||
#define F2X(A) ((int)((A)* 65536.f))
|
||||
|
||||
#endif // _TYPE_UTILS_H
|
||||
|
@ -9,13 +9,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef MSVC
|
||||
#define RGL_LIKELY(COND) __builtin_expect((COND),1)
|
||||
#define RGL_UNLIKELY(COND) __builtin_expect((COND),0)
|
||||
|
||||
#else
|
||||
#ifdef MSVC
|
||||
#define RGL_LIKELY(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
|
||||
|
||||
#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;})
|
||||
|
||||
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;
|
||||
}
|
||||
#define rglClampf(value) (MAX( MIN((value), 1.f ), 0.f ))
|
||||
#define endianSwapHalf(v) (((v) >> 8 & 0x00ff) | ((v) << 8 & 0xff00))
|
||||
#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 int rglLog2( unsigned int i )
|
||||
{
|
||||
@ -55,56 +38,38 @@ extern "C" {
|
||||
return l -1;
|
||||
}
|
||||
|
||||
static inline int rglIsPow2( unsigned int i )
|
||||
{
|
||||
return ( i&( i - 1 ) ) == 0;
|
||||
}
|
||||
#define rglIsPow2(i) (((i) & ((i) - 1 )) == 0)
|
||||
// Pad argument x to the next multiple of argument pad.
|
||||
#define rglPad(x, pad) (((x) + (pad) - 1 ) / (pad) * (pad))
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// 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);
|
||||
RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name);
|
||||
RGL_EXPORT void rglEraseName (void *data, unsigned int name);
|
||||
static inline void *rglGetNamedValue(void *data, unsigned int name )
|
||||
{
|
||||
return ((struct rglNameSpace*)data)->data[name - 1];
|
||||
}
|
||||
|
||||
static inline void *rglGetNamedValue(void *data, unsigned int name )
|
||||
{
|
||||
return ((struct rglNameSpace*)data)->data[name - 1];
|
||||
}
|
||||
|
||||
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);
|
||||
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
|
||||
}
|
||||
#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_
|
||||
|
@ -33,7 +33,7 @@ typedef void( * RGLcontextHookFunction )( RGLcontext *context );
|
||||
extern RGL_EXPORT RGLcontextHookFunction rglContextCreateHook;
|
||||
extern RGL_EXPORT RGLcontextHookFunction rglContextDestroyHook;
|
||||
|
||||
extern RGLcontext* rglContextCreate();
|
||||
extern RGLcontext* rglContextCreate(void);
|
||||
extern void rglContextFree( RGLcontext* LContext );
|
||||
extern void rglSetError( GLenum error );
|
||||
void rglDetachContext( RGLdevice *device, RGLcontext* context );
|
||||
@ -59,13 +59,14 @@ static inline rglFramebuffer *rglGetFramebuffer( RGLcontext *LContext, GLuint na
|
||||
static inline void rglTextureTouchFBOs (void *data)
|
||||
{
|
||||
rglTexture *texture = (rglTexture*)data;
|
||||
RGLcontext *LContext = _CurrentContext;
|
||||
RGLcontext *LContext = (RGLcontext*)_CurrentContext;
|
||||
|
||||
if (!LContext )
|
||||
return; // may be called in psglDestroyContext
|
||||
|
||||
// check if bound to any framebuffer
|
||||
GLuint fbCount = texture->framebuffers.getCount();
|
||||
GLuint fbCount = texture->framebuffers.count;
|
||||
|
||||
if ( fbCount > 0 )
|
||||
{
|
||||
rglFramebuffer *contextFramebuffer = LContext->framebuffer ? rglGetFramebuffer( LContext, LContext->framebuffer ) : NULL;
|
||||
|
@ -3568,8 +3568,8 @@ static void rglSetImage(void *data, GLint internalFormat, GLsizei width, GLsizei
|
||||
image->format = 0;
|
||||
image->type = 0;
|
||||
image->internalFormat = 0;
|
||||
const GLenum status = rglPlatformChooseInternalStorage( image, internalFormat );
|
||||
(( void )status );
|
||||
|
||||
rglPlatformChooseInternalStorage( image, internalFormat);
|
||||
|
||||
image->data = NULL;
|
||||
image->mallocData = NULL;
|
||||
|
@ -763,7 +763,8 @@ static void rglpsAllocateBuffer (void *data)
|
||||
if ( rglBuffer->bufferId == GMM_ERROR )
|
||||
rglBuffer->pool = RGLGCM_SURFACE_POOL_NONE;
|
||||
|
||||
GLuint referenceCount = bufferObject->textureReferences.getCount();
|
||||
GLuint referenceCount = bufferObject->textureReferences.count;
|
||||
|
||||
if ( referenceCount > 0 )
|
||||
{
|
||||
for ( GLuint i = 0;i < referenceCount;++i )
|
||||
|
Loading…
x
Reference in New Issue
Block a user