Add glNormalX, remove more dead code

This commit is contained in:
Luke Benstead 2018-05-12 21:20:26 +01:00
parent 97f4e020ad
commit c76338b16f
3 changed files with 30 additions and 162 deletions

View File

@ -1,3 +1,12 @@
/*
* This implements immediate mode over the top of glDrawArrays
* current problems:
*
* 1. Calling glNormal(); glVertex(); glVertex(); glVertex(); will break.
* 2. Mixing with glXPointer stuff will break badly
* 3. This is entirely untested.
*/
#include "../include/gl.h"
#include "private.h"
@ -7,11 +16,14 @@ static GLenum ACTIVE_POLYGON_MODE = GL_TRIANGLES;
static AlignedVector VERTICES;
static AlignedVector COLOURS;
static AlignedVector TEXCOORDS;
static AlignedVector NORMALS;
void initImmediateMode() {
aligned_vector_init(&VERTICES, sizeof(GLfloat));
aligned_vector_init(&COLOURS, sizeof(GLfloat));
aligned_vector_init(&TEXCOORDS, sizeof(GLfloat));
aligned_vector_init(&NORMALS, sizeof(GLfloat));
}
GLubyte checkImmediateModeInactive(const char* func) {
@ -66,6 +78,12 @@ void APIENTRY glVertex3fv(const GLfloat* v) {
glVertex3f(v[0], v[1], v[2]);
}
void APIENTRY glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
aligned_vector_push_back(&VERTICES, &x, 1);
aligned_vector_push_back(&VERTICES, &y, 1);
aligned_vector_push_back(&VERTICES, &z, 1);
}
void APIENTRY glVertex4fv(const GLfloat* v) {
glVertex4f(v[0], v[1], v[2], v[3]);
}
@ -79,6 +97,16 @@ void APIENTRY glTexCoord2fv(const GLfloat* v) {
glTexCoord2f(v[0], v[1]);
}
void APIENTRY glNormal3f(GLfloat x, GLfloat y, GLfloat z) {
aligned_vector_push_back(&NORMALS, &x, 1);
aligned_vector_push_back(&NORMALS, &y, 1);
aligned_vector_push_back(&NORMALS, &z, 1);
}
void APIENTRY glNormal3fv(const GLfloat* v) {
glNormal3f(v[0], v[1], v[2]);
}
void APIENTRY glEnd() {
IMMEDIATE_MODE_ACTIVE = GL_FALSE;
@ -86,6 +114,7 @@ void APIENTRY glEnd() {
glVertexPointer(3, GL_FLOAT, 0, VERTICES.data);
glColorPointer(4, GL_FLOAT, 0, COLOURS.data);
glNormalPointer(GL_FLOAT, 0, NORMALS.data);
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, 0, TEXCOORDS.data);
@ -95,6 +124,7 @@ void APIENTRY glEnd() {
aligned_vector_clear(&VERTICES);
aligned_vector_clear(&COLOURS);
aligned_vector_clear(&TEXCOORDS);
aligned_vector_clear(&NORMALS);
/* FIXME: Pop pointers */
}

View File

@ -94,19 +94,6 @@ GLubyte _glKosGetMaxLights() {
return GL_KOS_MAX_LIGHTS;
}
/* Vertex Normal Submission */
void glNormal3f(GLfloat x, GLfloat y, GLfloat z) {
GL_VERTEX_NORMAL[0] = x;
GL_VERTEX_NORMAL[1] = y;
GL_VERTEX_NORMAL[2] = z;
}
void glNormal3fv(const GLfloat *xyz) {
GL_VERTEX_NORMAL[0] = xyz[0];
GL_VERTEX_NORMAL[1] = xyz[1];
GL_VERTEX_NORMAL[2] = xyz[2];
}
/* Misc Lighting Functions ************************************/
static inline void glCopyRGBA(const rgba *src, rgba *dst) {
*dst = *src;

149
gl-pvr.c
View File

@ -47,52 +47,8 @@ static GLuint GL_LIST = GL_KOS_LIST_OP;
#define GL_KOS_MAX_MULTITEXTURE_OBJECTS 512
static GL_MULTITEX_OBJECT GL_MTOBJS[GL_KOS_MAX_MULTITEXTURE_OBJECTS];
static GLuint GL_MTOBJECTS = 0;
/* Custom version of sq_cpy from KOS for copying vertex data to the PVR */
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;
}
#ifdef GL_KOS_USE_DMA
/* Custom version of sq_cpy from KOS for copying 32bytes of vertex data to the PVR */
static void pvr_hdr_submit(const GLuint *src) {
GLuint *d = TA_SQ_ADDR;
d[0] = *(src++);
d[1] = *(src++);
d[2] = *(src++);
d[3] = *(src++);
d[4] = *(src++);
d[5] = *(src++);
d[6] = *(src++);
d[7] = *(src++);
__asm__("pref @%0" : : "r"(d));
}
#endif
void _glKosResetMultiTexObject() {
GL_MTOBJECTS = 0;
}
@ -218,110 +174,5 @@ void _glKosVertexBufCopy(void *dst, void *src, GLuint count) {
memcpy(dst, src, count * 0x20);
}
static void glutSwapBuffer() {
#ifndef GL_KOS_USE_DMA
QACR0 = QACRTA;
QACR1 = QACRTA;
#endif
pvr_list_begin(PVR_LIST_OP_POLY);
#ifdef GL_KOS_USE_DMA
pvr_dma_transfer(_glKosVertexBufAddress(GL_KOS_LIST_OP), 0,
_glKosVertexBufCount(GL_KOS_LIST_OP) * 32,
PVR_DMA_TA, 1, NULL, 0);
#else
pvr_list_submit(_glKosVertexBufAddress(GL_KOS_LIST_OP), _glKosVertexBufCount(GL_KOS_LIST_OP));
#endif
pvr_list_finish();
pvr_list_begin(PVR_LIST_TR_POLY);
#ifdef GL_KOS_USE_DMA
pvr_dma_transfer(_glKosVertexBufAddress(GL_KOS_LIST_TR), 0,
_glKosVertexBufCount(GL_KOS_LIST_TR) * 32,
PVR_DMA_TA, 1, NULL, 0);
#else
pvr_list_submit(_glKosVertexBufAddress(GL_KOS_LIST_TR), _glKosVertexBufCount(GL_KOS_LIST_TR));
#endif
/* Multi-Texture Pass - Modify U/V coords of submitted vertices */
GLuint i, v;
glTexCoord *mt = _glKosMultiUVBufAddress();
for(i = 0; i < GL_MTOBJECTS; i++) {
//copy vertex uv
for(v = 0; v < GL_MTOBJS[i].count; v ++) {
GL_MTOBJS[i].src[v].u = mt->u;
GL_MTOBJS[i].src[v].v = mt->v;
++mt;
}
// submit vertex data to PVR
#ifdef GL_KOS_USE_DMA
pvr_hdr_submit((GLuint *)&GL_MTOBJS[i].hdr);
pvr_dma_transfer(GL_MTOBJS[i].src, 0,
GL_MTOBJS[i].count * 32, PVR_DMA_TA, 1, NULL, 0);
#else
pvr_list_submit((pvr_poly_hdr_t *)&GL_MTOBJS[i].hdr, 1);
pvr_list_submit((pvr_vertex_t *)GL_MTOBJS[i].src, GL_MTOBJS[i].count);
#endif
}
_glKosResetMultiTexObject(); /* End Multi-Texture Pass */
pvr_list_finish();
pvr_scene_finish();
}
void glutSwapBuffers() {
pvr_wait_ready();
if(_glKosGetFBO()) {
GLsizei w = _glKosGetFBOWidth(_glKosGetFBO());
GLsizei h = _glKosGetFBOHeight(_glKosGetFBO());
pvr_scene_begin_txr(_glKosGetFBOData(_glKosGetFBO()), &w, &h);
}
else
pvr_scene_begin();
glutSwapBuffer();
_glKosVertexBufReset();
_glKosMultiUVBufReset();
}
void glutCopyBufferToTexture(void *dst, GLsizei *x, GLsizei *y) {
if(_glKosGetFBO()) {
pvr_wait_ready();
pvr_scene_begin_txr(dst, x, y);
glutSwapBuffer();
}
}
int _glKosInitPVR() {
GLubyte i;
pvr_init_params_t params = {
/* Enable opaque and translucent polygons with size 32 and 32 */
{ PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_0 },
GL_PVR_VERTEX_BUF_SIZE, /* Vertex buffer size */
0, /* No DMA */
0, /* No FSAA */
1 /* Disable translucent auto-sorting to match traditional GL */
};
pvr_init(&params);
for(i = 0; i < 2; ++i) {
GL_VBUF[i] = memalign(0x20, COMMANDS_PER_ALLOC * sizeof(pvr_cmd_t));
GL_VERTS_ALLOCATED[i] = COMMANDS_PER_ALLOC;
}
GL_CBUF = malloc((GL_KOS_MAX_VERTS / 2) * sizeof(pvr_cmd_t));
GL_UVBUF = malloc(GL_KOS_MAX_VERTS * sizeof(glTexCoord));
return 1;
}