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:
parent
3196c0a0fb
commit
6bd38b1801
10 changed files with 43 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -272,6 +272,8 @@ typedef struct GLContext {
|
|||
|
||||
// depth test
|
||||
int depth_test;
|
||||
|
||||
int color_mask;
|
||||
} GLContext;
|
||||
|
||||
extern GLContext *gl_ctx;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue