mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 17:53:47 +00:00
09edbf49fd
This commit changes a bunch of internal rendering logic to use FBOs in a way that doesn't violate the GL spec. The water surface FBO's output texture was bound for reading while at the same time rendering the water surface back into the same FBO! Depending on the card/driver/load/zoom factor/moon phase, this could lead to water surface flickering, chessboard effects, and other visual glitches. In order to fix this an extra FBO is needed. In theory this is a simple fix but in practice this is the Aquaria codebase and everything is more complicated than it has any right to be. Couple other things: - FBOs no longer have a depth renderbuffer. Aquaria never uses the depth buffer for anything, so this can go to save some memory. Also remove renderbuffer GL function pointers. - Make FBOs multi-"paged". This is supposedly more efficient on desktop GL, if glDrawBuffer() supports GL_COLOR_ATTACHMENTn. This is currently checked via the presence of glDrawBuffersARB(). - Main core FBO now has 2 pages becaus it's needed for the water surface. The same 2 pages are later used by the after effect manager to ping-pong postprocessing shaders. Remove private after effect FBO. TODO: - There's still a bug in the one-fbo-multiple-binding-points code path. -> for now glDrawBuffersARB must be NULL to work properly.
142 lines
3.3 KiB
C++
142 lines
3.3 KiB
C++
/*
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
This file is part of Aquaria.
|
|
|
|
Aquaria is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "ScreenTransition.h"
|
|
#include "Core.h"
|
|
#include "RenderBase.h"
|
|
|
|
ScreenTransition::ScreenTransition() : RenderObject()
|
|
{
|
|
screen_texture = 0;
|
|
cull = false;
|
|
followCamera = 1;
|
|
alpha = 0;
|
|
createTexture();
|
|
}
|
|
|
|
void ScreenTransition::createTexture()
|
|
{
|
|
destroyTexture();
|
|
|
|
width = core->getVirtualWidth();
|
|
height = core->getVirtualHeight();
|
|
|
|
windowWidth = core->getWindowWidth();
|
|
windowHeight = core->getWindowHeight();
|
|
|
|
textureWidth = windowWidth;
|
|
textureHeight = windowHeight;
|
|
|
|
sizePowerOf2Texture(textureWidth);
|
|
sizePowerOf2Texture(textureHeight);
|
|
|
|
//create our texture
|
|
glGenTextures(1,&screen_texture);
|
|
glBindTexture(GL_TEXTURE_2D, screen_texture);
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST);
|
|
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB, textureWidth, textureHeight, 0 , GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
|
glBindTexture(GL_TEXTURE_2D,0);
|
|
}
|
|
|
|
void ScreenTransition::destroyTexture()
|
|
{
|
|
if (screen_texture)
|
|
{
|
|
glDeleteTextures(1, &screen_texture);
|
|
screen_texture = 0;
|
|
}
|
|
}
|
|
|
|
void ScreenTransition::unloadDevice()
|
|
{
|
|
RenderObject::unloadDevice();
|
|
destroyTexture();
|
|
}
|
|
|
|
void ScreenTransition::reloadDevice()
|
|
{
|
|
RenderObject::reloadDevice();
|
|
createTexture();
|
|
}
|
|
|
|
void ScreenTransition::capture()
|
|
{
|
|
assert(screen_texture);
|
|
core->renderExternal();
|
|
|
|
if (screen_texture)
|
|
{
|
|
glBindTexture(GL_TEXTURE_2D,screen_texture);
|
|
glReadBuffer(GL_BACK);
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, windowWidth, windowHeight);
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
|
|
core->showBuffer();
|
|
}
|
|
|
|
void ScreenTransition::go(float time)
|
|
{
|
|
capture();
|
|
transition(time);
|
|
}
|
|
|
|
void ScreenTransition::transition(float time)
|
|
{
|
|
core->resetTimer();
|
|
alpha = 1;
|
|
alpha.interpolateTo(0, time);
|
|
}
|
|
|
|
bool ScreenTransition::isGoing()
|
|
{
|
|
return alpha.isInterpolating();
|
|
}
|
|
|
|
void ScreenTransition::onRender(const RenderState& rs) const
|
|
{
|
|
if (alpha.x == 0) return;
|
|
|
|
float width2 = float(width)/2;
|
|
float height2 = float(height)/2;
|
|
|
|
const float pw = float(windowWidth)/float(textureWidth);
|
|
const float ph = float(windowHeight)/float(textureHeight);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, screen_texture);
|
|
|
|
glBegin(GL_QUADS);
|
|
glTexCoord2f(0, 0);
|
|
glVertex3f(-width2, height2, 0.0);
|
|
glTexCoord2f(pw, 0);
|
|
glVertex3f( width2, height2, 0.0);
|
|
glTexCoord2f(pw, ph);
|
|
glVertex3f( width2, -height2, 0.0);
|
|
glTexCoord2f(0, ph);
|
|
glVertex3f(-width2, -height2, 0.0);
|
|
glEnd();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
RenderObject::lastTextureApplied = 0;
|
|
}
|
|
|