diff --git a/source/common/rendering/gl/renderer/gl_renderer.cpp b/source/common/rendering/gl/renderer/gl_renderer.cpp index 7bde82962..1c6bfa7cc 100644 --- a/source/common/rendering/gl/renderer/gl_renderer.cpp +++ b/source/common/rendering/gl/renderer/gl_renderer.cpp @@ -59,6 +59,7 @@ //#include "r_data/models/models.h" #include "gl/renderer/gl_postprocessstate.h" #include "gl/system/gl_buffers.h" +#include "../glbackend/gl_hwtexture.h" #include "build.h" EXTERN_CVAR(Int, screenblocks) @@ -168,20 +169,17 @@ void FGLRenderer::EndOffscreen() // //=========================================================================== -void FGLRenderer::BindToFrameBuffer(FMaterial *mat) +void FGLRenderer::BindToFrameBuffer(FTexture *mat) { -#if 0 - auto BaseLayer = static_cast(mat->GetLayer(0, 0)); + auto pBaseLayer = mat->GetHardwareTexture(0); + auto BaseLayer = pBaseLayer ? *pBaseLayer : nullptr; if (BaseLayer == nullptr) { // must create the hardware texture first - BaseLayer->BindOrCreate(mat->sourcetex, 0, 0, 0, 0); - FHardwareTexture::Unbind(0); - gl_RenderState.ClearLastMaterial(); + BaseLayer->CreateTexture(mat->GetWidth(), mat->GetHeight(), FHardwareTexture::TrueColor, false); } BaseLayer->BindToFrameBuffer(mat->GetWidth(), mat->GetHeight()); -#endif } //=========================================================================== diff --git a/source/common/rendering/gl/renderer/gl_renderer.h b/source/common/rendering/gl/renderer/gl_renderer.h index f588440db..b3a2ec6b6 100644 --- a/source/common/rendering/gl/renderer/gl_renderer.h +++ b/source/common/rendering/gl/renderer/gl_renderer.h @@ -88,20 +88,12 @@ public: bool StartOffscreen(); void EndOffscreen(); - void BindToFrameBuffer(FMaterial *mat); + void BindToFrameBuffer(FTexture* tex); private: void DrawScene(HWDrawInfo *di, int drawmode); - bool QuadStereoCheckInitialRenderContextState(); - void PresentAnaglyph(bool r, bool g, bool b); - void PresentSideBySide(); - void PresentTopBottom(); - void prepareInterleavedPresent(FPresentShaderBase& shader); - void PresentColumnInterleaved(); - void PresentRowInterleaved(); - void PresentCheckerInterleaved(); - void PresentQuadStereo(); + }; diff --git a/source/common/rendering/gl/system/gl_framebuffer.h b/source/common/rendering/gl/system/gl_framebuffer.h index 6f9b0e7c9..aeda7cada 100644 --- a/source/common/rendering/gl/system/gl_framebuffer.h +++ b/source/common/rendering/gl/system/gl_framebuffer.h @@ -8,7 +8,6 @@ namespace OpenGLRenderer { -class FHardwareTexture; class FGLDebug; class OpenGLFrameBuffer : public SystemGLFrameBuffer diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index ba7621719..5bd9e877f 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -139,7 +139,6 @@ class FSerializer; namespace OpenGLRenderer { class FGLRenderState; - class FHardwareTexture; } union FContentIdBuilder diff --git a/source/glbackend/gl_hwtexture.cpp b/source/glbackend/gl_hwtexture.cpp index ae1beebe8..6288c93c9 100644 --- a/source/glbackend/gl_hwtexture.cpp +++ b/source/glbackend/gl_hwtexture.cpp @@ -39,6 +39,7 @@ #include "bitmap.h" #include "c_dispatch.h" #include "printf.h" +#include "gl_interface.h" //#include "compat.h" // Workaround to avoid including the dirty 'compat.h' header. This will hopefully not be needed anymore once the texture format uses something better. @@ -145,6 +146,7 @@ FHardwareTexture::~FHardwareTexture() { alltexturesize -= allocated; if (glTexID != 0) glDeleteTextures(1, &glTexID); + if (glBufferID != 0) glDeleteBuffers(1, &glBufferID); } @@ -153,4 +155,44 @@ unsigned int FHardwareTexture::GetTextureHandle() return glTexID; } +static int GetTexDimension(int value) +{ + if (value > gl.max_texturesize) return gl.max_texturesize; + return value; +} + +//=========================================================================== +// +// Creates a depth buffer for this texture +// +//=========================================================================== + +int FHardwareTexture::GetDepthBuffer(int width, int height) +{ + if (glDepthID == 0) + { + glGenRenderbuffers(1, &glDepthID); + glBindRenderbuffer(GL_RENDERBUFFER, glDepthID); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + return glDepthID; +} + + +//=========================================================================== +// +// Binds this texture's surfaces to the current framrbuffer +// +//=========================================================================== + +void FHardwareTexture::BindToFrameBuffer(int width, int height) +{ + width = GetTexDimension(width); + height = GetTexDimension(height); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glTexID, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer(width, height)); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer(width, height)); +} + diff --git a/source/glbackend/gl_hwtexture.h b/source/glbackend/gl_hwtexture.h index a4c9be5a5..f2db59b54 100644 --- a/source/glbackend/gl_hwtexture.h +++ b/source/glbackend/gl_hwtexture.h @@ -1,7 +1,4 @@ - -#ifndef __GLTEXTURE_H -#define __GLTEXTURE_H - +#pragma once class FBitmap; class FTexture; @@ -22,12 +19,16 @@ private: int mSampler = 0; unsigned int glTexID = 0; + unsigned int glDepthID = 0; // only used by camera textures + unsigned int glBufferID = 0; int internalType = TrueColor; bool mipmapped = true; int mWidth = 0, mHeight = 0; int colorId = 0; uint32_t allocated = 0; + int GetDepthBuffer(int w, int h); + public: ~FHardwareTexture(); @@ -43,9 +44,9 @@ public: int GetSampler() { return mSampler; } void SetSampler(int sampler) { mSampler = sampler; } bool isIndexed() const { return internalType == Indexed; } + void BindToFrameBuffer(int w, int h); friend class FGameTexture; }; -#endif