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();
|
||||
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());
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if(clip)
|
||||
g_graphics.endClipping();
|
||||
g_painter.resetClipRect();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
glViewport(0, 0, size.width(), size.height());
|
||||
|
|
|
@ -44,9 +44,6 @@ public:
|
|||
void beginRender();
|
||||
void endRender();
|
||||
|
||||
void beginClipping(const Rect& clipRect);
|
||||
void endClipping();
|
||||
|
||||
void setViewportSize(const Size& size);
|
||||
|
||||
int getMaxTextureSize();
|
||||
|
|
|
@ -138,6 +138,17 @@ void Painter::setCompositionMode(Painter::CompositionMode 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()
|
||||
{
|
||||
m_oldCustomProgram = m_customProgram;
|
||||
|
@ -145,8 +156,10 @@ void Painter::saveAndResetState()
|
|||
m_oldColor = m_color;
|
||||
m_oldOpacity = m_opacity;
|
||||
m_oldCompostionMode = m_compostionMode;
|
||||
m_oldClipRect = m_clipRect;
|
||||
|
||||
releaseCustomProgram();
|
||||
resetClipRect();
|
||||
setColor(Color::white);
|
||||
setOpacity(1);
|
||||
setCompositionMode(CompositionMode_Normal);
|
||||
|
@ -158,9 +171,11 @@ void Painter::restoreSavedState()
|
|||
setColor(m_oldColor);
|
||||
setOpacity(m_oldOpacity);
|
||||
setCompositionMode(m_oldCompostionMode);
|
||||
setClipRect(m_oldClipRect);
|
||||
|
||||
m_oldCustomProgram = nullptr;
|
||||
m_oldColor = Color::white;
|
||||
m_oldOpacity = 1;
|
||||
m_oldCompostionMode = CompositionMode_Normal;
|
||||
m_oldClipRect = Rect();
|
||||
}
|
||||
|
|
|
@ -57,6 +57,10 @@ public:
|
|||
void setOpacity(float opacity) { m_opacity = 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 releaseCustomProgram() { m_customProgram = nullptr; }
|
||||
void setCompositionMode(CompositionMode compositionMode);
|
||||
|
@ -77,11 +81,13 @@ private:
|
|||
float m_opacity;
|
||||
CompositionMode m_compostionMode;
|
||||
CoordsBuffer m_coordsBuffer;
|
||||
Rect m_clipRect;
|
||||
|
||||
PainterShaderProgramPtr m_oldCustomProgram;
|
||||
Matrix3 m_oldProjectionMatrix;
|
||||
Color m_oldColor;
|
||||
float m_oldOpacity;
|
||||
Rect m_oldClipRect;
|
||||
CompositionMode m_oldCompostionMode;
|
||||
};
|
||||
|
||||
|
|
|
@ -54,19 +54,19 @@ UIWidget::~UIWidget()
|
|||
void UIWidget::draw(const Rect& visibleRect)
|
||||
{
|
||||
if(m_clipping)
|
||||
g_graphics.beginClipping(visibleRect);
|
||||
g_painter.setClipRect(visibleRect);
|
||||
|
||||
drawSelf();
|
||||
|
||||
if(m_children.size() > 0) {
|
||||
if(m_clipping)
|
||||
g_graphics.beginClipping(visibleRect.intersection(getClippingRect()));
|
||||
g_painter.setClipRect(visibleRect.intersection(getClippingRect()));
|
||||
|
||||
drawChildren(visibleRect);
|
||||
}
|
||||
|
||||
if(m_clipping)
|
||||
g_graphics.endClipping();
|
||||
g_painter.resetClipRect();
|
||||
}
|
||||
|
||||
void UIWidget::drawSelf()
|
||||
|
|
|
@ -183,10 +183,12 @@ void Creature::drawOutfit(const Rect& destRect, bool resize)
|
|||
if(!outfitBuffer)
|
||||
outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)));
|
||||
|
||||
g_painter.saveAndResetState();
|
||||
outfitBuffer->bind();
|
||||
outfitBuffer->clear(Color::alpha);
|
||||
internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
|
||||
outfitBuffer->release();
|
||||
g_painter.restoreSavedState();
|
||||
|
||||
if(resize) {
|
||||
Rect srcRect;
|
||||
|
|
Loading…
Reference in New Issue