From b4962f645e10b55fa9f35e3be977ca7ea7fd9421 Mon Sep 17 00:00:00 2001 From: Pawel Kolodziejski Date: Fri, 4 Jul 2014 08:43:19 +0200 Subject: [PATCH] TINYGL: added tglAlphaTest stubs --- engines/grim/gfx_tinygl.cpp | 6 +++--- graphics/tinygl/Changelog | 1 + graphics/tinygl/api.cpp | 10 ++++++++++ graphics/tinygl/get.cpp | 5 ++++- graphics/tinygl/gl.h | 1 + graphics/tinygl/init.cpp | 10 +++++++++- graphics/tinygl/misc.cpp | 10 ++++++++++ graphics/tinygl/opinfo.h | 1 + graphics/tinygl/zbuffer.cpp | 10 ++++++++++ graphics/tinygl/zbuffer.h | 7 ++++++- graphics/tinygl/zgl.h | 7 ++++++- 11 files changed, 61 insertions(+), 7 deletions(-) diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index 23d7bc7f918..a54c77a89ac 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -862,10 +862,10 @@ void GfxTinyGL::drawSprite(const Sprite *sprite) { tglDisable(TGL_LIGHTING); if (sprite->_alphaTest) { - //tglEnable(TGL_ALPHA_TEST); - //tglAlphaFunc(TGL_GEQUAL, g_grim->getGameType() == GType_MONKEY4 ? 0.1f : 0.5f); + tglEnable(TGL_ALPHA_TEST); + tglAlphaFunc(TGL_GEQUAL, g_grim->getGameType() == GType_MONKEY4 ? 0.1f : 0.5f); } else { - //tglDisable(TGL_ALPHA_TEST); + tglDisable(TGL_ALPHA_TEST); } if (sprite->_writeDepth) { diff --git a/graphics/tinygl/Changelog b/graphics/tinygl/Changelog index 62a38e125fc..931f9f677e0 100644 --- a/graphics/tinygl/Changelog +++ b/graphics/tinygl/Changelog @@ -25,5 +25,6 @@ The changes made from the original version of TinyGL 0.4 are: * Heavily refactored the triangle and line drawing routines * Renamed ZBuffer into FrameBuffer and moved all the external C functions as member functions. * Added implementation of glBlendFunc and support for 8-bit alpha. +* Added implementation of glAlphaTestFunc. For more information refer to log changes in github: https://github.com/residualvm/residualvm diff --git a/graphics/tinygl/api.cpp b/graphics/tinygl/api.cpp index a9b1faa6b48..f64201f1ede 100644 --- a/graphics/tinygl/api.cpp +++ b/graphics/tinygl/api.cpp @@ -185,6 +185,16 @@ void tglBlendFunc(TGLenum sfactor, TGLenum dfactor) { TinyGL::gl_add_op(p); } +void tglAlphaFunc(TGLenum func, float ref) { + TinyGL::GLParam p[3]; + + p[0].op = TinyGL::OP_AlphaFunc; + p[1].i = func; + p[2].f = ref; + + TinyGL::gl_add_op(p); +} + void tglPolygonMode(int face, int mode) { TinyGL::GLParam p[3]; diff --git a/graphics/tinygl/get.cpp b/graphics/tinygl/get.cpp index 728510977ee..5679c95860c 100644 --- a/graphics/tinygl/get.cpp +++ b/graphics/tinygl/get.cpp @@ -31,8 +31,11 @@ void tglGetIntegerv(int pname, int *params) { case TGL_BLEND: *params = c->enableBlend; break; + case TGL_ALPHA_TEST: + *params = c->_alphaTestEnabled; + break; default: - error("glGet: option not implemented"); + error("tglGet: option not implemented"); break; } } diff --git a/graphics/tinygl/gl.h b/graphics/tinygl/gl.h index 267dc38aa12..5320cb4b3e8 100644 --- a/graphics/tinygl/gl.h +++ b/graphics/tinygl/gl.h @@ -798,6 +798,7 @@ void tglFrontFace(int mode); void tglColorMask(TGLboolean r, TGLboolean g, TGLboolean b, TGLboolean a); void tglDepthMask(int enableWrite); void tglBlendFunc(TGLenum sfactor, TGLenum dfactor); +void tglAlphaFunc(TGLenum func, float ref); 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 f4e06c0870f..1f7c08cca63 100644 --- a/graphics/tinygl/init.cpp +++ b/graphics/tinygl/init.cpp @@ -126,8 +126,13 @@ void glInit(void *zbuffer1) { c->render_mode = TGL_RENDER; c->select_buffer = NULL; c->name_stack_size = 0; + + // blending c->enableBlend = false; - + + // alpha test + c->_alphaTestEnabled = false; + // matrix c->matrix_mode = 0; @@ -146,8 +151,11 @@ void glInit(void *zbuffer1) { tglLoadIdentity(); tglMatrixMode(TGL_MODELVIEW); tglLoadIdentity(); + tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA); + tglAlphaFunc(TGL_ALWAYS, 0.f); + c->matrix_model_projection_updated = 1; // opengl 1.1 arrays diff --git a/graphics/tinygl/misc.cpp b/graphics/tinygl/misc.cpp index 6138a958cfc..1c1331d7bfb 100644 --- a/graphics/tinygl/misc.cpp +++ b/graphics/tinygl/misc.cpp @@ -61,6 +61,10 @@ void glopEnableDisable(GLContext *c, GLParam *p) { case TGL_DEPTH_TEST: c->depth_test = v; break; + case TGL_ALPHA_TEST: + c->_alphaTestEnabled = v; + c->fb->enableAlphaTest(v); + break; case TGL_BLEND: c->enableBlend = v; c->fb->enableBlending(v); @@ -111,6 +115,12 @@ void glopBlendFunc(GLContext *c, GLParam *p) { c->fb->setBlendingFactors(sfactor, dfactor); } +void glopAlphaFunc(GLContext *c, GLParam *p) { + TGLenum func = p[1].i; + float ref = p[2].i; + c->fb->setAlphaTestFunc(func, ref); +} + void glopShadeModel(GLContext *c, GLParam *p) { int code = p[1].i; c->current_shade_model = code; diff --git a/graphics/tinygl/opinfo.h b/graphics/tinygl/opinfo.h index c201538fd81..06bce72e7a2 100644 --- a/graphics/tinygl/opinfo.h +++ b/graphics/tinygl/opinfo.h @@ -52,6 +52,7 @@ ADD_OP(PolygonMode, 2, "%C %C") ADD_OP(ColorMask, 1, "%08x") ADD_OP(DepthMask, 1, "%d") ADD_OP(BlendFunc, 2, "%d %d") +ADD_OP(AlphaFunc, 2, "%d %f") ADD_OP(CallList, 1, "%d") ADD_OP(Hint, 2, "%C %C") diff --git a/graphics/tinygl/zbuffer.cpp b/graphics/tinygl/zbuffer.cpp index 4316029ee2f..d9c1c42b116 100644 --- a/graphics/tinygl/zbuffer.cpp +++ b/graphics/tinygl/zbuffer.cpp @@ -86,6 +86,7 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelBuffer &fra this->buffer.pbuf = this->pbuf.getRawBuffer(); this->buffer.zbuf = this->zbuf; _blendingEnabled = false; + _alphaTestEnabled = false; } FrameBuffer::~FrameBuffer() { @@ -171,4 +172,13 @@ void FrameBuffer::enableBlending(bool enable) { _blendingEnabled = enable; } +void FrameBuffer::setAlphaTestFunc(int func, float ref) { + _alphaTestFunc = func; + _alphaTestRefVal = (int)(ref * 255); +} + +void FrameBuffer::enableAlphaTest(bool enable) { + _alphaTestEnabled = enable; +} + } // end of namespace TinyGL diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h index 28f541123b1..a34380bea63 100644 --- a/graphics/tinygl/zbuffer.h +++ b/graphics/tinygl/zbuffer.h @@ -199,8 +199,10 @@ struct FrameBuffer { pbuf.copyBuffer(0, xsize * ysize, buf); } - void enableBlending(bool enableBlending); + void enableBlending(bool enable); void setBlendingFactors(int sfactor, int dfactor); + void enableAlphaTest(bool enable); + void setAlphaTestFunc(int func, float ref); void enableDepthWrite(bool enable) { this->_depthWrite = enable; } @@ -261,6 +263,9 @@ private: bool _blendingEnabled; int _sourceBlendingFactor; int _destinationBlendingFactor; + bool _alphaTestEnabled; + int _alphaTestFunc; + int _alphaTestRefVal; }; // memory.c diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index 90e6861587c..bffeb0b3762 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -210,7 +210,6 @@ struct GLContext { gl_draw_triangle_func draw_triangle_front, draw_triangle_back; // selection - bool enableBlend; int render_mode; unsigned int *select_buffer; int select_size; @@ -275,6 +274,12 @@ struct GLContext { // depth test int depth_test; int color_mask; + + // alpha test + bool _alphaTestEnabled; + + // blending + bool enableBlend; }; extern GLContext *gl_ctx;