Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 1ef74220 authored by TAVERNIER Vincent's avatar TAVERNIER Vincent
Browse files

Only allocate texture objects once, but update storage on size change

parent 16934390
No related branches found
No related tags found
No related merge requests found
......@@ -90,8 +90,8 @@ public:
{ return targetTex; }
private:
std::shared_ptr<oglplus::Texture> InitializeRenderTexture(int width,
int height);
void InitializeRenderTexture(std::shared_ptr<oglplus::Texture> &texptr,
int width, int height);
};
}
......
......@@ -48,8 +48,8 @@ void ToyBuffer::Initialize(int width, int height)
void ToyBuffer::AllocateTextures(int width, int height)
{
// Initialize buffer textures
sourceTex = InitializeRenderTexture(width, height);
targetTex = InitializeRenderTexture(width, height);
InitializeRenderTexture(sourceTex, width, height);
InitializeRenderTexture(targetTex, width, height);
// Setup render buffers
targetTex->Bind(TextureTarget::_2D);
......@@ -102,9 +102,13 @@ void ToyBuffer::Render()
swap(sourceTex, targetTex);
}
shared_ptr<Texture> ToyBuffer::InitializeRenderTexture(int width, int height)
void ToyBuffer::InitializeRenderTexture(shared_ptr<Texture> &texptr, int width, int height)
{
auto texptr = make_shared<Texture>();
// Only create a texture object if it is necessary
if (!texptr)
texptr = make_shared<Texture>();
// Allocate texture storage according to width/height
gl.DirectEXT(TextureTarget::_2D, *texptr)
.MinFilter(TextureMinFilter::Nearest)
.MagFilter(TextureMagFilter::Nearest)
......@@ -115,13 +119,10 @@ shared_ptr<Texture> ToyBuffer::InitializeRenderTexture(int width, int height)
PixelDataType::UnsignedByte, nullptr);
// Clear the frame accumulator so it doesn't contain garbage
float black[4];
memset(black, 0, sizeof(black));
float black[4] = {0.f};
glClearTexImage(GetName(*texptr),
0,
GL_BGRA,
GL_FLOAT,
black);
return texptr;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment