Skip to content

Commit

Permalink
- removed the intermediate FGLTexture class.
Browse files Browse the repository at this point in the history
This wasn't serving any real purpose anymore, and all its remaining functionality could be moved to FHardwareTexture
  • Loading branch information
coelckers committed Apr 24, 2018
1 parent 8d62ebd commit c37ff22
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 294 deletions.
17 changes: 9 additions & 8 deletions src/gl/scene/gl_swscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ class FSWPaletteTexture : public FTexture
class FSWSceneTexture : public FTexture
{
public:
FHardwareTexture *hwtex;

FSWSceneTexture(int w, int h, int bits)
{
Width = w;
Height = h;
WidthBits = bits;
UseType = ETextureType::SWCanvas;

hwtex = new FHardwareTexture(true);
new FGLTexture(this, hwtex);
bNoCompress = true;
gl_info.SystemTexture[0] = screen->CreateHardwareTexture(this);
}

// This is just a wrapper around the hardware texture and should never call the bitmap getters - if it does, something is wrong.
Expand All @@ -101,20 +99,23 @@ SWSceneDrawer::~SWSceneDrawer()
void SWSceneDrawer::RenderView(player_t *player)
{
DCanvas buffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor());
if (FBTexture == nullptr || FBTexture->hwtex == nullptr || FBTexture->GetWidth() != screen->GetWidth() || FBTexture->GetHeight() != screen->GetHeight() || (V_IsTrueColor() ? 1:0) != FBTexture->WidthBits)
if (FBTexture == nullptr || FBTexture->gl_info.SystemTexture[0] == nullptr ||
FBTexture->GetWidth() != screen->GetWidth() ||
FBTexture->GetHeight() != screen->GetHeight() ||
(V_IsTrueColor() ? 1:0) != FBTexture->WidthBits)
{
// This manually constructs its own material here.
if (FBTexture != nullptr) delete FBTexture;
FBTexture = new FSWSceneTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor());
FBTexture->hwtex->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
FBTexture->gl_info.SystemTexture[0]->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
auto mat = FMaterial::ValidateTexture(FBTexture, false);
mat->AddTextureLayer(PaletteTexture);
}
auto buf = FBTexture->hwtex->MapBuffer();
auto buf = FBTexture->gl_info.SystemTexture[0]->MapBuffer();
if (!buf) I_FatalError("Unable to map buffer for software rendering");
buffer.SetBuffer(screen->GetWidth(), screen->GetHeight(), screen->GetWidth(), buf);
SWRenderer->RenderView(player, &buffer);
FBTexture->hwtex->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
FBTexture->gl_info.SystemTexture[0]->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");

auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
screen->Begin2D(false);
Expand Down
6 changes: 6 additions & 0 deletions src/gl/system/gl_framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ void OpenGLFrameBuffer::SetTextureFilterMode()
if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode();
}

FHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(FTexture *tex)
{
return new FHardwareTexture(tex->bNoCompress);
}


void OpenGLFrameBuffer::UpdatePalette()
{
if (GLRenderer)
Expand Down
1 change: 1 addition & 0 deletions src/gl/system/gl_framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OpenGLFrameBuffer : public SystemFrameBuffer
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;

// Retrieves a buffer containing image data for a screenshot.
// Hint: Pitch can be negative for upside-down images, in which case buffer
Expand Down
62 changes: 62 additions & 0 deletions src/gl/textures/gl_hwtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "gl/system/gl_debug.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/textures/gl_material.h"
#include "gl/textures/gl_samplers.h"


extern TexFilter_s TexFilter[];
Expand Down Expand Up @@ -491,3 +492,64 @@ void FHardwareTexture::BindToFrameBuffer(int width, int height)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer(width, height));
}


//===========================================================================
//
// Binds a texture to the renderer
//
//===========================================================================

bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags)
{
int usebright = false;

if (translation <= 0)
{
translation = -translation;
}
else
{
auto remap = TranslationToTable(translation);
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
}

bool needmipmap = (clampmode <= CLAMP_XY);

// Texture has become invalid
if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified(DefaultRenderStyle()))
{
Clean(true);
}

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

int w = 0, h = 0;

// Create this texture
unsigned char * buffer = nullptr;

if (!tex->bHasCanvas)
{
if (gl.legacyMode) flags |= CTF_MaybeWarped;
buffer = tex->CreateTexBuffer(translation, w, h, flags | CTF_ProcessData);
}
else
{
w = tex->GetWidth();
h = tex->GetHeight();
}
if (!CreateTexture(buffer, w, h, texunit, needmipmap, translation, "FHardwareTexture.BindOrCreate"))
{
// could not create texture
delete[] buffer;
return false;
}
delete[] buffer;
}
if (tex->bHasCanvas) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
return true;
}

2 changes: 2 additions & 0 deletions src/gl/textures/gl_hwtexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class FHardwareTexture
void BindToFrameBuffer(int w, int h);

unsigned int Bind(int texunit, int translation, bool needmipmap);
bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);

void AllocateBuffer(int w, int h, int texelsize);
uint8_t *MapBuffer();

Expand Down
Loading

0 comments on commit c37ff22

Please sign in to comment.