mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-26 04:35:16 +00:00
TINYGL: Rearrange access gl context access from/to frame buffer class
This commit is contained in:
parent
d6aebf4eaa
commit
2368991ab6
@ -730,12 +730,12 @@ void tglDebug(int mode) {
|
||||
|
||||
void tglSetShadowMaskBuf(unsigned char *buf) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
c->fb->shadow_mask_buf = buf;
|
||||
c->shadow_mask_buf = buf;
|
||||
}
|
||||
|
||||
void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
c->fb->shadow_color_r = r << 8;
|
||||
c->fb->shadow_color_g = g << 8;
|
||||
c->fb->shadow_color_b = b << 8;
|
||||
c->shadow_color_r = r << 8;
|
||||
c->shadow_color_g = g << 8;
|
||||
c->shadow_color_b = b << 8;
|
||||
}
|
||||
|
@ -400,10 +400,10 @@ void GLContext::gl_draw_triangle_fill(GLContext *c, GLVertex *p0, GLVertex *p1,
|
||||
c->fb->fillTriangleDepthOnly(&p0->zp, &p1->zp, &p2->zp);
|
||||
}
|
||||
if (c->shadow_mode & 1) {
|
||||
assert(c->fb->shadow_mask_buf);
|
||||
assert(c->shadow_mask_buf);
|
||||
c->fb->fillTriangleFlatShadowMask(&p0->zp, &p1->zp, &p2->zp);
|
||||
} else if (c->shadow_mode & 2) {
|
||||
assert(c->fb->shadow_mask_buf);
|
||||
assert(c->shadow_mask_buf);
|
||||
c->fb->fillTriangleFlatShadow(&p0->zp, &p1->zp, &p2->zp);
|
||||
} else if (c->texture_2d_enabled && c->current_texture && c->current_texture->images[0].pixmap) {
|
||||
#ifdef TINYGL_PROFILE
|
||||
|
@ -57,10 +57,10 @@ void tglGetIntegerv(int pname, int *params) {
|
||||
*params = MAX_TEXTURE_STACK_DEPTH;
|
||||
break;
|
||||
case TGL_BLEND:
|
||||
*params = c->fb->isBlendingEnabled();
|
||||
*params = c->blending_enabled;
|
||||
break;
|
||||
case TGL_ALPHA_TEST:
|
||||
*params = c->fb->isAlphaTestEnabled();
|
||||
*params = c->alpha_test_enabled;
|
||||
break;
|
||||
default:
|
||||
error("tglGet: option not implemented");
|
||||
|
@ -95,7 +95,6 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
|
||||
initSharedState();
|
||||
|
||||
// lists
|
||||
|
||||
exec_flag = 1;
|
||||
compile_flag = 0;
|
||||
print_flag = 0;
|
||||
@ -179,10 +178,13 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
|
||||
name_stack_size = 0;
|
||||
|
||||
// blending
|
||||
fb->enableBlending(false);
|
||||
blending_enabled = false;
|
||||
|
||||
// alpha test
|
||||
fb->enableAlphaTest(false);
|
||||
alpha_test_enabled = false;
|
||||
|
||||
// depth test
|
||||
depth_test = false;
|
||||
|
||||
// matrix
|
||||
matrix_mode = 0;
|
||||
@ -230,9 +232,6 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
|
||||
specbuf_used_counter = 0;
|
||||
specbuf_num_buffers = 0;
|
||||
|
||||
// depth test
|
||||
depth_test = 0;
|
||||
|
||||
color_mask = (1 << 24) | (1 << 16) | (1 << 8) | (1 << 0);
|
||||
|
||||
const int kDrawCallMemory = 5 * 1024 * 1024;
|
||||
|
@ -87,13 +87,12 @@ void GLContext::glopEnableDisable(GLParam *p) {
|
||||
break;
|
||||
case TGL_DEPTH_TEST:
|
||||
depth_test = v;
|
||||
fb->enableDepthTest(v);
|
||||
break;
|
||||
case TGL_ALPHA_TEST:
|
||||
fb->enableAlphaTest(v);
|
||||
alpha_test_enabled = v;
|
||||
break;
|
||||
case TGL_BLEND:
|
||||
fb->enableBlending(v);
|
||||
blending_enabled = v;
|
||||
break;
|
||||
case TGL_POLYGON_OFFSET_FILL:
|
||||
if (v)
|
||||
@ -136,20 +135,17 @@ void GLContext::glopEnableDisable(GLParam *p) {
|
||||
}
|
||||
|
||||
void GLContext::glopBlendFunc(GLParam *p) {
|
||||
TGLenum sfactor = p[1].i;
|
||||
TGLenum dfactor = p[2].i;
|
||||
fb->setBlendingFactors(sfactor, dfactor);
|
||||
source_blending_factor = p[1].i;
|
||||
destination_blending_factor = p[2].i;
|
||||
}
|
||||
|
||||
void GLContext::glopAlphaFunc(GLParam *p) {
|
||||
TGLenum func = p[1].i;
|
||||
float ref = p[2].f;
|
||||
fb->setAlphaTestFunc(func, (int)(ref * 255));
|
||||
alpha_test_func = p[1].i;
|
||||
alpha_test_ref_val = (int)(p[2].f * 255);
|
||||
}
|
||||
|
||||
void GLContext::glopDepthFunc(GLParam *p) {
|
||||
TGLenum func = p[1].i;
|
||||
fb->setDepthFunc(func);
|
||||
depth_func = p[1].i;
|
||||
}
|
||||
|
||||
void GLContext::glopShadeModel(GLParam *p) {
|
||||
@ -200,8 +196,8 @@ void GLContext::glopColorMask(GLParam *p) {
|
||||
color_mask = p[1].i;
|
||||
}
|
||||
|
||||
void GLContext::glopDepthMask(TinyGL::GLParam *p) {
|
||||
fb->enableDepthWrite(p[1].i);
|
||||
void GLContext::glopDepthMask(GLParam *p) {
|
||||
depth_write = p[1].i;
|
||||
}
|
||||
|
||||
} // end of namespace TinyGL
|
||||
|
@ -314,8 +314,8 @@ namespace TinyGL {
|
||||
// This blit only supports tinting but it will fall back to simpleBlit
|
||||
// if flipping is required (or anything more complex than that, including rotationd and scaling).
|
||||
template <bool kDisableColoring, bool kDisableBlending, bool kEnableAlphaBlending>
|
||||
FORCEINLINE void TinyGL::BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, int srcWidth, int srcHeight, float aTint, float rTint, float gTint, float bTint) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
FORCEINLINE void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, int srcWidth, int srcHeight, float aTint, float rTint, float gTint, float bTint) {
|
||||
GLContext *c = gl_get_context();
|
||||
|
||||
int clampWidth, clampHeight;
|
||||
int width = srcWidth, height = srcHeight;
|
||||
@ -404,8 +404,8 @@ FORCEINLINE void TinyGL::BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int
|
||||
|
||||
// This blit function is called when flipping is needed but transformation isn't.
|
||||
template <bool kDisableBlending, bool kDisableColoring, bool kFlipVertical, bool kFlipHorizontal>
|
||||
FORCEINLINE void TinyGL::BlitImage::tglBlitSimple(int dstX, int dstY, int srcX, int srcY, int srcWidth, int srcHeight, float aTint, float rTint, float gTint, float bTint) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
FORCEINLINE void BlitImage::tglBlitSimple(int dstX, int dstY, int srcX, int srcY, int srcWidth, int srcHeight, float aTint, float rTint, float gTint, float bTint) {
|
||||
GLContext *c = gl_get_context();
|
||||
|
||||
int clampWidth, clampHeight;
|
||||
int width = srcWidth, height = srcHeight;
|
||||
@ -457,9 +457,9 @@ FORCEINLINE void TinyGL::BlitImage::tglBlitSimple(int dstX, int dstY, int srcX,
|
||||
// This function is called when scale is needed: it uses a simple nearest
|
||||
// filter to scale the blit image before copying it to the screen.
|
||||
template <bool kDisableBlending, bool kDisableColoring, bool kFlipVertical, bool kFlipHorizontal>
|
||||
FORCEINLINE void TinyGL::BlitImage::tglBlitScale(int dstX, int dstY, int width, int height, int srcX, int srcY, int srcWidth, int srcHeight,
|
||||
FORCEINLINE void BlitImage::tglBlitScale(int dstX, int dstY, int width, int height, int srcX, int srcY, int srcWidth, int srcHeight,
|
||||
float aTint, float rTint, float gTint, float bTint) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
|
||||
int clampWidth, clampHeight;
|
||||
if (clipBlitImage(c, srcX, srcY, srcWidth, srcHeight, width, height, dstX, dstY, clampWidth, clampHeight) == false)
|
||||
@ -546,9 +546,9 @@ systems.
|
||||
*/
|
||||
|
||||
template <bool kDisableBlending, bool kDisableColoring, bool kFlipVertical, bool kFlipHorizontal>
|
||||
FORCEINLINE void TinyGL::BlitImage::tglBlitRotoScale(int dstX, int dstY, int width, int height, int srcX, int srcY, int srcWidth, int srcHeight, int rotation,
|
||||
FORCEINLINE void BlitImage::tglBlitRotoScale(int dstX, int dstY, int width, int height, int srcX, int srcY, int srcWidth, int srcHeight, int rotation,
|
||||
int originX, int originY, float aTint, float rTint, float gTint, float bTint) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
|
||||
int clampWidth, clampHeight;
|
||||
if (clipBlitImage(c, srcX, srcY, srcWidth, srcHeight, width, height, dstX, dstY, clampWidth, clampHeight) == false)
|
||||
@ -710,8 +710,8 @@ void tglBlit(BlitImage *blitImage, const BlitTransform &transform) {
|
||||
GLContext *c = gl_get_context();
|
||||
bool disableColor = transform._aTint == 1.0f && transform._bTint == 1.0f && transform._gTint == 1.0f && transform._rTint == 1.0f;
|
||||
bool disableTransform = transform._destinationRectangle.width() == 0 && transform._destinationRectangle.height() == 0 && transform._rotation == 0;
|
||||
bool disableBlend = c->fb->isBlendingEnabled() == false;
|
||||
bool enableAlphaBlending = c->fb->isAlphaBlendingEnabled();
|
||||
bool disableBlend = c->blending_enabled == false;
|
||||
bool enableAlphaBlending = c->source_blending_factor == TGL_SRC_ALPHA && c->destination_blending_factor == TGL_ONE_MINUS_SRC_ALPHA;
|
||||
|
||||
if (enableAlphaBlending) {
|
||||
tglBlit<true>(blitImage, transform, disableColor, disableTransform, disableBlend);
|
||||
@ -756,7 +756,7 @@ void tglBlitSetScissorRect(const Common::Rect &rect) {
|
||||
gl_get_context()->_scissorRect = rect;
|
||||
}
|
||||
|
||||
void tglBlitResetScissorRect(void) {
|
||||
void tglBlitResetScissorRect() {
|
||||
GLContext *c = gl_get_context();
|
||||
c->_scissorRect = c->renderRect;
|
||||
}
|
||||
|
@ -175,15 +175,15 @@ namespace Internal {
|
||||
void tglCleanupImages(); // This function checks if any blit image is to be cleaned up and deletes it.
|
||||
|
||||
// Documentation for those is the same as the one before, only those function are the one that actually execute the correct code path.
|
||||
void tglBlit(TinyGL::BlitImage *blitImage, const TinyGL::BlitTransform &transform);
|
||||
void tglBlit(BlitImage *blitImage, const BlitTransform &transform);
|
||||
|
||||
// Disables blending explicitly.
|
||||
void tglBlitNoBlend(TinyGL::BlitImage *blitImage, const TinyGL::BlitTransform &transform);
|
||||
void tglBlitNoBlend(BlitImage *blitImage, const BlitTransform &transform);
|
||||
|
||||
// Disables blending, transforms and tinting.
|
||||
void tglBlitFast(TinyGL::BlitImage *blitImage, int x, int y);
|
||||
void tglBlitFast(BlitImage *blitImage, int x, int y);
|
||||
|
||||
void tglBlitZBuffer(TinyGL::BlitImage *blitImage, int x, int y);
|
||||
void tglBlitZBuffer(BlitImage *blitImage, int x, int y);
|
||||
|
||||
/**
|
||||
@brief Sets up a scissor rectangle for blit calls: every blit call is affected by this rectangle.
|
||||
|
@ -80,66 +80,23 @@ void memset_l(void *adr, int val, int count) {
|
||||
*p++ = val;
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelBuffer &frame_buffer) : _depthWrite(true), _enableScissor(false) {
|
||||
this->xsize = width;
|
||||
this->ysize = height;
|
||||
this->cmode = frame_buffer.getFormat();
|
||||
this->pixelbytes = this->cmode.bytesPerPixel;
|
||||
this->linesize = (xsize * this->pixelbytes + 3) & ~3;
|
||||
|
||||
int size = this->xsize * this->ysize * sizeof(unsigned int);
|
||||
|
||||
this->_zbuf = (unsigned int *)gl_zalloc(size);
|
||||
|
||||
this->frame_buffer_allocated = 0;
|
||||
this->pbuf = frame_buffer;
|
||||
|
||||
this->current_texture = NULL;
|
||||
this->shadow_mask_buf = NULL;
|
||||
|
||||
this->buffer.pbuf = this->pbuf.getRawBuffer();
|
||||
this->buffer.zbuf = this->_zbuf;
|
||||
_blendingEnabled = false;
|
||||
_alphaTestEnabled = false;
|
||||
_depthTestEnabled = false;
|
||||
_depthFunc = TGL_LESS;
|
||||
_offsetStates = 0;
|
||||
_offsetFactor = 0.0f;
|
||||
_offsetUnits = 0.0f;
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &format) : _depthWrite(true), _enableScissor(false) {
|
||||
FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &format) {
|
||||
this->xsize = width;
|
||||
this->ysize = height;
|
||||
this->cmode = format;
|
||||
this->pixelbytes = this->cmode.bytesPerPixel;
|
||||
this->linesize = (xsize * this->pixelbytes + 3) & ~3;
|
||||
|
||||
int size = this->xsize * this->ysize * sizeof(unsigned int);
|
||||
|
||||
this->_zbuf = (unsigned int *)gl_zalloc(size);
|
||||
|
||||
byte *pixelBuffer = new byte[this->ysize * this->linesize];
|
||||
this->pbuf.set(this->cmode, pixelBuffer);
|
||||
this->frame_buffer_allocated = 1;
|
||||
|
||||
this->current_texture = NULL;
|
||||
this->shadow_mask_buf = NULL;
|
||||
this->buffer.zbuf = this->_zbuf = (unsigned int *)gl_zalloc(this->xsize * this->ysize * sizeof(unsigned int));
|
||||
|
||||
this->pbuf.set(this->cmode, new byte[this->ysize * this->linesize]);
|
||||
this->buffer.pbuf = this->pbuf.getRawBuffer();
|
||||
this->buffer.zbuf = this->_zbuf;
|
||||
_blendingEnabled = false;
|
||||
_alphaTestEnabled = false;
|
||||
_depthTestEnabled = false;
|
||||
_depthFunc = TGL_LESS;
|
||||
_offsetStates = 0;
|
||||
_offsetFactor = 0.0f;
|
||||
_offsetUnits = 0.0f;
|
||||
|
||||
_currentTexture = nullptr;
|
||||
}
|
||||
|
||||
FrameBuffer::~FrameBuffer() {
|
||||
if (frame_buffer_allocated)
|
||||
pbuf.free();
|
||||
pbuf.free();
|
||||
gl_free(_zbuf);
|
||||
}
|
||||
|
||||
@ -329,12 +286,6 @@ void FrameBuffer::clearOffscreenBuffer(Buffer *buf) {
|
||||
buf->used = false;
|
||||
}
|
||||
|
||||
void FrameBuffer::setTexture(const Graphics::TexelBuffer *texture, unsigned int wraps, unsigned int wrapt) {
|
||||
current_texture = texture;
|
||||
wrapS = wraps;
|
||||
wrapT = wrapt;
|
||||
}
|
||||
|
||||
void getSurfaceRef(Graphics::Surface &surface) {
|
||||
GLContext *c = gl_get_context();
|
||||
assert(c->fb);
|
||||
|
@ -103,7 +103,6 @@ struct ZBufferPoint {
|
||||
};
|
||||
|
||||
struct FrameBuffer {
|
||||
FrameBuffer(int xsize, int ysize, const Graphics::PixelBuffer &frame_buffer);
|
||||
FrameBuffer(int xsize, int ysize, const Graphics::PixelFormat &format);
|
||||
~FrameBuffer();
|
||||
|
||||
@ -394,6 +393,21 @@ public:
|
||||
surface.init(xsize, ysize, linesize, pbuf.getRawBuffer(), cmode);
|
||||
}
|
||||
|
||||
void setScissorRectangle(const Common::Rect &rect) {
|
||||
_clipRectangle = rect;
|
||||
_enableScissor = true;
|
||||
}
|
||||
void resetScissorRectangle() {
|
||||
_enableScissor = false;
|
||||
}
|
||||
void setShadowMaskBuf(byte *shadowBuffer) {
|
||||
_shadowMaskBuf = shadowBuffer;
|
||||
}
|
||||
void setShadowRGB(int r, int g, int b) {
|
||||
_shadowColorR = r;
|
||||
_shadowColorG = g;
|
||||
_shadowColorB = b;
|
||||
}
|
||||
void enableBlending(bool enable) {
|
||||
_blendingEnabled = enable;
|
||||
}
|
||||
@ -433,11 +447,13 @@ public:
|
||||
}
|
||||
|
||||
void enableDepthWrite(bool enable) {
|
||||
this->_depthWrite = enable;
|
||||
_depthWrite = enable;
|
||||
}
|
||||
|
||||
bool isAlphaBlendingEnabled() const {
|
||||
return _sourceBlendingFactor == TGL_SRC_ALPHA && _destinationBlendingFactor == TGL_ONE_MINUS_SRC_ALPHA;
|
||||
void setTexture(const Graphics::TexelBuffer *texture, unsigned int wraps, unsigned int wrapt) {
|
||||
_currentTexture = texture;
|
||||
_wrapS = wraps;
|
||||
_wrapT = wrapt;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -449,10 +465,7 @@ private:
|
||||
void blitOffscreenBuffer(Buffer *buffer);
|
||||
void selectOffscreenBuffer(Buffer *buffer);
|
||||
void clearOffscreenBuffer(Buffer *buffer);
|
||||
public:
|
||||
void setTexture(const Graphics::TexelBuffer *texture, unsigned int wraps, unsigned int wrapt);
|
||||
|
||||
private:
|
||||
template <bool kInterpRGB, bool kInterpZ, bool kInterpST, bool kInterpSTZ, int kDrawLogic, bool kDepthWrite, bool enableAlphaTest, bool kEnableScissor, bool enableBlending>
|
||||
void fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2);
|
||||
|
||||
@ -486,16 +499,6 @@ private:
|
||||
void fillLineFlat(ZBufferPoint *p1, ZBufferPoint *p2);
|
||||
void fillLineInterp(ZBufferPoint *p1, ZBufferPoint *p2);
|
||||
|
||||
public:
|
||||
void setScissorRectangle(const Common::Rect &rect) {
|
||||
_clipRectangle = rect;
|
||||
_enableScissor = true;
|
||||
}
|
||||
void resetScissorRectangle() {
|
||||
_enableScissor = false;
|
||||
}
|
||||
|
||||
private:
|
||||
Common::Rect _clipRectangle;
|
||||
bool _enableScissor;
|
||||
public:
|
||||
@ -507,42 +510,13 @@ private:
|
||||
|
||||
Buffer buffer;
|
||||
|
||||
public:
|
||||
unsigned char *shadow_mask_buf;
|
||||
int shadow_color_r;
|
||||
int shadow_color_g;
|
||||
int shadow_color_b;
|
||||
private:
|
||||
int frame_buffer_allocated;
|
||||
|
||||
unsigned char *dctable;
|
||||
int *ctable;
|
||||
const Graphics::TexelBuffer *current_texture;
|
||||
public:
|
||||
int _textureSize;
|
||||
int _textureSizeMask;
|
||||
private:
|
||||
unsigned int wrapS, wrapT;
|
||||
|
||||
public:
|
||||
FORCEINLINE bool isBlendingEnabled() const { return _blendingEnabled; }
|
||||
FORCEINLINE void getBlendingFactors(int &sourceFactor, int &destinationFactor) const { sourceFactor = _sourceBlendingFactor; destinationFactor = _destinationBlendingFactor; }
|
||||
FORCEINLINE bool isAlphaTestEnabled() const { return _alphaTestEnabled; }
|
||||
private:
|
||||
FORCEINLINE bool isDepthWriteEnabled() const { return _depthWrite; }
|
||||
public:
|
||||
FORCEINLINE int getDepthFunc() const { return _depthFunc; }
|
||||
FORCEINLINE int getDepthWrite() const { return _depthWrite; }
|
||||
FORCEINLINE int getAlphaTestFunc() const { return _alphaTestFunc; }
|
||||
FORCEINLINE int getAlphaTestRefVal() const { return _alphaTestRefVal; }
|
||||
FORCEINLINE int getDepthTestEnabled() const { return _depthTestEnabled; }
|
||||
private:
|
||||
FORCEINLINE int getOffsetStates() const { return _offsetStates; }
|
||||
FORCEINLINE float getOffsetFactor() const { return _offsetFactor; }
|
||||
FORCEINLINE float getOffsetUnits() const { return _offsetUnits; }
|
||||
|
||||
private:
|
||||
|
||||
template <bool kDepthWrite>
|
||||
FORCEINLINE void putPixel(unsigned int pixelOffset, int color, int x, int y, unsigned int z);
|
||||
|
||||
@ -559,15 +533,22 @@ private:
|
||||
void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
|
||||
|
||||
unsigned int *_zbuf;
|
||||
bool _depthWrite;
|
||||
Graphics::PixelBuffer pbuf;
|
||||
|
||||
const Graphics::TexelBuffer *_currentTexture;
|
||||
unsigned int _wrapS, _wrapT;
|
||||
byte *_shadowMaskBuf;
|
||||
int _shadowColorR;
|
||||
int _shadowColorG;
|
||||
int _shadowColorB;
|
||||
bool _blendingEnabled;
|
||||
int _sourceBlendingFactor;
|
||||
int _destinationBlendingFactor;
|
||||
bool _alphaTestEnabled;
|
||||
bool _depthTestEnabled;
|
||||
int _alphaTestFunc;
|
||||
int _alphaTestRefVal;
|
||||
bool _depthTestEnabled;
|
||||
bool _depthWrite;
|
||||
int _depthFunc;
|
||||
int _offsetStates;
|
||||
float _offsetFactor;
|
||||
|
@ -42,7 +42,7 @@ void GLContext::issueDrawCall(DrawCall *drawCall) {
|
||||
|
||||
#if TGL_DIRTY_RECT_SHOW
|
||||
static void DebugDrawRectangle(Common::Rect rect, int r, int g, int b) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
|
||||
if (rect.left < 0)
|
||||
rect.left = 0;
|
||||
@ -253,7 +253,7 @@ void GLContext::presentBufferSimple() {
|
||||
}
|
||||
|
||||
void presentBuffer() {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
if (c->_enableDirtyRectangles) {
|
||||
c->presentBufferDirtyRects();
|
||||
} else {
|
||||
@ -281,8 +281,9 @@ bool DrawCall::operator==(const DrawCall &other) const {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RasterizationDrawCall::RasterizationDrawCall() : DrawCall(DrawCall_Rasterization) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
_vertexCount = c->vertex_cnt;
|
||||
_vertex = (GLVertex *) Internal::allocateFrame(_vertexCount * sizeof(GLVertex));
|
||||
_drawTriangleFront = c->draw_triangle_front;
|
||||
@ -302,7 +303,7 @@ void RasterizationDrawCall::computeDirtyRegion() {
|
||||
}
|
||||
|
||||
if (!clip_code) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
int xmax = c->fb->xsize - 1;
|
||||
int ymax = c->fb->ysize - 1;
|
||||
int left = xmax, right = 0, top = ymax, bottom = 0;
|
||||
@ -328,7 +329,7 @@ void RasterizationDrawCall::computeDirtyRegion() {
|
||||
}
|
||||
|
||||
void RasterizationDrawCall::execute(bool restoreState) const {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
|
||||
RasterizationDrawCall::RasterizationState backupState;
|
||||
if (restoreState) {
|
||||
@ -336,13 +337,13 @@ void RasterizationDrawCall::execute(bool restoreState) const {
|
||||
}
|
||||
applyState(_state);
|
||||
|
||||
TinyGL::GLVertex *prevVertex = c->vertex;
|
||||
GLVertex *prevVertex = c->vertex;
|
||||
int prevVertexCount = c->vertex_cnt;
|
||||
|
||||
c->vertex = _vertex;
|
||||
c->vertex_cnt = _vertexCount;
|
||||
c->draw_triangle_front = (TinyGL::gl_draw_triangle_func)_drawTriangleFront;
|
||||
c->draw_triangle_back = (TinyGL::gl_draw_triangle_func)_drawTriangleBack;
|
||||
c->draw_triangle_front = (gl_draw_triangle_func)_drawTriangleFront;
|
||||
c->draw_triangle_back = (gl_draw_triangle_func)_drawTriangleBack;
|
||||
|
||||
int n = c->vertex_n;
|
||||
int cnt = c->vertex_cnt;
|
||||
@ -429,13 +430,13 @@ void RasterizationDrawCall::execute(bool restoreState) const {
|
||||
|
||||
RasterizationDrawCall::RasterizationState RasterizationDrawCall::captureState() const {
|
||||
RasterizationState state;
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
state.alphaTest = c->fb->isAlphaTestEnabled();
|
||||
c->fb->getBlendingFactors(state.sfactor, state.dfactor);
|
||||
state.enableBlending = c->fb->isBlendingEnabled();
|
||||
state.alphaFunc = c->fb->getAlphaTestFunc();
|
||||
state.alphaRefValue = c->fb->getAlphaTestRefVal();
|
||||
|
||||
GLContext *c = gl_get_context();
|
||||
state.alphaTest = c->alpha_test_enabled;
|
||||
state.sfactor = c->source_blending_factor;
|
||||
state.dfactor = c->destination_blending_factor;
|
||||
state.enableBlending = c->blending_enabled;
|
||||
state.alphaFunc = c->alpha_test_func;
|
||||
state.alphaRefValue = c->alpha_test_ref_val;
|
||||
state.cullFaceEnabled = c->cull_face_enabled;
|
||||
state.beginType = c->begin_type;
|
||||
state.colorMask = c->color_mask;
|
||||
@ -452,11 +453,14 @@ RasterizationDrawCall::RasterizationState RasterizationDrawCall::captureState()
|
||||
state.texture = c->current_texture;
|
||||
state.wrapS = c->texture_wrap_s;
|
||||
state.wrapT = c->texture_wrap_t;
|
||||
state.shadowMaskBuf = c->fb->shadow_mask_buf;
|
||||
state.depthFunction = c->fb->getDepthFunc();
|
||||
state.depthWrite = c->fb->getDepthWrite();
|
||||
state.shadowMaskBuf = c->shadow_mask_buf;
|
||||
state.shadowColorR = c->shadow_color_r;
|
||||
state.shadowColorG = c->shadow_color_g;
|
||||
state.shadowColorB = c->shadow_color_b;
|
||||
state.depthFunction = c->depth_func;
|
||||
state.depthWrite = c->depth_write;
|
||||
state.lightingEnabled = c->lighting_enabled;
|
||||
state.depthTestEnabled = c->fb->getDepthTestEnabled();
|
||||
state.depthTestEnabled = c->depth_test;
|
||||
if (c->current_texture != nullptr)
|
||||
state.textureVersion = c->current_texture->versionNumber;
|
||||
|
||||
@ -467,9 +471,9 @@ RasterizationDrawCall::RasterizationState RasterizationDrawCall::captureState()
|
||||
}
|
||||
|
||||
void RasterizationDrawCall::applyState(const RasterizationDrawCall::RasterizationState &state) const {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
c->fb->setBlendingFactors(state.sfactor, state.dfactor);
|
||||
GLContext *c = gl_get_context();
|
||||
c->fb->enableBlending(state.enableBlending);
|
||||
c->fb->setBlendingFactors(state.sfactor, state.dfactor);
|
||||
c->fb->enableAlphaTest(state.alphaTest);
|
||||
c->fb->setAlphaTestFunc(state.alphaFunc, state.alphaRefValue);
|
||||
c->fb->setDepthFunc(state.depthFunction);
|
||||
@ -478,6 +482,25 @@ void RasterizationDrawCall::applyState(const RasterizationDrawCall::Rasterizatio
|
||||
c->fb->setOffsetStates(state.offsetStates);
|
||||
c->fb->setOffsetFactor(state.offsetFactor);
|
||||
c->fb->setOffsetUnits(state.offsetUnits);
|
||||
c->fb->setShadowMaskBuf(state.shadowMaskBuf);
|
||||
c->fb->setShadowRGB(state.shadowColorB, state.shadowColorG, state.shadowColorB);
|
||||
|
||||
c->blending_enabled = state.enableBlending;
|
||||
c->source_blending_factor = state.sfactor;
|
||||
c->destination_blending_factor = state.dfactor;
|
||||
c->alpha_test_enabled = state.alphaTest;
|
||||
c->alpha_test_func = state.alphaFunc;
|
||||
c->alpha_test_ref_val = state.alphaRefValue;
|
||||
c->depth_test = state.depthTest;
|
||||
c->depth_func = state.depthFunction;
|
||||
c->depth_write = state.depthWrite;
|
||||
c->offset_states = state.offsetStates;
|
||||
c->offset_factor = state.offsetFactor;
|
||||
c->offset_units = state.offsetUnits;
|
||||
c->shadow_mask_buf = state.shadowMaskBuf;
|
||||
c->shadow_color_r = state.shadowColorR;
|
||||
c->shadow_color_g = state.shadowColorG;
|
||||
c->shadow_color_b = state.shadowColorB;
|
||||
|
||||
c->lighting_enabled = state.lightingEnabled;
|
||||
c->cull_face_enabled = state.cullFaceEnabled;
|
||||
@ -485,7 +508,6 @@ void RasterizationDrawCall::applyState(const RasterizationDrawCall::Rasterizatio
|
||||
c->color_mask = state.colorMask;
|
||||
c->current_front_face = state.currentFrontFace;
|
||||
c->current_shade_model = state.currentShadeModel;
|
||||
c->depth_test = state.depthTest;
|
||||
c->polygon_mode_back = state.polygonModeBack;
|
||||
c->polygon_mode_front = state.polygonModeFront;
|
||||
c->shadow_mode = state.shadowMode;
|
||||
@ -493,14 +515,13 @@ void RasterizationDrawCall::applyState(const RasterizationDrawCall::Rasterizatio
|
||||
c->current_texture = state.texture;
|
||||
c->texture_wrap_s = state.wrapS;
|
||||
c->texture_wrap_t = state.wrapT;
|
||||
c->fb->shadow_mask_buf = state.shadowMaskBuf;
|
||||
|
||||
memcpy(c->viewport.scale._v, state.viewportScaling, sizeof(c->viewport.scale._v));
|
||||
memcpy(c->viewport.trans._v, state.viewportTranslation, sizeof(c->viewport.trans._v));
|
||||
}
|
||||
|
||||
void RasterizationDrawCall::execute(const Common::Rect &clippingRectangle, bool restoreState) const {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
TinyGL::GLContext *c = gl_get_context();
|
||||
c->fb->setScissorRectangle(clippingRectangle);
|
||||
execute(restoreState);
|
||||
c->fb->resetScissorRectangle();
|
||||
@ -521,11 +542,12 @@ bool RasterizationDrawCall::operator==(const RasterizationDrawCall &other) const
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
BlittingDrawCall::BlittingDrawCall(BlitImage *image, const BlitTransform &transform, BlittingMode blittingMode) : DrawCall(DrawCall_Blitting), _transform(transform), _mode(blittingMode), _image(image) {
|
||||
tglIncBlitImageRef(image);
|
||||
_blitState = captureState();
|
||||
_imageVersion = tglGetBlitImageVersion(image);
|
||||
if (TinyGL::gl_get_context()->_enableDirtyRectangles) {
|
||||
if (gl_get_context()->_enableDirtyRectangles) {
|
||||
computeDirtyRegion();
|
||||
}
|
||||
}
|
||||
@ -570,23 +592,32 @@ void BlittingDrawCall::execute(const Common::Rect &clippingRectangle, bool resto
|
||||
|
||||
BlittingDrawCall::BlittingState BlittingDrawCall::captureState() const {
|
||||
BlittingState state;
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
state.alphaTest = c->fb->isAlphaTestEnabled();
|
||||
c->fb->getBlendingFactors(state.sfactor, state.dfactor);
|
||||
state.enableBlending = c->fb->isBlendingEnabled();
|
||||
state.alphaFunc = c->fb->getAlphaTestFunc();
|
||||
state.alphaRefValue = c->fb->getAlphaTestRefVal();
|
||||
state.depthTestEnabled = c->fb->getDepthTestEnabled();
|
||||
TinyGL::GLContext *c = gl_get_context();
|
||||
state.enableBlending = c->blending_enabled;
|
||||
state.sfactor = c->source_blending_factor;
|
||||
state.dfactor = c->destination_blending_factor;
|
||||
state.alphaTest = c->alpha_test_enabled;
|
||||
state.alphaFunc = c->alpha_test_func;
|
||||
state.alphaRefValue = c->alpha_test_ref_val;
|
||||
state.depthTestEnabled = c->depth_test;
|
||||
return state;
|
||||
}
|
||||
|
||||
void BlittingDrawCall::applyState(const BlittingState &state) const {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
c->fb->setBlendingFactors(state.sfactor, state.dfactor);
|
||||
TinyGL::GLContext *c = gl_get_context();
|
||||
c->fb->enableBlending(state.enableBlending);
|
||||
c->fb->setBlendingFactors(state.sfactor, state.dfactor);
|
||||
c->fb->enableAlphaTest(state.alphaTest);
|
||||
c->fb->setAlphaTestFunc(state.alphaFunc, state.alphaRefValue);
|
||||
c->fb->enableDepthTest(state.depthTestEnabled);
|
||||
|
||||
c->blending_enabled = state.enableBlending;
|
||||
c->source_blending_factor = state.sfactor;
|
||||
c->destination_blending_factor = state.dfactor;
|
||||
c->alpha_test_enabled = state.alphaTest;
|
||||
c->alpha_test_func = state.alphaFunc;
|
||||
c->alpha_test_ref_val = state.alphaRefValue;
|
||||
c->depth_test = state.depthTestEnabled;
|
||||
}
|
||||
|
||||
void BlittingDrawCall::computeDirtyRegion() {
|
||||
@ -615,7 +646,7 @@ void BlittingDrawCall::computeDirtyRegion() {
|
||||
_transform._destinationRectangle.left + blitWidth + 1,
|
||||
_transform._destinationRectangle.top + blitHeight + 1
|
||||
);
|
||||
_dirtyRegion.clip(TinyGL::gl_get_context()->renderRect);
|
||||
_dirtyRegion.clip(gl_get_context()->renderRect);
|
||||
}
|
||||
}
|
||||
|
||||
@ -627,21 +658,22 @@ bool BlittingDrawCall::operator==(const BlittingDrawCall &other) const {
|
||||
_imageVersion == tglGetBlitImageVersion(other._image);
|
||||
}
|
||||
|
||||
|
||||
ClearBufferDrawCall::ClearBufferDrawCall(bool clearZBuffer, int zValue, bool clearColorBuffer, int rValue, int gValue, int bValue)
|
||||
: _clearZBuffer(clearZBuffer), _clearColorBuffer(clearColorBuffer), _zValue(zValue), _rValue(rValue), _gValue(gValue), _bValue(bValue), DrawCall(DrawCall_Clear) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
TinyGL::GLContext *c = gl_get_context();
|
||||
if (c->_enableDirtyRectangles) {
|
||||
_dirtyRegion = c->renderRect;
|
||||
}
|
||||
}
|
||||
|
||||
void ClearBufferDrawCall::execute(bool restoreState) const {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
TinyGL::GLContext *c = gl_get_context();
|
||||
c->fb->clear(_clearZBuffer, _zValue, _clearColorBuffer, _rValue, _gValue, _bValue);
|
||||
}
|
||||
|
||||
void ClearBufferDrawCall::execute(const Common::Rect &clippingRectangle, bool restoreState) const {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
TinyGL::GLContext *c = gl_get_context();
|
||||
Common::Rect clearRect = clippingRectangle.findIntersectingRect(getDirtyRegion());
|
||||
c->fb->clearRegion(clearRect.left, clearRect.top, clearRect.width(), clearRect.height(), _clearZBuffer, _zValue, _clearColorBuffer, _rValue, _gValue, _bValue);
|
||||
}
|
||||
@ -679,20 +711,20 @@ bool RasterizationDrawCall::RasterizationState::operator==(const RasterizationSt
|
||||
alphaTest == other.alphaTest &&
|
||||
alphaFunc == other.alphaFunc &&
|
||||
alphaRefValue == other.alphaRefValue &&
|
||||
depthTestEnabled == other.depthTestEnabled &&
|
||||
texture == other.texture &&
|
||||
textureVersion == texture->versionNumber &&
|
||||
shadowMaskBuf == other.shadowMaskBuf &&
|
||||
viewportTranslation[0] == other.viewportTranslation[0] &&
|
||||
viewportTranslation[1] == other.viewportTranslation[1] &&
|
||||
viewportTranslation[2] == other.viewportTranslation[2] &&
|
||||
viewportScaling[0] == other.viewportScaling[0] &&
|
||||
viewportScaling[1] == other.viewportScaling[1] &&
|
||||
viewportScaling[2] == other.viewportScaling[2] &&
|
||||
depthTestEnabled == other.depthTestEnabled &&
|
||||
textureVersion == texture->versionNumber;
|
||||
viewportScaling[2] == other.viewportScaling[2];
|
||||
}
|
||||
|
||||
void *Internal::allocateFrame(int size) {
|
||||
TinyGL::GLContext *c = TinyGL::gl_get_context();
|
||||
GLContext *c = gl_get_context();
|
||||
return c->_drawCallAllocator[c->_currentAllocatorIndex].allocate(size);
|
||||
}
|
||||
|
||||
|
@ -102,9 +102,9 @@ public:
|
||||
void operator delete(void *p) { }
|
||||
private:
|
||||
void computeDirtyRegion();
|
||||
typedef void (*gl_draw_triangle_func_ptr)(TinyGL::GLContext *c, TinyGL::GLVertex *p0, TinyGL::GLVertex *p1, TinyGL::GLVertex *p2);
|
||||
typedef void (*gl_draw_triangle_func_ptr)(GLContext *c, TinyGL::GLVertex *p0, TinyGL::GLVertex *p1, TinyGL::GLVertex *p2);
|
||||
int _vertexCount;
|
||||
TinyGL::GLVertex *_vertex;
|
||||
GLVertex *_vertex;
|
||||
gl_draw_triangle_func_ptr _drawTriangleFront, _drawTriangleBack;
|
||||
|
||||
struct RasterizationState {
|
||||
@ -116,6 +116,9 @@ private:
|
||||
int depthFunction;
|
||||
int depthWrite;
|
||||
int shadowMode;
|
||||
int shadowColorR;
|
||||
int shadowColorG;
|
||||
int shadowColorB;
|
||||
int texture2DEnabled;
|
||||
int currentShadeModel;
|
||||
int polygonModeBack;
|
||||
|
@ -265,6 +265,22 @@ struct GLContext {
|
||||
FrameBuffer *fb;
|
||||
Common::Rect renderRect;
|
||||
|
||||
// blending
|
||||
bool blending_enabled;
|
||||
int source_blending_factor;
|
||||
int destination_blending_factor;
|
||||
|
||||
// alpha blending
|
||||
bool alpha_test_enabled;
|
||||
int alpha_test_func;
|
||||
int alpha_test_ref_val;
|
||||
|
||||
// shadow
|
||||
unsigned char *shadow_mask_buf;
|
||||
int shadow_color_r;
|
||||
int shadow_color_g;
|
||||
int shadow_color_b;
|
||||
|
||||
// Internal texture size
|
||||
int _textureSize;
|
||||
|
||||
@ -392,7 +408,10 @@ struct GLContext {
|
||||
int (*gl_resize_viewport)(int *xsize, int *ysize);
|
||||
|
||||
// depth test
|
||||
int depth_test;
|
||||
bool depth_test;
|
||||
int depth_func;
|
||||
bool depth_write;
|
||||
|
||||
int color_mask;
|
||||
|
||||
Common::Rect _scissorRect;
|
||||
|
@ -244,13 +244,13 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
|
||||
|
||||
switch (kDrawLogic) {
|
||||
case DRAW_SHADOW_MASK:
|
||||
pm1 = shadow_mask_buf + p0->y * xsize;
|
||||
pm1 = _shadowMaskBuf + p0->y * xsize;
|
||||
break;
|
||||
case DRAW_SHADOW:
|
||||
pm1 = shadow_mask_buf + p0->y * xsize;
|
||||
r1 = shadow_color_r;
|
||||
g1 = shadow_color_g;
|
||||
b1 = shadow_color_b;
|
||||
pm1 = _shadowMaskBuf + p0->y * xsize;
|
||||
r1 = _shadowColorR;
|
||||
g1 = _shadowColorG;
|
||||
b1 = _shadowColorB;
|
||||
break;
|
||||
case DRAW_DEPTH_ONLY:
|
||||
break;
|
||||
@ -267,7 +267,7 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
|
||||
}
|
||||
|
||||
if ((kInterpST || kInterpSTZ) && (kDrawLogic == DRAW_FLAT || kDrawLogic == DRAW_SMOOTH)) {
|
||||
texture = current_texture;
|
||||
texture = _currentTexture;
|
||||
fdzdx = (float)dzdx;
|
||||
fndzdx = NB_INTERP * fdzdx;
|
||||
ndszdx = NB_INTERP * dszdx;
|
||||
@ -543,7 +543,7 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
|
||||
zinv = (float)(1.0 / fz);
|
||||
}
|
||||
for (int _a = 0; _a < NB_INTERP; _a++) {
|
||||
putPixelTextureMappingPerspective<kDepthWrite, kInterpRGB, kDrawLogic == DRAW_SMOOTH, kAlphaTestEnabled, kEnableScissor, kBlendingEnabled>(this, buf, texture, wrapS, wrapT,
|
||||
putPixelTextureMappingPerspective<kDepthWrite, kInterpRGB, kDrawLogic == DRAW_SMOOTH, kAlphaTestEnabled, kEnableScissor, kBlendingEnabled>(this, buf, texture, _wrapS, _wrapT,
|
||||
pz, _a, x, y, z, t, s, r, g, b, a, dzdx, dsdx, dtdx, drdx, dgdx, dbdx, dadx);
|
||||
}
|
||||
pz += NB_INTERP;
|
||||
@ -565,7 +565,7 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
|
||||
}
|
||||
|
||||
while (n >= 0) {
|
||||
putPixelTextureMappingPerspective<kDepthWrite, kInterpRGB, kDrawLogic == DRAW_SMOOTH, kAlphaTestEnabled, kEnableScissor, kBlendingEnabled>(this, buf, texture, wrapS, wrapT,
|
||||
putPixelTextureMappingPerspective<kDepthWrite, kInterpRGB, kDrawLogic == DRAW_SMOOTH, kAlphaTestEnabled, kEnableScissor, kBlendingEnabled>(this, buf, texture, _wrapS, _wrapT,
|
||||
pz, 0, x, y, z, t, s, r, g, b, a, dzdx, dsdx, dtdx, drdx, dgdx, dbdx, dadx);
|
||||
pz += 1;
|
||||
buf += 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user