TINYGL: added tglAlphaTest stubs

This commit is contained in:
Pawel Kolodziejski 2014-07-04 08:43:19 +02:00
parent 2bf63a5f52
commit b4962f645e
11 changed files with 61 additions and 7 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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];

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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;