Skip to content

Commit

Permalink
- add the hardware texture container to FTexture.
Browse files Browse the repository at this point in the history
Currently it does not use the translated entries yet.

# Conflicts:
#	src/hwrenderer/textures/hw_material.cpp
  • Loading branch information
coelckers committed Dec 12, 2018
1 parent e6b4c63 commit fb6ee50
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/gl/system/gl_framebuffer.cpp
Expand Up @@ -515,9 +515,9 @@ FTexture *OpenGLFrameBuffer::WipeStartScreen()
const auto &viewport = screen->mScreenViewport;

auto tex = new FWrapperTexture(viewport.width, viewport.height, 1);
tex->GetSystemTexture(0)->CreateTexture(nullptr, viewport.width, viewport.height, 0, false, 0, "WipeStartScreen");
tex->GetSystemTexture()->CreateTexture(nullptr, viewport.width, viewport.height, 0, false, 0, "WipeStartScreen");
glFinish();
static_cast<FHardwareTexture*>(tex->GetSystemTexture(0))->Bind(0, false, false);
static_cast<FHardwareTexture*>(tex->GetSystemTexture())->Bind(0, false, false);

GLRenderer->mBuffers->BindCurrentFB();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height);
Expand All @@ -537,9 +537,9 @@ FTexture *OpenGLFrameBuffer::WipeEndScreen()
GLRenderer->Flush();
const auto &viewport = screen->mScreenViewport;
auto tex = new FWrapperTexture(viewport.width, viewport.height, 1);
tex->GetSystemTexture(0)->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeEndScreen");
tex->GetSystemTexture()->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeEndScreen");
glFinish();
static_cast<FHardwareTexture*>(tex->GetSystemTexture(0))->Bind(0, false, false);
static_cast<FHardwareTexture*>(tex->GetSystemTexture())->Bind(0, false, false);
GLRenderer->mBuffers->BindCurrentFB();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height);
return tex;
Expand Down
14 changes: 10 additions & 4 deletions src/hwrenderer/textures/hw_texcontainer.h
@@ -1,8 +1,10 @@
#pragma once

#include "tarray.h"
#include "hwrenderer/textures/hw_ihwtexture.h"

struct FTextureBuffer;
class IHardwareTexture;

class FHardwareTextureContainer
{
Expand Down Expand Up @@ -49,10 +51,10 @@ class FHardwareTextureContainer
unsigned index = hwTex_Translated.FindEx([=](auto &element)
{
return element.translation == translation;
}
});
if (index < hwTex_Translated.Size())
{
return &hwTex_Translated[i];
return &hwTex_Translated[index];
}

int add = hwTex_Translated.Reserve(1);
Expand All @@ -65,7 +67,11 @@ class FHardwareTextureContainer

void Clean(bool all)
{
if (all) hwDefTex.Delete();
if (all)
{
hwDefTex[0].Delete();
hwDefTex[1].Delete();
}
hwTex_Translated.Clear();

}
Expand All @@ -90,7 +96,7 @@ class FHardwareTextureContainer
//
//===========================================================================

void FHardwareTexture::CleanUnused(SpriteHits &usedtranslations, bool expanded)
void CleanUnused(SpriteHits &usedtranslations, bool expanded)
{
if (usedtranslations.CheckKey(0) == nullptr)
{
Expand Down
8 changes: 4 additions & 4 deletions src/swrenderer/r_swscene.cpp
Expand Up @@ -91,26 +91,26 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
FBTextureIndex = (FBTextureIndex + 1) % 2;
auto &fbtex = FBTexture[FBTextureIndex];

if (fbtex == nullptr || fbtex->GetSystemTexture(0) == nullptr ||
if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr ||
fbtex->GetDisplayWidth() != screen->GetWidth() ||
fbtex->GetDisplayHeight() != screen->GetHeight() ||
(V_IsTrueColor() ? 1:0) != fbtex->GetColorFormat())
{
// This manually constructs its own material here.
fbtex.reset();
fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
fbtex->GetSystemTexture(0)->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
mat->AddTextureLayer(PaletteTexture);

Canvas.reset();
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
}

auto buf = fbtex->GetSystemTexture(0)->MapBuffer();
auto buf = fbtex->GetSystemTexture()->MapBuffer();
if (!buf) I_FatalError("Unable to map buffer for software rendering");
SWRenderer->RenderView(player, Canvas.get(), buf);
fbtex->GetSystemTexture(0)->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
fbtex->GetSystemTexture()->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");

auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
screen->DrawTexture(fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE);
Expand Down
5 changes: 1 addition & 4 deletions src/textures/texture.cpp
Expand Up @@ -178,9 +178,6 @@ FTexture::~FTexture ()
{
if (Material[i] != nullptr) delete Material[i];
Material[i] = nullptr;

if (SystemTexture[i] != nullptr) delete SystemTexture[i];
SystemTexture[i] = nullptr;
}
if (SoftwareTexture != nullptr)
{
Expand Down Expand Up @@ -793,7 +790,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
Format = bits;
UseType = ETextureType::SWCanvas;
bNoCompress = true;
SystemTexture[0] = screen->CreateHardwareTexture();
SystemTextures.AddHardwareTexture(0, false, screen->CreateHardwareTexture());
}

//===========================================================================
Expand Down
8 changes: 5 additions & 3 deletions src/textures/textures.h
Expand Up @@ -42,6 +42,7 @@
#include "colormatcher.h"
#include "r_data/renderstyle.h"
#include "r_data/r_translate.h"
#include "hwrenderer/textures/hw_texcontainer.h"
#include <vector>

// 15 because 0th texture is our texture
Expand Down Expand Up @@ -344,7 +345,8 @@ class FTexture
FTextureID id;

FMaterial *Material[2] = { nullptr, nullptr };
IHardwareTexture *SystemTexture[2] = { nullptr, nullptr };
FHardwareTextureContainer SystemTextures;
//IHardwareTexture *SystemTexture[2] = { nullptr, nullptr };
FSoftwareTexture *SoftwareTexture = nullptr;

// None of the following pointers are owned by this texture, they are all controlled by the texture manager.
Expand Down Expand Up @@ -710,9 +712,9 @@ class FWrapperTexture : public FTexture
int Format;
public:
FWrapperTexture(int w, int h, int bits = 1);
IHardwareTexture *GetSystemTexture(int slot)
IHardwareTexture *GetSystemTexture()
{
return SystemTexture[slot];
return SystemTextures.GetHardwareTexture(0, false);
}

int GetColorFormat() const
Expand Down

0 comments on commit fb6ee50

Please sign in to comment.