From 1a903f06e0152ee3d46d9d448feceb4356dc0ec3 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 19 Dec 2024 15:50:28 +0100 Subject: [PATCH] Implement TglD3DRMIMAGE::CreateBuffer (ecx/edi are swapped) --- LEGO1/tgl/d3drm/texture.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/LEGO1/tgl/d3drm/texture.cpp b/LEGO1/tgl/d3drm/texture.cpp index a51a5c0b..52dec7fe 100644 --- a/LEGO1/tgl/d3drm/texture.cpp +++ b/LEGO1/tgl/d3drm/texture.cpp @@ -86,10 +86,38 @@ void TglD3DRMIMAGE::Destroy() delete m_image.palette; } -// STUB: LEGO1 0x100a13e0 +static inline int IsPowerOfTwo(int v) { + int m = 0; + while (v > 2 && m == 0) { + m = v % 2; + v /= 2; + } + return v == 2 && m == 0; +} + +// FUNCTION: LEGO1 0x100a13e0 Result TglD3DRMIMAGE::CreateBuffer(int width, int height, int depth, void* pBuffer, int useBuffer) { - return Error; + if (!(IsPowerOfTwo(width) && IsPowerOfTwo(height) && width % 4 == 0)) { + return Error; + } + m_image.width = width; + m_image.height = height; + m_image.depth = depth; + m_image.bytes_per_line = width; + if (!m_texelsAllocatedByClient) { + delete[] m_image.buffer1; + m_image.buffer1 = NULL; + } + if (useBuffer) { + m_texelsAllocatedByClient = 1; + m_image.buffer1 = (char *)pBuffer; + } else { + m_image.buffer1 = new char[width * height]; + memcpy(m_image.buffer1, pBuffer, width * height); + m_texelsAllocatedByClient = 0; + } + return Success; } // FUNCTION: LEGO1 0x100a1510