- made FHardwareTexture inherit from an abstract interface to remove all GL dependencies from gl_material.cpp.

This commit is contained in:
Christoph Oelckers 2018-04-24 23:06:34 +02:00
parent f9a82e66e4
commit 0675315b41
8 changed files with 34 additions and 33 deletions

View file

@ -29,7 +29,7 @@
#include "gl/system/gl_debug.h"
#include "gl/data/gl_vertexbuffer.h"
#include "gl/shaders/gl_shader.h"
#include "gl/textures/gl_hwtexture.h"
#include "hwrenderer/textures/hw_ihwtexture.h"
#include "gl_swscene.h"
#include "w_wad.h"
#include "d_player.h"

View file

@ -388,11 +388,17 @@ void OpenGLFrameBuffer::SetTextureFilterMode()
if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode();
}
FHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(FTexture *tex)
IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(FTexture *tex)
{
return new FHardwareTexture(tex->bNoCompress);
}
void OpenGLFrameBuffer::UnbindTexUnit(int no)
{
FHardwareTexture::Unbind(no);
}
void OpenGLFrameBuffer::UpdatePalette()
{

View file

@ -43,7 +43,8 @@ public:
void WriteSavePic(player_t *player, FileWriter *file, int width, int height) override;
void RenderView(player_t *player) override;
void SetTextureFilterMode() override;
FHardwareTexture *CreateHardwareTexture(FTexture *tex) override;
IHardwareTexture *CreateHardwareTexture(FTexture *tex) override;
void UnbindTexUnit(int no) override;
// Retrieves a buffer containing image data for a screenshot.
// Hint: Pitch can be negative for upside-down images, in which case buffer

View file

@ -11,10 +11,10 @@
#include "tarray.h"
#include "gl/system/gl_interface.h"
#include "hwrenderer/textures/hw_ihwtexture.h"
class FCanvasTexture;
class AActor;
typedef TMap<int, bool> SpriteHits;
// For error catching while changing parameters.
@ -23,7 +23,7 @@ enum EInvalid
Invalid = 0
};
class FHardwareTexture
class FHardwareTexture : public IHardwareTexture
{
public:
enum

View file

@ -20,23 +20,15 @@
//--------------------------------------------------------------------------
//
#include "gl/system/gl_system.h"
#include "w_wad.h"
#include "m_png.h"
#include "sbar.h"
#include "stats.h"
#include "r_utility.h"
#include "hwrenderer/textures/hw_ihwtexture.h"
#include "gl/system/gl_interface.h"
#include "gl/system/gl_framebuffer.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/textures/gl_hwtexture.h"
#include "gl/textures/gl_material.h"
#include "gl/shaders/gl_shader.h"
#include "gl_material.h"
EXTERN_CVAR(Bool, gl_render_precise)
EXTERN_CVAR(Int, gl_lightmode)
EXTERN_CVAR(Bool, gl_precache)
EXTERN_CVAR(Bool, gl_texture_usehires)
//===========================================================================
@ -95,10 +87,10 @@ float FTexCoordInfo::TextureAdjustWidth() const
if (mWorldPanning)
{
float tscale = fabs(mTempScale.X);
if (tscale == 1.f) return mRenderWidth;
if (tscale == 1.f) return (float)mRenderWidth;
else return mWidth / fabs(tscale);
}
else return mWidth;
else return (float)mWidth;
}
@ -108,11 +100,11 @@ float FTexCoordInfo::TextureAdjustWidth() const
//
//
//===========================================================================
FHardwareTexture * FMaterial::ValidateSysTexture(FTexture * tex, bool expand)
IHardwareTexture * FMaterial::ValidateSysTexture(FTexture * tex, bool expand)
{
if (tex && tex->UseType!=ETextureType::Null)
{
FHardwareTexture *gltex = tex->gl_info.SystemTexture[expand];
IHardwareTexture *gltex = tex->gl_info.SystemTexture[expand];
if (gltex == nullptr)
{
gltex = tex->gl_info.SystemTexture[expand] = screen->CreateHardwareTexture(tex);
@ -272,8 +264,8 @@ void FMaterial::SetSpriteRect()
auto leftOffset = tex->GetLeftOffsetHW();
auto topOffset = tex->GetTopOffsetHW();
float fxScale = tex->Scale.X;
float fyScale = tex->Scale.Y;
float fxScale = (float)tex->Scale.X;
float fyScale = (float)tex->Scale.Y;
// mSpriteRect is for positioning the sprite in the scene.
mSpriteRect.left = -leftOffset / fxScale;
@ -468,7 +460,7 @@ void FMaterial::Bind(int clampmode, int translation)
// unbind everything from the last texture that's still active
for(int i=maxbound+1; i<=mMaxBound;i++)
{
FHardwareTexture::Unbind(i);
screen->UnbindTexUnit(i);
mMaxBound = maxbound;
}
}
@ -508,12 +500,12 @@ void FMaterial::GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const
if (x == 1.f)
{
tci->mRenderWidth = mRenderWidth;
tci->mScale.X = tex->Scale.X;
tci->mScale.X = (float)tex->Scale.X;
tci->mTempScale.X = 1.f;
}
else
{
float scale_x = x * tex->Scale.X;
float scale_x = x * (float)tex->Scale.X;
tci->mRenderWidth = xs_CeilToInt(mWidth / scale_x);
tci->mScale.X = scale_x;
tci->mTempScale.X = x;
@ -522,12 +514,12 @@ void FMaterial::GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const
if (y == 1.f)
{
tci->mRenderHeight = mRenderHeight;
tci->mScale.Y = tex->Scale.Y;
tci->mScale.Y = (float)tex->Scale.Y;
tci->mTempScale.Y = 1.f;
}
else
{
float scale_y = y * tex->Scale.Y;
float scale_y = y * (float)tex->Scale.Y;
tci->mRenderHeight = xs_CeilToInt(mHeight / scale_y);
tci->mScale.Y = scale_y;
tci->mTempScale.Y = y;
@ -572,7 +564,7 @@ void FMaterial::BindToFrameBuffer()
{
// must create the hardware texture first
mBaseLayer->BindOrCreate(sourcetex, 0, 0, 0, 0);
FHardwareTexture::Unbind(0);
screen->UnbindTexUnit(0);
ClearLastTexture();
}
mBaseLayer->BindToFrameBuffer(mWidth, mHeight);

View file

@ -11,6 +11,7 @@ EXTERN_CVAR(Bool, gl_precache)
struct FRemapTable;
class FTextureShader;
class IHardwareTexture;
enum
{
@ -63,7 +64,7 @@ class FMaterial
static TArray<FMaterial *> mMaterials;
static int mMaxBound;
FHardwareTexture *mBaseLayer;
IHardwareTexture *mBaseLayer;
TArray<FTextureLayer> mTextureLayers;
int mShaderIndex;
@ -80,7 +81,7 @@ class FMaterial
float mSpriteU[2], mSpriteV[2];
FloatRect mSpriteRect;
FHardwareTexture * ValidateSysTexture(FTexture * tex, bool expand);
IHardwareTexture * ValidateSysTexture(FTexture * tex, bool expand);
bool TrimBorders(uint16_t *rect);
public:

View file

@ -117,7 +117,7 @@ class FScanner;
// Texture IDs
class FTextureManager;
class FTerrainTypeArray;
class FHardwareTexture;
class IHardwareTexture;
class FMaterial;
extern int r_spriteadjustSW, r_spriteadjustHW;
@ -484,7 +484,7 @@ public:
struct GLTexInfo
{
FMaterial *Material[2] = { nullptr, nullptr };
FHardwareTexture *SystemTexture[2] = { nullptr, nullptr };
IHardwareTexture *SystemTexture[2] = { nullptr, nullptr };
bool bNoExpand = false;
~GLTexInfo();

View file

@ -280,7 +280,7 @@ public:
class FUniquePalette;
class FHardwareTexture;
class IHardwareTexture;
class FTexture;
// A canvas that represents the actual display. The video code is responsible
@ -353,7 +353,8 @@ public:
// Delete any resources that need to be deleted after restarting with a different IWAD
virtual void CleanForRestart() {}
virtual void SetTextureFilterMode() {}
virtual FHardwareTexture *CreateHardwareTexture(FTexture *tex) { return nullptr; }
virtual IHardwareTexture *CreateHardwareTexture(FTexture *tex) { return nullptr; }
virtual void UnbindTexUnit(int no) {}
// Begin 2D drawing operations.
// Returns true if hardware-accelerated 2D has been entered, false if not.