dynamic buffer allocation

this wasnt that bad, idk how it actually performs tho, didnt need a rewrite like i initially thought
This commit is contained in:
DrPerkyLegit committed 2026-10-22 20:20:53 -04:00
1 parent fa93d9ac8a
commit 1ff63f4785
4 files changed
+229 -129

No files matched your search

@@ -40,6 +40,14 @@ DXGI_FORMAT Renderer::textureFormats[] = {
void user_flush_data(png_struct_def *png_ptr);
void user_write_data(png_struct_def *png_ptr, unsigned char *src, size_t length);
void Renderer::GrowTexturePool(size_t extraSlots)
{
const size_t oldCapacity = m_textures.size();
m_textures.resize(oldCapacity + extraSlots);
TracePoolGrowth("texture pool", oldCapacity, oldCapacity + extraSlots);
}
HRESULT Renderer::LoadTextureData(BYTE* pbData, DWORD dwBytes, D3DXIMAGE_INFO* pSrcInfo, int** ppDataOut)
{
PROFILER_SCOPE("Renderer::LoadTextureData_Memory", "LoadTextureData_Memory", MP_PURPLE4);
@@ -155,18 +163,29 @@ void Renderer::TextureBindVertex(int idx)
int Renderer::TextureCreate()
{
PROFILER_SCOPE("Renderer::TextureCreate", "TextureCreate", MP_PURPLE4);
for (int i = 0; i < MAX_TEXTURES; i++)
const std::uint32_t poolSize = static_cast<std::uint32_t>(m_textures.size());
std::uint32_t slot = m_textureScanHint;
while (slot < poolSize && m_textures[slot].allocated)
++slot;
if (slot >= poolSize)
{
if (!m_textures[i].allocated)
{
m_textures[i].texture = NULL;
m_textures[i].allocated = true;
m_textures[i].mipLevels = 1;
m_textures[i].samplerParams = 0;
return i;
}
GrowTexturePool(MAX_TEXTURES);
slot = poolSize;
}
return -1;
Texture& texture = m_textures[slot];
texture.allocated = true;
texture.texture = NULL;
texture.view = NULL;
texture.textureFlags = 0;
texture.mipLevels = 0;
texture.textureFormat = 0;
texture.samplerParams = 0;
m_textureScanHint = slot + 1;
return static_cast<int>(slot);
}
void Renderer::TextureData(int width, int height, void* data, int level, C4JRender::eTextureFormat format)
@@ -239,11 +258,18 @@ void Renderer::TextureDynamicUpdateStart() {}
void Renderer::TextureFree(int idx)
{
PROFILER_SCOPE("Renderer::TextureFree", "TextureFree", MP_PURPLE4);
m_textures[idx].texture->Release();
m_textures[idx].view->Release();
m_textures[idx].view = NULL;
m_textures[idx].allocated = false;
m_textures[idx].texture = NULL;
if (idx < 0 || static_cast<std::uint32_t>(idx) >= m_textures.size())
return;
Texture& texture = m_textures[idx];
if (texture.view)
texture.view->Release();
if (texture.texture)
texture.texture->Release();
texture = Texture();
if (static_cast<std::uint32_t>(idx) < m_textureScanHint)
m_textureScanHint = static_cast<std::uint32_t>(idx);
}
void Renderer::TextureGetStats() {}