Skip to content

Commit

Permalink
- backend sync with Raze.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed May 31, 2020
1 parent b60fd4d commit 4c11b01
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 68 deletions.
4 changes: 2 additions & 2 deletions src/common/rendering/gl/gl_framebuffer.cpp
Expand Up @@ -56,6 +56,7 @@
#include "gl_postprocessstate.h"
#include "v_draw.h"
#include "printf.h"
#include "gl_hwtexture.h"

#include "flatvertices.h"
#include "hw_cvars.h"
Expand Down Expand Up @@ -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.
// If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed!
Super::SetVSync(vid_vsync);
FHardwareTexture::InitGlobalState();

// Make sure all global variables tracking OpenGL context state are reset..
FHardwareTexture::InitGlobalState();
gl_RenderState.Reset();

GLRenderer = nullptr;
Expand Down Expand Up @@ -215,7 +216,6 @@ void OpenGLFrameBuffer::CopyScreenToBuffer(int width, int height, uint8_t* scr)
//===========================================================================

void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect &)> renderFunc)

{
GLRenderer->StartOffscreen();
GLRenderer->BindToFrameBuffer(tex);
Expand Down
10 changes: 8 additions & 2 deletions src/common/rendering/gl/gl_hwtexture.cpp
Expand Up @@ -42,6 +42,7 @@
#include "hw_cvars.h"
#include "gl_debug.h"
#include "gl_renderer.h"
#include "gl_renderstate.h"
#include "gl_samplers.h"
#include "gl_hwtexture.h"

Expand Down Expand Up @@ -302,12 +303,16 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
{
int usebright = false;

bool needmipmap = (clampmode <= CLAMP_XY);
bool needmipmap = (clampmode <= CLAMP_XY) && !forcenofilter;

// Bind it to the system.
if (!Bind(texunit, needmipmap))
{

if (flags & CTF_Indexed)
{
glTextureBytes = 1;
forcenofilter = true;
}
int w = 0, h = 0;

// Create this texture
Expand All @@ -331,6 +336,7 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
return false;
}
}
if (forcenofilter && clampmode <= CLAMP_XY) clampmode += CLAMP_NOFILTER - CLAMP_NONE;
GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/rendering/gl/gl_samplers.cpp
Expand Up @@ -93,7 +93,7 @@ FSamplerManager::~FSamplerManager()

void FSamplerManager::UnbindAll()
{
for (int i = 0; i < FHardwareTexture::MAX_TEXTURES; i++)
for (int i = 0; i < IHardwareTexture::MAX_TEXTURES; i++)
{
glBindSampler(i, 0);
}
Expand Down
5 changes: 0 additions & 5 deletions src/common/rendering/v_video.cpp
Expand Up @@ -457,11 +457,6 @@ DEFINE_GLOBAL(CleanYfac_1)
DEFINE_GLOBAL(CleanWidth_1)
DEFINE_GLOBAL(CleanHeight_1)

IHardwareTexture* CreateHardwareTexture(int numchannels)
{
return screen->CreateHardwareTexture(numchannels);
}

//==========================================================================
//
// CVAR transsouls
Expand Down
4 changes: 2 additions & 2 deletions src/common/rendering/vulkan/textures/vk_hwtexture.cpp
Expand Up @@ -390,8 +390,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)

WriteDescriptors update;
MaterialLayerInfo *layer;
auto systex = static_cast<VkHardwareTexture*>(GetLayer(0, state.mTranslation, &layer));
update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
auto systex = static_cast<VkHardwareTexture*>(GetLayer(0, translation, &layer));
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++)
{
auto systex = static_cast<VkHardwareTexture*>(GetLayer(i, 0, &layer));
Expand Down
2 changes: 1 addition & 1 deletion src/common/textures/gametexture.cpp
Expand Up @@ -187,7 +187,7 @@ void FGameTexture::AddAutoMaterials()
void FGameTexture::CreateDefaultBrightmap()
{
auto tex = GetTexture();
if (flags & GTexf_BrightmapChecked)
if (!(flags & GTexf_BrightmapChecked))
{
flags |= GTexf_BrightmapChecked;
// Check for brightmaps
Expand Down
44 changes: 44 additions & 0 deletions src/common/textures/gametexture.h
Expand Up @@ -92,6 +92,7 @@ class FGameTexture
FMaterial* Material[4] = { };

// Material properties
FVector2 detailScale = { 1.f, 1.f };
float Glossiness = 10.f;
float SpecularLevel = 0.1f;
float shaderspeed = 1.f;
Expand Down Expand Up @@ -305,6 +306,49 @@ class FGameTexture
}
}

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)
Expand Down
12 changes: 6 additions & 6 deletions src/common/textures/hw_material.cpp
Expand Up @@ -83,30 +83,30 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
auto placeholder = TexMan.GameByIndex(1);
if (tx->Brightmap.get())
{
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags });
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Brightmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0 });
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
if (tx->Detailmap.get())
{
mTextureLayers.Push({ tx->Detailmap.get(), 0 });
mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE });
mLayerFlags |= TEXF_Detailmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0 });
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
if (tx->Glowmap.get())
{
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags });
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Glowmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0 });
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}

