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>
|
2019-03-07 21:21:30 +00:00
|
|
|
#include <assert.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
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
void _glInitAttributePointers() {
|
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);
|
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
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
|
|
|
|
static void _readVertexData3f3f(const float* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float* end = (float*) (((GLubyte*) input) + (count * stride));
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* VE == VertexExtra */
|
|
|
|
static void _readVertexData3f3fVE(const float* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float* end = (float*) (((GLubyte*) input) + (count * stride));
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData3us3f(const GLushort* input, GLuint count, GLubyte stride, GLfloat* output) {
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLushort* end = (GLushort*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
|
|
|
|
|
|
|
input = (GLushort*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData3us3fVE(const GLushort* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const GLushort* end = (GLushort*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
|
|
|
|
|
|
|
input = (GLushort*) (((GLubyte*) input) + stride);
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData3ui3f(const GLuint* input, GLuint count, GLubyte stride, GLfloat* output) {
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLuint* end = (GLuint*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
|
|
|
|
|
|
|
input = (GLuint*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData3ui3fVE(const GLuint* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const GLuint* end = (GLuint*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = input[2];
|
|
|
|
|
|
|
|
input = (GLuint*) (((GLubyte*) input) + stride);
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData3ub3f(const GLubyte* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
|
|
|
const GLubyte* end = ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
input += stride;
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData3ub3fVE(const GLubyte* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
|
|
|
const GLubyte* end = ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
input += stride;
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData2f2f(const float* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float* end = (float*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData2f2fVE(const float* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const float* end = (float*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData2f3f(const float* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float* end = (float*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = 0.0f;
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData2ub3f(const GLubyte* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
|
|
|
const GLubyte* end = ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[2] = 0.0f;
|
|
|
|
|
|
|
|
input += stride;
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData2us3f(const GLushort* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const GLushort* end = (GLushort*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = 0.0f;
|
|
|
|
|
|
|
|
input = (GLushort*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData2us2f(const GLushort* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const GLushort* end = (GLushort*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
|
|
|
|
input = (GLushort*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData2us2fVE(const GLushort* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const GLushort* end = (GLushort*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
|
|
|
|
input = (GLushort*) (((GLubyte*) input) + stride);
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData2ui2f(const GLuint* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const GLuint* end = (GLuint*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
|
|
|
|
input = (GLuint*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData2ui2fVE(const GLuint* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const GLuint* end = (GLuint*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
|
|
|
|
input = (GLuint*) (((GLubyte*) input) + stride);
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData2ub2f(const GLubyte* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
|
|
|
const GLubyte* end = (GLubyte*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
|
|
|
|
input = (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _readVertexData2ub2fVE(const GLubyte* input, GLuint count, GLubyte stride, GLfloat* output) {
|
|
|
|
const float ONE_OVER_TWO_FIVE_FIVE = 1.0f / 255.0f;
|
|
|
|
const GLubyte* end = (GLubyte*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
output[1] = input[1] * ONE_OVER_TWO_FIVE_FIVE;
|
|
|
|
|
|
|
|
input = (((GLubyte*) input) + stride);
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData2ui3f(const GLuint* input, GLuint count, GLubyte stride, float* output) {
|
|
|
|
const GLuint* end = (GLuint*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[0] = input[0];
|
|
|
|
output[1] = input[1];
|
|
|
|
output[2] = 0.0f;
|
|
|
|
|
|
|
|
input = (GLuint*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (float*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData4ubARGB(const GLubyte* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
const GLubyte* end = ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[R8IDX] = input[0];
|
|
|
|
output[G8IDX] = input[1];
|
|
|
|
output[B8IDX] = input[2];
|
|
|
|
output[A8IDX] = input[3];
|
|
|
|
|
|
|
|
input = (GLubyte*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (GLubyte*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData4fARGB(const float* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
const float* end = (float*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[R8IDX] = (GLubyte) (input[0] * 255.0f);
|
|
|
|
output[G8IDX] = (GLubyte) (input[1] * 255.0f);
|
|
|
|
output[B8IDX] = (GLubyte) (input[2] * 255.0f);
|
|
|
|
output[A8IDX] = (GLubyte) (input[3] * 255.0f);
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (GLubyte*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData3fARGB(const float* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
const float* end = (float*) ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[R8IDX] = (GLubyte) (input[0] * 255.0f);
|
|
|
|
output[G8IDX] = (GLubyte) (input[1] * 255.0f);
|
|
|
|
output[B8IDX] = (GLubyte) (input[2] * 255.0f);
|
|
|
|
output[A8IDX] = 1.0f;
|
|
|
|
|
|
|
|
input = (float*) (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (GLubyte*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData3ubARGB(const GLubyte* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
const GLubyte* end = ((GLubyte*) input) + (count * stride);
|
|
|
|
|
|
|
|
while(input < end) {
|
|
|
|
output[R8IDX] = input[0];
|
|
|
|
output[G8IDX] = input[1];
|
|
|
|
output[B8IDX] = input[2];
|
|
|
|
output[A8IDX] = 1.0f;
|
|
|
|
|
|
|
|
input = (((GLubyte*) input) + stride);
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (GLubyte*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-13 11:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void _fillWithNegZVE(GLuint count, GLfloat* output) {
|
|
|
|
const GLfloat* end = output + (count * 3);
|
2019-03-14 13:15:56 +00:00
|
|
|
while(output < end) {
|
|
|
|
output[0] = output[1] = 0.0f;
|
|
|
|
output[2] = -1.0f;
|
2019-03-24 08:09:02 +00:00
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
2019-03-14 13:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _fillWhiteARGB(GLuint count, GLubyte* output) {
|
2019-03-25 09:44:59 +00:00
|
|
|
const GLubyte* end = output + (sizeof(Vertex) * count);
|
2019-03-14 13:15:56 +00:00
|
|
|
|
|
|
|
while(output < end) {
|
|
|
|
output[R8IDX] = 255;
|
|
|
|
output[G8IDX] = 255;
|
|
|
|
output[B8IDX] = 255;
|
|
|
|
output[A8IDX] = 255;
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
output += sizeof(Vertex);
|
2019-03-14 13:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _fillZero2f(GLuint count, GLfloat* output) {
|
2019-03-25 09:44:59 +00:00
|
|
|
const GLfloat* end = (GLfloat*) ((GLubyte*) output) + (count * sizeof(Vertex));
|
2019-03-14 13:15:56 +00:00
|
|
|
while(output < end) {
|
|
|
|
output[0] = output[1] = 0.0f;
|
2019-03-25 09:44:59 +00:00
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(Vertex));
|
2019-03-24 08:09:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _fillZero2fVE(GLuint count, GLfloat* output) {
|
|
|
|
const GLfloat* end = output + (2 * count);
|
|
|
|
while(output < end) {
|
|
|
|
output[0] = output[1] = 0.0f;
|
|
|
|
output = (GLfloat*) (((GLubyte*) output) + sizeof(VertexExtra));
|
2019-03-14 13:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void _readVertexData3usARGB(const GLushort* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData3uiARGB(const GLuint* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData4usARGB(const GLushort* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _readVertexData4uiARGB(const GLuint* input, GLuint count, GLubyte stride, GLubyte* output) {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
|
2018-08-21 15:08:06 +00:00
|
|
|
GLuint _glGetEnabledAttributes() {
|
|
|
|
return ENABLED_VERTEX_ATTRIBUTES;
|
|
|
|
}
|
|
|
|
|
2018-08-21 15:15:43 +00:00
|
|
|
AttribPointer* _glGetVertexAttribPointer() {
|
|
|
|
return &VERTEX_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetDiffuseAttribPointer() {
|
|
|
|
return &DIFFUSE_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetNormalAttribPointer() {
|
|
|
|
return &NORMAL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetUVAttribPointer() {
|
|
|
|
return &UV_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttribPointer* _glGetSTAttribPointer() {
|
|
|
|
return &ST_POINTER;
|
|
|
|
}
|
|
|
|
|
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) {
|
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]);
|
|
|
|
}
|
|
|
|
|
2018-07-14 20:54:43 +00:00
|
|
|
static 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]);
|
|
|
|
}
|
|
|
|
|
2019-03-25 10:33:05 +00:00
|
|
|
|
|
|
|
/* FIXME: SH4 has a swap.w instruction, we should leverage it here! */
|
2019-03-25 12:38:34 +00:00
|
|
|
#define _SWAP32(x, y) \
|
|
|
|
do { \
|
|
|
|
uint32_t t = *((uint32_t*) &x); \
|
|
|
|
*((uint32_t*) &x) = *((uint32_t*) &y); \
|
|
|
|
*((uint32_t*) &y) = t; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/*
|
2019-03-25 10:33:05 +00:00
|
|
|
*((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); \
|
|
|
|
*((uint32_t*) &y) = *((uint32_t*) &x) ^ *((uint32_t*) &y); \
|
2019-03-25 12:38:34 +00:00
|
|
|
*((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); */
|
2019-03-25 10:33:05 +00:00
|
|
|
|
|
|
|
|
2019-03-13 15:35:42 +00:00
|
|
|
#define swapVertex(a, b) \
|
|
|
|
do { \
|
2019-03-25 12:38:34 +00:00
|
|
|
_SWAP32(a->flags, b->flags); \
|
|
|
|
_SWAP32(a->xyz[0], b->xyz[0]); \
|
|
|
|
_SWAP32(a->xyz[1], b->xyz[1]); \
|
|
|
|
_SWAP32(a->xyz[2], b->xyz[2]); \
|
|
|
|
_SWAP32(a->uv[0], b->uv[0]); \
|
|
|
|
_SWAP32(a->uv[1], b->uv[1]); \
|
|
|
|
_SWAP32(a->bgra, b->bgra); \
|
|
|
|
_SWAP32(a->w, b->w); \
|
2019-03-13 15:35:42 +00:00
|
|
|
} while(0)
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2019-03-25 10:33:05 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
PVRHeader* _glSubmissionTargetHeader(SubmissionTarget* target) {
|
|
|
|
return aligned_vector_at(&target->output->vector, target->header_offset);
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* _glSubmissionTargetStart(SubmissionTarget* target) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static inline void genTriangles(Vertex* output, GLuint count) {
|
|
|
|
const Vertex* end = output + count;
|
|
|
|
Vertex* it = output + 2;
|
2019-03-13 17:38:42 +00:00
|
|
|
while(it < end) {
|
|
|
|
it->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
it += 3;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static inline void genQuads(Vertex* output, GLuint count) {
|
2019-03-25 10:33:05 +00:00
|
|
|
Vertex* this = output + 2;
|
|
|
|
Vertex* next = this + 1;
|
2019-03-25 09:44:59 +00:00
|
|
|
const Vertex* end = output + count;
|
2018-10-09 08:27:53 +00:00
|
|
|
|
2019-03-13 15:35:42 +00:00
|
|
|
while(this < end) {
|
2019-03-25 10:33:05 +00:00
|
|
|
swapVertex(this, next);
|
|
|
|
next->flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
|
2019-03-13 15:35:42 +00:00
|
|
|
this += 4;
|
2019-03-25 10:33:05 +00:00
|
|
|
next += 4;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static void genTriangleStrip(Vertex* output, GLuint count) {
|
2018-10-08 21:03:50 +00:00
|
|
|
output[count - 1].flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
}
|
|
|
|
|
2019-03-10 16:10:59 +00:00
|
|
|
#define MAX_POLYGON_SIZE 32
|
2019-03-07 21:41:25 +00:00
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static void genTriangleFan(Vertex* output, GLuint count) {
|
2019-03-10 12:24:27 +00:00
|
|
|
assert(count < MAX_POLYGON_SIZE);
|
2019-03-25 09:44:59 +00:00
|
|
|
static Vertex buffer[MAX_POLYGON_SIZE];
|
2019-03-10 12:24:27 +00:00
|
|
|
|
|
|
|
if(count <= 3){
|
|
|
|
output[2].flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
return;
|
|
|
|
}
|
2019-03-07 21:41:25 +00:00
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
memcpy(buffer, output, sizeof(Vertex) * count);
|
2019-03-07 21:41:25 +00:00
|
|
|
|
|
|
|
// First 3 vertices are in the right place, just end early
|
2018-10-08 21:03:50 +00:00
|
|
|
output[2].flags = PVR_CMD_VERTEX_EOL;
|
|
|
|
|
2019-03-07 21:41:25 +00:00
|
|
|
GLsizei i = 3, target = 3;
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* first = &output[0];
|
2018-10-08 21:03:50 +00:00
|
|
|
|
2019-03-07 21:41:25 +00:00
|
|
|
for(; i < count; ++i) {
|
|
|
|
output[target++] = *first;
|
2019-03-13 15:19:28 +00:00
|
|
|
output[target++] = buffer[i - 1];
|
|
|
|
output[target] = buffer[i];
|
2019-03-07 21:41:25 +00:00
|
|
|
output[target++].flags = PVR_CMD_VERTEX_EOL;
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static inline void _readPositionData(const GLuint first, const GLuint count, Vertex* output) {
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLubyte vstride = (VERTEX_POINTER.stride) ? VERTEX_POINTER.stride : VERTEX_POINTER.size * byte_size(VERTEX_POINTER.type);
|
|
|
|
const void* vptr = ((GLubyte*) VERTEX_POINTER.ptr + (first * vstride));
|
|
|
|
|
|
|
|
if(VERTEX_POINTER.size == 3) {
|
|
|
|
switch(VERTEX_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
|
|
|
_readVertexData3f3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
_readVertexData3ub3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
_readVertexData3us3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
_readVertexData3ui3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else if(VERTEX_POINTER.size == 2) {
|
|
|
|
switch(VERTEX_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
|
|
|
_readVertexData2f3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
_readVertexData2ub3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
_readVertexData2us3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
_readVertexData2ui3f(vptr, count, vstride, output[0].xyz);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static inline void _readUVData(const GLuint first, const GLuint count, Vertex* output) {
|
2019-03-14 13:15:56 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) != UV_ENABLED_FLAG) {
|
|
|
|
_fillZero2f(count, output->uv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLubyte uvstride = (UV_POINTER.stride) ? UV_POINTER.stride : UV_POINTER.size * byte_size(UV_POINTER.type);
|
|
|
|
const void* uvptr = ((GLubyte*) UV_POINTER.ptr + (first * uvstride));
|
|
|
|
|
|
|
|
if(UV_POINTER.size == 2) {
|
|
|
|
switch(UV_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
|
|
|
_readVertexData2f2f(uvptr, count, uvstride, output[0].uv);
|
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
_readVertexData2ub2f(uvptr, count, uvstride, output[0].uv);
|
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
_readVertexData2us2f(uvptr, count, uvstride, output[0].uv);
|
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
_readVertexData2ui2f(uvptr, count, uvstride, output[0].uv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static inline void _readSTData(const GLuint first, const GLuint count, SubmissionTarget* target) {
|
2019-03-14 13:15:56 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG) {
|
2019-03-24 08:09:02 +00:00
|
|
|
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
|
|
|
_fillZero2fVE(count, extra->st);
|
2019-03-14 13:15:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLubyte ststride = (ST_POINTER.stride) ? ST_POINTER.stride : ST_POINTER.size * byte_size(ST_POINTER.type);
|
|
|
|
const void* stptr = ((GLubyte*) ST_POINTER.ptr + (first * ststride));
|
|
|
|
|
|
|
|
if(ST_POINTER.size == 2) {
|
2019-03-24 08:09:02 +00:00
|
|
|
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
2019-03-13 11:24:35 +00:00
|
|
|
switch(ST_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData2f2fVE(stptr, count, ststride, extra->st);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData2ub2fVE(stptr, count, ststride, extra->st);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData2us2fVE(stptr, count, ststride, extra->st);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData2ui2fVE(stptr, count, ststride, extra->st);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static inline void _readNormalData(const GLuint first, const GLuint count, SubmissionTarget* target) {
|
2019-03-14 13:15:56 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG) != NORMAL_ENABLED_FLAG) {
|
2019-03-24 08:09:02 +00:00
|
|
|
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
|
|
|
_fillWithNegZVE(count, extra->nxyz);
|
2019-03-14 13:15:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLuint nstride = (NORMAL_POINTER.stride) ? NORMAL_POINTER.stride : NORMAL_POINTER.size * byte_size(NORMAL_POINTER.type);
|
|
|
|
const void* nptr = ((GLubyte*) NORMAL_POINTER.ptr + (first * nstride));
|
|
|
|
|
|
|
|
if(NORMAL_POINTER.size == 3) {
|
2019-03-24 08:09:02 +00:00
|
|
|
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
2019-03-13 11:24:35 +00:00
|
|
|
switch(NORMAL_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData3f3fVE(nptr, count, nstride, extra->nxyz);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData3ub3fVE(nptr, count, nstride, extra->nxyz);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData3us3fVE(nptr, count, nstride, extra->nxyz);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
2019-03-24 08:09:02 +00:00
|
|
|
_readVertexData3ui3fVE(nptr, count, nstride, extra->nxyz);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static inline void _readDiffuseData(const GLuint first, const GLuint count, Vertex* output) {
|
2019-03-14 13:15:56 +00:00
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG) != DIFFUSE_ENABLED_FLAG) {
|
|
|
|
/* Just fill the whole thing white if the attribute is disabled */
|
|
|
|
_fillWhiteARGB(count, output[0].bgra);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
const GLubyte cstride = (DIFFUSE_POINTER.stride) ? DIFFUSE_POINTER.stride : DIFFUSE_POINTER.size * byte_size(DIFFUSE_POINTER.type);
|
|
|
|
const void* cptr = ((GLubyte*) DIFFUSE_POINTER.ptr + (first * cstride));
|
|
|
|
|
|
|
|
if(DIFFUSE_POINTER.size == 3) {
|
|
|
|
switch(DIFFUSE_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
|
|
|
_readVertexData3fARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
_readVertexData3ubARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
_readVertexData3usARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
_readVertexData3uiARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else if(DIFFUSE_POINTER.size == 4) {
|
|
|
|
switch(DIFFUSE_POINTER.type) {
|
|
|
|
case GL_FLOAT:
|
|
|
|
_readVertexData4fARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
_readVertexData4ubARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
_readVertexData4usARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
_readVertexData4uiARGB(cptr, count, cstride, output[0].bgra);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Not Implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei first, const GLuint 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-10-09 08:27:53 +00:00
|
|
|
const GLsizei istride = byte_size(type);
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* it;
|
|
|
|
const Vertex* end;
|
2018-10-08 21:03:50 +00:00
|
|
|
|
2018-10-09 08:27:53 +00:00
|
|
|
if(!indices) {
|
2019-03-24 08:09:02 +00:00
|
|
|
_readPositionData(first, count, _glSubmissionTargetStart(target));
|
|
|
|
_readDiffuseData(first, count, _glSubmissionTargetStart(target));
|
|
|
|
if(doTexture) _readUVData(first, count, _glSubmissionTargetStart(target));
|
|
|
|
if(doLighting) _readNormalData(first, count, target);
|
|
|
|
if(doTexture && doMultitexture) _readSTData(first, count, target);
|
|
|
|
|
|
|
|
it = _glSubmissionTargetStart(target);
|
|
|
|
end = _glSubmissionTargetEnd(target);
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
while(it < end) {
|
|
|
|
(it++)->flags = PVR_CMD_VERTEX;
|
|
|
|
}
|
|
|
|
|
2018-10-08 21:03:50 +00:00
|
|
|
// Drawing arrays
|
|
|
|
switch(mode) {
|
|
|
|
case GL_TRIANGLES:
|
2019-03-24 08:09:02 +00:00
|
|
|
genTriangles(_glSubmissionTargetStart(target), count);
|
2018-10-09 08:27:53 +00:00
|
|
|
break;
|
2018-10-08 21:03:50 +00:00
|
|
|
case GL_QUADS:
|
2019-03-24 08:09:02 +00:00
|
|
|
genQuads(_glSubmissionTargetStart(target), count);
|
2018-10-09 08:27:53 +00:00
|
|
|
break;
|
2018-10-08 21:03:50 +00:00
|
|
|
case GL_TRIANGLE_FAN:
|
2019-03-24 08:09:02 +00:00
|
|
|
genTriangleFan(_glSubmissionTargetStart(target), count);
|
2018-10-09 08:27:53 +00:00
|
|
|
break;
|
2018-10-08 21:03:50 +00:00
|
|
|
case GL_TRIANGLE_STRIP:
|
2019-03-24 08:09:02 +00:00
|
|
|
genTriangleStrip(_glSubmissionTargetStart(target), count);
|
2019-03-13 11:24:35 +00:00
|
|
|
break;
|
2018-10-08 21:03:50 +00:00
|
|
|
default:
|
2019-03-13 11:24:35 +00:00
|
|
|
assert(0 && "Not Implemented");
|
2018-10-08 21:03:50 +00:00
|
|
|
}
|
2018-10-09 08:27:53 +00:00
|
|
|
} else {
|
2019-03-14 13:15:56 +00:00
|
|
|
const IndexParseFunc indexFunc = _calcParseIndexFunc(type);
|
2019-03-24 08:09:02 +00:00
|
|
|
it = _glSubmissionTargetStart(target);
|
|
|
|
end = _glSubmissionTargetEnd(target);
|
|
|
|
|
2019-03-14 13:15:56 +00:00
|
|
|
GLuint j;
|
|
|
|
const GLubyte* idx = indices;
|
|
|
|
while(it < end) {
|
|
|
|
j = indexFunc(idx);
|
|
|
|
_readPositionData(j, 1, it);
|
|
|
|
_readDiffuseData(j, 1, it);
|
|
|
|
if(doTexture) _readUVData(j, 1, it);
|
2019-03-24 08:09:02 +00:00
|
|
|
//FIXME: Need to think about how we can share this */
|
|
|
|
//if(doLighting) _readNormalData(j, 1, it);
|
|
|
|
//if(doTexture && doMultitexture) _readSTData(j, 1, it);
|
2019-03-14 13:15:56 +00:00
|
|
|
++it;
|
|
|
|
idx += istride;
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
it = _glSubmissionTargetStart(target);
|
2019-03-14 13:15:56 +00:00
|
|
|
while(it < end) {
|
|
|
|
(it++)->flags = PVR_CMD_VERTEX;
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
it = _glSubmissionTargetStart(target);
|
2019-03-14 13:15:56 +00:00
|
|
|
// Drawing arrays
|
|
|
|
switch(mode) {
|
|
|
|
case GL_TRIANGLES:
|
2019-03-24 08:09:02 +00:00
|
|
|
genTriangles(it, count);
|
2019-03-14 13:15:56 +00:00
|
|
|
break;
|
|
|
|
case GL_QUADS:
|
2019-03-24 08:09:02 +00:00
|
|
|
genQuads(it, count);
|
2019-03-14 13:15:56 +00:00
|
|
|
break;
|
|
|
|
case GL_TRIANGLE_FAN:
|
2019-03-24 08:09:02 +00:00
|
|
|
genTriangleFan(it, count);
|
2019-03-14 13:15:56 +00:00
|
|
|
break;
|
|
|
|
case GL_TRIANGLE_STRIP:
|
2019-03-24 08:09:02 +00:00
|
|
|
genTriangleStrip(it, count);
|
2019-03-14 13:15:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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) {
|
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);
|
|
|
|
const Vertex* end = _glSubmissionTargetEnd(target);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
_glApplyRenderMatrix(); /* Apply the Render Matrix Stack */
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
while(vertex < end) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void clip(SubmissionTarget* target) {
|
2018-07-09 07:57:01 +00:00
|
|
|
/* Perform clipping, generating new vertices as necessary */
|
2019-03-24 08:09:02 +00:00
|
|
|
_glClipTriangleStrip(target, _glGetShadeModel() == GL_FLAT);
|
2018-09-06 19:08:55 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* Reset the count now that we may have added vertices */
|
|
|
|
target->count = target->output->vector.size - target->start_offset;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void light(SubmissionTarget* target) {
|
2019-03-03 19:06:01 +00:00
|
|
|
if(!_glIsLightingEnabled()) {
|
2018-07-09 07:57:01 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
_glMatrixLoadModelView();
|
2019-03-25 09:44:59 +00:00
|
|
|
mat_transform3(vertex->xyz, eye_space->xyz, target->count, sizeof(Vertex), sizeof(EyeSpaceData));
|
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
|
|
|
|
|
|
|
GLsizei i;
|
2018-08-19 20:10:42 +00:00
|
|
|
EyeSpaceData* ES = aligned_vector_at(eye_space_data, 0);
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
for(i = 0; i < target->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) {
|
2019-03-03 19:06:01 +00:00
|
|
|
if(_glIsLightEnabled(j)) {
|
2018-08-22 08:24:49 +00:00
|
|
|
_glCalculateLightingContribution(j, ES->xyz, ES->n, vertex->bgra, 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
|
|
|
|
2018-08-27 20:35:07 +00:00
|
|
|
vertex->bgra[A8IDX] = (GLubyte) (255.0f * fminf(total[3], 1.0f));
|
|
|
|
vertex->bgra[R8IDX] = (GLubyte) (255.0f * fminf(total[0], 1.0f));
|
|
|
|
vertex->bgra[G8IDX] = (GLubyte) (255.0f * fminf(total[1], 1.0f));
|
|
|
|
vertex->bgra[B8IDX] = (GLubyte) (255.0f * fminf(total[2], 1.0f));
|
2018-07-09 07:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
static void divide(SubmissionTarget* target) {
|
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);
|
|
|
|
const Vertex* end = _glSubmissionTargetEnd(target);
|
2018-07-09 07:57:01 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
while(vertex < end) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
static void push(PVRHeader* header, Vertex* output, const GLuint count, PolyList* activePolyList, GLshort textureUnit) {
|
2018-08-21 08:37:19 +00:00
|
|
|
// Compile the header
|
2019-03-03 19:06:01 +00:00
|
|
|
pvr_poly_cxt_t cxt = *_glGetPVRContext();
|
2018-07-09 07:57:01 +00:00
|
|
|
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 */
|
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
|
|
|
|
|
2019-03-13 11:24:35 +00:00
|
|
|
static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type, const GLvoid* indices) {
|
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-24 08:09:02 +00:00
|
|
|
static SubmissionTarget* target = NULL;
|
|
|
|
static AlignedVector extras;
|
|
|
|
|
|
|
|
/* Initialization of the target and extras */
|
|
|
|
if(!target) {
|
|
|
|
target = (SubmissionTarget*) malloc(sizeof(SubmissionTarget));
|
|
|
|
target->extras = NULL;
|
|
|
|
target->count = 0;
|
|
|
|
target->output = NULL;
|
|
|
|
target->header_offset = target->start_offset = 0;
|
|
|
|
|
|
|
|
aligned_vector_init(&extras, sizeof(VertexExtra));
|
|
|
|
target->extras = &extras;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
doLighting = _glIsLightingEnabled();
|
2018-08-19 20:10:42 +00:00
|
|
|
|
2018-08-21 14:50:41 +00:00
|
|
|
glActiveTextureARB(activeTexture);
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_push(__func__);
|
|
|
|
|
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) {
|
|
|
|
if(count == 3) {
|
|
|
|
mode = GL_TRIANGLES;
|
|
|
|
} else if(count == 4) {
|
|
|
|
mode = GL_QUADS;
|
|
|
|
} else {
|
|
|
|
mode = GL_TRIANGLE_FAN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't handle this any further, so just make sure we never pass it down */
|
|
|
|
assert(mode != GL_POLYGON);
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
target->output = _glActivePolyList();
|
2019-03-25 09:48:58 +00:00
|
|
|
target->count = (mode == GL_TRIANGLE_FAN) ? ((count - 2) * 3) : count;
|
2019-03-24 08:09:02 +00:00
|
|
|
target->header_offset = target->output->vector.size;
|
|
|
|
target->start_offset = target->header_offset + 1;
|
2018-08-01 11:00:56 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* Make sure we have enough room for all the "extra" data */
|
|
|
|
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 */
|
|
|
|
aligned_vector_extend(&target->output->vector, target->count + 1);
|
2018-09-06 19:00:18 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("allocate");
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
generate(target, 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
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
light(target);
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("light");
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
transform(target);
|
2018-08-01 10:32:07 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("transform");
|
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
if(_glIsClippingEnabled()) {
|
2018-09-06 18:45:52 +00:00
|
|
|
#if DEBUG_CLIPPING
|
2018-09-03 20:48:42 +00:00
|
|
|
uint32_t i = 0;
|
2018-09-06 18:19:00 +00:00
|
|
|
fprintf(stderr, "=========\n");
|
|
|
|
|
|
|
|
for(i = offset; i < activeList->vector.size; ++i) {
|
2018-09-03 20:48:42 +00:00
|
|
|
ClipVertex* v = aligned_vector_at(&activeList->vector, i);
|
|
|
|
if(v->flags == 0xe0000000 || v->flags == 0xf0000000) {
|
|
|
|
fprintf(stderr, "(%f, %f, %f) -> %x\n", v->xyz[0], v->xyz[1], v->xyz[2], v->flags);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%x\n", *((uint32_t*)v));
|
|
|
|
}
|
2018-09-06 18:45:52 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-09-06 18:19:00 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
clip(target);
|
2018-09-19 16:11:56 +00:00
|
|
|
|
2018-09-06 18:45:52 +00:00
|
|
|
#if DEBUG_CLIPPING
|
2018-09-06 18:19:00 +00:00
|
|
|
fprintf(stderr, "--------\n");
|
|
|
|
for(i = offset; i < activeList->vector.size; ++i) {
|
|
|
|
ClipVertex* v = aligned_vector_at(&activeList->vector, i);
|
|
|
|
if(v->flags == 0xe0000000 || v->flags == 0xf0000000) {
|
|
|
|
fprintf(stderr, "(%f, %f, %f) -> %x\n", v->xyz[0], v->xyz[1], v->xyz[2], v->flags);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%x\n", *((uint32_t*)v));
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 18:46:04 +00:00
|
|
|
#endif
|
|
|
|
|
2018-08-01 10:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("clip");
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
divide(target);
|
2018-08-16 16:51:15 +00:00
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
profiler_checkpoint("divide");
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
push(_glSubmissionTargetHeader(target), _glSubmissionTargetStart(target), target->count, _glActivePolyList(), 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
|
|
|
|
*/
|
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
TextureObject* texture1 = _glGetTexture1();
|
2018-08-04 20:00:26 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* Multitexture implicitly disabled */
|
2018-08-04 20:00:26 +00:00
|
|
|
if(!texture1 || ((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG)) {
|
2019-03-24 08:09:02 +00:00
|
|
|
doMultitexture = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!doMultitexture) {
|
|
|
|
/* Multitexture actively 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
|
2019-03-24 08:09:02 +00:00
|
|
|
(hence the + 1)
|
2018-08-21 08:37:19 +00:00
|
|
|
*/
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* vertex = aligned_vector_push_back(
|
|
|
|
&_glTransparentPolyList()->vector, (Vertex*) _glSubmissionTargetHeader(target), target->count + 1
|
2018-08-21 08:37:19 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
PVRHeader* mtHeader = (PVRHeader*) vertex++;
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* mtStart = vertex;
|
2018-08-04 20:00:26 +00:00
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* Replace the UV coordinates with the ST ones */
|
|
|
|
const VertexExtra* end = aligned_vector_back(target->extras) + 1;
|
|
|
|
VertexExtra* ve = aligned_vector_at(target->extras, 0);
|
|
|
|
while(ve < end) {
|
|
|
|
vertex->uv[0] = ve->st[0];
|
|
|
|
vertex->uv[1] = ve->st[1];
|
2018-08-19 20:10:42 +00:00
|
|
|
++vertex;
|
2019-03-24 08:09:02 +00:00
|
|
|
++ve;
|
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);
|
2019-03-24 14:09:52 +00:00
|
|
|
|
|
|
|
/* This is modulation, we need to switch depending on the texture env mode! */
|
|
|
|
glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
2018-08-04 20:00:26 +00:00
|
|
|
|
|
|
|
/* Send the buffer again to the transparent list */
|
2019-03-24 08:09:02 +00:00
|
|
|
push(mtHeader, mtStart, target->count, _glTransparentPolyList(), 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();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|