#include "EffekseerMaterialCompilerGL.h" #include #include "../GLSLGenerator/ShaderGenerator.h" namespace Effekseer { static const int InstanceCount = 10; class CompiledMaterialBinaryGL : public CompiledMaterialBinary, public ReferenceObject { private: std::array, static_cast(MaterialShaderType::Max)> vertexShaders_; std::array, static_cast(MaterialShaderType::Max)> pixelShaders_; public: CompiledMaterialBinaryGL() { } virtual ~CompiledMaterialBinaryGL() { } void SetVertexShaderData(MaterialShaderType type, const std::vector& data) { vertexShaders_.at(static_cast(type)) = data; } void SetPixelShaderData(MaterialShaderType type, const std::vector& data) { pixelShaders_.at(static_cast(type)) = data; } const uint8_t* GetVertexShaderData(MaterialShaderType type) const override { return vertexShaders_.at(static_cast(type)).data(); } int32_t GetVertexShaderSize(MaterialShaderType type) const override { return static_cast(vertexShaders_.at(static_cast(type)).size()); } const uint8_t* GetPixelShaderData(MaterialShaderType type) const override { return pixelShaders_.at(static_cast(type)).data(); } int32_t GetPixelShaderSize(MaterialShaderType type) const override { return static_cast(pixelShaders_.at(static_cast(type)).size()); } int AddRef() override { return ReferenceObject::AddRef(); } int Release() override { return ReferenceObject::Release(); } int GetRef() override { return ReferenceObject::GetRef(); } }; CompiledMaterialBinary* MaterialCompilerGL::Compile(MaterialFile* materialFile, int32_t maximumUniformCount, int32_t maximumTextureCount) { auto binary = new CompiledMaterialBinaryGL(); auto convertToVector = [](const std::string& str) -> std::vector { std::vector ret; ret.resize(str.size() + 1); memcpy(ret.data(), str.data(), str.size()); ret[str.size()] = 0; return ret; }; auto saveBinary = [&materialFile, &binary, &convertToVector, &maximumUniformCount, &maximumTextureCount](MaterialShaderType type) { GLSL::ShaderGenerator generator; auto shader = generator.GenerateShader(materialFile, type, maximumUniformCount, maximumTextureCount, false, false, false, false, 0, false, false, InstanceCount); binary->SetVertexShaderData(type, convertToVector(shader.CodeVS)); binary->SetPixelShaderData(type, convertToVector(shader.CodePS)); }; if (materialFile->GetHasRefraction()) { saveBinary(MaterialShaderType::Refraction); saveBinary(MaterialShaderType::RefractionModel); } saveBinary(MaterialShaderType::Standard); saveBinary(MaterialShaderType::Model); return binary; } CompiledMaterialBinary* MaterialCompilerGL::Compile(MaterialFile* materialFile) { return Compile(materialFile, Effekseer::UserUniformSlotMax, Effekseer::UserTextureSlotMax); } } // namespace Effekseer #ifdef __SHARED_OBJECT__ extern "C" { #ifdef _WIN32 #define EFK_EXPORT __declspec(dllexport) #else #define EFK_EXPORT #endif EFK_EXPORT Effekseer::MaterialCompiler* EFK_STDCALL CreateCompiler() { return new Effekseer::MaterialCompilerGL(); } } #endif