isle-portable/LEGO1/lego/sources/3dmanager/tglsurface.cpp
Anonymous Maarten e4690a57b8
Some checks are pending
CI / clang-format (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain /usr/local/vitasdk/share/vita.toolchain.cmake, false, false, Ninja, Vita, ubuntu-latest, true, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0, false, false, Visual Studio 17 2022, true, Xbox One, windows-latest, amd64, false, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake, false, devkitpro/devkitarm:latest, false, Ninja, true, Nintendo 3DS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake, false, devkitpro/devkita64:latest, false, Ninja, Nintendo Switch, true, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, emcmake, false, false, true, Ninja, Emscripten, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, false, Ninja, true, MSVC (arm64), windows-latest, amd64_arm64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, true, Ninja, true, MSVC (x86), windows-latest, amd64_x86, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, false, Ninja, true, MSVC (x64), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, true, false, Ninja, true, MSVC (x64 Debug), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, -DCMAKE_SYSTEM_NAME=iOS, false, false, Xcode, true, iOS, macos-15, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, Ninja, true, mingw-w64-i686, mingw32, msys2 mingw32, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, false, Ninja, Android, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, true, false, Ninja, macOS, macos-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, false, Ninja, true, mingw-w64-x86_64, mingw64, msys2 mingw64, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux (Debug), ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux, ubuntu-latest, true) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (x86_64, ubuntu-latest) (push) Waiting to run
CI / C++ (push) Waiting to run
CI / Release (push) Blocked by required conditions
Docker / Publish web port (push) Waiting to run
Plug leaks until Information Center, detected by the LeakSanitizer (#764)
2026-01-04 03:35:42 +01:00

241 lines
4.8 KiB
C++

// TglSurface.cpp : implementation file
#include "tglsurface.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(TglSurface, 0x70);
using namespace Tgl;
/////////////////////////////////////////////////////////////////////////////
// TglSurface
// FUNCTION: LEGO1 0x100abbf0
// FUNCTION: BETA10 0x1017d490
TglSurface::TglSurface()
{
m_pRenderer = 0;
m_pDevice = 0;
m_pView = 0;
m_pScene = 0;
m_width = 0;
m_height = 0;
m_stopRendering = FALSE;
m_isInitialized = FALSE;
// statistics
m_frameCount = 0;
#ifdef _DEBUG
m_triangleCount = 0;
#endif
}
// FUNCTION: LEGO1 0x100abd60
// FUNCTION: BETA10 0x1017d5a2
TglSurface::~TglSurface()
{
Destroy();
}
// FUNCTION: LEGO1 0x100abde0
// FUNCTION: BETA10 0x1017d647
void TglSurface::Destroy()
{
DestroyView();
delete m_pDevice;
m_pDevice = 0;
m_pRenderer = 0;
m_pScene = 0;
}
// ???
// FUNCTION: LEGO1 0x100abe10
// FUNCTION: BETA10 0x1017d6b0
int GetBitsPerPixel(IDirectDrawSurface* pSurface)
{
DDPIXELFORMAT pixelFormat;
HRESULT result;
memset(&pixelFormat, 0, sizeof(pixelFormat));
pixelFormat.dwSize = sizeof(pixelFormat);
result = pSurface->GetPixelFormat(&pixelFormat);
assert(result == DD_OK);
assert((pixelFormat.dwFlags & DDPF_RGB) == DDPF_RGB);
return pixelFormat.dwRGBBitCount;
}
// FUNCTION: LEGO1 0x100abe50
// FUNCTION: BETA10 0x1017d742
BOOL TglSurface::Create(const CreateStruct& rCreateStruct, Renderer* pRenderer, Group* pScene)
{
DeviceDirect3DCreateData createData = {rCreateStruct.m_direct3d, rCreateStruct.m_d3dDevice};
int bitsPerPixel = GetBitsPerPixel(rCreateStruct.m_pFrontBuffer);
ColorModel colorModel = Ramp;
ShadingModel shadingModel = Gouraud;
int shadeCount = 32;
BOOL dither = TRUE;
int textureShadeCount = -1;
int textureColorCount = -1;
Result result;
assert(!m_pRenderer);
assert(!m_pScene);
assert(!m_pDevice);
m_pRenderer = pRenderer;
m_pScene = pScene;
m_pDevice = m_pRenderer->CreateDevice(createData);
if (!m_pDevice) {
assert(0);
m_pRenderer = 0;
m_pScene = 0;
return FALSE;
}
if (bitsPerPixel == 1) {
shadeCount = 4;
textureShadeCount = 4;
}
else if (bitsPerPixel == 8) {
shadeCount = 32;
shadeCount = 16;
dither = FALSE;
textureShadeCount = shadeCount;
textureColorCount = 256;
}
else if (bitsPerPixel == 16) {
shadeCount = 32;
dither = FALSE;
textureShadeCount = shadeCount;
textureColorCount = 256;
}
else if (bitsPerPixel >= 24) {
shadeCount = 256;
dither = FALSE;
textureShadeCount = 256;
textureColorCount = 64;
}
else {
dither = FALSE;
}
if (textureShadeCount != -1) {
result = pRenderer->SetTextureDefaultShadeCount(textureShadeCount);
assert(Succeeded(result));
}
if (textureColorCount != -1) {
result = pRenderer->SetTextureDefaultColorCount(textureColorCount);
assert(Succeeded(result));
}
result = m_pDevice->SetColorModel(colorModel);
assert(Succeeded(result));
result = m_pDevice->SetShadingModel(shadingModel);
assert(Succeeded(result));
result = m_pDevice->SetShadeCount(shadeCount);
assert(Succeeded(result));
result = m_pDevice->SetDither(dither);
assert(Succeeded(result));
m_width = m_pDevice->GetWidth();
m_height = m_pDevice->GetHeight();
assert(!m_pView);
m_pView = CreateView(m_pRenderer, m_pDevice);
if (!m_pView) {
delete m_pDevice;
m_pDevice = 0;
m_pRenderer = 0;
m_pScene = 0;
return FALSE;
}
m_frameRateMeter.Reset();
m_renderingRateMeter.Reset();
#ifdef _DEBUG
m_triangleRateMeter.Reset();
#endif
m_frameRateMeter.StartOperation();
m_isInitialized = TRUE;
return TRUE;
}
// FUNCTION: LEGO1 0x100ac030
// FUNCTION: BETA10 0x1017db86
void TglSurface::DestroyView()
{
delete m_pView;
m_pView = 0;
}
// FUNCTION: LEGO1 0x100ac050
// FUNCTION: BETA10 0x1017dbd0
double TglSurface::Render()
{
MxStopWatch renderTimer;
if (m_isInitialized && !m_stopRendering) {
Result result;
#ifdef _DEBUG
m_triangleRateMeter.StartOperation();
#endif
m_renderingRateMeter.StartOperation();
renderTimer.Start();
result = m_pView->Render(m_pScene);
renderTimer.Stop();
assert(Succeeded(result));
m_renderingRateMeter.EndOperation();
#ifdef _DEBUG
m_triangleRateMeter.EndOperation();
#endif
m_frameRateMeter.EndOperation();
m_frameCount++;
#ifdef _DEBUG
{
#if 0
// FIXME: Tgl::Device::GetDrawnTriangleCount does not exist
unsigned int triangleCount = m_pDevice->GetDrawnTriangleCount();
#else
unsigned int triangleCount = 0;
#endif
m_triangleRateMeter.IncreaseOperationCount(triangleCount - m_triangleCount - 1);
m_triangleCount = triangleCount;
}
#endif
#if 0
// reset rate meters every 20 frames
if ((++m_frameCount % 20) == 0)
#else
// reset rate meters every 4 seconds
if (m_frameRateMeter.ElapsedSeconds() > 4.0)
#endif
{
m_frameRateMeter.Reset();
m_renderingRateMeter.Reset();
#ifdef _DEBUG
m_triangleRateMeter.Reset();
#endif
}
m_frameRateMeter.StartOperation();
}
return renderTimer.ElapsedSeconds();
}