TINYGL: Support ColorMask

Note, this is just basic support, it is either all or nothing.
Disabling select channels is not possible.
This commit is contained in:
Dries Harnie 2013-07-02 00:11:26 +02:00
parent 3196c0a0fb
commit 6bd38b1801
10 changed files with 43 additions and 0 deletions

View file

@ -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 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 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 additional functions missing, like glColor4ub. (To make the code similar with the GL-code we use)
* Added simplistic glColorMask implementation, on/off.

View file

@ -156,6 +156,15 @@ void tglFrontFace(int mode) {
TinyGL::gl_add_op(p); 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) { void tglPolygonMode(int face, int mode) {
TinyGL::GLParam p[3]; TinyGL::GLParam p[3];

View file

@ -387,6 +387,10 @@ void gl_draw_triangle_fill(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p
} }
#endif #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) { if (c->shadow_mode & 1) {
assert(c->zb->shadow_mask_buf); assert(c->zb->shadow_mask_buf);
ZB_fillTriangleFlatShadowMask(c->zb, &p0->zp, &p1->zp, &p2->zp); ZB_fillTriangleFlatShadowMask(c->zb, &p0->zp, &p1->zp, &p2->zp);

View file

@ -790,6 +790,7 @@ void tglHint(int target, int mode);
void tglGetIntegerv(int pname, int *params); void tglGetIntegerv(int pname, int *params);
void tglGetFloatv(int pname, float *v); void tglGetFloatv(int pname, float *v);
void tglFrontFace(int mode); void tglFrontFace(int mode);
void tglColorMask(TGLboolean r, TGLboolean g, TGLboolean b, TGLboolean a);
void tglSetShadowMaskBuf(unsigned char *buf); void tglSetShadowMaskBuf(unsigned char *buf);
void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b); void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b);

View file

@ -180,6 +180,8 @@ void glInit(void *zbuffer1) {
// depth test // depth test
c->depth_test = 0; c->depth_test = 0;
c->color_mask = (1 << 24) | (1 << 16) | (1 << 8) | (1 << 0);
} }
void glClose() { void glClose() {

View file

@ -145,4 +145,8 @@ void glopPolygonOffset(GLContext *c, GLParam *p) {
c->offset_units = p[2].f; c->offset_units = p[2].f;
} }
void glopColorMask(GLContext *c, TinyGL::GLParam *p) {
c->color_mask = p[1].i;
}
} // end of namespace TinyGL } // end of namespace TinyGL

View file

@ -48,6 +48,7 @@ ADD_OP(ShadeModel, 1, "%C")
ADD_OP(CullFace, 1, "%C") ADD_OP(CullFace, 1, "%C")
ADD_OP(FrontFace, 1, "%C") ADD_OP(FrontFace, 1, "%C")
ADD_OP(PolygonMode, 2, "%C %C") ADD_OP(PolygonMode, 2, "%C %C")
ADD_OP(ColorMask, 1, "%08x")
ADD_OP(CallList, 1, "%d") ADD_OP(CallList, 1, "%d")
ADD_OP(Hint, 2, "%C %C") ADD_OP(Hint, 2, "%C %C")

View file

@ -98,6 +98,8 @@ void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2);
// ztriangle.c */ // ztriangle.c */
void ZB_setTexture(ZBuffer *zb, const Graphics::PixelBuffer &texture); 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, void ZB_fillTriangleFlat(ZBuffer *zb, ZBufferPoint *p1,
ZBufferPoint *p2, ZBufferPoint *p3); ZBufferPoint *p2, ZBufferPoint *p3);
void ZB_fillTriangleFlatShadowMask(ZBuffer *zb, ZBufferPoint *p1, void ZB_fillTriangleFlatShadowMask(ZBuffer *zb, ZBufferPoint *p1,

View file

@ -272,6 +272,8 @@ typedef struct GLContext {
// depth test // depth test
int depth_test; int depth_test;
int color_mask;
} GLContext; } GLContext;
extern GLContext *gl_ctx; extern GLContext *gl_ctx;

View file

@ -6,6 +6,23 @@ namespace TinyGL {
#define ZCMP(z, zpix) ((z) >= (zpix)) #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) { void ZB_fillTriangleFlat(ZBuffer *zb, ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
int color; int color;