Fix twiddling issues
This commit is contained in:
parent
951ece6d19
commit
43d64a4957
24
GL/draw.c
24
GL/draw.c
|
@ -78,7 +78,7 @@ static void _readVertexData3f3f(const GLubyte* __restrict__ in, GLubyte* __restr
|
||||||
|
|
||||||
// 10:10:10:2REV format
|
// 10:10:10:2REV format
|
||||||
static void _readVertexData1i3f(const GLubyte* in, GLubyte* out) {
|
static void _readVertexData1i3f(const GLubyte* in, GLubyte* out) {
|
||||||
const static float MULTIPLIER = 1.0f / 1023.0f;
|
static const float MULTIPLIER = 1.0f / 1023.0f;
|
||||||
|
|
||||||
GLfloat* output = (GLfloat*) out;
|
GLfloat* output = (GLfloat*) out;
|
||||||
|
|
||||||
|
@ -585,7 +585,6 @@ static void _readPositionData(ReadDiffuseFunc func, const GLuint first, const GL
|
||||||
const GLubyte* vptr = ((GLubyte*) ATTRIB_POINTERS.vertex.ptr + (first * vstride));
|
const GLubyte* vptr = ((GLubyte*) ATTRIB_POINTERS.vertex.ptr + (first * vstride));
|
||||||
|
|
||||||
float pos[3];
|
float pos[3];
|
||||||
float w = 0.0f;
|
|
||||||
|
|
||||||
ITERATE(count) {
|
ITERATE(count) {
|
||||||
PREFETCH(vptr + vstride);
|
PREFETCH(vptr + vstride);
|
||||||
|
@ -726,9 +725,7 @@ typedef struct {
|
||||||
} Float2;
|
} Float2;
|
||||||
|
|
||||||
static const Float3 F3Z = {0.0f, 0.0f, 1.0f};
|
static const Float3 F3Z = {0.0f, 0.0f, 1.0f};
|
||||||
static const Float3 F3ZERO = {0.0f, 0.0f, 0.0f};
|
|
||||||
static const Float2 F2ZERO = {0.0f, 0.0f};
|
static const Float2 F2ZERO = {0.0f, 0.0f};
|
||||||
static const uint32_t U4ONE = ~0;
|
|
||||||
|
|
||||||
static void generateElementsFastPath(
|
static void generateElementsFastPath(
|
||||||
SubmissionTarget* target, const GLsizei first, const GLuint count,
|
SubmissionTarget* target, const GLsizei first, const GLuint count,
|
||||||
|
@ -910,24 +907,6 @@ static void transform(SubmissionTarget* target) {
|
||||||
TransformVertices(vertex, target->count);
|
TransformVertices(vertex, target->count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mat_transform3(const float* xyz, const float* xyzOut, const uint32_t count, const uint32_t inStride, const uint32_t outStride) {
|
|
||||||
const uint8_t* dataIn = (const uint8_t*) xyz;
|
|
||||||
uint8_t* dataOut = (uint8_t*) xyzOut;
|
|
||||||
|
|
||||||
ITERATE(count) {
|
|
||||||
const float* in = (const float*) dataIn;
|
|
||||||
float* out = (float*) dataOut;
|
|
||||||
|
|
||||||
TransformVec3NoMod(
|
|
||||||
in,
|
|
||||||
out
|
|
||||||
);
|
|
||||||
|
|
||||||
dataIn += inStride;
|
|
||||||
dataOut += outStride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mat_transform_normal3(const float* xyz, const float* xyzOut, const uint32_t count, const uint32_t inStride, const uint32_t outStride) {
|
static void mat_transform_normal3(const float* xyz, const float* xyzOut, const uint32_t count, const uint32_t inStride, const uint32_t outStride) {
|
||||||
const uint8_t* dataIn = (const uint8_t*) xyz;
|
const uint8_t* dataIn = (const uint8_t*) xyz;
|
||||||
uint8_t* dataOut = (uint8_t*) xyzOut;
|
uint8_t* dataOut = (uint8_t*) xyzOut;
|
||||||
|
@ -1224,7 +1203,6 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
|
||||||
target->header_offset = vector_size;
|
target->header_offset = vector_size;
|
||||||
target->start_offset = target->header_offset + (header_required ? 1 : 0);
|
target->start_offset = target->header_offset + (header_required ? 1 : 0);
|
||||||
|
|
||||||
gl_assert(target->header_offset >= 0);
|
|
||||||
gl_assert(target->start_offset >= target->header_offset);
|
gl_assert(target->start_offset >= target->header_offset);
|
||||||
gl_assert(target->count);
|
gl_assert(target->count);
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ void TransformVec3NoMod(const float* v, float* ret);
|
||||||
|
|
||||||
/* Transform a 3-element normal using the stored matrix (w == 0)*/
|
/* Transform a 3-element normal using the stored matrix (w == 0)*/
|
||||||
static inline void TransformNormalNoMod(const float* xIn, float* xOut) {
|
static inline void TransformNormalNoMod(const float* xIn, float* xOut) {
|
||||||
|
(void) xIn;
|
||||||
|
(void) xOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformVertices(Vertex* vertices, const int count);
|
void TransformVertices(Vertex* vertices, const int count);
|
||||||
|
|
72
GL/texture.c
72
GL/texture.c
|
@ -38,54 +38,16 @@ static GLboolean TEXTURE_TWIDDLE_ENABLED = GL_FALSE;
|
||||||
static void* ALLOC_BASE = NULL;
|
static void* ALLOC_BASE = NULL;
|
||||||
static size_t ALLOC_SIZE = 0;
|
static size_t ALLOC_SIZE = 0;
|
||||||
|
|
||||||
static const unsigned short MortonTable256[256] =
|
|
||||||
{
|
|
||||||
0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015,
|
|
||||||
0x0040, 0x0041, 0x0044, 0x0045, 0x0050, 0x0051, 0x0054, 0x0055,
|
|
||||||
0x0100, 0x0101, 0x0104, 0x0105, 0x0110, 0x0111, 0x0114, 0x0115,
|
|
||||||
0x0140, 0x0141, 0x0144, 0x0145, 0x0150, 0x0151, 0x0154, 0x0155,
|
|
||||||
0x0400, 0x0401, 0x0404, 0x0405, 0x0410, 0x0411, 0x0414, 0x0415,
|
|
||||||
0x0440, 0x0441, 0x0444, 0x0445, 0x0450, 0x0451, 0x0454, 0x0455,
|
|
||||||
0x0500, 0x0501, 0x0504, 0x0505, 0x0510, 0x0511, 0x0514, 0x0515,
|
|
||||||
0x0540, 0x0541, 0x0544, 0x0545, 0x0550, 0x0551, 0x0554, 0x0555,
|
|
||||||
0x1000, 0x1001, 0x1004, 0x1005, 0x1010, 0x1011, 0x1014, 0x1015,
|
|
||||||
0x1040, 0x1041, 0x1044, 0x1045, 0x1050, 0x1051, 0x1054, 0x1055,
|
|
||||||
0x1100, 0x1101, 0x1104, 0x1105, 0x1110, 0x1111, 0x1114, 0x1115,
|
|
||||||
0x1140, 0x1141, 0x1144, 0x1145, 0x1150, 0x1151, 0x1154, 0x1155,
|
|
||||||
0x1400, 0x1401, 0x1404, 0x1405, 0x1410, 0x1411, 0x1414, 0x1415,
|
|
||||||
0x1440, 0x1441, 0x1444, 0x1445, 0x1450, 0x1451, 0x1454, 0x1455,
|
|
||||||
0x1500, 0x1501, 0x1504, 0x1505, 0x1510, 0x1511, 0x1514, 0x1515,
|
|
||||||
0x1540, 0x1541, 0x1544, 0x1545, 0x1550, 0x1551, 0x1554, 0x1555,
|
|
||||||
0x4000, 0x4001, 0x4004, 0x4005, 0x4010, 0x4011, 0x4014, 0x4015,
|
|
||||||
0x4040, 0x4041, 0x4044, 0x4045, 0x4050, 0x4051, 0x4054, 0x4055,
|
|
||||||
0x4100, 0x4101, 0x4104, 0x4105, 0x4110, 0x4111, 0x4114, 0x4115,
|
|
||||||
0x4140, 0x4141, 0x4144, 0x4145, 0x4150, 0x4151, 0x4154, 0x4155,
|
|
||||||
0x4400, 0x4401, 0x4404, 0x4405, 0x4410, 0x4411, 0x4414, 0x4415,
|
|
||||||
0x4440, 0x4441, 0x4444, 0x4445, 0x4450, 0x4451, 0x4454, 0x4455,
|
|
||||||
0x4500, 0x4501, 0x4504, 0x4505, 0x4510, 0x4511, 0x4514, 0x4515,
|
|
||||||
0x4540, 0x4541, 0x4544, 0x4545, 0x4550, 0x4551, 0x4554, 0x4555,
|
|
||||||
0x5000, 0x5001, 0x5004, 0x5005, 0x5010, 0x5011, 0x5014, 0x5015,
|
|
||||||
0x5040, 0x5041, 0x5044, 0x5045, 0x5050, 0x5051, 0x5054, 0x5055,
|
|
||||||
0x5100, 0x5101, 0x5104, 0x5105, 0x5110, 0x5111, 0x5114, 0x5115,
|
|
||||||
0x5140, 0x5141, 0x5144, 0x5145, 0x5150, 0x5151, 0x5154, 0x5155,
|
|
||||||
0x5400, 0x5401, 0x5404, 0x5405, 0x5410, 0x5411, 0x5414, 0x5415,
|
|
||||||
0x5440, 0x5441, 0x5444, 0x5445, 0x5450, 0x5451, 0x5454, 0x5455,
|
|
||||||
0x5500, 0x5501, 0x5504, 0x5505, 0x5510, 0x5511, 0x5514, 0x5515,
|
|
||||||
0x5540, 0x5541, 0x5544, 0x5545, 0x5550, 0x5551, 0x5554, 0x5555
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static struct TwiddleTable {
|
static struct TwiddleTable {
|
||||||
int32_t width;
|
int32_t width;
|
||||||
int32_t height;
|
int32_t height;
|
||||||
int32_t* table;
|
int32_t* table;
|
||||||
} TWIDDLE_TABLE = {0, 0, NULL};
|
} TWIDDLE_TABLE = {0, 0, NULL};
|
||||||
|
|
||||||
|
|
||||||
int32_t twiddle_recurse(int32_t* table, int32_t stride, int32_t x, int32_t y, int32_t block_size, int32_t idx) {
|
int32_t twiddle_recurse(int32_t* table, int32_t stride, int32_t x, int32_t y, int32_t block_size, int32_t idx) {
|
||||||
int32_t prev_idx = idx;
|
int32_t prev_idx = idx;
|
||||||
if(block_size == 1) {
|
if(block_size == 1) {
|
||||||
table[idx++] = y * stride + x;
|
table[y * stride + x] = idx++;
|
||||||
} else {
|
} else {
|
||||||
block_size = block_size >> 1;
|
block_size = block_size >> 1;
|
||||||
idx += twiddle_recurse(table, stride, x, y, block_size, idx);
|
idx += twiddle_recurse(table, stride, x, y, block_size, idx);
|
||||||
|
@ -97,7 +59,7 @@ int32_t twiddle_recurse(int32_t* table, int32_t stride, int32_t x, int32_t y, in
|
||||||
return (idx - prev_idx);
|
return (idx - prev_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void build_twiddle_table(int32_t* table, int32_t w, int32_t h) {
|
void build_twiddle_table(int32_t w, int32_t h) {
|
||||||
free(TWIDDLE_TABLE.table);
|
free(TWIDDLE_TABLE.table);
|
||||||
TWIDDLE_TABLE.table = (int32_t*) malloc(w * h * sizeof(int32_t));
|
TWIDDLE_TABLE.table = (int32_t*) malloc(w * h * sizeof(int32_t));
|
||||||
TWIDDLE_TABLE.width = w;
|
TWIDDLE_TABLE.width = w;
|
||||||
|
@ -107,11 +69,11 @@ void build_twiddle_table(int32_t* table, int32_t w, int32_t h) {
|
||||||
|
|
||||||
if(w < h) {
|
if(w < h) {
|
||||||
for(int32_t i = 0; i < h; i += w) {
|
for(int32_t i = 0; i < h; i += w) {
|
||||||
idx += twiddle_recurse(table, w, 0, i, w, idx);
|
idx += twiddle_recurse(TWIDDLE_TABLE.table, w, 0, i, w, idx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(int32_t i = 0; i < w; i += h) {
|
for(int32_t i = 0; i < w; i += h) {
|
||||||
idx += twiddle_recurse(table, w, i, 0, h, idx);
|
idx += twiddle_recurse(TWIDDLE_TABLE.table, w, i, 0, h, idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,25 +82,11 @@ void build_twiddle_table(int32_t* table, int32_t w, int32_t h) {
|
||||||
* new 0-based texel location */
|
* new 0-based texel location */
|
||||||
GL_FORCE_INLINE uint32_t twid_location(uint32_t i, uint32_t w, uint32_t h) {
|
GL_FORCE_INLINE uint32_t twid_location(uint32_t i, uint32_t w, uint32_t h) {
|
||||||
if(TWIDDLE_TABLE.width != w || TWIDDLE_TABLE.height != h || !TWIDDLE_TABLE.table) {
|
if(TWIDDLE_TABLE.width != w || TWIDDLE_TABLE.height != h || !TWIDDLE_TABLE.table) {
|
||||||
build_twiddle_table(TWIDDLE_TABLE.table, w, h);
|
build_twiddle_table(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ret = TWIDDLE_TABLE.table[i];
|
uint32_t ret = TWIDDLE_TABLE.table[i];
|
||||||
fprintf(stderr, "%d -> %d\n", i, ret);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
// uint32_t x = i % w;
|
|
||||||
// uint32_t y = i / w;
|
|
||||||
|
|
||||||
// uint32_t ret = MortonTable256[y >> 8] << 17 |
|
|
||||||
// MortonTable256[x >> 8] << 16 |
|
|
||||||
// MortonTable256[y & 0xFF] << 1 |
|
|
||||||
// MortonTable256[x & 0xFF];
|
|
||||||
|
|
||||||
// uint32_t min = (w < h) ? w : h;
|
|
||||||
// uint32_t r = (x / min + y / min) * min * min / 2;
|
|
||||||
// return ret + r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -295,7 +243,6 @@ void _glApplyColorTable(TexturePalette* src) {
|
||||||
|
|
||||||
GLushort i;
|
GLushort i;
|
||||||
GLushort offset = src->size * src->bank;
|
GLushort offset = src->size * src->bank;
|
||||||
|
|
||||||
for(i = 0; i < src->width; ++i) {
|
for(i = 0; i < src->width; ++i) {
|
||||||
GLubyte* entry = &src->data[i * 4];
|
GLubyte* entry = &src->data[i * 4];
|
||||||
|
|
||||||
|
@ -1000,10 +947,12 @@ static GLint _cleanInternalFormat(GLint internalFormat) {
|
||||||
case GL_COLOR_INDEX8_TWID_KOS:
|
case GL_COLOR_INDEX8_TWID_KOS:
|
||||||
case GL_COLOR_INDEX4_TWID_KOS:
|
case GL_COLOR_INDEX4_TWID_KOS:
|
||||||
return internalFormat;
|
return internalFormat;
|
||||||
|
/* Paletted textures are always twiddled.. otherwise they don't work! */
|
||||||
case GL_COLOR_INDEX4_EXT:
|
case GL_COLOR_INDEX4_EXT:
|
||||||
return (TEXTURE_TWIDDLE_ENABLED) ? GL_COLOR_INDEX4_TWID_KOS : internalFormat;
|
return GL_COLOR_INDEX4_TWID_KOS;
|
||||||
case GL_COLOR_INDEX8_EXT:
|
case GL_COLOR_INDEX8_EXT:
|
||||||
return (TEXTURE_TWIDDLE_ENABLED) ? GL_COLOR_INDEX8_TWID_KOS : internalFormat;
|
return GL_COLOR_INDEX8_TWID_KOS;
|
||||||
|
|
||||||
case GL_RGB_TWID_KOS:
|
case GL_RGB_TWID_KOS:
|
||||||
return GL_RGB565_TWID_KOS;
|
return GL_RGB565_TWID_KOS;
|
||||||
case GL_RGBA_TWID_KOS:
|
case GL_RGBA_TWID_KOS:
|
||||||
|
@ -1079,7 +1028,6 @@ static GLuint _determinePVRFormat(GLint internalFormat) {
|
||||||
* that can hold it
|
* that can hold it
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fprintf(stderr, "Internal format -> 0x%x\n", internalFormat);
|
|
||||||
switch(internalFormat) {
|
switch(internalFormat) {
|
||||||
case GL_RGB565_KOS:
|
case GL_RGB565_KOS:
|
||||||
return GPU_TXRFMT_RGB565 | GPU_TXRFMT_NONTWIDDLED;
|
return GPU_TXRFMT_RGB565 | GPU_TXRFMT_NONTWIDDLED;
|
||||||
|
@ -1700,8 +1648,8 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
for(uint32_t i = 0; i < (width * height); ++i) {
|
for(uint32_t i = 0; i < (width * height); ++i) {
|
||||||
uint32_t newLocation = twid_location(i, width, height);
|
uint32_t newLocation = twid_location(i, width, height);
|
||||||
dst = conversionBuffer + (destStride * newLocation);
|
dst = conversionBuffer + (destStride * newLocation);
|
||||||
|
src = data + (sourceStride * i);
|
||||||
conversion(src, dst);
|
conversion(src, dst);
|
||||||
src += sourceStride;
|
|
||||||
}
|
}
|
||||||
} else if(pack) {
|
} else if(pack) {
|
||||||
FASTCPY(conversionBuffer, data, srcBytes);
|
FASTCPY(conversionBuffer, data, srcBytes);
|
||||||
|
|
|
@ -61,7 +61,6 @@ void LoadGLTextures() {
|
||||||
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
||||||
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
|
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
|
||||||
{
|
{
|
||||||
glEnable(GL_TEXTURE_TWIDDLE_KOS);
|
|
||||||
LoadGLTextures();
|
LoadGLTextures();
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 96 KiB |
|
@ -254,6 +254,8 @@ int BMP_Infos(FILE *pFile, uint32_t *width, uint32_t *height)
|
||||||
*width = (uint32_t)BmpInfoHeader.Width;
|
*width = (uint32_t)BmpInfoHeader.Width;
|
||||||
*height = (uint32_t)BmpInfoHeader.Height;
|
*height = (uint32_t)BmpInfoHeader.Height;
|
||||||
|
|
||||||
|
fseek(pFile, BmpInfoHeader.Size + 14, SEEK_SET);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +272,7 @@ int BMP_GetPalette(FILE *pFile)
|
||||||
bitCount = BmpInfoHeader.ClrImportant * sizeof(RGB_QUAD);
|
bitCount = BmpInfoHeader.ClrImportant * sizeof(RGB_QUAD);
|
||||||
|
|
||||||
if (fread(BmpRgbQuad, 1, bitCount, pFile) != bitCount){
|
if (fread(BmpRgbQuad, 1, bitCount, pFile) != bitCount){
|
||||||
|
fprintf(stderr, "Failed to read palette: %d\n", bitCount);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 16 KiB |
Loading…
Reference in New Issue
Block a user