2018-05-11 14:39:28 +00:00
|
|
|
#include <stdio.h>
|
2018-07-09 07:57:01 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
#include "../include/gl.h"
|
2018-05-11 14:39:28 +00:00
|
|
|
#include "../include/glext.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
#include "private.h"
|
2018-08-16 16:51:15 +00:00
|
|
|
#include "profiler.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2018-05-11 14:39:28 +00:00
|
|
|
const void* ptr;
|
2018-05-05 19:38:55 +00:00
|
|
|
GLenum type;
|
|
|
|
GLsizei stride;
|
|
|
|
GLint size;
|
|
|
|
} AttribPointer;
|
|
|
|
|
|
|
|
|
|
|
|
static AttribPointer VERTEX_POINTER;
|
|
|
|
static AttribPointer UV_POINTER;
|
|
|
|
static AttribPointer ST_POINTER;
|
|
|
|
static AttribPointer NORMAL_POINTER;
|
|
|
|
static AttribPointer DIFFUSE_POINTER;
|
|
|
|
|
|
|
|
static GLuint ENABLED_VERTEX_ATTRIBUTES = 0;
|
|
|
|
static GLubyte ACTIVE_CLIENT_TEXTURE = 0;
|
|
|
|
|
|
|
|
void initAttributePointers() {
|
2018-05-11 14:39:28 +00:00
|
|
|
TRACE();
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
VERTEX_POINTER.ptr = NULL;
|
|
|
|
VERTEX_POINTER.stride = 0;
|
|
|
|
VERTEX_POINTER.type = GL_FLOAT;
|
|
|
|
VERTEX_POINTER.size = 4;
|
2018-05-19 08:17:24 +00:00
|
|
|
|
|
|
|
DIFFUSE_POINTER.ptr = NULL;
|
|
|
|
DIFFUSE_POINTER.stride = 0;
|
|
|
|
DIFFUSE_POINTER.type = GL_FLOAT;
|
|
|
|
DIFFUSE_POINTER.size = 4;
|
|
|
|
|
|
|
|
UV_POINTER.ptr = NULL;
|
|
|
|
UV_POINTER.stride = 0;
|
|
|
|
UV_POINTER.type = GL_FLOAT;
|
|
|
|
UV_POINTER.size = 4;
|
|
|
|
|
|
|
|
ST_POINTER.ptr = NULL;
|
|
|
|
ST_POINTER.stride = 0;
|
|
|
|
ST_POINTER.type = GL_FLOAT;
|
|
|
|
ST_POINTER.size = 4;
|
|
|
|
|
|
|
|
NORMAL_POINTER.ptr = NULL;
|
|
|
|
NORMAL_POINTER.stride = 0;
|
|
|
|
NORMAL_POINTER.type = GL_FLOAT;
|
|
|
|
NORMAL_POINTER.size = 3;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline GLuint byte_size(GLenum type) {
|
2018-05-05 19:38:55 +00:00
|
|
|
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);
|
2018-05-19 08:17:24 +00:00
|
|
|
case GL_FLOAT:
|
2018-05-05 19:38:55 +00:00
|
|
|
default: return sizeof(GLfloat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
typedef void (*FloatParseFunc)(GLfloat* out, const GLubyte* in);
|
2018-08-20 08:28:30 +00:00
|
|
|
typedef void (*ByteParseFunc)(GLubyte* out, const GLubyte* in);
|
2018-08-16 16:51:15 +00:00
|
|
|
typedef void (*PolyBuildFunc)(ClipVertex* first, ClipVertex* previous, ClipVertex* vertex, ClipVertex* next, const GLsizei i);
|
|
|
|
|
2018-08-21 15:08:06 +00:00
|
|
|
GLuint _glGetEnabledAttributes() {
|
|
|
|
return ENABLED_VERTEX_ATTRIBUTES;
|
|
|
|
}
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline void _parseVec3FromShort3(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLshort* ptr = (GLshort*) in;
|
|
|
|
|
|
|
|
out[0] = (GLfloat) ptr[0];
|
|
|
|
out[1] = (GLfloat) ptr[1];
|
|
|
|
out[2] = (GLfloat) ptr[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseVec3FromInt3(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLint* ptr = (GLint*) in;
|
|
|
|
|
|
|
|
out[0] = (GLfloat) ptr[0];
|
|
|
|
out[1] = (GLfloat) ptr[1];
|
|
|
|
out[2] = (GLfloat) ptr[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseVec3FromFloat3(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLfloat* ptr = (GLfloat*) in;
|
|
|
|
|
|
|
|
out[0] = ptr[0];
|
|
|
|
out[1] = ptr[1];
|
|
|
|
out[2] = ptr[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseVec2FromFloat2(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLfloat* ptr = (GLfloat*) in;
|
|
|
|
|
|
|
|
out[0] = ptr[0];
|
|
|
|
out[1] = ptr[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseVec3FromFloat2(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLfloat* ptr = (GLfloat*) in;
|
|
|
|
|
|
|
|
out[0] = ptr[0];
|
|
|
|
out[1] = ptr[1];
|
|
|
|
out[2] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseVec4FromFloat3(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLfloat* ptr = (GLfloat*) in;
|
|
|
|
|
|
|
|
out[0] = ptr[0];
|
|
|
|
out[1] = ptr[1];
|
|
|
|
out[2] = ptr[2];
|
|
|
|
out[3] = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseVec4FromFloat4(GLfloat* out, const GLubyte* in) {
|
|
|
|
GLfloat* ptr = (GLfloat*) in;
|
|
|
|
|
|
|
|
out[0] = ptr[0];
|
|
|
|
out[1] = ptr[1];
|
|
|
|
out[2] = ptr[2];
|
|
|
|
out[3] = ptr[3];
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:28:30 +00:00
|
|
|
static inline void _parseColourFromUByte4(GLubyte* out, const GLubyte* in) {
|
|
|
|
out[R8IDX] = in[0];
|
|
|
|
out[G8IDX] = in[1];
|
|
|
|
out[B8IDX] = in[2];
|
|
|
|
out[A8IDX] = in[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseColourFromFloat4(GLubyte* out, const GLubyte* in) {
|
|
|
|
GLfloat* fin = (GLfloat*) in;
|
|
|
|
|
|
|
|
out[R8IDX] = (GLubyte) (fin[0] * 255.0f);
|
|
|
|
out[G8IDX] = (GLubyte) (fin[1] * 255.0f);
|
|
|
|
out[B8IDX] = (GLubyte) (fin[2] * 255.0f);
|
|
|
|
out[A8IDX] = (GLubyte) (fin[3] * 255.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _parseColourFromFloat3(GLubyte* out, const GLubyte* in) {
|
|
|
|
out[A8IDX] = 255;
|
|
|
|
out[R8IDX] = (GLubyte) ((GLfloat) in[0]) * 255.0f;
|
|
|
|
out[G8IDX] = (GLubyte) ((GLfloat) in[1]) * 255.0f;
|
|
|
|
out[B8IDX] = (GLubyte) ((GLfloat) in[2]) * 255.0f;
|
2018-08-16 16:51:15 +00:00
|
|
|
}
|
2018-08-01 11:00:56 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline void _constVec2Zero(GLfloat* out, const GLubyte* in) {
|
|
|
|
out[0] = 0.0f;
|
|
|
|
out[1] = 0.0f;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline void _constVec3NegZ(GLfloat* out, const GLubyte* in) {
|
|
|
|
out[0] = 0.0f;
|
|
|
|
out[1] = 0.0f;
|
|
|
|
out[2] = -1.0f;
|
|
|
|
}
|
2018-05-14 16:10:53 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline void _constVec4One(GLfloat* out, const GLubyte* in) {
|
|
|
|
out[0] = 1.0f;
|
|
|
|
out[1] = 1.0f;
|
|
|
|
out[2] = 1.0f;
|
|
|
|
out[3] = 1.0f;
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:28:30 +00:00
|
|
|
static inline void _constColourOne(GLubyte* out, const GLubyte* in) {
|
|
|
|
out[0] = 255;
|
|
|
|
out[1] = 255;
|
|
|
|
out[2] = 255;
|
|
|
|
out[3] = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
typedef GLuint (*IndexParseFunc)(const GLubyte* in);
|
|
|
|
|
|
|
|
static inline GLuint _parseUByteIndex(const GLubyte* in) {
|
|
|
|
return (GLuint) *in;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline GLuint _parseUIntIndex(const GLubyte* in) {
|
|
|
|
return *((GLuint*) in);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline GLuint _parseUShortIndex(const GLubyte* in) {
|
|
|
|
return *((GLshort*) in);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
|
|
|
|
static inline IndexParseFunc _calcParseIndexFunc(GLenum type) {
|
2018-05-05 19:38:55 +00:00
|
|
|
switch(type) {
|
|
|
|
case GL_UNSIGNED_BYTE:
|
2018-08-16 16:51:15 +00:00
|
|
|
return &_parseUByteIndex;
|
2018-08-01 10:08:51 +00:00
|
|
|
break;
|
|
|
|
case GL_UNSIGNED_INT:
|
2018-08-16 16:51:15 +00:00
|
|
|
return &_parseUIntIndex;
|
2018-05-05 19:38:55 +00:00
|
|
|
break;
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
default:
|
2018-08-16 16:51:15 +00:00
|
|
|
break;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
|
|
|
|
return &_parseUShortIndex;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 20:00:41 +00:00
|
|
|
|
2018-05-19 08:17:24 +00:00
|
|
|
/* There was a bug in this macro that shipped with Kos
|
|
|
|
* which has now been fixed. But just in case...
|
|
|
|
*/
|
|
|
|
#undef mat_trans_single3_nodiv
|
|
|
|
#define mat_trans_single3_nodiv(x, y, z) { \
|
|
|
|
register float __x __asm__("fr12") = (x); \
|
|
|
|
register float __y __asm__("fr13") = (y); \
|
|
|
|
register float __z __asm__("fr14") = (z); \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"fldi1 fr15\n" \
|
|
|
|
"ftrv xmtrx, fv12\n" \
|
|
|
|
: "=f" (__x), "=f" (__y), "=f" (__z) \
|
|
|
|
: "0" (__x), "1" (__y), "2" (__z) \
|
|
|
|
: "fr15"); \
|
|
|
|
x = __x; y = __y; z = __z; \
|
|
|
|
}
|
2018-05-16 20:00:41 +00:00
|
|
|
|
2018-07-14 20:54:43 +00:00
|
|
|
|
|
|
|
/* FIXME: Is this right? Shouldn't it be fr12->15? */
|
2018-05-19 08:17:24 +00:00
|
|
|
#undef mat_trans_normal3
|
|
|
|
#define mat_trans_normal3(x, y, z) { \
|
|
|
|
register float __x __asm__("fr8") = (x); \
|
|
|
|
register float __y __asm__("fr9") = (y); \
|
|
|
|
register float __z __asm__("fr10") = (z); \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"fldi0 fr11\n" \
|
|
|
|
"ftrv xmtrx, fv8\n" \
|
|
|
|
: "=f" (__x), "=f" (__y), "=f" (__z) \
|
|
|
|
: "0" (__x), "1" (__y), "2" (__z) \
|
|
|
|
: "fr11"); \
|
|
|
|
x = __x; y = __y; z = __z; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-14 20:54:43 +00:00
|
|
|
static inline void transformToEyeSpace(GLfloat* point) {
|
2018-05-16 20:00:41 +00:00
|
|
|
_matrixLoadModelView();
|
|
|
|
mat_trans_single3_nodiv(point[0], point[1], point[2]);
|
|
|
|
}
|
|
|
|
|
2018-07-14 20:54:43 +00:00
|
|
|
static inline void transformNormalToEyeSpace(GLfloat* normal) {
|
2018-05-16 20:00:41 +00:00
|
|
|
_matrixLoadNormal();
|
|
|
|
mat_trans_normal3(normal[0], normal[1], normal[2]);
|
|
|
|
}
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline void swapVertex(ClipVertex* v1, ClipVertex* v2) {
|
|
|
|
static ClipVertex tmp;
|
|
|
|
|
|
|
|
tmp = *v1;
|
2018-07-09 07:57:01 +00:00
|
|
|
*v1 = *v2;
|
|
|
|
*v2 = tmp;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline FloatParseFunc _calcVertexParseFunc() {
|
|
|
|
switch(VERTEX_POINTER.type) {
|
|
|
|
case GL_SHORT: {
|
|
|
|
if(VERTEX_POINTER.size == 3) {
|
|
|
|
return &_parseVec3FromShort3;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case GL_INT: {
|
|
|
|
if(VERTEX_POINTER.size == 3) {
|
|
|
|
return &_parseVec3FromInt3;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case GL_FLOAT: {
|
|
|
|
if(VERTEX_POINTER.size == 3) {
|
|
|
|
return &_parseVec3FromFloat3;
|
|
|
|
} else if(VERTEX_POINTER.size == 2) {
|
|
|
|
return &_parseVec3FromFloat2;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-20 08:28:30 +00:00
|
|
|
static inline ByteParseFunc _calcDiffuseParseFunc() {
|
2018-08-16 16:51:15 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG) != DIFFUSE_ENABLED_FLAG) {
|
2018-08-20 08:28:30 +00:00
|
|
|
return &_constColourOne;
|
2018-08-16 16:51:15 +00:00
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
switch(DIFFUSE_POINTER.type) {
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE: {
|
|
|
|
if(DIFFUSE_POINTER.size == 4) {
|
|
|
|
return &_parseColourFromUByte4;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case GL_FLOAT: {
|
|
|
|
if(DIFFUSE_POINTER.size == 3) {
|
2018-08-20 08:28:30 +00:00
|
|
|
return &_parseColourFromFloat3;
|
2018-08-16 16:51:15 +00:00
|
|
|
} else if(DIFFUSE_POINTER.size == 4) {
|
2018-08-20 08:28:30 +00:00
|
|
|
return &_parseColourFromFloat4;
|
2018-08-16 16:51:15 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-20 08:28:30 +00:00
|
|
|
return &_constColourOne;
|
2018-08-16 16:51:15 +00:00
|
|
|
}
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline FloatParseFunc _calcUVParseFunc() {
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) != UV_ENABLED_FLAG) {
|
|
|
|
return &_constVec2Zero;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
switch(UV_POINTER.type) {
|
|
|
|
case GL_FLOAT: {
|
|
|
|
if(UV_POINTER.size == 2) {
|
|
|
|
return &_parseVec2FromFloat2;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
return &_constVec2Zero;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline FloatParseFunc _calcSTParseFunc() {
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG) {
|
|
|
|
return &_constVec2Zero;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
switch(ST_POINTER.type) {
|
|
|
|
case GL_FLOAT: {
|
|
|
|
if(ST_POINTER.size == 2) {
|
|
|
|
return &_parseVec2FromFloat2;
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
return &_constVec2Zero;
|
|
|
|
}
|
2018-08-04 20:00:26 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
static inline FloatParseFunc _calcNormalParseFunc() {
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG) != NORMAL_ENABLED_FLAG) {
|
|
|
|
return &_constVec3NegZ;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
switch(NORMAL_POINTER.type) {
|
|
|
|
case GL_SHORT: {
|
|
|
|
if(NORMAL_POINTER.size == 3) {
|
|
|
|
return &_parseVec3FromShort3;
|
2018-08-01 08:57:44 +00:00
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
} break;
|
|
|
|
case GL_INT: {
|
|
|
|
if(NORMAL_POINTER.size == 3) {
|
|
|
|
return &_parseVec3FromInt3;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case GL_FLOAT: {
|
|
|
|
if(NORMAL_POINTER.size == 3) {
|
|
|
|
return &_parseVec3FromFloat3;
|
|
|
|
} else if(NORMAL_POINTER.size == 2) {
|
|
|
|
return &_parseVec3FromFloat2;
|
2018-05-12 13:05:54 +00:00
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &_constVec3NegZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 20:40:27 +00:00
|
|
|
static inline void _buildTriangle(ClipVertex* first, ClipVertex* previous, ClipVertex* vertex, ClipVertex* next, const GLsizei i) {
|
2018-08-16 16:51:15 +00:00
|
|
|
if(((i + 1) % 3) == 0) {
|
|
|
|
vertex->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline GLsizei fast_mod(const GLsizei input, const GLsizei ceil) {
|
|
|
|
return input >= ceil ? input % ceil : input;
|
|
|
|
}
|
|
|
|
|
2018-08-17 20:40:27 +00:00
|
|
|
static inline void _buildQuad(ClipVertex* first, ClipVertex* previous, ClipVertex* vertex, ClipVertex* next, const GLsizei i) {
|
2018-08-16 16:51:15 +00:00
|
|
|
if((i + 1) % 4 == 0) {
|
|
|
|
previous->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
swapVertex(previous, vertex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _buildTriangleFan(ClipVertex* first, ClipVertex* previous, ClipVertex* vertex, ClipVertex* next, const GLsizei i) {
|
|
|
|
if(i == 2) {
|
|
|
|
swapVertex(previous, vertex);
|
|
|
|
vertex->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
} else if(i > 2) {
|
|
|
|
ClipVertex* next = vertex + 1;
|
|
|
|
|
|
|
|
*next = *first;
|
|
|
|
|
|
|
|
swapVertex(next, vertex);
|
|
|
|
|
|
|
|
vertex = next + 1;
|
|
|
|
*vertex = *previous;
|
|
|
|
|
|
|
|
vertex->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _buildStrip(ClipVertex* first, ClipVertex* previous, ClipVertex* vertex, ClipVertex* next, const GLsizei i) {
|
|
|
|
if(!next) {
|
|
|
|
/* If the mode was triangle strip, then the last vertex is the last vertex */
|
|
|
|
vertex->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline PolyBuildFunc _calcBuildFunc(const GLenum type) {
|
|
|
|
switch(type) {
|
|
|
|
case GL_TRIANGLES:
|
|
|
|
return &_buildTriangle;
|
|
|
|
break;
|
|
|
|
case GL_QUADS:
|
|
|
|
return &_buildQuad;
|
|
|
|
break;
|
|
|
|
case GL_TRIANGLE_FAN:
|
|
|
|
case GL_POLYGON:
|
|
|
|
return &_buildTriangleFan;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &_buildStrip;
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
static void generate(ClipVertex* output, const GLenum mode, const GLsizei first, const GLsizei count,
|
2018-08-19 20:10:42 +00:00
|
|
|
const GLubyte* indices, const GLenum type, const GLboolean doTexture, const GLboolean doMultitexture, const GLboolean doLighting) {
|
2018-08-16 16:51:15 +00:00
|
|
|
/* Read from the client buffers and generate an array of ClipVertices */
|
|
|
|
|
2018-08-17 20:40:27 +00:00
|
|
|
const GLuint vstride = (VERTEX_POINTER.stride) ? VERTEX_POINTER.stride : VERTEX_POINTER.size * byte_size(VERTEX_POINTER.type);
|
|
|
|
const GLuint cstride = (DIFFUSE_POINTER.stride) ? DIFFUSE_POINTER.stride : DIFFUSE_POINTER.size * byte_size(DIFFUSE_POINTER.type);
|
|
|
|
const GLuint uvstride = (UV_POINTER.stride) ? UV_POINTER.stride : UV_POINTER.size * byte_size(UV_POINTER.type);
|
|
|
|
const GLuint ststride = (ST_POINTER.stride) ? ST_POINTER.stride : ST_POINTER.size * byte_size(ST_POINTER.type);
|
|
|
|
const GLuint nstride = (NORMAL_POINTER.stride) ? NORMAL_POINTER.stride : NORMAL_POINTER.size * byte_size(NORMAL_POINTER.type);
|
|
|
|
|
2018-08-16 16:51:15 +00:00
|
|
|
const GLsizei max = first + count;
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
ClipVertex* vertex = output;
|
2018-08-16 16:51:15 +00:00
|
|
|
|
|
|
|
const FloatParseFunc vertexFunc = _calcVertexParseFunc();
|
2018-08-20 08:28:30 +00:00
|
|
|
const ByteParseFunc diffuseFunc = _calcDiffuseParseFunc();
|
2018-08-16 16:51:15 +00:00
|
|
|
const FloatParseFunc uvFunc = _calcUVParseFunc();
|
|
|
|
const FloatParseFunc stFunc = _calcSTParseFunc();
|
|
|
|
const FloatParseFunc normalFunc = _calcNormalParseFunc();
|
|
|
|
|
|
|
|
const PolyBuildFunc buildFunc = _calcBuildFunc(mode);
|
|
|
|
const IndexParseFunc indexFunc = _calcParseIndexFunc(type);
|
|
|
|
|
|
|
|
const GLsizei type_byte_size = byte_size(type);
|
|
|
|
|
|
|
|
ClipVertex* previous = NULL;
|
|
|
|
ClipVertex* firstV = vertex;
|
|
|
|
ClipVertex* next = NULL;
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
ClipVertex* target = NULL;
|
|
|
|
|
|
|
|
GLsizei i, j = 0;
|
|
|
|
GLuint idx;
|
|
|
|
|
|
|
|
if(!indices) {
|
|
|
|
GLubyte* vptr = VERTEX_POINTER.ptr + (first * vstride);
|
|
|
|
GLubyte* cptr = DIFFUSE_POINTER.ptr + (first * cstride);
|
|
|
|
GLubyte* uvptr = UV_POINTER.ptr + (first * uvstride);
|
|
|
|
GLubyte* stptr = ST_POINTER.ptr + (first * ststride);
|
|
|
|
GLubyte* nptr = NORMAL_POINTER.ptr + (first * nstride);
|
|
|
|
|
|
|
|
for(j = 0; j < count; ++j, ++vertex) {
|
|
|
|
if(mode == GL_QUADS) {
|
|
|
|
/* Performance optimisation to prevent copying to a temporary */
|
|
|
|
GLsizei mod = (j + 1) % 4;
|
|
|
|
if(mod == 0) {
|
|
|
|
target = vertex - 1;
|
|
|
|
target->flags = PVR_CMD_VERTEX;
|
|
|
|
} else if(mod == 3) {
|
|
|
|
target = vertex + 1;
|
|
|
|
target->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
} else {
|
|
|
|
target = vertex;
|
|
|
|
target->flags = PVR_CMD_VERTEX;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target = vertex;
|
|
|
|
target->flags = PVR_CMD_VERTEX;
|
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
vertexFunc(target->xyz, vptr);
|
2018-08-20 08:28:30 +00:00
|
|
|
diffuseFunc(target->bgra, cptr);
|
2018-08-19 20:10:42 +00:00
|
|
|
vptr += vstride;
|
|
|
|
cptr += cstride;
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
if(doTexture) {
|
|
|
|
uvFunc(target->uv, uvptr);
|
|
|
|
uvptr += uvstride;
|
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
if(doMultitexture) {
|
|
|
|
stFunc(target->st, stptr);
|
|
|
|
stptr += ststride;
|
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
if(doLighting) {
|
|
|
|
normalFunc(target->nxyz, nptr);
|
|
|
|
nptr += nstride;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mode != GL_QUADS) {
|
|
|
|
next = (j < count - 1) ? vertex + 1 : NULL;
|
|
|
|
previous = (j > 0) ? vertex - 1 : NULL;
|
|
|
|
buildFunc(firstV, previous, vertex, next, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for(i = first; i < max; ++i, ++j, ++vertex) {
|
|
|
|
if(mode == GL_QUADS) {
|
|
|
|
/* Performance optimisation to prevent copying to a temporary */
|
|
|
|
GLsizei mod = (j + 1) % 4;
|
|
|
|
if(mod == 0) {
|
|
|
|
target = vertex - 1;
|
|
|
|
target->flags = PVR_CMD_VERTEX;
|
|
|
|
} else if(mod == 3) {
|
|
|
|
target = vertex + 1;
|
|
|
|
target->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
} else {
|
|
|
|
target = vertex;
|
|
|
|
target->flags = PVR_CMD_VERTEX;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target = vertex;
|
|
|
|
target->flags = PVR_CMD_VERTEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = (indices) ?
|
|
|
|
indexFunc(&indices[type_byte_size * i]) : i;
|
|
|
|
|
|
|
|
vertexFunc(target->xyz, VERTEX_POINTER.ptr + (idx * vstride));
|
2018-08-20 08:28:30 +00:00
|
|
|
diffuseFunc(target->bgra, DIFFUSE_POINTER.ptr + (idx * cstride));
|
2018-08-19 20:10:42 +00:00
|
|
|
|
|
|
|
if(doTexture) {
|
|
|
|
uvFunc(target->uv, UV_POINTER.ptr + (idx * uvstride));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doMultitexture) {
|
|
|
|
stFunc(target->st, ST_POINTER.ptr + (idx * ststride));
|
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
if(doLighting) {
|
|
|
|
normalFunc(target->nxyz, NORMAL_POINTER.ptr + (idx * nstride));
|
|
|
|
}
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
if(mode != GL_QUADS) {
|
|
|
|
next = (j < count - 1) ? vertex + 1 : NULL;
|
|
|
|
previous = (j > 0) ? vertex - 1 : NULL;
|
|
|
|
buildFunc(firstV, previous, vertex, next, j);
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 20:00:41 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
static void transform(ClipVertex* output, const GLsizei count) {
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform modelview transform, storing W */
|
2018-05-29 12:12:38 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
ClipVertex* vertex = output;
|
2018-07-09 07:57:01 +00:00
|
|
|
|
|
|
|
_applyRenderMatrix(); /* Apply the Render Matrix Stack */
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
GLsizei i = count;
|
2018-08-19 20:10:42 +00:00
|
|
|
while(i--) {
|
2018-07-09 07:57:01 +00:00
|
|
|
register float __x __asm__("fr12") = (vertex->xyz[0]);
|
|
|
|
register float __y __asm__("fr13") = (vertex->xyz[1]);
|
|
|
|
register float __z __asm__("fr14") = (vertex->xyz[2]);
|
2018-07-14 20:54:43 +00:00
|
|
|
register float __w __asm__("fr15");
|
2018-07-09 07:57:01 +00:00
|
|
|
|
|
|
|
__asm__ __volatile__(
|
2018-07-14 20:54:43 +00:00
|
|
|
"fldi1 fr15\n"
|
2018-07-09 07:57:01 +00:00
|
|
|
"ftrv xmtrx,fv12\n"
|
|
|
|
: "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w)
|
|
|
|
: "0" (__x), "1" (__y), "2" (__z), "3" (__w)
|
|
|
|
);
|
|
|
|
|
|
|
|
vertex->xyz[0] = __x;
|
|
|
|
vertex->xyz[1] = __y;
|
|
|
|
vertex->xyz[2] = __z;
|
|
|
|
vertex->w = __w;
|
2018-08-19 20:10:42 +00:00
|
|
|
|
|
|
|
++vertex;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
static GLsizei clip(AlignedVector* polylist, ClipVertex* output, const GLsizei count) {
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform clipping, generating new vertices as necessary */
|
2018-07-10 18:48:25 +00:00
|
|
|
|
|
|
|
static AlignedVector* CLIP_BUFFER = NULL;
|
|
|
|
|
|
|
|
/* First entry into this, allocate the clip buffer */
|
|
|
|
if(!CLIP_BUFFER) {
|
|
|
|
CLIP_BUFFER = (AlignedVector*) malloc(sizeof(AlignedVector));
|
|
|
|
aligned_vector_init(CLIP_BUFFER, sizeof(ClipVertex));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we allocate roughly enough space */
|
2018-08-21 08:37:19 +00:00
|
|
|
aligned_vector_reserve(CLIP_BUFFER, count * 1.5);
|
2018-07-10 18:48:25 +00:00
|
|
|
|
|
|
|
/* Start from empty */
|
|
|
|
aligned_vector_resize(CLIP_BUFFER, 0);
|
|
|
|
|
|
|
|
/* Now perform clipping! */
|
2018-08-21 08:37:19 +00:00
|
|
|
clipTriangleStrip(output, count, CLIP_BUFFER);
|
|
|
|
|
|
|
|
/* Calculate the new required size for the poly list. This is the original size
|
|
|
|
* plus the difference in size between the original vertex count and the clip buffer
|
|
|
|
* count */
|
|
|
|
GLsizei newSize = polylist->size + (CLIP_BUFFER->size - count);
|
2018-07-10 18:48:25 +00:00
|
|
|
|
|
|
|
/* Copy the clip buffer over the vertices */
|
2018-08-21 08:37:19 +00:00
|
|
|
aligned_vector_resize(polylist, newSize);
|
|
|
|
|
|
|
|
GLsizei i = CLIP_BUFFER->size;
|
|
|
|
ClipVertex* dst = output;
|
|
|
|
ClipVertex* src = (ClipVertex*) CLIP_BUFFER->data;
|
|
|
|
while(i--) {
|
|
|
|
*dst = *src;
|
|
|
|
++dst;
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the new vertex count */
|
|
|
|
return CLIP_BUFFER->size;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
static void mat_transform3(const float* xyz, const float* xyzOut, const uint32_t count, const uint32_t inStride, const uint32_t outStride) {
|
2018-07-09 07:57:01 +00:00
|
|
|
uint8_t* dataIn = (uint8_t*) xyz;
|
|
|
|
uint8_t* dataOut = (uint8_t*) xyzOut;
|
|
|
|
uint32_t i = count;
|
|
|
|
|
|
|
|
while(i--) {
|
|
|
|
float* in = (float*) dataIn;
|
|
|
|
float* out = (float*) dataOut;
|
|
|
|
|
|
|
|
mat_trans_single3_nodiv_nomod(in[0], in[1], in[2], out[0], out[1], out[2]);
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
dataIn += inStride;
|
|
|
|
dataOut += outStride;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-29 12:12:38 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
static void mat_transform_normal3(const float* xyz, const float* xyzOut, const uint32_t count, const uint32_t inStride, const uint32_t outStride) {
|
2018-07-09 07:57:01 +00:00
|
|
|
uint8_t* dataIn = (uint8_t*) xyz;
|
|
|
|
uint8_t* dataOut = (uint8_t*) xyzOut;
|
|
|
|
uint32_t i = count;
|
|
|
|
|
|
|
|
while(i--) {
|
|
|
|
float* in = (float*) dataIn;
|
|
|
|
float* out = (float*) dataOut;
|
|
|
|
|
|
|
|
mat_trans_normal3_nomod(in[0], in[1], in[2], out[0], out[1], out[2]);
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
dataIn += inStride;
|
|
|
|
dataOut += outStride;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
static void light(ClipVertex* output, const GLsizei count) {
|
2018-07-09 07:57:01 +00:00
|
|
|
if(!isLightingEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
typedef struct {
|
|
|
|
float xyz[3];
|
|
|
|
float n[3];
|
|
|
|
} EyeSpaceData;
|
|
|
|
|
|
|
|
static AlignedVector* eye_space_data = NULL;
|
|
|
|
|
|
|
|
if(!eye_space_data) {
|
|
|
|
eye_space_data = (AlignedVector*) malloc(sizeof(AlignedVector));
|
|
|
|
aligned_vector_init(eye_space_data, sizeof(EyeSpaceData));
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
aligned_vector_resize(eye_space_data, count);
|
2018-08-19 20:10:42 +00:00
|
|
|
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform lighting calculations and manipulate the colour */
|
2018-08-21 08:37:19 +00:00
|
|
|
ClipVertex* vertex = output;
|
2018-08-19 20:10:42 +00:00
|
|
|
EyeSpaceData* eye_space = (EyeSpaceData*) eye_space_data->data;
|
2018-07-09 07:57:01 +00:00
|
|
|
|
|
|
|
_matrixLoadModelView();
|
2018-08-21 08:37:19 +00:00
|
|
|
mat_transform3(vertex->xyz, eye_space->xyz, count, sizeof(ClipVertex), sizeof(EyeSpaceData));
|
2018-07-09 07:57:01 +00:00
|
|
|
|
|
|
|
_matrixLoadNormal();
|
2018-08-21 08:37:19 +00:00
|
|
|
mat_transform_normal3(vertex->nxyz, eye_space->n, count, sizeof(ClipVertex), sizeof(EyeSpaceData));
|
2018-07-09 07:57:01 +00:00
|
|
|
|
|
|
|
GLsizei i;
|
2018-08-19 20:10:42 +00:00
|
|
|
EyeSpaceData* ES = aligned_vector_at(eye_space_data, 0);
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
for(i = 0; i < count; ++i, ++vertex, ++ES) {
|
2018-07-09 07:57:01 +00:00
|
|
|
/* We ignore diffuse colour when lighting is enabled. If GL_COLOR_MATERIAL is enabled
|
|
|
|
* then the lighting calculation should possibly take it into account */
|
2018-08-01 11:00:56 +00:00
|
|
|
|
2018-08-20 08:28:30 +00:00
|
|
|
GLfloat total [] = {0.0f, 0.0f, 0.0f, 0.0f};
|
2018-07-09 07:57:01 +00:00
|
|
|
GLfloat to_add [] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
GLubyte j;
|
|
|
|
for(j = 0; j < MAX_LIGHTS; ++j) {
|
|
|
|
if(isLightEnabled(j)) {
|
2018-08-19 20:10:42 +00:00
|
|
|
calculateLightingContribution(j, ES->xyz, ES->n, to_add);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-20 08:28:30 +00:00
|
|
|
total[0] += to_add[0];
|
|
|
|
total[1] += to_add[1];
|
|
|
|
total[2] += to_add[2];
|
|
|
|
total[3] += to_add[3];
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
2018-05-29 12:12:38 +00:00
|
|
|
}
|
2018-08-20 08:28:30 +00:00
|
|
|
|
|
|
|
vertex->bgra[A8IDX] = (GLubyte) (255.0f * total[3]);
|
|
|
|
vertex->bgra[R8IDX] = (GLubyte) (255.0f * total[0]);
|
|
|
|
vertex->bgra[G8IDX] = (GLubyte) (255.0f * total[1]);
|
|
|
|
vertex->bgra[B8IDX] = (GLubyte) (255.0f * total[2]);
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
static void divide(ClipVertex* output, const GLsizei count) {
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform perspective divide on each vertex */
|
2018-08-21 08:37:19 +00:00
|
|
|
ClipVertex* vertex = output;
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
GLsizei i = count;
|
2018-08-19 20:10:42 +00:00
|
|
|
while(i--) {
|
2018-07-09 07:57:01 +00:00
|
|
|
vertex->xyz[2] = 1.0f / vertex->w;
|
|
|
|
vertex->xyz[0] *= vertex->xyz[2];
|
2018-08-01 10:08:51 +00:00
|
|
|
vertex->xyz[1] *= vertex->xyz[2];
|
2018-08-19 20:10:42 +00:00
|
|
|
++vertex;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
static void push(PVRHeader* header, ClipVertex* output, const GLsizei count, PolyList* activePolyList, GLshort textureUnit) {
|
|
|
|
// Compile the header
|
2018-07-09 07:57:01 +00:00
|
|
|
pvr_poly_cxt_t cxt = *getPVRContext();
|
|
|
|
cxt.list_type = activePolyList->list_type;
|
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
_glUpdatePVRTextureContext(&cxt, textureUnit);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-20 20:19:12 +00:00
|
|
|
pvr_poly_compile(&header->hdr, &cxt);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
/* Post-process the vertex list */
|
|
|
|
ClipVertex* vout = output;
|
2018-08-01 19:41:59 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
GLuint i = count;
|
2018-08-19 20:10:42 +00:00
|
|
|
while(i--) {
|
2018-08-21 08:37:19 +00:00
|
|
|
vout->oargb = 0;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-09 07:57:01 +00:00
|
|
|
static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum type, const GLvoid* indices) {
|
|
|
|
/* Do nothing if vertices aren't enabled */
|
|
|
|
if(!(ENABLED_VERTEX_ATTRIBUTES & VERTEX_ENABLED_FLAG)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
GLboolean doMultitexture, doTexture, doLighting;
|
|
|
|
GLint activeTexture;
|
|
|
|
glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTexture);
|
|
|
|
|
|
|
|
glActiveTextureARB(GL_TEXTURE0);
|
|
|
|
glGetBooleanv(GL_TEXTURE_2D, &doTexture);
|
|
|
|
|
|
|
|
glActiveTextureARB(GL_TEXTURE1);
|
|
|
|
glGetBooleanv(GL_TEXTURE_2D, &doMultitexture);
|
|
|
|
|
|
|
|
doLighting = isLightingEnabled();
|
|
|
|
|
2018-08-21 14:50:41 +00:00
|
|
|
glActiveTextureARB(activeTexture);
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_push(__func__);
|
|
|
|
|
2018-08-01 11:00:56 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
PolyList* activeList = activePolyList();
|
|
|
|
|
|
|
|
/* Make room in the list buffer */
|
|
|
|
GLsizei spaceNeeded = (mode == GL_POLYGON || mode == GL_TRIANGLE_FAN) ? ((count - 2) * 3) : count;
|
|
|
|
ClipVertex* start = aligned_vector_extend(&activeList->vector, spaceNeeded + 1);
|
|
|
|
|
|
|
|
/* Store a pointer to the header for later */
|
|
|
|
PVRHeader* header = (PVRHeader*) start++;
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("allocate");
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
generate(start, mode, first, count, (GLubyte*) indices, type, doTexture, doMultitexture, doLighting);
|
2018-08-19 20:10:42 +00:00
|
|
|
|
|
|
|
profiler_checkpoint("generate");
|
2018-08-04 20:00:26 +00:00
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
light(start, spaceNeeded);
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("light");
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
transform(start, spaceNeeded);
|
2018-08-01 10:32:07 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("transform");
|
|
|
|
|
2018-08-01 10:32:07 +00:00
|
|
|
if(isClippingEnabled()) {
|
2018-08-21 08:37:19 +00:00
|
|
|
spaceNeeded = clip(&activeList->vector, start, spaceNeeded);
|
2018-08-01 10:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("clip");
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
divide(start, spaceNeeded);
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("divide");
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
push(header, start, spaceNeeded, activePolyList(), 0);
|
2018-08-04 20:00:26 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("push");
|
2018-08-04 20:00:26 +00:00
|
|
|
/*
|
|
|
|
Now, if multitexturing is enabled, we want to send exactly the same vertices again, except:
|
|
|
|
- We want to enable blending, and send them to the TR list
|
|
|
|
- We want to set the depth func to GL_EQUAL
|
|
|
|
- We want to set the second texture ID
|
|
|
|
- We want to set the uv coordinates to the passed st ones
|
|
|
|
*/
|
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
if(!doMultitexture) {
|
|
|
|
/* Multitexture actively disabled */
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_pop();
|
2018-08-14 08:49:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-04 20:00:26 +00:00
|
|
|
TextureObject* texture1 = getTexture1();
|
|
|
|
|
|
|
|
if(!texture1 || ((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG)) {
|
2018-08-14 08:49:31 +00:00
|
|
|
/* Multitexture implicitly disabled */
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_pop();
|
2018-08-04 20:00:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
/* Push back a copy of the list to the transparent poly list, including the header
|
|
|
|
(hence the - 1)
|
|
|
|
*/
|
|
|
|
ClipVertex* vertex = aligned_vector_push_back(
|
|
|
|
&transparentPolyList()->vector, start - 1, spaceNeeded + 1
|
|
|
|
);
|
|
|
|
|
|
|
|
PVRHeader* mtHeader = (PVRHeader*) vertex++;
|
|
|
|
ClipVertex* mtStart = vertex;
|
2018-08-04 20:00:26 +00:00
|
|
|
|
|
|
|
/* Copy ST coordinates to UV ones */
|
2018-08-21 08:37:19 +00:00
|
|
|
GLsizei i = spaceNeeded;
|
2018-08-19 20:10:42 +00:00
|
|
|
while(i--) {
|
2018-08-04 20:00:26 +00:00
|
|
|
vertex->uv[0] = vertex->st[0];
|
2018-08-19 20:10:42 +00:00
|
|
|
vertex->uv[1] = vertex->st[1];
|
|
|
|
++vertex;
|
2018-08-04 20:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store state, as we're about to mess around with it */
|
|
|
|
GLint depthFunc, blendSrc, blendDst;
|
|
|
|
glGetIntegerv(GL_DEPTH_FUNC, &depthFunc);
|
|
|
|
glGetIntegerv(GL_BLEND_SRC, &blendSrc);
|
|
|
|
glGetIntegerv(GL_BLEND_DST, &blendDst);
|
|
|
|
|
|
|
|
GLboolean blendEnabled = glIsEnabled(GL_BLEND);
|
|
|
|
GLboolean depthEnabled = glIsEnabled(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
glDepthFunc(GL_EQUAL);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
/* Send the buffer again to the transparent list */
|
2018-08-21 08:37:19 +00:00
|
|
|
push(mtHeader, mtStart, spaceNeeded, transparentPolyList(), 1);
|
2018-08-04 20:00:26 +00:00
|
|
|
|
|
|
|
/* Reset state */
|
|
|
|
glDepthFunc(depthFunc);
|
|
|
|
glBlendFunc(blendSrc, blendDst);
|
|
|
|
(blendEnabled) ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
|
|
|
(depthEnabled) ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-12 13:54:06 +00:00
|
|
|
if(checkImmediateModeInactive(__func__)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
submitVertices(mode, 0, count, type, indices);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-12 13:54:06 +00:00
|
|
|
if(checkImmediateModeInactive(__func__)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
submitVertices(mode, first, count, GL_UNSIGNED_SHORT, NULL);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glEnableClientState(GLenum cap) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
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, "glEnableClientState");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glDisableClientState(GLenum cap) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
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, "glDisableClientState");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 14:50:59 +00:00
|
|
|
GLuint _glGetActiveClientTexture() {
|
|
|
|
return ACTIVE_CLIENT_TEXTURE;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glClientActiveTextureARB(GLenum texture) {
|
|
|
|
TRACE();
|
|
|
|
|
|
|
|
if(texture < GL_TEXTURE0_ARB || texture > GL_TEXTURE0_ARB + MAX_TEXTURE_UNITS) {
|
|
|
|
_glKosThrowError(GL_INVALID_ENUM, "glClientActiveTextureARB");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_glKosHasError()) {
|
|
|
|
_glKosPrintError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTIVE_CLIENT_TEXTURE = (texture == GL_TEXTURE1_ARB) ? 1 : 0;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
|
|
|
TRACE();
|
|
|
|
|
|
|
|
AttribPointer* tointer = (ACTIVE_CLIENT_TEXTURE == 0) ? &UV_POINTER : &ST_POINTER;
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
tointer->ptr = pointer;
|
|
|
|
tointer->stride = stride;
|
|
|
|
tointer->type = type;
|
|
|
|
tointer->size = size;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
VERTEX_POINTER.ptr = pointer;
|
|
|
|
VERTEX_POINTER.stride = stride;
|
|
|
|
VERTEX_POINTER.type = type;
|
|
|
|
VERTEX_POINTER.size = size;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
DIFFUSE_POINTER.ptr = pointer;
|
|
|
|
DIFFUSE_POINTER.stride = stride;
|
|
|
|
DIFFUSE_POINTER.type = type;
|
|
|
|
DIFFUSE_POINTER.size = size;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer) {
|
|
|
|
TRACE();
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
NORMAL_POINTER.ptr = pointer;
|
|
|
|
NORMAL_POINTER.stride = stride;
|
|
|
|
NORMAL_POINTER.type = type;
|
|
|
|
NORMAL_POINTER.size = 3;
|
|
|
|
}
|