diff --git a/src/services/impl/bgfx_graphics_backend.cpp b/src/services/impl/bgfx_graphics_backend.cpp index c9bd8d7..c6c8bf9 100644 --- a/src/services/impl/bgfx_graphics_backend.cpp +++ b/src/services/impl/bgfx_graphics_backend.cpp @@ -51,10 +51,8 @@ bool IsIdentityMatrix(const std::array& value) { } uint64_t DefaultSamplerFlags() { - return BGFX_SAMPLER_U_REPEAT | - BGFX_SAMPLER_V_REPEAT | - BGFX_SAMPLER_MIN_LINEAR | - BGFX_SAMPLER_MAG_LINEAR; + // Repeat + linear are the default sampler state in bgfx; no flags needed. + return 0; } bgfx::TextureHandle CreateSolidTexture(uint32_t rgba, uint64_t flags) { @@ -818,35 +816,51 @@ GraphicsPipelineHandle BgfxGraphicsBackend::CreatePipeline(GraphicsDeviceHandle if (!shaderPaths.textures.empty()) { const uint64_t samplerFlags = DefaultSamplerFlags(); uint8_t stage = 0; - const uint8_t maxStages = BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; - for (const auto& texture : shaderPaths.textures) { - if (stage >= maxStages) { - if (logger_) { - logger_->Warn("BgfxGraphicsBackend::CreatePipeline: texture limit reached for " + - shaderKey); - } - break; - } - if (texture.uniformName.empty() || texture.path.empty()) { - continue; - } - PipelineEntry::TextureBinding binding{}; - binding.stage = stage++; - binding.uniformName = texture.uniformName; - binding.sourcePath = texture.path; - binding.sampler = bgfx::createUniform(binding.uniformName.c_str(), bgfx::UniformType::Sampler); - binding.texture = LoadTextureFromFile(binding.sourcePath, samplerFlags); - if (!bgfx::isValid(binding.texture)) { - binding.texture = CreateSolidTexture(0xff00ffff, samplerFlags); - } + const bgfx::Caps* caps = bgfx::getCaps(); + uint8_t maxStages = 0; + if (caps) { + maxStages = static_cast(std::min(caps->limits.maxTextureSamplers, 255u)); + } + if (logger_) { + logger_->Trace("BgfxGraphicsBackend", "CreatePipeline", + "maxTextureSamplers=" + std::to_string(maxStages)); + } + if (maxStages == 0) { if (logger_) { - logger_->Trace("BgfxGraphicsBackend", "CreatePipeline", - "shaderKey=" + shaderKey + - ", textureUniform=" + binding.uniformName + - ", texturePath=" + binding.sourcePath + - ", stage=" + std::to_string(binding.stage)); + logger_->Warn("BgfxGraphicsBackend::CreatePipeline: maxTextureSamplers unavailable for " + + shaderKey); + } + } else { + for (const auto& texture : shaderPaths.textures) { + if (stage >= maxStages) { + if (logger_) { + logger_->Warn("BgfxGraphicsBackend::CreatePipeline: texture limit reached for " + + shaderKey); + } + break; + } + if (texture.uniformName.empty() || texture.path.empty()) { + continue; + } + PipelineEntry::TextureBinding binding{}; + binding.stage = stage++; + binding.uniformName = texture.uniformName; + binding.sourcePath = texture.path; + binding.sampler = bgfx::createUniform(binding.uniformName.c_str(), + bgfx::UniformType::Sampler); + binding.texture = LoadTextureFromFile(binding.sourcePath, samplerFlags); + if (!bgfx::isValid(binding.texture)) { + binding.texture = CreateSolidTexture(0xff00ffff, samplerFlags); + } + if (logger_) { + logger_->Trace("BgfxGraphicsBackend", "CreatePipeline", + "shaderKey=" + shaderKey + + ", textureUniform=" + binding.uniformName + + ", texturePath=" + binding.sourcePath + + ", stage=" + std::to_string(binding.stage)); + } + entry->textures.push_back(std::move(binding)); } - entry->textures.push_back(std::move(binding)); } } GraphicsPipelineHandle handle = reinterpret_cast(entry.get()); diff --git a/src/services/impl/bgfx_gui_service.cpp b/src/services/impl/bgfx_gui_service.cpp index ad4d152..ba9aed0 100644 --- a/src/services/impl/bgfx_gui_service.cpp +++ b/src/services/impl/bgfx_gui_service.cpp @@ -10,7 +10,7 @@ #include #include FT_FREETYPE_H -#include +#include #include #include @@ -23,9 +23,7 @@ namespace sdl3cpp::services::impl { namespace { constexpr uint64_t kGuiSamplerFlags = BGFX_SAMPLER_U_CLAMP | - BGFX_SAMPLER_V_CLAMP | - BGFX_SAMPLER_MIN_LINEAR | - BGFX_SAMPLER_MAG_LINEAR; + BGFX_SAMPLER_V_CLAMP; const char* kGuiVertexSource = R"( #version 450