Clean ups and optimisations

This commit is contained in:
Luke Benstead 2022-08-25 21:24:08 +01:00
parent 4edf8ce04d
commit 0b62ac8673
12 changed files with 116 additions and 114 deletions

102
GL/draw.c
View File

@ -3,7 +3,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <assert.h>
#include "private.h" #include "private.h"
#include "platform.h" #include "platform.h"
@ -260,37 +259,37 @@ static void _fillZero2f(const GLubyte* __restrict__ input, GLubyte* __restrict__
static void _readVertexData3usARGB(const GLubyte* input, GLubyte* output) { static void _readVertexData3usARGB(const GLubyte* input, GLubyte* output) {
_GL_UNUSED(input); _GL_UNUSED(input);
_GL_UNUSED(output); _GL_UNUSED(output);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
static void _readVertexData3uiARGB(const GLubyte* input, GLubyte* output) { static void _readVertexData3uiARGB(const GLubyte* input, GLubyte* output) {
_GL_UNUSED(input); _GL_UNUSED(input);
_GL_UNUSED(output); _GL_UNUSED(output);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
static void _readVertexData4usARGB(const GLubyte* input, GLubyte* output) { static void _readVertexData4usARGB(const GLubyte* input, GLubyte* output) {
_GL_UNUSED(input); _GL_UNUSED(input);
_GL_UNUSED(output); _GL_UNUSED(output);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
static void _readVertexData4uiARGB(const GLubyte* input, GLubyte* output) { static void _readVertexData4uiARGB(const GLubyte* input, GLubyte* output) {
_GL_UNUSED(input); _GL_UNUSED(input);
_GL_UNUSED(output); _GL_UNUSED(output);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
static void _readVertexData4usRevARGB(const GLubyte* input, GLubyte* output) { static void _readVertexData4usRevARGB(const GLubyte* input, GLubyte* output) {
_GL_UNUSED(input); _GL_UNUSED(input);
_GL_UNUSED(output); _GL_UNUSED(output);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
static void _readVertexData4uiRevARGB(const GLubyte* input, GLubyte* output) { static void _readVertexData4uiRevARGB(const GLubyte* input, GLubyte* output) {
_GL_UNUSED(input); _GL_UNUSED(input);
_GL_UNUSED(output); _GL_UNUSED(output);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLuint* _glGetEnabledAttributes() { GLuint* _glGetEnabledAttributes() {
@ -394,12 +393,12 @@ GL_FORCE_INLINE void transformNormalToEyeSpace(GLfloat* normal) {
} }
GL_FORCE_INLINE PolyHeader *_glSubmissionTargetHeader(SubmissionTarget* target) { GL_FORCE_INLINE PolyHeader *_glSubmissionTargetHeader(SubmissionTarget* target) {
assert(target->header_offset < target->output->vector.size); gl_assert(target->header_offset < target->output->vector.size);
return aligned_vector_at(&target->output->vector, target->header_offset); return aligned_vector_at(&target->output->vector, target->header_offset);
} }
GL_INLINE_DEBUG Vertex* _glSubmissionTargetStart(SubmissionTarget* target) { GL_INLINE_DEBUG Vertex* _glSubmissionTargetStart(SubmissionTarget* target) {
assert(target->start_offset < target->output->vector.size); gl_assert(target->start_offset < target->output->vector.size);
return aligned_vector_at(&target->output->vector, target->start_offset); return aligned_vector_at(&target->output->vector, target->start_offset);
} }
@ -438,7 +437,7 @@ GL_FORCE_INLINE void genTriangleStrip(Vertex* output, GLuint count) {
} }
static void genTriangleFan(Vertex* output, GLuint count) { static void genTriangleFan(Vertex* output, GLuint count) {
assert(count <= 255); gl_assert(count <= 255);
Vertex* dst = output + (((count - 2) * 3) - 1); Vertex* dst = output + (((count - 2) * 3) - 1);
Vertex* src = output + (count - 1); Vertex* src = output + (count - 1);
@ -583,74 +582,60 @@ ReadNormalFunc calcReadNormalFunc() {
} }
} }
static void _readPositionData(ReadDiffuseFunc func, const GLuint first, const GLuint count, const Vertex* output) { static void _readPositionData(ReadDiffuseFunc func, const GLuint first, const GLuint count, Vertex* it) {
const GLsizei vstride = ATTRIB_POINTERS.vertex.stride; const GLsizei vstride = ATTRIB_POINTERS.vertex.stride;
const GLubyte* vptr = ((GLubyte*) ATTRIB_POINTERS.vertex.ptr + (first * vstride)); const GLubyte* vptr = ((GLubyte*) ATTRIB_POINTERS.vertex.ptr + (first * vstride));
GLubyte* out = (GLubyte*) output[0].xyz; float pos[3];
uint32_t* flags; float w = 0.0f;
ITERATE(count) { ITERATE(count) {
PREFETCH(vptr + vstride); PREFETCH(vptr + vstride);
func(vptr, (GLubyte*) pos);
it->flags = GPU_CMD_VERTEX;
TransformVertex((const float*) pos, &w, it->xyz, &it->w);
func(vptr, out);
vptr += vstride; vptr += vstride;
++it;
/* Set the flags which are 4 bytes before the position. Doing it here saves
* an additional loop */
flags = (uint32_t*) out - 1;
*flags = GPU_CMD_VERTEX;
out += sizeof(Vertex);
} }
} }
static void _readUVData(ReadUVFunc func, const GLuint first, const GLuint count, const Vertex* output) { static void _readUVData(ReadUVFunc func, const GLuint first, const GLuint count, Vertex* it) {
const GLsizei uvstride = ATTRIB_POINTERS.uv.stride; const GLsizei uvstride = ATTRIB_POINTERS.uv.stride;
const GLubyte* uvptr = ((GLubyte*) ATTRIB_POINTERS.uv.ptr + (first * uvstride)); const GLubyte* uvptr = ((GLubyte*) ATTRIB_POINTERS.uv.ptr + (first * uvstride));
GLubyte* out = (GLubyte*) output[0].uv;
ITERATE(count) { ITERATE(count) {
PREFETCH(uvptr + uvstride); PREFETCH(uvptr + uvstride);
func(uvptr, out); func(uvptr, (GLubyte*) it->uv);
uvptr += uvstride; uvptr += uvstride;
out += sizeof(Vertex); ++it;
} }
} }
static void _readSTData(ReadUVFunc func, const GLuint first, const GLuint count, const VertexExtra* extra) { static void _readSTData(ReadUVFunc func, const GLuint first, const GLuint count, VertexExtra* it) {
const GLsizei ststride = ATTRIB_POINTERS.st.stride; const GLsizei ststride = ATTRIB_POINTERS.st.stride;
const GLubyte* stptr = ((GLubyte*) ATTRIB_POINTERS.st.ptr + (first * ststride)); const GLubyte* stptr = ((GLubyte*) ATTRIB_POINTERS.st.ptr + (first * ststride));
GLubyte* out = (GLubyte*) extra[0].st;
ITERATE(count) { ITERATE(count) {
PREFETCH(stptr + ststride); PREFETCH(stptr + ststride);
func(stptr, (GLubyte*) it->st);
func(stptr, out);
stptr += ststride; stptr += ststride;
out += sizeof(VertexExtra); ++it;
} }
} }
static void _readNormalData(ReadNormalFunc func, const GLuint first, const GLuint count, const VertexExtra* extra) { static void _readNormalData(ReadNormalFunc func, const GLuint first, const GLuint count, VertexExtra* it) {
const GLsizei nstride = ATTRIB_POINTERS.normal.stride; const GLsizei nstride = ATTRIB_POINTERS.normal.stride;
const GLubyte* nptr = ((GLubyte*) ATTRIB_POINTERS.normal.ptr + (first * nstride)); const GLubyte* nptr = ((GLubyte*) ATTRIB_POINTERS.normal.ptr + (first * nstride));
GLubyte* out = (GLubyte*) extra[0].nxyz;
ITERATE(count) { ITERATE(count) {
func(nptr, out); func(nptr, (GLubyte*) it->nxyz);
nptr += nstride; nptr += nstride;
out += sizeof(VertexExtra);
}
if(_glIsNormalizeEnabled()) { if(_glIsNormalizeEnabled()) {
GLubyte* ptr = (GLubyte*) extra->nxyz; GLfloat* n = (GLfloat*) it->nxyz;
ITERATE(count) {
GLfloat* n = (GLfloat*) ptr;
float temp = n[0] * n[0]; float temp = n[0] * n[0];
temp = MATH_fmac(n[1], n[1], temp); temp = MATH_fmac(n[1], n[1], temp);
temp = MATH_fmac(n[2], n[2], temp); temp = MATH_fmac(n[2], n[2], temp);
@ -659,9 +644,9 @@ static void _readNormalData(ReadNormalFunc func, const GLuint first, const GLuin
n[0] *= ilength; n[0] *= ilength;
n[1] *= ilength; n[1] *= ilength;
n[2] *= ilength; n[2] *= ilength;
ptr += sizeof(VertexExtra);
} }
++it;
} }
} }
@ -669,18 +654,15 @@ GL_FORCE_INLINE GLuint diffusePointerSize() {
return (ATTRIB_POINTERS.colour.size == GL_BGRA) ? 4 : ATTRIB_POINTERS.colour.size; return (ATTRIB_POINTERS.colour.size == GL_BGRA) ? 4 : ATTRIB_POINTERS.colour.size;
} }
static void _readDiffuseData(ReadDiffuseFunc func, const GLuint first, const GLuint count, const Vertex* output) { static void _readDiffuseData(ReadDiffuseFunc func, const GLuint first, const GLuint count, Vertex* it) {
const GLuint cstride = ATTRIB_POINTERS.colour.stride; const GLuint cstride = ATTRIB_POINTERS.colour.stride;
const GLubyte* cptr = ((GLubyte*) ATTRIB_POINTERS.colour.ptr) + (first * cstride); const GLubyte* cptr = ((GLubyte*) ATTRIB_POINTERS.colour.ptr) + (first * cstride);
GLubyte* out = (GLubyte*) output[0].bgra;
ITERATE(count) { ITERATE(count) {
PREFETCH(cptr + cstride); PREFETCH(cptr + cstride);
func(cptr, it->bgra);
func(cptr, out);
cptr += cstride; cptr += cstride;
out += sizeof(Vertex); ++it;
} }
} }
@ -864,11 +846,11 @@ static void generateArrays(SubmissionTarget* target, const GLsizei first, const
Vertex* start = _glSubmissionTargetStart(target); Vertex* start = _glSubmissionTargetStart(target);
VertexExtra* ve = aligned_vector_at(target->extras, 0); VertexExtra* ve = aligned_vector_at(target->extras, 0);
ReadPositionFunc pfunc = calcReadPositionFunc(); const ReadPositionFunc pfunc = calcReadPositionFunc();
ReadDiffuseFunc dfunc = calcReadDiffuseFunc(); const ReadDiffuseFunc dfunc = calcReadDiffuseFunc();
ReadUVFunc uvfunc = calcReadUVFunc(); const ReadUVFunc uvfunc = calcReadUVFunc();
ReadNormalFunc nfunc = calcReadNormalFunc(); const ReadNormalFunc nfunc = calcReadNormalFunc();
ReadUVFunc stfunc = calcReadSTFunc(); const ReadUVFunc stfunc = calcReadSTFunc();
_readPositionData(pfunc, first, count, start); _readPositionData(pfunc, first, count, start);
_readDiffuseData(dfunc, first, count, start); _readDiffuseData(dfunc, first, count, start);
@ -920,7 +902,7 @@ static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei
genTriangleStrip(it, count); genTriangleStrip(it, count);
break; break;
default: default:
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
} }
@ -1042,7 +1024,7 @@ GL_FORCE_INLINE void push(PolyHeader* header, GLboolean multiTextureHeader, Poly
_glUpdatePVRTextureContext(&cxt, textureUnit); _glUpdatePVRTextureContext(&cxt, textureUnit);
if(multiTextureHeader) { if(multiTextureHeader) {
assert(cxt.list_type == GPU_LIST_TR_POLY); gl_assert(cxt.list_type == GPU_LIST_TR_POLY);
cxt.gen.alpha = GPU_ALPHA_ENABLE; cxt.gen.alpha = GPU_ALPHA_ENABLE;
cxt.txr.alpha = GPU_TXRALPHA_ENABLE; cxt.txr.alpha = GPU_TXRALPHA_ENABLE;
@ -1117,14 +1099,14 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
} }
// We don't handle this any further, so just make sure we never pass it down */ // We don't handle this any further, so just make sure we never pass it down */
assert(mode != GL_POLYGON); gl_assert(mode != GL_POLYGON);
target->output = _glActivePolyList(); target->output = _glActivePolyList();
target->count = (mode == GL_TRIANGLE_FAN) ? ((count - 2) * 3) : count; target->count = (mode == GL_TRIANGLE_FAN) ? ((count - 2) * 3) : count;
target->header_offset = target->output->vector.size; target->header_offset = target->output->vector.size;
target->start_offset = target->header_offset + 1; target->start_offset = target->header_offset + 1;
assert(target->count); gl_assert(target->count);
/* Make sure we have enough room for all the "extra" data */ /* Make sure we have enough room for all the "extra" data */
aligned_vector_resize(&extras, target->count); aligned_vector_resize(&extras, target->count);
@ -1192,7 +1174,7 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
&_glTransparentPolyList()->vector, (Vertex*) _glSubmissionTargetHeader(target), target->count + 1 &_glTransparentPolyList()->vector, (Vertex*) _glSubmissionTargetHeader(target), target->count + 1
); );
assert(vertex); gl_assert(vertex);
PolyHeader* mtHeader = (PolyHeader*) vertex++; PolyHeader* mtHeader = (PolyHeader*) vertex++;

View File

@ -1,5 +1,4 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include "private.h" #include "private.h"
@ -197,7 +196,7 @@ static GL_NO_INSTRUMENT GLboolean _glCalculateAverageTexel(GLuint pvrFormat, con
*d1 = PACK_ARGB4444(a, r, g, b); *d1 = PACK_ARGB4444(a, r, g, b);
} else { } else {
assert(format == ARGB1555); gl_assert(format == ARGB1555);
GLushort* s1 = (GLushort*) src1; GLushort* s1 = (GLushort*) src1;
GLushort* s2 = (GLushort*) src2; GLushort* s2 = (GLushort*) src2;
@ -246,8 +245,8 @@ GLboolean _glGenerateMipmapTwiddled(const GLuint pvrFormat, const GLubyte* prevD
const GLubyte* s4 = s3 + stride; const GLubyte* s4 = s3 + stride;
GLubyte* t = &thisData[j * stride]; GLubyte* t = &thisData[j * stride];
assert(s4 < prevData + (lastHeight * lastWidth * stride)); gl_assert(s4 < prevData + (lastHeight * lastWidth * stride));
assert(t < thisData + (thisHeight * thisWidth * stride)); gl_assert(t < thisData + (thisHeight * thisWidth * stride));
_glCalculateAverageTexel(pvrFormat, s1, s2, s3, s4, t); _glCalculateAverageTexel(pvrFormat, s1, s2, s3, s4, t);
} }
@ -323,7 +322,7 @@ void APIENTRY glGenerateMipmapEXT(GLenum target) {
prevHeight = thisHeight; prevHeight = thisHeight;
} }
assert(_glIsMipmapComplete(tex)); gl_assert(_glIsMipmapComplete(tex));
} }
/* generate mipmaps for any image provided by the user and then pass them to OpenGL */ /* generate mipmaps for any image provided by the user and then pass them to OpenGL */

20
GL/gl_assert.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef NDEBUG
/* We're debugging, use normal assert */
#include <assert.h>
#define gl_assert assert
#else
/* Release mode, use our custom assert */
#include <stdio.h>
#include <stdlib.h>
#define gl_assert(x) \
do {\
if(!(x)) {\
fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
exit(1);\
}\
} while(0); \
#endif

View File

@ -275,7 +275,7 @@ void APIENTRY glEnd() {
#ifndef NDEBUG #ifndef NDEBUG
// Immediate mode should always activate the fast path // Immediate mode should always activate the fast path
GLuint fastPathEnabled = _glRecalcFastPath(); GLuint fastPathEnabled = _glRecalcFastPath();
assert(fastPathEnabled); gl_assert(fastPathEnabled);
#else #else
/* If we're not debugging, set to true - we assume we haven't broken it! */ /* If we're not debugging, set to true - we assume we haven't broken it! */
FAST_PATH_ENABLED = GL_TRUE; FAST_PATH_ENABLED = GL_TRUE;

View File

@ -1,4 +1,3 @@
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -144,7 +143,7 @@ void APIENTRY glLightModeli(GLenum pname, const GLint param) {
void APIENTRY glLightModelfv(GLenum pname, const GLfloat *params) { void APIENTRY glLightModelfv(GLenum pname, const GLfloat *params) {
switch(pname) { switch(pname) {
case GL_LIGHT_MODEL_AMBIENT: { case GL_LIGHT_MODEL_AMBIENT: {
memcpy(SCENE_AMBIENT, params, sizeof(GLfloat) * 4); for(int i = 0; i < 4; ++i) SCENE_AMBIENT[i] = params[i];
_glPrecalcLightingValues(SCENE_AMBIENT_MASK); _glPrecalcLightingValues(SCENE_AMBIENT_MASK);
} break; } break;
case GL_LIGHT_MODEL_LOCAL_VIEWER: case GL_LIGHT_MODEL_LOCAL_VIEWER:
@ -393,7 +392,7 @@ GL_FORCE_INLINE float faster_pow2(const float p) {
} }
GL_FORCE_INLINE float faster_log2(const float x) { GL_FORCE_INLINE float faster_log2(const float x) {
assert(x >= 0.0f); gl_assert(x >= 0.0f);
const union { float f; uint32_t i; } vx = { x }; const union { float f; uint32_t i; } vx = { x };
const float y = (float) (vx.i) * 1.1920928955078125e-7f; const float y = (float) (vx.i) * 1.1920928955078125e-7f;

View File

@ -3,7 +3,8 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#include "gl_assert.h"
#define MEMSET(dst, v, size) memset((dst), (v), (size)) #define MEMSET(dst, v, size) memset((dst), (v), (size))

View File

@ -75,8 +75,8 @@ static uint32_t *d; // SQ target
GL_FORCE_INLINE void _glSubmitHeaderOrVertex(const Vertex* v) { GL_FORCE_INLINE void _glSubmitHeaderOrVertex(const Vertex* v) {
#ifndef NDEBUG #ifndef NDEBUG
assert(!isnan(v->xyz[2])); gl_assert(!isnan(v->xyz[2]));
assert(!isnan(v->w)); gl_assert(!isnan(v->w));
#endif #endif
#if CLIP_DEBUG #if CLIP_DEBUG

View File

@ -31,7 +31,7 @@
#define FASTCPY(dst, src, bytes) \ #define FASTCPY(dst, src, bytes) \
do { \ do { \
if(bytes % 32 == 0 && ((uintptr_t) src % 4) == 0) { \ if(bytes % 32 == 0 && ((uintptr_t) src % 4) == 0) { \
assert(((uintptr_t) dst) % 32 == 0); \ gl_assert(((uintptr_t) dst) % 32 == 0); \
sq_cpy(dst, src, bytes); \ sq_cpy(dst, src, bytes); \
} else { \ } else { \
memcpy(dst, src, bytes); \ memcpy(dst, src, bytes); \

View File

@ -164,8 +164,8 @@ GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex, const float h) {
GL_FORCE_INLINE void _glSubmitHeaderOrVertex(const Vertex* v) { GL_FORCE_INLINE void _glSubmitHeaderOrVertex(const Vertex* v) {
#ifndef NDEBUG #ifndef NDEBUG
if(glIsVertex(v->flags)) { if(glIsVertex(v->flags)) {
assert(!isnan(v->xyz[2])); gl_assert(!isnan(v->xyz[2]));
assert(!isnan(v->w)); gl_assert(!isnan(v->w));
} }
#endif #endif

View File

@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "gl_assert.h"
#include "platform.h" #include "platform.h"
#include "types.h" #include "types.h"

View File

@ -3,7 +3,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
@ -44,14 +43,14 @@ static void* yalloc_alloc_and_defrag(size_t size) {
ret = yalloc_alloc(YALLOC_BASE, size); ret = yalloc_alloc(YALLOC_BASE, size);
} }
assert(ret && "Out of PVR memory!"); gl_assert(ret && "Out of PVR memory!");
return ret; return ret;
} }
static TexturePalette* _initTexturePalette() { static TexturePalette* _initTexturePalette() {
TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette)); TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette));
assert(palette); gl_assert(palette);
MEMSET4(palette, 0x0, sizeof(TexturePalette)); MEMSET4(palette, 0x0, sizeof(TexturePalette));
palette->bank = -1; palette->bank = -1;
@ -61,7 +60,7 @@ static TexturePalette* _initTexturePalette() {
static GLshort _glGenPaletteSlot(GLushort size) { static GLshort _glGenPaletteSlot(GLushort size) {
GLushort i, j; GLushort i, j;
assert(size == 16 || size == 256); gl_assert(size == 16 || size == 256);
if(size == 16) { if(size == 16) {
for(i = 0; i < MAX_GLDC_PALETTE_SLOTS; ++i) { for(i = 0; i < MAX_GLDC_PALETTE_SLOTS; ++i) {
@ -94,7 +93,7 @@ GLushort _glFreePaletteSlots(GLushort size)
{ {
GLushort i, j , slots = 0; GLushort i, j , slots = 0;
assert(size == 16 || size == 256); gl_assert(size == 16 || size == 256);
if(size == 16) { if(size == 16) {
for(i = 0; i < MAX_GLDC_PALETTE_SLOTS; ++i) { for(i = 0; i < MAX_GLDC_PALETTE_SLOTS; ++i) {
@ -119,7 +118,7 @@ static void _glReleasePaletteSlot(GLshort slot, GLushort size)
{ {
GLushort i; GLushort i;
assert(size == 16 || size == 256); gl_assert(size == 16 || size == 256);
if (size == 16) { if (size == 16) {
GLushort bank = slot / MAX_GLDC_PALETTE_SLOTS; GLushort bank = slot / MAX_GLDC_PALETTE_SLOTS;
@ -215,7 +214,7 @@ static void GPUTextureTwiddle16BPP(void * src, void* dst, uint32_t w, uint32_t h
} }
TexturePalette* _glGetSharedPalette(GLshort bank) { TexturePalette* _glGetSharedPalette(GLshort bank) {
assert(bank >= 0 && bank < MAX_GLDC_SHARED_PALETTES); gl_assert(bank >= 0 && bank < MAX_GLDC_SHARED_PALETTES);
return SHARED_PALETTES[bank]; return SHARED_PALETTES[bank];
} }
void _glSetInternalPaletteFormat(GLenum val) { void _glSetInternalPaletteFormat(GLenum val) {
@ -235,7 +234,7 @@ void _glSetInternalPaletteFormat(GLenum val) {
GPUSetPaletteFormat(GPU_PAL_RGB565); GPUSetPaletteFormat(GPU_PAL_RGB565);
break; break;
default: default:
assert(0); gl_assert(0);
} }
} }
@ -473,7 +472,7 @@ GLubyte _glInitTextures() {
#ifdef __DREAMCAST__ #ifdef __DREAMCAST__
/* Ensure memory is aligned */ /* Ensure memory is aligned */
assert((uintptr_t) YALLOC_BASE % 32 == 0); gl_assert((uintptr_t) YALLOC_BASE % 32 == 0);
#endif #endif
yalloc_init(YALLOC_BASE, YALLOC_SIZE); yalloc_init(YALLOC_BASE, YALLOC_SIZE);
@ -536,7 +535,7 @@ void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
GLuint id = 0; GLuint id = 0;
TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id); TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id);
assert(id); // Generated IDs must never be zero gl_assert(id); // Generated IDs must never be zero
_glInitializeTextureObject(txr, id); _glInitializeTextureObject(txr, id);
@ -805,7 +804,7 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
active->data = yalloc_alloc_and_defrag(imageSize); active->data = yalloc_alloc_and_defrag(imageSize);
assert(active->data); // Debug assert gl_assert(active->data); // Debug assert
if(!active->data) { // Release, bail out "gracefully" if(!active->data) { // Release, bail out "gracefully"
_glKosThrowError(GL_OUT_OF_MEMORY, __func__); _glKosThrowError(GL_OUT_OF_MEMORY, __func__);
@ -1226,7 +1225,7 @@ void _glAllocateSpaceForMipmaps(TextureObject* active) {
active->data = yalloc_alloc_and_defrag(bytes); active->data = yalloc_alloc_and_defrag(bytes);
assert(active->data); gl_assert(active->data);
if(!active->data) { if(!active->data) {
free(temp); free(temp);
return; return;
@ -1313,7 +1312,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
} else { } else {
/* Mipmap Errors, kos crashes if 1x1 */ /* Mipmap Errors, kos crashes if 1x1 */
if((h < 2) || (w < 2)){ if((h < 2) || (w < 2)){
assert(TEXTURE_UNITS[ACTIVE_TEXTURE]); gl_assert(TEXTURE_UNITS[ACTIVE_TEXTURE]);
TEXTURE_UNITS[ACTIVE_TEXTURE]->mipmap |= (1 << level); TEXTURE_UNITS[ACTIVE_TEXTURE]->mipmap |= (1 << level);
return; return;
} }
@ -1351,7 +1350,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE]; TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE];
assert(active); gl_assert(active);
if(active->data && (level == 0)) { if(active->data && (level == 0)) {
/* pre-existing texture - check if changed */ /* pre-existing texture - check if changed */
@ -1382,10 +1381,10 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
} }
if(!active->data) { if(!active->data) {
assert(active); gl_assert(active);
assert(width); gl_assert(width);
assert(height); gl_assert(height);
assert(destStride); gl_assert(destStride);
/* need texture memory */ /* need texture memory */
active->width = width; active->width = width;
@ -1397,7 +1396,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
active->dataStride = destStride; active->dataStride = destStride;
active->baseDataSize = bytes; active->baseDataSize = bytes;
assert(bytes); gl_assert(bytes);
if(level > 0) { if(level > 0) {
/* If we're uploading a mipmap level, we need to allocate the full amount of space */ /* If we're uploading a mipmap level, we need to allocate the full amount of space */
@ -1416,7 +1415,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
_glAllocateSpaceForMipmaps(active); _glAllocateSpaceForMipmaps(active);
} }
assert(active->data); gl_assert(active->data);
/* If we run out of PVR memory just return */ /* If we run out of PVR memory just return */
if(!active->data) { if(!active->data) {
@ -1462,7 +1461,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
} }
GLubyte* targetData = (active->baseDataOffset == 0) ? active->data : _glGetMipmapLocation(active, level); GLubyte* targetData = (active->baseDataOffset == 0) ? active->data : _glGetMipmapLocation(active, level);
assert(targetData); gl_assert(targetData);
GLubyte* conversionBuffer = NULL; GLubyte* conversionBuffer = NULL;
@ -1470,9 +1469,9 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
/* No data? Do nothing! */ /* No data? Do nothing! */
return; return;
} else if(!needsConversion && !needsTwiddling) { } else if(!needsConversion && !needsTwiddling) {
assert(targetData); gl_assert(targetData);
assert(data); gl_assert(data);
assert(bytes); gl_assert(bytes);
/* No conversion? Just copy the data, and the pvr_format is correct */ /* No conversion? Just copy the data, and the pvr_format is correct */
FASTCPY(targetData, data, bytes); FASTCPY(targetData, data, bytes);
@ -1491,7 +1490,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
} }
GLint stride = _determineStride(format, type); GLint stride = _determineStride(format, type);
assert(stride > -1); gl_assert(stride > -1);
if(stride == -1) { if(stride == -1) {
INFO_MSG("Stride was not detected\n"); INFO_MSG("Stride was not detected\n");
@ -1504,8 +1503,8 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
GLubyte* dest = conversionBuffer; GLubyte* dest = conversionBuffer;
const GLubyte* source = data; const GLubyte* source = data;
assert(conversionBuffer); gl_assert(conversionBuffer);
assert(source); gl_assert(source);
/* Perform the conversion */ /* Perform the conversion */
GLuint i; GLuint i;
@ -1538,7 +1537,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
active->color &= ~(1 << 26); active->color &= ~(1 << 26);
} else { } else {
/* We should only get here if we converted twiddled data... which is never currently */ /* We should only get here if we converted twiddled data... which is never currently */
assert(conversionBuffer); gl_assert(conversionBuffer);
// We've already converted the data and we // We've already converted the data and we
// don't need to twiddle it! // don't need to twiddle it!
@ -1697,7 +1696,7 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize
GLint sourceStride = _determineStride(format, type); GLint sourceStride = _determineStride(format, type);
assert(sourceStride > -1); gl_assert(sourceStride > -1);
TextureConversionFunc convert = _determineConversion( TextureConversionFunc convert = _determineConversion(
INTERNAL_PALETTE_FORMAT, INTERNAL_PALETTE_FORMAT,
@ -1734,7 +1733,7 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize
palette = active->palette; palette = active->palette;
} }
assert(palette); gl_assert(palette);
if(target) { if(target) {
free(palette->data); free(palette->data);
@ -1750,7 +1749,7 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize
palette->format = format; palette->format = format;
palette->width = width; palette->width = width;
palette->size = (width > 16) ? 256 : 16; palette->size = (width > 16) ? 256 : 16;
assert(palette->size == 16 || palette->size == 256); gl_assert(palette->size == 16 || palette->size == 256);
palette->bank = _glGenPaletteSlot(palette->size); palette->bank = _glGenPaletteSlot(palette->size);
@ -1766,8 +1765,8 @@ GLAPI void APIENTRY glColorTableEXT(GLenum target, GLenum internalFormat, GLsize
GLubyte* src = (GLubyte*) data; GLubyte* src = (GLubyte*) data;
GLubyte* dst = (GLubyte*) palette->data; GLubyte* dst = (GLubyte*) palette->data;
assert(src); gl_assert(src);
assert(dst); gl_assert(dst);
/* Transform and copy the source palette to the texture */ /* Transform and copy the source palette to the texture */
GLushort i = 0; GLushort i = 0;
@ -1825,7 +1824,7 @@ GLAPI void APIENTRY glTexSubImage2D(
_GL_UNUSED(format); _GL_UNUSED(format);
_GL_UNUSED(type); _GL_UNUSED(type);
_GL_UNUSED(pixels); _GL_UNUSED(pixels);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLAPI void APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { GLAPI void APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
@ -1837,7 +1836,7 @@ GLAPI void APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffse
_GL_UNUSED(y); _GL_UNUSED(y);
_GL_UNUSED(width); _GL_UNUSED(width);
_GL_UNUSED(height); _GL_UNUSED(height);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLAPI void APIENTRY glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) { GLAPI void APIENTRY glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) {
@ -1847,7 +1846,7 @@ GLAPI void APIENTRY glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffse
_GL_UNUSED(x); _GL_UNUSED(x);
_GL_UNUSED(y); _GL_UNUSED(y);
_GL_UNUSED(width); _GL_UNUSED(width);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLAPI void APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { GLAPI void APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {
@ -1859,7 +1858,7 @@ GLAPI void APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internal
_GL_UNUSED(width); _GL_UNUSED(width);
_GL_UNUSED(height); _GL_UNUSED(height);
_GL_UNUSED(border); _GL_UNUSED(border);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLAPI void APIENTRY glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) { GLAPI void APIENTRY glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) {
@ -1870,7 +1869,7 @@ GLAPI void APIENTRY glCopyTexImage1D(GLenum target, GLint level, GLenum internal
_GL_UNUSED(y); _GL_UNUSED(y);
_GL_UNUSED(width); _GL_UNUSED(width);
_GL_UNUSED(border); _GL_UNUSED(border);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) { GLAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
@ -1881,7 +1880,7 @@ GLAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height
_GL_UNUSED(format); _GL_UNUSED(format);
_GL_UNUSED(type); _GL_UNUSED(type);
_GL_UNUSED(pixels); _GL_UNUSED(pixels);
assert(0 && "Not Implemented"); gl_assert(0 && "Not Implemented");
} }
GLuint _glMaxTextureMemory() { GLuint _glMaxTextureMemory() {
return YALLOC_SIZE; return YALLOC_SIZE;

View File

@ -1,5 +1,6 @@
#include "yalloc.h" #include "yalloc.h"
#include "yalloc_internals.h" #include "yalloc_internals.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>