2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
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 "DarkLayer.h"
|
|
|
|
#include "Core.h"
|
2016-07-09 02:18:40 +00:00
|
|
|
#include "RenderBase.h"
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
DarkLayer::DarkLayer()
|
|
|
|
{
|
|
|
|
quality = 0;
|
|
|
|
active = false;
|
|
|
|
texture = 0;
|
2024-04-25 01:33:02 +00:00
|
|
|
useFrameBuffer = false;
|
|
|
|
layer = -1;
|
|
|
|
beginLayer = -1;
|
|
|
|
lastLayer = -1;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DarkLayer::unloadDevice()
|
|
|
|
{
|
|
|
|
if (useFrameBuffer)
|
|
|
|
frameBuffer.unloadDevice();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (texture)
|
|
|
|
glDeleteTextures(1, &texture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DarkLayer::reloadDevice()
|
|
|
|
{
|
|
|
|
if (useFrameBuffer)
|
|
|
|
frameBuffer.reloadDevice();
|
|
|
|
else
|
|
|
|
texture = generateEmptyTexture(quality);
|
|
|
|
}
|
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
bool DarkLayer::isUsed() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
return active;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
bool DarkLayer::shouldRenderLayer(int lr) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
if(!active)
|
|
|
|
return true;
|
|
|
|
return useFrameBuffer || (lr < beginLayer || lr > lastLayer);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DarkLayer::init(int quality, bool useFrameBufferParam)
|
|
|
|
{
|
|
|
|
useFrameBuffer = useFrameBufferParam;
|
|
|
|
|
|
|
|
this->quality = quality;
|
|
|
|
|
|
|
|
if (useFrameBuffer)
|
2016-05-05 17:40:28 +00:00
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
if (!frameBuffer.init(quality, quality, 1))
|
2011-08-03 20:05:33 +00:00
|
|
|
useFrameBuffer = false;
|
|
|
|
else
|
|
|
|
debugLog("Dark Layer: using framebuffer");
|
|
|
|
}
|
|
|
|
if (!useFrameBuffer)
|
|
|
|
{
|
|
|
|
debugLog("Dark Layer: using generated texture");
|
|
|
|
texture = generateEmptyTexture(quality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DarkLayer::toggle(bool on)
|
|
|
|
{
|
|
|
|
this->active = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DarkLayer::preRender()
|
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
if(!useFrameBuffer)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
glViewport(0, 0, quality, quality);
|
2024-01-10 23:05:45 +00:00
|
|
|
glClearColor(1,1,1,0);
|
2011-08-03 20:05:33 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2024-04-25 01:33:02 +00:00
|
|
|
core->renderInternal(beginLayer, lastLayer, false);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, quality, quality, 0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
void DarkLayer::beginCapture()
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
if(useFrameBuffer)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2024-04-25 01:33:02 +00:00
|
|
|
frameBuffer.pushCapture(0);
|
|
|
|
glClearColor(1,1,1,0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
void DarkLayer::endCapture()
|
|
|
|
{
|
|
|
|
if(useFrameBuffer)
|
|
|
|
{
|
|
|
|
frameBuffer.popCapture();
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
void DarkLayer::render(const RenderState& rs) const
|
|
|
|
{
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
if (useFrameBuffer)
|
|
|
|
frameBuffer.bindTexture(0);
|
|
|
|
else
|
|
|
|
glBindTexture(GL_TEXTURE_2D,texture);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
rs.gpu.setBlend(BLEND_MULT);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glColor4f(1,1,1,1);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
const float width = core->getWindowWidth();
|
|
|
|
const float height = core->getWindowHeight();
|
|
|
|
const float offX = -(core->getVirtualOffX() * width / core->getVirtualWidth());
|
|
|
|
const float offY = -(core->getVirtualOffY() * height / core->getVirtualHeight());
|
|
|
|
const float stretch = 4;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glBegin(GL_QUADS);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glTexCoord2f(0,1);
|
|
|
|
glVertex2f(offX-stretch, offY-stretch);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glTexCoord2f(0,0);
|
|
|
|
glVertex2f(offX-stretch, height+offY+stretch);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glTexCoord2f(1,0);
|
|
|
|
glVertex2f(width+offX+stretch, height+offY+stretch);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glTexCoord2f(1,1);
|
|
|
|
glVertex2f(width+offX+stretch, offY-stretch);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glEnd();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
glPopMatrix();
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2024-04-25 01:33:02 +00:00
|
|
|
RenderObject::lastTextureApplied = 0;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|