Full 3ds support and fix dx9

This commit is contained in:
2026-03-18 11:34:36 +01:00
parent e04046720b
commit 66412ca8e0
4 changed files with 126 additions and 76 deletions

View File

@@ -55,6 +55,7 @@ struct GfxCitro3D::Impl {
shaderProgram_s pShader;
DVLB_s* pCode;
int uLocProjection = 0;
C3D_Tex* CurrentTex = nullptr;
std::vector<u8> pShaderRaw;
GPU_TEXCOLOR TextureTranslateFormat(TextureFormat fmt) {
@@ -83,14 +84,15 @@ struct GfxCitro3D::Impl {
}
}
void SetupPixelStage(GPU_TEXCOLOR clr) {
void SetupPixelStage() {
shaderProgramUse(&pShader);
C3D_BindProgram(&pShader);
C3D_SetAttrInfo(&pAttr);
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
if (!CurrentTex) return;
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
switch (clr) {
switch (CurrentTex->fmt) {
case GPU_A4:
case GPU_A8:
case GPU_L4:
@@ -142,15 +144,30 @@ void GfxCitro3D::SysDeinit() {
void GfxCitro3D::Submit(size_t count, size_t start) {
if (!impl) return;
BindTexture(CurrentTex);
impl->SetupPixelStage(); // needs to be called after
C3D_Mtx proj;
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection, &proj);
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection,
// (C3D_Mtx*)&Projection);
auto buf = C3D_GetBufInfo();
BufInfo_Init(buf);
BufInfo_Add(buf, GetVertexBufPtr(0), sizeof(Li::Vertex), 3, 0x210);
C3D_DrawElements(GPU_TRIANGLES, count, C3D_UNSIGNED_SHORT,
GetIndexBufPtr(start));
impl->CurrentTex = nullptr;
}
void GfxCitro3D::BindTexture(TextureID id) {
if (!impl) return;
if (!impl || !id) return;
impl->CurrentTex = (C3D_Tex*)id;
C3D_TexBind(0, (C3D_Tex*)id);
}
void GfxCitro3D::SysReset() {
if (!impl) return;
C3D_CullFace(GPU_CULL_NONE);
}
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
@@ -210,7 +227,7 @@ Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
if (!tex.GetID()) return;
UnRegisterTexture(tex);
UnregisterTexture(tex);
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex.GetID());
C3D_TexDelete(t);
delete t;

View File

@@ -37,7 +37,7 @@ VS_OUT main(VS_IN input) {
static const char* g_psCode = R"(
sampler2D tex : register(s0);
bool alfa;
float alfa;
struct PS_IN {
float2 uv : TEXCOORD0;
@@ -46,7 +46,7 @@ struct PS_IN {
float4 main(PS_IN input) : COLOR0 {
float4 tc = tex2D(tex, input.uv);
if (alfa)
if (alfa > 0.5)
return float4(input.col.rgb, tc.a * input.col.a);
else
return tc * input.col;
@@ -136,6 +136,7 @@ void GfxDirectX9::SysDeinit() {
void GfxDirectX9::Submit(size_t count, size_t start) {
if (!impl || !impl->Device || !impl->VBO || !impl->IBO) return;
BindTexture(CurrentTex);
impl->Device->SetVertexShaderConstantF(
0, reinterpret_cast<const float*>(&Projection), 4);
@@ -186,7 +187,7 @@ void GfxDirectX9::SysReset() {
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
if (!impl || !impl->Device) return 0;
if (!impl || !impl->Device) return Li::Texture();
IDirect3DTexture9* tex = nullptr;
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
if (type == TextureFormat::RGB24)
@@ -196,7 +197,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
HRESULT hr = impl->Device->CreateTexture(w, h, 1, 0, fmt, D3DPOOL_MANAGED,
&tex, nullptr);
if (FAILED(hr) || !tex) return 0;
if (FAILED(hr) || !tex) return Li::Texture();
D3DLOCKED_RECT rect;
tex->LockRect(0, &rect, nullptr, 0);
@@ -209,7 +210,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
u8 r = pixels[(y * w + x) * 3 + 0];
u8 g = pixels[(y * w + x) * 3 + 1];
u8 b = pixels[(y * w + x) * 3 + 2];
dst[x] = (0xFF << 24) | (r << 16) | (g << 8) | b; // X8R8G8B8
dst[x] = (0xFF << 24) | (r << 16) | (g << 8) | b;
}
dstRow += rect.Pitch;
}
@@ -222,7 +223,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
u8 g = pixels[(y * w + x) * 4 + 1];
u8 b = pixels[(y * w + x) * 4 + 2];
u8 a = pixels[(y * w + x) * 4 + 3];
dst[x] = (a << 24) | (r << 16) | (g << 8) | b; // A8R8G8B8
dst[x] = (a << 24) | (r << 16) | (g << 8) | b;
}
dstRow += rect.Pitch;
}
@@ -246,7 +247,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
if (!tex.GetID()) return;
UnRegisterTexture(tex);
UnregisterTexture(tex);
IDirect3DTexture9* t = (IDirect3DTexture9*)tex.GetID();
t->Release();
}