feat(gx): remove placeholder gx caps (#45)

This commit is contained in:
fallenoak 2023-03-09 22:29:33 -06:00 committed by GitHub
parent 0e0b57fce9
commit 907c3faf8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 57 additions and 61 deletions

View File

@ -167,6 +167,10 @@ int32_t CGxDevice::BufUnlock(CGxBuf* buf, uint32_t size) {
return 1; return 1;
} }
const CGxCaps& CGxDevice::Caps() const {
return this->m_caps;
}
int32_t CGxDevice::DeviceCreate(long (*windowProc)(void*, uint32_t, uint32_t, long), const CGxFormat& format) { int32_t CGxDevice::DeviceCreate(long (*windowProc)(void*, uint32_t, uint32_t, long), const CGxFormat& format) {
// TODO // TODO
// this->m_windowProc = windowProc; // this->m_windowProc = windowProc;

View File

@ -122,6 +122,7 @@ class CGxDevice {
// Member functions // Member functions
CGxDevice(); CGxDevice();
const CGxCaps& Caps() const;
CGxBuf* BufCreate(CGxPool*, uint32_t, uint32_t, uint32_t); CGxBuf* BufCreate(CGxPool*, uint32_t, uint32_t, uint32_t);
CGxBuf* BufStream(EGxPoolTarget, uint32_t, uint32_t); CGxBuf* BufStream(EGxPoolTarget, uint32_t, uint32_t);
void DeviceCreatePools(void); void DeviceCreatePools(void);

View File

@ -1,10 +1,6 @@
#include "gx/Gx.hpp" #include "gx/Gx.hpp"
#include "gx/Device.hpp" #include "gx/Device.hpp"
// TODO
// - remove placeholder after proper implementation
static CGxCaps* g_placeholderGxCaps = new CGxCaps();
const char* vsProfileNames[] = { const char* vsProfileNames[] = {
"none", "vs_1_1", "vs_2_0", "vs_3_0", "vs_4_0", "vs_5_0", "arbvp1", "arbvp1_cg12", "nvvp", "nvvp2", "nvvp3", "glsl" "none", "vs_1_1", "vs_2_0", "vs_3_0", "vs_4_0", "vs_5_0", "arbvp1", "arbvp1_cg12", "nvvp", "nvvp2", "nvvp3", "glsl"
}; };
@ -38,37 +34,8 @@ const char** g_gxShaderProfileNames[GxShTargets_Last] = {
csProfileNames csProfileNames
}; };
CGxCaps* GxCaps() { const CGxCaps& GxCaps() {
// TODO return g_theGxDevicePtr->Caps();
g_placeholderGxCaps->m_pixelCenterOnEdge = 1;
g_placeholderGxCaps->m_texelCenterOnEdge = 1;
g_placeholderGxCaps->m_colorFormat = GxCF_rgba;
g_placeholderGxCaps->m_generateMipMaps = 1;
g_placeholderGxCaps->m_texFmtDxt1 = 1;
g_placeholderGxCaps->m_texFmtDxt3 = 1;
g_placeholderGxCaps->m_texFmtDxt5 = 1;
g_placeholderGxCaps->m_vertexShaderTarget = GxShVS_arbvp1;
g_placeholderGxCaps->m_pixelShaderTarget = GxShPS_arbfp1;
g_placeholderGxCaps->m_texFilterAnisotropic = 1;
g_placeholderGxCaps->m_maxTexAnisotropy = 16;
g_placeholderGxCaps->m_texTarget[GxTex_2d] = 1;
g_placeholderGxCaps->m_texTarget[GxTex_CubeMap] = 1;
g_placeholderGxCaps->m_texTarget[GxTex_Rectangle] = 1;
g_placeholderGxCaps->m_texTarget[GxTex_NonPow2] = 1;
g_placeholderGxCaps->m_texMaxSize[GxTex_2d] = 4096;
g_placeholderGxCaps->m_texMaxSize[GxTex_CubeMap] = 4096;
g_placeholderGxCaps->m_texMaxSize[GxTex_Rectangle] = 4096;
g_placeholderGxCaps->m_texMaxSize[GxTex_NonPow2] = 4096;
return g_placeholderGxCaps;
} }
bool GxCapsWindowHasFocus(int32_t a1) { bool GxCapsWindowHasFocus(int32_t a1) {
@ -81,7 +48,7 @@ void GxCapsWindowSize(CRect& rect) {
} }
void GxFormatColor(CImVector& color) { void GxFormatColor(CImVector& color) {
if (GxCaps()->m_colorFormat == GxCF_rgba) { if (GxCaps().m_colorFormat == GxCF_rgba) {
CImVector formattedColor = { CImVector formattedColor = {
color.r, color.r,
color.g, color.g,

View File

@ -10,7 +10,7 @@ class CRect;
extern const char** g_gxShaderProfileNames[GxShTargets_Last]; extern const char** g_gxShaderProfileNames[GxShTargets_Last];
CGxCaps* GxCaps(void); const CGxCaps& GxCaps();
bool GxCapsWindowHasFocus(int32_t); bool GxCapsWindowHasFocus(int32_t);

View File

@ -243,17 +243,17 @@ int32_t GxTexCreate(EGxTexTarget target, uint32_t width, uint32_t height, uint32
texId = nullptr; texId = nullptr;
STORM_ASSERT(target <= GxTexTargets_Last); STORM_ASSERT(target <= GxTexTargets_Last);
STORM_ASSERT(GxCaps()->m_texTarget[target] == 1); STORM_ASSERT(GxCaps().m_texTarget[target] == 1);
STORM_ASSERT(width >= 8); STORM_ASSERT(width >= 8);
STORM_ASSERT(height >= 8); STORM_ASSERT(height >= 8);
STORM_ASSERT(width <= GxCaps()->m_texMaxSize[target]); STORM_ASSERT(width <= GxCaps().m_texMaxSize[target]);
STORM_ASSERT(height <= GxCaps()->m_texMaxSize[target]); STORM_ASSERT(height <= GxCaps().m_texMaxSize[target]);
STORM_ASSERT((target != GxTex_Rectangle && target != GxTex_NonPow2) ? (width & (width - 1)) == 0 : 1); STORM_ASSERT((target != GxTex_Rectangle && target != GxTex_NonPow2) ? (width & (width - 1)) == 0 : 1);
STORM_ASSERT((target != GxTex_Rectangle && target != GxTex_NonPow2) ? (height & (height - 1)) == 0 : 1); STORM_ASSERT((target != GxTex_Rectangle && target != GxTex_NonPow2) ? (height & (height - 1)) == 0 : 1);
STORM_ASSERT((target == GxTex_Rectangle) ? flags.m_filter <= GxTex_Linear : 1); STORM_ASSERT((target == GxTex_Rectangle) ? flags.m_filter <= GxTex_Linear : 1);
STORM_ASSERT(format <= GxTexFormats_Last); STORM_ASSERT(format <= GxTexFormats_Last);
STORM_ASSERT((flags.m_generateMipMaps) ? (GxCaps()->m_generateMipMaps && !(format >= GxTex_Dxt1 && format <= GxTex_Dxt5)) : 1); STORM_ASSERT((flags.m_generateMipMaps) ? (GxCaps().m_generateMipMaps && !(format >= GxTex_Dxt1 && format <= GxTex_Dxt5)) : 1);
STORM_ASSERT((flags.m_filter == GxTex_Anisotropic) ? GxCaps()->m_texFilterAnisotropic : 1); STORM_ASSERT((flags.m_filter == GxTex_Anisotropic) ? GxCaps().m_texFilterAnisotropic : 1);
STORM_ASSERT(dataFormat <= GxTexFormats_Last); STORM_ASSERT(dataFormat <= GxTexFormats_Last);
STORM_ASSERT(userFunc != nullptr); STORM_ASSERT(userFunc != nullptr);
@ -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) { void GetTextureFormats(PIXEL_FORMAT* pixFormat, EGxTexFormat* gxTexFormat, PIXEL_FORMAT preferredFormat, int32_t alphaBits) {
switch (preferredFormat) { switch (preferredFormat) {
case PIXEL_DXT1: case PIXEL_DXT1:
if (GxCaps()->m_texFmtDxt1) { if (GxCaps().m_texFmtDxt1) {
*gxTexFormat = GxTex_Dxt1; *gxTexFormat = GxTex_Dxt1;
*pixFormat = PIXEL_DXT1; *pixFormat = PIXEL_DXT1;
} else if (alphaBits) { } else if (alphaBits) {
@ -408,7 +408,7 @@ void GetTextureFormats(PIXEL_FORMAT* pixFormat, EGxTexFormat* gxTexFormat, PIXEL
break; break;
case PIXEL_DXT3: case PIXEL_DXT3:
if (GxCaps()->m_texFmtDxt3) { if (GxCaps().m_texFmtDxt3) {
*gxTexFormat = GxTex_Dxt3; *gxTexFormat = GxTex_Dxt3;
*pixFormat = PIXEL_DXT3; *pixFormat = PIXEL_DXT3;
} else { } else {
@ -443,7 +443,7 @@ void GetTextureFormats(PIXEL_FORMAT* pixFormat, EGxTexFormat* gxTexFormat, PIXEL
break; break;
case PIXEL_DXT5: case PIXEL_DXT5:
if (GxCaps()->m_texFmtDxt5) { if (GxCaps().m_texFmtDxt5) {
*gxTexFormat = GxTex_Dxt5; *gxTexFormat = GxTex_Dxt5;
*pixFormat = PIXEL_DXT5; *pixFormat = PIXEL_DXT5;
} else { } else {
@ -508,7 +508,7 @@ uint32_t MippedImgCalcSize(uint32_t fourCC, uint32_t width, uint32_t height) {
// - order: width, height or height, width? // - order: width, height or height, width?
void RequestImageDimensions(uint32_t* width, uint32_t* height, uint32_t* bestMip) { void RequestImageDimensions(uint32_t* width, uint32_t* height, uint32_t* bestMip) {
CGxCaps systemCaps; CGxCaps systemCaps;
memcpy(&systemCaps, GxCaps(), sizeof(systemCaps)); memcpy(&systemCaps, &GxCaps(), sizeof(systemCaps));
auto maxTextureSize = systemCaps.m_texMaxSize[GxTex_2d]; auto maxTextureSize = systemCaps.m_texMaxSize[GxTex_2d];

View File

@ -24,7 +24,7 @@ int32_t SetProjection() {
float v14 = 0.0f; float v14 = 0.0f;
float v15 = 0.0f; float v15 = 0.0f;
if (!GxCaps()->m_pixelCenterOnEdge) { if (!GxCaps().m_pixelCenterOnEdge) {
v14 = -0.5f; v14 = -0.5f;
v15 = 0.5f; v15 = 0.5f;
} }

View File

@ -206,7 +206,7 @@ int32_t CGxDeviceGLL::DeviceCreate(long (*windowProc)(void*, uint32_t, uint32_t,
GLDevice::SetOption(GLDevice::eUseHybridShader, true); GLDevice::SetOption(GLDevice::eUseHybridShader, true);
this->ISetCaps(); this->ISetCaps(format);
// TODO // TODO
// CGxDevice::Log(this, this + 604); // CGxDevice::Log(this, this + 604);
@ -662,12 +662,36 @@ void CGxDeviceGLL::ISceneBegin() {
// TODO GameMovie::ReadFrame(this); // TODO GameMovie::ReadFrame(this);
} }
void CGxDeviceGLL::ISetCaps() { void CGxDeviceGLL::ISetCaps(const CGxFormat& format) {
// TODO // TODO fill in proper implementation
this->m_caps.m_pixelCenterOnEdge = 1; this->m_caps.m_pixelCenterOnEdge = 1;
this->m_caps.m_texelCenterOnEdge = 1; this->m_caps.m_texelCenterOnEdge = 1;
this->m_caps.m_colorFormat = GxCF_rgba;
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_vertexShaderTarget = GxShVS_arbvp1;
this->m_caps.m_pixelShaderTarget = GxShPS_arbfp1;
this->m_caps.m_texFilterAnisotropic = 1;
this->m_caps.m_maxTexAnisotropy = 16;
this->m_caps.m_texTarget[GxTex_2d] = 1;
this->m_caps.m_texTarget[GxTex_CubeMap] = 1;
this->m_caps.m_texTarget[GxTex_Rectangle] = 1;
this->m_caps.m_texTarget[GxTex_NonPow2] = 1;
this->m_caps.m_texMaxSize[GxTex_2d] = 4096;
this->m_caps.m_texMaxSize[GxTex_CubeMap] = 4096;
this->m_caps.m_texMaxSize[GxTex_Rectangle] = 4096;
this->m_caps.m_texMaxSize[GxTex_NonPow2] = 4096;
// TODO // TODO
} }

View File

@ -52,7 +52,7 @@ class CGxDeviceGLL : public CGxDevice {
char* IBufLock(CGxBuf*); char* IBufLock(CGxBuf*);
int32_t IBufUnlock(CGxBuf*); int32_t IBufUnlock(CGxBuf*);
void ISceneBegin(); void ISceneBegin();
void ISetCaps(void); void ISetCaps(const CGxFormat& format);
void IShaderBindPixel(CGxShader*); void IShaderBindPixel(CGxShader*);
void IShaderBindVertex(CGxShader*); void IShaderBindVertex(CGxShader*);
void IShaderConstantsFlush(void); void IShaderConstantsFlush(void);

View File

@ -31,7 +31,7 @@ void CShaderEffect::InitShaderSystem(int32_t enableShaders, int32_t usePcf) {
CShaderEffect::s_usePcfFiltering = enableShaders && usePcf ? 1 : 0; CShaderEffect::s_usePcfFiltering = enableShaders && usePcf ? 1 : 0;
CShaderEffect::s_fogMul = 1.0f; CShaderEffect::s_fogMul = 1.0f;
CShaderEffect::s_useAlphaRef = GxCaps()->int130; CShaderEffect::s_useAlphaRef = GxCaps().int130;
} }
void CShaderEffect::SetAlphaRef(float alphaRef) { void CShaderEffect::SetAlphaRef(float alphaRef) {
@ -65,13 +65,13 @@ void CShaderEffect::SetEmissive(const C4Vector& emissive) {
void CShaderEffect::SetFogEnabled(int32_t fogEnabled) { void CShaderEffect::SetFogEnabled(int32_t fogEnabled) {
if (fogEnabled && GxMasterEnable(GxMasterEnable_Fog)) { if (fogEnabled && GxMasterEnable(GxMasterEnable_Fog)) {
if (CShaderEffect::s_enableShaders && !GxCaps()->int138) { if (CShaderEffect::s_enableShaders && !GxCaps().int138) {
GxShaderConstantsSet(GxSh_Vertex, 30, reinterpret_cast<float*>(&CShaderEffect::s_fogParams), 1); GxShaderConstantsSet(GxSh_Vertex, 30, reinterpret_cast<float*>(&CShaderEffect::s_fogParams), 1);
} else { } else {
GxRsSet(GxRs_Fog, 1); GxRsSet(GxRs_Fog, 1);
} }
} else { } else {
if (CShaderEffect::s_enableShaders && !GxCaps()->int138) { if (CShaderEffect::s_enableShaders && !GxCaps().int138) {
float fogParams[] = { 0.0f, 1.0f, 1.0f, 0.0f }; float fogParams[] = { 0.0f, 1.0f, 1.0f, 0.0f };
GxShaderConstantsSet(GxSh_Vertex, 30, fogParams, 1); GxShaderConstantsSet(GxSh_Vertex, 30, fogParams, 1);
} else { } else {
@ -92,7 +92,7 @@ void CShaderEffect::SetFogParams(float fogStart, float fogEnd, float fogRate, co
CShaderEffect::s_fogParams.z = fogRate; CShaderEffect::s_fogParams.z = fogRate;
CShaderEffect::s_fogParams.w = 0.0f; CShaderEffect::s_fogParams.w = 0.0f;
if (!GxCaps()->int134) { if (!GxCaps().int134) {
GxShaderConstantsSet(GxSh_Pixel, 2, reinterpret_cast<float*>(&CShaderEffect::s_fogColorAlphaRef), 1); GxShaderConstantsSet(GxSh_Pixel, 2, reinterpret_cast<float*>(&CShaderEffect::s_fogColorAlphaRef), 1);
return; return;
} }

View File

@ -9,7 +9,7 @@ CGxTexFlags::CGxTexFlags(EGxTexFilter filter, uint32_t wrapU, uint32_t wrapV, ui
this->m_forceMipTracking = force; this->m_forceMipTracking = force;
this->m_generateMipMaps = generateMipMaps; this->m_generateMipMaps = generateMipMaps;
this->m_renderTarget = renderTarget; this->m_renderTarget = renderTarget;
this->m_maxAnisotropy = std::min(maxAnisotropy, GxCaps()->m_maxTexAnisotropy); this->m_maxAnisotropy = std::min(maxAnisotropy, GxCaps().m_maxTexAnisotropy);
// TODO // TODO
this->m_bit13 = 0; this->m_bit13 = 0;

View File

@ -73,7 +73,7 @@ int32_t CM2Cache::Initialize(uint32_t flags) {
// TODO // TODO
if (flags & 0x8) { if (flags & 0x8) {
if (GxCaps()->m_vertexShaderTarget > GxShVS_none && GxCaps()->m_pixelShaderTarget > GxShPS_none) { if (GxCaps().m_vertexShaderTarget > GxShVS_none && GxCaps().m_pixelShaderTarget > GxShPS_none) {
this->m_flags |= 0x8; this->m_flags |= 0x8;
} }
} }

View File

@ -62,7 +62,7 @@ void CM2Scene::ComputeElementShaders(M2Element* element) {
} }
} }
int32_t v9 = v18 && (/* TODO !GxCaps()->dword130 ||*/ v8); int32_t v9 = v18 && (/* TODO !GxCaps().dword130 ||*/ v8);
int32_t v10 = std::min(boneInfluences, 2); int32_t v10 = std::min(boneInfluences, 2);
int32_t v11 = std::min(v8, 2); int32_t v11 = std::min(v8, 2);

View File

@ -97,7 +97,7 @@ void CSimpleRender::DrawBatch(CRenderBatch* batch) {
if (mesh->color) { if (mesh->color) {
auto& color = mesh->color[i * mesh->colorCount >> 2]; auto& color = mesh->color[i * mesh->colorCount >> 2];
if (GxCaps()->m_colorFormat == GxCF_rgba) { if (GxCaps().m_colorFormat == GxCF_rgba) {
vertexBuf->c.r = color.b; vertexBuf->c.r = color.b;
vertexBuf->c.g = color.g; vertexBuf->c.g = color.g;
vertexBuf->c.b = color.r; vertexBuf->c.b = color.r;

View File

@ -24,11 +24,11 @@ void CWorld::Initialize() {
// TODO // TODO
if (GxCaps()->m_pixelShaderTarget > GxShPS_none) { if (GxCaps().m_pixelShaderTarget > GxShPS_none) {
CWorld::s_enables |= Enables::Enable_PixelShader; CWorld::s_enables |= Enables::Enable_PixelShader;
} }
if (GxCaps()->m_vertexShaderTarget > GxShVS_none) { if (GxCaps().m_vertexShaderTarget > GxShVS_none) {
CWorld::s_enables2 |= Enables2::Enable_VertexShader; CWorld::s_enables2 |= Enables2::Enable_VertexShader;
} }