put tinygl internals into namespace, left only api

This commit is contained in:
Pawel Kolodziejski 2009-05-25 13:19:29 +00:00
parent 7ad12a0856
commit 49b578ec6a
28 changed files with 367 additions and 285 deletions

View file

@ -142,7 +142,7 @@ GfxTinyGL::GfxTinyGL() {
GfxTinyGL::~GfxTinyGL() {
delete[] _storedDisplay;
if (_zb) {
tglClose();
TinyGL::glClose();
ZB_close(_zb);
}
}
@ -157,8 +157,8 @@ byte *GfxTinyGL::setupScreen(int screenW, int screenH, bool fullscreen, bool acc
g_system->setWindowCaption("Residual: Software 3D Renderer");
_zb = ZB_open(screenW, screenH, ZB_MODE_5R6G5B, buffer);
tglInit(_zb);
_zb = TinyGL::ZB_open(screenW, screenH, ZB_MODE_5R6G5B, buffer);
TinyGL::glInit(_zb);
_storedDisplay = new byte[640 * 480 * 2];
memset(_storedDisplay, 0, 640 * 480 * 2);

View file

@ -104,7 +104,7 @@ public:
protected:
private:
ZBuffer *_zb;
TinyGL::ZBuffer *_zb;
byte *_screen;
byte *_smushBitmap;
int _smushWidth;

View file

@ -4,15 +4,15 @@
// glVertex
void tglVertex4f(float x, float y, float z, float w) {
TGLParam p[5];
TinyGL::GLParam p[5];
p[0].op = OP_Vertex;
p[0].op = TinyGL::OP_Vertex;
p[1].f = x;
p[2].f = y;
p[3].f = z;
p[4].f = w;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglVertex2f(float x, float y) {
@ -30,14 +30,14 @@ void tglVertex3fv(float *v) {
// glNormal
void tglNormal3f(float x, float y, float z) {
TGLParam p[4];
TinyGL::GLParam p[4];
p[0].op = OP_Normal;
p[0].op = TinyGL::OP_Normal;
p[1].f = x;
p[2].f = y;
p[3].f = z;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglNormal3fv(float *v) {
@ -47,9 +47,9 @@ void tglNormal3fv(float *v) {
// glColor
void tglColor4f(float r, float g, float b, float a) {
TGLParam p[8];
TinyGL::GLParam p[8];
p[0].op = OP_Color;
p[0].op = TinyGL::OP_Color;
p[1].f = r;
p[2].f = g;
p[3].f = b;
@ -62,9 +62,9 @@ void tglColor4f(float r, float g, float b, float a) {
}
void tglColor4fv(float *v) {
TGLParam p[8];
TinyGL::GLParam p[8];
p[0].op = OP_Color;
p[0].op = TinyGL::OP_Color;
p[1].f=v[0];
p[2].f=v[1];
p[3].f=v[2];
@ -73,7 +73,7 @@ void tglColor4fv(float *v) {
p[5].ui = (unsigned int)(v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) + ZB_POINT_RED_MIN);
p[6].ui = (unsigned int)(v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) + ZB_POINT_GREEN_MIN);
p[7].ui = (unsigned int)(v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN);
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglColor3f(float x, float y, float z) {
@ -87,15 +87,15 @@ void glColor3fv(float *v) {
// TexCoord
void tglTexCoord4f(float s, float t, float r, float q) {
TGLParam p[5];
TinyGL::GLParam p[5];
p[0].op = OP_TexCoord;
p[0].op = TinyGL::OP_TexCoord;
p[1].f = s;
p[2].f = t;
p[3].f = r;
p[4].f = q;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglTexCoord2f(float s, float t) {
@ -107,9 +107,9 @@ void tglTexCoord2fv(float *v) {
}
void tglEdgeFlag(int flag) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_EdgeFlag;
p[0].op = TinyGL::OP_EdgeFlag;
p[1].i = flag;
gl_add_op(p);
@ -118,179 +118,179 @@ void tglEdgeFlag(int flag) {
// misc
void tglShadeModel(int mode) {
TGLParam p[2];
TinyGL::GLParam p[2];
assert(mode == TGL_FLAT || mode == TGL_SMOOTH);
p[0].op = OP_ShadeModel;
p[0].op = TinyGL::OP_ShadeModel;
p[1].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglCullFace(int mode) {
TGLParam p[2];
TinyGL::GLParam p[2];
assert(mode == TGL_BACK || mode == TGL_FRONT || mode == TGL_FRONT_AND_BACK);
p[0].op = OP_CullFace;
p[0].op = TinyGL::OP_CullFace;
p[1].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglFrontFace(int mode) {
TGLParam p[2];
TinyGL::GLParam p[2];
assert(mode == TGL_CCW || mode == TGL_CW);
mode = (mode != TGL_CCW);
p[0].op = OP_FrontFace;
p[0].op = TinyGL::OP_FrontFace;
p[1].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglPolygonMode(int face, int mode) {
TGLParam p[3];
TinyGL::GLParam p[3];
assert(face == TGL_BACK || face == TGL_FRONT || face == TGL_FRONT_AND_BACK);
assert(mode == TGL_POINT || mode == TGL_LINE || mode == TGL_FILL);
p[0].op = OP_PolygonMode;
p[0].op = TinyGL::OP_PolygonMode;
p[1].i = face;
p[2].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// glEnable, glDisable
void tglEnable(int cap) {
TGLParam p[3];
TinyGL::GLParam p[3];
p[0].op = OP_EnableDisable;
p[0].op = TinyGL::OP_EnableDisable;
p[1].i = cap;
p[2].i = 1;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglDisable(int cap) {
TGLParam p[3];
TinyGL::GLParam p[3];
p[0].op = OP_EnableDisable;
p[0].op = TinyGL::OP_EnableDisable;
p[1].i = cap;
p[2].i = 0;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// glBegin, glEnd
void tglBegin(int mode) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_Begin;
p[0].op = TinyGL::OP_Begin;
p[1].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglEnd() {
TGLParam p[1];
TinyGL::GLParam p[1];
p[0].op = OP_End;
p[0].op = TinyGL::OP_End;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// matrix
void tglMatrixMode(int mode) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_MatrixMode;
p[0].op = TinyGL::OP_MatrixMode;
p[1].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLoadMatrixf(const float *m) {
TGLParam p[17];
TinyGL::GLParam p[17];
int i;
p[0].op = OP_LoadMatrix;
p[0].op = TinyGL::OP_LoadMatrix;
for (i = 0; i < 16; i++)
p[i + 1].f = m[i];
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLoadIdentity() {
TGLParam p[1];
TinyGL::GLParam p[1];
p[0].op = OP_LoadIdentity;
p[0].op = TinyGL::OP_LoadIdentity;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglMultMatrixf(const float *m) {
TGLParam p[17];
TinyGL::GLParam p[17];
int i;
p[0].op = OP_MultMatrix;
p[0].op = TinyGL::OP_MultMatrix;
for (i = 0; i < 16; i++)
p[i + 1].f = m[i];
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglPushMatrix() {
TGLParam p[1];
TinyGL::GLParam p[1];
p[0].op = OP_PushMatrix;
p[0].op = TinyGL::OP_PushMatrix;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglPopMatrix() {
TGLParam p[1];
TinyGL::GLParam p[1];
p[0].op = OP_PopMatrix;
p[0].op = TinyGL::OP_PopMatrix;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglRotatef(float angle, float x, float y, float z) {
TGLParam p[5];
TinyGL::GLParam p[5];
p[0].op = OP_Rotate;
p[0].op = TinyGL::OP_Rotate;
p[1].f = angle;
p[2].f = x;
p[3].f = y;
p[4].f = z;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglTranslatef(float x, float y, float z) {
TGLParam p[4];
TinyGL::GLParam p[4];
p[0].op = OP_Translate;
p[0].op = TinyGL::OP_Translate;
p[1].f = x;
p[2].f = y;
p[3].f = z;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglScalef(float x, float y, float z) {
TGLParam p[4];
TinyGL::GLParam p[4];
p[0].op = OP_Scale;
p[0].op = TinyGL::OP_Scale;
p[1].f = x;
p[2].f = y;
p[3].f = z;
@ -299,9 +299,9 @@ void tglScalef(float x, float y, float z) {
}
void tglViewport(int x, int y, int width, int height) {
TGLParam p[5];
TinyGL::GLParam p[5];
p[0].op = OP_Viewport;
p[0].op = TinyGL::OP_Viewport;
p[1].i = x;
p[2].i = y;
p[3].i = width;
@ -311,9 +311,9 @@ void tglViewport(int x, int y, int width, int height) {
}
void tglFrustum(double left, double right, double bottom, double top, double nearv, double farv) {
TGLParam p[7];
TinyGL::GLParam p[7];
p[0].op = OP_Frustum;
p[0].op = TinyGL::OP_Frustum;
p[1].f = (float)left;
p[2].f = (float)right;
p[3].f = (float)bottom;
@ -321,18 +321,18 @@ void tglFrustum(double left, double right, double bottom, double top, double nea
p[5].f = (float)nearv;
p[6].f = (float)farv;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// lightening
void tglMaterialfv(int mode, int type, float *v) {
TGLParam p[7];
TinyGL::GLParam p[7];
int i, n;
assert(mode == TGL_FRONT || mode == TGL_BACK || mode==TGL_FRONT_AND_BACK);
p[0].op = OP_Material;
p[0].op = TinyGL::OP_Material;
p[1].i = mode;
p[2].i = type;
n = 4;
@ -343,102 +343,102 @@ void tglMaterialfv(int mode, int type, float *v) {
for (i = n; i < 4; i++)
p[3 + i].f = 0;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglMaterialf(int mode, int type, float v) {
TGLParam p[7];
TinyGL::GLParam p[7];
int i;
p[0].op = OP_Material;
p[0].op = TinyGL::OP_Material;
p[1].i = mode;
p[2].i = type;
p[3].f = v;
for (i = 0; i < 3; i++)
p[4 + i].f = 0;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglColorMaterial(int mode, int type) {
TGLParam p[3];
TinyGL::GLParam p[3];
p[0].op = OP_ColorMaterial;
p[0].op = TinyGL::OP_ColorMaterial;
p[1].i = mode;
p[2].i = type;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLightfv(int light, int type, float *v) {
TGLParam p[7];
TinyGL::GLParam p[7];
int i;
p[0].op=OP_Light;
p[1].i=light;
p[2].i=type;
p[0].op = TinyGL::OP_Light;
p[1].i = light;
p[2].i = type;
// TODO: 3 composants
for (i = 0; i < 4; i++)
p[3 + i].f = v[i];
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLightf(int light, int type, float v) {
TGLParam p[7];
TinyGL::GLParam p[7];
int i;
p[0].op = OP_Light;
p[0].op = TinyGL::OP_Light;
p[1].i = light;
p[2].i = type;
p[3].f = v;
for (i = 0; i < 3; i++)
p[4 + i].f = 0;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLightModeli(int pname, int param) {
TGLParam p[6];
TinyGL::GLParam p[6];
int i;
p[0].op = OP_LightModel;
p[0].op = TinyGL::OP_LightModel;
p[1].i = pname;
p[2].f = (float)param;
for (i = 0; i < 4; i++)
p[3 + i].f = 0;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLightModelfv(int pname, float *param) {
TGLParam p[6];
TinyGL::GLParam p[6];
int i;
p[0].op = OP_LightModel;
p[0].op = TinyGL::OP_LightModel;
p[1].i = pname;
for (i = 0; i < 4; i++)
p[2 + i].f = param[i];
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// clear
void tglClear(int mask) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_Clear;
p[0].op = TinyGL::OP_Clear;
p[1].i = mask;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglClearColor(float r, float g, float b, float a) {
TGLParam p[5];
TinyGL::GLParam p[5];
p[0].op = OP_ClearColor;
p[0].op = TinyGL::OP_ClearColor;
p[1].f = r;
p[2].f = g;
p[3].f = b;
@ -448,12 +448,12 @@ void tglClearColor(float r, float g, float b, float a) {
}
void tglClearDepth(double depth) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_ClearDepth;
p[0].op = TinyGL::OP_ClearDepth;
p[1].f = (float)depth;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// textures
@ -461,9 +461,9 @@ void tglClearDepth(double depth) {
void tglTexImage2D( int target, int level, int components,
int width, int height, int border,
int format, int type, void *pixels) {
TGLParam p[10];
TinyGL::GLParam p[10];
p[0].op = OP_TexImage2D;
p[0].op = TinyGL::OP_TexImage2D;
p[1].i = target;
p[2].i = level;
p[3].i = components;
@ -474,23 +474,23 @@ void tglTexImage2D( int target, int level, int components,
p[8].i = type;
p[9].p = pixels;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglBindTexture(int target, int texture) {
TGLParam p[3];
TinyGL::GLParam p[3];
p[0].op = OP_BindTexture;
p[0].op = TinyGL::OP_BindTexture;
p[1].i = target;
p[2].i = texture;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglTexEnvi(int target, int pname, int param) {
TGLParam p[8];
TinyGL::GLParam p[8];
p[0].op = OP_TexEnv;
p[0].op = TinyGL::OP_TexEnv;
p[1].i = target;
p[2].i = pname;
p[3].i = param;
@ -503,9 +503,9 @@ void tglTexEnvi(int target, int pname, int param) {
}
void tglTexParameteri(int target, int pname, int param) {
TGLParam p[8];
TinyGL::GLParam p[8];
p[0].op = OP_TexParameter;
p[0].op = TinyGL::OP_TexParameter;
p[1].i = target;
p[2].i = pname;
p[3].i = param;
@ -514,71 +514,72 @@ void tglTexParameteri(int target, int pname, int param) {
p[6].f = 0;
p[7].f = 0;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglPixelStorei(int pname, int param) {
TGLParam p[3];
TinyGL::GLParam p[3];
p[0].op = OP_PixelStore;
p[0].op = TinyGL::OP_PixelStore;
p[1].i = pname;
p[2].i = param;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// selection
void tglInitNames() {
TGLParam p[1];
TinyGL::GLParam p[1];
p[0].op = OP_InitNames;
p[0].op = TinyGL::OP_InitNames;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglPushName(unsigned int name) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_PushName;
p[0].op = TinyGL::OP_PushName;
p[1].i = name;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglPopName() {
TGLParam p[1];
TinyGL::GLParam p[1];
p[0].op = OP_PopName;
p[0].op = TinyGL::OP_PopName;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglLoadName(unsigned int name) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_LoadName;
p[0].op = TinyGL::OP_LoadName;
p[1].i = name;
gl_add_op(p);
}
void tglPolygonOffset(TGLfloat factor, TGLfloat units) {
TGLParam p[3];
p[0].op = OP_PolygonOffset;
p[1].f = factor;
p[2].f = units;
void tglPolygonOffset(TGLfloat factor, TGLfloat units) {
TinyGL::GLParam p[3];
p[0].op = TinyGL::OP_PolygonOffset;
p[1].f = factor;
p[2].f = units;
}
// Special Functions
void tglCallList(unsigned int list) {
TGLParam p[2];
TinyGL::GLParam p[2];
p[0].op = OP_CallList;
p[0].op = TinyGL::OP_CallList;
p[1].i = list;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
void tglFlush() {
@ -586,29 +587,29 @@ void tglFlush() {
}
void tglHint(int target, int mode) {
TGLParam p[3];
TinyGL::GLParam p[3];
p[0].op = OP_Hint;
p[0].op = TinyGL::OP_Hint;
p[1].i = target;
p[2].i = mode;
gl_add_op(p);
TinyGL::gl_add_op(p);
}
// Non standard functions
void tglDebug(int mode) {
GLContext *c = gl_get_context();
TinyGL::GLContext *c = TinyGL::gl_get_context();
c->print_flag = mode;
}
void tglSetShadowMaskBuf(unsigned char *buf) {
GLContext *c = gl_get_context();
TinyGL::GLContext *c = TinyGL::gl_get_context();
c->zb->shadow_mask_buf = buf;
}
void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b) {
GLContext *c = gl_get_context();
TinyGL::GLContext *c = TinyGL::gl_get_context();
c->zb->shadow_color_r = r << 8;
c->zb->shadow_color_g = g << 8;
c->zb->shadow_color_b = b << 8;

View file

@ -6,13 +6,15 @@
#define NORMAL_ARRAY 0x0004
#define TEXCOORD_ARRAY 0x0008
void glopArrayElement(GLContext *c, TGLParam *param) {
namespace TinyGL {
void glopArrayElement(GLContext *c, GLParam *param) {
int i;
int states = c->client_states;
int idx = param[1].i;
if (states & COLOR_ARRAY) {
TGLParam p[5];
GLParam p[5];
int size = c->color_array_size;
i = idx * (size + c->color_array_stride);
p[1].f = c->color_array[i];
@ -37,7 +39,7 @@ void glopArrayElement(GLContext *c, TGLParam *param) {
c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f;
}
if (states & VERTEX_ARRAY) {
TGLParam p[5];
GLParam p[5];
int size = c->vertex_array_size;
i = idx * (size + c->vertex_array_stride);
p[1].f = c->vertex_array[i];
@ -49,18 +51,18 @@ void glopArrayElement(GLContext *c, TGLParam *param) {
}
void glArrayElement(TGLint i) {
TGLParam p[2];
GLParam p[2];
p[0].op = OP_ArrayElement;
p[1].i = i;
gl_add_op(p);
}
void glopEnableClientState(GLContext *c, TGLParam *p) {
void glopEnableClientState(GLContext *c, GLParam *p) {
c->client_states |= p[1].i;
}
void glEnableClientState(TGLenum array) {
TGLParam p[2];
GLParam p[2];
p[0].op = OP_EnableClientState;
switch(array) {
@ -83,12 +85,12 @@ void glEnableClientState(TGLenum array) {
gl_add_op(p);
}
void glopDisableClientState(GLContext *c, TGLParam *p) {
void glopDisableClientState(GLContext *c, GLParam *p) {
c->client_states &= p[1].i;
}
void glDisableClientState(TGLenum array) {
TGLParam p[2];
GLParam p[2];
p[0].op = OP_DisableClientState;
switch(array) {
@ -111,14 +113,14 @@ void glDisableClientState(TGLenum array) {
gl_add_op(p);
}
void glopVertexPointer(GLContext *c, TGLParam *p) {
void glopVertexPointer(GLContext *c, GLParam *p) {
c->vertex_array_size = p[1].i;
c->vertex_array_stride = p[2].i;
c->vertex_array = (float *)p[3].p;
}
void glVertexPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TGLParam p[4];
GLParam p[4];
assert(type == TGL_FLOAT);
p[0].op = OP_VertexPointer;
p[1].i = size;
@ -127,14 +129,14 @@ void glVertexPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid
gl_add_op(p);
}
void glopColorPointer(GLContext *c, TGLParam *p) {
void glopColorPointer(GLContext *c, GLParam *p) {
c->color_array_size = p[1].i;
c->color_array_stride = p[2].i;
c->color_array = (float *)p[3].p;
}
void glColorPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TGLParam p[4];
GLParam p[4];
assert(type == TGL_FLOAT);
p[0].op = OP_ColorPointer;
p[1].i = size;
@ -143,30 +145,32 @@ void glColorPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *
gl_add_op(p);
}
void glopNormalPointer(GLContext *c, TGLParam *p) {
void glopNormalPointer(GLContext *c, GLParam *p) {
c->normal_array_stride = p[1].i;
c->normal_array = (float *)p[2].p;
}
void glNormalPointer(TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TGLParam p[3];
GLParam p[3];
assert(type == TGL_FLOAT);
p[0].op = OP_NormalPointer;
p[1].i = stride;
p[2].p = (void *)pointer;
}
void glopTexCoordPointer(GLContext *c, TGLParam *p) {
void glopTexCoordPointer(GLContext *c, GLParam *p) {
c->texcoord_array_size = p[1].i;
c->texcoord_array_stride = p[2].i;
c->texcoord_array = (float *)p[3].p;
}
void glTexCoordPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TGLParam p[4];
GLParam p[4];
assert(type == TGL_FLOAT);
p[0].op = OP_TexCoordPointer;
p[1].i = size;
p[2].i = stride;
p[3].p = (void *)pointer;
}
} // end of namespace TinyGL

View file

@ -1,18 +1,20 @@
#include "graphics/tinygl/zgl.h"
void glopClearColor(GLContext *c, TGLParam *p) {
namespace TinyGL {
void glopClearColor(GLContext *c, GLParam *p) {
c->clear_color.v[0] = p[1].f;
c->clear_color.v[1] = p[2].f;
c->clear_color.v[2] = p[3].f;
c->clear_color.v[3] = p[4].f;
}
void glopClearDepth(GLContext *c, TGLParam *p) {
void glopClearDepth(GLContext *c, GLParam *p) {
c->clear_depth = p[1].f;
}
void glopClear(GLContext *c,TGLParam *p) {
void glopClear(GLContext *c,GLParam *p) {
int mask = p[1].i;
int z = 0;
int r = (int)(c->clear_color.v[0] * 65535);
@ -22,3 +24,5 @@ void glopClear(GLContext *c,TGLParam *p) {
// TODO : correct value of Z
ZB_clear(c->zb,mask & TGL_DEPTH_BUFFER_BIT, z, mask & TGL_COLOR_BUFFER_BIT, r, g, b);
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
// fill triangle profile
// #define TINYGL_PROFILE
@ -433,3 +435,5 @@ void gl_draw_triangle_point(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *
if (p2->edge_flag)
ZB_plot(c->zb, &p2->zp);
}
} // end of namespace TinyGL

View file

@ -2,7 +2,7 @@
#include "graphics/tinygl/zgl.h"
void tglGetIntegerv(int pname,int *params) {
GLContext *c=gl_get_context();
TinyGL::GLContext *c = TinyGL::gl_get_context();
switch (pname) {
case TGL_VIEWPORT:
@ -35,7 +35,7 @@ void tglGetIntegerv(int pname,int *params) {
void tglGetFloatv(int pname, float *v) {
int i;
int mnr = 0; // just a trick to return the correct matrix
GLContext *c = gl_get_context();
TinyGL::GLContext *c = TinyGL::gl_get_context();
switch (pname) {
case TGL_TEXTURE_MATRIX:
mnr++;

View file

@ -802,7 +802,4 @@ void tglPolygonOffset(TGLfloat factor, TGLfloat units);
void tglDebug(int mode);
void tglInit(void *zbuffer);
void tglClose();
#endif

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
// image conversion
void gl_convertRGB_to_5R6G5B8A(unsigned short *pixmap, unsigned char *rgba, int xsize, int ysize) {
@ -140,3 +142,5 @@ void gl_resizeImageNoInterpolate(unsigned char *dest, int xsize_dest, int ysize_
y1 += y1inc;
}
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
GLContext *gl_ctx;
void initSharedState(GLContext *c) {
@ -23,7 +25,7 @@ void endSharedState(GLContext *c) {
gl_free(s->texture_hash_table);
}
void tglInit(void *zbuffer1) {
void glInit(void *zbuffer1) {
ZBuffer *zbuffer = (ZBuffer *)zbuffer1;
GLContext *c;
GLViewport *v;
@ -179,8 +181,10 @@ void tglInit(void *zbuffer1) {
c->depth_test = 0;
}
void tglClose() {
void glClose() {
GLContext *c = gl_get_context();
endSharedState(c);
gl_free(c);
}
} // end of namespace TinyGL

View file

@ -1,7 +1,9 @@
#include "graphics/tinygl/zgl.h"
void glopMaterial(GLContext *c, TGLParam *p) {
namespace TinyGL {
void glopMaterial(GLContext *c, GLParam *p) {
int mode = p[1].i;
int type = p[2].i;
float *v = &p[3].f;
@ -50,7 +52,7 @@ void glopMaterial(GLContext *c, TGLParam *p) {
}
}
void glopColorMaterial(GLContext *c, TGLParam *p) {
void glopColorMaterial(GLContext *c, GLParam *p) {
int mode = p[1].i;
int type = p[2].i;
@ -58,7 +60,7 @@ void glopColorMaterial(GLContext *c, TGLParam *p) {
c->current_color_material_type = type;
}
void glopLight(GLContext *c, TGLParam *p) {
void glopLight(GLContext *c, GLParam *p) {
int light=p[1].i;
int type=p[2].i;
V4 v;
@ -131,7 +133,7 @@ void glopLight(GLContext *c, TGLParam *p) {
}
}
void glopLightModel(GLContext *c, TGLParam *p) {
void glopLightModel(GLContext *c, GLParam *p) {
int pname = p[1].i;
float *v = &p[2].f;
int i;
@ -309,3 +311,5 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) {
v->color.v[2] = clampf(B, 0, 1);
v->color.v[3] = A;
}
} // end of namespace TinyGL

View file

@ -1,13 +1,15 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
static const char *op_table_str[] = {
#define ADD_OP(a, b, c) "gl" #a " " #c,
#include "graphics/tinygl/opinfo.h"
};
static void (*op_table_func[])(GLContext *, TGLParam *) = {
static void (*op_table_func[])(GLContext *, GLParam *) = {
#define ADD_OP(a, b, c) glop ## a ,
#include "graphics/tinygl/opinfo.h"
@ -28,7 +30,7 @@ static GLList *find_list(GLContext *c, unsigned int list) {
}
static void delete_list(GLContext *c, int list) {
TGLParamBuffer *pb, *pb1;
GLParamBuffer *pb, *pb1;
GLList *l;
l = find_list(c, list);
@ -48,10 +50,10 @@ static void delete_list(GLContext *c, int list) {
static GLList *alloc_list(GLContext *c, int list) {
GLList *l;
TGLParamBuffer *ob;
GLParamBuffer *ob;
l = (GLList *)gl_zalloc(sizeof(GLList));
ob = (TGLParamBuffer *)gl_zalloc(sizeof(TGLParamBuffer));
ob = (GLParamBuffer *)gl_zalloc(sizeof(GLParamBuffer));
ob->next = NULL;
l->first_op_buffer = ob;
@ -62,7 +64,7 @@ static GLList *alloc_list(GLContext *c, int list) {
return l;
}
void gl_print_op(FILE *f, TGLParam *p) {
void gl_print_op(FILE *f, GLParam *p) {
int op;
const char *s;
@ -90,9 +92,9 @@ void gl_print_op(FILE *f, TGLParam *p) {
}
void gl_compile_op(GLContext *c, TGLParam *p) {
void gl_compile_op(GLContext *c, GLParam *p) {
int op, op_size;
TGLParamBuffer *ob, *ob1;
GLParamBuffer *ob, *ob1;
int index,i;
op = p[0].op;
@ -103,7 +105,7 @@ void gl_compile_op(GLContext *c, TGLParam *p) {
// we should be able to add a NextBuffer opcode
if ((index + op_size) > (OP_BUFFER_MAX_SIZE - 2)) {
ob1 = (TGLParamBuffer *)gl_zalloc(sizeof(TGLParamBuffer));
ob1 = (GLParamBuffer *)gl_zalloc(sizeof(GLParamBuffer));
ob1->next = NULL;
ob->next = ob1;
@ -122,7 +124,7 @@ void gl_compile_op(GLContext *c, TGLParam *p) {
c->current_op_buffer_index = index;
}
void gl_add_op(TGLParam *p) {
void gl_add_op(GLParam *p) {
GLContext *c=gl_get_context();
int op;
@ -139,16 +141,16 @@ void gl_add_op(TGLParam *p) {
}
// this opcode is never called directly
void glopEndList(GLContext *, TGLParam *) {
void glopEndList(GLContext *, GLParam *) {
assert(0);
}
// this opcode is never called directly
void glopNextBuffer(GLContext *, TGLParam *) {
void glopNextBuffer(GLContext *, GLParam *) {
assert(0);
}
void glopCallList(GLContext *c, TGLParam *p) {
void glopCallList(GLContext *c, GLParam *p) {
GLList *l;
int list, op;
@ -163,7 +165,7 @@ void glopCallList(GLContext *c, TGLParam *p) {
if (op == OP_EndList)
break;
if (op == OP_NextBuffer) {
p =(TGLParam *)p[1].p;
p =(GLParam *)p[1].p;
} else {
op_table_func[op](c,p);
p += op_table_size[op];
@ -192,7 +194,7 @@ void glNewList(unsigned int list, int mode) {
void glEndList() {
GLContext *c = gl_get_context();
TGLParam p[1];
GLParam p[1];
assert(c->compile_flag == 1);
@ -234,3 +236,5 @@ unsigned int glGenLists(int range) {
}
return 0;
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
void gl_print_matrix(const float *m) {
int i;
@ -13,7 +15,7 @@ static inline void gl_matrix_update(GLContext *c) {
c->matrix_model_projection_updated = (c->matrix_mode <= 1);
}
void glopMatrixMode(GLContext *c, TGLParam *p) {
void glopMatrixMode(GLContext *c, GLParam *p) {
int mode = p[1].i;
switch (mode) {
case TGL_MODELVIEW:
@ -30,11 +32,11 @@ void glopMatrixMode(GLContext *c, TGLParam *p) {
}
}
void glopLoadMatrix(GLContext *c, TGLParam *p) {
void glopLoadMatrix(GLContext *c, GLParam *p) {
M4 *m;
int i;
TGLParam *q;
GLParam *q;
m = c->matrix_stack_ptr[c->matrix_mode];
q = p + 1;
@ -50,17 +52,17 @@ void glopLoadMatrix(GLContext *c, TGLParam *p) {
gl_matrix_update(c);
}
void glopLoadIdentity(GLContext *c, TGLParam *) {
void glopLoadIdentity(GLContext *c, GLParam *) {
gl_M4_Id(c->matrix_stack_ptr[c->matrix_mode]);
gl_matrix_update(c);
}
void glopMultMatrix(GLContext *c, TGLParam *p) {
void glopMultMatrix(GLContext *c, GLParam *p) {
M4 m;
int i;
TGLParam *q;
GLParam *q;
q = p + 1;
for (i = 0; i < 4; i++) {
@ -77,7 +79,7 @@ void glopMultMatrix(GLContext *c, TGLParam *p) {
}
void glopPushMatrix(GLContext *c, TGLParam *) {
void glopPushMatrix(GLContext *c, GLParam *) {
int n = c->matrix_mode;
M4 *m;
@ -90,7 +92,7 @@ void glopPushMatrix(GLContext *c, TGLParam *) {
gl_matrix_update(c);
}
void glopPopMatrix(GLContext *c, TGLParam *) {
void glopPopMatrix(GLContext *c, GLParam *) {
int n=c->matrix_mode;
assert(c->matrix_stack_ptr[n] > c->matrix_stack[n]);
@ -98,7 +100,7 @@ void glopPopMatrix(GLContext *c, TGLParam *) {
gl_matrix_update(c);
}
void glopRotate(GLContext *c, TGLParam *p) {
void glopRotate(GLContext *c, GLParam *p) {
M4 m;
float u[3];
float angle;
@ -167,7 +169,7 @@ void glopRotate(GLContext *c, TGLParam *p) {
gl_matrix_update(c);
}
void glopScale(GLContext *c, TGLParam *p) {
void glopScale(GLContext *c, GLParam *p) {
float *m;
float x = p[1].f, y = p[2].f, z = p[3].f;
@ -180,7 +182,7 @@ void glopScale(GLContext *c, TGLParam *p) {
gl_matrix_update(c);
}
void glopTranslate(GLContext *c, TGLParam *p) {
void glopTranslate(GLContext *c, GLParam *p) {
float *m;
float x = p[1].f, y = p[2].f, z = p[3].f;
@ -194,7 +196,7 @@ void glopTranslate(GLContext *c, TGLParam *p) {
gl_matrix_update(c);
}
void glopFrustum(GLContext *c, TGLParam *p) {
void glopFrustum(GLContext *c, GLParam *p) {
float *r;
M4 m;
float left = p[1].f;
@ -222,3 +224,5 @@ void glopFrustum(GLContext *c, TGLParam *p) {
gl_matrix_update(c);
}
} // end of namespace TinyGL

View file

@ -3,6 +3,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
// modify these functions so that they suit your needs
void gl_free(void *p) {
@ -16,3 +18,5 @@ void *gl_malloc(int size) {
void *gl_zalloc(int size) {
return calloc(1, size);
}
} // end of namespace TinyGL

View file

@ -1,7 +1,9 @@
#include "graphics/tinygl/zgl.h"
void glopViewport(GLContext *c, TGLParam *p) {
namespace TinyGL {
void glopViewport(GLContext *c, GLParam *p) {
int xsize, ysize, xmin, ymin, xsize_req, ysize_req;
xmin = p[1].i;
@ -36,7 +38,7 @@ void glopViewport(GLContext *c, TGLParam *p) {
}
}
void glopEnableDisable(GLContext *c, TGLParam *p) {
void glopEnableDisable(GLContext *c, GLParam *p) {
int code = p[1].i;
int v = p[2].i;
@ -99,22 +101,22 @@ void glopEnableDisable(GLContext *c, TGLParam *p) {
}
}
void glopShadeModel(GLContext *c, TGLParam *p) {
void glopShadeModel(GLContext *c, GLParam *p) {
int code = p[1].i;
c->current_shade_model = code;
}
void glopCullFace(GLContext *c, TGLParam *p) {
void glopCullFace(GLContext *c, GLParam *p) {
int code = p[1].i;
c->current_cull_face = code;
}
void glopFrontFace(GLContext *c, TGLParam *p) {
void glopFrontFace(GLContext *c, GLParam *p) {
int code = p[1].i;
c->current_front_face = code;
}
void glopPolygonMode(GLContext *c, TGLParam *p) {
void glopPolygonMode(GLContext *c, GLParam *p) {
int face = p[1].i;
int mode = p[2].i;
@ -134,11 +136,13 @@ void glopPolygonMode(GLContext *c, TGLParam *p) {
}
}
void glopHint(GLContext *, TGLParam *) {
void glopHint(GLContext *, GLParam *) {
// do nothing
}
void glopPolygonOffset(GLContext *c, TGLParam *p) {
void glopPolygonOffset(GLContext *c, GLParam *p) {
c->offset_factor = p[1].f;
c->offset_units = p[2].f;
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
int glRenderMode(int mode) {
GLContext *c = gl_get_context();
int result = 0;
@ -48,14 +50,14 @@ void glSelectBuffer(int size, unsigned int *buf) {
c->select_size = size;
}
void glopInitNames(GLContext *c, TGLParam *) {
void glopInitNames(GLContext *c, GLParam *) {
if (c->render_mode == TGL_SELECT) {
c->name_stack_size = 0;
c->select_hit = NULL;
}
}
void glopPushName(GLContext *c, TGLParam *p) {
void glopPushName(GLContext *c, GLParam *p) {
if (c->render_mode == TGL_SELECT) {
assert(c->name_stack_size < MAX_NAME_STACK_DEPTH);
c->name_stack[c->name_stack_size++] = p[1].i;
@ -63,7 +65,7 @@ void glopPushName(GLContext *c, TGLParam *p) {
}
}
void glopPopName(GLContext *c, TGLParam *) {
void glopPopName(GLContext *c, GLParam *) {
if (c->render_mode == TGL_SELECT) {
assert(c->name_stack_size > 0);
c->name_stack_size--;
@ -71,7 +73,7 @@ void glopPopName(GLContext *c, TGLParam *) {
}
}
void glopLoadName(GLContext *c, TGLParam *p) {
void glopLoadName(GLContext *c, GLParam *p) {
if (c->render_mode == TGL_SELECT) {
assert(c->name_stack_size > 0);
c->name_stack[c->name_stack_size - 1] = p[1].i;
@ -107,3 +109,5 @@ void gl_add_select(GLContext *c, unsigned int zmin, unsigned int zmax) {
}
}
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
static void calc_buf(GLSpecBuf *buf, const float shininess) {
int i;
float val, inc;
@ -44,3 +46,5 @@ GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float s
calc_buf(oldest, shininess);
return oldest;
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#ifndef GRAPHICS_TINYGL_SPECBUF_H
#define GRAPHICS_TINYGL_SPECBUF_H
namespace TinyGL {
// Max # of specular light pow buffers
#define MAX_SPECULAR_BUFFERS 8
// # of entries in specular buffer
@ -19,4 +21,6 @@ GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i,
const float shininess);
void specbuf_cleanup(GLContext *c); // free all memory used
#endif // _tgl_specbuf_h_
} // end of namespace TinyGL
#endif

View file

@ -3,6 +3,8 @@
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
static GLTexture *find_texture(GLContext *c, int h) {
GLTexture *t;
@ -63,42 +65,7 @@ void glInitTextures(GLContext *c) {
c->current_texture = find_texture(c, 0);
}
void tglGenTextures(int n, unsigned int *textures) {
GLContext *c = gl_get_context();
int max, i;
GLTexture *t;
max = 0;
for (i = 0; i < TEXTURE_HASH_TABLE_SIZE; i++) {
t = c->shared_state.texture_hash_table[i];
while (t) {
if (t->handle > max)
max = t->handle;
t = t->next;
}
}
for (i = 0; i < n; i++) {
textures[i] = max + i + 1;
}
}
void tglDeleteTextures(int n, const unsigned int *textures) {
GLContext *c = gl_get_context();
int i;
GLTexture *t;
for (i = 0; i < n; i++) {
t = find_texture(c, textures[i]);
if (t) {
if (t == c->current_texture) {
tglBindTexture(TGL_TEXTURE_2D, 0);
}
free_texture(c, textures[i]);
}
}
}
void glopBindTexture(GLContext *c, TGLParam *p) {
void glopBindTexture(GLContext *c, GLParam *p) {
int target = p[1].i;
int texture = p[2].i;
GLTexture *t;
@ -112,7 +79,7 @@ void glopBindTexture(GLContext *c, TGLParam *p) {
c->current_texture = t;
}
void glopTexImage2D(GLContext *c, TGLParam *p) {
void glopTexImage2D(GLContext *c, GLParam *p) {
int target = p[1].i;
int level = p[2].i;
int components = p[3].i;
@ -158,7 +125,7 @@ void glopTexImage2D(GLContext *c, TGLParam *p) {
}
// TODO: not all tests are done
void glopTexEnv(GLContext *, TGLParam *p) {
void glopTexEnv(GLContext *, GLParam *p) {
int target = p[1].i;
int pname = p[2].i;
int param = p[3].i;
@ -176,7 +143,7 @@ error:
}
// TODO: not all tests are done
void glopTexParameter(GLContext *, TGLParam *p) {
void glopTexParameter(GLContext *, GLParam *p) {
int target = p[1].i;
int pname = p[2].i;
int param = p[3].i;
@ -197,7 +164,7 @@ error:
}
}
void glopPixelStore(GLContext *, TGLParam *p) {
void glopPixelStore(GLContext *, GLParam *p) {
int pname = p[1].i;
int param = p[2].i;
@ -205,3 +172,40 @@ void glopPixelStore(GLContext *, TGLParam *p) {
error("glPixelStore: unsupported option");
}
}
} // end of namespace TinyGL
void tglGenTextures(int n, unsigned int *textures) {
TinyGL::GLContext *c = TinyGL::gl_get_context();
int max, i;
TinyGL::GLTexture *t;
max = 0;
for (i = 0; i < TEXTURE_HASH_TABLE_SIZE; i++) {
t = c->shared_state.texture_hash_table[i];
while (t) {
if (t->handle > max)
max = t->handle;
t = t->next;
}
}
for (i = 0; i < n; i++) {
textures[i] = max + i + 1;
}
}
void tglDeleteTextures(int n, const unsigned int *textures) {
TinyGL::GLContext *c = TinyGL::gl_get_context();
int i;
TinyGL::GLTexture *t;
for (i = 0; i < n; i++) {
t = TinyGL::find_texture(c, textures[i]);
if (t) {
if (t == c->current_texture) {
tglBindTexture(TGL_TEXTURE_2D, 0);
}
TinyGL::free_texture(c, textures[i]);
}
}
}

View file

@ -1,9 +1,9 @@
#include "graphics/tinygl/zgl.h"
#include <string.h>
namespace TinyGL {
void glopNormal(GLContext *c, TGLParam *p) {
void glopNormal(GLContext *c, GLParam *p) {
V3 v;
v.X = p[1].f;
@ -16,18 +16,18 @@ void glopNormal(GLContext *c, TGLParam *p) {
c->current_normal.W = 0;
}
void glopTexCoord(GLContext *c, TGLParam *p) {
void glopTexCoord(GLContext *c, GLParam *p) {
c->current_tex_coord.X = p[1].f;
c->current_tex_coord.Y = p[2].f;
c->current_tex_coord.Z = p[3].f;
c->current_tex_coord.W = p[4].f;
}
void glopEdgeFlag(GLContext *c, TGLParam *p) {
void glopEdgeFlag(GLContext *c, GLParam *p) {
c->current_edge_flag = p[1].i;
}
void glopColor(GLContext *c, TGLParam *p){
void glopColor(GLContext *c, GLParam *p){
c->current_color.X = p[1].f;
c->current_color.Y = p[2].f;
c->current_color.Z = p[3].f;
@ -37,7 +37,7 @@ void glopColor(GLContext *c, TGLParam *p){
c->longcurrent_color[2] = p[7].ui;
if (c->color_material_enabled) {
TGLParam q[7];
GLParam q[7];
q[0].op = OP_Material;
q[1].i = c->current_color_material_mode;
q[2].i = c->current_color_material_type;
@ -64,7 +64,7 @@ void gl_eval_viewport(GLContext *c) {
v->scale.Z = (float)(-((zsize - 0.5) / 2.0));
}
void glopBegin(GLContext *c, TGLParam *p) {
void glopBegin(GLContext *c, GLParam *p) {
int type;
M4 tmp;
@ -188,7 +188,7 @@ static inline void gl_vertex_transform(GLContext *c, GLVertex *v) {
v->clip_code = gl_clipcode(v->pc.X, v->pc.Y, v->pc.Z, v->pc.W);
}
void glopVertex(GLContext *c, TGLParam *p) {
void glopVertex(GLContext *c, GLParam *p) {
GLVertex *v;
int n, i, cnt;
@ -325,7 +325,7 @@ void glopVertex(GLContext *c, TGLParam *p) {
c->vertex_n = n;
}
void glopEnd(GLContext *c, TGLParam *) {
void glopEnd(GLContext *c, GLParam *) {
assert(c->in_begin == 1);
if (c->begin_type == TGL_LINE_LOOP) {
@ -341,3 +341,5 @@ void glopEnd(GLContext *c, TGLParam *) {
}
c->in_begin = 0;
}
} // end of namespace TinyGL

View file

@ -1,13 +1,12 @@
// Z buffer: 16,32 bits Z / 16 bits color
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "common/sys.h"
#include "graphics/tinygl/zbuffer.h"
namespace TinyGL {
ZBuffer *ZB_open(int xsize, int ysize, int mode, void *frame_buffer) {
ZBuffer *zb;
int size;
@ -193,3 +192,5 @@ void ZB_clear(ZBuffer *zb, int clear_z, int z, int clear_color, int r, int g, in
}
}
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#ifndef GRAPHICS_TINYGL_ZBUFFER_H_
#define GRAPHICS_TINYGL_ZBUFFER_H_
namespace TinyGL {
// Z buffer
#define ZB_Z_BITS 16
@ -93,4 +95,6 @@ void gl_free(void *p);
void *gl_malloc(int size);
void *gl_zalloc(int size);
#endif // _tgl_zbuffer_h_
} // end of namespace TinyGL
#endif

View file

@ -7,6 +7,8 @@
#include "graphics/tinygl/zbuffer.h"
#include "graphics/tinygl/zmath.h"
namespace TinyGL {
enum {
#define ADD_OP(a,b,c) OP_ ## a ,
@ -94,15 +96,15 @@ typedef union {
int i;
unsigned int ui;
void *p;
} TGLParam;
} GLParam;
typedef struct TGLParamBuffer {
TGLParam ops[OP_BUFFER_MAX_SIZE];
struct TGLParamBuffer *next;
} TGLParamBuffer;
typedef struct GLParamBuffer {
GLParam ops[OP_BUFFER_MAX_SIZE];
struct GLParamBuffer *next;
} GLParamBuffer;
typedef struct GLList {
TGLParamBuffer *first_op_buffer;
GLParamBuffer *first_op_buffer;
// TODO: extensions for an hash table or a better allocating scheme
} GLList;
@ -175,7 +177,7 @@ typedef struct GLContext {
GLSharedState shared_state;
// current list
TGLParamBuffer *current_op_buffer;
GLParamBuffer *current_op_buffer;
int current_op_buffer_index;
int exec_flag, compile_flag, print_flag;
@ -273,7 +275,7 @@ typedef struct GLContext {
extern GLContext *gl_ctx;
void gl_add_op(TGLParam *p);
void gl_add_op(GLParam *p);
// clip.c
void gl_transform_to_viewport(GLContext *c, GLVertex *v);
@ -310,6 +312,9 @@ GLContext *gl_get_context();
// specular buffer "api"
GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess);
void glInit(void *zbuffer);
void glClose();
#ifdef DEBUG
#define dprintf fprintf
#else
@ -322,7 +327,7 @@ GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float s
// glopXXX functions
#define ADD_OP(a,b,c) void glop ## a (GLContext *, TGLParam *);
#define ADD_OP(a,b,c) void glop ## a (GLContext *, GLParam *);
#include "opinfo.h"
// this clip epsilon is needed to avoid some rounding errors after
@ -337,4 +342,6 @@ static inline int gl_clipcode(float x, float y, float z, float w1) {
return (x < -w) | ((x > w) << 1) | ((y < -w) << 2) | ((y > w) << 3) | ((z < -w) << 4) | ((z > w) << 5);
}
#endif // _tgl_zgl_h_
} // end of namespace TinyGL
#endif

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zbuffer.h"
namespace TinyGL {
#define ZCMP(z,zpix) ((z) >= (zpix))
void ZB_plot(ZBuffer * zb, ZBufferPoint * p) {
@ -68,3 +70,5 @@ void ZB_line(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
ZB_line_interp(zb, p1, p2);
}
}
} // end of namespace TinyGL

View file

@ -1,12 +1,10 @@
// Some simple mathematical functions. Don't look for some logic in
// the function names :-)
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "common/sys.h"
#include "graphics/tinygl/zmath.h"
namespace TinyGL {
void gl_M4_Id(M4 *a) {
int i, j;
for (i = 0; i < 4; i++) {
@ -270,3 +268,5 @@ V4 gl_V4_New(float x, float y, float z, float w) {
a.W = w;
return a;
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#ifndef GRAPHICS_TINYGL_ZMATH_H
#define GRAPHICS_TINYGL_ZMATH_H
namespace TinyGL {
// Matrix & Vertex
typedef struct {
@ -50,4 +52,6 @@ V4 gl_V4_New(float x, float y, float z, float w);
int gl_Matrix_Inv(float *r, float *m, int n);
} // end of namespace TinyGL
#endif

View file

@ -1,8 +1,8 @@
#include <stdlib.h>
#include "graphics/tinygl/zbuffer.h"
namespace TinyGL {
#define ZCMP(z, zpix) ((z) >= (zpix))
void ZB_fillTriangleFlat(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
@ -488,3 +488,5 @@ void ZB_fillTriangleMappingPerspective(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoi
}
}
}
} // end of namespace TinyGL

View file

@ -1,6 +1,8 @@
#include "graphics/tinygl/zbuffer.h"
namespace TinyGL {
#define ZCMP(z, zpix) ((z) >= (zpix))
void ZB_fillTriangleFlatShadowMask(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
@ -362,3 +364,5 @@ void ZB_fillTriangleFlatShadow(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoint *p1,
}
}
}
} // end of namespace TinyGL