2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <kos.h>
|
|
|
|
|
2019-03-11 19:07:59 +00:00
|
|
|
#include "../include/glkos.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
#include "../containers/aligned_vector.h"
|
|
|
|
#include "private.h"
|
2018-08-16 16:51:15 +00:00
|
|
|
#include "profiler.h"
|
2019-09-22 20:48:21 +00:00
|
|
|
#include "version.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
#define TA_SQ_ADDR (unsigned int *)(void *) \
|
|
|
|
(0xe0000000 | (((unsigned long)0x10000000) & 0x03ffffe0))
|
|
|
|
|
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
|
|
|
|
|
|
|
static void pvr_list_submit(void *src, int n) {
|
|
|
|
GLuint *d = TA_SQ_ADDR;
|
|
|
|
GLuint *s = src;
|
|
|
|
|
|
|
|
/* fill/write queues as many times necessary */
|
|
|
|
while(n--) {
|
|
|
|
__asm__("pref @%0" : : "r"(s + 8)); /* prefetch 32 bytes for next loop */
|
|
|
|
d[0] = *(s++);
|
|
|
|
d[1] = *(s++);
|
|
|
|
d[2] = *(s++);
|
|
|
|
d[3] = *(s++);
|
|
|
|
d[4] = *(s++);
|
|
|
|
d[5] = *(s++);
|
|
|
|
d[6] = *(s++);
|
|
|
|
d[7] = *(s++);
|
|
|
|
__asm__("pref @%0" : : "r"(d));
|
|
|
|
d += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for both store queues to complete */
|
|
|
|
d = (GLuint *)0xe0000000;
|
|
|
|
d[0] = d[8] = 0;
|
|
|
|
}
|
|
|
|
|
2020-03-18 20:47:12 +00:00
|
|
|
static void _glInitPVR(GLboolean autosort, GLboolean fsaa) {
|
2018-05-05 19:38:55 +00:00
|
|
|
pvr_init_params_t params = {
|
|
|
|
/* Enable opaque and translucent polygons with size 32 and 32 */
|
2019-03-10 19:59:34 +00:00
|
|
|
{PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32},
|
2018-05-11 14:39:28 +00:00
|
|
|
PVR_VERTEX_BUF_SIZE, /* Vertex buffer size */
|
2018-05-05 19:38:55 +00:00
|
|
|
0, /* No DMA */
|
2020-03-18 20:47:12 +00:00
|
|
|
fsaa, /* No FSAA */
|
2019-03-11 19:07:59 +00:00
|
|
|
(autosort) ? 0 : 1 /* Disable translucent auto-sorting to match traditional GL */
|
2018-05-05 19:38:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pvr_init(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2019-03-13 15:43:50 +00:00
|
|
|
config->initial_op_capacity = 1024;
|
|
|
|
config->initial_pt_capacity = 512;
|
|
|
|
config->initial_tr_capacity = 1024;
|
|
|
|
config->initial_immediate_capacity = 1024;
|
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);
|
|
|
|
|
2020-03-18 20:47:12 +00:00
|
|
|
_glInitPVR(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
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
OP_LIST.list_type = PVR_LIST_OP_POLY;
|
|
|
|
PT_LIST.list_type = PVR_LIST_PT_POLY;
|
|
|
|
TR_LIST.list_type = PVR_LIST_TR_POLY;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-09-03 19:47:24 +00:00
|
|
|
#define QACRTA ((((unsigned int)0x10000000)>>26)<<2)&0x1c
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void APIENTRY glKosSwapBuffers() {
|
2018-08-19 20:10:42 +00:00
|
|
|
static int frame_count = 0;
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
TRACE();
|
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
profiler_push(__func__);
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
pvr_wait_ready();
|
|
|
|
|
|
|
|
pvr_scene_begin();
|
2018-09-03 19:47:24 +00:00
|
|
|
QACR0 = QACRTA;
|
|
|
|
QACR1 = QACRTA;
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
pvr_list_begin(PVR_LIST_OP_POLY);
|
2018-05-11 14:39:28 +00:00
|
|
|
pvr_list_submit(OP_LIST.vector.data, OP_LIST.vector.size);
|
2018-05-05 19:38:55 +00:00
|
|
|
pvr_list_finish();
|
|
|
|
|
|
|
|
pvr_list_begin(PVR_LIST_PT_POLY);
|
2018-05-11 14:39:28 +00:00
|
|
|
pvr_list_submit(PT_LIST.vector.data, PT_LIST.vector.size);
|
2018-05-05 19:38:55 +00:00
|
|
|
pvr_list_finish();
|
|
|
|
|
|
|
|
pvr_list_begin(PVR_LIST_TR_POLY);
|
2018-05-11 14:39:28 +00:00
|
|
|
pvr_list_submit(TR_LIST.vector.data, TR_LIST.vector.size);
|
2018-05-05 19:38:55 +00:00
|
|
|
pvr_list_finish();
|
|
|
|
pvr_scene_finish();
|
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
|
|
|
|
2018-08-21 08:37:19 +00:00
|
|
|
profiler_checkpoint("scene");
|
|
|
|
profiler_pop();
|
|
|
|
|
2018-08-19 20:10:42 +00:00
|
|
|
if(frame_count++ > 100) {
|
|
|
|
profiler_print_stats();
|
|
|
|
frame_count = 0;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|