2019-12-28 17:20:47 +00:00
|
|
|
/*
|
2020-01-03 07:03:29 +00:00
|
|
|
** gl_renderer.cpp
|
2019-12-28 17:20:47 +00:00
|
|
|
** Renderer interface
|
|
|
|
**
|
2020-01-03 07:03:29 +00:00
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2005-2020 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.
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
2019-12-28 17:20:47 +00:00
|
|
|
|
2020-04-26 21:17:54 +00:00
|
|
|
#include "gl_system.h"
|
2019-12-28 17:20:47 +00:00
|
|
|
#include "files.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "i_time.h"
|
|
|
|
#include "cmdlib.h"
|
2020-04-26 21:17:54 +00:00
|
|
|
#include "version.h"
|
2020-05-31 08:24:04 +00:00
|
|
|
#include "gl_interface.h"
|
2020-05-31 08:41:59 +00:00
|
|
|
#include "gl_framebuffer.h"
|
2020-05-31 08:24:04 +00:00
|
|
|
#include "hw_cvars.h"
|
2020-05-28 21:48:50 +00:00
|
|
|
#include "gl_debug.h"
|
2020-05-31 08:41:59 +00:00
|
|
|
#include "gl_renderer.h"
|
2020-04-26 21:17:54 +00:00
|
|
|
#include "gl_renderstate.h"
|
|
|
|
#include "gl_renderbuffers.h"
|
|
|
|
#include "gl_shaderprogram.h"
|
|
|
|
#include "flatvertices.h"
|
2020-05-28 23:03:01 +00:00
|
|
|
#include "gl_samplers.h"
|
2020-04-26 21:17:54 +00:00
|
|
|
#include "hw_lightbuffer.h"
|
2019-12-28 17:20:47 +00:00
|
|
|
#include "r_videoscale.h"
|
2020-05-31 08:24:04 +00:00
|
|
|
#include "model.h"
|
2020-04-26 21:17:54 +00:00
|
|
|
#include "gl_postprocessstate.h"
|
|
|
|
#include "gl_buffers.h"
|
2020-05-29 14:46:36 +00:00
|
|
|
#include "gl_hwtexture.h"
|
2020-05-31 08:24:04 +00:00
|
|
|
#include "texturemanager.h"
|
2019-12-28 17:20:47 +00:00
|
|
|
|
|
|
|
EXTERN_CVAR(Int, screenblocks)
|
|
|
|
|
|
|
|
namespace OpenGLRenderer
|
|
|
|
{
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Renderer interface
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Initialize
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
|
|
|
|
{
|
|
|
|
framebuffer = fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGLRenderer::Initialize(int width, int height)
|
|
|
|
{
|
2020-04-26 21:17:54 +00:00
|
|
|
mScreenBuffers = new FGLRenderBuffers();
|
|
|
|
mSaveBuffers = new FGLRenderBuffers();
|
2019-12-28 17:20:47 +00:00
|
|
|
mBuffers = mScreenBuffers;
|
|
|
|
mPresentShader = new FPresentShader();
|
|
|
|
mPresent3dCheckerShader = new FPresent3DCheckerShader();
|
|
|
|
mPresent3dColumnShader = new FPresent3DColumnShader();
|
|
|
|
mPresent3dRowShader = new FPresent3DRowShader();
|
2020-04-26 21:17:54 +00:00
|
|
|
mShadowMapShader = new FShadowMapShader();
|
2019-12-28 17:20:47 +00:00
|
|
|
|
|
|
|
// needed for the core profile, because someone decided it was a good idea to remove the default VAO.
|
|
|
|
glGenVertexArrays(1, &mVAOID);
|
|
|
|
glBindVertexArray(mVAOID);
|
|
|
|
FGLDebug::LabelObject(GL_VERTEX_ARRAY, mVAOID, "FGLRenderer.mVAOID");
|
|
|
|
|
|
|
|
mFBID = 0;
|
|
|
|
mOldFBID = 0;
|
|
|
|
|
2020-04-26 21:17:54 +00:00
|
|
|
mShaderManager = new FShaderManager;
|
2020-05-28 23:03:01 +00:00
|
|
|
mSamplerManager = new FSamplerManager;
|
2019-12-28 17:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGLRenderer::~FGLRenderer()
|
|
|
|
{
|
2020-04-28 20:55:37 +00:00
|
|
|
FlushModels();
|
2020-04-26 21:17:54 +00:00
|
|
|
TexMan.FlushAll();
|
|
|
|
if (mShaderManager != nullptr) delete mShaderManager;
|
2020-05-28 23:03:01 +00:00
|
|
|
if (mSamplerManager != nullptr) delete mSamplerManager;
|
2019-12-28 17:20:47 +00:00
|
|
|
if (mFBID != 0) glDeleteFramebuffers(1, &mFBID);
|
|
|
|
if (mVAOID != 0)
|
|
|
|
{
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glDeleteVertexArrays(1, &mVAOID);
|
|
|
|
}
|
|
|
|
if (mBuffers) delete mBuffers;
|
|
|
|
if (mSaveBuffers) delete mSaveBuffers;
|
|
|
|
if (mPresentShader) delete mPresentShader;
|
|
|
|
if (mPresent3dCheckerShader) delete mPresent3dCheckerShader;
|
|
|
|
if (mPresent3dColumnShader) delete mPresent3dColumnShader;
|
|
|
|
if (mPresent3dRowShader) delete mPresent3dRowShader;
|
2020-04-26 21:17:54 +00:00
|
|
|
if (mShadowMapShader) delete mShadowMapShader;
|
2019-12-28 17:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool FGLRenderer::StartOffscreen()
|
|
|
|
{
|
|
|
|
bool firstBind = (mFBID == 0);
|
|
|
|
if (mFBID == 0)
|
|
|
|
glGenFramebuffers(1, &mFBID);
|
|
|
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &mOldFBID);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, mFBID);
|
|
|
|
if (firstBind)
|
|
|
|
FGLDebug::LabelObject(GL_FRAMEBUFFER, mFBID, "OffscreenFB");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::EndOffscreen()
|
|
|
|
{
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, mOldFBID);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
void FGLRenderer::BindToFrameBuffer(FGameTexture *mat)
|
2019-12-28 17:20:47 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
auto pBaseLayer = mat->GetTexture()->SystemTextures.GetHardwareTexture(0, false);
|
2020-05-28 23:03:01 +00:00
|
|
|
auto BaseLayer = pBaseLayer ? (OpenGLRenderer::FHardwareTexture*)pBaseLayer : nullptr;
|
2019-12-28 17:20:47 +00:00
|
|
|
|
|
|
|
if (BaseLayer == nullptr)
|
|
|
|
{
|
|
|
|
// must create the hardware texture first
|
2020-05-28 23:03:01 +00:00
|
|
|
BaseLayer = new FHardwareTexture(4);
|
|
|
|
BaseLayer->CreateTexture(nullptr, mat->GetTexelWidth() * 4, mat->GetTexelHeight() * 4, 15, false, "Camtex");
|
2020-05-25 21:59:07 +00:00
|
|
|
mat->GetTexture()->SystemTextures.AddHardwareTexture(0, false, BaseLayer);
|
2019-12-28 17:20:47 +00:00
|
|
|
}
|
2020-05-23 22:38:10 +00:00
|
|
|
BaseLayer->BindToFrameBuffer(mat->GetTexelWidth()*4, mat->GetTexelHeight()*4);
|
2019-12-28 17:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::BeginFrame()
|
|
|
|
{
|
|
|
|
mScreenBuffers->Setup(screen->mScreenViewport.width, screen->mScreenViewport.height, screen->mSceneViewport.width, screen->mSceneViewport.height);
|
2020-04-26 21:17:54 +00:00
|
|
|
mSaveBuffers->Setup(SAVEPICWIDTH, SAVEPICHEIGHT, SAVEPICWIDTH, SAVEPICHEIGHT);
|
|
|
|
}
|
|
|
|
|
2019-12-28 17:20:47 +00:00
|
|
|
}
|