mirror of
https://github.com/ZDoom/Raze.git
synced 2025-05-30 08:51:08 +00:00
- added the GL framebuffer class.
Everything compiles again but obviously no init code will run for now.
This commit is contained in:
parent
6b475417dc
commit
a1f7f0cc30
26 changed files with 8946 additions and 8903 deletions
371
source/common/rendering/gl/system/gl_debug.cpp
Normal file
371
source/common/rendering/gl/system/gl_debug.cpp
Normal file
|
@ -0,0 +1,371 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2016 Magnus Norddahl
|
||||
// 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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
/*
|
||||
** gl_debig.cpp
|
||||
** OpenGL debugging support functions
|
||||
**
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "gl_load/gl_system.h"
|
||||
#include "gl/system/gl_debug.h"
|
||||
#include "stats.h"
|
||||
#include "printf.h"
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
CUSTOM_CVAR(Int, gl_debug_level, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
if (!OpenGLRenderer::FGLDebug::HasDebugApi())
|
||||
{
|
||||
Printf("No OpenGL debug support detected.\n");
|
||||
}
|
||||
}
|
||||
|
||||
CVAR(Bool, gl_debug_breakpoint, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
|
||||
bool gpuStatActive;
|
||||
bool keepGpuStatActive;
|
||||
FString gpuStatOutput;
|
||||
|
||||
namespace OpenGLRenderer
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
std::vector<std::pair<FString, GLuint>> timeElapsedQueries;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Updates OpenGL debugging state
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::Update()
|
||||
{
|
||||
gpuStatOutput = "";
|
||||
for (auto &query : timeElapsedQueries)
|
||||
{
|
||||
GLuint timeElapsed = 0;
|
||||
glGetQueryObjectuiv(query.second, GL_QUERY_RESULT, &timeElapsed);
|
||||
glDeleteQueries(1, &query.second);
|
||||
|
||||
FString out;
|
||||
out.Format("%s=%04.2f ms\n", query.first.GetChars(), timeElapsed / 1000000.0f);
|
||||
gpuStatOutput += out;
|
||||
}
|
||||
timeElapsedQueries.clear();
|
||||
|
||||
gpuStatActive = keepGpuStatActive;
|
||||
keepGpuStatActive = false;
|
||||
|
||||
if (!HasDebugApi())
|
||||
return;
|
||||
|
||||
SetupBreakpointMode();
|
||||
UpdateLoggingLevel();
|
||||
OutputMessageLog();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Label objects so they are referenced by name in debug messages and in
|
||||
// OpenGL debuggers (renderdoc)
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::LabelObject(GLenum type, GLuint handle, const char *name)
|
||||
{
|
||||
if (HasDebugApi() && gl_debug_level != 0)
|
||||
{
|
||||
glObjectLabel(type, handle, -1, name);
|
||||
}
|
||||
}
|
||||
|
||||
void FGLDebug::LabelObjectPtr(void *ptr, const char *name)
|
||||
{
|
||||
if (HasDebugApi() && gl_debug_level != 0)
|
||||
{
|
||||
glObjectPtrLabel(ptr, -1, name);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Marks which render pass/group is executing commands so that debuggers can
|
||||
// display this information
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::PushGroup(const FString &name)
|
||||
{
|
||||
if (HasDebugApi() && gl_debug_level != 0)
|
||||
{
|
||||
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, (GLsizei)name.Len(), name.GetChars());
|
||||
}
|
||||
|
||||
if (gpuStatActive)
|
||||
{
|
||||
GLuint queryHandle = 0;
|
||||
glGenQueries(1, &queryHandle);
|
||||
glBeginQuery(GL_TIME_ELAPSED, queryHandle);
|
||||
timeElapsedQueries.push_back({ name, queryHandle });
|
||||
}
|
||||
}
|
||||
|
||||
void FGLDebug::PopGroup()
|
||||
{
|
||||
if (HasDebugApi() && gl_debug_level != 0)
|
||||
{
|
||||
glPopDebugGroup();
|
||||
}
|
||||
|
||||
if (gpuStatActive)
|
||||
{
|
||||
glEndQuery(GL_TIME_ELAPSED);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Turns on synchronous debugging on and off based on gl_debug_breakpoint
|
||||
//
|
||||
// Allows getting the debugger to break exactly at the OpenGL function emitting
|
||||
// a message.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::SetupBreakpointMode()
|
||||
{
|
||||
if (mBreakpointMode != gl_debug_breakpoint)
|
||||
{
|
||||
if (gl_debug_breakpoint)
|
||||
{
|
||||
glDebugMessageCallback(&FGLDebug::DebugCallback, this);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDebugMessageCallback(nullptr, nullptr);
|
||||
glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
}
|
||||
mBreakpointMode = gl_debug_breakpoint;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Tells OpenGL which debug messages we are interested in
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::UpdateLoggingLevel()
|
||||
{
|
||||
const GLenum level = gl_debug_level;
|
||||
if (level != mCurrentLevel)
|
||||
{
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, level > 0);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, level > 1);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, nullptr, level > 2);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, level > 3);
|
||||
mCurrentLevel = level;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The log may already contain entries for a debug level we are no longer
|
||||
// interested in..
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool FGLDebug::IsFilteredByDebugLevel(GLenum severity)
|
||||
{
|
||||
int severityLevel = 0;
|
||||
switch (severity)
|
||||
{
|
||||
case GL_DEBUG_SEVERITY_HIGH: severityLevel = 1; break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM: severityLevel = 2; break;
|
||||
case GL_DEBUG_SEVERITY_LOW: severityLevel = 3; break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION: severityLevel = 4; break;
|
||||
}
|
||||
return severityLevel > (int)gl_debug_level;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Prints all logged messages to the console
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::OutputMessageLog()
|
||||
{
|
||||
if (mCurrentLevel <= 0)
|
||||
return;
|
||||
|
||||
GLint maxDebugMessageLength = 0;
|
||||
glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH, &maxDebugMessageLength);
|
||||
|
||||
const int maxMessages = 50;
|
||||
const int messageLogSize = maxMessages * maxDebugMessageLength;
|
||||
|
||||
TArray<GLenum> sources, types, severities;
|
||||
TArray<GLuint> ids;
|
||||
TArray<GLsizei> lengths;
|
||||
TArray<GLchar> messageLog;
|
||||
|
||||
sources.Resize(maxMessages);
|
||||
types.Resize(maxMessages);
|
||||
severities.Resize(maxMessages);
|
||||
ids.Resize(maxMessages);
|
||||
lengths.Resize(maxMessages);
|
||||
messageLog.Resize(messageLogSize);
|
||||
|
||||
while (true)
|
||||
{
|
||||
GLuint numMessages = glGetDebugMessageLog(maxMessages, messageLogSize, &sources[0], &types[0], &ids[0], &severities[0], &lengths[0], &messageLog[0]);
|
||||
if (numMessages <= 0) break;
|
||||
|
||||
GLsizei offset = 0;
|
||||
for (GLuint i = 0; i < numMessages; i++)
|
||||
{
|
||||
if (!IsFilteredByDebugLevel(severities[i]))
|
||||
PrintMessage(sources[i], types[i], ids[i], severities[i], lengths[i], &messageLog[offset]);
|
||||
offset += lengths[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Print a single message to the console
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::PrintMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message)
|
||||
{
|
||||
if (type == GL_DEBUG_TYPE_PUSH_GROUP || type == GL_DEBUG_TYPE_POP_GROUP)
|
||||
return;
|
||||
|
||||
const int maxMessages = 50;
|
||||
|
||||
static int messagesPrinted = 0;
|
||||
if (messagesPrinted > maxMessages)
|
||||
return;
|
||||
|
||||
FString msg(message, length);
|
||||
|
||||
static std::set<std::string> seenMessages;
|
||||
bool alreadySeen = !seenMessages.insert(msg.GetChars()).second;
|
||||
if (alreadySeen)
|
||||
return;
|
||||
|
||||
messagesPrinted++;
|
||||
if (messagesPrinted == maxMessages)
|
||||
{
|
||||
Printf("Max OpenGL debug messages reached. Suppressing further output.\n");
|
||||
}
|
||||
else if (messagesPrinted < maxMessages)
|
||||
{
|
||||
FString sourceStr = SourceToString(source);
|
||||
FString typeStr = TypeToString(type);
|
||||
FString severityStr = SeverityToString(severity);
|
||||
if (type != GL_DEBUG_TYPE_OTHER)
|
||||
Printf("[%s] %s, %s: %s\n", sourceStr.GetChars(), severityStr.GetChars(), typeStr.GetChars(), msg.GetChars());
|
||||
else
|
||||
Printf("[%s] %s: %s\n", sourceStr.GetChars(), severityStr.GetChars(), msg.GetChars());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// OpenGL callback function used when synchronous debugging is enabled
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLDebug::DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
|
||||
{
|
||||
if (IsFilteredByDebugLevel(severity))
|
||||
return;
|
||||
|
||||
PrintMessage(source, type, id, severity, length, message);
|
||||
assert(severity == GL_DEBUG_SEVERITY_NOTIFICATION);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Enum to string helpers
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
FString FGLDebug::SourceToString(GLenum source)
|
||||
{
|
||||
FString s;
|
||||
switch (source)
|
||||
{
|
||||
case GL_DEBUG_SOURCE_API: s = "api"; break;
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: s = "window system"; break;
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER: s = "shader compiler"; break;
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY: s = "third party"; break;
|
||||
case GL_DEBUG_SOURCE_APPLICATION: s = "application"; break;
|
||||
case GL_DEBUG_SOURCE_OTHER: s = "other"; break;
|
||||
default: s.Format("%d", (int)source);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
FString FGLDebug::TypeToString(GLenum type)
|
||||
{
|
||||
FString s;
|
||||
switch (type)
|
||||
{
|
||||
case GL_DEBUG_TYPE_ERROR: s = "error"; break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: s = "deprecated"; break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: s = "undefined"; break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY: s = "portability"; break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE: s = "performance"; break;
|
||||
case GL_DEBUG_TYPE_MARKER: s = "marker"; break;
|
||||
case GL_DEBUG_TYPE_PUSH_GROUP: s = "push group"; break;
|
||||
case GL_DEBUG_TYPE_POP_GROUP: s = "pop group"; break;
|
||||
case GL_DEBUG_TYPE_OTHER: s = "other"; break;
|
||||
default: s.Format("%d", (int)type);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
FString FGLDebug::SeverityToString(GLenum severity)
|
||||
{
|
||||
FString s;
|
||||
switch (severity)
|
||||
{
|
||||
case GL_DEBUG_SEVERITY_LOW: s = "low severity"; break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM: s = "medium severity"; break;
|
||||
case GL_DEBUG_SEVERITY_HIGH: s = "high severity"; break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION: s = "notification"; break;
|
||||
default: s.Format("%d", (int)severity);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
44
source/common/rendering/gl/system/gl_debug.h
Normal file
44
source/common/rendering/gl/system/gl_debug.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#ifndef __GL_DEBUG_H
|
||||
#define __GL_DEBUG_H
|
||||
|
||||
#include <string.h>
|
||||
#include "gl_load/gl_interface.h"
|
||||
#include "c_cvars.h"
|
||||
#include "v_video.h"
|
||||
|
||||
namespace OpenGLRenderer
|
||||
{
|
||||
|
||||
class FGLDebug
|
||||
{
|
||||
public:
|
||||
void Update();
|
||||
|
||||
static void LabelObject(GLenum type, GLuint handle, const char *name);
|
||||
static void LabelObjectPtr(void *ptr, const char *name);
|
||||
|
||||
static void PushGroup(const FString &name);
|
||||
static void PopGroup();
|
||||
|
||||
static bool HasDebugApi() { return (gl.flags & RFL_DEBUG) != 0; }
|
||||
|
||||
private:
|
||||
void SetupBreakpointMode();
|
||||
void UpdateLoggingLevel();
|
||||
void OutputMessageLog();
|
||||
|
||||
static bool IsFilteredByDebugLevel(GLenum severity);
|
||||
static void PrintMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message);
|
||||
|
||||
static void APIENTRY DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam);
|
||||
|
||||
static FString SourceToString(GLenum source);
|
||||
static FString TypeToString(GLenum type);
|
||||
static FString SeverityToString(GLenum severity);
|
||||
|
||||
GLenum mCurrentLevel = 0;
|
||||
bool mBreakpointMode = false;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
410
source/common/rendering/gl/system/gl_framebuffer.cpp
Normal file
410
source/common/rendering/gl/system/gl_framebuffer.cpp
Normal file
|
@ -0,0 +1,410 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2010-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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
/*
|
||||
** gl_framebuffer.cpp
|
||||
** Implementation of the non-hardware specific parts of the
|
||||
** OpenGL frame buffer
|
||||
**
|
||||
*/
|
||||
|
||||
#include "gl_load/gl_system.h"
|
||||
#include "v_video.h"
|
||||
#include "m_png.h"
|
||||
#include "printf.h"
|
||||
#include "templates.h"
|
||||
|
||||
#include "gl_load/gl_interface.h"
|
||||
#include "gl/system/gl_framebuffer.h"
|
||||
/*
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/renderer/gl_renderbuffers.h"
|
||||
#include "gl/textures/gl_samplers.h"
|
||||
#include "hwrenderer/utility/hw_clock.h"
|
||||
#include "hwrenderer/utility/hw_vrmodes.h"
|
||||
#include "hwrenderer/models/hw_models.h"
|
||||
#include "hwrenderer/scene/hw_skydome.h"
|
||||
#include "hwrenderer/data/hw_viewpointbuffer.h"
|
||||
#include "hwrenderer/dynlights/hw_lightbuffer.h"
|
||||
#include "gl/shaders/gl_shaderprogram.h"
|
||||
*/
|
||||
#include "gl_debug.h"
|
||||
#include "r_videoscale.h"
|
||||
//#include "gl_buffers.h"
|
||||
|
||||
//#include "hwrenderer/data/flatvertices.h"
|
||||
|
||||
EXTERN_CVAR (Bool, vid_vsync)
|
||||
EXTERN_CVAR(Bool, r_drawvoxels)
|
||||
EXTERN_CVAR(Int, gl_tonemap)
|
||||
EXTERN_CVAR(Bool, gl_texture_usehires)
|
||||
|
||||
void gl_LoadExtensions();
|
||||
void gl_PrintStartupLog();
|
||||
//void Draw2D(F2DDrawer *drawer, FRenderState &state);
|
||||
|
||||
extern bool vid_hdr_active;
|
||||
|
||||
namespace OpenGLRenderer
|
||||
{
|
||||
#ifdef IMPLEMENT_IT
|
||||
FGLRenderer *GLRenderer;
|
||||
#endif
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, bool fullscreen) :
|
||||
Super(hMonitor, fullscreen)
|
||||
{
|
||||
// SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver.
|
||||
// If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed!
|
||||
Super::SetVSync(vid_vsync);
|
||||
|
||||
#ifdef IMPLEMENT_IT
|
||||
// Make sure all global variables tracking OpenGL context state are reset..
|
||||
FHardwareTexture::InitGlobalState();
|
||||
gl_RenderState.Reset();
|
||||
|
||||
GLRenderer = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
OpenGLFrameBuffer::~OpenGLFrameBuffer()
|
||||
{
|
||||
#ifdef IMPLEMENT_IT
|
||||
PPResource::ResetAll();
|
||||
|
||||
if (mVertexData != nullptr) delete mVertexData;
|
||||
if (mSkyData != nullptr) delete mSkyData;
|
||||
if (mViewpoints != nullptr) delete mViewpoints;
|
||||
if (mLights != nullptr) delete mLights;
|
||||
mShadowMap.Reset();
|
||||
|
||||
if (GLRenderer)
|
||||
{
|
||||
delete GLRenderer;
|
||||
GLRenderer = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Initializes the GL renderer
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::InitializeState()
|
||||
{
|
||||
static bool first=true;
|
||||
|
||||
if (first)
|
||||
{
|
||||
if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
|
||||
{
|
||||
I_FatalError("Failed to load OpenGL functions.");
|
||||
}
|
||||
}
|
||||
|
||||
gl_LoadExtensions();
|
||||
|
||||
// Move some state to the framebuffer object for easier access.
|
||||
hwcaps = gl.flags;
|
||||
glslversion = gl.glslversion;
|
||||
uniformblockalignment = gl.uniformblockalignment;
|
||||
maxuniformblock = gl.maxuniformblock;
|
||||
vendorstring = gl.vendorstring;
|
||||
|
||||
if (first)
|
||||
{
|
||||
first=false;
|
||||
gl_PrintStartupLog();
|
||||
}
|
||||
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glEnable(GL_DITHER);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glEnable(GL_POLYGON_OFFSET_LINE);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_CLAMP);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearDepth(1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
SetViewportRects(nullptr);
|
||||
|
||||
#ifdef IMPLEMENT_IT
|
||||
mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight());
|
||||
mSkyData = new FSkyVertexBuffer;
|
||||
mViewpoints = new HWViewpointBuffer;
|
||||
mLights = new FLightBuffer();
|
||||
|
||||
GLRenderer = new FGLRenderer(this);
|
||||
GLRenderer->Initialize(GetWidth(), GetHeight());
|
||||
|
||||
static_cast<GLDataBuffer*>(mLights->GetBuffer())->BindBase();
|
||||
#endif
|
||||
|
||||
mDebug = std::make_shared<FGLDebug>();
|
||||
mDebug->Update();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Updates the screen
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::Update()
|
||||
{
|
||||
#ifdef IMPLEMENT_IT
|
||||
twoD.Reset();
|
||||
Flush3D.Reset();
|
||||
|
||||
Flush3D.Clock();
|
||||
GLRenderer->Flush();
|
||||
Flush3D.Unclock();
|
||||
#endif
|
||||
|
||||
Swap();
|
||||
Super::Update();
|
||||
}
|
||||
|
||||
|
||||
const char* OpenGLFrameBuffer::DeviceName() const
|
||||
{
|
||||
return gl.modelstring;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Swap the buffers
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
CVAR(Bool, gl_finishbeforeswap, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
||||
|
||||
void OpenGLFrameBuffer::Swap()
|
||||
{
|
||||
bool swapbefore = gl_finishbeforeswap && camtexcount == 0;
|
||||
//Finish.Reset();
|
||||
//Finish.Clock();
|
||||
if (swapbefore) glFinish();
|
||||
FPSLimit();
|
||||
SwapBuffers();
|
||||
if (!swapbefore) glFinish();
|
||||
//Finish.Unclock();
|
||||
camtexcount = 0;
|
||||
//FHardwareTexture::UnbindAll();
|
||||
mDebug->Update();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Enable/disable vertical sync
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::SetVSync(bool vsync)
|
||||
{
|
||||
// Switch to the default frame buffer because some drivers associate the vsync state with the bound FB object.
|
||||
GLint oldDrawFramebufferBinding = 0, oldReadFramebufferBinding = 0;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDrawFramebufferBinding);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldReadFramebufferBinding);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
|
||||
Super::SetVSync(vsync);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDrawFramebufferBinding);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadFramebufferBinding);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::CleanForRestart()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef IMPLEMENT_IT
|
||||
void OpenGLFrameBuffer::SetTextureFilterMode()
|
||||
{
|
||||
//if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode();
|
||||
}
|
||||
|
||||
IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture()
|
||||
{
|
||||
return nullptr;// new FHardwareTexture(true/*tex->bNoCompress*/);
|
||||
}
|
||||
|
||||
void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
||||
{
|
||||
auto tex = mat->tex;
|
||||
if (tex->isSWCanvas()) return;
|
||||
|
||||
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
|
||||
int flags = mat->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled()) ? CTF_CheckHires : 0;
|
||||
int numLayers = mat->GetLayers();
|
||||
auto base = static_cast<FHardwareTexture*>(mat->GetLayer(0, translation));
|
||||
|
||||
if (base->BindOrCreate(tex, 0, CLAMP_NONE, translation, flags))
|
||||
{
|
||||
for (int i = 1; i < numLayers; i++)
|
||||
{
|
||||
FTexture *layer;
|
||||
auto systex = static_cast<FHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
||||
systex->BindOrCreate(layer, i, CLAMP_NONE, 0, mat->isExpanded() ? CTF_Expand : 0);
|
||||
}
|
||||
}
|
||||
// unbind everything.
|
||||
FHardwareTexture::UnbindAll();
|
||||
}
|
||||
|
||||
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
|
||||
{
|
||||
return new FHWModelRenderer(nullptr, gl_RenderState, mli);
|
||||
}
|
||||
|
||||
IVertexBuffer *OpenGLFrameBuffer::CreateVertexBuffer()
|
||||
{
|
||||
return new GLVertexBuffer;
|
||||
}
|
||||
|
||||
IIndexBuffer *OpenGLFrameBuffer::CreateIndexBuffer()
|
||||
{
|
||||
return new GLIndexBuffer;
|
||||
}
|
||||
|
||||
IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize)
|
||||
{
|
||||
return new GLDataBuffer(bindingpoint, ssbo);
|
||||
}
|
||||
|
||||
void OpenGLFrameBuffer::TextureFilterChanged()
|
||||
{
|
||||
if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode();
|
||||
}
|
||||
|
||||
void OpenGLFrameBuffer::BlurScene(float amount)
|
||||
{
|
||||
GLRenderer->BlurScene(amount);
|
||||
}
|
||||
|
||||
void OpenGLFrameBuffer::SetViewportRects(IntRect *bounds)
|
||||
{
|
||||
Super::SetViewportRects(bounds);
|
||||
if (!bounds)
|
||||
{
|
||||
auto vrmode = VRMode::GetVRMode(true);
|
||||
vrmode->AdjustViewport(this);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::BeginFrame()
|
||||
{
|
||||
SetViewportRects(nullptr);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Takes a screenshot
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
TArray<uint8_t> OpenGLFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma)
|
||||
{
|
||||
const auto &viewport = mOutputLetterbox;
|
||||
|
||||
// Grab what is in the back buffer.
|
||||
// We cannot rely on SCREENWIDTH/HEIGHT here because the output may have been scaled.
|
||||
TArray<uint8_t> pixels;
|
||||
pixels.Resize(viewport.width * viewport.height * 3);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(viewport.left, viewport.top, viewport.width, viewport.height, GL_RGB, GL_UNSIGNED_BYTE, &pixels[0]);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
|
||||
// Copy to screenshot buffer:
|
||||
int w = SCREENWIDTH;
|
||||
int h = SCREENHEIGHT;
|
||||
|
||||
TArray<uint8_t> ScreenshotBuffer(w * h * 3, true);
|
||||
|
||||
float rcpWidth = 1.0f / w;
|
||||
float rcpHeight = 1.0f / h;
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
float u = (x + 0.5f) * rcpWidth;
|
||||
float v = (y + 0.5f) * rcpHeight;
|
||||
int sx = u * viewport.width;
|
||||
int sy = v * viewport.height;
|
||||
int sindex = (sx + sy * viewport.width) * 3;
|
||||
int dindex = (x + (h - y - 1) * w) * 3;
|
||||
ScreenshotBuffer[dindex] = pixels[sindex];
|
||||
ScreenshotBuffer[dindex + 1] = pixels[sindex + 1];
|
||||
ScreenshotBuffer[dindex + 2] = pixels[sindex + 2];
|
||||
}
|
||||
}
|
||||
|
||||
pitch = w * 3;
|
||||
color_type = SS_RGB;
|
||||
|
||||
// Screenshot should not use gamma correction if it was already applied to rendered image
|
||||
gamma = 1;
|
||||
return ScreenshotBuffer;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// 2D drawing
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D)
|
||||
{
|
||||
//GLRenderer->PostProcessScene(fixedcm, afterBloomDrawEndScene2D);
|
||||
}
|
||||
|
||||
|
||||
}
|
66
source/common/rendering/gl/system/gl_framebuffer.h
Normal file
66
source/common/rendering/gl/system/gl_framebuffer.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef __GL_FRAMEBUFFER
|
||||
#define __GL_FRAMEBUFFER
|
||||
|
||||
#include "gl_sysfb.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace OpenGLRenderer
|
||||
{
|
||||
|
||||
class FHardwareTexture;
|
||||
class FGLDebug;
|
||||
|
||||
class OpenGLFrameBuffer : public SystemGLFrameBuffer
|
||||
{
|
||||
typedef SystemGLFrameBuffer Super;
|
||||
|
||||
public:
|
||||
|
||||
explicit OpenGLFrameBuffer() {}
|
||||
OpenGLFrameBuffer(void *hMonitor, bool fullscreen) ;
|
||||
~OpenGLFrameBuffer();
|
||||
|
||||
void InitializeState() override;
|
||||
void Update() override;
|
||||
|
||||
void CleanForRestart() override;
|
||||
const char* DeviceName() const override;
|
||||
#ifdef IMPLEMENT_IT
|
||||
void SetTextureFilterMode() override;
|
||||
IHardwareTexture *CreateHardwareTexture() override;
|
||||
void PrecacheMaterial(FMaterial *mat, int translation) override;
|
||||
FModelRenderer *CreateModelRenderer(int mli) override;
|
||||
void TextureFilterChanged() override;
|
||||
#endif
|
||||
void BeginFrame() override;
|
||||
#ifdef IMPLEMENT_IT
|
||||
void SetViewportRects(IntRect *bounds) override;
|
||||
void BlurScene(float amount) override;
|
||||
IVertexBuffer *CreateVertexBuffer() override;
|
||||
IIndexBuffer *CreateIndexBuffer() override;
|
||||
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override;
|
||||
#endif
|
||||
|
||||
// Retrieves a buffer containing image data for a screenshot.
|
||||
// Hint: Pitch can be negative for upside-down images, in which case buffer
|
||||
// points to the last row in the buffer, which will be the first row output.
|
||||
virtual TArray<uint8_t> GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) override;
|
||||
|
||||
void Swap();
|
||||
bool IsHWGammaActive() const { return HWGammaActive; }
|
||||
|
||||
void SetVSync(bool vsync);
|
||||
|
||||
//void Draw2D() override;
|
||||
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override;
|
||||
|
||||
bool HWGammaActive = false; // Are we using hardware or software gamma?
|
||||
std::shared_ptr<FGLDebug> mDebug; // Debug API
|
||||
|
||||
int camtexcount = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //__GL_FRAMEBUFFER
|
Loading…
Add table
Add a link
Reference in a new issue