TINYGL: Added a way to disable or enable dirty rectangles at runtime.

This commit is contained in:
Stefano Musumeci 2014-08-15 23:53:57 +02:00
parent e1aea3a1f3
commit 974f47fa42
5 changed files with 67 additions and 30 deletions

View File

@ -698,3 +698,8 @@ void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b) {
c->fb->shadow_color_g = g << 8;
c->fb->shadow_color_b = b << 8;
}
void tglEnableDirtyRects(bool enable) {
TinyGL::GLContext *c = TinyGL::gl_get_context();
c->_enableDirtyRectangles = enable;
}

View File

@ -839,6 +839,8 @@ void tglTexCoordPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoi
// opengl 1.2 polygon offset
void tglPolygonOffset(TGLfloat factor, TGLfloat units);
void tglEnableDirtyRects(bool enable);
void tglDebug(int mode);
namespace TinyGL {

View File

@ -224,6 +224,7 @@ void glInit(void *zbuffer1, int textureSize) {
c->_currentAllocatorIndex = 0;
c->_drawCallAllocator[0].initialize(kDrawCallMemory);
c->_drawCallAllocator[1].initialize(kDrawCallMemory);
c->_enableDirtyRectangles = false;
Graphics::Internal::tglBlitSetScissorRect(0, 0, c->fb->xsize, c->fb->ysize);
}

View File

@ -74,9 +74,28 @@ struct DirtyRectangle {
}
};
void tglPresentBuffer() {
TinyGL::GLContext *c = TinyGL::gl_get_context();
void tglDisposeResources(TinyGL::GLContext *c) {
// Dispose textures and resources.
bool allDisposed = true;
do {
allDisposed = true;
TinyGL::GLTexture *t = c->shared_state.texture_hash_table[0];
while (t) {
if (t->disposed) {
TinyGL::free_texture(c, t->handle);
allDisposed = false;
break;
}
t = t->next;
}
} while (allDisposed == false);
Graphics::Internal::tglCleanupImages();
}
void tglPresentBufferDirtyRects(TinyGL::GLContext *c) {
typedef Common::List<Graphics::DrawCall *>::const_iterator DrawCallIterator;
typedef Common::List<TinyGL::DirtyRectangle>::iterator RectangleIterator;
@ -88,19 +107,19 @@ void tglPresentBuffer() {
// Compare draw calls.
if (c->_drawCallsQueue.size() > 0) {
for (DrawCallIterator itPrevFrame = c->_previousFrameDrawCallsQueue.begin();
itPrevFrame != endPrevFrame;
++itPrevFrame, ++itFrame) {
const Graphics::DrawCall &currentCall = **itFrame;
const Graphics::DrawCall &previousCall = **itPrevFrame;
itPrevFrame != endPrevFrame;
++itPrevFrame, ++itFrame) {
const Graphics::DrawCall &currentCall = **itFrame;
const Graphics::DrawCall &previousCall = **itPrevFrame;
if (previousCall != currentCall) {
while (itPrevFrame != endPrevFrame) {
Graphics::DrawCall *dirtyDrawCall = *itPrevFrame;
rectangles.push_back(DirtyRectangle(dirtyDrawCall->getDirtyRegion(), 255, 255, 255));
++itPrevFrame;
if (previousCall != currentCall) {
while (itPrevFrame != endPrevFrame) {
Graphics::DrawCall *dirtyDrawCall = *itPrevFrame;
rectangles.push_back(DirtyRectangle(dirtyDrawCall->getDirtyRegion(), 255, 255, 255));
++itPrevFrame;
}
break;
}
break;
}
}
}
@ -189,23 +208,7 @@ void tglPresentBuffer() {
c->fb->enableAlphaTest(alphaTestEnabled);
#endif
// Dispose textures and resources.
bool allDisposed = true;
do {
allDisposed = true;
TinyGL::GLTexture *t = c->shared_state.texture_hash_table[0];
while (t) {
if (t->disposed) {
TinyGL::free_texture(c, t->handle);
allDisposed = false;
break;
}
t = t->next;
}
} while (allDisposed == false);
Graphics::Internal::tglCleanupImages();
tglDisposeResources(c);
c->_currentAllocatorIndex++;
if (c->_currentAllocatorIndex == 2) {
@ -215,6 +218,30 @@ void tglPresentBuffer() {
}
}
void tglPresentBufferSimple(TinyGL::GLContext *c) {
typedef Common::List<Graphics::DrawCall *>::const_iterator DrawCallIterator;
for (DrawCallIterator it = c->_drawCallsQueue.begin(); it != c->_drawCallsQueue.end(); ++it) {
(*it)->execute(true);
delete *it;
}
c->_drawCallsQueue.clear();
tglDisposeResources(c);
c->_drawCallAllocator[c->_currentAllocatorIndex].reset();
}
void tglPresentBuffer() {
TinyGL::GLContext *c = TinyGL::gl_get_context();
if (c->_enableDirtyRectangles) {
tglPresentBufferDirtyRects(c);
} else {
tglPresentBufferSimple(c);
}
}
} // end of namespace TinyGL
namespace Graphics {

View File

@ -378,6 +378,8 @@ struct GLContext {
Common::Rect _scissorRect;
bool _enableDirtyRectangles;
// blit test
Common::List<Graphics::BlitImage *> _blitImages;