glNormalPointer should accept GL_INT_2_10_10_10_REV, not GL_UNSIGNED_INT_2_...

This commit is contained in:
Luke Benstead 2019-11-27 09:10:10 +00:00
parent 11cd54bc0b
commit 140eec3d92
3 changed files with 27 additions and 20 deletions

View File

@ -104,6 +104,7 @@ static inline GLuint byte_size(GLenum type) {
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_DOUBLE: return sizeof(GLdouble);
case GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GLuint);
case GL_INT_2_10_10_10_REV: return sizeof(GLint);
case GL_FLOAT:
default: return sizeof(GLfloat);
}
@ -142,7 +143,7 @@ static inline float conv_i10_to_norm_float(int i10) {
}
// 10:10:10:2REV format
static void _readVertexData1ui3f(const GLuint* input, GLuint count, GLubyte stride, float* output) {
static void _readVertexData1i3f(const GLuint* input, GLuint count, GLubyte stride, float* output) {
ITERATE(count) {
int inp = *input;
output[0] = conv_i10_to_norm_float((inp) & 0x3ff);
@ -774,9 +775,10 @@ static inline void _readNormalData(const GLuint first, const GLuint count, Verte
}
const GLuint nstride = (NORMAL_POINTER.stride) ? NORMAL_POINTER.stride : NORMAL_POINTER.size * byte_size(NORMAL_POINTER.type);
const void* nptr = ((GLubyte*) NORMAL_POINTER.ptr + (first * nstride));
if(NORMAL_POINTER.size == 3 || NORMAL_POINTER.type == GL_UNSIGNED_INT_2_10_10_10_REV) {
if(NORMAL_POINTER.size == 3 || NORMAL_POINTER.type == GL_INT_2_10_10_10_REV) {
switch(NORMAL_POINTER.type) {
case GL_DOUBLE:
case GL_FLOAT:
@ -794,8 +796,8 @@ static inline void _readNormalData(const GLuint first, const GLuint count, Verte
case GL_UNSIGNED_INT:
_readVertexData3ui3fVE(nptr, count, nstride, extra->nxyz);
break;
case GL_UNSIGNED_INT_2_10_10_10_REV:
_readVertexData1ui3f(nptr, count, nstride, extra->nxyz);
case GL_INT_2_10_10_10_REV:
_readVertexData1i3f(nptr, count, nstride, extra->nxyz);
break;
default:
assert(0 && "Not Implemented");
@ -916,13 +918,13 @@ static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei
if(FAST_PATH_ENABLED) {
/* Copy the pos, uv and color directly in one go */
const GLfloat* pos = VERTEX_POINTER.ptr;
const GLubyte* pos = VERTEX_POINTER.ptr;
Vertex* it = start;
ITERATE(count) {
it->flags = PVR_CMD_VERTEX;
memcpy(it->xyz, pos, FAST_PATH_BYTE_SIZE);
it++;
pos += 32 / sizeof(GLfloat);
pos += VERTEX_POINTER.stride;
}
} else {
_readPositionData(first, count, start);
@ -1259,7 +1261,9 @@ static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type
profiler_checkpoint("generate");
light(target);
if(doLighting) {
light(target);
}
profiler_checkpoint("light");
@ -1507,7 +1511,7 @@ void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid * poin
NORMAL_POINTER.ptr = pointer;
NORMAL_POINTER.stride = stride;
NORMAL_POINTER.type = type;
NORMAL_POINTER.size = 3;
NORMAL_POINTER.size = (type == GL_INT_2_10_10_10_REV) ? 1 : 3;
_glRecalcFastPath();
}

View File

@ -61,7 +61,7 @@ void _glInitImmediateMode(GLuint initial_size) {
NORMAL_ATTRIB.ptr = NORMALS.data;
NORMAL_ATTRIB.stride = 0;
NORMAL_ATTRIB.type = GL_UNSIGNED_INT_2_10_10_10_REV;
NORMAL_ATTRIB.type = GL_INT_2_10_10_10_REV;
NORMAL_ATTRIB.size = 1;
ST_ATTRIB.ptr = ST_COORDS.data;
@ -141,19 +141,21 @@ void APIENTRY glColor3fv(const GLfloat* v) {
COLOR[3] = 255;
}
static inline uint32_t pack_vertex_attribute_vec3_1ui(float x, float y, float z) {
struct attr_bits_10 {
signed int x:10;
};
static inline uint32_t pack_vertex_attribute_vec3_1i(float x, float y, float z) {
const float w = 0.0f;
struct attr_bits_10 xi, yi, zi;
xi.x = x * 511.0f;
yi.x = y * 511.0f;
zi.x = z * 511.0f;
const uint32_t xs = x < 0;
const uint32_t ys = y < 0;
const uint32_t zs = z < 0;
const uint32_t ws = w < 0;
int ret = (xi.x) | (yi.x << 10) | (zi.x << 20);
uint32_t vi =
ws << 31 | ((uint32_t)(w + (ws << 1)) & 1) << 30 |
zs << 29 | ((uint32_t)(z * 511 + (zs << 9)) & 511) << 20 |
ys << 19 | ((uint32_t)(y * 511 + (ys << 9)) & 511) << 10 |
xs << 9 | ((uint32_t)(x * 511 + (xs << 9)) & 511);
return ret;
return vi;
}
void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
@ -172,7 +174,7 @@ void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
vert->bgra[B8IDX] = COLOR[2];
vert->bgra[A8IDX] = COLOR[3];
*n = pack_vertex_attribute_vec3_1ui(NORMAL[0], NORMAL[1], NORMAL[2]);
*n = pack_vertex_attribute_vec3_1i(NORMAL[0], NORMAL[1], NORMAL[2]);
memcpy(st, ST_COORD, sizeof(GLfloat) * 2);
}

View File

@ -336,6 +336,7 @@ __BEGIN_DECLS
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
#define GL_INT_2_10_10_10_REV 0x8D9F
#define GL_COLOR_INDEX 0x1900
#define GL_RED 0x1903