port: GrpImageInstance/GrpExpandedImageInstance verbatim; fix SCREEN blend factor

Both units are the 40250 bodies; only the PDT-stream draw becomes
UIRenderAddImage (with the rendering mode). SCREEN/COLOR_DODGE were packed as
0x28 (INVDESTALPHA+ONE); 40250 uses INVDESTCOLOR+ONE (0x2A). OnIsType calls the
base OnIsType instead of 40250's recursing IsType. port.grp_resource covers the
quads, UVs, colour and blend mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 14:21:13 +09:00
co-authored by Claude Opus 5.5
parent 010e99f070
commit 65777331f7
8 changed files with 819 additions and 231 deletions
+142 -115
View File
@@ -1,63 +1,148 @@
// Platform skeleton for EterLib/GrpExpandedImageInstance.h (40250 EterLib/GrpExpandedImageInstance.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
// 40250 EterLib/GrpExpandedImageInstance.cpp, verbatim.
#include "EterLib/StdAfx.h"
#include "EterLib/GrpExpandedImageInstance.h"
#include "../PlatformStub.h"
#include "EterBase/CRC32.h"
#include "EterLib/GrpExpandedImageInstance.h"
#include "EterLib/StateManager.h"
#include "UIRenderCommands.h"
#include <cmath>
CDynamicPool<CGraphicExpandedImageInstance> CGraphicExpandedImageInstance::ms_kPool;
auto CGraphicExpandedImageInstance::Type() -> DWORD
void CGraphicExpandedImageInstance::CreateSystem(UINT uCapacity)
{
static DWORD type = GetCRC32("CGraphicExpandedImageInstance", sizeof("CGraphicExpandedImageInstance") - 1);
return type;
ms_kPool.Create(uCapacity);
}
CGraphicExpandedImageInstance::CGraphicExpandedImageInstance()
void CGraphicExpandedImageInstance::DestroySystem()
{
Initialize();
ms_kPool.Destroy();
}
CGraphicExpandedImageInstance::~CGraphicExpandedImageInstance()
CGraphicExpandedImageInstance* CGraphicExpandedImageInstance::New()
{
Destroy();
return ms_kPool.Alloc();
}
auto CGraphicExpandedImageInstance::Destroy() -> void
void CGraphicExpandedImageInstance::Delete(CGraphicExpandedImageInstance* pkImgInst)
{
CGraphicImageInstance::Destroy();
Initialize();
pkImgInst->Destroy();
ms_kPool.Free(pkImgInst);
}
auto CGraphicExpandedImageInstance::SetDepth(float depth) -> void
void CGraphicExpandedImageInstance::OnRender()
{
m_fDepth = depth;
CGraphicImage * pImage = m_roImage.GetPointer();
CGraphicTexture * pTexture = pImage->GetTexturePointer();
const RECT& c_rRect = pImage->GetRectReference();
float texReverseWidth = 1.0f / float(pTexture->GetWidth());
float texReverseHeight = 1.0f / float(pTexture->GetHeight());
float su = (c_rRect.left - m_RenderingRect.left) * texReverseWidth;
float sv = (c_rRect.top - m_RenderingRect.top) * texReverseHeight;
float eu = (c_rRect.left + m_RenderingRect.right + (c_rRect.right-c_rRect.left)) * texReverseWidth;
float ev = (c_rRect.top + m_RenderingRect.bottom + (c_rRect.bottom-c_rRect.top)) * texReverseHeight;
TPDTVertex vertices[4];
vertices[0].position.x = m_v2Position.x-0.5f;
vertices[0].position.y = m_v2Position.y-0.5f;
vertices[0].position.z = m_fDepth;
vertices[0].texCoord = TTextureCoordinate(su, sv);
vertices[0].diffuse = m_DiffuseColor;
vertices[1].position.x = m_v2Position.x-0.5f;
vertices[1].position.y = m_v2Position.y-0.5f;
vertices[1].position.z = m_fDepth;
vertices[1].texCoord = TTextureCoordinate(eu, sv);
vertices[1].diffuse = m_DiffuseColor;
vertices[2].position.x = m_v2Position.x-0.5f;
vertices[2].position.y = m_v2Position.y-0.5f;
vertices[2].position.z = m_fDepth;
vertices[2].texCoord = TTextureCoordinate(su, ev);
vertices[2].diffuse = m_DiffuseColor;
vertices[3].position.x = m_v2Position.x-0.5f;
vertices[3].position.y = m_v2Position.y-0.5f;
vertices[3].position.z = m_fDepth;
vertices[3].texCoord = TTextureCoordinate(eu, ev);
vertices[3].diffuse = m_DiffuseColor;
if (0.0f == m_fRotation)
{
float fimgWidth = float(pImage->GetWidth()) * m_v2Scale.x;
float fimgHeight = float(pImage->GetHeight()) * m_v2Scale.y;
vertices[0].position.x -= m_RenderingRect.left;
vertices[0].position.y -= m_RenderingRect.top;
vertices[1].position.x += fimgWidth + m_RenderingRect.right;
vertices[1].position.y -= m_RenderingRect.top;
vertices[2].position.x -= m_RenderingRect.left;
vertices[2].position.y += fimgHeight + m_RenderingRect.bottom;
vertices[3].position.x += fimgWidth + m_RenderingRect.right;
vertices[3].position.y += fimgHeight + m_RenderingRect.bottom;
// PORT: 40250 flips D3DRS_CULLMODE to CCW for a mirrored scale; the UI pipeline draws both windings.
}
else
{
float fimgHalfWidth = float(pImage->GetWidth())/2.0f * m_v2Scale.x;
float fimgHalfHeight = float(pImage->GetHeight())/2.0f * m_v2Scale.y;
for (int i = 0; i < 4; ++i)
{
vertices[i].position.x += m_v2Origin.x;
vertices[i].position.y += m_v2Origin.y;
}
float fRadian = D3DXToRadian(m_fRotation);
vertices[0].position.x += (-fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian));
vertices[0].position.y += (-fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian));
vertices[1].position.x += (+fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian));
vertices[1].position.y += (+fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian));
vertices[2].position.x += (-fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian));
vertices[2].position.y += (-fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian));
vertices[3].position.x += (+fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian));
vertices[3].position.y += (+fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian));
}
// PORT: 40250 saves SRCBLEND/DESTBLEND for the rendering mode (SCREEN/COLOR_DODGE: INVDESTCOLOR+ONE,
// MODULATE: ZERO+SRCCOLOR), draws the fill-rect quad with the PDT stream and restores the states; here
// the quad and its mode go to the UI command list, which picks the matching blend pipeline.
float x[4], y[4];
for (int i = 0; i < 4; ++i)
{
x[i] = vertices[i].position.x;
y[i] = vertices[i].position.y;
}
UIRenderAddImage(pTexture, x, y, su, sv, eu, ev, vertices[0].diffuse, m_iRenderingMode);
}
auto CGraphicExpandedImageInstance::SetOrigin() -> void
void CGraphicExpandedImageInstance::SetDepth(float fDepth)
{
m_v2Origin = D3DXVECTOR2(GetWidth() * 0.5f, GetHeight() * 0.5f);
m_fDepth = fDepth;
}
auto CGraphicExpandedImageInstance::SetOrigin(float x, float y) -> void
void CGraphicExpandedImageInstance::SetOrigin()
{
m_v2Origin = D3DXVECTOR2(x, y);
SetOrigin(float(GetWidth()) / 2.0f, float(GetHeight()) / 2.0f);
}
auto CGraphicExpandedImageInstance::SetRotation(float rotation) -> void
void CGraphicExpandedImageInstance::SetOrigin(float fx, float fy)
{
m_fRotation = rotation;
m_v2Origin.x = fx;
m_v2Origin.y = fy;
}
auto CGraphicExpandedImageInstance::SetScale(float x, float y) -> void
void CGraphicExpandedImageInstance::SetRotation(float fRotation)
{
m_v2Scale = D3DXVECTOR2(x, y);
m_fRotation = fRotation;
}
// In 40250, the arguments are fractions of the image size (uiToolTip gauges, SetPercentage).
auto CGraphicExpandedImageInstance::SetRenderingRect(float fLeft, float fTop, float fRight, float fBottom) -> void
void CGraphicExpandedImageInstance::SetScale(float fx, float fy)
{
m_v2Scale.x = fx;
m_v2Scale.y = fy;
}
void CGraphicExpandedImageInstance::SetRenderingRect(float fLeft, float fTop, float fRight, float fBottom)
{
if (IsEmpty())
return;
@@ -71,115 +156,57 @@ auto CGraphicExpandedImageInstance::SetRenderingRect(float fLeft, float fTop, fl
m_RenderingRect.bottom = fHeight * fBottom;
}
auto CGraphicExpandedImageInstance::SetRenderingMode(int mode) -> void
void CGraphicExpandedImageInstance::SetRenderingMode(int iMode)
{
m_iRenderingMode = mode;
m_iRenderingMode = iMode;
}
auto CGraphicExpandedImageInstance::Initialize() -> void
DWORD CGraphicExpandedImageInstance::Type()
{
m_fDepth = 0;
m_v2Origin = D3DXVECTOR2(0, 0);
m_v2Scale = D3DXVECTOR2(1, 1);
m_fRotation = 0;
m_RenderingRect = {0, 0, 0, 0};
m_iRenderingMode = RENDERING_MODE_NORMAL;
static DWORD s_dwType = GetCRC32("CGraphicExpandedImageInstance", strlen("CGraphicExpandedImageInstance"));
return (s_dwType);
}
// 40250 GrpExpandedImageInstance.cpp:29-142. The vertex and texture-coordinate arithmetic is
// verbatim; the D3D stream/blend-state calls become one UIRenderCommand with the four vertices.
auto CGraphicExpandedImageInstance::OnRender() -> void
void CGraphicExpandedImageInstance::OnSetImagePointer()
{
CGraphicImage * pImage = m_roImage.GetPointer();
CGraphicTexture * pTexture = pImage->GetTexturePointer();
if (pTexture->GetWidth() <= 0 || pTexture->GetHeight() <= 0)
if (IsEmpty())
return;
const RECT& c_rRect = pImage->GetRectReference();
float texReverseWidth = 1.0f / float(pTexture->GetWidth());
float texReverseHeight = 1.0f / float(pTexture->GetHeight());
float su = (c_rRect.left - m_RenderingRect.left) * texReverseWidth;
float sv = (c_rRect.top - m_RenderingRect.top) * texReverseHeight;
float eu = (c_rRect.left + m_RenderingRect.right + (c_rRect.right-c_rRect.left)) * texReverseWidth;
float ev = (c_rRect.top + m_RenderingRect.bottom + (c_rRect.bottom-c_rRect.top)) * texReverseHeight;
float x[4], y[4];
for (int i = 0; i < 4; ++i)
{
x[i] = m_v2Position.x-0.5f;
y[i] = m_v2Position.y-0.5f;
}
if (0.0f == m_fRotation)
{
float fimgWidth = float(pImage->GetWidth()) * m_v2Scale.x;
float fimgHeight = float(pImage->GetHeight()) * m_v2Scale.y;
x[0] -= m_RenderingRect.left;
y[0] -= m_RenderingRect.top;
x[1] += fimgWidth + m_RenderingRect.right;
y[1] -= m_RenderingRect.top;
x[2] -= m_RenderingRect.left;
y[2] += fimgHeight + m_RenderingRect.bottom;
x[3] += fimgWidth + m_RenderingRect.right;
y[3] += fimgHeight + m_RenderingRect.bottom;
// PORT: 40250 flips D3DRS_CULLMODE for a mirrored scale; the Godot canvas has no culling.
}
else
{
float fimgHalfWidth = float(pImage->GetWidth())/2.0f * m_v2Scale.x;
float fimgHalfHeight = float(pImage->GetHeight())/2.0f * m_v2Scale.y;
for (int i = 0; i < 4; ++i)
{
x[i] += m_v2Origin.x;
y[i] += m_v2Origin.y;
}
float fRadian = D3DXToRadian(m_fRotation);
x[0] += (-fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian));
y[0] += (-fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian));
x[1] += (+fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian));
y[1] += (+fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian));
x[2] += (-fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian));
y[2] += (-fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian));
x[3] += (+fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian));
y[3] += (+fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian));
}
UIRenderAddImage(pTexture, x, y, su, sv, eu, ev, UIRenderColor(m_DiffuseColor), m_iRenderingMode);
SetOrigin(float(GetWidth()) / 2.0f, float(GetHeight()) / 2.0f);
}
auto CGraphicExpandedImageInstance::OnSetImagePointer() -> void
BOOL CGraphicExpandedImageInstance::OnIsType(DWORD dwType)
{
if (!IsEmpty()) SetOrigin();
if (CGraphicExpandedImageInstance::Type() == dwType)
return TRUE;
// PORT: 40250 calls CGraphicImageInstance::IsType, which dispatches back to this override and recurses
// until the stack overflows for any other type; the base OnIsType gives the intended answer.
return CGraphicImageInstance::OnIsType(dwType);
}
auto CGraphicExpandedImageInstance::OnIsType(DWORD type) -> BOOL
void CGraphicExpandedImageInstance::Initialize()
{
return type == Type() || CGraphicImageInstance::OnIsType(type);
m_iRenderingMode = RENDERING_MODE_NORMAL;
m_fDepth = 0.0f;
m_v2Origin.x = m_v2Origin.y = 0.0f;
m_v2Scale.x = m_v2Scale.y = 1.0f;
m_fRotation = 0.0f;
memset(&m_RenderingRect, 0, sizeof(RECT));
}
auto CGraphicExpandedImageInstance::CreateSystem(UINT) -> void
void CGraphicExpandedImageInstance::Destroy()
{
MT_PLATFORM_STUB();
CGraphicImageInstance::Destroy();
Initialize();
}
auto CGraphicExpandedImageInstance::DestroySystem() -> void
CGraphicExpandedImageInstance::CGraphicExpandedImageInstance()
{
MT_PLATFORM_STUB();
Initialize();
}
auto CGraphicExpandedImageInstance::New() -> CGraphicExpandedImageInstance *
CGraphicExpandedImageInstance::~CGraphicExpandedImageInstance()
{
return new CGraphicExpandedImageInstance();
Destroy();
}
auto CGraphicExpandedImageInstance::Delete(CGraphicExpandedImageInstance *instance) -> void
{
if (!instance) return;
instance->Destroy();
delete instance;
}
decltype(CGraphicExpandedImageInstance::ms_kPool) CGraphicExpandedImageInstance::ms_kPool{};