From: PH3NOM <ph...@us...> - 2015-01-04 22:13:15
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The KallistiOS port of OpenGL.". The branch, master has been updated via 763ec9948364538cacef45526e1e1ce785c11f18 (commit) from 4af2c8aacc9d59b3314767f16acddf9cb25ee73a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 763ec9948364538cacef45526e1e1ce785c11f18 Author: Josh Pearson <ph...@us...> Date: Sun Jan 4 15:07:57 2015 -0800 Added multi-texture support and glCompressedTexImage2D to the GL API ----------------------------------------------------------------------- Summary of changes: Makefile | 4 +- gl-api.c | 91 +++++-- gl-api.h | 54 ++++- gl-arrays.c | 732 ++++++++++++++++++++++++++++++++++-------------------- gl-arrays.h | 35 +--- gl-cap.c | 4 +- gl-clip-arrays.c | 418 +++++++++++++++++++++++++++++++ gl-clip.c | 621 +++++++--------------------------------------- gl-clip.h | 10 +- gl-light.c | 8 +- gl-matrix.c | 3 +- gl-pvr.c | 121 +++++++--- gl-pvr.h | 10 +- gl-texture.c | 146 ++++++++--- include/gl.h | 75 ++++-- include/glext.h | 78 ++++++- include/glu.h | 2 +- include/glut.h | 4 +- 18 files changed, 1428 insertions(+), 988 deletions(-) create mode 100755 gl-clip-arrays.c diff --git a/Makefile b/Makefile index 246c828..53b3f5d 100755 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ # Copyright (C) 2014 Lawrence Sebald TARGET = libgl.a -OBJS = gl-rgb.o gl-fog.o gl-sh4-light.o gl-light.o gl-clip.o gl-pvr.o -OBJS += gl-arrays.o gl-matrix.o gl-api.o gl-texture.o glu-texture.o +OBJS = gl-rgb.o gl-fog.o gl-sh4-light.o gl-light.o gl-clip.o gl-clip-arrays.o +OBJS += gl-arrays.o gl-pvr.o gl-matrix.o gl-api.o gl-texture.o glu-texture.o OBJS += gl-framebuffer.o gl-cap.o gl-error.o SUBDIRS = diff --git a/gl-api.c b/gl-api.c index 31ddbd7..b9fae8c 100755 --- a/gl-api.c +++ b/gl-api.c @@ -290,25 +290,25 @@ void APIENTRY glVertex2fv(const GLfloat *xy) { } void APIENTRY glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) { - pvr_vertex_t * v = _glKosVertexBufPointer(); - + pvr_vertex_t *v = _glKosVertexBufPointer(); + v[0].z = v[3].z = 0; - + mat_trans_single3_nomod(x1, y1, v[0].z, v[0].x, v[0].y, v[0].z); mat_trans_single3_nomod(x2, y2, v[3].z, v[3].x, v[3].y, v[3].z); - - _glKosFinishRect(); + + _glKosFinishRect(); } void APIENTRY glRectfv(const GLfloat *v1, const GLfloat *v2) { - pvr_vertex_t * v = _glKosVertexBufPointer(); - + pvr_vertex_t *v = _glKosVertexBufPointer(); + v[0].z = v[3].z = 0; - + mat_trans_single3_nomod(v1[0], v1[1], v[0].z, v[0].x, v[0].y, v[0].z); mat_trans_single3_nomod(v2[0], v2[1], v[3].z, v[3].x, v[3].y, v[3].z); - - _glKosFinishRect(); + + _glKosFinishRect(); } void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2) { @@ -582,46 +582,46 @@ void _glKosVertex3fcv(const GLfloat *xyz) { /* GL_POINTS */ GLvoid _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z) { - pvr_vertex_t * v = _glKosVertexBufPointer(); + pvr_vertex_t *v = _glKosVertexBufPointer(); mat_trans_single3_nomod(x - GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z, v[0].x, v[0].y, v[0].z); mat_trans_single3_nomod(x + GL_KOS_POINT_SIZE, y - GL_KOS_POINT_SIZE, z, v[3].x, v[3].y, v[3].z); - - _glKosFinishRect(); + + _glKosFinishRect(); } GLvoid _glKosVertex3fpv(const GLfloat *xyz) { - pvr_vertex_t * v = _glKosVertexBufPointer(); + pvr_vertex_t *v = _glKosVertexBufPointer(); mat_trans_single3_nomod(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2], v[0].x, v[0].y, v[0].z); mat_trans_single3_nomod(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2], v[3].x, v[3].y, v[3].z); - - _glKosFinishRect(); + + _glKosFinishRect(); } static inline void _glKosFinishRect() { - pvr_vertex_t * v = _glKosVertexBufPointer(); - + pvr_vertex_t *v = _glKosVertexBufPointer(); + v[0].argb = v[1].argb = v[2].argb = v[3].argb = GL_KOS_VERTEX_COLOR; - + v[0].flags = v[1].flags = v[2].flags = PVR_CMD_VERTEX; v[3].flags = PVR_CMD_VERTEX_EOL; v[1].x = v[0].x; v[1].y = v[3].y; v[1].z = v[3].z; - + v[2].x = v[3].x; v[2].y = v[0].y; - v[2].z = v[0].z; - - _glKosVertexBufAdd( 4 ); - - GL_KOS_VERTEX_COUNT += 4; + v[2].z = v[0].z; + + _glKosVertexBufAdd(4); + + GL_KOS_VERTEX_COUNT += 4; } void _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts) { @@ -732,6 +732,12 @@ static inline void _glKosApplyBlendFunc() { } } +static inline void _glKosApplyTextureFunc(GL_TEXTURE_OBJECT *tex) { + GL_KOS_POLY_CXT.txr.uv_clamp = tex->uv_clamp; + GL_KOS_POLY_CXT.txr.mipmap = tex->mip_map ? 1 : 0; + GL_KOS_POLY_CXT.txr.mipmap_bias = PVR_MIPBIAS_NORMAL; +} + void _glKosCompileHdr() { pvr_poly_hdr_t *hdr = _glKosVertexBufPointer(); @@ -777,9 +783,7 @@ void _glKosCompileHdrT(GL_TEXTURE_OBJECT *tex) { _glKosApplyBlendFunc(); - GL_KOS_POLY_CXT.txr.uv_clamp = tex->uv_clamp; - GL_KOS_POLY_CXT.txr.mipmap = tex->mip_map ? 1 : 0; - GL_KOS_POLY_CXT.txr.mipmap_bias = PVR_MIPBIAS_NORMAL; + _glKosApplyTextureFunc(tex); if(_glKosEnabledBlend()) GL_KOS_POLY_CXT.txr.env = tex->env; @@ -792,6 +796,37 @@ void _glKosCompileHdrT(GL_TEXTURE_OBJECT *tex) { _glKosVertexBufIncrement(); } +void _glKosCompileHdrMT(pvr_poly_hdr_t *dst, GL_TEXTURE_OBJECT *tex) { + pvr_poly_cxt_txr(&GL_KOS_POLY_CXT, + PVR_LIST_TR_POLY, + tex->color, + tex->width, + tex->height, + tex->data, + tex->filter); + + GL_KOS_POLY_CXT.gen.shading = GL_KOS_SHADE_FUNC; + + _glKosApplyDepthFunc(); + + _glKosApplyScissorFunc(); + + _glKosApplyFogFunc(); + + _glKosApplyCullingFunc(); + + _glKosApplyTextureFunc(tex); + + GL_KOS_POLY_CXT.blend.src = (GL_KOS_BLEND_FUNC & 0xF0) >> 4; + GL_KOS_POLY_CXT.blend.dst = (GL_KOS_BLEND_FUNC & 0x0F); + GL_KOS_POLY_CXT.txr.env = tex->env; + + pvr_poly_compile(dst, &GL_KOS_POLY_CXT); + + if(GL_KOS_SUPERSAMPLE) + dst->mode2 |= GL_PVR_SAMPLE_SUPER << PVR_TA_SUPER_SAMPLE_SHIFT; +} + //====================================================================================================// //== Internal GL KOS API State Functions ==// diff --git a/gl-api.h b/gl-api.h index b505649..9f3082f 100755 --- a/gl-api.h +++ b/gl-api.h @@ -10,12 +10,18 @@ #ifndef GL_API_H #define GL_API_H +#include "gl.h" + typedef struct { - float pos[3]; - float norm[3]; + GLfloat pos[3]; + GLfloat norm[3]; } glVertex; /* Simple Vertex used for Dynamic Vertex Lighting */ typedef struct { + GLfloat u, v; +} glTexCoord; /* Simple Texture Coordinate used for Multi-Texturing */ + +typedef struct { GLushort width; GLushort height; GLuint color; @@ -35,8 +41,14 @@ typedef struct { GLvoid *link; } GL_FRAMEBUFFER_OBJECT; /* KOS Open GL Frame Buffer Object */ -typedef unsigned short uint16; -typedef unsigned char uint8; +typedef struct { + pvr_poly_hdr_t hdr; + pvr_vertex_t *src; + GLuint count; +} GL_MULTITEX_OBJECT; + +typedef GLushort uint16; +typedef GLubyte uint8; /* Vertex Main Buffer Internal Functions */ inline void _glKosVertexBufSwitchOP(); @@ -54,6 +66,11 @@ inline unsigned int _glKosVertexBufCount(unsigned char list); unsigned char _glKosList(); inline void _glKosVertexBufCopy(void *src, void *dst, GLuint count); inline void _glKosResetEnabledTex(); +inline void *_glKosMultiUVBufAddress(); +inline void *_glKosMultiUVBufPointer(); +inline void _glKosMultiUVBufIncrement(); +inline void _glKosMultiUVBufAdd(GLuint count); +inline void _glKosMultiUVBufReset(); /* Vertex Clip Buffer Internal Functions */ inline void *_glKosClipBufAddress(); @@ -69,13 +86,14 @@ inline glVertex *_glKosArrayBufPtr(); /* Initialize the OpenGL PVR Pipeline */ int _glKosInitPVR(); -GLubyte _glKosInitTextures(); +unsigned char _glKosInitTextures(); /* Compile the current Polygon Header for the PVR */ void _glKosCompileHdr(); void _glKosCompileHdrTx(); -void _glKosCompileHdrTx2(); +void _glKosCompileHdrMTx(); void _glKosCompileHdrT(GL_TEXTURE_OBJECT *tex); +void _glKosCompileHdrMT(pvr_poly_hdr_t *dst, GL_TEXTURE_OBJECT *tex); /* Clipping Internal Functions */ void _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts); @@ -84,10 +102,17 @@ unsigned int _glKosClipTriangles(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned unsigned int _glKosClipQuads(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices); unsigned int _glKosClipTrianglesTransformed(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, GLuint count); -unsigned char _glKosClipTriTransformed(pvr_vertex_t *vin, float *w, pvr_vertex_t *vout); unsigned int _glKosClipQuadsTransformed(pvr_vertex_t *vin, float *w, pvr_vertex_t *vout, unsigned int vertices); unsigned int _glKosClipTriangleStripTransformed(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, GLuint count); +unsigned int _glKosClipTrianglesTransformedMT(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, + GLfloat *uvsrc, glTexCoord *uvdst, GLuint uv_src_stride, GLuint count); +unsigned int _glKosClipTriangleStripTransformedMT(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, + GLfloat *uvsrc, glTexCoord *uvdst, GLuint uv_src_stride, GLuint count); +unsigned int _glKosClipQuadsTransformedMT(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, + GLfloat *uvsrc, glTexCoord *uvdst, GLuint uv_src_stride, GLuint count); + + /* Lighting Internal Functions */ void _glKosInitLighting(); void _glKosEnableLight(const GLuint light); @@ -176,5 +201,20 @@ GLubyte _glKosIsLightEnabled(GLubyte light); GLubyte _glKosGetMaxLights(); GLuint _glKosBoundTexID(); GLuint _glKosVertexColor(); +GLubyte _glKosMaxTextureUnits(); + +GL_TEXTURE_OBJECT *_glKosBoundMultiTexID(); + +inline void _glKosPushMultiTexObject(GL_TEXTURE_OBJECT *tex, + pvr_vertex_t *src, + GLuint count); + +static inline void _glKosVertexCopyPVR(const pvr_vertex_t *src, pvr_vertex_t *dst) { + *dst = *src; +} + +static inline void _glKosTexCoordCopy(const glTexCoord *src, glTexCoord *dst) { + *dst = *src; +} #endif diff --git a/gl-arrays.c b/gl-arrays.c index 248fbde..efdc366 100755 --- a/gl-arrays.c +++ b/gl-arrays.c @@ -19,21 +19,44 @@ #include <stdlib.h> #include "gl.h" +#include "glext.h" #include "gl-api.h" #include "gl-arrays.h" +#include "gl-pvr.h" #include "gl-rgb.h" #include "gl-sh4.h" //========================================================================================// //== Local Variables ==// -#define GL_MAX_ARRAY_VERTICES 1024*32 /* Maximum Number of Vertices in the Array Buffer */ -static glVertex GL_ARRAY_BUF[GL_MAX_ARRAY_VERTICES]; -static GLfloat GL_ARRAY_BUFW[GL_MAX_ARRAY_VERTICES]; -static GLfloat GL_ARRAY_DSTW[GL_MAX_ARRAY_VERTICES]; -static glVertex *GL_ARRAY_BUF_PTR; -static GLuint GL_VERTEX_PTR_MODE = 0; +static glVertex GL_KOS_ARRAY_BUF[GL_KOS_MAX_VERTS]; +static glVertex *GL_KOS_ARRAY_BUF_PTR; + +static GLfloat GL_KOS_ARRAY_BUFW[GL_KOS_MAX_VERTS]; +static GLfloat GL_KOS_ARRAY_DSTW[GL_KOS_MAX_VERTS]; + +static GLfloat GL_KOS_ARRAY_BUFUV[GL_KOS_MAX_VERTS]; + +static GLubyte GL_KOS_CLIENT_ACTIVE_TEXTURE = GL_TEXTURE0_ARB & 0xF; + +static GLfloat *GL_KOS_VERTEX_POINTER = NULL; +static GLfloat *GL_KOS_NORMAL_POINTER = NULL; +static GLfloat *GL_KOS_TEXCOORD0_POINTER = NULL; +static GLfloat *GL_KOS_TEXCOORD1_POINTER = NULL; +static GLfloat *GL_KOS_COLOR_POINTER = NULL; +static GLubyte *GL_KOS_INDEX_POINTER_U8 = NULL; +static GLushort *GL_KOS_INDEX_POINTER_U16 = NULL; + +static GLushort GL_KOS_VERTEX_STRIDE = 0; +static GLushort GL_KOS_NORMAL_STRIDE = 0; +static GLushort GL_KOS_TEXCOORD0_STRIDE = 0; +static GLushort GL_KOS_TEXCOORD1_STRIDE = 0; +static GLushort GL_KOS_COLOR_STRIDE = 0; + +static GLuint GL_KOS_VERTEX_PTR_MODE = 0; static GLubyte GL_KOS_VERTEX_SIZE = 0; +static GLubyte GL_KOS_COLOR_COMPONENTS = 0; +static GLenum GL_KOS_COLOR_TYPE = 0; //========================================================================================// //== Local Function Definitions ==// @@ -41,6 +64,12 @@ static GLubyte GL_KOS_VERTEX_SIZE = 0; static inline void _glKosArraysTransformNormals(GLfloat *normal, GLuint count); static inline void _glKosArraysTransformPositions(GLfloat *position, GLuint count); +void (*_glKosArrayTexCoordFunc)(pvr_vertex_t *); +void (*_glKosArrayColorFunc)(pvr_vertex_t *); + +void (*_glKosElementTexCoordFunc)(pvr_vertex_t *, GLuint); +void (*_glKosElementColorFunc)(pvr_vertex_t *, GLuint); + //========================================================================================// //== Open GL API Public Functions ==// @@ -61,14 +90,14 @@ GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type, _glKosPrintError(); return; } - + GL_KOS_VERTEX_SIZE = size; - - (stride) ? (GL_VERTEX_STRIDE = stride / 4) : (GL_VERTEX_STRIDE = 3); - - GL_VERTEX_POINTER = (float *)pointer; - GL_VERTEX_PTR_MODE |= GL_USE_ARRAY; + (stride) ? (GL_KOS_VERTEX_STRIDE = stride / 4) : (GL_KOS_VERTEX_STRIDE = 3); + + GL_KOS_VERTEX_POINTER = (float *)pointer; + + GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_ARRAY; } /* Submit a Vertex Normal Pointer */ @@ -84,11 +113,11 @@ GLAPI void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *p return; } - (stride) ? (GL_NORMAL_STRIDE = stride / 4) : (GL_NORMAL_STRIDE = 3); + (stride) ? (GL_KOS_NORMAL_STRIDE = stride / 4) : (GL_KOS_NORMAL_STRIDE = 3); - GL_NORMAL_POINTER = (float *)pointer; + GL_KOS_NORMAL_POINTER = (float *)pointer; - GL_VERTEX_PTR_MODE |= GL_USE_NORMAL; + GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_NORMAL; } /* Submit a Texture Coordinate Pointer */ @@ -108,35 +137,44 @@ GLAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, return; } - (stride) ? (GL_TEXCOORD_STRIDE = stride / 4) : (GL_TEXCOORD_STRIDE = 2); + if(GL_KOS_CLIENT_ACTIVE_TEXTURE) { + (stride) ? (GL_KOS_TEXCOORD1_STRIDE = stride / 4) : (GL_KOS_TEXCOORD1_STRIDE = 2); + + GL_KOS_TEXCOORD1_POINTER = (float *)pointer; + + GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_TEXTURE1; + } + else { + (stride) ? (GL_KOS_TEXCOORD0_STRIDE = stride / 4) : (GL_KOS_TEXCOORD0_STRIDE = 2); - GL_TEXCOORD_POINTER = (float *)pointer; + GL_KOS_TEXCOORD0_POINTER = (float *)pointer; - GL_VERTEX_PTR_MODE |= GL_USE_TEXTURE; + GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_TEXTURE0; + } } /* Submit a Color Pointer */ GLAPI void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { if((type == GL_UNSIGNED_INT) && (size == 1)) { - GL_COLOR_COMPONENTS = 1; - GL_COLOR_POINTER = (GLvoid *)pointer; - GL_COLOR_TYPE = type; + GL_KOS_COLOR_COMPONENTS = 1; + GL_KOS_COLOR_POINTER = (GLvoid *)pointer; + GL_KOS_COLOR_TYPE = type; } else if((type == GL_UNSIGNED_BYTE) && (size == 4)) { - GL_COLOR_COMPONENTS = 4; - GL_COLOR_POINTER = (GLvoid *)pointer; - GL_COLOR_TYPE = type; + GL_KOS_COLOR_COMPONENTS = 4; + GL_KOS_COLOR_POINTER = (GLvoid *)pointer; + GL_KOS_COLOR_TYPE = type; } else if((type == GL_FLOAT) && (size == 3)) { - GL_COLOR_COMPONENTS = 3; - GL_COLOR_POINTER = (GLfloat *)pointer; - GL_COLOR_TYPE = type; + GL_KOS_COLOR_COMPONENTS = 3; + GL_KOS_COLOR_POINTER = (GLfloat *)pointer; + GL_KOS_COLOR_TYPE = type; } else if((type == GL_FLOAT) && (size == 4)) { - GL_COLOR_COMPONENTS = 4; - GL_COLOR_POINTER = (GLfloat *)pointer; - GL_COLOR_TYPE = type; + GL_KOS_COLOR_COMPONENTS = 4; + GL_KOS_COLOR_POINTER = (GLfloat *)pointer; + GL_KOS_COLOR_TYPE = type; } else { _glKosThrowError(GL_INVALID_ENUM, "glColorPointer"); @@ -144,31 +182,31 @@ GLAPI void APIENTRY glColorPointer(GLint size, GLenum type, return; } - (stride) ? (GL_COLOR_STRIDE = stride / 4) : (GL_COLOR_STRIDE = size); + (stride) ? (GL_KOS_COLOR_STRIDE = stride / 4) : (GL_KOS_COLOR_STRIDE = size); - GL_VERTEX_PTR_MODE |= GL_USE_COLOR; + GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_COLOR; } //========================================================================================// //== Vertex Pointer Internal API ==// inline void _glKosArrayBufIncrement() { - ++GL_ARRAY_BUF_PTR; + ++GL_KOS_ARRAY_BUF_PTR; } inline void _glKosArrayBufReset() { - GL_ARRAY_BUF_PTR = &GL_ARRAY_BUF[0]; + GL_KOS_ARRAY_BUF_PTR = &GL_KOS_ARRAY_BUF[0]; } inline glVertex *_glKosArrayBufAddr() { - return &GL_ARRAY_BUF[0]; + return &GL_KOS_ARRAY_BUF[0]; } inline glVertex *_glKosArrayBufPtr() { - return GL_ARRAY_BUF_PTR; + return GL_KOS_ARRAY_BUF_PTR; } static inline void _glKosArraysTransformNormals(GLfloat *normal, GLuint count) { - glVertex *v = &GL_ARRAY_BUF[0]; + glVertex *v = &GL_KOS_ARRAY_BUF[0]; GLfloat *N = normal; ...<truncated>... hooks/post-receive -- The KallistiOS port of OpenGL. |