mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-04-25 08:51:20 +00:00
Updated gles/gles_renderbuffers.cpp TO BE CLEANED UP!
This commit is contained in:
parent
4ac0ec900d
commit
8d572fab17
2 changed files with 714 additions and 885 deletions
|
@ -23,7 +23,6 @@
|
|||
#include "v_video.h"
|
||||
#include "printf.h"
|
||||
#include "hw_cvars.h"
|
||||
#include "gles_debug.h"
|
||||
#include "gles_renderer.h"
|
||||
#include "gles_renderbuffers.h"
|
||||
#include "gles_postprocessstate.h"
|
||||
|
@ -45,7 +44,8 @@ namespace OpenGLESRenderer
|
|||
|
||||
FGLRenderBuffers::FGLRenderBuffers()
|
||||
{
|
||||
glGetIntegerv(GL_MAX_SAMPLES, &mMaxSamples);
|
||||
//glGetIntegerv(GL_MAX_SAMPLES, &mMaxSamples);
|
||||
mMaxSamples = 0;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -190,11 +190,12 @@ void FGLRenderBuffers::CreateScene(int width, int height, int samples, bool need
|
|||
|
||||
if (samples > 1)
|
||||
{
|
||||
/*
|
||||
if (needsSceneTextures)
|
||||
{
|
||||
mSceneMultisampleTex = Create2DMultisampleTexture("SceneMultisample", GL_RGBA16F, width, height, samples, false);
|
||||
mSceneDepthStencilTex = Create2DMultisampleTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height, samples, false);
|
||||
mSceneFogTex = Create2DMultisampleTexture("SceneFog", GL_RGBA8, width, height, samples, false);
|
||||
mSceneMultisampleTex = Create2DMultisampleTexture("SceneMultisample", GL_RGBA, width, height, samples, false);
|
||||
mSceneDepthStencilTex = Create2DMultisampleTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8_OES, width, height, samples, false);
|
||||
mSceneFogTex = Create2DMultisampleTexture("SceneFog", GL_RGBA, width, height, samples, false);
|
||||
mSceneNormalTex = Create2DMultisampleTexture("SceneNormal", GL_RGB10_A2, width, height, samples, false);
|
||||
mSceneFB = CreateFrameBuffer("SceneFB", mSceneMultisampleTex, {}, {}, mSceneDepthStencilTex, true);
|
||||
mSceneDataFB = CreateFrameBuffer("SceneGBufferFB", mSceneMultisampleTex, mSceneFogTex, mSceneNormalTex, mSceneDepthStencilTex, true);
|
||||
|
@ -206,20 +207,21 @@ void FGLRenderBuffers::CreateScene(int width, int height, int samples, bool need
|
|||
mSceneFB = CreateFrameBuffer("SceneFB", mSceneMultisampleBuf, mSceneDepthStencilBuf);
|
||||
mSceneDataFB = CreateFrameBuffer("SceneGBufferFB", mSceneMultisampleBuf, mSceneDepthStencilBuf);
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
if (needsSceneTextures)
|
||||
{
|
||||
mSceneDepthStencilTex = Create2DTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height);
|
||||
mSceneFogTex = Create2DTexture("SceneFog", GL_RGBA8, width, height);
|
||||
mSceneNormalTex = Create2DTexture("SceneNormal", GL_RGB10_A2, width, height);
|
||||
mSceneDepthStencilTex = Create2DTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8_OES, width, height);
|
||||
mSceneFogTex = Create2DTexture("SceneFog", GL_RGBA, width, height);
|
||||
mSceneNormalTex = Create2DTexture("SceneNormal", GL_RGBA, width, height);
|
||||
mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], {}, {}, mSceneDepthStencilTex, false);
|
||||
mSceneDataFB = CreateFrameBuffer("SceneGBufferFB", mPipelineTexture[0], mSceneFogTex, mSceneNormalTex, mSceneDepthStencilTex, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSceneDepthStencilBuf = CreateRenderBuffer("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height);
|
||||
mSceneDepthStencilBuf = CreateRenderBuffer("SceneDepthStencil", GL_DEPTH24_STENCIL8_OES, width, height);
|
||||
mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], mSceneDepthStencilBuf);
|
||||
mSceneDataFB = CreateFrameBuffer("SceneGBufferFB", mPipelineTexture[0], mSceneDepthStencilBuf);
|
||||
}
|
||||
|
@ -239,7 +241,7 @@ void FGLRenderBuffers::CreatePipeline(int width, int height)
|
|||
|
||||
for (int i = 0; i < NumPipelineTextures; i++)
|
||||
{
|
||||
mPipelineTexture[i] = Create2DTexture("PipelineTexture", GL_RGBA16F, width, height);
|
||||
mPipelineTexture[i] = Create2DTexture("PipelineTexture", GL_RGBA, width, height);
|
||||
mPipelineFB[i] = CreateFrameBuffer("PipelineFB", mPipelineTexture[i]);
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +265,7 @@ void FGLRenderBuffers::CreateEyeBuffers(int eye)
|
|||
|
||||
while (mEyeFBs.Size() <= unsigned(eye))
|
||||
{
|
||||
PPGLTexture texture = Create2DTexture("EyeTexture", GL_RGBA16F, mWidth, mHeight);
|
||||
PPGLTexture texture = Create2DTexture("EyeTexture", GL_RGBA, mWidth, mHeight);
|
||||
mEyeTextures.Push(texture);
|
||||
mEyeFBs.Push(CreateFrameBuffer("EyeFB", texture));
|
||||
}
|
||||
|
@ -286,12 +288,13 @@ PPGLTexture FGLRenderBuffers::Create2DTexture(const char *name, GLuint format, i
|
|||
tex.Height = height;
|
||||
glGenTextures(1, &tex.handle);
|
||||
glBindTexture(GL_TEXTURE_2D, tex.handle);
|
||||
FGLDebug::LabelObject(GL_TEXTURE, tex.handle, name);
|
||||
|
||||
GLenum dataformat = 0, datatype = 0;
|
||||
/*
|
||||
switch (format)
|
||||
{
|
||||
case GL_RGBA8: dataformat = GL_RGBA; datatype = GL_UNSIGNED_BYTE; break;
|
||||
case GL_RGBA: dataformat = GL_RGBA; datatype = GL_UNSIGNED_BYTE; break;
|
||||
|
||||
case GL_RGBA16: dataformat = GL_RGBA; datatype = GL_UNSIGNED_SHORT; break;
|
||||
case GL_RGBA16F: dataformat = GL_RGBA; datatype = GL_FLOAT; break;
|
||||
case GL_RGBA32F: dataformat = GL_RGBA; datatype = GL_FLOAT; break;
|
||||
|
@ -302,10 +305,15 @@ PPGLTexture FGLRenderBuffers::Create2DTexture(const char *name, GLuint format, i
|
|||
case GL_RG16F: dataformat = GL_RG; datatype = GL_FLOAT; break;
|
||||
case GL_RGB10_A2: dataformat = GL_RGBA; datatype = GL_UNSIGNED_INT_10_10_10_2; break;
|
||||
case GL_DEPTH_COMPONENT24: dataformat = GL_DEPTH_COMPONENT; datatype = GL_FLOAT; break;
|
||||
case GL_STENCIL_INDEX8: dataformat = GL_STENCIL_INDEX; datatype = GL_INT; break;
|
||||
case GL_DEPTH24_STENCIL8: dataformat = GL_DEPTH_STENCIL; datatype = GL_UNSIGNED_INT_24_8; break;
|
||||
|
||||
case GL_STENCIL_INDEX8: dataformat = GL_STENCIL_INDEX8_OES; datatype = GL_INT; break;
|
||||
case GL_DEPTH24_STENCIL8_OES: dataformat = GL_DEPTH_STENCIL_OES; datatype = GL_UNSIGNED_INT_24_8; break;
|
||||
default: I_FatalError("Unknown format passed to FGLRenderBuffers.Create2DTexture");
|
||||
}
|
||||
*/
|
||||
format = GL_RGBA;
|
||||
dataformat = GL_RGBA;
|
||||
datatype = GL_UNSIGNED_BYTE;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, dataformat, datatype, data);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
@ -317,7 +325,9 @@ PPGLTexture FGLRenderBuffers::Create2DTexture(const char *name, GLuint format, i
|
|||
|
||||
PPGLTexture FGLRenderBuffers::Create2DMultisampleTexture(const char* name, GLuint format, int width, int height, int samples, bool fixedSampleLocations)
|
||||
{
|
||||
|
||||
PPGLTexture tex;
|
||||
/*
|
||||
tex.Width = width;
|
||||
tex.Height = height;
|
||||
glGenTextures(1, &tex.handle);
|
||||
|
@ -325,6 +335,7 @@ PPGLTexture FGLRenderBuffers::Create2DMultisampleTexture(const char *name, GLuin
|
|||
FGLDebug::LabelObject(GL_TEXTURE, tex.handle, name);
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, format, width, height, fixedSampleLocations);
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
|
||||
*/
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
@ -339,7 +350,7 @@ PPGLRenderBuffer FGLRenderBuffers::CreateRenderBuffer(const char *name, GLuint f
|
|||
PPGLRenderBuffer buf;
|
||||
glGenRenderbuffers(1, &buf.handle);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, buf.handle);
|
||||
FGLDebug::LabelObject(GL_RENDERBUFFER, buf.handle, name);
|
||||
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
|
||||
return buf;
|
||||
}
|
||||
|
@ -348,13 +359,15 @@ PPGLRenderBuffer FGLRenderBuffers::CreateRenderBuffer(const char *name, GLuint f
|
|||
{
|
||||
if (samples <= 1)
|
||||
return CreateRenderBuffer(name, format, width, height);
|
||||
|
||||
/*
|
||||
PPGLRenderBuffer buf;
|
||||
glGenRenderbuffers(1, &buf.handle);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, buf.handle);
|
||||
FGLDebug::LabelObject(GL_RENDERBUFFER, buf.handle, name);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, format, width, height);
|
||||
|
||||
return buf;
|
||||
*/
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -368,7 +381,7 @@ PPGLFrameBuffer FGLRenderBuffers::CreateFrameBuffer(const char *name, PPGLTextur
|
|||
PPGLFrameBuffer fb;
|
||||
glGenFramebuffers(1, &fb.handle);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb.handle);
|
||||
FGLDebug::LabelObject(GL_FRAMEBUFFER, fb.handle, name);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer.handle, 0);
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(false, false);
|
||||
|
@ -380,9 +393,10 @@ PPGLFrameBuffer FGLRenderBuffers::CreateFrameBuffer(const char *name, PPGLTextur
|
|||
PPGLFrameBuffer fb;
|
||||
glGenFramebuffers(1, &fb.handle);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb.handle);
|
||||
FGLDebug::LabelObject(GL_FRAMEBUFFER, fb.handle, name);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer.handle, 0);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(true, true);
|
||||
return fb;
|
||||
|
@ -393,9 +407,10 @@ PPGLFrameBuffer FGLRenderBuffers::CreateFrameBuffer(const char *name, PPGLRender
|
|||
PPGLFrameBuffer fb;
|
||||
glGenFramebuffers(1, &fb.handle);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb.handle);
|
||||
FGLDebug::LabelObject(GL_FRAMEBUFFER, fb.handle, name);
|
||||
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(true, true);
|
||||
return fb;
|
||||
|
@ -406,24 +421,30 @@ PPGLFrameBuffer FGLRenderBuffers::CreateFrameBuffer(const char *name, PPGLTextur
|
|||
PPGLFrameBuffer fb;
|
||||
glGenFramebuffers(1, &fb.handle);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb.handle);
|
||||
FGLDebug::LabelObject(GL_FRAMEBUFFER, fb.handle, name);
|
||||
|
||||
if (multisample)
|
||||
{
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, colorbuffer0.handle, 0);
|
||||
/*
|
||||
if (colorbuffer1.handle != 0)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, colorbuffer1.handle, 0);
|
||||
if (colorbuffer2.handle != 0)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D_MULTISAMPLE, colorbuffer2.handle, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, depthstencil.handle, 0);
|
||||
*/
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer0.handle, 0);
|
||||
/*
|
||||
if (colorbuffer1.handle != 0)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, colorbuffer1.handle, 0);
|
||||
if (colorbuffer2.handle != 0)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, colorbuffer2.handle, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthstencil.handle, 0);
|
||||
*/
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil.handle);
|
||||
}
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(true, true);
|
||||
|
@ -450,14 +471,14 @@ bool FGLRenderBuffers::CheckFrameBufferCompleteness()
|
|||
switch (result)
|
||||
{
|
||||
default: error.AppendFormat("error code %d", (int)result); break;
|
||||
case GL_FRAMEBUFFER_UNDEFINED: error << "GL_FRAMEBUFFER_UNDEFINED"; break;
|
||||
//case GL_FRAMEBUFFER_UNDEFINED: error << "GL_FRAMEBUFFER_UNDEFINED"; break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: error << "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: error << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: error << "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"; break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: error << "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"; break;
|
||||
//case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: error << "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"; break;
|
||||
//case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: error << "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"; break;
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED: error << "GL_FRAMEBUFFER_UNSUPPORTED"; break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: error << "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"; break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: error << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
|
||||
//case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: error << "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"; break;
|
||||
//case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: error << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
|
||||
}
|
||||
Printf("%s\n", error.GetChars());
|
||||
}
|
||||
|
@ -475,13 +496,13 @@ void FGLRenderBuffers::ClearFrameBuffer(bool stencil, bool depth)
|
|||
{
|
||||
GLboolean scissorEnabled;
|
||||
GLint stencilValue;
|
||||
GLdouble depthValue;
|
||||
GLfloat depthValue;
|
||||
glGetBooleanv(GL_SCISSOR_TEST, &scissorEnabled);
|
||||
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencilValue);
|
||||
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &depthValue);
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthValue);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClearDepth(0.0);
|
||||
glClearDepthf(0.0);
|
||||
glClearStencil(0);
|
||||
GLenum flags = GL_COLOR_BUFFER_BIT;
|
||||
if (stencil)
|
||||
|
@ -490,7 +511,7 @@ void FGLRenderBuffers::ClearFrameBuffer(bool stencil, bool depth)
|
|||
flags |= GL_DEPTH_BUFFER_BIT;
|
||||
glClear(flags);
|
||||
glClearStencil(stencilValue);
|
||||
glClearDepth(depthValue);
|
||||
glClearDepthf(depthValue);
|
||||
if (scissorEnabled)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
@ -507,15 +528,20 @@ void FGLRenderBuffers::BlitSceneToTexture()
|
|||
|
||||
if (mSamples <= 1)
|
||||
return;
|
||||
|
||||
/*
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, mSceneFB.handle);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mPipelineFB[mCurrentPipelineTexture].handle);
|
||||
glBlitFramebuffer(0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
|
||||
if ((gl.flags & RFL_INVALIDATE_BUFFER) != 0)
|
||||
{
|
||||
GLenum attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_STENCIL_ATTACHMENT };
|
||||
glInvalidateFramebuffer(GL_READ_FRAMEBUFFER, 2, attachments);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
*/
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -526,30 +552,42 @@ void FGLRenderBuffers::BlitSceneToTexture()
|
|||
|
||||
void FGLRenderBuffers::BlitToEyeTexture(int eye, bool allowInvalidate)
|
||||
{
|
||||
/*
|
||||
CreateEyeBuffers(eye);
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, mPipelineFB[mCurrentPipelineTexture].handle);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mEyeFBs[eye].handle);
|
||||
glBlitFramebuffer(0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
|
||||
if ((gl.flags & RFL_INVALIDATE_BUFFER) != 0 && allowInvalidate)
|
||||
{
|
||||
GLenum attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_STENCIL_ATTACHMENT };
|
||||
glInvalidateFramebuffer(GL_READ_FRAMEBUFFER, 2, attachments);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
*/
|
||||
}
|
||||
|
||||
void FGLRenderBuffers::BlitFromEyeTexture(int eye)
|
||||
{
|
||||
/*
|
||||
if (mEyeFBs.Size() <= unsigned(eye)) return;
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mPipelineFB[mCurrentPipelineTexture].handle);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, mEyeFBs[eye].handle);
|
||||
glBlitFramebuffer(0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
|
||||
if ((gl.flags & RFL_INVALIDATE_BUFFER) != 0)
|
||||
{
|
||||
GLenum attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_STENCIL_ATTACHMENT };
|
||||
glInvalidateFramebuffer(GL_READ_FRAMEBUFFER, 2, attachments);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
*/
|
||||
}
|
||||
|
||||
void FGLRenderBuffers::BindEyeTexture(int eye, int texunit)
|
||||
|
@ -576,7 +614,7 @@ void FGLRenderBuffers::BindDitherTexture(int texunit)
|
|||
};
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texunit);
|
||||
mDitherTexture = Create2DTexture("DitherTexture", GL_R32F, 8, 8, data);
|
||||
mDitherTexture = Create2DTexture("DitherTexture", GL_RGBA, 8, 8, data);
|
||||
}
|
||||
mDitherTexture.Bind(1, GL_NEAREST, GL_REPEAT);
|
||||
}
|
||||
|
@ -620,7 +658,7 @@ void FGLRenderBuffers::CreateShadowMap()
|
|||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &frameBufferBinding);
|
||||
|
||||
mShadowMapTexture = Create2DTexture("ShadowMap", GL_R32F, gl_shadowmap_quality, 1024);
|
||||
//mShadowMapTexture = Create2DTexture("ShadowMap", GL_RGBA, gl_shadomap_quality, 1024);
|
||||
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);
|
||||
|
@ -770,200 +808,6 @@ void FGLRenderBuffers::BindOutputFB()
|
|||
|
||||
bool FGLRenderBuffers::FailedCreate = false;
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates or updates textures used by postprocess effects
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
PPGLTextureBackend *GLPPRenderState::GetGLTexture(PPTexture *texture)
|
||||
{
|
||||
if (!texture->Backend)
|
||||
{
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
auto backend = std::make_unique<PPGLTextureBackend>();
|
||||
|
||||
int glformat;
|
||||
switch (texture->Format)
|
||||
{
|
||||
default:
|
||||
case PixelFormat::Rgba8: glformat = GL_RGBA8; break;
|
||||
case PixelFormat::Rgba16f: glformat = GL_RGBA16F; break;
|
||||
case PixelFormat::R32f: glformat = GL_R32F; break;
|
||||
case PixelFormat::Rg16f: glformat = GL_RG16F; break;
|
||||
case PixelFormat::Rgba16_snorm: glformat = GL_RGBA16_SNORM; break;
|
||||
}
|
||||
|
||||
if (texture->Data)
|
||||
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height, texture->Data.get());
|
||||
else
|
||||
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height);
|
||||
|
||||
texture->Backend = std::move(backend);
|
||||
}
|
||||
return static_cast<PPGLTextureBackend*>(texture->Backend.get());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Compile the shaders declared by post process effects
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FShaderProgram *GLPPRenderState::GetGLShader(PPShader *shader)
|
||||
{
|
||||
if (!shader->Backend)
|
||||
{
|
||||
auto glshader = std::make_unique<FShaderProgram>();
|
||||
|
||||
FString prolog;
|
||||
if (!shader->Uniforms.empty())
|
||||
prolog = UniformBlockDecl::Create("Uniforms", shader->Uniforms, POSTPROCESS_BINDINGPOINT);
|
||||
prolog += shader->Defines;
|
||||
|
||||
glshader->Compile(FShaderProgram::Vertex, shader->VertexShader, "", shader->Version);
|
||||
glshader->Compile(FShaderProgram::Fragment, shader->FragmentShader, prolog, shader->Version);
|
||||
glshader->Link(shader->FragmentShader.GetChars());
|
||||
if (!shader->Uniforms.empty())
|
||||
glshader->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms");
|
||||
|
||||
shader->Backend = std::move(glshader);
|
||||
}
|
||||
return static_cast<FShaderProgram*>(shader->Backend.get());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Renders one post process effect
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void GLPPRenderState::Draw()
|
||||
{
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
// Bind input textures
|
||||
for (unsigned int index = 0; index < Textures.Size(); index++)
|
||||
{
|
||||
savedState.SaveTextureBindings(index + 1);
|
||||
|
||||
const PPTextureInput &input = Textures[index];
|
||||
int filter = (input.Filter == PPFilterMode::Nearest) ? GL_NEAREST : GL_LINEAR;
|
||||
int wrap = (input.Wrap == PPWrapMode::Clamp) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
|
||||
switch (input.Type)
|
||||
{
|
||||
default:
|
||||
case PPTextureType::CurrentPipelineTexture:
|
||||
buffers->BindCurrentTexture(index, filter, wrap);
|
||||
break;
|
||||
|
||||
case PPTextureType::NextPipelineTexture:
|
||||
I_FatalError("PPTextureType::NextPipelineTexture not allowed as input\n");
|
||||
break;
|
||||
|
||||
case PPTextureType::PPTexture:
|
||||
GetGLTexture(input.Texture)->Tex.Bind(index, filter, wrap);
|
||||
break;
|
||||
|
||||
case PPTextureType::SceneColor:
|
||||
buffers->BindSceneColorTexture(index);
|
||||
break;
|
||||
|
||||
case PPTextureType::SceneFog:
|
||||
buffers->BindSceneFogTexture(index);
|
||||
break;
|
||||
|
||||
case PPTextureType::SceneNormal:
|
||||
buffers->BindSceneNormalTexture(index);
|
||||
break;
|
||||
|
||||
case PPTextureType::SceneDepth:
|
||||
buffers->BindSceneDepthTexture(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set render target
|
||||
switch (Output.Type)
|
||||
{
|
||||
default:
|
||||
I_FatalError("Unsupported postprocess output type\n");
|
||||
break;
|
||||
|
||||
case PPTextureType::CurrentPipelineTexture:
|
||||
buffers->BindCurrentFB();
|
||||
break;
|
||||
|
||||
case PPTextureType::NextPipelineTexture:
|
||||
buffers->BindNextFB();
|
||||
break;
|
||||
|
||||
case PPTextureType::PPTexture:
|
||||
if (GetGLTexture(Output.Texture)->FB)
|
||||
GetGLTexture(Output.Texture)->FB.Bind();
|
||||
else
|
||||
GetGLTexture(Output.Texture)->FB = buffers->CreateFrameBuffer("PPTextureFB"/*Output.Texture.GetChars()*/, GetGLTexture(Output.Texture)->Tex);
|
||||
break;
|
||||
|
||||
case PPTextureType::SceneColor:
|
||||
buffers->BindSceneFB(false);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set blend mode
|
||||
if (BlendMode.BlendOp == STYLEOP_Add && BlendMode.SrcAlpha == STYLEALPHA_One && BlendMode.DestAlpha == STYLEALPHA_Zero && BlendMode.Flags == 0)
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
else
|
||||
{
|
||||
// To do: support all the modes
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
if (BlendMode.SrcAlpha == STYLEALPHA_One && BlendMode.DestAlpha == STYLEALPHA_One)
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
else
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
// Setup viewport
|
||||
glViewport(Viewport.left, Viewport.top, Viewport.width, Viewport.height);
|
||||
|
||||
auto shader = GetGLShader(Shader);
|
||||
|
||||
// Set uniforms
|
||||
if (Uniforms.Data.Size() > 0)
|
||||
{
|
||||
if (!shader->Uniforms)
|
||||
shader->Uniforms.reset(screen->CreateDataBuffer(POSTPROCESS_BINDINGPOINT, false, false));
|
||||
shader->Uniforms->SetData(Uniforms.Data.Size(), Uniforms.Data.Data());
|
||||
static_cast<GLDataBuffer*>(shader->Uniforms.get())->BindBase();
|
||||
}
|
||||
|
||||
// Set shader
|
||||
shader->Bind();
|
||||
|
||||
// Draw the screen quad
|
||||
GLRenderer->RenderScreenQuad();
|
||||
|
||||
// Advance to next PP texture if our output was sent there
|
||||
if (Output.Type == PPTextureType::NextPipelineTexture)
|
||||
buffers->NextTexture();
|
||||
|
||||
glViewport(screen->mScreenViewport.left, screen->mScreenViewport.top, screen->mScreenViewport.width, screen->mScreenViewport.height);
|
||||
}
|
||||
|
||||
void GLPPRenderState::PushGroup(const FString &name)
|
||||
{
|
||||
FGLDebug::PushGroup(name.GetChars());
|
||||
}
|
||||
|
||||
void GLPPRenderState::PopGroup()
|
||||
{
|
||||
FGLDebug::PopGroup();
|
||||
}
|
||||
|
||||
|
||||
// Store the current stereo 3D eye buffer, and Load the next one
|
||||
|
@ -978,4 +822,4 @@ int FGLRenderBuffers::NextEye(int eyeCount)
|
|||
return mCurrentEye;
|
||||
}
|
||||
|
||||
} // namespace OpenGLESRenderer
|
||||
} // namespace OpenGLRenderer
|
|
@ -83,21 +83,6 @@ public:
|
|||
|
||||
class FShaderProgram;
|
||||
|
||||
class GLPPRenderState : public PPRenderState
|
||||
{
|
||||
public:
|
||||
GLPPRenderState(FGLRenderBuffers *buffers) : buffers(buffers) { }
|
||||
|
||||
void PushGroup(const FString &name) override;
|
||||
void PopGroup() override;
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
PPGLTextureBackend *GetGLTexture(PPTexture *texture);
|
||||
FShaderProgram *GetGLShader(PPShader *shader);
|
||||
|
||||
FGLRenderBuffers *buffers;
|
||||
};
|
||||
|
||||
class FGLRenderBuffers
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue