- backend sync with Raze.

This commit is contained in:
Christoph Oelckers 2020-05-31 23:37:11 +02:00
parent b60fd4d8bc
commit 4c11b01588
12 changed files with 142 additions and 73 deletions

View file

@ -56,6 +56,7 @@
#include "gl_postprocessstate.h" #include "gl_postprocessstate.h"
#include "v_draw.h" #include "v_draw.h"
#include "printf.h" #include "printf.h"
#include "gl_hwtexture.h"
#include "flatvertices.h" #include "flatvertices.h"
#include "hw_cvars.h" #include "hw_cvars.h"
@ -87,9 +88,9 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, bool fullscreen) :
// SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver. // SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver.
// If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed! // If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed!
Super::SetVSync(vid_vsync); Super::SetVSync(vid_vsync);
FHardwareTexture::InitGlobalState();
// Make sure all global variables tracking OpenGL context state are reset.. // Make sure all global variables tracking OpenGL context state are reset..
FHardwareTexture::InitGlobalState();
gl_RenderState.Reset(); gl_RenderState.Reset();
GLRenderer = nullptr; GLRenderer = nullptr;
@ -215,7 +216,6 @@ void OpenGLFrameBuffer::CopyScreenToBuffer(int width, int height, uint8_t* scr)
//=========================================================================== //===========================================================================
void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect &)> renderFunc) void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect &)> renderFunc)
{ {
GLRenderer->StartOffscreen(); GLRenderer->StartOffscreen();
GLRenderer->BindToFrameBuffer(tex); GLRenderer->BindToFrameBuffer(tex);

View file

@ -42,6 +42,7 @@
#include "hw_cvars.h" #include "hw_cvars.h"
#include "gl_debug.h" #include "gl_debug.h"
#include "gl_renderer.h" #include "gl_renderer.h"
#include "gl_renderstate.h"
#include "gl_samplers.h" #include "gl_samplers.h"
#include "gl_hwtexture.h" #include "gl_hwtexture.h"
@ -302,12 +303,16 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
{ {
int usebright = false; int usebright = false;
bool needmipmap = (clampmode <= CLAMP_XY); bool needmipmap = (clampmode <= CLAMP_XY) && !forcenofilter;
// Bind it to the system. // Bind it to the system.
if (!Bind(texunit, needmipmap)) if (!Bind(texunit, needmipmap))
{ {
if (flags & CTF_Indexed)
{
glTextureBytes = 1;
forcenofilter = true;
}
int w = 0, h = 0; int w = 0, h = 0;
// Create this texture // Create this texture
@ -331,6 +336,7 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
return false; return false;
} }
} }
if (forcenofilter && clampmode <= CLAMP_XY) clampmode += CLAMP_NOFILTER - CLAMP_NONE;
GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255); GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
return true; return true;
} }

View file

@ -93,7 +93,7 @@ FSamplerManager::~FSamplerManager()
void FSamplerManager::UnbindAll() void FSamplerManager::UnbindAll()
{ {
for (int i = 0; i < FHardwareTexture::MAX_TEXTURES; i++) for (int i = 0; i < IHardwareTexture::MAX_TEXTURES; i++)
{ {
glBindSampler(i, 0); glBindSampler(i, 0);
} }

View file

@ -457,11 +457,6 @@ DEFINE_GLOBAL(CleanYfac_1)
DEFINE_GLOBAL(CleanWidth_1) DEFINE_GLOBAL(CleanWidth_1)
DEFINE_GLOBAL(CleanHeight_1) DEFINE_GLOBAL(CleanHeight_1)
IHardwareTexture* CreateHardwareTexture(int numchannels)
{
return screen->CreateHardwareTexture(numchannels);
}
//========================================================================== //==========================================================================
// //
// CVAR transsouls // CVAR transsouls

View file

@ -390,8 +390,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
WriteDescriptors update; WriteDescriptors update;
MaterialLayerInfo *layer; MaterialLayerInfo *layer;
auto systex = static_cast<VkHardwareTexture*>(GetLayer(0, state.mTranslation, &layer)); auto systex = static_cast<VkHardwareTexture*>(GetLayer(0, translation, &layer));
update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, translation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
for (int i = 1; i < numLayers; i++) for (int i = 1; i < numLayers; i++)
{ {
auto systex = static_cast<VkHardwareTexture*>(GetLayer(i, 0, &layer)); auto systex = static_cast<VkHardwareTexture*>(GetLayer(i, 0, &layer));

View file

@ -187,7 +187,7 @@ void FGameTexture::AddAutoMaterials()
void FGameTexture::CreateDefaultBrightmap() void FGameTexture::CreateDefaultBrightmap()
{ {
auto tex = GetTexture(); auto tex = GetTexture();
if (flags & GTexf_BrightmapChecked) if (!(flags & GTexf_BrightmapChecked))
{ {
flags |= GTexf_BrightmapChecked; flags |= GTexf_BrightmapChecked;
// Check for brightmaps // Check for brightmaps

View file

@ -92,6 +92,7 @@ class FGameTexture
FMaterial* Material[4] = { }; FMaterial* Material[4] = { };
// Material properties // Material properties
FVector2 detailScale = { 1.f, 1.f };
float Glossiness = 10.f; float Glossiness = 10.f;
float SpecularLevel = 0.1f; float SpecularLevel = 0.1f;
float shaderspeed = 1.f; float shaderspeed = 1.f;
@ -305,6 +306,49 @@ public:
} }
} }
FVector2 GetDetailScale() const
{
return detailScale;
}
void SetDetailScale(float x, float y)
{
detailScale.X = x;
detailScale.Y = y;
}
FTexture* GetBrightmap()
{
if (Brightmap.get() || (flags & GTexf_BrightmapChecked)) return Brightmap.get();
CreateDefaultBrightmap();
return Brightmap.get();
}
FTexture* GetGlowmap()
{
return Glowmap.get();
}
FTexture* GetDetailmap()
{
return Detailmap.get();
}
void SetGlowmap(FTexture *T)
{
Glowmap = T;
}
void SetDetailmap(FTexture* T)
{
Detailmap = T;
}
void SetNormalmap(FTexture* T)
{
Normal = T;
}
void SetSpecularmap(FTexture* T)
{
Specular = T;
}
}; };
inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType)

View file

@ -83,30 +83,30 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
auto placeholder = TexMan.GameByIndex(1); auto placeholder = TexMan.GameByIndex(1);
if (tx->Brightmap.get()) if (tx->Brightmap.get())
{ {
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags }); mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Brightmap; mLayerFlags |= TEXF_Brightmap;
} }
else else
{ {
mTextureLayers.Push({ placeholder->GetTexture(), 0 }); mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
} }
if (tx->Detailmap.get()) if (tx->Detailmap.get())
{ {
mTextureLayers.Push({ tx->Detailmap.get(), 0 }); mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE });
mLayerFlags |= TEXF_Detailmap; mLayerFlags |= TEXF_Detailmap;
} }
else else
{ {
mTextureLayers.Push({ placeholder->GetTexture(), 0 }); mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
} }
if (tx->Glowmap.get()) if (tx->Glowmap.get())
{ {
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags }); mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Glowmap; mLayerFlags |= TEXF_Glowmap;
} }
else else
{ {
mTextureLayers.Push({ placeholder->GetTexture(), 0 }); mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
} }
auto index = tx->GetShaderIndex(); auto index = tx->GetShaderIndex();

