Merge branch 'micro_opts' into 'master'
Few micro optimisations See merge request simulant/GLdc!133
This commit is contained in:
commit
b4c2dd0a5e
64
GL/draw.c
64
GL/draw.c
@ -1253,7 +1253,6 @@ GL_FORCE_INLINE GLuint calcFinalVertices(GLenum mode, GLuint count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type, const GLvoid* indices) {
|
GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type, const GLvoid* indices) {
|
||||||
|
|
||||||
SubmissionTarget* const target = &SUBMISSION_TARGET;
|
SubmissionTarget* const target = &SUBMISSION_TARGET;
|
||||||
AlignedVector* const extras = target->extras;
|
AlignedVector* const extras = target->extras;
|
||||||
|
|
||||||
@ -1324,7 +1323,6 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
|
|||||||
_glMatrixLoadModelViewProjection();
|
_glMatrixLoadModelViewProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we're FAST_PATH_ENABLED, then this will do the transform for us */
|
|
||||||
generate(target, mode, first, count, (GLubyte*) indices, type);
|
generate(target, mode, first, count, (GLubyte*) indices, type);
|
||||||
|
|
||||||
if(_glIsLightingEnabled()){
|
if(_glIsLightingEnabled()){
|
||||||
@ -1468,28 +1466,25 @@ void APIENTRY glClientActiveTextureARB(GLenum texture) {
|
|||||||
ACTIVE_CLIENT_TEXTURE = (texture == GL_TEXTURE1_ARB) ? 1 : 0;
|
ACTIVE_CLIENT_TEXTURE = (texture == GL_TEXTURE1_ARB) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_FORCE_INLINE GLboolean _glComparePointers(AttribPointer* p, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
|
// Used to avoid checking and updating attribute related state unless necessary
|
||||||
return (p->size == size && p->type == type && p->stride == stride && p->ptr == pointer);
|
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) {
|
void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||||
TRACE();
|
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) {
|
if(size < 1 || size > 4) {
|
||||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stride = (stride) ? stride : size * byte_size(type);
|
|
||||||
|
|
||||||
AttribPointer* tointer = (ACTIVE_CLIENT_TEXTURE == 0) ? &ATTRIB_POINTERS.uv : &ATTRIB_POINTERS.st;
|
|
||||||
|
|
||||||
if(_glComparePointers(tointer, size, type, stride, pointer)) {
|
|
||||||
// No Change
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tointer->ptr = pointer;
|
|
||||||
tointer->stride = stride;
|
tointer->stride = stride;
|
||||||
tointer->type = type;
|
tointer->type = type;
|
||||||
tointer->size = size;
|
tointer->size = size;
|
||||||
@ -1497,22 +1492,19 @@ void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const G
|
|||||||
_glRecalcFastPath();
|
_glRecalcFastPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||||
TRACE();
|
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) {
|
if(size < 2 || size > 4) {
|
||||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stride = (stride) ? stride : (size * byte_size(ATTRIB_POINTERS.vertex.type));
|
|
||||||
|
|
||||||
if(_glComparePointers(&ATTRIB_POINTERS.vertex, size, type, stride, pointer)) {
|
|
||||||
// No Change
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ATTRIB_POINTERS.vertex.ptr = pointer;
|
|
||||||
ATTRIB_POINTERS.vertex.stride = stride;
|
ATTRIB_POINTERS.vertex.stride = stride;
|
||||||
ATTRIB_POINTERS.vertex.type = type;
|
ATTRIB_POINTERS.vertex.type = type;
|
||||||
ATTRIB_POINTERS.vertex.size = size;
|
ATTRIB_POINTERS.vertex.size = size;
|
||||||
@ -1523,19 +1515,16 @@ void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const G
|
|||||||
void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
||||||
TRACE();
|
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) {
|
if(size != 3 && size != 4 && size != GL_BGRA) {
|
||||||
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stride = (stride) ? stride : ((size == GL_BGRA) ? 4 : size) * byte_size(type);
|
|
||||||
|
|
||||||
if(_glComparePointers(&ATTRIB_POINTERS.colour, size, type, stride, pointer)) {
|
|
||||||
// No Change
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ATTRIB_POINTERS.colour.ptr = pointer;
|
|
||||||
ATTRIB_POINTERS.colour.type = type;
|
ATTRIB_POINTERS.colour.type = type;
|
||||||
ATTRIB_POINTERS.colour.size = size;
|
ATTRIB_POINTERS.colour.size = size;
|
||||||
ATTRIB_POINTERS.colour.stride = stride;
|
ATTRIB_POINTERS.colour.stride = stride;
|
||||||
@ -1557,18 +1546,15 @@ void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid * poin
|
|||||||
0
|
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) {
|
if(_glCheckValidEnum(type, validTypes, __func__) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stride = (stride) ? stride : ATTRIB_POINTERS.normal.size * byte_size(type);
|
|
||||||
|
|
||||||
if(_glComparePointers(&ATTRIB_POINTERS.normal, 3, type, stride, pointer)) {
|
|
||||||
// No Change
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ATTRIB_POINTERS.normal.ptr = pointer;
|
|
||||||
ATTRIB_POINTERS.normal.size = (type == GL_UNSIGNED_INT_2_10_10_10_REV) ? 1 : 3;
|
ATTRIB_POINTERS.normal.size = (type == GL_UNSIGNED_INT_2_10_10_10_REV) ? 1 : 3;
|
||||||
ATTRIB_POINTERS.normal.stride = stride;
|
ATTRIB_POINTERS.normal.stride = stride;
|
||||||
ATTRIB_POINTERS.normal.type = type;
|
ATTRIB_POINTERS.normal.type = type;
|
||||||
|
|||||||
125
GL/matrix.c
125
GL/matrix.c
@ -139,6 +139,15 @@ void APIENTRY glLoadIdentity() {
|
|||||||
OnMatrixChanged();
|
OnMatrixChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GL_FORCE_INLINE _glMultMatrix(const Matrix4x4* mat) {
|
||||||
|
void* top = stack_top(MATRIX_STACKS + MATRIX_IDX);
|
||||||
|
|
||||||
|
UploadMatrix4x4(top);
|
||||||
|
MultiplyMatrix4x4(mat);
|
||||||
|
DownloadMatrix4x4(top);
|
||||||
|
OnMatrixChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
||||||
const Matrix4x4 trn __attribute__((aligned(32))) = {
|
const Matrix4x4 trn __attribute__((aligned(32))) = {
|
||||||
1.0f, 0.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
@ -146,17 +155,7 @@ void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
0.0f, 0.0f, 1.0f, 0.0f,
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
x, y, z, 1.0f
|
x, y, z, 1.0f
|
||||||
};
|
};
|
||||||
void* top = stack_top(MATRIX_STACKS + MATRIX_IDX);
|
_glMultMatrix(&trn);
|
||||||
assert(top);
|
|
||||||
|
|
||||||
UploadMatrix4x4(top);
|
|
||||||
MultiplyMatrix4x4(&trn);
|
|
||||||
|
|
||||||
top = stack_top(MATRIX_STACKS + MATRIX_IDX);
|
|
||||||
assert(top);
|
|
||||||
|
|
||||||
DownloadMatrix4x4(top);
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -167,11 +166,7 @@ void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
0.0f, 0.0f, z, 0.0f,
|
0.0f, 0.0f, z, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 1.0f
|
0.0f, 0.0f, 0.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
_glMultMatrix(&scale);
|
||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
MultiplyMatrix4x4(&scale);
|
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
||||||
@ -213,10 +208,7 @@ void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
rotate[M9] = yz * invc - xs;
|
rotate[M9] = yz * invc - xs;
|
||||||
rotate[M10] = (z * z) * invc + c;
|
rotate[M10] = (z * z) * invc + c;
|
||||||
|
|
||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
_glMultMatrix(&rotate);
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &rotate);
|
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load an arbitrary matrix */
|
/* Load an arbitrary matrix */
|
||||||
@ -233,25 +225,21 @@ void APIENTRY glOrtho(GLfloat left, GLfloat right,
|
|||||||
GLfloat bottom, GLfloat top,
|
GLfloat bottom, GLfloat top,
|
||||||
GLfloat znear, GLfloat zfar) {
|
GLfloat znear, GLfloat zfar) {
|
||||||
|
|
||||||
/* Ortho Matrix */
|
Matrix4x4 ortho __attribute__((aligned(32))) = {
|
||||||
Matrix4x4 OrthoMatrix __attribute__((aligned(32))) = {
|
|
||||||
1.0f, 0.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 1.0f, 0.0f, 0.0f,
|
0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f, 0.0f,
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 1.0f
|
0.0f, 0.0f, 0.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
OrthoMatrix[M0] = 2.0f / (right - left);
|
ortho[M0] = 2.0f / (right - left);
|
||||||
OrthoMatrix[M5] = 2.0f / (top - bottom);
|
ortho[M5] = 2.0f / (top - bottom);
|
||||||
OrthoMatrix[M10] = -2.0f / (zfar - znear);
|
ortho[M10] = -2.0f / (zfar - znear);
|
||||||
OrthoMatrix[M12] = -(right + left) / (right - left);
|
ortho[M12] = -(right + left) / (right - left);
|
||||||
OrthoMatrix[M13] = -(top + bottom) / (top - bottom);
|
ortho[M13] = -(top + bottom) / (top - bottom);
|
||||||
OrthoMatrix[M14] = -(zfar + znear) / (zfar - znear);
|
ortho[M14] = -(zfar + znear) / (zfar - znear);
|
||||||
|
|
||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
_glMultMatrix(&ortho);
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &OrthoMatrix);
|
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -260,10 +248,8 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right,
|
|||||||
GLfloat bottom, GLfloat top,
|
GLfloat bottom, GLfloat top,
|
||||||
GLfloat znear, GLfloat zfar) {
|
GLfloat znear, GLfloat zfar) {
|
||||||
|
|
||||||
/* Frustum Matrix */
|
Matrix4x4 frustum __attribute__((aligned(32)));
|
||||||
Matrix4x4 FrustumMatrix __attribute__((aligned(32)));
|
MEMSET(frustum, 0, sizeof(float) * 16);
|
||||||
|
|
||||||
MEMSET(FrustumMatrix, 0, sizeof(float) * 16);
|
|
||||||
|
|
||||||
const float near2 = 2.0f * znear;
|
const float near2 = 2.0f * znear;
|
||||||
const float A = (right + left) / (right - left);
|
const float A = (right + left) / (right - left);
|
||||||
@ -271,31 +257,25 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right,
|
|||||||
const float C = -((zfar + znear) / (zfar - znear));
|
const float C = -((zfar + znear) / (zfar - znear));
|
||||||
const float D = -((2.0f * zfar * znear) / (zfar - znear));
|
const float D = -((2.0f * zfar * znear) / (zfar - znear));
|
||||||
|
|
||||||
FrustumMatrix[M0] = near2 / (right - left);
|
frustum[M0] = near2 / (right - left);
|
||||||
FrustumMatrix[M5] = near2 / (top - bottom);
|
frustum[M5] = near2 / (top - bottom);
|
||||||
|
|
||||||
FrustumMatrix[M8] = A;
|
frustum[M8] = A;
|
||||||
FrustumMatrix[M9] = B;
|
frustum[M9] = B;
|
||||||
FrustumMatrix[M10] = C;
|
frustum[M10] = C;
|
||||||
FrustumMatrix[M11] = -1.0f;
|
frustum[M11] = -1.0f;
|
||||||
FrustumMatrix[M14] = D;
|
frustum[M14] = D;
|
||||||
|
|
||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
_glMultMatrix(&frustum);
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &FrustumMatrix);
|
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Multiply the current matrix by an arbitrary matrix */
|
/* Multiply the current matrix by an arbitrary matrix */
|
||||||
void glMultMatrixf(const GLfloat *m) {
|
void glMultMatrixf(const GLfloat *m) {
|
||||||
Matrix4x4 TEMP __attribute__((aligned(32)));
|
Matrix4x4 tmp __attribute__((aligned(32)));
|
||||||
MEMCPY4(TEMP, m, sizeof(Matrix4x4));
|
MEMCPY4(tmp, m, sizeof(Matrix4x4));
|
||||||
|
|
||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
_glMultMatrix(&tmp);
|
||||||
MultiplyMatrix4x4(&TEMP);
|
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load an arbitrary transposed matrix */
|
/* Load an arbitrary transposed matrix */
|
||||||
@ -331,32 +311,29 @@ void glLoadTransposeMatrixf(const GLfloat *m) {
|
|||||||
|
|
||||||
/* Multiply the current matrix by an arbitrary transposed matrix */
|
/* Multiply the current matrix by an arbitrary transposed matrix */
|
||||||
void glMultTransposeMatrixf(const GLfloat *m) {
|
void glMultTransposeMatrixf(const GLfloat *m) {
|
||||||
static Matrix4x4 TEMP __attribute__((aligned(32)));
|
static Matrix4x4 tmp __attribute__((aligned(32)));
|
||||||
|
|
||||||
TEMP[M0] = m[0];
|
tmp[M0] = m[0];
|
||||||
TEMP[M1] = m[4];
|
tmp[M1] = m[4];
|
||||||
TEMP[M2] = m[8];
|
tmp[M2] = m[8];
|
||||||
TEMP[M3] = m[12];
|
tmp[M3] = m[12];
|
||||||
|
|
||||||
TEMP[M4] = m[1];
|
tmp[M4] = m[1];
|
||||||
TEMP[M5] = m[5];
|
tmp[M5] = m[5];
|
||||||
TEMP[M6] = m[9];
|
tmp[M6] = m[9];
|
||||||
TEMP[M7] = m[13];
|
tmp[M7] = m[13];
|
||||||
|
|
||||||
TEMP[M8] = m[3];
|
tmp[M8] = m[3];
|
||||||
TEMP[M9] = m[6];
|
tmp[M9] = m[6];
|
||||||
TEMP[M10] = m[10];
|
tmp[M10] = m[10];
|
||||||
TEMP[M11] = m[14];
|
tmp[M11] = m[14];
|
||||||
|
|
||||||
TEMP[M12] = m[4];
|
tmp[M12] = m[4];
|
||||||
TEMP[M13] = m[7];
|
tmp[M13] = m[7];
|
||||||
TEMP[M14] = m[11];
|
tmp[M14] = m[11];
|
||||||
TEMP[M15] = m[15];
|
tmp[M15] = m[15];
|
||||||
|
|
||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
_glMultMatrix(&tmp);
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &TEMP);
|
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
|
||||||
OnMatrixChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the GL viewport */
|
/* Set the GL viewport */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user