diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 7b4d9425a..14ecd897b 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -164,7 +164,7 @@ Graphics::~Graphics() delete batchedDrawState.vb[1]; delete batchedDrawState.indexBuffer; - for (int i = 0; i < (int) ShaderStage::STAGE_MAX_ENUM; i++) + for (int i = 0; i < (int) SHADERSTAGE_MAX_ENUM; i++) cachedShaderStages[i].clear(); Shader::deinitialize(); @@ -219,7 +219,7 @@ love::graphics::ParticleSystem *Graphics::newParticleSystem(Texture *texture, in return new ParticleSystem(texture, size); } -ShaderStage *Graphics::newShaderStage(ShaderStage::StageType stage, const std::string &source, const Shader::SourceInfo &info) +ShaderStage *Graphics::newShaderStage(ShaderStageType stage, const std::string &source, const Shader::SourceInfo &info) { ShaderStage *s = nullptr; std::string cachekey; @@ -252,18 +252,18 @@ ShaderStage *Graphics::newShaderStage(ShaderStage::StageType stage, const std::s Shader *Graphics::newShader(const std::vector &stagessource) { - StrongRef stages[ShaderStage::STAGE_MAX_ENUM] = {}; + StrongRef stages[SHADERSTAGE_MAX_ENUM] = {}; - bool validstages[ShaderStage::STAGE_MAX_ENUM] = {}; - validstages[ShaderStage::STAGE_VERTEX] = true; - validstages[ShaderStage::STAGE_PIXEL] = true; + bool validstages[SHADERSTAGE_MAX_ENUM] = {}; + validstages[SHADERSTAGE_VERTEX] = true; + validstages[SHADERSTAGE_PIXEL] = true; for (const std::string &source : stagessource) { Shader::SourceInfo info = Shader::getSourceInfo(source); bool isanystage = false; - for (int i = 0; i < ShaderStage::STAGE_MAX_ENUM; i++) + for (int i = 0; i < SHADERSTAGE_MAX_ENUM; i++) { if (!validstages[i]) continue; @@ -271,7 +271,7 @@ Shader *Graphics::newShader(const std::vector &stagessource) if (info.stages[i] != Shader::ENTRYPOINT_NONE) { isanystage = true; - stages[i].set(newShaderStage((ShaderStage::StageType) i, source, info), Acquire::NORETAIN); + stages[i].set(newShaderStage((ShaderStageType) i, source, info), Acquire::NORETAIN); } } @@ -279,9 +279,9 @@ Shader *Graphics::newShader(const std::vector &stagessource) throw love::Exception("Could not parse shader code (missing 'position' or 'effect' function?)"); } - for (int i = 0; i < ShaderStage::STAGE_MAX_ENUM; i++) + for (int i = 0; i < SHADERSTAGE_MAX_ENUM; i++) { - auto stype = (ShaderStage::StageType) i; + auto stype = (ShaderStageType) i; if (validstages[i] && stages[i].get() == nullptr) { const std::string &source = Shader::getDefaultCode(Shader::STANDARD_DEFAULT, stype); @@ -291,7 +291,7 @@ Shader *Graphics::newShader(const std::vector &stagessource) } - return newShaderInternal(stages[ShaderStage::STAGE_VERTEX], stages[ShaderStage::STAGE_PIXEL]); + return newShaderInternal(stages[SHADERSTAGE_VERTEX], stages[SHADERSTAGE_PIXEL]); } Buffer *Graphics::newBuffer(const Buffer::Settings &settings, DataFormat format, const void *data, size_t size, size_t arraylength) @@ -320,18 +320,18 @@ love::graphics::Text *Graphics::newText(graphics::Font *font, const std::vector< return new Text(font, text); } -void Graphics::cleanupCachedShaderStage(ShaderStage::StageType type, const std::string &hashkey) +void Graphics::cleanupCachedShaderStage(ShaderStageType type, const std::string &hashkey) { cachedShaderStages[type].erase(hashkey); } bool Graphics::validateShader(bool gles, const std::vector &stagessource, std::string &err) { - StrongRef stages[ShaderStage::STAGE_MAX_ENUM] = {}; + StrongRef stages[SHADERSTAGE_MAX_ENUM] = {}; - bool validstages[ShaderStage::STAGE_MAX_ENUM] = {}; - validstages[ShaderStage::STAGE_VERTEX] = true; - validstages[ShaderStage::STAGE_PIXEL] = true; + bool validstages[SHADERSTAGE_MAX_ENUM] = {}; + validstages[SHADERSTAGE_VERTEX] = true; + validstages[SHADERSTAGE_PIXEL] = true; // Don't use cached shader stages, since the gles flag may not match the // current renderer. @@ -340,9 +340,9 @@ bool Graphics::validateShader(bool gles, const std::vector &stagess Shader::SourceInfo info = Shader::getSourceInfo(source); bool isanystage = false; - for (int i = 0; i < ShaderStage::STAGE_MAX_ENUM; i++) + for (int i = 0; i < SHADERSTAGE_MAX_ENUM; i++) { - auto stype = (ShaderStage::StageType) i; + auto stype = (ShaderStageType) i; if (!validstages[i]) continue; @@ -362,7 +362,7 @@ bool Graphics::validateShader(bool gles, const std::vector &stagess } } - return Shader::validate(stages[ShaderStage::STAGE_VERTEX], stages[ShaderStage::STAGE_PIXEL], err); + return Shader::validate(stages[SHADERSTAGE_VERTEX], stages[SHADERSTAGE_PIXEL], err); } int Graphics::getWidth() const diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index c03991d8b..28f93ddbe 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -830,7 +830,7 @@ public: static void flushBatchedDrawsGlobal(); - void cleanupCachedShaderStage(ShaderStage::StageType type, const std::string &cachekey); + void cleanupCachedShaderStage(ShaderStageType type, const std::string &cachekey); template T *getScratchBuffer(size_t count) @@ -927,8 +927,8 @@ protected: {} }; - ShaderStage *newShaderStage(ShaderStage::StageType stage, const std::string &source, const Shader::SourceInfo &info); - virtual ShaderStage *newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles) = 0; + ShaderStage *newShaderStage(ShaderStageType stage, const std::string &source, const Shader::SourceInfo &info); + virtual ShaderStage *newShaderStageInternal(ShaderStageType stage, const std::string &cachekey, const std::string &source, bool gles) = 0; virtual Shader *newShaderInternal(ShaderStage *vertex, ShaderStage *pixel) = 0; virtual StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) = 0; @@ -994,7 +994,7 @@ private: std::vector scratchBuffer; - std::unordered_map cachedShaderStages[ShaderStage::STAGE_MAX_ENUM]; + std::unordered_map cachedShaderStages[SHADERSTAGE_MAX_ENUM]; }; // Graphics diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index 46f1b9d97..af7328546 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -405,7 +405,7 @@ static const StageInfo stageInfo[] = { "PIXEL", pixel_header, pixel_functions, pixel_main, pixel_main_custom, pixel_main_raw }, }; -static_assert((sizeof(stageInfo) / sizeof(StageInfo)) == ShaderStage::STAGE_MAX_ENUM, "Stages array size must match ShaderStage enum."); +static_assert((sizeof(stageInfo) / sizeof(StageInfo)) == SHADERSTAGE_MAX_ENUM, "Stages array size must match ShaderStage enum."); struct Version { @@ -478,12 +478,12 @@ Shader::SourceInfo Shader::getSourceInfo(const std::string &src) { SourceInfo info = {}; info.language = glsl::getTargetLanguage(src); - info.stages[ShaderStage::STAGE_VERTEX] = glsl::getVertexEntryPoint(src); - info.stages[ShaderStage::STAGE_PIXEL] = glsl::getPixelEntryPoint(src, info.usesMRT); + info.stages[SHADERSTAGE_VERTEX] = glsl::getVertexEntryPoint(src); + info.stages[SHADERSTAGE_PIXEL] = glsl::getPixelEntryPoint(src, info.usesMRT); return info; } -std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStage::StageType stage, const std::string &code, const Shader::SourceInfo &info) +std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage, const std::string &code, const Shader::SourceInfo &info) { if (info.language == Shader::LANGUAGE_MAX_ENUM) throw love::Exception("Invalid shader language"); @@ -548,8 +548,8 @@ Shader::Shader(ShaderStage *vertex, ShaderStage *pixel) if (!validateInternal(vertex, pixel, err, validationReflection)) throw love::Exception("%s", err.c_str()); - stages[ShaderStage::STAGE_VERTEX] = vertex; - stages[ShaderStage::STAGE_PIXEL] = pixel; + stages[SHADERSTAGE_VERTEX] = vertex; + stages[SHADERSTAGE_PIXEL] = pixel; } Shader::~Shader() @@ -768,9 +768,9 @@ void effect() } )"; -const std::string &Shader::getDefaultCode(StandardShader shader, ShaderStage::StageType stage) +const std::string &Shader::getDefaultCode(StandardShader shader, ShaderStageType stage) { - if (stage == ShaderStage::STAGE_VERTEX) + if (stage == SHADERSTAGE_VERTEX) { if (shader == STANDARD_POINTS) return defaultPointsVertex; diff --git a/src/modules/graphics/Shader.h b/src/modules/graphics/Shader.h index 16eb78d22..88807ebcf 100644 --- a/src/modules/graphics/Shader.h +++ b/src/modules/graphics/Shader.h @@ -102,7 +102,7 @@ public: struct SourceInfo { Language language; - EntryPoint stages[ShaderStage::STAGE_MAX_ENUM]; + EntryPoint stages[SHADERSTAGE_MAX_ENUM]; bool usesMRT; }; @@ -212,14 +212,14 @@ public: void validateDrawState(PrimitiveType primtype, Texture *maintexture) const; static SourceInfo getSourceInfo(const std::string &src); - static std::string createShaderStageCode(Graphics *gfx, ShaderStage::StageType stage, const std::string &code, const SourceInfo &info); + static std::string createShaderStageCode(Graphics *gfx, ShaderStageType stage, const std::string &code, const SourceInfo &info); static bool validate(ShaderStage *vertex, ShaderStage *pixel, std::string &err); static bool initialize(); static void deinitialize(); - static const std::string &getDefaultCode(StandardShader shader, ShaderStage::StageType stage); + static const std::string &getDefaultCode(StandardShader shader, ShaderStageType stage); static bool getConstant(const char *in, Language &out); static bool getConstant(Language in, const char *&out); @@ -243,7 +243,7 @@ protected: static bool validateInternal(ShaderStage* vertex, ShaderStage* pixel, std::string& err, ValidationReflection &reflection); - StrongRef stages[ShaderStage::STAGE_MAX_ENUM]; + StrongRef stages[SHADERSTAGE_MAX_ENUM]; ValidationReflection validationReflection; diff --git a/src/modules/graphics/ShaderStage.cpp b/src/modules/graphics/ShaderStage.cpp index 0a8a355b8..a539860b5 100644 --- a/src/modules/graphics/ShaderStage.cpp +++ b/src/modules/graphics/ShaderStage.cpp @@ -137,16 +137,16 @@ namespace love namespace graphics { -ShaderStage::ShaderStage(Graphics *gfx, StageType stage, const std::string &glsl, bool gles, const std::string &cachekey) +ShaderStage::ShaderStage(Graphics *gfx, ShaderStageType stage, const std::string &glsl, bool gles, const std::string &cachekey) : stageType(stage) , source(glsl) , cacheKey(cachekey) , glslangShader(nullptr) { EShLanguage glslangStage = EShLangCount; - if (stage == STAGE_VERTEX) + if (stage == SHADERSTAGE_VERTEX) glslangStage = EShLangVertex; - else if (stage == STAGE_PIXEL) + else if (stage == SHADERSTAGE_PIXEL) glslangStage = EShLangFragment; else throw love::Exception("Cannot compile shader stage: unknown stage type."); @@ -193,30 +193,30 @@ ShaderStage::~ShaderStage() delete glslangShader; } -bool ShaderStage::getConstant(const char *in, StageType &out) +bool ShaderStage::getConstant(const char *in, ShaderStageType &out) { return stageNames.find(in, out); } -bool ShaderStage::getConstant(StageType in, const char *&out) +bool ShaderStage::getConstant(ShaderStageType in, const char *&out) { return stageNames.find(in, out); } -const char *ShaderStage::getConstant(StageType in) +const char *ShaderStage::getConstant(ShaderStageType in) { const char *name = nullptr; getConstant(in, name); return name; } -StringMap::Entry ShaderStage::stageNameEntries[] = +StringMap::Entry ShaderStage::stageNameEntries[] = { - { "vertex", STAGE_VERTEX }, - { "pixel", STAGE_PIXEL }, + { "vertex", SHADERSTAGE_VERTEX }, + { "pixel", SHADERSTAGE_PIXEL }, }; -StringMap ShaderStage::stageNames(ShaderStage::stageNameEntries, sizeof(ShaderStage::stageNameEntries)); +StringMap ShaderStage::stageNames(ShaderStage::stageNameEntries, sizeof(ShaderStage::stageNameEntries)); } // graphics } // love diff --git a/src/modules/graphics/ShaderStage.h b/src/modules/graphics/ShaderStage.h index 675da5bf8..11fd79765 100644 --- a/src/modules/graphics/ShaderStage.h +++ b/src/modules/graphics/ShaderStage.h @@ -40,29 +40,29 @@ namespace graphics class Graphics; +// Order is used for stages array in ShaderStage.cpp +enum ShaderStageType +{ + SHADERSTAGE_VERTEX, + SHADERSTAGE_PIXEL, + SHADERSTAGE_MAX_ENUM +}; + class ShaderStage : public love::Object, public Volatile, public Resource { public: - // Order is used for stages array in ShaderStage.cpp - enum StageType - { - STAGE_VERTEX, - STAGE_PIXEL, - STAGE_MAX_ENUM - }; - - ShaderStage(Graphics *gfx, StageType stage, const std::string &glsl, bool gles, const std::string &cachekey); + ShaderStage(Graphics *gfx, ShaderStageType stage, const std::string &glsl, bool gles, const std::string &cachekey); virtual ~ShaderStage(); - StageType getStageType() const { return stageType; } + ShaderStageType getStageType() const { return stageType; } const std::string &getSource() const { return source; } const std::string &getWarnings() const { return warnings; } glslang::TShader *getGLSLangShader() const { return glslangShader; } - static bool getConstant(const char *in, StageType &out); - static bool getConstant(StageType in, const char *&out); - static const char *getConstant(StageType in); + static bool getConstant(const char *in, ShaderStageType &out); + static bool getConstant(ShaderStageType in, const char *&out); + static const char *getConstant(ShaderStageType in); protected: @@ -70,13 +70,13 @@ protected: private: - StageType stageType; + ShaderStageType stageType; std::string source; std::string cacheKey; glslang::TShader *glslangShader; - static StringMap::Entry stageNameEntries[]; - static StringMap stageNames; + static StringMap::Entry stageNameEntries[]; + static StringMap stageNames; }; // ShaderStage @@ -84,7 +84,7 @@ class ShaderStageForValidation final : public ShaderStage { public: - ShaderStageForValidation(Graphics *gfx, StageType stage, const std::string &glsl, bool gles) + ShaderStageForValidation(Graphics *gfx, ShaderStageType stage, const std::string &glsl, bool gles) : ShaderStage(gfx, stage, glsl, gles, "") {} diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index a10d75f74..419a1afb5 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -150,7 +150,7 @@ love::graphics::Texture *Graphics::newTexture(const Texture::Settings &settings, return new Texture(settings, data); } -love::graphics::ShaderStage *Graphics::newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles) +love::graphics::ShaderStage *Graphics::newShaderStageInternal(ShaderStageType stage, const std::string &cachekey, const std::string &source, bool gles) { return new ShaderStage(this, stage, source, gles, cachekey); } @@ -401,8 +401,8 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b if (!Shader::standardShaders[i]) { std::vector stages; - stages.push_back(Shader::getDefaultCode(stype, ShaderStage::STAGE_VERTEX)); - stages.push_back(Shader::getDefaultCode(stype, ShaderStage::STAGE_PIXEL)); + stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_VERTEX)); + stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_PIXEL)); Shader::standardShaders[i] = newShader(stages); } } diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index a319cf43f..44d2a1c1d 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -136,7 +136,7 @@ private: } }; - love::graphics::ShaderStage *newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles) override; + love::graphics::ShaderStage *newShaderStageInternal(ShaderStageType stage, const std::string &cachekey, const std::string &source, bool gles) override; love::graphics::Shader *newShaderInternal(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage *pixel) override; love::graphics::StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) override; void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) override; diff --git a/src/modules/graphics/opengl/ShaderStage.cpp b/src/modules/graphics/opengl/ShaderStage.cpp index 3e1684bb0..ca3439229 100644 --- a/src/modules/graphics/opengl/ShaderStage.cpp +++ b/src/modules/graphics/opengl/ShaderStage.cpp @@ -27,7 +27,7 @@ namespace graphics namespace opengl { -ShaderStage::ShaderStage(love::graphics::Graphics *gfx, StageType stage, const std::string &source, bool gles, const std::string &cachekey) +ShaderStage::ShaderStage(love::graphics::Graphics *gfx, ShaderStageType stage, const std::string &source, bool gles, const std::string &cachekey) : love::graphics::ShaderStage(gfx, stage, source, gles, cachekey) , glShader(0) { @@ -44,14 +44,14 @@ bool ShaderStage::loadVolatile() if (glShader != 0) return true; - StageType stage = getStageType(); + ShaderStageType stage = getStageType(); const char *typestr = "unknown"; getConstant(stage, typestr); GLenum glstage = 0; - if (stage == STAGE_VERTEX) + if (stage == SHADERSTAGE_VERTEX) glstage = GL_VERTEX_SHADER; - else if (stage == STAGE_PIXEL) + else if (stage == SHADERSTAGE_PIXEL) glstage = GL_FRAGMENT_SHADER; else throw love::Exception("%s shader stage is not handled in OpenGL backend code.", typestr); diff --git a/src/modules/graphics/opengl/ShaderStage.h b/src/modules/graphics/opengl/ShaderStage.h index 81dcf9d5e..d873b779f 100644 --- a/src/modules/graphics/opengl/ShaderStage.h +++ b/src/modules/graphics/opengl/ShaderStage.h @@ -35,7 +35,7 @@ class ShaderStage final : public love::graphics::ShaderStage { public: - ShaderStage(love::graphics::Graphics *gfx, StageType stage, const std::string &source, bool gles, const std::string &cachekey); + ShaderStage(love::graphics::Graphics *gfx, ShaderStageType stage, const std::string &source, bool gles, const std::string &cachekey); virtual ~ShaderStage(); ptrdiff_t getHandle() const override { return glShader; }