add framebuffer support for old video cards
This commit is contained in:
parent
7e0618b247
commit
1386064d71
|
@ -79,6 +79,9 @@ FrameBuffer::FrameBuffer(int width, int height)
|
|||
// otherwise fallback to copy texture from screen implementation
|
||||
m_fallbackOldImp = true;
|
||||
}
|
||||
|
||||
if(m_fallbackOldImp)
|
||||
logInfo("Framebuffers not supported, falling back to old implementation.");
|
||||
}
|
||||
|
||||
FrameBuffer::~FrameBuffer()
|
||||
|
@ -92,13 +95,23 @@ void FrameBuffer::bind()
|
|||
if(!m_fallbackOldImp) {
|
||||
// bind framebuffer
|
||||
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||
} else {
|
||||
int screenWidth = g_graphics.getScreenSize().width();
|
||||
int screenHeight = g_graphics.getScreenSize().height();
|
||||
|
||||
if(!m_screenBackup || m_screenBackup->getSize() != g_graphics.getScreenSize())
|
||||
m_screenBackup = TexturePtr(new Texture(screenWidth, screenHeight, 4));
|
||||
|
||||
// save screen state
|
||||
glBindTexture(GL_TEXTURE_2D, m_screenBackup->getId());
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenWidth, screenHeight);
|
||||
}
|
||||
|
||||
// setup framebuffer viewport
|
||||
glViewport(0, 0, m_texture->getWidth(), m_texture->getHeight());
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0f, m_texture->getWidth(), 0, m_texture->getHeight(), -1, 1);
|
||||
glOrtho(0.0f, m_texture->getWidth(), m_texture->getHeight(), 0, -1, 1);
|
||||
|
||||
// back to model view
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
@ -127,13 +140,14 @@ void FrameBuffer::unbind()
|
|||
// restore graphics viewport
|
||||
g_graphics.restoreViewport();
|
||||
|
||||
// clear screen
|
||||
// restore screen
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
g_graphics.drawTexturedRect(Rect(Point(0,0), g_graphics.getScreenSize()), m_screenBackup, Rect(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBuffer::draw(const Rect& screenCoords, const Rect& framebufferCoords)
|
||||
{
|
||||
g_graphics.drawTexturedRect(screenCoords, m_texture, framebufferCoords);
|
||||
g_graphics.drawTexturedRect(screenCoords, m_texture, framebufferCoords, true);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
private:
|
||||
TexturePtr m_texture;
|
||||
TexturePtr m_screenBackup;
|
||||
uint m_fbo;
|
||||
bool m_fallbackOldImp;
|
||||
};
|
||||
|
|
|
@ -132,7 +132,8 @@ void Graphics::endRender()
|
|||
|
||||
void Graphics::drawTexturedRect(const Rect& screenCoords,
|
||||
const TexturePtr& texture,
|
||||
const Rect& textureCoords)
|
||||
const Rect& textureCoords,
|
||||
bool upsideDown)
|
||||
{
|
||||
if(screenCoords.isEmpty() || texture->getId() == 0)
|
||||
return;
|
||||
|
@ -151,13 +152,23 @@ void Graphics::drawTexturedRect(const Rect& screenCoords,
|
|||
|
||||
if(textureCoords.isEmpty()) {
|
||||
textureRight = texture->getWidth() / (float)textureSize.width();
|
||||
textureBottom = texture->getHeight() / (float)textureSize.height();
|
||||
textureTop = 0.0f;
|
||||
if(upsideDown) {
|
||||
textureBottom = 0.0f;
|
||||
textureTop = texture->getHeight() / (float)textureSize.height();
|
||||
} else {
|
||||
textureBottom = texture->getHeight() / (float)textureSize.height();
|
||||
textureTop = 0.0f;
|
||||
}
|
||||
textureLeft = 0.0f;
|
||||
} else {
|
||||
textureRight = (textureCoords.right() + 1) / (float)textureSize.width();
|
||||
textureBottom = (textureCoords.bottom() + 1) / (float)textureSize.height();
|
||||
textureTop = textureCoords.top() / (float)textureSize.height();
|
||||
if(upsideDown) {
|
||||
textureTop = (textureCoords.bottom() + 1) / (float)textureSize.height();
|
||||
textureBottom = textureCoords.top() / (float)textureSize.height();
|
||||
} else {
|
||||
textureBottom = (textureCoords.bottom() + 1) / (float)textureSize.height();
|
||||
textureTop = textureCoords.top() / (float)textureSize.height();
|
||||
}
|
||||
textureLeft = textureCoords.left() / (float)textureSize.width();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ public:
|
|||
// drawing API
|
||||
void drawTexturedRect(const Rect& screenCoords,
|
||||
const TexturePtr& texture,
|
||||
const Rect& textureCoords = Rect());
|
||||
const Rect& textureCoords = Rect(),
|
||||
bool upsideDown = false);
|
||||
|
||||
void drawRepeatedTexturedRect(const Rect& screenCoords,
|
||||
const TexturePtr& texture,
|
||||
|
|
Loading…
Reference in New Issue