2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl_wipe.cpp
|
|
|
|
** Screen wipe stuff
|
|
|
|
** (This uses immediate mode and the fixed function pipeline
|
|
|
|
** even if the new renderer is active)
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2008 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
** 4. When not used as part of GZDoom or a GZDoom derivative, this code will be
|
|
|
|
** covered by the terms of the GNU Lesser General Public License as published
|
|
|
|
** by the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
** your option) any later version.
|
|
|
|
** 5. Full disclosure of the entire project's source code, except for third
|
|
|
|
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gl/system/gl_system.h"
|
|
|
|
#include "files.h"
|
|
|
|
#include "f_wipe.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "vectors.h"
|
|
|
|
|
2013-09-03 16:29:39 +00:00
|
|
|
#include "gl/system/gl_interface.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/renderer/gl_renderer.h"
|
|
|
|
#include "gl/renderer/gl_renderstate.h"
|
2016-07-26 19:27:02 +00:00
|
|
|
#include "gl/renderer/gl_renderbuffers.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/system/gl_framebuffer.h"
|
2016-07-26 19:27:02 +00:00
|
|
|
#include "gl/system/gl_cvars.h"
|
2014-06-21 14:41:45 +00:00
|
|
|
#include "gl/shaders/gl_shader.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/textures/gl_translate.h"
|
|
|
|
#include "gl/textures/gl_material.h"
|
2014-08-22 21:50:38 +00:00
|
|
|
#include "gl/textures/gl_samplers.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/utility/gl_templates.h"
|
2014-06-30 08:05:15 +00:00
|
|
|
#include "gl/data/gl_vertexbuffer.h"
|
2016-08-08 10:13:09 +00:00
|
|
|
#include "gl/renderer/gl_2ddrawer.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2013-06-26 23:01:00 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
struct POINT {
|
|
|
|
SDWORD x;
|
|
|
|
SDWORD y;
|
|
|
|
};
|
|
|
|
struct RECT {
|
|
|
|
SDWORD left;
|
|
|
|
SDWORD top;
|
|
|
|
SDWORD right;
|
|
|
|
SDWORD bottom;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Screen wipes
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
// TYPES -------------------------------------------------------------------
|
|
|
|
|
|
|
|
class OpenGLFrameBuffer::Wiper_Crossfade : public OpenGLFrameBuffer::Wiper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Wiper_Crossfade();
|
|
|
|
bool Run(int ticks, OpenGLFrameBuffer *fb);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int Clock;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpenGLFrameBuffer::Wiper_Melt : public OpenGLFrameBuffer::Wiper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Wiper_Melt();
|
2016-08-06 12:12:40 +00:00
|
|
|
int MakeVBO(int ticks, OpenGLFrameBuffer *fb, bool &done);
|
2013-06-23 07:49:34 +00:00
|
|
|
bool Run(int ticks, OpenGLFrameBuffer *fb);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int WIDTH = 320, HEIGHT = 200;
|
|
|
|
int y[WIDTH];
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpenGLFrameBuffer::Wiper_Burn : public OpenGLFrameBuffer::Wiper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Wiper_Burn();
|
|
|
|
~Wiper_Burn();
|
|
|
|
bool Run(int ticks, OpenGLFrameBuffer *fb);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int WIDTH = 64, HEIGHT = 64;
|
|
|
|
BYTE BurnArray[WIDTH * (HEIGHT + 5)];
|
|
|
|
FHardwareTexture *BurnTexture;
|
|
|
|
int Density;
|
|
|
|
int BurnTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: WipeStartScreen
|
|
|
|
//
|
|
|
|
// Called before the current screen has started rendering. This needs to
|
|
|
|
// save what was drawn the previous frame so that it can be animated into
|
|
|
|
// what gets drawn this frame.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool OpenGLFrameBuffer::WipeStartScreen(int type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case wipe_Burn:
|
|
|
|
ScreenWipe = new Wiper_Burn;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wipe_Fade:
|
|
|
|
ScreenWipe = new Wiper_Crossfade;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wipe_Melt:
|
|
|
|
ScreenWipe = new Wiper_Melt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 05:28:29 +00:00
|
|
|
const auto &viewport = GLRenderer->mScreenViewport;
|
|
|
|
wipestartscreen = new FHardwareTexture(viewport.width, viewport.height, true);
|
|
|
|
wipestartscreen->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0);
|
2016-04-22 17:54:51 +00:00
|
|
|
GLRenderer->mSamplerManager->Bind(0, CLAMP_NOFILTER, -1);
|
|
|
|
GLRenderer->mSamplerManager->Bind(1, CLAMP_NONE, -1);
|
2013-09-03 12:05:41 +00:00
|
|
|
glFinish();
|
2014-09-09 11:21:36 +00:00
|
|
|
wipestartscreen->Bind(0, false, false);
|
2016-07-26 19:27:02 +00:00
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
if (FGLRenderBuffers::IsEnabled())
|
2016-07-26 19:27:02 +00:00
|
|
|
{
|
2016-08-04 15:16:49 +00:00
|
|
|
GLRenderer->mBuffers->BindCurrentFB();
|
2016-08-12 05:28:29 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height);
|
2016-07-26 19:27:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GLint readbuffer = 0;
|
|
|
|
glGetIntegerv(GL_READ_BUFFER, &readbuffer);
|
|
|
|
glReadBuffer(GL_FRONT);
|
2016-08-12 05:28:29 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height);
|
2016-07-26 19:27:02 +00:00
|
|
|
glReadBuffer(readbuffer);
|
|
|
|
}
|
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: WipeEndScreen
|
|
|
|
//
|
|
|
|
// The screen we want to animate to has just been drawn.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void OpenGLFrameBuffer::WipeEndScreen()
|
|
|
|
{
|
2016-08-08 10:13:09 +00:00
|
|
|
GLRenderer->m2DDrawer->Flush();
|
2016-08-12 05:28:29 +00:00
|
|
|
|
|
|
|
const auto &viewport = GLRenderer->mScreenViewport;
|
|
|
|
wipeendscreen = new FHardwareTexture(viewport.width, viewport.height, true);
|
|
|
|
wipeendscreen->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0);
|
2016-04-22 17:54:51 +00:00
|
|
|
GLRenderer->mSamplerManager->Bind(0, CLAMP_NOFILTER, -1);
|
2014-08-22 21:50:38 +00:00
|
|
|
glFinish();
|
2014-09-09 11:21:36 +00:00
|
|
|
wipeendscreen->Bind(0, false, false);
|
2016-07-26 19:27:02 +00:00
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
if (FGLRenderBuffers::IsEnabled())
|
2016-08-04 15:16:49 +00:00
|
|
|
GLRenderer->mBuffers->BindCurrentFB();
|
2016-07-26 19:27:02 +00:00
|
|
|
|
2016-08-12 05:28:29 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height);
|
2013-09-03 12:05:41 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-06-23 07:49:34 +00:00
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: WipeDo
|
|
|
|
//
|
|
|
|
// Perform the actual wipe animation. The number of tics since the last
|
|
|
|
// time this function was called is passed in. Returns true when the wipe
|
|
|
|
// is over. The first time this function has been called, the screen is
|
|
|
|
// still locked from before and EndScene() still has not been called.
|
|
|
|
// Successive times need to call BeginScene().
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool OpenGLFrameBuffer::WipeDo(int ticks)
|
|
|
|
{
|
2016-08-06 12:12:40 +00:00
|
|
|
bool done = true;
|
2013-06-23 07:49:34 +00:00
|
|
|
// Sanity checks.
|
2016-08-06 12:12:40 +00:00
|
|
|
if (wipestartscreen != nullptr && wipeendscreen != nullptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-08-06 12:12:40 +00:00
|
|
|
Lock(true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
gl_RenderState.EnableTexture(true);
|
|
|
|
gl_RenderState.EnableFog(false);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
if (FGLRenderBuffers::IsEnabled())
|
|
|
|
{
|
|
|
|
GLRenderer->mBuffers->BindCurrentFB();
|
|
|
|
const auto &bounds = GLRenderer->mScreenViewport;
|
|
|
|
glViewport(bounds.left, bounds.top, bounds.width, bounds.height);
|
|
|
|
}
|
2016-07-26 19:27:02 +00:00
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
done = ScreenWipe->Run(ticks, this);
|
|
|
|
glDepthMask(true);
|
|
|
|
}
|
|
|
|
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
2013-06-23 07:49:34 +00:00
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: WipeCleanup
|
|
|
|
//
|
|
|
|
// Release any resources that were specifically created for the wipe.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void OpenGLFrameBuffer::WipeCleanup()
|
|
|
|
{
|
|
|
|
if (ScreenWipe != NULL)
|
|
|
|
{
|
|
|
|
delete ScreenWipe;
|
|
|
|
ScreenWipe = NULL;
|
|
|
|
}
|
|
|
|
if (wipestartscreen != NULL)
|
|
|
|
{
|
|
|
|
delete wipestartscreen;
|
|
|
|
wipestartscreen = NULL;
|
|
|
|
}
|
|
|
|
if (wipeendscreen != NULL)
|
|
|
|
{
|
|
|
|
delete wipeendscreen;
|
|
|
|
wipeendscreen = NULL;
|
|
|
|
}
|
2014-08-31 17:00:17 +00:00
|
|
|
FMaterial::ClearLastTexture();
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper Constructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-08-06 12:12:40 +00:00
|
|
|
OpenGLFrameBuffer::Wiper::Wiper()
|
|
|
|
{
|
2016-08-06 22:40:31 +00:00
|
|
|
mVertexBuf = new FSimpleVertexBuffer;
|
2016-08-06 12:12:40 +00:00
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
OpenGLFrameBuffer::Wiper::~Wiper()
|
|
|
|
{
|
2016-08-06 12:12:40 +00:00
|
|
|
delete mVertexBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLFrameBuffer::Wiper::MakeVBO(OpenGLFrameBuffer *fb)
|
|
|
|
{
|
2016-08-08 10:13:09 +00:00
|
|
|
FSimpleVertex make[4];
|
|
|
|
FSimpleVertex *ptr = make;
|
2016-08-06 12:12:40 +00:00
|
|
|
|
|
|
|
float ur = fb->GetWidth() / FHardwareTexture::GetTexDimension(fb->GetWidth());
|
|
|
|
float vb = fb->GetHeight() / FHardwareTexture::GetTexDimension(fb->GetHeight());
|
|
|
|
|
|
|
|
ptr->Set(0, 0, 0, 0, vb);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(0, fb->Height, 0, 0, 0);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(fb->Width, 0, 0, ur, vb);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(fb->Width, fb->Height, 0, ur, 0);
|
|
|
|
mVertexBuf->set(make, 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WIPE: CROSSFADE ---------------------------------------------------------
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Crossfade Constructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
OpenGLFrameBuffer::Wiper_Crossfade::Wiper_Crossfade()
|
|
|
|
: Clock(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Crossfade :: Run
|
|
|
|
//
|
|
|
|
// Fades the old screen into the new one over 32 ticks.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool OpenGLFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLFrameBuffer *fb)
|
|
|
|
{
|
|
|
|
Clock += ticks;
|
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
MakeVBO(fb);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
2014-07-14 19:14:43 +00:00
|
|
|
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
|
2014-05-11 19:47:54 +00:00
|
|
|
gl_RenderState.ResetColor();
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.Apply();
|
2014-09-09 11:21:36 +00:00
|
|
|
fb->wipestartscreen->Bind(0, 0, false);
|
2016-08-06 12:12:40 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2014-06-30 08:05:15 +00:00
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
float a = clamp(Clock / 32.f, 0.f, 1.f);
|
|
|
|
gl_RenderState.SetColorAlpha(0xffffff, a);
|
2014-05-11 19:47:54 +00:00
|
|
|
gl_RenderState.Apply();
|
2016-08-06 12:12:40 +00:00
|
|
|
fb->wipeendscreen->Bind(0, 0, false);
|
2016-08-18 22:21:17 +00:00
|
|
|
mVertexBuf->EnableColorArray(false);
|
2016-08-06 12:12:40 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2014-07-14 19:14:43 +00:00
|
|
|
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f);
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.SetTextureMode(TM_MODULATE);
|
|
|
|
|
|
|
|
return Clock >= 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Melt Constructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
OpenGLFrameBuffer::Wiper_Melt::Wiper_Melt()
|
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
// setup initial column positions
|
|
|
|
// (y<0 => not ready to scroll yet)
|
|
|
|
y[0] = -(M_Random() & 15);
|
|
|
|
for (i = 1; i < WIDTH; ++i)
|
|
|
|
{
|
|
|
|
r = (M_Random()%3) - 1;
|
|
|
|
y[i] = clamp(y[i-1] + r, -15, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Melt :: Run
|
|
|
|
//
|
|
|
|
// Fades the old screen into the new one over 32 ticks.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
int OpenGLFrameBuffer::Wiper_Melt::MakeVBO(int ticks, OpenGLFrameBuffer *fb, bool &done)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-08-08 10:13:09 +00:00
|
|
|
FSimpleVertex *make = new FSimpleVertex[321*4];
|
|
|
|
FSimpleVertex *ptr = make;
|
2016-08-06 12:12:40 +00:00
|
|
|
int dy;
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
float ur = fb->GetWidth() / FHardwareTexture::GetTexDimension(fb->GetWidth());
|
|
|
|
float vb = fb->GetHeight() / FHardwareTexture::GetTexDimension(fb->GetHeight());
|
|
|
|
|
2014-06-30 08:05:15 +00:00
|
|
|
ptr->Set(0, 0, 0, 0, vb);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(0, fb->Height, 0, 0, 0);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(fb->Width, 0, 0, ur, vb);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(fb->Width, fb->Height, 0, ur, 0);
|
|
|
|
ptr++;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Copy the old screen in vertical strips on top of the new one.
|
|
|
|
while (ticks--)
|
|
|
|
{
|
|
|
|
done = true;
|
2016-08-06 12:12:40 +00:00
|
|
|
for (int i = 0; i < WIDTH; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (y[i] < 0)
|
|
|
|
{
|
|
|
|
y[i]++;
|
|
|
|
done = false;
|
2016-08-06 12:12:40 +00:00
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
else if (y[i] < HEIGHT)
|
|
|
|
{
|
2016-08-06 12:12:40 +00:00
|
|
|
dy = (y[i] < 16) ? y[i] + 1 : 8;
|
2013-06-23 07:49:34 +00:00
|
|
|
y[i] = MIN(y[i] + dy, HEIGHT);
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
if (ticks == 0)
|
2016-08-06 12:12:40 +00:00
|
|
|
{
|
2014-06-30 08:05:15 +00:00
|
|
|
// Only draw for the final tick.
|
|
|
|
// No need for optimization. Wipes won't ever be drawn with anything else.
|
2013-06-23 07:49:34 +00:00
|
|
|
RECT rect;
|
|
|
|
POINT dpt;
|
|
|
|
|
|
|
|
dpt.x = i * fb->Width / WIDTH;
|
|
|
|
dpt.y = MAX(0, y[i] * fb->Height / HEIGHT);
|
|
|
|
rect.left = dpt.x;
|
|
|
|
rect.top = 0;
|
|
|
|
rect.right = (i + 1) * fb->Width / WIDTH;
|
|
|
|
rect.bottom = fb->Height - dpt.y;
|
|
|
|
if (rect.bottom > rect.top)
|
|
|
|
{
|
|
|
|
float tw = (float)FHardwareTexture::GetTexDimension(fb->Width);
|
|
|
|
float th = (float)FHardwareTexture::GetTexDimension(fb->Height);
|
|
|
|
rect.bottom = fb->Height - rect.bottom;
|
|
|
|
rect.top = fb->Height - rect.top;
|
2014-06-30 08:05:15 +00:00
|
|
|
|
|
|
|
ptr->Set(rect.left, rect.bottom, 0, rect.left / tw, rect.top / th);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(rect.left, rect.top, 0, rect.left / tw, rect.bottom / th);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(rect.right, rect.bottom, 0, rect.right / tw, rect.top / th);
|
|
|
|
ptr++;
|
|
|
|
ptr->Set(rect.right, rect.top, 0, rect.right / tw, rect.bottom / th);
|
|
|
|
ptr++;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-06 12:12:40 +00:00
|
|
|
int numverts = int(ptr - make);
|
|
|
|
mVertexBuf->set(make, numverts);
|
|
|
|
delete[] make;
|
|
|
|
return numverts;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGLFrameBuffer::Wiper_Melt::Run(int ticks, OpenGLFrameBuffer *fb)
|
|
|
|
{
|
|
|
|
bool done = false;
|
|
|
|
int maxvert = MakeVBO(ticks, fb, done);
|
|
|
|
|
|
|
|
// Draw the new screen on the bottom.
|
|
|
|
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
|
|
|
gl_RenderState.ResetColor();
|
|
|
|
gl_RenderState.Apply();
|
|
|
|
fb->wipeendscreen->Bind(0, 0, false);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
fb->wipestartscreen->Bind(0, 0, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.SetTextureMode(TM_MODULATE);
|
2016-08-06 12:12:40 +00:00
|
|
|
for (int i = 4; i < maxvert; i += 4)
|
|
|
|
{
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, i, 4);
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Burn Constructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
OpenGLFrameBuffer::Wiper_Burn::Wiper_Burn()
|
|
|
|
{
|
|
|
|
Density = 4;
|
|
|
|
BurnTime = 0;
|
|
|
|
memset(BurnArray, 0, sizeof(BurnArray));
|
|
|
|
BurnTexture = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Burn Destructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
OpenGLFrameBuffer::Wiper_Burn::~Wiper_Burn()
|
|
|
|
{
|
|
|
|
if (BurnTexture != NULL)
|
|
|
|
{
|
|
|
|
delete BurnTexture;
|
|
|
|
BurnTexture = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OpenGLFrameBuffer :: Wiper_Burn :: Run
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool OpenGLFrameBuffer::Wiper_Burn::Run(int ticks, OpenGLFrameBuffer *fb)
|
|
|
|
{
|
|
|
|
bool done;
|
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
MakeVBO(fb);
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
BurnTime += ticks;
|
|
|
|
ticks *= 2;
|
|
|
|
|
|
|
|
// Make the fire burn
|
|
|
|
done = false;
|
|
|
|
while (!done && ticks--)
|
|
|
|
{
|
|
|
|
Density = wipe_CalcBurn(BurnArray, WIDTH, HEIGHT, Density);
|
|
|
|
done = (Density < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BurnTexture != NULL) delete BurnTexture;
|
2014-08-22 21:50:38 +00:00
|
|
|
BurnTexture = new FHardwareTexture(WIDTH, HEIGHT, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Update the burn texture with the new burn data
|
|
|
|
BYTE rgb_buffer[WIDTH*HEIGHT*4];
|
|
|
|
|
|
|
|
const BYTE *src = BurnArray;
|
|
|
|
DWORD *dest = (DWORD *)rgb_buffer;
|
|
|
|
for (int y = HEIGHT; y != 0; --y)
|
|
|
|
{
|
|
|
|
for (int x = WIDTH; x != 0; --x)
|
|
|
|
{
|
|
|
|
BYTE s = clamp<int>((*src++)*2, 0, 255);
|
|
|
|
*dest++ = MAKEARGB(s,255,255,255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float ur = fb->GetWidth() / FHardwareTexture::GetTexDimension(fb->GetWidth());
|
|
|
|
float vb = fb->GetHeight() / FHardwareTexture::GetTexDimension(fb->GetHeight());
|
|
|
|
|
|
|
|
|
|
|
|
// Put the initial screen back to the buffer.
|
|
|
|
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
2014-07-14 19:14:43 +00:00
|
|
|
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
|
2014-05-11 19:47:54 +00:00
|
|
|
gl_RenderState.ResetColor();
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.Apply();
|
2014-09-09 11:21:36 +00:00
|
|
|
fb->wipestartscreen->Bind(0, 0, false);
|
2016-08-06 12:12:40 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-06-21 14:41:45 +00:00
|
|
|
gl_RenderState.SetTextureMode(TM_MODULATE);
|
|
|
|
gl_RenderState.SetEffect(EFF_BURN);
|
|
|
|
gl_RenderState.ResetColor();
|
|
|
|
gl_RenderState.Apply();
|
|
|
|
|
|
|
|
// Burn the new screen on top of it.
|
2014-09-09 11:21:36 +00:00
|
|
|
fb->wipeendscreen->Bind(0, 0, false);
|
2014-06-21 14:41:45 +00:00
|
|
|
|
2014-09-09 11:21:36 +00:00
|
|
|
BurnTexture->CreateTexture(rgb_buffer, WIDTH, HEIGHT, 1, true, 0);
|
2014-06-21 14:41:45 +00:00
|
|
|
|
2016-08-06 12:12:40 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2014-06-21 14:41:45 +00:00
|
|
|
gl_RenderState.SetEffect(EFF_NONE);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// The fire may not always stabilize, so the wipe is forced to end
|
|
|
|
// after an arbitrary maximum time.
|
|
|
|
return done || (BurnTime > 40);
|
|
|
|
}
|