Compare commits
9 Commits
texture-re
...
master
Author | SHA1 | Date | |
---|---|---|---|
2601afb5f3 | |||
|
0efe4c6cef | ||
|
744dfb32f7 | ||
|
79172452f2 | ||
|
420e2d75f2 | ||
|
202f546848 | ||
|
d054dde785 | ||
|
00b4468928 | ||
|
f0d799d14f |
102
GL/draw.c
102
GL/draw.c
|
@ -3,10 +3,36 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "private.h"
|
||||
#include "platform.h"
|
||||
|
||||
GLushort _quantize( GLfloat v ) {
|
||||
union { GLfloat f; GLuint ui; } u = {v};
|
||||
GLuint ui = u.ui;
|
||||
|
||||
int s = (ui >> 16) & 0x8000;
|
||||
int em = ui & 0x7fffffff;
|
||||
|
||||
int h = (em - (112 << 23) + (1 << 12)) >> 13;
|
||||
h = (em < (113 << 23)) ? 0 : h;
|
||||
h = (em >= (143 << 23)) ? 0x7c00 : h;
|
||||
h = (em > (255 << 23)) ? 0x7e00 : h;
|
||||
|
||||
return (GLushort)(s | h);
|
||||
}
|
||||
GLfloat _dequantize( GLushort h ) {
|
||||
GLuint s = (GLuint) (h & 0x8000) << 16;
|
||||
int em = h & 0x7fff;
|
||||
int r = (em + (112 << 10)) << 13;
|
||||
r = (em < (1 << 10)) ? 0 : r;
|
||||
r += (em >= (31 << 10)) ? (112 << 23) : 0;
|
||||
|
||||
union { GLfloat f; GLuint ui; } u;
|
||||
u.ui = s | r;
|
||||
return u.f;
|
||||
}
|
||||
|
||||
AttribPointerList ATTRIB_POINTERS;
|
||||
GLuint ENABLED_VERTEX_ATTRIBUTES = 0;
|
||||
|
@ -62,6 +88,7 @@ GL_FORCE_INLINE GLsizei byte_size(GLenum type) {
|
|||
case GL_INT: return sizeof(GLint);
|
||||
case GL_UNSIGNED_INT: return sizeof(GLuint);
|
||||
case GL_DOUBLE: return sizeof(GLdouble);
|
||||
case GL_HALF_FLOAT: return sizeof(GLhalf);
|
||||
case GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GLuint);
|
||||
case GL_FLOAT:
|
||||
default: return sizeof(GLfloat);
|
||||
|
@ -108,6 +135,15 @@ static void _readVertexData3us3f(const GLubyte* in, GLubyte* out) {
|
|||
output[2] = input[2];
|
||||
}
|
||||
|
||||
static void _readVertexData3usq3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = _dequantize(input[0]);
|
||||
output[1] = _dequantize(input[1]);
|
||||
output[2] = _dequantize(input[2]);
|
||||
}
|
||||
|
||||
static void _readVertexData3ui3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) in;
|
||||
float* output = (float*) out;
|
||||
|
@ -126,6 +162,15 @@ static void _readVertexData3ub3f(const GLubyte* input, GLubyte* out) {
|
|||
output[2] = input[2] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
}
|
||||
|
||||
static void _readVertexData3f16_3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLhalf* input = (const GLhalf*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = input[2];
|
||||
}
|
||||
|
||||
static void _readVertexData2f2f(const GLubyte* in, GLubyte* out) {
|
||||
vec2cpy(out, in);
|
||||
}
|
||||
|
@ -159,8 +204,25 @@ static void _readVertexData2us2f(const GLubyte* in, GLubyte* out) {
|
|||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[0] = (float)input[0] / SHRT_MAX;
|
||||
output[1] = (float)input[1] / SHRT_MAX;
|
||||
}
|
||||
|
||||
static void _readVertexData2usq3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = _dequantize(input[0]);
|
||||
output[1] = _dequantize(input[1]);
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2usq2f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = _dequantize(input[0]);
|
||||
output[1] = _dequantize(input[1]);
|
||||
}
|
||||
|
||||
static void _readVertexData2ui2f(const GLubyte* in, GLubyte* out) {
|
||||
|
@ -178,6 +240,14 @@ static void _readVertexData2ub2f(const GLubyte* input, GLubyte* out) {
|
|||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
}
|
||||
|
||||
static void _readVertexData2f16_2f(const GLubyte* in, GLubyte* out) {
|
||||
const GLhalf* input = (const GLhalf*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
}
|
||||
|
||||
static void _readVertexData2ui3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) in;
|
||||
float* output = (float*) out;
|
||||
|
@ -187,6 +257,15 @@ static void _readVertexData2ui3f(const GLubyte* in, GLubyte* out) {
|
|||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2f16_3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLhalf* input = (const GLhalf*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData4ubARGB(const GLubyte* input, GLubyte* output) {
|
||||
output[R8IDX] = input[0];
|
||||
output[G8IDX] = input[1];
|
||||
|
@ -492,14 +571,17 @@ ReadPositionFunc calcReadPositionFunc() {
|
|||
case GL_FLOAT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3f3f:
|
||||
_readVertexData2f3f;
|
||||
case GL_HALF_FLOAT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3f16_3f:
|
||||
_readVertexData2f16_3f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3ub3f:
|
||||
_readVertexData2ub3f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3us3f:
|
||||
_readVertexData2us3f;
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3usq3f:
|
||||
_readVertexData2usq3f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3ui3f:
|
||||
|
@ -517,12 +599,14 @@ ReadUVFunc calcReadUVFunc() {
|
|||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData2f2f;
|
||||
case GL_HALF_FLOAT:
|
||||
return _readVertexData2f16_2f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData2ub2f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData2us2f;
|
||||
return _readVertexData2usq2f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData2ui2f;
|
||||
|
@ -539,12 +623,14 @@ ReadUVFunc calcReadSTFunc() {
|
|||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData2f2f;
|
||||
case GL_HALF_FLOAT:
|
||||
return _readVertexData2f16_2f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData2ub2f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData2us2f;
|
||||
return _readVertexData2usq2f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData2ui2f;
|
||||
|
@ -561,6 +647,8 @@ ReadNormalFunc calcReadNormalFunc() {
|
|||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData3f3f;
|
||||
case GL_HALF_FLOAT:
|
||||
return _readVertexData3f16_3f;
|
||||
break;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
|
@ -568,7 +656,7 @@ ReadNormalFunc calcReadNormalFunc() {
|
|||
break;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData3us3f;
|
||||
return _readVertexData3usq3f;
|
||||
break;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
|
|
|
@ -409,7 +409,7 @@ GL_FORCE_INLINE void vec3f_normalize_sh4(float *v){
|
|||
void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
|
||||
GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy,
|
||||
GLfloat upz) {
|
||||
GLfloat m [16];
|
||||
GLfloat m [16] __attribute__((aligned(32)));
|
||||
GLfloat f [3];
|
||||
GLfloat u [3];
|
||||
GLfloat s [3];
|
||||
|
|
18
GL/texture.c
18
GL/texture.c
|
@ -905,21 +905,6 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
|
|||
_glGPUStateMarkDirty();
|
||||
}
|
||||
|
||||
static GLboolean isTwiddledInternalFormat(GLint internalFormat) {
|
||||
switch(internalFormat) {
|
||||
case GL_RGB565_TWID_KOS:
|
||||
case GL_ARGB4444_TWID_KOS:
|
||||
case GL_ARGB1555_TWID_KOS:
|
||||
case GL_COLOR_INDEX8_TWID_KOS:
|
||||
case GL_COLOR_INDEX4_TWID_KOS:
|
||||
case GL_RGB_TWID_KOS:
|
||||
case GL_RGBA_TWID_KOS:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an internal format, and returns a GL format matching how we'd store
|
||||
* it internally, so it'll return one of the following:
|
||||
|
@ -1626,7 +1611,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
|||
|
||||
uint8_t src_value = (i % 2) == 0 ? (*src >> 4) : (*src & 0xF);
|
||||
|
||||
if(newLocation % 2 == 0) {
|
||||
if(newLocation % 2 == 1) {
|
||||
*dst = (*dst & 0xF) | (src_value << 4);
|
||||
} else {
|
||||
*dst = (*dst & 0xF0) | (src_value & 0xF);
|
||||
|
@ -2059,7 +2044,6 @@ static void update_data_pointer(void* src, void* dst, void*) {
|
|||
for(size_t id = 0; id < MAX_TEXTURE_COUNT; id++){
|
||||
TextureObject* txr = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, id);
|
||||
if(txr && txr->data == src) {
|
||||
fprintf(stderr, "Defrag moved 0x%x -> 0x%x\n", src, dst);
|
||||
gl_assert(txr->index == id);
|
||||
txr->data = dst;
|
||||
return;
|
||||
|
|
|
@ -19,6 +19,10 @@ __BEGIN_DECLS
|
|||
|
||||
#include <math.h>
|
||||
|
||||
#if __STDCPP_FLOAT16_T__
|
||||
#include <stdfloat>
|
||||
#endif
|
||||
|
||||
/* Primitive Types taken from GL for compatability */
|
||||
/* Not all types are implemented in Open GL DC V.1.0 */
|
||||
#define GL_POINTS 0x0000
|
||||
|
@ -305,6 +309,7 @@ __BEGIN_DECLS
|
|||
#define GL_UNSIGNED_INT 0x1405
|
||||
#define GL_FLOAT 0x1406
|
||||
#define GL_DOUBLE 0x140A
|
||||
#define GL_HALF_FLOAT 0x140B
|
||||
#define GL_2_BYTES 0x1407
|
||||
#define GL_3_BYTES 0x1408
|
||||
#define GL_4_BYTES 0x1409
|
||||
|
@ -359,7 +364,7 @@ __BEGIN_DECLS
|
|||
#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
|
||||
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
|
||||
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
|
||||
|
||||
#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
|
||||
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
|
||||
|
||||
#define GL_COLOR_INDEX 0x1900
|
||||
|
@ -396,6 +401,7 @@ __BEGIN_DECLS
|
|||
#define GL_INTENSITY12 0x804C
|
||||
#define GL_INTENSITY16 0x804D
|
||||
|
||||
#define GL_BGR 0x80E0
|
||||
#define GL_BGRA 0x80E1
|
||||
#define GL_INTENSITY 0x8049
|
||||
#define GL_RGB4 0x804F
|
||||
|
@ -460,6 +466,12 @@ __BEGIN_DECLS
|
|||
#define GL_FALSE 0
|
||||
#define GL_TRUE 1
|
||||
|
||||
#if __STDCPP_FLOAT16_T__
|
||||
#define GLhalf std::float16_t
|
||||
#else
|
||||
#define GLhalf unsigned short
|
||||
#endif
|
||||
|
||||
/* Stubs for portability */
|
||||
#define GL_LINE_SMOOTH 0x0B20
|
||||
#define GL_ALPHA_TEST 0x0BC0
|
||||
|
|
|
@ -59,10 +59,10 @@ int ImageLoad(char *filename, Image *image) {
|
|||
|
||||
fread(&header, sizeof(header), 1, file);
|
||||
|
||||
GLboolean twiddled = (header.type & (1 << 25)) < 1;
|
||||
GLboolean compressed = (header.type & (1 << 29)) > 0;
|
||||
GLboolean mipmapped = (header.type & (1 << 30)) > 0;
|
||||
GLboolean strided = (header.type & (1 << 24)) > 0;
|
||||
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
||||
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
||||
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
||||
GLboolean strided = (header.type & (1 << 25)) > 0;
|
||||
GLuint format = (header.type >> 27) & 0b111;
|
||||
|
||||
image->data = (char *) malloc (header.size);
|
||||
|
|
Loading…
Reference in New Issue
Block a user