From 80284ad816dea7a4e9d9b25b6c8c10e54a28a695 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 3 Apr 2016 19:00:40 -1000 Subject: [PATCH] Update GLSL backend for proper block bindings --- hecl/extern/boo | 2 +- hecl/include/hecl/Backend/GLSL.hpp | 3 +++ hecl/include/hecl/Runtime.hpp | 6 +++++- hecl/lib/Backend/GLSL.cpp | 29 ++++++++++++++++++++++------- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/hecl/extern/boo b/hecl/extern/boo index af188afc8..54ae8c2b1 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit af188afc819a388e34b7b00b8e4e524ff83c94e9 +Subproject commit 54ae8c2b1a2ce58cabbebacd0ec4c0b16d92cd8c diff --git a/hecl/include/hecl/Backend/GLSL.hpp b/hecl/include/hecl/Backend/GLSL.hpp index bb0443b3d..8534a9033 100644 --- a/hecl/include/hecl/Backend/GLSL.hpp +++ b/hecl/include/hecl/Backend/GLSL.hpp @@ -8,6 +8,9 @@ namespace hecl namespace Backend { +#define HECL_GLSL_VERT_UNIFORM_BLOCK_NAME "HECLVertUniform" +#define HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME "HECLTexMtxUniform" + struct GLSL : ProgrammableCommon { void reset(const IR& ir, Diagnostics& diag); diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index 9930a213b..86c000074 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -128,6 +128,8 @@ public: { Function lighting; Function post; + size_t blockCount = 0; + const char** blockNames = nullptr; }; std::vector m_extensionSlots; @@ -139,12 +141,14 @@ public: operator bool() const {return m_plat != boo::IGraphicsDataFactory::Platform::Null;} /* Strings must remain resident!! (intended to be stored static const) */ - unsigned registerExtensionSlot(Function lighting, Function post) + unsigned registerExtensionSlot(Function lighting, Function post, size_t blockCount, const char** blockNames) { m_extensionSlots.emplace_back(); ExtensionSlot& slot = m_extensionSlots.back(); slot.lighting = lighting; slot.post = post; + slot.blockCount = blockCount; + slot.blockNames = blockNames; return m_extensionSlots.size() - 1; } }; diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index b76036002..9a48c3225 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -253,7 +253,8 @@ std::string GLSL::makeFrag(const char* glslVer, namespace Runtime { -static const char* STD_BLOCKNAMES[] = {"HECLVertUniform"}; +static const char* STD_BLOCKNAMES[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME, + HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME}; struct GLSLBackendFactory : IShaderBackendFactory { @@ -280,7 +281,7 @@ struct GLSLBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), m_backend.m_texMapEnd, "texs", - 1, STD_BLOCKNAMES, + 2, STD_BLOCKNAMES, m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); @@ -312,7 +313,7 @@ struct GLSLBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), texMapEnd, "texs", - 1, STD_BLOCKNAMES, + 2, STD_BLOCKNAMES, blendSrc, blendDst, tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); @@ -341,13 +342,20 @@ struct GLSLBackendFactory : IShaderBackendFactory fragSources.reserve(extensionSlots.size()); for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots) { + size_t bc = 2; + const char** bn = STD_BLOCKNAMES; + if (slot.blockCount) + { + bc = slot.blockCount; + bn = slot.blockNames; + } + fragSources.push_back(m_backend.makeFrag("#version 330", slot.lighting, slot.post)); cachedSz += fragSources.back().size() + 1; boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(), - m_backend.m_texMapEnd, "texs", - 1, STD_BLOCKNAMES, + m_backend.m_texMapEnd, "texs", bc, bn, m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); @@ -381,12 +389,19 @@ struct GLSLBackendFactory : IShaderBackendFactory std::string vertSource = r.readString(); for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots) { + size_t bc = 2; + const char** bn = STD_BLOCKNAMES; + if (slot.blockCount) + { + bc = slot.blockCount; + bn = slot.blockNames; + } + std::string fragSource = r.readString(); boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - texMapEnd, "texs", - 1, STD_BLOCKNAMES, + texMapEnd, "texs", bc, bn, blendSrc, blendDst, tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling());