move clipping to painter
This commit is contained in:
parent
1410031e02
commit
16acfebe3b
|
@ -105,13 +105,13 @@ void FrameBuffer::clear(const Color& color, const Rect& rect)
|
||||||
{
|
{
|
||||||
bool clip = rect.isValid();
|
bool clip = rect.isValid();
|
||||||
if(clip)
|
if(clip)
|
||||||
g_graphics.beginClipping(Rect(0, 0, m_texture->getSize()));
|
g_painter.setClipRect(Rect(0, 0, m_texture->getSize()));
|
||||||
|
|
||||||
glClearColor(color.rF(), color.gF(), color.bF(), color.aF());
|
glClearColor(color.rF(), color.gF(), color.bF(), color.aF());
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
if(clip)
|
if(clip)
|
||||||
g_graphics.endClipping();
|
g_painter.resetClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBuffer::bind()
|
void FrameBuffer::bind()
|
||||||
|
|
|
@ -152,17 +152,6 @@ void Graphics::endRender()
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::beginClipping(const Rect& clipRect)
|
|
||||||
{
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
|
||||||
glScissor(clipRect.left(), m_viewportSize.height() - clipRect.bottom() - 1, clipRect.width(), clipRect.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Graphics::endClipping()
|
|
||||||
{
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Graphics::setViewportSize(const Size& size)
|
void Graphics::setViewportSize(const Size& size)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, size.width(), size.height());
|
glViewport(0, 0, size.width(), size.height());
|
||||||
|
|
|
@ -44,9 +44,6 @@ public:
|
||||||
void beginRender();
|
void beginRender();
|
||||||
void endRender();
|
void endRender();
|
||||||
|
|
||||||
void beginClipping(const Rect& clipRect);
|
|
||||||
void endClipping();
|
|
||||||
|
|
||||||
void setViewportSize(const Size& size);
|
void setViewportSize(const Size& size);
|
||||||
|
|
||||||
int getMaxTextureSize();
|
int getMaxTextureSize();
|
||||||
|
|
|
@ -138,6 +138,17 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||||
m_compostionMode = compositionMode;
|
m_compostionMode = compositionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Painter::setClipRect(const Rect& clipRect)
|
||||||
|
{
|
||||||
|
if(clipRect.isValid()) {
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
glScissor(clipRect.left(), g_graphics.getViewportSize().height() - clipRect.bottom() - 1, clipRect.width(), clipRect.height());
|
||||||
|
m_clipRect = clipRect;
|
||||||
|
} else {
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Painter::saveAndResetState()
|
void Painter::saveAndResetState()
|
||||||
{
|
{
|
||||||
m_oldCustomProgram = m_customProgram;
|
m_oldCustomProgram = m_customProgram;
|
||||||
|
@ -145,8 +156,10 @@ void Painter::saveAndResetState()
|
||||||
m_oldColor = m_color;
|
m_oldColor = m_color;
|
||||||
m_oldOpacity = m_opacity;
|
m_oldOpacity = m_opacity;
|
||||||
m_oldCompostionMode = m_compostionMode;
|
m_oldCompostionMode = m_compostionMode;
|
||||||
|
m_oldClipRect = m_clipRect;
|
||||||
|
|
||||||
releaseCustomProgram();
|
releaseCustomProgram();
|
||||||
|
resetClipRect();
|
||||||
setColor(Color::white);
|
setColor(Color::white);
|
||||||
setOpacity(1);
|
setOpacity(1);
|
||||||
setCompositionMode(CompositionMode_Normal);
|
setCompositionMode(CompositionMode_Normal);
|
||||||
|
@ -158,9 +171,11 @@ void Painter::restoreSavedState()
|
||||||
setColor(m_oldColor);
|
setColor(m_oldColor);
|
||||||
setOpacity(m_oldOpacity);
|
setOpacity(m_oldOpacity);
|
||||||
setCompositionMode(m_oldCompostionMode);
|
setCompositionMode(m_oldCompostionMode);
|
||||||
|
setClipRect(m_oldClipRect);
|
||||||
|
|
||||||
m_oldCustomProgram = nullptr;
|
m_oldCustomProgram = nullptr;
|
||||||
m_oldColor = Color::white;
|
m_oldColor = Color::white;
|
||||||
m_oldOpacity = 1;
|
m_oldOpacity = 1;
|
||||||
m_oldCompostionMode = CompositionMode_Normal;
|
m_oldCompostionMode = CompositionMode_Normal;
|
||||||
|
m_oldClipRect = Rect();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,10 @@ public:
|
||||||
void setOpacity(float opacity) { m_opacity = opacity; }
|
void setOpacity(float opacity) { m_opacity = opacity; }
|
||||||
float getOpacity() { return m_opacity; }
|
float getOpacity() { return m_opacity; }
|
||||||
|
|
||||||
|
void setClipRect(const Rect& clipRect);
|
||||||
|
Rect getClipRect() { return m_clipRect; }
|
||||||
|
void resetClipRect() { setClipRect(Rect()); }
|
||||||
|
|
||||||
void setCustomProgram(PainterShaderProgramPtr program);
|
void setCustomProgram(PainterShaderProgramPtr program);
|
||||||
void releaseCustomProgram() { m_customProgram = nullptr; }
|
void releaseCustomProgram() { m_customProgram = nullptr; }
|
||||||
void setCompositionMode(CompositionMode compositionMode);
|
void setCompositionMode(CompositionMode compositionMode);
|
||||||
|
@ -77,11 +81,13 @@ private:
|
||||||
float m_opacity;
|
float m_opacity;
|
||||||
CompositionMode m_compostionMode;
|
CompositionMode m_compostionMode;
|
||||||
CoordsBuffer m_coordsBuffer;
|
CoordsBuffer m_coordsBuffer;
|
||||||
|
Rect m_clipRect;
|
||||||
|
|
||||||
PainterShaderProgramPtr m_oldCustomProgram;
|
PainterShaderProgramPtr m_oldCustomProgram;
|
||||||
Matrix3 m_oldProjectionMatrix;
|
Matrix3 m_oldProjectionMatrix;
|
||||||
Color m_oldColor;
|
Color m_oldColor;
|
||||||
float m_oldOpacity;
|
float m_oldOpacity;
|
||||||
|
Rect m_oldClipRect;
|
||||||
CompositionMode m_oldCompostionMode;
|
CompositionMode m_oldCompostionMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,19 +54,19 @@ UIWidget::~UIWidget()
|
||||||
void UIWidget::draw(const Rect& visibleRect)
|
void UIWidget::draw(const Rect& visibleRect)
|
||||||
{
|
{
|
||||||
if(m_clipping)
|
if(m_clipping)
|
||||||
g_graphics.beginClipping(visibleRect);
|
g_painter.setClipRect(visibleRect);
|
||||||
|
|
||||||
drawSelf();
|
drawSelf();
|
||||||
|
|
||||||
if(m_children.size() > 0) {
|
if(m_children.size() > 0) {
|
||||||
if(m_clipping)
|
if(m_clipping)
|
||||||
g_graphics.beginClipping(visibleRect.intersection(getClippingRect()));
|
g_painter.setClipRect(visibleRect.intersection(getClippingRect()));
|
||||||
|
|
||||||
drawChildren(visibleRect);
|
drawChildren(visibleRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_clipping)
|
if(m_clipping)
|
||||||
g_graphics.endClipping();
|
g_painter.resetClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::drawSelf()
|
void UIWidget::drawSelf()
|
||||||
|
|
|
@ -183,10 +183,12 @@ void Creature::drawOutfit(const Rect& destRect, bool resize)
|
||||||
if(!outfitBuffer)
|
if(!outfitBuffer)
|
||||||
outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)));
|
outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)));
|
||||||
|
|
||||||
|
g_painter.saveAndResetState();
|
||||||
outfitBuffer->bind();
|
outfitBuffer->bind();
|
||||||
outfitBuffer->clear(Color::alpha);
|
outfitBuffer->clear(Color::alpha);
|
||||||
internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
|
internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
|
||||||
outfitBuffer->release();
|
outfitBuffer->release();
|
||||||
|
g_painter.restoreSavedState();
|
||||||
|
|
||||||
if(resize) {
|
if(resize) {
|
||||||
Rect srcRect;
|
Rect srcRect;
|
||||||
|
|
Loading…
Reference in New Issue