- moved most of the OpenGL backend to 'common'.

A few things are yet to do, because they still need some changes.
This commit is contained in:
Christoph Oelckers 2020-04-26 14:44:19 +02:00
commit 02832297ff
26 changed files with 216 additions and 220 deletions

View file

@ -1,28 +1,35 @@
//
//---------------------------------------------------------------------------
//
// Copyright(C) 2005-2016 Christoph Oelckers
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
//--------------------------------------------------------------------------
//
/*
** gl1_renderer.cpp
** gl_renderer.cpp
** Renderer interface
**
**---------------------------------------------------------------------------
** 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.
**---------------------------------------------------------------------------
**
*/
#include "gl_system.h"
@ -36,6 +43,7 @@
#include "d_player.h"
#include "a_dynlight.h"
#include "cmdlib.h"
#include "version.h"
#include "g_game.h"
#include "swrenderer/r_swscene.h"
#include "hwrenderer/utility/hw_clock.h"
@ -43,22 +51,22 @@
#include "gl_interface.h"
#include "gl/system/gl_framebuffer.h"
#include "hw_cvars.h"
#include "gl/system/gl_debug.h"
#include "gl_debug.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderstate.h"
#include "gl/renderer/gl_renderbuffers.h"
#include "gl_renderstate.h"
#include "gl_renderbuffers.h"
#include "gl/shaders/gl_shaderprogram.h"
#include "hw_vrmodes.h"
#include "flatvertices.h"
#include "hwrenderer/scene/hw_skydome.h"
#include "hwrenderer/scene/hw_fakeflat.h"
#include "gl/textures/gl_samplers.h"
#include "gl_samplers.h"
#include "hw_lightbuffer.h"
#include "hwrenderer/data/hw_viewpointbuffer.h"
#include "r_videoscale.h"
#include "r_data/models/models.h"
#include "gl/renderer/gl_postprocessstate.h"
#include "gl/system/gl_buffers.h"
#include "gl_postprocessstate.h"
#include "gl_buffers.h"
#include "texturemanager.h"
EXTERN_CVAR(Int, screenblocks)
@ -95,8 +103,6 @@ void FGLRenderer::Initialize(int width, int height)
mShadowMapShader = new FShadowMapShader();
// needed for the core profile, because someone decided it was a good idea to remove the default VAO.
glGenQueries(1, &PortalQueryObject);
glGenVertexArrays(1, &mVAOID);
glBindVertexArray(mVAOID);
FGLDebug::LabelObject(GL_VERTEX_ARRAY, mVAOID, "FGLRenderer.mVAOID");
@ -120,8 +126,6 @@ FGLRenderer::~FGLRenderer()
glBindVertexArray(0);
glDeleteVertexArrays(1, &mVAOID);
}
if (PortalQueryObject != 0) glDeleteQueries(1, &PortalQueryObject);
if (mBuffers) delete mBuffers;
if (mSaveBuffers) delete mSaveBuffers;
if (mPresentShader) delete mPresentShader;
@ -160,44 +164,6 @@ void FGLRenderer::EndOffscreen()
glBindFramebuffer(GL_FRAMEBUFFER, mOldFBID);
}
//===========================================================================
//
//
//
//===========================================================================
void FGLRenderer::UpdateShadowMap()
{
if (screen->mShadowMap.PerformUpdate())
{
FGLDebug::PushGroup("ShadowMap");
FGLPostProcessState savedState;
static_cast<GLDataBuffer*>(screen->mShadowMap.mLightList)->BindBase();
static_cast<GLDataBuffer*>(screen->mShadowMap.mNodesBuffer)->BindBase();
static_cast<GLDataBuffer*>(screen->mShadowMap.mLinesBuffer)->BindBase();
mBuffers->BindShadowMapFB();
mShadowMapShader->Bind();
mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality;
mShadowMapShader->Uniforms->NodesCount = screen->mShadowMap.NodesCount();
mShadowMapShader->Uniforms.SetData();
static_cast<GLDataBuffer*>(mShadowMapShader->Uniforms.GetBuffer())->BindBase();
glViewport(0, 0, gl_shadowmap_quality, 1024);
RenderScreenQuad();
const auto &viewport = screen->mScreenViewport;
glViewport(viewport.left, viewport.top, viewport.width, viewport.height);
mBuffers->BindShadowMapTexture(16);
FGLDebug::PopGroup();
screen->mShadowMap.FinishUpdate();
}
}
//===========================================================================
//
//
@ -207,14 +173,10 @@ void FGLRenderer::UpdateShadowMap()
void FGLRenderer::BindToFrameBuffer(FTexture *tex)
{
auto BaseLayer = static_cast<FHardwareTexture*>(tex->GetHardwareTexture(0, 0));
if (BaseLayer == nullptr)
{
// must create the hardware texture first
BaseLayer->BindOrCreate(tex, 0, 0, 0, 0);
FHardwareTexture::Unbind(0);
gl_RenderState.ClearLastMaterial();
}
// must create the hardware texture first
BaseLayer->BindOrCreate(tex, 0, 0, 0, 0);
FHardwareTexture::Unbind(0);
gl_RenderState.ClearLastMaterial();
BaseLayer->BindToFrameBuffer(tex->GetWidth(), tex->GetHeight());
}