- basics for hardware rendered camera textures.

This commit is contained in:
Christoph Oelckers 2020-01-19 08:40:03 +01:00
parent c7ffed4867
commit 352c099b5a
6 changed files with 55 additions and 24 deletions

View file

@ -59,6 +59,7 @@
//#include "r_data/models/models.h" //#include "r_data/models/models.h"
#include "gl/renderer/gl_postprocessstate.h" #include "gl/renderer/gl_postprocessstate.h"
#include "gl/system/gl_buffers.h" #include "gl/system/gl_buffers.h"
#include "../glbackend/gl_hwtexture.h"
#include "build.h" #include "build.h"
EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Int, screenblocks)
@ -168,20 +169,17 @@ void FGLRenderer::EndOffscreen()
// //
//=========================================================================== //===========================================================================
void FGLRenderer::BindToFrameBuffer(FMaterial *mat) void FGLRenderer::BindToFrameBuffer(FTexture *mat)
{ {
#if 0 auto pBaseLayer = mat->GetHardwareTexture(0);
auto BaseLayer = static_cast<FHardwareTexture*>(mat->GetLayer(0, 0)); auto BaseLayer = pBaseLayer ? *pBaseLayer : nullptr;
if (BaseLayer == nullptr) if (BaseLayer == nullptr)
{ {
// must create the hardware texture first // must create the hardware texture first
BaseLayer->BindOrCreate(mat->sourcetex, 0, 0, 0, 0); BaseLayer->CreateTexture(mat->GetWidth(), mat->GetHeight(), FHardwareTexture::TrueColor, false);
FHardwareTexture::Unbind(0);
gl_RenderState.ClearLastMaterial();
} }
BaseLayer->BindToFrameBuffer(mat->GetWidth(), mat->GetHeight()); BaseLayer->BindToFrameBuffer(mat->GetWidth(), mat->GetHeight());
#endif
} }
//=========================================================================== //===========================================================================

View file

@ -88,20 +88,12 @@ public:
bool StartOffscreen(); bool StartOffscreen();
void EndOffscreen(); void EndOffscreen();
void BindToFrameBuffer(FMaterial *mat); void BindToFrameBuffer(FTexture* tex);
private: private:
void DrawScene(HWDrawInfo *di, int drawmode); 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();
}; };

View file

@ -8,7 +8,6 @@
namespace OpenGLRenderer namespace OpenGLRenderer
{ {
class FHardwareTexture;
class FGLDebug; class FGLDebug;
class OpenGLFrameBuffer : public SystemGLFrameBuffer class OpenGLFrameBuffer : public SystemGLFrameBuffer

View file

@ -139,7 +139,6 @@ class FSerializer;
namespace OpenGLRenderer namespace OpenGLRenderer
{ {
class FGLRenderState; class FGLRenderState;
class FHardwareTexture;
} }
union FContentIdBuilder union FContentIdBuilder

View file

@ -39,6 +39,7 @@
#include "bitmap.h" #include "bitmap.h"
#include "c_dispatch.h" #include "c_dispatch.h"
#include "printf.h" #include "printf.h"
#include "gl_interface.h"
//#include "compat.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. // 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; alltexturesize -= allocated;
if (glTexID != 0) glDeleteTextures(1, &glTexID); if (glTexID != 0) glDeleteTextures(1, &glTexID);
if (glBufferID != 0) glDeleteBuffers(1, &glBufferID);
} }
@ -153,4 +155,44 @@ unsigned int FHardwareTexture::GetTextureHandle()
return glTexID; 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));
}

View file

@ -1,7 +1,4 @@
#pragma once
#ifndef __GLTEXTURE_H
#define __GLTEXTURE_H
class FBitmap; class FBitmap;
class FTexture; class FTexture;
@ -22,12 +19,16 @@ private:
int mSampler = 0; int mSampler = 0;
unsigned int glTexID = 0; unsigned int glTexID = 0;
unsigned int glDepthID = 0; // only used by camera textures
unsigned int glBufferID = 0;
int internalType = TrueColor; int internalType = TrueColor;
bool mipmapped = true; bool mipmapped = true;
int mWidth = 0, mHeight = 0; int mWidth = 0, mHeight = 0;
int colorId = 0; int colorId = 0;
uint32_t allocated = 0; uint32_t allocated = 0;
int GetDepthBuffer(int w, int h);
public: public:
~FHardwareTexture(); ~FHardwareTexture();
@ -43,9 +44,9 @@ public:
int GetSampler() { return mSampler; } int GetSampler() { return mSampler; }
void SetSampler(int sampler) { mSampler = sampler; } void SetSampler(int sampler) { mSampler = sampler; }
bool isIndexed() const { return internalType == Indexed; } bool isIndexed() const { return internalType == Indexed; }
void BindToFrameBuffer(int w, int h);
friend class FGameTexture; friend class FGameTexture;
}; };
#endif