Fixed Canvas:clear

This commit is contained in:
Alex Szpakowski
2013-05-30 04:31:32 -03:00
parent 6a76e082e4
commit 6c6cb270de
4 changed files with 40 additions and 18 deletions
+6 -5
View File
@@ -553,13 +553,14 @@ void Canvas::clear(const Color &c)
previous = current->fbo;
strategy->bindFBO(fbo);
glPushAttrib(GL_COLOR_BUFFER_BIT);
}
// Make sure only this canvas is cleared when multi-canvas rendering is set
// Make sure only this canvas is cleared when multi-canvas rendering is set.
if (attachedCanvases.size() > 0)
strategy->setAttachments();
// Don't use the state-shadowed gl.setClearColor because we want to save the
// previous clear color.
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -567,10 +568,10 @@ void Canvas::clear(const Color &c)
strategy->setAttachments(attachedCanvases);
if (current != this)
{
glPopAttrib();
strategy->bindFBO(previous);
}
// Restore the previous clear color.
gl.setClearColor(gl.getClearColor());
}
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
+2 -11
View File
@@ -534,21 +534,12 @@ Color Graphics::getColor() const
void Graphics::setBackgroundColor(const Color &c)
{
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
gl.setClearColor(c);
}
Color Graphics::getBackgroundColor() const
{
float c[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE, c);
Color t;
t.r = (unsigned char)(255.0f*c[0]);
t.g = (unsigned char)(255.0f*c[1]);
t.b = (unsigned char)(255.0f*c[2]);
t.a = (unsigned char)(255.0f*c[3]);
return t;
return gl.getClearColor();
}
void Graphics::setFont(Font *font)
+19 -1
View File
@@ -57,6 +57,13 @@ void OpenGL::initContext()
state.color.b = glcolor[2] * 255;
state.color.a = glcolor[3] * 255;
// Same with the current clear color.
glGetFloatv(GL_COLOR_CLEAR_VALUE, glcolor);
state.clearColor.r = glcolor[0] * 255;
state.clearColor.g = glcolor[1] * 255;
state.clearColor.b = glcolor[2] * 255;
state.clearColor.a = glcolor[3] * 255;
// Initialize multiple texture unit support for shaders, if available.
state.textureUnits.clear();
if (Shader::isSupported())
@@ -164,11 +171,22 @@ void OpenGL::setColor(const Color &c)
state.color = c;
}
Color OpenGL::getColor()
Color OpenGL::getColor() const
{
return state.color;
}
void OpenGL::setClearColor(const Color &c)
{
glClearColor(c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f);
state.clearColor = c;
}
Color OpenGL::getClearColor() const
{
return state.clearColor;
}
void OpenGL::setActiveTextureUnit(int textureunit)
{
if (textureunit < 0 || (size_t) textureunit >= state.textureUnits.size())
+13 -1
View File
@@ -71,7 +71,17 @@ public:
/**
* Gets the current constant color.
**/
Color getColor();
Color getColor() const;
/**
* Sets the current clear color for all framebuffer objects.
**/
void setClearColor(const Color &c);
/**
* Gets the current clear color.
**/
Color getClearColor() const;
/**
* Helper for setting the active texture unit.
@@ -135,6 +145,8 @@ private:
// Current constant color.
Color color;
Color clearColor;
// Texture unit state (currently bound texture for each texture unit.)
std::vector<GLuint> textureUnits;