- 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 "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<FHardwareTexture*>(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
}
//===========================================================================

View file

@ -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();
};

View file

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

View file

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

View file

@ -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));
}

View file

@ -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