Calculate read attribute functions when attribute states changes, instead of at every draw call
This commit is contained in:
parent
2a2849d5e9
commit
bdecf90d64
@ -68,6 +68,7 @@ set(
|
||||
containers/aligned_vector.c
|
||||
containers/named_array.c
|
||||
containers/stack.c
|
||||
GL/attributes.c
|
||||
GL/draw.c
|
||||
GL/error.c
|
||||
GL/flush.c
|
||||
|
567
GL/attributes.c
Normal file
567
GL/attributes.c
Normal file
@ -0,0 +1,567 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "private.h"
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
AttribPointerList ATTRIB_POINTERS;
|
||||
GLuint ENABLED_VERTEX_ATTRIBUTES = 0;
|
||||
|
||||
static const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
||||
|
||||
extern inline GLuint _glRecalcFastPath();
|
||||
|
||||
GL_FORCE_INLINE GLsizei byte_size(GLenum type) {
|
||||
switch(type) {
|
||||
case GL_BYTE: return sizeof(GLbyte);
|
||||
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
|
||||
case GL_SHORT: return sizeof(GLshort);
|
||||
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
|
||||
case GL_INT: return sizeof(GLint);
|
||||
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_FLOAT:
|
||||
default: return sizeof(GLfloat);
|
||||
}
|
||||
}
|
||||
|
||||
static void _readVertexData3f3f(const GLubyte* __restrict__ in, GLubyte* __restrict__ out) {
|
||||
vec3cpy(out, in);
|
||||
}
|
||||
|
||||
// 10:10:10:2REV format
|
||||
static void _readVertexData1i3f(const GLubyte* in, GLubyte* out) {
|
||||
static const float MULTIPLIER = 1.0f / 1023.0f;
|
||||
|
||||
GLfloat* output = (GLfloat*) out;
|
||||
|
||||
union {
|
||||
int value;
|
||||
struct {
|
||||
signed int x: 10;
|
||||
signed int y: 10;
|
||||
signed int z: 10;
|
||||
signed int w: 2;
|
||||
} bits;
|
||||
} input;
|
||||
|
||||
input.value = *((const GLint*) in);
|
||||
|
||||
output[0] = (2.0f * (float) input.bits.x + 1.0f) * MULTIPLIER;
|
||||
output[1] = (2.0f * (float) input.bits.y + 1.0f) * MULTIPLIER;
|
||||
output[2] = (2.0f * (float) input.bits.z + 1.0f) * MULTIPLIER;
|
||||
}
|
||||
|
||||
static void _readVertexData3us3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = input[2];
|
||||
}
|
||||
|
||||
static void _readVertexData3ui3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = input[2];
|
||||
}
|
||||
|
||||
|
||||
static void _readVertexData3ub3f(const GLubyte* input, GLubyte* out) {
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[2] = input[2] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
}
|
||||
|
||||
static void _readVertexData2f2f(const GLubyte* in, GLubyte* out) {
|
||||
vec2cpy(out, in);
|
||||
}
|
||||
|
||||
static void _readVertexData2f3f(const GLubyte* in, GLubyte* out) {
|
||||
const float* input = (const float*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
vec2cpy(output, input);
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2ub3f(const GLubyte* input, GLubyte* out) {
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2us3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2us2f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = (float)input[0] / SHRT_MAX;
|
||||
output[1] = (float)input[1] / SHRT_MAX;
|
||||
}
|
||||
|
||||
static void _readVertexData2ui2f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
}
|
||||
|
||||
static void _readVertexData2ub2f(const GLubyte* input, GLubyte* out) {
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
}
|
||||
|
||||
static void _readVertexData2ui3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) 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];
|
||||
output[B8IDX] = input[2];
|
||||
output[A8IDX] = input[3];
|
||||
}
|
||||
|
||||
static void _readVertexData4fARGB(const GLubyte* in, GLubyte* output) {
|
||||
const float* input = (const float*) in;
|
||||
|
||||
output[R8IDX] = (GLubyte) clamp(input[0] * 255.0f, 0, 255);
|
||||
output[G8IDX] = (GLubyte) clamp(input[1] * 255.0f, 0, 255);
|
||||
output[B8IDX] = (GLubyte) clamp(input[2] * 255.0f, 0, 255);
|
||||
output[A8IDX] = (GLubyte) clamp(input[3] * 255.0f, 0, 255);
|
||||
}
|
||||
|
||||
static void _readVertexData3fARGB(const GLubyte* in, GLubyte* output) {
|
||||
const float* input = (const float*) in;
|
||||
|
||||
output[R8IDX] = (GLubyte) clamp(input[0] * 255.0f, 0, 255);
|
||||
output[G8IDX] = (GLubyte) clamp(input[1] * 255.0f, 0, 255);
|
||||
output[B8IDX] = (GLubyte) clamp(input[2] * 255.0f, 0, 255);
|
||||
output[A8IDX] = 255;
|
||||
}
|
||||
|
||||
static void _readVertexData3ubARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
||||
output[R8IDX] = input[0];
|
||||
output[G8IDX] = input[1];
|
||||
output[B8IDX] = input[2];
|
||||
output[A8IDX] = 255;
|
||||
}
|
||||
|
||||
static void _readVertexData4ubRevARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
||||
argbcpy(output, input);
|
||||
}
|
||||
|
||||
static void _readVertexData4fRevARGB(const GLubyte* __restrict__ in, GLubyte* __restrict__ output) {
|
||||
const float* input = (const float*) in;
|
||||
|
||||
output[0] = (GLubyte) clamp(input[0] * 255.0f, 0, 255);
|
||||
output[1] = (GLubyte) clamp(input[1] * 255.0f, 0, 255);
|
||||
output[2] = (GLubyte) clamp(input[2] * 255.0f, 0, 255);
|
||||
output[3] = (GLubyte) clamp(input[3] * 255.0f, 0, 255);
|
||||
}
|
||||
|
||||
static void _fillWithNegZVE(const GLubyte* __restrict__ input, GLubyte* __restrict__ out) {
|
||||
_GL_UNUSED(input);
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} V;
|
||||
|
||||
static const V NegZ = {0.0f, 0.0f, -1.0f};
|
||||
|
||||
*((V*) out) = NegZ;
|
||||
}
|
||||
|
||||
static void _fillWhiteARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
||||
_GL_UNUSED(input);
|
||||
*((uint32_t*) output) = ~0;
|
||||
}
|
||||
|
||||
static void _fillZero2f(const GLubyte* __restrict__ input, GLubyte* __restrict__ out) {
|
||||
_GL_UNUSED(input);
|
||||
memset(out, 0, sizeof(float) * 2);
|
||||
}
|
||||
|
||||
static void _readVertexData3usARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData3uiARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4usARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4uiARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4usRevARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4uiRevARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static ReadAttributeFunc calcReadDiffuseFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG) != DIFFUSE_ENABLED_FLAG) {
|
||||
/* Just fill the whole thing white if the attribute is disabled */
|
||||
return _fillWhiteARGB;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.colour.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3fARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4fARGB:
|
||||
_readVertexData4fRevARGB;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3ubARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4ubARGB:
|
||||
_readVertexData4ubRevARGB;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3usARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4usARGB:
|
||||
_readVertexData4usRevARGB;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3uiARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4uiARGB:
|
||||
_readVertexData4uiRevARGB;
|
||||
}
|
||||
}
|
||||
|
||||
static ReadAttributeFunc calcReadPositionFunc() {
|
||||
switch(ATTRIB_POINTERS.vertex.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3f3f:
|
||||
_readVertexData2f3f;
|
||||
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;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3ui3f:
|
||||
_readVertexData2ui3f;
|
||||
}
|
||||
}
|
||||
|
||||
static ReadAttributeFunc calcReadUVFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) != UV_ENABLED_FLAG) {
|
||||
return _fillZero2f;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.uv.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData2f2f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData2ub2f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData2us2f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData2ui2f;
|
||||
}
|
||||
}
|
||||
|
||||
static ReadAttributeFunc calcReadSTFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG) {
|
||||
return _fillZero2f;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.st.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData2f2f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData2ub2f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData2us2f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData2ui2f;
|
||||
}
|
||||
}
|
||||
|
||||
static ReadAttributeFunc calcReadNormalFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG) != NORMAL_ENABLED_FLAG) {
|
||||
return _fillWithNegZVE;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.normal.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData3f3f;
|
||||
break;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData3ub3f;
|
||||
break;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData3us3f;
|
||||
break;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData3ui3f;
|
||||
break;
|
||||
case GL_UNSIGNED_INT_2_10_10_10_REV:
|
||||
return _readVertexData1i3f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void APIENTRY glEnableClientState(GLenum cap) {
|
||||
TRACE();
|
||||
|
||||
switch(cap) {
|
||||
case GL_VERTEX_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES |= VERTEX_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_COLOR_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES |= DIFFUSE_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_NORMAL_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES |= NORMAL_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
(ACTIVE_CLIENT_TEXTURE) ?
|
||||
(ENABLED_VERTEX_ATTRIBUTES |= ST_ENABLED_FLAG):
|
||||
(ENABLED_VERTEX_ATTRIBUTES |= UV_ENABLED_FLAG);
|
||||
break;
|
||||
default:
|
||||
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
||||
}
|
||||
|
||||
/* It's possible that we called glVertexPointer and friends before
|
||||
* calling glEnableClientState, so we should recheck to make sure
|
||||
* everything is in the right format with this new information */
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glDisableClientState(GLenum cap) {
|
||||
TRACE();
|
||||
|
||||
switch(cap) {
|
||||
case GL_VERTEX_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES &= ~VERTEX_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_COLOR_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES &= ~DIFFUSE_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_NORMAL_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES &= ~NORMAL_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
(ACTIVE_CLIENT_TEXTURE) ?
|
||||
(ENABLED_VERTEX_ATTRIBUTES &= ~ST_ENABLED_FLAG):
|
||||
(ENABLED_VERTEX_ATTRIBUTES &= ~UV_ENABLED_FLAG);
|
||||
break;
|
||||
default:
|
||||
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
||||
}
|
||||
|
||||
/* State changed, recalculate */
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
|
||||
// Used to avoid checking and updating attribute related state unless necessary
|
||||
GL_FORCE_INLINE GLboolean _glStateUnchanged(AttribPointer* p, GLint size, GLenum type, GLsizei stride) {
|
||||
return (p->size == size && p->type == type && p->stride == stride);
|
||||
}
|
||||
|
||||
void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
stride = (stride) ? stride : size * byte_size(type);
|
||||
AttribPointer* tointer = (ACTIVE_CLIENT_TEXTURE == 0) ? &ATTRIB_POINTERS.uv : &ATTRIB_POINTERS.st;
|
||||
tointer->ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(tointer, size, type, stride)) return;
|
||||
|
||||
if(size < 1 || size > 4) {
|
||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
tointer->stride = stride;
|
||||
tointer->type = type;
|
||||
tointer->size = size;
|
||||
|
||||
ATTRIB_POINTERS.uv_func = calcReadUVFunc();
|
||||
ATTRIB_POINTERS.st_func = calcReadSTFunc();
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
stride = (stride) ? stride : (size * byte_size(type));
|
||||
ATTRIB_POINTERS.vertex.ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(&ATTRIB_POINTERS.vertex, size, type, stride)) return;
|
||||
|
||||
if(size < 2 || size > 4) {
|
||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ATTRIB_POINTERS.vertex.stride = stride;
|
||||
ATTRIB_POINTERS.vertex.type = type;
|
||||
ATTRIB_POINTERS.vertex.size = size;
|
||||
ATTRIB_POINTERS.vertex_func = calcReadPositionFunc();
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
stride = (stride) ? stride : ((size == GL_BGRA) ? 4 : size) * byte_size(type);
|
||||
ATTRIB_POINTERS.colour.ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(&ATTRIB_POINTERS.colour, size, type, stride)) return;
|
||||
|
||||
if(size != 3 && size != 4 && size != GL_BGRA) {
|
||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ATTRIB_POINTERS.colour.type = type;
|
||||
ATTRIB_POINTERS.colour.size = size;
|
||||
ATTRIB_POINTERS.colour.stride = stride;
|
||||
ATTRIB_POINTERS.colour_func = calcReadDiffuseFunc();
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
GLint validTypes[] = {
|
||||
GL_DOUBLE,
|
||||
GL_FLOAT,
|
||||
GL_BYTE,
|
||||
GL_UNSIGNED_BYTE,
|
||||
GL_INT,
|
||||
GL_UNSIGNED_INT,
|
||||
GL_UNSIGNED_INT_2_10_10_10_REV,
|
||||
0
|
||||
};
|
||||
|
||||
stride = (stride) ? stride : ATTRIB_POINTERS.normal.size * byte_size(type);
|
||||
ATTRIB_POINTERS.normal.ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(&ATTRIB_POINTERS.normal, 3, type, stride)) return;
|
||||
|
||||
if(_glCheckValidEnum(type, validTypes, __func__) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ATTRIB_POINTERS.normal.size = (type == GL_UNSIGNED_INT_2_10_10_10_REV) ? 1 : 3;
|
||||
ATTRIB_POINTERS.normal.stride = stride;
|
||||
ATTRIB_POINTERS.normal.type = type;
|
||||
ATTRIB_POINTERS.normal_func = calcReadNormalFunc();
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
|
||||
void _glInitAttributePointers() {
|
||||
TRACE();
|
||||
|
||||
ATTRIB_POINTERS.vertex.ptr = NULL;
|
||||
ATTRIB_POINTERS.vertex.stride = 0;
|
||||
ATTRIB_POINTERS.vertex.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.vertex.size = 4;
|
||||
ATTRIB_POINTERS.vertex_func = calcReadPositionFunc();
|
||||
|
||||
ATTRIB_POINTERS.colour.ptr = NULL;
|
||||
ATTRIB_POINTERS.colour.stride = 0;
|
||||
ATTRIB_POINTERS.colour.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.colour.size = 4;
|
||||
ATTRIB_POINTERS.colour_func = calcReadDiffuseFunc();
|
||||
|
||||
ATTRIB_POINTERS.uv.ptr = NULL;
|
||||
ATTRIB_POINTERS.uv.stride = 0;
|
||||
ATTRIB_POINTERS.uv.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.uv.size = 4;
|
||||
ATTRIB_POINTERS.uv_func = calcReadUVFunc();
|
||||
|
||||
ATTRIB_POINTERS.st.ptr = NULL;
|
||||
ATTRIB_POINTERS.st.stride = 0;
|
||||
ATTRIB_POINTERS.st.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.st.size = 4;
|
||||
ATTRIB_POINTERS.st_func = calcReadSTFunc();
|
||||
|
||||
ATTRIB_POINTERS.normal.ptr = NULL;
|
||||
ATTRIB_POINTERS.normal.stride = 0;
|
||||
ATTRIB_POINTERS.normal.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.normal.size = 3;
|
||||
ATTRIB_POINTERS.normal_func = calcReadNormalFunc();
|
||||
}
|
637
GL/draw.c
637
GL/draw.c
@ -8,15 +8,8 @@
|
||||
#include "private.h"
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
AttribPointerList ATTRIB_POINTERS;
|
||||
GLuint ENABLED_VERTEX_ATTRIBUTES = 0;
|
||||
GLuint FAST_PATH_ENABLED = GL_FALSE;
|
||||
|
||||
static GLubyte ACTIVE_CLIENT_TEXTURE = 0;
|
||||
static const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
||||
|
||||
extern inline GLuint _glRecalcFastPath();
|
||||
GLubyte ACTIVE_CLIENT_TEXTURE;
|
||||
|
||||
extern GLboolean AUTOSORT_ENABLED;
|
||||
|
||||
@ -25,296 +18,6 @@ extern GLboolean AUTOSORT_ENABLED;
|
||||
while(i--)
|
||||
|
||||
|
||||
void _glInitAttributePointers() {
|
||||
TRACE();
|
||||
|
||||
ATTRIB_POINTERS.vertex.ptr = NULL;
|
||||
ATTRIB_POINTERS.vertex.stride = 0;
|
||||
ATTRIB_POINTERS.vertex.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.vertex.size = 4;
|
||||
|
||||
ATTRIB_POINTERS.colour.ptr = NULL;
|
||||
ATTRIB_POINTERS.colour.stride = 0;
|
||||
ATTRIB_POINTERS.colour.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.colour.size = 4;
|
||||
|
||||
ATTRIB_POINTERS.uv.ptr = NULL;
|
||||
ATTRIB_POINTERS.uv.stride = 0;
|
||||
ATTRIB_POINTERS.uv.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.uv.size = 4;
|
||||
|
||||
ATTRIB_POINTERS.st.ptr = NULL;
|
||||
ATTRIB_POINTERS.st.stride = 0;
|
||||
ATTRIB_POINTERS.st.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.st.size = 4;
|
||||
|
||||
ATTRIB_POINTERS.normal.ptr = NULL;
|
||||
ATTRIB_POINTERS.normal.stride = 0;
|
||||
ATTRIB_POINTERS.normal.type = GL_FLOAT;
|
||||
ATTRIB_POINTERS.normal.size = 3;
|
||||
}
|
||||
|
||||
GL_FORCE_INLINE GLsizei byte_size(GLenum type) {
|
||||
switch(type) {
|
||||
case GL_BYTE: return sizeof(GLbyte);
|
||||
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
|
||||
case GL_SHORT: return sizeof(GLshort);
|
||||
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
|
||||
case GL_INT: return sizeof(GLint);
|
||||
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_FLOAT:
|
||||
default: return sizeof(GLfloat);
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*FloatParseFunc)(GLfloat* out, const GLubyte* in);
|
||||
typedef void (*ByteParseFunc)(GLubyte* out, const GLubyte* in);
|
||||
typedef void (*PolyBuildFunc)(Vertex* first, Vertex* previous, Vertex* vertex, Vertex* next, const GLsizei i);
|
||||
|
||||
static void _readVertexData3f3f(const GLubyte* __restrict__ in, GLubyte* __restrict__ out) {
|
||||
vec3cpy(out, in);
|
||||
}
|
||||
|
||||
// 10:10:10:2REV format
|
||||
static void _readVertexData1i3f(const GLubyte* in, GLubyte* out) {
|
||||
static const float MULTIPLIER = 1.0f / 1023.0f;
|
||||
|
||||
GLfloat* output = (GLfloat*) out;
|
||||
|
||||
union {
|
||||
int value;
|
||||
struct {
|
||||
signed int x: 10;
|
||||
signed int y: 10;
|
||||
signed int z: 10;
|
||||
signed int w: 2;
|
||||
} bits;
|
||||
} input;
|
||||
|
||||
input.value = *((const GLint*) in);
|
||||
|
||||
output[0] = (2.0f * (float) input.bits.x + 1.0f) * MULTIPLIER;
|
||||
output[1] = (2.0f * (float) input.bits.y + 1.0f) * MULTIPLIER;
|
||||
output[2] = (2.0f * (float) input.bits.z + 1.0f) * MULTIPLIER;
|
||||
}
|
||||
|
||||
static void _readVertexData3us3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = input[2];
|
||||
}
|
||||
|
||||
static void _readVertexData3ui3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = input[2];
|
||||
}
|
||||
|
||||
|
||||
static void _readVertexData3ub3f(const GLubyte* input, GLubyte* out) {
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[2] = input[2] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
}
|
||||
|
||||
static void _readVertexData2f2f(const GLubyte* in, GLubyte* out) {
|
||||
vec2cpy(out, in);
|
||||
}
|
||||
|
||||
static void _readVertexData2f3f(const GLubyte* in, GLubyte* out) {
|
||||
const float* input = (const float*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
vec2cpy(output, input);
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2ub3f(const GLubyte* input, GLubyte* out) {
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2us3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
output[2] = 0.0f;
|
||||
}
|
||||
|
||||
static void _readVertexData2us2f(const GLubyte* in, GLubyte* out) {
|
||||
const GLushort* input = (const GLushort*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = (float)input[0] / SHRT_MAX;
|
||||
output[1] = (float)input[1] / SHRT_MAX;
|
||||
}
|
||||
|
||||
static void _readVertexData2ui2f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) in;
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0];
|
||||
output[1] = input[1];
|
||||
}
|
||||
|
||||
static void _readVertexData2ub2f(const GLubyte* input, GLubyte* out) {
|
||||
float* output = (float*) out;
|
||||
|
||||
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
||||
}
|
||||
|
||||
static void _readVertexData2ui3f(const GLubyte* in, GLubyte* out) {
|
||||
const GLuint* input = (const GLuint*) 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];
|
||||
output[B8IDX] = input[2];
|
||||
output[A8IDX] = input[3];
|
||||
}
|
||||
|
||||
static void _readVertexData4fARGB(const GLubyte* in, GLubyte* output) {
|
||||
const float* input = (const float*) in;
|
||||
|
||||
output[R8IDX] = (GLubyte) clamp(input[0] * 255.0f, 0, 255);
|
||||
output[G8IDX] = (GLubyte) clamp(input[1] * 255.0f, 0, 255);
|
||||
output[B8IDX] = (GLubyte) clamp(input[2] * 255.0f, 0, 255);
|
||||
output[A8IDX] = (GLubyte) clamp(input[3] * 255.0f, 0, 255);
|
||||
}
|
||||
|
||||
static void _readVertexData3fARGB(const GLubyte* in, GLubyte* output) {
|
||||
const float* input = (const float*) in;
|
||||
|
||||
output[R8IDX] = (GLubyte) clamp(input[0] * 255.0f, 0, 255);
|
||||
output[G8IDX] = (GLubyte) clamp(input[1] * 255.0f, 0, 255);
|
||||
output[B8IDX] = (GLubyte) clamp(input[2] * 255.0f, 0, 255);
|
||||
output[A8IDX] = 255;
|
||||
}
|
||||
|
||||
static void _readVertexData3ubARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
||||
output[R8IDX] = input[0];
|
||||
output[G8IDX] = input[1];
|
||||
output[B8IDX] = input[2];
|
||||
output[A8IDX] = 255;
|
||||
}
|
||||
|
||||
static void _readVertexData4ubRevARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
||||
argbcpy(output, input);
|
||||
}
|
||||
|
||||
static void _readVertexData4fRevARGB(const GLubyte* __restrict__ in, GLubyte* __restrict__ output) {
|
||||
const float* input = (const float*) in;
|
||||
|
||||
output[0] = (GLubyte) clamp(input[0] * 255.0f, 0, 255);
|
||||
output[1] = (GLubyte) clamp(input[1] * 255.0f, 0, 255);
|
||||
output[2] = (GLubyte) clamp(input[2] * 255.0f, 0, 255);
|
||||
output[3] = (GLubyte) clamp(input[3] * 255.0f, 0, 255);
|
||||
}
|
||||
|
||||
static void _fillWithNegZVE(const GLubyte* __restrict__ input, GLubyte* __restrict__ out) {
|
||||
_GL_UNUSED(input);
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} V;
|
||||
|
||||
static const V NegZ = {0.0f, 0.0f, -1.0f};
|
||||
|
||||
*((V*) out) = NegZ;
|
||||
}
|
||||
|
||||
static void _fillWhiteARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
||||
_GL_UNUSED(input);
|
||||
*((uint32_t*) output) = ~0;
|
||||
}
|
||||
|
||||
static void _fillZero2f(const GLubyte* __restrict__ input, GLubyte* __restrict__ out) {
|
||||
_GL_UNUSED(input);
|
||||
memset(out, 0, sizeof(float) * 2);
|
||||
}
|
||||
|
||||
static void _readVertexData3usARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData3uiARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4usARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4uiARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4usRevARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
static void _readVertexData4uiRevARGB(const GLubyte* input, GLubyte* output) {
|
||||
_GL_UNUSED(input);
|
||||
_GL_UNUSED(output);
|
||||
gl_assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
GLuint* _glGetEnabledAttributes() {
|
||||
return &ENABLED_VERTEX_ATTRIBUTES;
|
||||
}
|
||||
|
||||
AttribPointer* _glGetVertexAttribPointer() {
|
||||
return &ATTRIB_POINTERS.vertex;
|
||||
}
|
||||
|
||||
AttribPointer* _glGetDiffuseAttribPointer() {
|
||||
return &ATTRIB_POINTERS.colour;
|
||||
}
|
||||
|
||||
AttribPointer* _glGetNormalAttribPointer() {
|
||||
return &ATTRIB_POINTERS.normal;
|
||||
}
|
||||
|
||||
AttribPointer* _glGetUVAttribPointer() {
|
||||
return &ATTRIB_POINTERS.uv;
|
||||
}
|
||||
|
||||
AttribPointer* _glGetSTAttribPointer() {
|
||||
return &ATTRIB_POINTERS.st;
|
||||
}
|
||||
|
||||
typedef GLuint (*IndexParseFunc)(const GLubyte* in);
|
||||
|
||||
static inline GLuint _parseUByteIndex(const GLubyte* in) {
|
||||
@ -329,6 +32,14 @@ static inline GLuint _parseUShortIndex(const GLubyte* in) {
|
||||
return *((GLshort*) in);
|
||||
}
|
||||
|
||||
GL_FORCE_INLINE GLsizei index_size(GLenum type) {
|
||||
switch(type) {
|
||||
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
|
||||
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
|
||||
case GL_UNSIGNED_INT: return sizeof(GLuint);
|
||||
default: return sizeof(GLushort);
|
||||
}
|
||||
}
|
||||
|
||||
GL_FORCE_INLINE IndexParseFunc _calcParseIndexFunc(GLenum type) {
|
||||
switch(type) {
|
||||
@ -574,138 +285,8 @@ static GL_NO_INLINE void genLineLoop(Vertex* output, GLuint count) {
|
||||
draw_line(dst, &first, &last);
|
||||
}
|
||||
|
||||
typedef void (*ReadPositionFunc)(const GLubyte*, GLubyte*);
|
||||
typedef void (*ReadDiffuseFunc)(const GLubyte*, GLubyte*);
|
||||
typedef void (*ReadUVFunc)(const GLubyte*, GLubyte*);
|
||||
typedef void (*ReadNormalFunc)(const GLubyte*, GLubyte*);
|
||||
|
||||
ReadPositionFunc calcReadDiffuseFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG) != DIFFUSE_ENABLED_FLAG) {
|
||||
/* Just fill the whole thing white if the attribute is disabled */
|
||||
return _fillWhiteARGB;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.colour.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3fARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4fARGB:
|
||||
_readVertexData4fRevARGB;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3ubARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4ubARGB:
|
||||
_readVertexData4ubRevARGB;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3usARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4usARGB:
|
||||
_readVertexData4usRevARGB;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3uiARGB:
|
||||
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4uiARGB:
|
||||
_readVertexData4uiRevARGB;
|
||||
}
|
||||
}
|
||||
|
||||
ReadPositionFunc calcReadPositionFunc() {
|
||||
switch(ATTRIB_POINTERS.vertex.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3f3f:
|
||||
_readVertexData2f3f;
|
||||
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;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3ui3f:
|
||||
_readVertexData2ui3f;
|
||||
}
|
||||
}
|
||||
|
||||
ReadUVFunc calcReadUVFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) != UV_ENABLED_FLAG) {
|
||||
return _fillZero2f;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.uv.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData2f2f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData2ub2f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData2us2f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData2ui2f;
|
||||
}
|
||||
}
|
||||
|
||||
ReadUVFunc calcReadSTFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG) {
|
||||
return _fillZero2f;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.st.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData2f2f;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData2ub2f;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData2us2f;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData2ui2f;
|
||||
}
|
||||
}
|
||||
|
||||
ReadNormalFunc calcReadNormalFunc() {
|
||||
if((ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG) != NORMAL_ENABLED_FLAG) {
|
||||
return _fillWithNegZVE;
|
||||
}
|
||||
|
||||
switch(ATTRIB_POINTERS.normal.type) {
|
||||
default:
|
||||
case GL_DOUBLE:
|
||||
case GL_FLOAT:
|
||||
return _readVertexData3f3f;
|
||||
break;
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return _readVertexData3ub3f;
|
||||
break;
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return _readVertexData3us3f;
|
||||
break;
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
return _readVertexData3ui3f;
|
||||
break;
|
||||
case GL_UNSIGNED_INT_2_10_10_10_REV:
|
||||
return _readVertexData1i3f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void _readPositionData(ReadDiffuseFunc func, const GLuint first, const GLuint count, Vertex* it) {
|
||||
static void _readPositionData(const GLuint first, const GLuint count, Vertex* it) {
|
||||
const ReadAttributeFunc func = ATTRIB_POINTERS.vertex_func;
|
||||
const GLsizei vstride = ATTRIB_POINTERS.vertex.stride;
|
||||
const GLubyte* vptr = ((GLubyte*) ATTRIB_POINTERS.vertex.ptr + (first * vstride));
|
||||
|
||||
@ -722,7 +303,8 @@ static void _readPositionData(ReadDiffuseFunc func, const GLuint first, const GL
|
||||
}
|
||||
}
|
||||
|
||||
static void _readUVData(ReadUVFunc func, const GLuint first, const GLuint count, Vertex* it) {
|
||||
static void _readUVData(const GLuint first, const GLuint count, Vertex* it) {
|
||||
const ReadAttributeFunc func = ATTRIB_POINTERS.uv_func;
|
||||
const GLsizei uvstride = ATTRIB_POINTERS.uv.stride;
|
||||
const GLubyte* uvptr = ((GLubyte*) ATTRIB_POINTERS.uv.ptr + (first * uvstride));
|
||||
|
||||
@ -735,7 +317,8 @@ static void _readUVData(ReadUVFunc func, const GLuint first, const GLuint count,
|
||||
}
|
||||
}
|
||||
|
||||
static void _readSTData(ReadUVFunc func, const GLuint first, const GLuint count, VertexExtra* it) {
|
||||
static void _readSTData(const GLuint first, const GLuint count, VertexExtra* it) {
|
||||
const ReadAttributeFunc func = ATTRIB_POINTERS.st_func;
|
||||
const GLsizei ststride = ATTRIB_POINTERS.st.stride;
|
||||
const GLubyte* stptr = ((GLubyte*) ATTRIB_POINTERS.st.ptr + (first * ststride));
|
||||
|
||||
@ -747,7 +330,8 @@ static void _readSTData(ReadUVFunc func, const GLuint first, const GLuint count,
|
||||
}
|
||||
}
|
||||
|
||||
static void _readNormalData(ReadNormalFunc func, const GLuint first, const GLuint count, VertexExtra* it) {
|
||||
static void _readNormalData(const GLuint first, const GLuint count, VertexExtra* it) {
|
||||
const ReadAttributeFunc func = ATTRIB_POINTERS.normal_func;
|
||||
const GLsizei nstride = ATTRIB_POINTERS.normal.stride;
|
||||
const GLubyte* nptr = ((GLubyte*) ATTRIB_POINTERS.normal.ptr + (first * nstride));
|
||||
|
||||
@ -771,11 +355,8 @@ static void _readNormalData(ReadNormalFunc func, const GLuint first, const GLuin
|
||||
}
|
||||
}
|
||||
|
||||
GL_FORCE_INLINE GLuint diffusePointerSize() {
|
||||
return (ATTRIB_POINTERS.colour.size == GL_BGRA) ? 4 : ATTRIB_POINTERS.colour.size;
|
||||
}
|
||||
|
||||
static void _readDiffuseData(ReadDiffuseFunc func, const GLuint first, const GLuint count, Vertex* it) {
|
||||
static void _readDiffuseData(const GLuint first, const GLuint count, Vertex* it) {
|
||||
const ReadAttributeFunc func = ATTRIB_POINTERS.colour_func;
|
||||
const GLuint cstride = ATTRIB_POINTERS.colour.stride;
|
||||
const GLubyte* cptr = ((GLubyte*) ATTRIB_POINTERS.colour.ptr) + (first * cstride);
|
||||
|
||||
@ -791,7 +372,7 @@ static void generateElements(
|
||||
SubmissionTarget* target, const GLsizei first, const GLuint count,
|
||||
const GLubyte* indices, const GLenum type) {
|
||||
|
||||
const GLsizei istride = byte_size(type);
|
||||
const GLsizei istride = index_size(type);
|
||||
const IndexParseFunc IndexFunc = _calcParseIndexFunc(type);
|
||||
|
||||
GLubyte* xyz;
|
||||
@ -807,19 +388,19 @@ static void generateElements(
|
||||
uint32_t i = first;
|
||||
uint32_t idx = 0;
|
||||
|
||||
const ReadPositionFunc pos_func = calcReadPositionFunc();
|
||||
const ReadAttributeFunc pos_func = ATTRIB_POINTERS.vertex_func;
|
||||
const GLsizei vstride = ATTRIB_POINTERS.vertex.stride;
|
||||
|
||||
const ReadUVFunc uv_func = calcReadUVFunc();
|
||||
const ReadAttributeFunc uv_func = ATTRIB_POINTERS.uv_func;
|
||||
const GLuint uvstride = ATTRIB_POINTERS.uv.stride;
|
||||
|
||||
const ReadUVFunc st_func = calcReadSTFunc();
|
||||
const ReadAttributeFunc st_func = ATTRIB_POINTERS.st_func;
|
||||
const GLuint ststride = ATTRIB_POINTERS.st.stride;
|
||||
|
||||
const ReadDiffuseFunc diffuse_func = calcReadDiffuseFunc();
|
||||
const ReadAttributeFunc diffuse_func = ATTRIB_POINTERS.colour_func;
|
||||
const GLuint dstride = ATTRIB_POINTERS.colour.stride;
|
||||
|
||||
const ReadNormalFunc normal_func = calcReadNormalFunc();
|
||||
const ReadAttributeFunc normal_func = ATTRIB_POINTERS.normal_func;
|
||||
const GLuint nstride = ATTRIB_POINTERS.normal.stride;
|
||||
|
||||
for(; i < first + count; ++i) {
|
||||
@ -867,7 +448,7 @@ static void generateElementsFastPath(
|
||||
const GLuint dstride = ATTRIB_POINTERS.colour.stride;
|
||||
const GLuint nstride = ATTRIB_POINTERS.normal.stride;
|
||||
|
||||
const GLsizei istride = byte_size(type);
|
||||
const GLsizei istride = index_size(type);
|
||||
const IndexParseFunc IndexFunc = _calcParseIndexFunc(type);
|
||||
|
||||
/* Copy the pos, uv and color directly in one go */
|
||||
@ -965,17 +546,11 @@ static void generateArrays(SubmissionTarget* target, const GLsizei first, const
|
||||
Vertex* start = _glSubmissionTargetStart(target);
|
||||
VertexExtra* ve = aligned_vector_at(target->extras, 0);
|
||||
|
||||
const ReadPositionFunc pfunc = calcReadPositionFunc();
|
||||
const ReadDiffuseFunc dfunc = calcReadDiffuseFunc();
|
||||
const ReadUVFunc uvfunc = calcReadUVFunc();
|
||||
const ReadNormalFunc nfunc = calcReadNormalFunc();
|
||||
const ReadUVFunc stfunc = calcReadSTFunc();
|
||||
|
||||
_readPositionData(pfunc, first, count, start);
|
||||
_readDiffuseData(dfunc, first, count, start);
|
||||
_readUVData(uvfunc, first, count, start);
|
||||
_readNormalData(nfunc, first, count, ve);
|
||||
_readSTData(stfunc, first, count, ve);
|
||||
_readPositionData(first, count, start);
|
||||
_readDiffuseData(first, count, start);
|
||||
_readUVData(first, count, start);
|
||||
_readNormalData(first, count, ve);
|
||||
_readSTData(first, count, ve);
|
||||
}
|
||||
|
||||
static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei first, const GLuint count,
|
||||
@ -1397,60 +972,6 @@ void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) {
|
||||
submitVertices(mode, first, count, GL_UNSIGNED_INT, NULL);
|
||||
}
|
||||
|
||||
void APIENTRY glEnableClientState(GLenum cap) {
|
||||
TRACE();
|
||||
|
||||
switch(cap) {
|
||||
case GL_VERTEX_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES |= VERTEX_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_COLOR_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES |= DIFFUSE_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_NORMAL_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES |= NORMAL_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
(ACTIVE_CLIENT_TEXTURE) ?
|
||||
(ENABLED_VERTEX_ATTRIBUTES |= ST_ENABLED_FLAG):
|
||||
(ENABLED_VERTEX_ATTRIBUTES |= UV_ENABLED_FLAG);
|
||||
break;
|
||||
default:
|
||||
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
||||
}
|
||||
|
||||
/* It's possible that we called glVertexPointer and friends before
|
||||
* calling glEnableClientState, so we should recheck to make sure
|
||||
* everything is in the right format with this new information */
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glDisableClientState(GLenum cap) {
|
||||
TRACE();
|
||||
|
||||
switch(cap) {
|
||||
case GL_VERTEX_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES &= ~VERTEX_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_COLOR_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES &= ~DIFFUSE_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_NORMAL_ARRAY:
|
||||
ENABLED_VERTEX_ATTRIBUTES &= ~NORMAL_ENABLED_FLAG;
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
(ACTIVE_CLIENT_TEXTURE) ?
|
||||
(ENABLED_VERTEX_ATTRIBUTES &= ~ST_ENABLED_FLAG):
|
||||
(ENABLED_VERTEX_ATTRIBUTES &= ~UV_ENABLED_FLAG);
|
||||
break;
|
||||
default:
|
||||
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
||||
}
|
||||
|
||||
/* State changed, recalculate */
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
GLuint _glGetActiveClientTexture() {
|
||||
return ACTIVE_CLIENT_TEXTURE;
|
||||
}
|
||||
@ -1465,99 +986,3 @@ void APIENTRY glClientActiveTextureARB(GLenum texture) {
|
||||
|
||||
ACTIVE_CLIENT_TEXTURE = (texture == GL_TEXTURE1_ARB) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Used to avoid checking and updating attribute related state unless necessary
|
||||
GL_FORCE_INLINE GLboolean _glStateUnchanged(AttribPointer* p, GLint size, GLenum type, GLsizei stride) {
|
||||
return (p->size == size && p->type == type && p->stride == stride);
|
||||
}
|
||||
|
||||
void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
stride = (stride) ? stride : size * byte_size(type);
|
||||
AttribPointer* tointer = (ACTIVE_CLIENT_TEXTURE == 0) ? &ATTRIB_POINTERS.uv : &ATTRIB_POINTERS.st;
|
||||
tointer->ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(tointer, size, type, stride)) return;
|
||||
|
||||
if(size < 1 || size > 4) {
|
||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
tointer->stride = stride;
|
||||
tointer->type = type;
|
||||
tointer->size = size;
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
stride = (stride) ? stride : (size * byte_size(type));
|
||||
ATTRIB_POINTERS.vertex.ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(&ATTRIB_POINTERS.vertex, size, type, stride)) return;
|
||||
|
||||
if(size < 2 || size > 4) {
|
||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ATTRIB_POINTERS.vertex.stride = stride;
|
||||
ATTRIB_POINTERS.vertex.type = type;
|
||||
ATTRIB_POINTERS.vertex.size = size;
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
stride = (stride) ? stride : ((size == GL_BGRA) ? 4 : size) * byte_size(type);
|
||||
ATTRIB_POINTERS.colour.ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(&ATTRIB_POINTERS.colour, size, type, stride)) return;
|
||||
|
||||
if(size != 3 && size != 4 && size != GL_BGRA) {
|
||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ATTRIB_POINTERS.colour.type = type;
|
||||
ATTRIB_POINTERS.colour.size = size;
|
||||
ATTRIB_POINTERS.colour.stride = stride;
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
||||
void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||
TRACE();
|
||||
|
||||
GLint validTypes[] = {
|
||||
GL_DOUBLE,
|
||||
GL_FLOAT,
|
||||
GL_BYTE,
|
||||
GL_UNSIGNED_BYTE,
|
||||
GL_INT,
|
||||
GL_UNSIGNED_INT,
|
||||
GL_UNSIGNED_INT_2_10_10_10_REV,
|
||||
0
|
||||
};
|
||||
|
||||
stride = (stride) ? stride : ATTRIB_POINTERS.normal.size * byte_size(type);
|
||||
ATTRIB_POINTERS.normal.ptr = pointer;
|
||||
|
||||
if(_glStateUnchanged(&ATTRIB_POINTERS.normal, 3, type, stride)) return;
|
||||
|
||||
if(_glCheckValidEnum(type, validTypes, __func__) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ATTRIB_POINTERS.normal.size = (type == GL_UNSIGNED_INT_2_10_10_10_REV) ? 1 : 3;
|
||||
ATTRIB_POINTERS.normal.stride = stride;
|
||||
ATTRIB_POINTERS.normal.type = type;
|
||||
|
||||
_glRecalcFastPath();
|
||||
}
|
||||
|
22
GL/private.h
22
GL/private.h
@ -346,6 +346,7 @@ typedef struct {
|
||||
GLsizei stride; // 4
|
||||
GLint size; // 4
|
||||
} AttribPointer;
|
||||
typedef void (*ReadAttributeFunc)(const GLubyte*, GLubyte*);
|
||||
|
||||
typedef struct {
|
||||
AttribPointer vertex; // 16
|
||||
@ -353,25 +354,29 @@ typedef struct {
|
||||
AttribPointer uv; // 48
|
||||
AttribPointer st; // 64
|
||||
AttribPointer normal; // 80
|
||||
AttribPointer padding; // 96
|
||||
|
||||
ReadAttributeFunc vertex_func;
|
||||
ReadAttributeFunc colour_func;
|
||||
ReadAttributeFunc uv_func;
|
||||
ReadAttributeFunc st_func;
|
||||
ReadAttributeFunc normal_func;
|
||||
} AttribPointerList;
|
||||
|
||||
extern GLuint ENABLED_VERTEX_ATTRIBUTES;
|
||||
extern AttribPointerList ATTRIB_POINTERS;
|
||||
|
||||
GLboolean _glCheckValidEnum(GLint param, GLint* values, const char* func);
|
||||
|
||||
GLuint* _glGetEnabledAttributes();
|
||||
AttribPointer* _glGetVertexAttribPointer();
|
||||
AttribPointer* _glGetDiffuseAttribPointer();
|
||||
AttribPointer* _glGetNormalAttribPointer();
|
||||
AttribPointer* _glGetUVAttribPointer();
|
||||
AttribPointer* _glGetSTAttribPointer();
|
||||
GLenum _glGetShadeModel();
|
||||
|
||||
GLenum _glGetShadeModel();
|
||||
TextureObject* _glGetTexture0();
|
||||
TextureObject* _glGetTexture1();
|
||||
TextureObject* _glGetBoundTexture();
|
||||
|
||||
extern GLubyte ACTIVE_TEXTURE;
|
||||
extern GLboolean TEXTURES_ENABLED[];
|
||||
extern GLubyte ACTIVE_CLIENT_TEXTURE;
|
||||
|
||||
GLubyte _glGetActiveTexture();
|
||||
GLint _glGetTextureInternalFormat();
|
||||
@ -422,9 +427,6 @@ GLboolean _glIsColorMaterialEnabled();
|
||||
|
||||
GLboolean _glIsNormalizeEnabled();
|
||||
|
||||
extern AttribPointerList ATTRIB_POINTERS;
|
||||
|
||||
extern GLuint ENABLED_VERTEX_ATTRIBUTES;
|
||||
extern GLuint FAST_PATH_ENABLED;
|
||||
|
||||
GL_FORCE_INLINE GLuint _glIsVertexDataFastPathCompatible() {
|
||||
|
Loading…
Reference in New Issue
Block a user