From 99ea94de39c2131a19939ee95980a389166cde86 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 14 Jan 2016 11:12:29 -1000 Subject: [PATCH] Integrate glslang AST compilation --- hecl/CMakeLists.txt | 2 +- hecl/extern/libBoo | 2 +- hecl/include/HECL/Backend/GLSL.hpp | 9 ++ hecl/include/HECL/Runtime.hpp | 5 +- hecl/lib/Backend/GLSL.cpp | 142 +++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 4 deletions(-) diff --git a/hecl/CMakeLists.txt b/hecl/CMakeLists.txt index 4fbe9c9db..aed4b1f9b 100644 --- a/hecl/CMakeLists.txt +++ b/hecl/CMakeLists.txt @@ -20,7 +20,7 @@ set(ATHENA_INCLUDE_DIR ${ATHENA_INCLUDE_DIR} PARENT_SCOPE) set(SQUISH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/libSquish) set(SQUISH_INCLUDE_DIR ${SQUISH_INCLUDE_DIR} PARENT_SCOPE) -set(BOO_INCLUDE_DIR extern/libBoo/include) +set(BOO_INCLUDE_DIR extern/libBoo/include extern/libBoo/glslang) add_subdirectory(bintoc) add_subdirectory(extern) diff --git a/hecl/extern/libBoo b/hecl/extern/libBoo index 9b416c654..a79f55c5c 160000 --- a/hecl/extern/libBoo +++ b/hecl/extern/libBoo @@ -1 +1 @@ -Subproject commit 9b416c6549d49ad6302c1f7a1612d051f68ad7fa +Subproject commit a79f55c5c19f98a8699e276c191ef047c1be3afa diff --git a/hecl/include/HECL/Backend/GLSL.hpp b/hecl/include/HECL/Backend/GLSL.hpp index 461bb6fe2..3bd05fdf2 100644 --- a/hecl/include/HECL/Backend/GLSL.hpp +++ b/hecl/include/HECL/Backend/GLSL.hpp @@ -2,6 +2,7 @@ #define HECLBACKEND_GLSL_HPP #include "ProgrammableCommon.hpp" +#include namespace HECL { @@ -19,6 +20,14 @@ struct GLSL : ProgrammableCommon const ShaderFunction& lighting, const ShaderFunction& post) const; + glslang::TShader makeVertAST(const char* glslVer, unsigned col, unsigned uv, unsigned w, + unsigned skinSlots, unsigned texMtxs) const; + glslang::TShader makeFragAST(const char* glslVer, + const ShaderFunction& lighting=ShaderFunction()) const; + glslang::TShader makeFragAST(const char* glslVer, + const ShaderFunction& lighting, + const ShaderFunction& post) const; + private: std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const; std::string GenerateVertToFragStruct() const; diff --git a/hecl/include/HECL/Runtime.hpp b/hecl/include/HECL/Runtime.hpp index cdfc95d43..7d1ad9bbe 100644 --- a/hecl/include/HECL/Runtime.hpp +++ b/hecl/include/HECL/Runtime.hpp @@ -140,8 +140,9 @@ public: unsigned registerExtensionSlot(Function lighting, Function post) { m_extensionSlots.emplace_back(); - m_extensionSlots.back().lighting = lighting; - m_extensionSlots.back().post = post; + ExtensionSlot& slot = m_extensionSlots.back(); + slot.lighting = lighting; + slot.post = post; return m_extensionSlots.size() - 1; } }; diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index 326e7f89e..73acff38b 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -6,6 +6,105 @@ static LogVisor::LogModule Log("HECL::Backend::GLSL"); +static const TBuiltInResource DefaultBuiltInResource = +{ + 32, + 6, + 32, + 32, + 64, + 4096, + 64, + 32, + 80, + 32, + 4096, + 32, + 128, + 8, + 16, + 16, + 15, + -8, + 7, + 8, + 65535, + 65535, + 65535, + 1024, + 1024, + 64, + 1024, + 16, + 8, + 8, + 1, + 60, + 64, + 64, + 128, + 128, + 8, + 8, + 8, + 0, + 0, + 0, + 0, + 0, + 8, + 8, + 16, + 256, + 1024, + 1024, + 64, + 128, + 128, + 16, + 1024, + 4096, + 128, + 128, + 16, + 1024, + 120, + 32, + 64, + 16, + 0, + 0, + 0, + 0, + 8, + 8, + 1, + 0, + 0, + 0, + 0, + 1, + 1, + 16384, + 4, + 64, + 8, + 8, + 4, + + { + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + } +}; + namespace HECL { namespace Backend @@ -150,6 +249,20 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig return retval + "}\n"; } +glslang::TShader GLSL::makeVertAST(const char* glslVer, unsigned col, unsigned uv, unsigned w, + unsigned s, unsigned tm) const +{ + std::string src = makeVert(glslVer, col, uv, w, s, tm); + const char* strs[] = {src.data()}; + int lens[] = {int(src.size())}; + + glslang::TShader ret(EShLangVertex); + ret.setStringsWithLengths(strs, lens, 1); + ret.parse(&DefaultBuiltInResource, 110, true, EShMsgDefault); + + return ret; +} + std::string GLSL::makeFrag(const char* glslVer, const ShaderFunction& lighting) const { @@ -191,6 +304,20 @@ std::string GLSL::makeFrag(const char* glslVer, return retval + "}\n"; } +glslang::TShader GLSL::makeFragAST(const char* glslVer, + const ShaderFunction& lighting) const +{ + std::string src = makeFrag(glslVer, lighting); + const char* strs[] = {src.data()}; + int lens[] = {int(src.size())}; + + glslang::TShader ret(EShLangFragment); + ret.setStringsWithLengths(strs, lens, 1); + ret.parse(&DefaultBuiltInResource, 110, true, EShMsgDefault); + + return ret; +} + std::string GLSL::makeFrag(const char* glslVer, const ShaderFunction& lighting, const ShaderFunction& post) const @@ -241,6 +368,21 @@ std::string GLSL::makeFrag(const char* glslVer, return retval + "}\n"; } +glslang::TShader GLSL::makeFragAST(const char* glslVer, + const ShaderFunction& lighting, + const ShaderFunction& post) const +{ + std::string src = makeFrag(glslVer, lighting, post); + const char* strs[] = {src.data()}; + int lens[] = {int(src.size())}; + + glslang::TShader ret(EShLangFragment); + ret.setStringsWithLengths(strs, lens, 1); + ret.parse(&DefaultBuiltInResource, 110, true, EShMsgDefault); + + return ret; +} + } namespace Runtime {