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-08-27 20:35:07 +00:00
|
|
|
#include <math.h>
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
#include "private.h"
|
2021-04-09 15:24:47 +00:00
|
|
|
#include "platform.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
|
|
|
|
AttribPointerList ATTRIB_POINTERS;
|
2021-09-12 14:04:52 +00:00
|
|
|
GLuint ENABLED_VERTEX_ATTRIBUTES = 0;
|
2021-09-13 11:57:52 +00:00
|
|
|
GLuint FAST_PATH_ENABLED = GL_FALSE;
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
static GLubyte ACTIVE_CLIENT_TEXTURE = 0;
|
2023-03-07 10:19:09 +00:00
|
|
|
static const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
2021-09-12 14:04:52 +00:00
|
|
|
|
2021-09-13 11:57:52 +00:00
|
|
|
extern inline GLuint _glRecalcFastPath();
|
2019-03-26 09:09:07 +00:00
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
extern GLboolean AUTOSORT_ENABLED;
|
|
|
|
|
2019-03-26 09:09:07 +00:00
|
|
|
#define ITERATE(count) \
|
2019-03-28 13:07:53 +00:00
|
|
|
GLuint i = count; \
|
2019-03-26 09:09:07 +00:00
|
|
|
while(i--)
|
|
|
|
|
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
void _glInitAttributePointers() {
|
2018-05-11 14:39:28 +00:00
|
|
|
TRACE();
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.vertex.ptr = NULL;
|
|
|
|
ATTRIB_POINTERS.vertex.stride = 0;
|
|
|
|
ATTRIB_POINTERS.vertex.type = GL_FLOAT;
|
|
|
|
ATTRIB_POINTERS.vertex.size = 4;
|
2018-05-19 08:17:24 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.colour.ptr = NULL;
|
|
|
|
ATTRIB_POINTERS.colour.stride = 0;
|
|
|
|
ATTRIB_POINTERS.colour.type = GL_FLOAT;
|
|
|
|
ATTRIB_POINTERS.colour.size = 4;
|
2018-05-19 08:17:24 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.uv.ptr = NULL;
|
|
|
|
ATTRIB_POINTERS.uv.stride = 0;
|
|
|
|
ATTRIB_POINTERS.uv.type = GL_FLOAT;
|
|
|
|
ATTRIB_POINTERS.uv.size = 4;
|
2018-05-19 08:17:24 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.st.ptr = NULL;
|
|
|
|
ATTRIB_POINTERS.st.stride = 0;
|
|
|
|
ATTRIB_POINTERS.st.type = GL_FLOAT;
|
|
|
|
ATTRIB_POINTERS.st.size = 4;
|
2018-05-19 08:17:24 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.normal.ptr = NULL;
|
|
|
|
ATTRIB_POINTERS.normal.stride = 0;
|
|
|
|
ATTRIB_POINTERS.normal.type = GL_FLOAT;
|
|
|
|
ATTRIB_POINTERS.normal.size = 3;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2021-04-19 20:23:23 +00:00
|
|
|
GL_FORCE_INLINE GLsizei 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);
|
2019-11-18 17:39:09 +00:00
|
|
|
case GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GLuint);
|
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);
|
2019-03-25 09:44:59 +00:00
|
|
|
typedef void (*PolyBuildFunc)(Vertex* first, Vertex* previous, Vertex* vertex, Vertex* next, const GLsizei i);
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2021-04-21 16:23:43 +00:00
|
|
|
static void _readVertexData3f3f(const GLubyte* __restrict__ in, GLubyte* __restrict__ out) {
|
2020-05-11 19:34:09 +00:00
|
|
|
vec3cpy(out, in);
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-18 17:39:09 +00:00
|
|
|
// 10:10:10:2REV format
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData1i3f(const GLubyte* in, GLubyte* out) {
|
2020-05-06 19:15:28 +00:00
|
|
|
const static float MULTIPLIER = 1.0f / 1023.0f;
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
GLfloat* output = (GLfloat*) out;
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2020-05-06 19:15:28 +00:00
|
|
|
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);
|
|
|
|
|
2020-05-08 12:53:56 +00:00
|
|
|
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;
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData3us3f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const GLushort* input = (const GLushort*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData3ui3f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const GLuint* input = (const GLuint*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData3ub3f(const GLubyte* input, GLubyte* out) {
|
|
|
|
float* output = (float*) out;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
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;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2f2f(const GLubyte* in, GLubyte* out) {
|
2020-05-11 19:34:09 +00:00
|
|
|
vec2cpy(out, in);
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2f3f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const float* input = (const float*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-11 19:34:09 +00:00
|
|
|
vec2cpy(output, input);
|
2020-05-05 20:52:37 +00:00
|
|
|
output[2] = 0.0f;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2ub3f(const GLubyte* input, GLubyte* out) {
|
|
|
|
float* output = (float*) out;
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[2] = 0.0f;
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2us3f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const GLushort* input = (const GLushort*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = 0.0f;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2us2f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const GLushort* input = (const GLushort*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2ui2f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const GLuint* input = (const GLuint*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2ub2f(const GLubyte* input, GLubyte* out) {
|
|
|
|
float* output = (float*) out;
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData2ui3f(const GLubyte* in, GLubyte* out) {
|
|
|
|
const GLuint* input = (const GLuint*) in;
|
|
|
|
float* output = (float*) out;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = 0.0f;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData4ubARGB(const GLubyte* input, GLubyte* output) {
|
|
|
|
output[R8IDX] = input[0];
|
|
|
|
output[G8IDX] = input[1];
|
|
|
|
output[B8IDX] = input[2];
|
|
|
|
output[A8IDX] = input[3];
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData4fARGB(const GLubyte* in, GLubyte* output) {
|
|
|
|
const float* input = (const float*) in;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
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);
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData3fARGB(const GLubyte* in, GLubyte* output) {
|
|
|
|
const float* input = (const float*) in;
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
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] = 1.0f;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
static void _readVertexData3ubARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
2020-05-05 20:52:37 +00:00
|
|
|
output[R8IDX] = input[0];
|
|
|
|
output[G8IDX] = input[1];
|
|
|
|
output[B8IDX] = input[2];
|
|
|
|
output[A8IDX] = 1.0f;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
static void _readVertexData4ubRevARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
2020-05-08 08:59:32 +00:00
|
|
|
argbcpy(output, input);
|
2019-09-30 20:59:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 16:23:43 +00:00
|
|
|
static void _readVertexData4fRevARGB(const GLubyte* __restrict__ in, GLubyte* __restrict__ output) {
|
2020-05-05 20:52:37 +00:00
|
|
|
const float* input = (const float*) in;
|
2019-09-30 20:59:11 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
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);
|
2019-09-30 20:59:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
static void _fillWithNegZVE(const GLubyte* __restrict__ input, GLubyte* __restrict__ out) {
|
2020-05-06 07:42:09 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
typedef struct {
|
|
|
|
float x, y, z;
|
|
|
|
} V;
|
|
|
|
|
2023-05-12 19:51:36 +00:00
|
|
|
static const V NegZ = {0.0f, 0.0f, -1.0f};
|
2021-04-20 15:08:58 +00:00
|
|
|
|
|
|
|
*((V*) out) = NegZ;
|
2019-03-14 13:15:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 16:23:43 +00:00
|
|
|
static void _fillWhiteARGB(const GLubyte* __restrict__ input, GLubyte* __restrict__ output) {
|
2020-05-06 07:42:09 +00:00
|
|
|
_GL_UNUSED(input);
|
2021-04-20 08:07:14 +00:00
|
|
|
*((uint32_t*) output) = ~0;
|
2019-03-14 13:15:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 16:23:43 +00:00
|
|
|
static void _fillZero2f(const GLubyte* __restrict__ input, GLubyte* __restrict__ out) {
|
2020-05-06 07:42:09 +00:00
|
|
|
_GL_UNUSED(input);
|
2021-09-04 12:36:59 +00:00
|
|
|
memset(out, 0, sizeof(float) * 2);
|
2019-03-14 13:15:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData3usARGB(const GLubyte* input, GLubyte* output) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
_GL_UNUSED(output);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData3uiARGB(const GLubyte* input, GLubyte* output) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
_GL_UNUSED(output);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData4usARGB(const GLubyte* input, GLubyte* output) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
_GL_UNUSED(output);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData4uiARGB(const GLubyte* input, GLubyte* output) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
_GL_UNUSED(output);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData4usRevARGB(const GLubyte* input, GLubyte* output) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
_GL_UNUSED(output);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2019-09-30 20:59:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
static void _readVertexData4uiRevARGB(const GLubyte* input, GLubyte* output) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_GL_UNUSED(input);
|
|
|
|
_GL_UNUSED(output);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2019-09-30 20:59:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 08:47:55 +00:00
|
|
|
GLuint* _glGetEnabledAttributes() {
|
|
|
|
return &ENABLED_VERTEX_ATTRIBUTES;
|
2018-08-21 15:08:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 15:15:43 +00:00
|
|
|
AttribPointer* _glGetVertexAttribPointer() {
|
2021-09-13 09:29:04 +00:00
|
|
|
return &ATTRIB_POINTERS.vertex;
|
2018-08-21 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetDiffuseAttribPointer() {
|
2021-09-13 09:29:04 +00:00
|
|
|
return &ATTRIB_POINTERS.colour;
|
2018-08-21 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetNormalAttribPointer() {
|
2021-09-13 09:29:04 +00:00
|
|
|
return &ATTRIB_POINTERS.normal;
|
2018-08-21 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetUVAttribPointer() {
|
2021-09-13 09:29:04 +00:00
|
|
|
return &ATTRIB_POINTERS.uv;
|
2018-08-21 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetSTAttribPointer() {
|
2021-09-13 09:29:04 +00:00
|
|
|
return &ATTRIB_POINTERS.st;
|
2018-08-21 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-02-29 13:25:30 +00:00
|
|
|
GL_FORCE_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; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 13:25:30 +00:00
|
|
|
GL_FORCE_INLINE void transformToEyeSpace(GLfloat* point) {
|
2019-03-03 19:02:25 +00:00
|
|
|
_glMatrixLoadModelView();
|
2018-05-16 20:00:41 +00:00
|
|
|
mat_trans_single3_nodiv(point[0], point[1], point[2]);
|
|
|
|
}
|
|
|
|
|
2020-02-29 13:25:30 +00:00
|
|
|
GL_FORCE_INLINE void transformNormalToEyeSpace(GLfloat* normal) {
|
2019-03-03 19:02:25 +00:00
|
|
|
_glMatrixLoadNormal();
|
2018-05-16 20:00:41 +00:00
|
|
|
mat_trans_normal3(normal[0], normal[1], normal[2]);
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
GL_FORCE_INLINE PolyHeader *_glSubmissionTargetHeader(SubmissionTarget* target) {
|
2023-05-12 19:51:36 +00:00
|
|
|
gl_assert(target->header_offset < aligned_vector_size(&target->output->vector));
|
2019-03-24 08:09:02 +00:00
|
|
|
return aligned_vector_at(&target->output->vector, target->header_offset);
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:48:37 +00:00
|
|
|
GL_INLINE_DEBUG Vertex* _glSubmissionTargetStart(SubmissionTarget* target) {
|
2023-05-12 19:51:36 +00:00
|
|
|
gl_assert(target->start_offset < aligned_vector_size(&target->output->vector));
|
2019-03-24 08:09:02 +00:00
|
|
|
return aligned_vector_at(&target->output->vector, target->start_offset);
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* _glSubmissionTargetEnd(SubmissionTarget* target) {
|
2019-03-24 08:09:02 +00:00
|
|
|
return _glSubmissionTargetStart(target) + target->count;
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
GL_FORCE_INLINE void genTriangles(Vertex* output, GLuint count) {
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* it = output + 2;
|
2020-02-22 21:00:33 +00:00
|
|
|
|
|
|
|
GLuint i;
|
|
|
|
for(i = 0; i < count; i += 3) {
|
2021-04-09 15:24:47 +00:00
|
|
|
it->flags = GPU_CMD_VERTEX_EOL;
|
2019-03-13 17:38:42 +00:00
|
|
|
it += 3;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
GL_FORCE_INLINE void genQuads(Vertex* output, GLuint count) {
|
|
|
|
Vertex* pen = output + 2;
|
2019-11-30 10:07:41 +00:00
|
|
|
Vertex* final = output + 3;
|
2021-04-26 15:14:33 +00:00
|
|
|
GLuint i = count >> 2;
|
|
|
|
while(i--) {
|
2021-05-14 20:53:27 +00:00
|
|
|
PREFETCH(pen + 4);
|
2021-09-13 18:35:53 +00:00
|
|
|
PREFETCH(final + 4);
|
2021-04-26 15:14:33 +00:00
|
|
|
|
|
|
|
swapVertex(pen, final);
|
2021-04-09 15:24:47 +00:00
|
|
|
final->flags = GPU_CMD_VERTEX_EOL;
|
2021-04-26 15:14:33 +00:00
|
|
|
|
|
|
|
pen += 4;
|
2019-11-30 10:07:41 +00:00
|
|
|
final += 4;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
GL_FORCE_INLINE void genTriangleStrip(Vertex* output, GLuint count) {
|
2021-04-09 15:24:47 +00:00
|
|
|
output[count - 1].flags = GPU_CMD_VERTEX_EOL;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static void genTriangleFan(Vertex* output, GLuint count) {
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(count <= 255);
|
2018-10-08 21:03:50 +00:00
|
|
|
|
2019-03-29 11:23:48 +00:00
|
|
|
Vertex* dst = output + (((count - 2) * 3) - 1);
|
|
|
|
Vertex* src = output + (count - 1);
|
2018-10-08 21:03:50 +00:00
|
|
|
|
2019-03-29 11:23:48 +00:00
|
|
|
GLubyte i = count - 2;
|
|
|
|
while(i--) {
|
|
|
|
*dst = *src--;
|
2021-04-09 15:24:47 +00:00
|
|
|
(*dst--).flags = GPU_CMD_VERTEX_EOL;
|
2019-03-29 11:23:48 +00:00
|
|
|
*dst-- = *src;
|
|
|
|
*dst-- = *output;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
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() {
|
2020-05-06 07:42:09 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG) != DIFFUSE_ENABLED_FLAG) {
|
|
|
|
/* Just fill the whole thing white if the attribute is disabled */
|
|
|
|
return _fillWhiteARGB;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
switch(ATTRIB_POINTERS.colour.type) {
|
2020-05-05 20:52:37 +00:00
|
|
|
default:
|
|
|
|
case GL_DOUBLE:
|
|
|
|
case GL_FLOAT:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3fARGB:
|
|
|
|
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4fARGB:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData4fRevARGB;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3ubARGB:
|
|
|
|
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4ubARGB:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData4ubRevARGB;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3usARGB:
|
|
|
|
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4usARGB:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData4usRevARGB;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.colour.size == 3) ? _readVertexData3uiARGB:
|
|
|
|
(ATTRIB_POINTERS.colour.size == 4) ? _readVertexData4uiARGB:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData4uiRevARGB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadPositionFunc calcReadPositionFunc() {
|
2021-09-13 09:29:04 +00:00
|
|
|
switch(ATTRIB_POINTERS.vertex.type) {
|
2020-05-05 20:52:37 +00:00
|
|
|
default:
|
|
|
|
case GL_DOUBLE:
|
|
|
|
case GL_FLOAT:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3f3f:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData2f3f;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3ub3f:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData2ub3f;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3us3f:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData2us3f;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.vertex.size == 3) ? _readVertexData3ui3f:
|
2020-05-05 20:52:37 +00:00
|
|
|
_readVertexData2ui3f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadUVFunc calcReadUVFunc() {
|
2020-05-06 07:42:09 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) != UV_ENABLED_FLAG) {
|
|
|
|
return _fillZero2f;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
switch(ATTRIB_POINTERS.uv.type) {
|
2020-05-05 20:52:37 +00:00
|
|
|
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() {
|
2020-05-06 07:42:09 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG) {
|
|
|
|
return _fillZero2f;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
switch(ATTRIB_POINTERS.st.type) {
|
2020-05-05 20:52:37 +00:00
|
|
|
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() {
|
2020-05-06 07:42:09 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG) != NORMAL_ENABLED_FLAG) {
|
|
|
|
return _fillWithNegZVE;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
switch(ATTRIB_POINTERS.normal.type) {
|
2020-05-05 20:52:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
static void _readPositionData(ReadDiffuseFunc func, const GLuint first, const GLuint count, Vertex* it) {
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLsizei vstride = ATTRIB_POINTERS.vertex.stride;
|
|
|
|
const GLubyte* vptr = ((GLubyte*) ATTRIB_POINTERS.vertex.ptr + (first * vstride));
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
float pos[3];
|
|
|
|
float w = 0.0f;
|
2020-05-05 20:52:37 +00:00
|
|
|
|
|
|
|
ITERATE(count) {
|
2021-05-14 20:53:27 +00:00
|
|
|
PREFETCH(vptr + vstride);
|
2022-08-25 20:24:08 +00:00
|
|
|
func(vptr, (GLubyte*) pos);
|
|
|
|
it->flags = GPU_CMD_VERTEX;
|
2021-04-26 15:14:33 +00:00
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
vptr += vstride;
|
|
|
|
++it;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
static void _readUVData(ReadUVFunc func, const GLuint first, const GLuint count, Vertex* it) {
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLsizei uvstride = ATTRIB_POINTERS.uv.stride;
|
|
|
|
const GLubyte* uvptr = ((GLubyte*) ATTRIB_POINTERS.uv.ptr + (first * uvstride));
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
ITERATE(count) {
|
2021-05-14 20:53:27 +00:00
|
|
|
PREFETCH(uvptr + uvstride);
|
2021-04-26 15:14:33 +00:00
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
func(uvptr, (GLubyte*) it->uv);
|
2020-05-05 20:52:37 +00:00
|
|
|
uvptr += uvstride;
|
2022-08-25 20:24:08 +00:00
|
|
|
++it;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
static void _readSTData(ReadUVFunc func, const GLuint first, const GLuint count, VertexExtra* it) {
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLsizei ststride = ATTRIB_POINTERS.st.stride;
|
|
|
|
const GLubyte* stptr = ((GLubyte*) ATTRIB_POINTERS.st.ptr + (first * ststride));
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
ITERATE(count) {
|
2021-05-14 20:53:27 +00:00
|
|
|
PREFETCH(stptr + ststride);
|
2022-08-25 20:24:08 +00:00
|
|
|
func(stptr, (GLubyte*) it->st);
|
2020-05-05 20:52:37 +00:00
|
|
|
stptr += ststride;
|
2022-08-25 20:24:08 +00:00
|
|
|
++it;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
static void _readNormalData(ReadNormalFunc func, const GLuint first, const GLuint count, VertexExtra* it) {
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLsizei nstride = ATTRIB_POINTERS.normal.stride;
|
|
|
|
const GLubyte* nptr = ((GLubyte*) ATTRIB_POINTERS.normal.ptr + (first * nstride));
|
2019-03-13 11:24:35 +00:00
|
|
|
|
2020-05-05 20:52:37 +00:00
|
|
|
ITERATE(count) {
|
2022-08-25 20:24:08 +00:00
|
|
|
func(nptr, (GLubyte*) it->nxyz);
|
2020-05-05 20:52:37 +00:00
|
|
|
nptr += nstride;
|
2019-11-18 17:39:09 +00:00
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
if(_glIsNormalizeEnabled()) {
|
|
|
|
GLfloat* n = (GLfloat*) it->nxyz;
|
2020-03-05 19:48:37 +00:00
|
|
|
float temp = n[0] * n[0];
|
|
|
|
temp = MATH_fmac(n[1], n[1], temp);
|
|
|
|
temp = MATH_fmac(n[2], n[2], temp);
|
|
|
|
|
|
|
|
float ilength = MATH_fsrra(temp);
|
|
|
|
n[0] *= ilength;
|
|
|
|
n[1] *= ilength;
|
|
|
|
n[2] *= ilength;
|
2019-11-18 17:39:09 +00:00
|
|
|
}
|
2022-08-25 20:24:08 +00:00
|
|
|
|
|
|
|
++it;
|
2019-11-18 17:39:09 +00:00
|
|
|
}
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 08:09:25 +00:00
|
|
|
GL_FORCE_INLINE GLuint diffusePointerSize() {
|
2021-09-13 09:29:04 +00:00
|
|
|
return (ATTRIB_POINTERS.colour.size == GL_BGRA) ? 4 : ATTRIB_POINTERS.colour.size;
|
2021-04-23 08:09:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
static void _readDiffuseData(ReadDiffuseFunc func, const GLuint first, const GLuint count, Vertex* it) {
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLuint cstride = ATTRIB_POINTERS.colour.stride;
|
|
|
|
const GLubyte* cptr = ((GLubyte*) ATTRIB_POINTERS.colour.ptr) + (first * cstride);
|
2020-05-05 20:52:37 +00:00
|
|
|
|
|
|
|
ITERATE(count) {
|
2021-05-14 20:53:27 +00:00
|
|
|
PREFETCH(cptr + cstride);
|
2022-08-25 20:24:08 +00:00
|
|
|
func(cptr, it->bgra);
|
2020-05-05 20:52:37 +00:00
|
|
|
cptr += cstride;
|
2022-08-25 20:24:08 +00:00
|
|
|
++it;
|
2020-05-05 20:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generateElements(
|
|
|
|
SubmissionTarget* target, const GLsizei first, const GLuint count,
|
2020-05-06 07:42:09 +00:00
|
|
|
const GLubyte* indices, const GLenum type) {
|
2020-05-05 20:52:37 +00:00
|
|
|
|
|
|
|
const GLsizei istride = byte_size(type);
|
|
|
|
const IndexParseFunc IndexFunc = _calcParseIndexFunc(type);
|
|
|
|
|
|
|
|
GLubyte* xyz;
|
|
|
|
GLubyte* uv;
|
|
|
|
GLubyte* bgra;
|
|
|
|
GLubyte* st;
|
|
|
|
GLubyte* nxyz;
|
|
|
|
|
|
|
|
Vertex* output = _glSubmissionTargetStart(target);
|
|
|
|
VertexExtra* ve = aligned_vector_at(target->extras, 0);
|
|
|
|
|
|
|
|
uint32_t i = first;
|
|
|
|
uint32_t idx = 0;
|
|
|
|
|
2020-05-06 14:23:37 +00:00
|
|
|
const ReadPositionFunc pos_func = calcReadPositionFunc();
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLsizei vstride = ATTRIB_POINTERS.vertex.stride;
|
|
|
|
|
2020-05-06 14:23:37 +00:00
|
|
|
const ReadUVFunc uv_func = calcReadUVFunc();
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLuint uvstride = ATTRIB_POINTERS.uv.stride;
|
|
|
|
|
2020-05-06 14:23:37 +00:00
|
|
|
const ReadUVFunc st_func = calcReadSTFunc();
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLuint ststride = ATTRIB_POINTERS.st.stride;
|
2020-05-06 14:23:37 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
const ReadDiffuseFunc diffuse_func = calcReadDiffuseFunc();
|
|
|
|
const GLuint dstride = ATTRIB_POINTERS.colour.stride;
|
2020-05-06 14:23:37 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
const ReadNormalFunc normal_func = calcReadNormalFunc();
|
|
|
|
const GLuint nstride = ATTRIB_POINTERS.normal.stride;
|
2020-05-05 20:52:37 +00:00
|
|
|
|
|
|
|
for(; i < first + count; ++i) {
|
|
|
|
idx = IndexFunc(indices + (i * istride));
|
2020-05-06 07:42:09 +00:00
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
xyz = (GLubyte*) ATTRIB_POINTERS.vertex.ptr + (idx * vstride);
|
|
|
|
uv = (GLubyte*) ATTRIB_POINTERS.uv.ptr + (idx * uvstride);
|
|
|
|
bgra = (GLubyte*) ATTRIB_POINTERS.colour.ptr + (idx * dstride);
|
|
|
|
st = (GLubyte*) ATTRIB_POINTERS.st.ptr + (idx * ststride);
|
|
|
|
nxyz = (GLubyte*) ATTRIB_POINTERS.normal.ptr + (idx * nstride);
|
2020-05-05 20:52:37 +00:00
|
|
|
|
|
|
|
pos_func(xyz, (GLubyte*) output->xyz);
|
|
|
|
uv_func(uv, (GLubyte*) output->uv);
|
|
|
|
diffuse_func(bgra, output->bgra);
|
|
|
|
st_func(st, (GLubyte*) ve->st);
|
|
|
|
normal_func(nxyz, (GLubyte*) ve->nxyz);
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
output->flags = GPU_CMD_VERTEX;
|
2020-05-05 20:52:37 +00:00
|
|
|
++output;
|
2020-05-06 07:42:09 +00:00
|
|
|
++ve;
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 16:48:15 +00:00
|
|
|
typedef struct {
|
|
|
|
float x, y, z;
|
|
|
|
} Float3;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float u, v;
|
|
|
|
} Float2;
|
|
|
|
|
|
|
|
static const Float3 F3Z = {0.0f, 0.0f, 1.0f};
|
|
|
|
static const Float3 F3ZERO = {0.0f, 0.0f, 0.0f};
|
|
|
|
static const Float2 F2ZERO = {0.0f, 0.0f};
|
2021-09-13 18:35:53 +00:00
|
|
|
static const uint32_t U4ONE = ~0;
|
2021-04-22 16:48:15 +00:00
|
|
|
|
|
|
|
static void generateElementsFastPath(
|
|
|
|
SubmissionTarget* target, const GLsizei first, const GLuint count,
|
|
|
|
const GLubyte* indices, const GLenum type) {
|
|
|
|
|
|
|
|
Vertex* start = _glSubmissionTargetStart(target);
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLuint vstride = ATTRIB_POINTERS.vertex.stride;
|
|
|
|
const GLuint uvstride = ATTRIB_POINTERS.uv.stride;
|
|
|
|
const GLuint ststride = ATTRIB_POINTERS.st.stride;
|
|
|
|
const GLuint dstride = ATTRIB_POINTERS.colour.stride;
|
|
|
|
const GLuint nstride = ATTRIB_POINTERS.normal.stride;
|
2021-04-22 16:48:15 +00:00
|
|
|
|
|
|
|
const GLsizei istride = byte_size(type);
|
|
|
|
const IndexParseFunc IndexFunc = _calcParseIndexFunc(type);
|
|
|
|
|
|
|
|
/* Copy the pos, uv and color directly in one go */
|
2021-09-13 09:29:04 +00:00
|
|
|
const GLubyte* pos = (ENABLED_VERTEX_ATTRIBUTES & VERTEX_ENABLED_FLAG) ? ATTRIB_POINTERS.vertex.ptr : NULL;
|
|
|
|
const GLubyte* uv = (ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) ? ATTRIB_POINTERS.uv.ptr : NULL;
|
|
|
|
const GLubyte* col = (ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG) ? ATTRIB_POINTERS.colour.ptr : NULL;
|
|
|
|
const GLubyte* st = (ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) ? ATTRIB_POINTERS.st.ptr : NULL;
|
|
|
|
const GLubyte* n = (ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG) ? ATTRIB_POINTERS.normal.ptr : NULL;
|
2021-04-22 16:48:15 +00:00
|
|
|
|
|
|
|
VertexExtra* ve = aligned_vector_at(target->extras, 0);
|
|
|
|
Vertex* it = start;
|
|
|
|
|
|
|
|
const float w = 1.0f;
|
|
|
|
|
2021-05-25 19:40:43 +00:00
|
|
|
if(!pos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-22 16:48:15 +00:00
|
|
|
for(GLuint i = first; i < first + count; ++i) {
|
|
|
|
GLuint idx = IndexFunc(indices + (i * istride));
|
|
|
|
|
|
|
|
it->flags = GPU_CMD_VERTEX;
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
pos = (GLubyte*) ATTRIB_POINTERS.vertex.ptr + (idx * vstride);
|
2021-05-25 19:40:43 +00:00
|
|
|
TransformVertex((const float*) pos, &w, it->xyz, &it->w);
|
2021-04-22 16:48:15 +00:00
|
|
|
|
|
|
|
if(uv) {
|
2021-09-13 09:29:04 +00:00
|
|
|
uv = (GLubyte*) ATTRIB_POINTERS.uv.ptr + (idx * uvstride);
|
2021-04-22 16:48:15 +00:00
|
|
|
MEMCPY4(it->uv, uv, sizeof(float) * 2);
|
|
|
|
} else {
|
|
|
|
*((Float2*) it->uv) = F2ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(col) {
|
2021-09-13 09:29:04 +00:00
|
|
|
col = (GLubyte*) ATTRIB_POINTERS.colour.ptr + (idx * dstride);
|
2021-04-22 16:48:15 +00:00
|
|
|
MEMCPY4(it->bgra, col, sizeof(uint32_t));
|
|
|
|
} else {
|
|
|
|
*((uint32_t*) it->bgra) = ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(st) {
|
2021-09-13 09:29:04 +00:00
|
|
|
st = (GLubyte*) ATTRIB_POINTERS.st.ptr + (idx * ststride);
|
2021-04-22 16:48:15 +00:00
|
|
|
MEMCPY4(ve->st, st, sizeof(float) * 2);
|
|
|
|
} else {
|
|
|
|
*((Float2*) ve->st) = F2ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(n) {
|
2021-09-13 09:29:04 +00:00
|
|
|
n = (GLubyte*) ATTRIB_POINTERS.normal.ptr + (idx * nstride);
|
2021-04-22 16:48:15 +00:00
|
|
|
MEMCPY4(ve->nxyz, n, sizeof(float) * 3);
|
|
|
|
} else {
|
|
|
|
*((Float3*) ve->nxyz) = F3Z;
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
ve++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
|
2021-09-14 18:36:42 +00:00
|
|
|
#define POLYMODE ALL
|
|
|
|
#define PROCESS_VERTEX_FLAGS(it, i) { \
|
|
|
|
(it)->flags = GPU_CMD_VERTEX; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "draw_fastpath.inc"
|
|
|
|
#undef PROCESS_VERTEX_FLAGS
|
|
|
|
#undef POLYMODE
|
|
|
|
|
|
|
|
#define POLYMODE QUADS
|
|
|
|
#define PROCESS_VERTEX_FLAGS(it, i) { \
|
2023-05-31 17:27:17 +00:00
|
|
|
it->flags = GPU_CMD_VERTEX; \
|
|
|
|
if(((i + 1) % 4) == 0) { \
|
|
|
|
Vertex t = *it; \
|
|
|
|
*it = *(it - 1); \
|
|
|
|
*(it - 1) = t; \
|
2021-09-14 18:36:42 +00:00
|
|
|
it->flags = GPU_CMD_VERTEX_EOL; \
|
|
|
|
} \
|
|
|
|
}
|
2023-05-31 17:27:17 +00:00
|
|
|
|
2021-09-14 18:36:42 +00:00
|
|
|
#include "draw_fastpath.inc"
|
|
|
|
#undef PROCESS_VERTEX_FLAGS
|
|
|
|
#undef POLYMODE
|
|
|
|
|
|
|
|
#define POLYMODE TRIS
|
|
|
|
#define PROCESS_VERTEX_FLAGS(it, i) { \
|
|
|
|
it->flags = ((i + 1) % 3 == 0) ? GPU_CMD_VERTEX_EOL : GPU_CMD_VERTEX; \
|
|
|
|
}
|
|
|
|
#include "draw_fastpath.inc"
|
|
|
|
#undef PROCESS_VERTEX_FLAGS
|
|
|
|
#undef POLYMODE
|
2021-04-20 15:08:58 +00:00
|
|
|
|
2021-04-21 16:23:43 +00:00
|
|
|
static void generateArrays(SubmissionTarget* target, const GLsizei first, const GLuint count) {
|
|
|
|
Vertex* start = _glSubmissionTargetStart(target);
|
2021-04-20 15:08:58 +00:00
|
|
|
VertexExtra* ve = aligned_vector_at(target->extras, 0);
|
|
|
|
|
2022-08-25 20:24:08 +00:00
|
|
|
const ReadPositionFunc pfunc = calcReadPositionFunc();
|
|
|
|
const ReadDiffuseFunc dfunc = calcReadDiffuseFunc();
|
|
|
|
const ReadUVFunc uvfunc = calcReadUVFunc();
|
|
|
|
const ReadNormalFunc nfunc = calcReadNormalFunc();
|
|
|
|
const ReadUVFunc stfunc = calcReadSTFunc();
|
2021-04-21 16:23:43 +00:00
|
|
|
|
|
|
|
_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);
|
2021-04-20 15:08:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei first, const GLuint count,
|
2020-05-06 07:42:09 +00:00
|
|
|
const GLubyte* indices, const GLenum type) {
|
2018-08-16 16:51:15 +00:00
|
|
|
/* Read from the client buffers and generate an array of ClipVertices */
|
2019-03-28 13:09:04 +00:00
|
|
|
TRACE();
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2021-04-22 16:48:15 +00:00
|
|
|
if(FAST_PATH_ENABLED) {
|
|
|
|
if(indices) {
|
|
|
|
generateElementsFastPath(target, first, count, indices, type);
|
|
|
|
} else {
|
2022-11-04 19:24:12 +00:00
|
|
|
switch(mode) {
|
|
|
|
case GL_QUADS:
|
|
|
|
generateArraysFastPath_QUADS(target, first, count);
|
|
|
|
return; // Don't need to do any more processing
|
|
|
|
case GL_TRIANGLES:
|
|
|
|
generateArraysFastPath_TRIS(target, first, count);
|
|
|
|
return; // Don't need to do any more processing
|
|
|
|
default:
|
|
|
|
generateArraysFastPath_ALL(target, first, count);
|
2021-09-14 18:36:42 +00:00
|
|
|
}
|
2021-04-22 16:48:15 +00:00
|
|
|
}
|
2018-10-09 08:27:53 +00:00
|
|
|
} else {
|
2021-04-22 16:48:15 +00:00
|
|
|
if(indices) {
|
|
|
|
generateElements(target, first, count, indices, type);
|
|
|
|
} else {
|
|
|
|
generateArrays(target, first, count);
|
|
|
|
}
|
2020-05-05 20:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vertex* it = _glSubmissionTargetStart(target);
|
|
|
|
// Drawing arrays
|
|
|
|
switch(mode) {
|
|
|
|
case GL_TRIANGLES:
|
2021-10-02 13:43:23 +00:00
|
|
|
genTriangles(it, count);
|
|
|
|
break;
|
|
|
|
case GL_QUADS:
|
|
|
|
genQuads(it, count);
|
2020-05-05 20:52:37 +00:00
|
|
|
break;
|
|
|
|
case GL_TRIANGLE_FAN:
|
|
|
|
genTriangleFan(it, count);
|
|
|
|
break;
|
|
|
|
case GL_TRIANGLE_STRIP:
|
|
|
|
genTriangleStrip(it, count);
|
|
|
|
break;
|
|
|
|
default:
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(0 && "Not Implemented");
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 20:00:41 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void transform(SubmissionTarget* target) {
|
2019-03-28 13:09:04 +00:00
|
|
|
TRACE();
|
|
|
|
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform modelview transform, storing W */
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* vertex = _glSubmissionTargetStart(target);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
TransformVertices(vertex, target->count);
|
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) {
|
2021-04-09 15:24:47 +00:00
|
|
|
const uint8_t* dataIn = (const uint8_t*) xyz;
|
2018-07-09 07:57:01 +00:00
|
|
|
uint8_t* dataOut = (uint8_t*) xyzOut;
|
|
|
|
|
2019-03-26 09:09:07 +00:00
|
|
|
ITERATE(count) {
|
2021-04-09 15:24:47 +00:00
|
|
|
const float* in = (const float*) dataIn;
|
2018-07-09 07:57:01 +00:00
|
|
|
float* out = (float*) dataOut;
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
TransformVec3NoMod(
|
|
|
|
in,
|
|
|
|
out
|
|
|
|
);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
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) {
|
2021-04-09 15:24:47 +00:00
|
|
|
const uint8_t* dataIn = (const uint8_t*) xyz;
|
2018-07-09 07:57:01 +00:00
|
|
|
uint8_t* dataOut = (uint8_t*) xyzOut;
|
|
|
|
|
2019-03-26 09:09:07 +00:00
|
|
|
ITERATE(count) {
|
2021-04-09 15:24:47 +00:00
|
|
|
const float* in = (const float*) dataIn;
|
2018-07-09 07:57:01 +00:00
|
|
|
float* out = (float*) dataOut;
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
TransformNormalNoMod(in, out);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
dataIn += inStride;
|
|
|
|
dataOut += outStride;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void light(SubmissionTarget* target) {
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
aligned_vector_resize(eye_space_data, target->count);
|
2018-08-19 20:10:42 +00:00
|
|
|
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform lighting calculations and manipulate the colour */
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* vertex = _glSubmissionTargetStart(target);
|
2019-03-24 08:09:02 +00:00
|
|
|
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
2018-08-19 20:10:42 +00:00
|
|
|
EyeSpaceData* eye_space = (EyeSpaceData*) eye_space_data->data;
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
_glMatrixLoadNormal();
|
2019-03-24 08:09:02 +00:00
|
|
|
mat_transform_normal3(extra->nxyz, eye_space->n, target->count, sizeof(VertexExtra), sizeof(EyeSpaceData));
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
EyeSpaceData* ES = aligned_vector_at(eye_space_data, 0);
|
2019-12-27 10:36:30 +00:00
|
|
|
_glPerformLighting(vertex, ES, target->count);
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 13:25:30 +00:00
|
|
|
GL_FORCE_INLINE void divide(SubmissionTarget* target) {
|
2019-03-28 13:09:04 +00:00
|
|
|
TRACE();
|
|
|
|
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform perspective divide on each vertex */
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* vertex = _glSubmissionTargetStart(target);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2021-04-25 12:33:24 +00:00
|
|
|
const float h = GetVideoMode()->height;
|
2021-04-25 12:05:56 +00:00
|
|
|
|
2021-04-25 12:33:24 +00:00
|
|
|
ITERATE(target->count) {
|
|
|
|
const float f = MATH_Fast_Invert(vertex->w);
|
2021-04-25 12:05:56 +00:00
|
|
|
|
2021-04-25 12:33:24 +00:00
|
|
|
/* Convert to NDC and apply viewport */
|
2021-04-25 12:05:56 +00:00
|
|
|
vertex->xyz[0] = MATH_fmac(
|
2021-04-25 12:33:24 +00:00
|
|
|
VIEWPORT.hwidth, vertex->xyz[0] * f, VIEWPORT.x_plus_hwidth
|
2021-04-25 12:05:56 +00:00
|
|
|
);
|
2021-04-25 12:33:24 +00:00
|
|
|
vertex->xyz[1] = h - MATH_fmac(
|
|
|
|
VIEWPORT.hheight, vertex->xyz[1] * f, VIEWPORT.y_plus_hheight
|
2021-04-25 12:05:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/* Apply depth range */
|
2021-04-19 20:08:09 +00:00
|
|
|
vertex->xyz[2] = MAX(
|
2021-04-19 20:12:46 +00:00
|
|
|
1.0f - MATH_fmac(vertex->xyz[2] * f, 0.5f, 0.5f),
|
2021-04-19 20:08:09 +00:00
|
|
|
PVR_MIN_Z
|
|
|
|
);
|
2021-04-25 12:33:24 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
++vertex;
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
GL_FORCE_INLINE int _calc_pvr_face_culling() {
|
|
|
|
if(!_glIsCullingEnabled()) {
|
|
|
|
return GPU_CULLING_SMALL;
|
|
|
|
} else {
|
|
|
|
if(_glGetCullFace() == GL_BACK) {
|
|
|
|
return (_glGetFrontFace() == GL_CW) ? GPU_CULLING_CCW : GPU_CULLING_CW;
|
|
|
|
} else {
|
|
|
|
return (_glGetFrontFace() == GL_CCW) ? GPU_CULLING_CCW : GPU_CULLING_CW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_FORCE_INLINE int _calc_pvr_depth_test() {
|
|
|
|
if(!_glIsDepthTestEnabled()) {
|
|
|
|
return GPU_DEPTHCMP_ALWAYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(_glGetDepthFunc()) {
|
|
|
|
case GL_NEVER:
|
|
|
|
return GPU_DEPTHCMP_NEVER;
|
|
|
|
case GL_LESS:
|
|
|
|
return GPU_DEPTHCMP_GREATER;
|
|
|
|
case GL_EQUAL:
|
|
|
|
return GPU_DEPTHCMP_EQUAL;
|
|
|
|
case GL_LEQUAL:
|
|
|
|
return GPU_DEPTHCMP_GEQUAL;
|
|
|
|
case GL_GREATER:
|
|
|
|
return GPU_DEPTHCMP_LESS;
|
|
|
|
case GL_NOTEQUAL:
|
|
|
|
return GPU_DEPTHCMP_NOTEQUAL;
|
|
|
|
case GL_GEQUAL:
|
|
|
|
return GPU_DEPTHCMP_LEQUAL;
|
|
|
|
break;
|
|
|
|
case GL_ALWAYS:
|
|
|
|
default:
|
|
|
|
return GPU_DEPTHCMP_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_FORCE_INLINE int _calcPVRBlendFactor(GLenum factor) {
|
|
|
|
switch(factor) {
|
|
|
|
case GL_ZERO:
|
|
|
|
return GPU_BLEND_ZERO;
|
|
|
|
case GL_SRC_ALPHA:
|
|
|
|
return GPU_BLEND_SRCALPHA;
|
|
|
|
case GL_DST_COLOR:
|
|
|
|
return GPU_BLEND_DESTCOLOR;
|
|
|
|
case GL_DST_ALPHA:
|
|
|
|
return GPU_BLEND_DESTALPHA;
|
|
|
|
case GL_ONE_MINUS_DST_COLOR:
|
|
|
|
return GPU_BLEND_INVDESTCOLOR;
|
|
|
|
case GL_ONE_MINUS_SRC_ALPHA:
|
|
|
|
return GPU_BLEND_INVSRCALPHA;
|
|
|
|
case GL_ONE_MINUS_DST_ALPHA:
|
|
|
|
return GPU_BLEND_INVDESTALPHA;
|
|
|
|
case GL_ONE:
|
|
|
|
return GPU_BLEND_ONE;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Invalid blend mode: %u\n", (unsigned int) factor);
|
|
|
|
return GPU_BLEND_ONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GL_FORCE_INLINE void _updatePVRBlend(PolyContext* context) {
|
|
|
|
if(_glIsBlendingEnabled() || _glIsAlphaTestEnabled()) {
|
|
|
|
context->gen.alpha = GPU_ALPHA_ENABLE;
|
|
|
|
} else {
|
|
|
|
context->gen.alpha = GPU_ALPHA_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->blend.src = _calcPVRBlendFactor(_glGetBlendSourceFactor());
|
|
|
|
context->blend.dst = _calcPVRBlendFactor(_glGetBlendDestFactor());
|
|
|
|
}
|
|
|
|
|
2022-12-03 20:01:43 +00:00
|
|
|
GL_FORCE_INLINE void apply_poly_header(PolyHeader* header, GLboolean multiTextureHeader, PolyList* activePolyList, GLshort textureUnit) {
|
2019-03-28 13:09:04 +00:00
|
|
|
TRACE();
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
// Compile the header
|
2023-03-07 21:27:48 +00:00
|
|
|
PolyContext ctx;
|
|
|
|
memset(&ctx, 0, sizeof(PolyContext));
|
|
|
|
|
|
|
|
ctx.list_type = activePolyList->list_type;
|
|
|
|
ctx.fmt.color = GPU_CLRFMT_ARGBPACKED;
|
|
|
|
ctx.fmt.uv = GPU_UVFMT_32BIT;
|
|
|
|
ctx.gen.color_clamp = GPU_CLRCLAMP_DISABLE;
|
|
|
|
|
|
|
|
ctx.gen.culling = _calc_pvr_face_culling();
|
|
|
|
ctx.depth.comparison = _calc_pvr_depth_test();
|
|
|
|
ctx.depth.write = _glIsDepthWriteEnabled() ? GPU_DEPTHWRITE_ENABLE : GPU_DEPTHWRITE_DISABLE;
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
ctx.gen.shading = (_glGetShadeModel() == GL_SMOOTH) ? GPU_SHADE_GOURAUD : GPU_SHADE_FLAT;
|
|
|
|
|
|
|
|
if(_glIsScissorTestEnabled()) {
|
|
|
|
ctx.gen.clip_mode = GPU_USERCLIP_INSIDE;
|
|
|
|
} else {
|
|
|
|
ctx.gen.clip_mode = GPU_USERCLIP_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_glIsFogEnabled()) {
|
|
|
|
ctx.gen.fog_type = GPU_FOG_TABLE;
|
|
|
|
} else {
|
|
|
|
ctx.gen.fog_type = GPU_FOG_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_updatePVRBlend(&ctx);
|
|
|
|
|
|
|
|
if(ctx.list_type == GPU_LIST_OP_POLY) {
|
2021-05-23 19:58:01 +00:00
|
|
|
/* Opaque polys are always one/zero */
|
2023-03-07 21:27:48 +00:00
|
|
|
ctx.blend.src = GPU_BLEND_ONE;
|
|
|
|
ctx.blend.dst = GPU_BLEND_ZERO;
|
|
|
|
} else if(ctx.list_type == GPU_LIST_PT_POLY) {
|
2021-05-23 19:58:01 +00:00
|
|
|
/* Punch-through polys require fixed blending and depth modes */
|
2023-03-07 21:27:48 +00:00
|
|
|
ctx.blend.src = GPU_BLEND_SRCALPHA;
|
|
|
|
ctx.blend.dst = GPU_BLEND_INVSRCALPHA;
|
|
|
|
ctx.depth.comparison = GPU_DEPTHCMP_LEQUAL;
|
|
|
|
} else if(ctx.list_type == GPU_LIST_TR_POLY && AUTOSORT_ENABLED) {
|
2021-05-23 12:19:54 +00:00
|
|
|
/* Autosort mode requires this mode for transparent polys */
|
2023-03-07 21:27:48 +00:00
|
|
|
ctx.depth.comparison = GPU_DEPTHCMP_GEQUAL;
|
2021-05-23 12:15:07 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
_glUpdatePVRTextureContext(&ctx, textureUnit);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2019-09-09 08:36:06 +00:00
|
|
|
if(multiTextureHeader) {
|
2023-03-07 21:27:48 +00:00
|
|
|
gl_assert(ctx.list_type == GPU_LIST_TR_POLY);
|
2019-09-09 08:36:06 +00:00
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
ctx.gen.alpha = GPU_ALPHA_ENABLE;
|
|
|
|
ctx.txr.alpha = GPU_TXRALPHA_ENABLE;
|
|
|
|
ctx.blend.src = GPU_BLEND_ZERO;
|
|
|
|
ctx.blend.dst = GPU_BLEND_DESTCOLOR;
|
|
|
|
ctx.depth.comparison = GPU_DEPTHCMP_EQUAL;
|
2019-09-09 08:36:06 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
CompilePolyHeader(header, &ctx);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2022-12-03 14:00:24 +00:00
|
|
|
/* Force bits 18 and 19 on to switch to 6 triangle strips */
|
|
|
|
header->cmd |= 0xC0000;
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
/* Post-process the vertex list */
|
2019-03-24 08:09:02 +00:00
|
|
|
/*
|
|
|
|
* This is currently unnecessary. aligned_vector memsets the allocated objects
|
|
|
|
* to zero, and we don't touch oargb, also, we don't *enable* oargb yet in the
|
|
|
|
* pvr header so it should be ignored anyway. If this ever becomes a problem,
|
|
|
|
* uncomment this.
|
2018-08-21 08:37:19 +00:00
|
|
|
ClipVertex* vout = output;
|
2019-03-24 08:09:02 +00:00
|
|
|
const ClipVertex* end = output + count;
|
|
|
|
while(vout < end) {
|
2018-08-21 08:37:19 +00:00
|
|
|
vout->oargb = 0;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
2019-03-24 08:09:02 +00:00
|
|
|
*/
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 18:45:52 +00:00
|
|
|
#define DEBUG_CLIPPING 0
|
|
|
|
|
2022-11-04 19:23:50 +00:00
|
|
|
|
|
|
|
static AlignedVector VERTEX_EXTRAS;
|
|
|
|
static SubmissionTarget SUBMISSION_TARGET;
|
|
|
|
|
|
|
|
|
|
|
|
void _glInitSubmissionTarget() {
|
|
|
|
SubmissionTarget* target = &SUBMISSION_TARGET;
|
|
|
|
|
|
|
|
target->extras = NULL;
|
|
|
|
target->count = 0;
|
|
|
|
target->output = NULL;
|
|
|
|
target->header_offset = target->start_offset = 0;
|
|
|
|
|
|
|
|
aligned_vector_init(&VERTEX_EXTRAS, sizeof(VertexExtra));
|
|
|
|
target->extras = &VERTEX_EXTRAS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 13:25:30 +00:00
|
|
|
GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type, const GLvoid* indices) {
|
2023-05-20 06:44:55 +00:00
|
|
|
|
2022-11-04 19:23:50 +00:00
|
|
|
SubmissionTarget* const target = &SUBMISSION_TARGET;
|
|
|
|
AlignedVector* const extras = target->extras;
|
|
|
|
|
2019-03-28 13:09:04 +00:00
|
|
|
TRACE();
|
|
|
|
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Do nothing if vertices aren't enabled */
|
|
|
|
if(!(ENABLED_VERTEX_ATTRIBUTES & VERTEX_ENABLED_FLAG)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-25 16:06:41 +00:00
|
|
|
/* No vertices? Do nothing */
|
|
|
|
if(!count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:48:58 +00:00
|
|
|
/* Polygons are treated as triangle fans, the only time this would be a
|
|
|
|
* problem is if we supported glPolygonMode(..., GL_LINE) but we don't.
|
|
|
|
* We optimise the triangle and quad cases.
|
|
|
|
*/
|
|
|
|
if(mode == GL_POLYGON) {
|
2022-11-04 19:24:12 +00:00
|
|
|
switch(count) {
|
|
|
|
case 2:
|
|
|
|
mode = GL_LINES;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
mode = GL_TRIANGLES;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
mode = GL_QUADS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode = GL_TRIANGLE_FAN;
|
2019-03-25 09:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 19:23:50 +00:00
|
|
|
if(mode == GL_LINE_STRIP || mode == GL_LINES) {
|
|
|
|
fprintf(stderr, "Line drawing is currently unsupported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:48:58 +00:00
|
|
|
// We don't handle this any further, so just make sure we never pass it down */
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(mode != GL_POLYGON);
|
2019-03-25 09:48:58 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
target->output = _glActivePolyList();
|
2023-05-20 06:44:55 +00:00
|
|
|
gl_assert(target->output);
|
|
|
|
gl_assert(extras);
|
|
|
|
|
|
|
|
uint32_t vector_size = aligned_vector_size(&target->output->vector);
|
|
|
|
|
|
|
|
GLboolean header_required = (vector_size == 0) || _glGPUStateIsDirty();
|
2023-05-12 19:51:36 +00:00
|
|
|
|
2019-03-25 09:48:58 +00:00
|
|
|
target->count = (mode == GL_TRIANGLE_FAN) ? ((count - 2) * 3) : count;
|
2023-05-20 06:44:55 +00:00
|
|
|
target->header_offset = vector_size;
|
|
|
|
target->start_offset = target->header_offset + (header_required ? 1 : 0);
|
2018-08-01 11:00:56 +00:00
|
|
|
|
2023-05-20 06:44:55 +00:00
|
|
|
gl_assert(target->header_offset >= 0);
|
|
|
|
gl_assert(target->start_offset >= target->header_offset);
|
2022-08-25 20:24:08 +00:00
|
|
|
gl_assert(target->count);
|
2019-03-28 13:10:53 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* Make sure we have enough room for all the "extra" data */
|
2022-11-04 19:23:50 +00:00
|
|
|
aligned_vector_resize(extras, target->count);
|
2018-08-21 08:37:19 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* Make room for the vertices and header */
|
2023-03-07 21:27:48 +00:00
|
|
|
aligned_vector_extend(&target->output->vector, target->count + (header_required));
|
2021-04-21 16:23:43 +00:00
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
if(header_required) {
|
|
|
|
apply_poly_header(_glSubmissionTargetHeader(target), GL_FALSE, target->output, 0);
|
|
|
|
_glGPUStateMarkClean();
|
|
|
|
}
|
2022-12-03 20:01:43 +00:00
|
|
|
|
2021-04-25 12:05:56 +00:00
|
|
|
/* If we're lighting, then we need to do some work in
|
|
|
|
* eye-space, so we only transform vertices by the modelview
|
|
|
|
* matrix, and then later multiply by projection.
|
|
|
|
*
|
|
|
|
* If we're not doing lighting though we can optimise by taking
|
|
|
|
* vertices straight to clip-space */
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
if(_glIsLightingEnabled()) {
|
2021-04-25 12:05:56 +00:00
|
|
|
_glMatrixLoadModelView();
|
|
|
|
} else {
|
|
|
|
_glMatrixLoadModelViewProjection();
|
|
|
|
}
|
2021-04-21 16:23:43 +00:00
|
|
|
|
2021-04-25 12:05:56 +00:00
|
|
|
/* If we're FAST_PATH_ENABLED, then this will do the transform for us */
|
2020-05-06 07:42:09 +00:00
|
|
|
generate(target, mode, first, count, (GLubyte*) indices, type);
|
2018-08-04 20:00:26 +00:00
|
|
|
|
2021-04-25 12:05:56 +00:00
|
|
|
/* No fast path, then we have to do another iteration :( */
|
|
|
|
if(!FAST_PATH_ENABLED) {
|
|
|
|
/* Multiply by modelview */
|
|
|
|
transform(target);
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
if(_glIsLightingEnabled()){
|
2019-11-27 09:10:10 +00:00
|
|
|
light(target);
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2021-04-25 12:05:56 +00:00
|
|
|
/* OK eye-space work done, now move into clip space */
|
|
|
|
_glMatrixLoadProjection();
|
2021-04-21 16:23:43 +00:00
|
|
|
transform(target);
|
|
|
|
}
|
2018-08-01 10:32:07 +00:00
|
|
|
|
2023-03-07 21:27:48 +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
|
|
|
|
// */
|
|
|
|
|
|
|
|
// if(!TEXTURES_ENABLED[1]) {
|
|
|
|
// /* Multitexture actively disabled */
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TextureObject* texture1 = _glGetTexture1();
|
|
|
|
|
|
|
|
// /* Multitexture implicitly disabled */
|
|
|
|
// if(!texture1 || ((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG)) {
|
|
|
|
// /* Multitexture actively disabled */
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /* Push back a copy of the list to the transparent poly list, including the header
|
|
|
|
// (hence the + 1)
|
|
|
|
// */
|
|
|
|
// Vertex* vertex = aligned_vector_push_back(
|
|
|
|
// &_glTransparentPolyList()->vector, (Vertex*) _glSubmissionTargetHeader(target), target->count + 1
|
|
|
|
// );
|
|
|
|
|
|
|
|
// gl_assert(vertex);
|
|
|
|
|
|
|
|
// PolyHeader* mtHeader = (PolyHeader*) vertex++;
|
|
|
|
// /* Send the buffer again to the transparent list */
|
|
|
|
// apply_poly_header(mtHeader, GL_TRUE, _glTransparentPolyList(), 1);
|
|
|
|
|
|
|
|
// /* Replace the UV coordinates with the ST ones */
|
|
|
|
// VertexExtra* ve = aligned_vector_at(target->extras, 0);
|
|
|
|
// ITERATE(target->count) {
|
|
|
|
// vertex->uv[0] = ve->st[0];
|
|
|
|
// vertex->uv[1] = ve->st[1];
|
|
|
|
// ++vertex;
|
|
|
|
// ++ve;
|
|
|
|
// }
|
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();
|
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
if(_glCheckImmediateModeInactive(__func__)) {
|
2018-05-12 13:54:06 +00:00
|
|
|
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();
|
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
if(_glCheckImmediateModeInactive(__func__)) {
|
2018-05-12 13:54:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-28 13:07:53 +00:00
|
|
|
submitVertices(mode, first, count, GL_UNSIGNED_INT, 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:
|
2019-09-22 19:52:58 +00:00
|
|
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
2021-10-02 19:01:44 +00:00
|
|
|
|
|
|
|
/* 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();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2019-09-22 19:52:58 +00:00
|
|
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
2021-10-02 19:01:44 +00:00
|
|
|
|
|
|
|
/* State changed, recalculate */
|
|
|
|
_glRecalcFastPath();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2021-12-03 07:32:53 +00:00
|
|
|
if(texture < GL_TEXTURE0_ARB || texture > GL_TEXTURE0_ARB + MAX_GLDC_TEXTURE_UNITS) {
|
2020-03-05 19:48:37 +00:00
|
|
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
2018-05-11 14:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTIVE_CLIENT_TEXTURE = (texture == GL_TEXTURE1_ARB) ? 1 : 0;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 09:40:25 +00:00
|
|
|
GL_FORCE_INLINE GLboolean _glComparePointers(AttribPointer* p, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
|
|
|
|
return (p->size == size && p->type == type && p->stride == stride && p->ptr == pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
2018-05-11 14:39:28 +00:00
|
|
|
TRACE();
|
|
|
|
|
2019-04-14 07:51:37 +00:00
|
|
|
if(size < 1 || size > 4) {
|
|
|
|
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-04 19:23:06 +00:00
|
|
|
stride = (stride) ? stride : size * byte_size(type);
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
AttribPointer* tointer = (ACTIVE_CLIENT_TEXTURE == 0) ? &ATTRIB_POINTERS.uv : &ATTRIB_POINTERS.st;
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-09-13 09:40:25 +00:00
|
|
|
if(_glComparePointers(tointer, size, type, stride, pointer)) {
|
|
|
|
// No Change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
tointer->ptr = pointer;
|
2022-11-04 19:23:06 +00:00
|
|
|
tointer->stride = stride;
|
2018-05-11 14:39:28 +00:00
|
|
|
tointer->type = type;
|
|
|
|
tointer->size = size;
|
2021-09-13 09:40:25 +00:00
|
|
|
|
|
|
|
_glRecalcFastPath();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 19:40:43 +00:00
|
|
|
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
2018-05-11 14:39:28 +00:00
|
|
|
TRACE();
|
|
|
|
|
2019-04-14 07:51:37 +00:00
|
|
|
if(size < 2 || size > 4) {
|
|
|
|
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-04 19:23:06 +00:00
|
|
|
stride = (stride) ? stride : (size * byte_size(ATTRIB_POINTERS.vertex.type));
|
|
|
|
|
2021-09-13 09:40:25 +00:00
|
|
|
if(_glComparePointers(&ATTRIB_POINTERS.vertex, size, type, stride, pointer)) {
|
|
|
|
// No Change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.vertex.ptr = pointer;
|
2022-11-04 19:23:06 +00:00
|
|
|
ATTRIB_POINTERS.vertex.stride = stride;
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.vertex.type = type;
|
|
|
|
ATTRIB_POINTERS.vertex.size = size;
|
2021-09-13 09:40:25 +00:00
|
|
|
|
|
|
|
_glRecalcFastPath();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
|
|
|
|
TRACE();
|
|
|
|
|
2019-09-30 20:59:11 +00:00
|
|
|
if(size != 3 && size != 4 && size != GL_BGRA) {
|
2019-04-14 07:51:37 +00:00
|
|
|
_glKosThrowError(GL_INVALID_VALUE, __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-04 19:23:06 +00:00
|
|
|
stride = (stride) ? stride : ((size == GL_BGRA) ? 4 : size) * byte_size(type);
|
|
|
|
|
2021-09-13 09:40:25 +00:00
|
|
|
if(_glComparePointers(&ATTRIB_POINTERS.colour, size, type, stride, pointer)) {
|
|
|
|
// No Change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.colour.ptr = pointer;
|
|
|
|
ATTRIB_POINTERS.colour.type = type;
|
2021-10-02 13:43:23 +00:00
|
|
|
ATTRIB_POINTERS.colour.size = size;
|
2022-11-04 19:23:06 +00:00
|
|
|
ATTRIB_POINTERS.colour.stride = stride;
|
2021-09-13 09:40:25 +00:00
|
|
|
|
|
|
|
_glRecalcFastPath();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer) {
|
|
|
|
TRACE();
|
|
|
|
|
2020-02-29 09:47:04 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
if(_glCheckValidEnum(type, validTypes, __func__) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-04 19:23:06 +00:00
|
|
|
stride = (stride) ? stride : ATTRIB_POINTERS.normal.size * byte_size(type);
|
|
|
|
|
2021-09-13 09:40:25 +00:00
|
|
|
if(_glComparePointers(&ATTRIB_POINTERS.normal, 3, type, stride, pointer)) {
|
|
|
|
// No Change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.normal.ptr = pointer;
|
|
|
|
ATTRIB_POINTERS.normal.size = (type == GL_UNSIGNED_INT_2_10_10_10_REV) ? 1 : 3;
|
2022-11-04 19:23:06 +00:00
|
|
|
ATTRIB_POINTERS.normal.stride = stride;
|
2021-09-13 09:29:04 +00:00
|
|
|
ATTRIB_POINTERS.normal.type = type;
|
2021-09-13 09:40:25 +00:00
|
|
|
|
|
|
|
_glRecalcFastPath();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|