2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
#include "../containers/aligned_vector.h"
|
|
|
|
#include "private.h"
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
static PolyList OP_LIST;
|
|
|
|
static PolyList PT_LIST;
|
|
|
|
static PolyList TR_LIST;
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
PolyList* _glActivePolyList() {
|
2019-03-03 19:06:01 +00:00
|
|
|
if(_glIsBlendingEnabled()) {
|
2018-05-11 14:39:28 +00:00
|
|
|
return &TR_LIST;
|
2019-03-10 17:53:58 +00:00
|
|
|
} else if(_glIsAlphaTestEnabled()) {
|
|
|
|
return &PT_LIST;
|
2018-05-11 14:39:28 +00:00
|
|
|
} else {
|
|
|
|
return &OP_LIST;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
PolyList* _glOpaquePolyList() {
|
|
|
|
return &OP_LIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
PolyList* _glPunchThruPolyList() {
|
|
|
|
return &PT_LIST;
|
|
|
|
}
|
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
PolyList *_glTransparentPolyList() {
|
2018-08-04 20:00:26 +00:00
|
|
|
return &TR_LIST;
|
|
|
|
}
|
|
|
|
|
2019-03-10 12:19:41 +00:00
|
|
|
void APIENTRY glFlush() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY glFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 19:07:59 +00:00
|
|
|
void APIENTRY glKosInitConfig(GLdcConfig* config) {
|
|
|
|
config->autosort_enabled = GL_FALSE;
|
2020-03-18 20:47:12 +00:00
|
|
|
config->fsaa_enabled = GL_FALSE;
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
config->initial_op_capacity = 1024 * 3;
|
|
|
|
config->initial_pt_capacity = 512 * 3;
|
|
|
|
config->initial_tr_capacity = 1024 * 3;
|
|
|
|
config->initial_immediate_capacity = 1024 * 3;
|
2019-03-11 19:07:59 +00:00
|
|
|
config->internal_palette_format = GL_RGBA4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY glKosInitEx(GLdcConfig* config) {
|
2018-05-11 14:39:28 +00:00
|
|
|
TRACE();
|
|
|
|
|
2019-09-22 20:48:21 +00:00
|
|
|
printf("\nWelcome to GLdc! Git revision: %s\n\n", GLDC_VERSION);
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
InitGPU(config->autosort_enabled, config->fsaa_enabled);
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
_glInitMatrices();
|
|
|
|
_glInitAttributePointers();
|
2018-09-15 10:45:38 +00:00
|
|
|
_glInitContext();
|
|
|
|
_glInitLights();
|
2019-03-13 15:43:50 +00:00
|
|
|
_glInitImmediateMode(config->initial_immediate_capacity);
|
2019-03-03 19:02:25 +00:00
|
|
|
_glInitFramebuffers();
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2019-03-13 08:51:05 +00:00
|
|
|
_glSetInternalPaletteFormat(config->internal_palette_format);
|
2019-03-11 19:07:59 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
_glInitTextures();
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
OP_LIST.list_type = GPU_LIST_OP_POLY;
|
|
|
|
PT_LIST.list_type = GPU_LIST_PT_POLY;
|
|
|
|
TR_LIST.list_type = GPU_LIST_TR_POLY;
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
aligned_vector_init(&OP_LIST.vector, sizeof(Vertex));
|
|
|
|
aligned_vector_init(&PT_LIST.vector, sizeof(Vertex));
|
|
|
|
aligned_vector_init(&TR_LIST.vector, sizeof(Vertex));
|
2019-03-11 19:07:59 +00:00
|
|
|
|
2019-03-13 15:43:50 +00:00
|
|
|
aligned_vector_reserve(&OP_LIST.vector, config->initial_op_capacity);
|
|
|
|
aligned_vector_reserve(&PT_LIST.vector, config->initial_pt_capacity);
|
|
|
|
aligned_vector_reserve(&TR_LIST.vector, config->initial_tr_capacity);
|
2019-03-11 19:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY glKosInit() {
|
|
|
|
GLdcConfig config;
|
|
|
|
glKosInitConfig(&config);
|
|
|
|
glKosInitEx(&config);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:14:33 +00:00
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
|
|
|
|
GL_FORCE_INLINE bool glIsVertex(const float flags) {
|
|
|
|
return flags == GPU_CMD_VERTEX_EOL || flags == GPU_CMD_VERTEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GL_FORCE_INLINE void glPerspectiveDivide(void* src, uint32_t n) {
|
|
|
|
TRACE();
|
|
|
|
|
|
|
|
/* Perform perspective divide on each vertex */
|
|
|
|
Vertex* vertex = (Vertex*) src;
|
|
|
|
|
|
|
|
const float h = GetVideoMode()->height;
|
|
|
|
|
|
|
|
while(n--) {
|
|
|
|
__asm__("pref @%0" : : "r"(vertex + 1));
|
|
|
|
|
|
|
|
if(likely(glIsVertex(vertex->flags))) {
|
|
|
|
const float f = MATH_Fast_Invert(vertex->w);
|
|
|
|
|
|
|
|
/* Convert to NDC and apply viewport */
|
|
|
|
vertex->xyz[0] = MATH_fmac(
|
|
|
|
VIEWPORT.hwidth, vertex->xyz[0] * f, VIEWPORT.x_plus_hwidth
|
|
|
|
);
|
|
|
|
|
|
|
|
vertex->xyz[1] = h - MATH_fmac(
|
|
|
|
VIEWPORT.hheight, vertex->xyz[1] * f, VIEWPORT.y_plus_hheight
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Apply depth range */
|
|
|
|
vertex->xyz[2] = MAX(
|
|
|
|
1.0f - MATH_fmac(vertex->xyz[2] * f, 0.5f, 0.5f),
|
|
|
|
PVR_MIN_Z
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
++vertex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-03 19:47:24 +00:00
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glKosSwapBuffers() {
|
|
|
|
TRACE();
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
SceneBegin();
|
|
|
|
SceneListBegin(GPU_LIST_OP_POLY);
|
2021-04-26 15:14:33 +00:00
|
|
|
glPerspectiveDivide(OP_LIST.vector.data, OP_LIST.vector.size);
|
2021-04-09 15:24:47 +00:00
|
|
|
SceneListSubmit(OP_LIST.vector.data, OP_LIST.vector.size);
|
|
|
|
SceneListFinish();
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
SceneListBegin(GPU_LIST_PT_POLY);
|
2021-04-26 15:14:33 +00:00
|
|
|
glPerspectiveDivide(PT_LIST.vector.data, PT_LIST.vector.size);
|
2021-04-09 15:24:47 +00:00
|
|
|
SceneListSubmit(PT_LIST.vector.data, PT_LIST.vector.size);
|
|
|
|
SceneListFinish();
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
SceneListBegin(GPU_LIST_TR_POLY);
|
2021-04-26 15:14:33 +00:00
|
|
|
glPerspectiveDivide(TR_LIST.vector.data, TR_LIST.vector.size);
|
2021-04-09 15:24:47 +00:00
|
|
|
SceneListSubmit(TR_LIST.vector.data, TR_LIST.vector.size);
|
|
|
|
SceneListFinish();
|
|
|
|
SceneFinish();
|
2018-05-11 14:39:28 +00:00
|
|
|
|
|
|
|
aligned_vector_clear(&OP_LIST.vector);
|
|
|
|
aligned_vector_clear(&PT_LIST.vector);
|
|
|
|
aligned_vector_clear(&TR_LIST.vector);
|
2018-08-19 20:10:42 +00:00
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
_glApplyScissor(true);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|