auto index = tx->GetShaderIndex();
Expand Down
5 changes: 5 additions & 0 deletions src/common/textures/hw_material.h
Expand Up @@ -12,6 +12,7 @@ struct MaterialLayerInfo
{
FTexture* layerTexture;
int scaleFlags;
int clampflags;
};

//===========================================================================
Expand All @@ -37,6 +38,10 @@ class FMaterial
int GetShaderIndex() const { return mShaderIndex; }
int GetScaleFlags() const { return mScaleFlags; }
virtual void DeleteDescriptors() { }
FVector2 GetDetailScale() const
{
return sourcetex->GetDetailScale();
}

FGameTexture* Source() const
{
Expand Down
1 change: 1 addition & 0 deletions src/common/textures/hw_texcontainer.h
Expand Up @@ -14,6 +14,7 @@ enum ECreateTexBufferFlags
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_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
Expand Down
112 changes: 65 additions & 47 deletions src/common/textures/texture.cpp
Expand Up @@ -48,6 +48,8 @@
#include "formats/multipatchtexture.h"
#include "texturemanager.h"
#include "c_cvars.h"
#include "imagehelpers.h"
#include "v_video.h"

// Wrappers to keep the definitions of these classes out of here.
IHardwareTexture* CreateHardwareTexture(int numchannels);
Expand Down Expand Up @@ -323,66 +325,82 @@ bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch)
FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
{
FTextureBuffer result;
if (flags & CTF_Indexed)
{
// Indexed textures will never be translated and never be scaled.
int w = GetWidth(), h = GetHeight();

unsigned char* buffer = nullptr;
int W, H;
int isTransparent = -1;
bool checkonly = !!(flags & CTF_CheckOnly);

int exx = !!(flags & CTF_Expand);

W = GetWidth() + 2 * exx;
H = GetHeight() + 2 * exx;
auto store = Get8BitPixels(false);
const uint8_t* p = store.Data();

if (!checkonly)
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
{
buffer = new unsigned char[W * (H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);
unsigned char* buffer = nullptr;
int W, H;
int isTransparent = -1;
bool checkonly = !!(flags & CTF_CheckOnly);

auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation);
if (remap) translation = remap->Index;
FBitmap bmp(buffer, W * 4, W, H);
int exx = !!(flags & CTF_Expand);

int trans;
auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans);
bmp.Blit(exx, exx, Pixels);
W = GetWidth() + 2 * exx;
H = GetHeight() + 2 * exx;

if (remap == nullptr)
if (!checkonly)
{
CheckTrans(buffer, W * H, trans);
isTransparent = bTranslucent;
buffer = new unsigned char[W * (H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);

auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation);
if (remap) translation = remap->Index;
FBitmap bmp(buffer, W * 4, W, H);

int trans;
auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans);
bmp.Blit(exx, exx, Pixels);

if (remap == nullptr)
{
CheckTrans(buffer, W * H, trans);
isTransparent = bTranslucent;
}
else
{
isTransparent = 0;
// A translated image is not conclusive for setting the texture's transparency info.
}
}
else

if (GetImage())
{
isTransparent = 0;
// A translated image is not conclusive for setting the texture's transparency info.
FContentIdBuilder builder;
builder.id = 0;
builder.imageID = GetImage()->GetId();
builder.translation = MAX(0, translation);
builder.expand = exx;
result.mContentId = builder.id;
}
}

if (GetImage())
{
FContentIdBuilder builder;
builder.id = 0;
builder.imageID = GetImage()->GetId();
builder.translation = MAX(0, translation);
builder.expand = exx;
result.mContentId = builder.id;
}
else result.mContentId = 0; // for non-image backed textures this has no meaning so leave it at 0.
else result.mContentId = 0; // for non-image backed textures this has no meaning so leave it at 0.

result.mBuffer = buffer;
result.mWidth = W;
result.mHeight = H;
result.mBuffer = buffer;
result.mWidth = W;
result.mHeight = H;

// Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.)
if (GetImage() && flags & CTF_ProcessData)
{
if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly);
// Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.)
if (GetImage() && flags & CTF_ProcessData)
{
if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly);

if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
}
}

return result;

}

//===========================================================================
Expand Down Expand Up @@ -514,7 +532,7 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
if (hwtex == nullptr)
{
hwtex = CreateHardwareTexture(4);
hwtex = screen->CreateHardwareTexture(4);
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
}
return hwtex;
Expand All @@ -535,7 +553,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
Height = h;
Format = bits;
//bNoCompress = true;
auto hwtex = CreateHardwareTexture(4);
auto hwtex = screen->CreateHardwareTexture(4);
// todo: Initialize here.
SystemTextures.AddHardwareTexture(0, false, hwtex);
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/textures/texturemanager.cpp
Expand Up @@ -625,8 +625,8 @@ void FTextureManager::AddHiresTextures (int wadnum)
auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override);
gtex->SetWorldPanning(true);
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(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY()));
gtex->SetOffsets(0, oldtex->GetTexelLeftOffset(0), oldtex->GetTexelTopOffset(0));
gtex->SetOffsets(1, oldtex->GetTexelLeftOffset(1), oldtex->GetTexelTopOffset(1));
ReplaceTexture(tlist[i], gtex, true);
}
}
Expand Down

0 comments on commit 4c11b01

Please sign in to comment.