diff --git a/graphics/tinygl/README.residualvm b/graphics/tinygl/README.residualvm index a8d975d5dc0..045d4391081 100644 --- a/graphics/tinygl/README.residualvm +++ b/graphics/tinygl/README.residualvm @@ -14,3 +14,4 @@ The changes made from the original version of TinyGL 0.4 are: * Added support for reading in RGB/BGR-textures, although the only internal format is still RGB565 * Added TGL_BGR/TGL_RGB definitions to gl.h, verifying against SDL_opengl.h that the values are ok. * Added additional functions missing, like glColor4ub. (To make the code similar with the GL-code we use) +* Added simplistic glColorMask implementation, on/off. diff --git a/graphics/tinygl/api.cpp b/graphics/tinygl/api.cpp index da1ee4d0fbd..ff8b4383213 100644 --- a/graphics/tinygl/api.cpp +++ b/graphics/tinygl/api.cpp @@ -156,6 +156,15 @@ void tglFrontFace(int mode) { TinyGL::gl_add_op(p); } +void tglColorMask(TGLboolean r, TGLboolean g, TGLboolean b, TGLboolean a) { + TinyGL::GLParam p[2]; + + p[0].op = TinyGL::OP_ColorMask; + p[1].i = (r << 24) | (g << 16) | (b << 8) | (a << 0); + + TinyGL::gl_add_op(p); +} + void tglPolygonMode(int face, int mode) { TinyGL::GLParam p[3]; diff --git a/graphics/tinygl/clip.cpp b/graphics/tinygl/clip.cpp index 7fa1f8fa211..0e581e008a7 100644 --- a/graphics/tinygl/clip.cpp +++ b/graphics/tinygl/clip.cpp @@ -387,6 +387,10 @@ void gl_draw_triangle_fill(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p } #endif + if (c->color_mask == 0) { + // FIXME: Accept more than just 0 or 1. + ZB_fillTriangleDepthOnly(c->zb, &p0->zp, &p1->zp, &p2->zp); + } if (c->shadow_mode & 1) { assert(c->zb->shadow_mask_buf); ZB_fillTriangleFlatShadowMask(c->zb, &p0->zp, &p1->zp, &p2->zp); diff --git a/graphics/tinygl/gl.h b/graphics/tinygl/gl.h index 5dc67c20bab..d68b830d301 100644 --- a/graphics/tinygl/gl.h +++ b/graphics/tinygl/gl.h @@ -790,6 +790,7 @@ void tglHint(int target, int mode); void tglGetIntegerv(int pname, int *params); void tglGetFloatv(int pname, float *v); void tglFrontFace(int mode); +void tglColorMask(TGLboolean r, TGLboolean g, TGLboolean b, TGLboolean a); void tglSetShadowMaskBuf(unsigned char *buf); void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b); diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp index 4e9a6e3ac5c..ffc9ff82317 100644 --- a/graphics/tinygl/init.cpp +++ b/graphics/tinygl/init.cpp @@ -180,6 +180,8 @@ void glInit(void *zbuffer1) { // depth test c->depth_test = 0; + + c->color_mask = (1 << 24) | (1 << 16) | (1 << 8) | (1 << 0); } void glClose() { diff --git a/graphics/tinygl/misc.cpp b/graphics/tinygl/misc.cpp index 269d77aa25b..70cd8316e45 100644 --- a/graphics/tinygl/misc.cpp +++ b/graphics/tinygl/misc.cpp @@ -145,4 +145,8 @@ void glopPolygonOffset(GLContext *c, GLParam *p) { c->offset_units = p[2].f; } +void glopColorMask(GLContext *c, TinyGL::GLParam *p) { + c->color_mask = p[1].i; +} + } // end of namespace TinyGL diff --git a/graphics/tinygl/opinfo.h b/graphics/tinygl/opinfo.h index 6b4aa7b9565..ce506088d79 100644 --- a/graphics/tinygl/opinfo.h +++ b/graphics/tinygl/opinfo.h @@ -48,6 +48,7 @@ ADD_OP(ShadeModel, 1, "%C") ADD_OP(CullFace, 1, "%C") ADD_OP(FrontFace, 1, "%C") ADD_OP(PolygonMode, 2, "%C %C") +ADD_OP(ColorMask, 1, "%08x") ADD_OP(CallList, 1, "%d") ADD_OP(Hint, 2, "%C %C") diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h index b63de2d0c4a..2cc7c3fc853 100644 --- a/graphics/tinygl/zbuffer.h +++ b/graphics/tinygl/zbuffer.h @@ -98,6 +98,8 @@ void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2); // ztriangle.c */ void ZB_setTexture(ZBuffer *zb, const Graphics::PixelBuffer &texture); +void ZB_fillTriangleDepthOnly(ZBuffer *zb, ZBufferPoint *p1, + ZBufferPoint *p2, ZBufferPoint *p3); void ZB_fillTriangleFlat(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2, ZBufferPoint *p3); void ZB_fillTriangleFlatShadowMask(ZBuffer *zb, ZBufferPoint *p1, diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index a5b4d73a767..37a30eb4c2c 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -272,6 +272,8 @@ typedef struct GLContext { // depth test int depth_test; + + int color_mask; } GLContext; extern GLContext *gl_ctx; diff --git a/graphics/tinygl/ztriangle.cpp b/graphics/tinygl/ztriangle.cpp index 25e477dae4c..93cf917ef38 100644 --- a/graphics/tinygl/ztriangle.cpp +++ b/graphics/tinygl/ztriangle.cpp @@ -6,6 +6,23 @@ namespace TinyGL { #define ZCMP(z, zpix) ((z) >= (zpix)) +void ZB_fillTriangleDepthOnly(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) { + +#define INTERP_Z + +#define DRAW_INIT() + +#define PUT_PIXEL(_a) { \ + if (ZCMP(z, pz[_a])) { \ + pz[_a] = z; \ + } \ + z += dzdx; \ +} + +#include "graphics/tinygl/ztriangle.h" +} + + void ZB_fillTriangleFlat(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) { int color;