View file

@ -12,6 +12,7 @@ struct MaterialLayerInfo
{ {
FTexture* layerTexture; FTexture* layerTexture;
int scaleFlags; int scaleFlags;
int clampflags;
}; };
//=========================================================================== //===========================================================================
@ -37,6 +38,10 @@ public:
int GetShaderIndex() const { return mShaderIndex; } int GetShaderIndex() const { return mShaderIndex; }
int GetScaleFlags() const { return mScaleFlags; } int GetScaleFlags() const { return mScaleFlags; }
virtual void DeleteDescriptors() { } virtual void DeleteDescriptors() { }
FVector2 GetDetailScale() const
{
return sourcetex->GetDetailScale();
}
FGameTexture* Source() const FGameTexture* Source() const
{ {

View file

@ -14,6 +14,7 @@ enum ECreateTexBufferFlags
CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation. CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation.
CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture. CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures. CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures.
CTF_Indexed = 16 // Tell the backend to create an indexed texture.
}; };
class FHardwareTextureContainer class FHardwareTextureContainer

View file

@ -48,6 +48,8 @@
#include "formats/multipatchtexture.h" #include "formats/multipatchtexture.h"
#include "texturemanager.h" #include "texturemanager.h"
#include "c_cvars.h" #include "c_cvars.h"
#include "imagehelpers.h"
#include "v_video.h"
// Wrappers to keep the definitions of these classes out of here. // Wrappers to keep the definitions of these classes out of here.
IHardwareTexture* CreateHardwareTexture(int numchannels); IHardwareTexture* CreateHardwareTexture(int numchannels);
@ -323,7 +325,22 @@ bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch)
FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
{ {
FTextureBuffer result; FTextureBuffer result;
if (flags & CTF_Indexed)
{
// Indexed textures will never be translated and never be scaled.
int w = GetWidth(), h = GetHeight();
auto store = Get8BitPixels(false);
const uint8_t* p = store.Data();
result.mBuffer = new uint8_t[w * h];
result.mWidth = w;
result.mHeight = h;
result.mContentId = 0;
ImageHelpers::FlipNonSquareBlock(result.mBuffer, p, h, w, h);
}
else
{
unsigned char* buffer = nullptr; unsigned char* buffer = nullptr;
int W, H; int W, H;
int isTransparent = -1; int isTransparent = -1;
@ -381,8 +398,9 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false); if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
} }
}
return result; return result;
} }
//=========================================================================== //===========================================================================
@ -514,7 +532,7 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
if (hwtex == nullptr) if (hwtex == nullptr)
{ {
hwtex = CreateHardwareTexture(4); hwtex = screen->CreateHardwareTexture(4);
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex); SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
} }
return hwtex; return hwtex;
@ -535,7 +553,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
Height = h; Height = h;
Format = bits; Format = bits;
//bNoCompress = true; //bNoCompress = true;
auto hwtex = CreateHardwareTexture(4); auto hwtex = screen->CreateHardwareTexture(4);
// todo: Initialize here. // todo: Initialize here.
SystemTextures.AddHardwareTexture(0, false, hwtex); SystemTextures.AddHardwareTexture(0, false, hwtex);
} }

View file

@ -625,8 +625,8 @@ void FTextureManager::AddHiresTextures (int wadnum)
auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override);
gtex->SetWorldPanning(true); gtex->SetWorldPanning(true);
gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight());
gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); gtex->SetOffsets(0, oldtex->GetTexelLeftOffset(0), oldtex->GetTexelTopOffset(0));
gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); gtex->SetOffsets(1, oldtex->GetTexelLeftOffset(1), oldtex->GetTexelTopOffset(1));
ReplaceTexture(tlist[i], gtex, true); ReplaceTexture(tlist[i], gtex, true);
} }
} }