diff --git a/GL/matrix.c b/GL/matrix.c index 5c19d0a..0a06eea 100644 --- a/GL/matrix.c +++ b/GL/matrix.c @@ -1,7 +1,8 @@ #include +#include #include -#include +#include #include "../include/gl.h" #include "../containers/stack.h" diff --git a/GL/private.h b/GL/private.h index 592e827..a312d28 100644 --- a/GL/private.h +++ b/GL/private.h @@ -98,17 +98,12 @@ typedef struct { GLboolean is_directional; } LightSource; -union color_t { - uint8_t bgra[sizeof(uint32_t)]; - uint32_t packed; -}; - typedef struct { /* Same 32 byte layout as pvr_vertex_t */ uint32_t flags; float xyz[3]; float uv[2]; - union color_t color; + uint8_t bgra[4]; /* In the pvr_vertex_t structure, this next 4 bytes is oargb * but we're not using that for now, so having W here makes the code @@ -116,14 +111,12 @@ typedef struct { float w; } Vertex; - - /* FIXME: SH4 has a swap.w instruction, we should leverage it here! */ -#define _SWAP32(type, x, y) \ +#define _SWAP32(x, y) \ do { \ - type t = *((type*) &x); \ - *((type*) &x) = *((type*) &y); \ - *((type*) &y) = t; \ + uint32_t t = *((uint32_t*) &x); \ + *((uint32_t*) &x) = *((uint32_t*) &y); \ + *((uint32_t*) &y) = t; \ } while(0) /* @@ -134,16 +127,48 @@ do { \ #define swapVertex(a, b) \ do { \ - _SWAP32(uint32_t, a->flags, b->flags); \ - _SWAP32(float, a->xyz[0], b->xyz[0]); \ - _SWAP32(float, a->xyz[1], b->xyz[1]); \ - _SWAP32(float, a->xyz[2], b->xyz[2]); \ - _SWAP32(float, a->uv[0], b->uv[0]); \ - _SWAP32(float, a->uv[1], b->uv[1]); \ - _SWAP32(uint32_t, a->color.packed, b->color.packed); \ - _SWAP32(float, a->w, b->w); \ + _SWAP32(a->flags, b->flags); \ + _SWAP32(a->xyz[0], b->xyz[0]); \ + _SWAP32(a->xyz[1], b->xyz[1]); \ + _SWAP32(a->xyz[2], b->xyz[2]); \ + _SWAP32(a->uv[0], b->uv[0]); \ + _SWAP32(a->uv[1], b->uv[1]); \ + _SWAP32(a->bgra, b->bgra); \ + _SWAP32(a->w, b->w); \ } while(0) +#if 0 +/* FIXME: SH4 has a swap.w instruction, we should leverage it here! */ +inline void _SWAP32( void* x, void* y) +{ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" + *((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); + *((uint32_t*) &y) = *((uint32_t*) &x) ^ *((uint32_t*) &y); + *((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); + #pragma GCC diagnostic pop +} + +/* + *((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); \ + *((uint32_t*) &y) = *((uint32_t*) &x) ^ *((uint32_t*) &y); \ + *((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); */ + + + +#define swapVertex(a, b) \ +{ \ + _SWAP32(&a->flags, &b->flags); \ + _SWAP32(&a->xyz[0], &b->xyz[0]); \ + _SWAP32(&a->xyz[1], &b->xyz[1]); \ + _SWAP32(&a->xyz[2], &b->xyz[2]); \ + _SWAP32(&a->uv[0], &b->uv[0]); \ + _SWAP32(&a->uv[1], &b->uv[1]); \ + _SWAP32(&a->bgra, &b->bgra); \ + _SWAP32(&a->w, &b->w); \ +} +#endif + /* ClipVertex doesn't have room for these, so we need to parse them * out separately. Potentially 'w' will be housed here if we support oargb */ typedef struct { @@ -213,6 +238,7 @@ pvr_poly_cxt_t* _glGetPVRContext(); GLubyte _glInitTextures(); void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit); +void _glAllocateSpaceForMipmaps(TextureObject* active); typedef struct { const void* ptr;