From 9fe6bc9cd678a4b077bfd8275e82dc4e96d84e46 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 9 Mar 2023 23:10:25 -0600 Subject: [PATCH] feat(gx): set supported texture formats in gx caps --- src/gx/CGxCaps.hpp | 4 +--- src/gx/Texture.cpp | 6 +++--- src/gx/d3d/CGxDeviceD3d.cpp | 18 +++++++++++++++++- src/gx/d3d/CGxDeviceD3d.hpp | 1 + src/gx/gll/CGxDeviceGLL.cpp | 6 +++--- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gx/CGxCaps.hpp b/src/gx/CGxCaps.hpp index aa5c180..546fd62 100644 --- a/src/gx/CGxCaps.hpp +++ b/src/gx/CGxCaps.hpp @@ -14,11 +14,9 @@ class CGxCaps { EGxColorFormat m_colorFormat = GxCF_argb; uint32_t m_maxIndex = 0; int32_t m_generateMipMaps = 0; + int32_t m_texFmt[GxTexFormats_Last] = { 0 }; int32_t m_texTarget[GxTexTargets_Last]; uint32_t m_texMaxSize[GxTexTargets_Last]; - int32_t m_texFmtDxt1 = 0; - int32_t m_texFmtDxt3 = 0; - int32_t m_texFmtDxt5 = 0; EGxShVS m_vertexShaderTarget = GxShVS_none; EGxShPS m_pixelShaderTarget = GxShPS_none; int32_t m_texFilterTrilinear = 0; diff --git a/src/gx/Texture.cpp b/src/gx/Texture.cpp index 941f0c2..a97c494 100644 --- a/src/gx/Texture.cpp +++ b/src/gx/Texture.cpp @@ -394,7 +394,7 @@ void GetDefaultTexture(uint32_t height, uint32_t width) { void GetTextureFormats(PIXEL_FORMAT* pixFormat, EGxTexFormat* gxTexFormat, PIXEL_FORMAT preferredFormat, int32_t alphaBits) { switch (preferredFormat) { case PIXEL_DXT1: - if (GxCaps().m_texFmtDxt1) { + if (GxCaps().m_texFmt[GxTex_Dxt1]) { *gxTexFormat = GxTex_Dxt1; *pixFormat = PIXEL_DXT1; } else if (alphaBits) { @@ -408,7 +408,7 @@ void GetTextureFormats(PIXEL_FORMAT* pixFormat, EGxTexFormat* gxTexFormat, PIXEL break; case PIXEL_DXT3: - if (GxCaps().m_texFmtDxt3) { + if (GxCaps().m_texFmt[GxTex_Dxt3]) { *gxTexFormat = GxTex_Dxt3; *pixFormat = PIXEL_DXT3; } else { @@ -443,7 +443,7 @@ void GetTextureFormats(PIXEL_FORMAT* pixFormat, EGxTexFormat* gxTexFormat, PIXEL break; case PIXEL_DXT5: - if (GxCaps().m_texFmtDxt5) { + if (GxCaps().m_texFmt[GxTex_Dxt5]) { *gxTexFormat = GxTex_Dxt5; *pixFormat = PIXEL_DXT5; } else { diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index ea8e7dc..948cba4 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -480,6 +480,7 @@ int32_t CGxDeviceD3d::ICreateD3dDevice(const CGxFormat& format) { if (SUCCEEDED(this->m_d3d->CreateDevice(0, D3DDEVTYPE_HAL, this->m_hwnd, behaviorFlags, &d3dpp, &this->m_d3dDevice))) { // TODO + this->m_devAdapterFormat = d3dpp.BackBufferFormat; this->m_context = 1; // TODO @@ -702,7 +703,22 @@ void CGxDeviceD3d::ISetCaps(const CGxFormat& format) { // TODO modify shader targets based on format - // TODO + // Texture formats + + for (int32_t i = 0; i < GxTexFormats_Last; i++) { + if (i == GxTex_Unknown) { + this->m_caps.m_texFmt[i] = 0; + } else { + this->m_caps.m_texFmt[i] = this->m_d3d->CheckDeviceFormat( + 0, + D3DDEVTYPE_HAL, + this->m_devAdapterFormat, + 0, + D3DRTYPE_TEXTURE, + CGxDeviceD3d::s_GxTexFmtToD3dFmt[i] + ) == D3D_OK; + } + } this->m_caps.m_generateMipMaps = (this->m_d3dCaps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP) != 0; diff --git a/src/gx/d3d/CGxDeviceD3d.hpp b/src/gx/d3d/CGxDeviceD3d.hpp index 02b8ffb..d26fd21 100644 --- a/src/gx/d3d/CGxDeviceD3d.hpp +++ b/src/gx/d3d/CGxDeviceD3d.hpp @@ -218,6 +218,7 @@ class CGxDeviceD3d : public CGxDevice { D3DCAPS9 m_d3dCaps; int32_t m_d3dIsHwDevice = 0; D3DDISPLAYMODE m_desktopDisplayMode; + D3DFORMAT m_devAdapterFormat; uint32_t m_deviceStates[DeviceStates_Last]; // Virtual member functions diff --git a/src/gx/gll/CGxDeviceGLL.cpp b/src/gx/gll/CGxDeviceGLL.cpp index c064130..4d8ac43 100644 --- a/src/gx/gll/CGxDeviceGLL.cpp +++ b/src/gx/gll/CGxDeviceGLL.cpp @@ -672,9 +672,9 @@ void CGxDeviceGLL::ISetCaps(const CGxFormat& format) { this->m_caps.m_generateMipMaps = 1; - this->m_caps.m_texFmtDxt1 = 1; - this->m_caps.m_texFmtDxt3 = 1; - this->m_caps.m_texFmtDxt5 = 1; + this->m_caps.m_texFmt[GxTex_Dxt1] = 1; + this->m_caps.m_texFmt[GxTex_Dxt3] = 1; + this->m_caps.m_texFmt[GxTex_Dxt5] = 1; this->m_caps.m_vertexShaderTarget = GxShVS_arbvp1; this->m_caps.m_pixelShaderTarget = GxShPS_arbfp1;