Rename internal enum

This commit is contained in:
Alex Szpakowski
2021-04-07 20:43:22 -03:00
parent 9b4aea8f17
commit 14cda7818f
10 changed files with 71 additions and 71 deletions
+19 -19
View File
@@ -164,7 +164,7 @@ Graphics::~Graphics()
delete batchedDrawState.vb[1]; delete batchedDrawState.vb[1];
delete batchedDrawState.indexBuffer; 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(); cachedShaderStages[i].clear();
Shader::deinitialize(); Shader::deinitialize();
@@ -219,7 +219,7 @@ love::graphics::ParticleSystem *Graphics::newParticleSystem(Texture *texture, in
return new ParticleSystem(texture, size); 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; ShaderStage *s = nullptr;
std::string cachekey; std::string cachekey;
@@ -252,18 +252,18 @@ ShaderStage *Graphics::newShaderStage(ShaderStage::StageType stage, const std::s
Shader *Graphics::newShader(const std::vector<std::string> &stagessource) Shader *Graphics::newShader(const std::vector<std::string> &stagessource)
{ {
StrongRef<ShaderStage> stages[ShaderStage::STAGE_MAX_ENUM] = {}; StrongRef<ShaderStage> stages[SHADERSTAGE_MAX_ENUM] = {};
bool validstages[ShaderStage::STAGE_MAX_ENUM] = {}; bool validstages[SHADERSTAGE_MAX_ENUM] = {};
validstages[ShaderStage::STAGE_VERTEX] = true; validstages[SHADERSTAGE_VERTEX] = true;
validstages[ShaderStage::STAGE_PIXEL] = true; validstages[SHADERSTAGE_PIXEL] = true;
for (const std::string &source : stagessource) for (const std::string &source : stagessource)
{ {
Shader::SourceInfo info = Shader::getSourceInfo(source); Shader::SourceInfo info = Shader::getSourceInfo(source);
bool isanystage = false; 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]) if (!validstages[i])
continue; continue;
@@ -271,7 +271,7 @@ Shader *Graphics::newShader(const std::vector<std::string> &stagessource)
if (info.stages[i] != Shader::ENTRYPOINT_NONE) if (info.stages[i] != Shader::ENTRYPOINT_NONE)
{ {
isanystage = true; 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<std::string> &stagessource)
throw love::Exception("Could not parse shader code (missing 'position' or 'effect' function?)"); 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) if (validstages[i] && stages[i].get() == nullptr)
{ {
const std::string &source = Shader::getDefaultCode(Shader::STANDARD_DEFAULT, stype); const std::string &source = Shader::getDefaultCode(Shader::STANDARD_DEFAULT, stype);
@@ -291,7 +291,7 @@ Shader *Graphics::newShader(const std::vector<std::string> &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) 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); 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); cachedShaderStages[type].erase(hashkey);
} }
bool Graphics::validateShader(bool gles, const std::vector<std::string> &stagessource, std::string &err) bool Graphics::validateShader(bool gles, const std::vector<std::string> &stagessource, std::string &err)
{ {
StrongRef<ShaderStage> stages[ShaderStage::STAGE_MAX_ENUM] = {}; StrongRef<ShaderStage> stages[SHADERSTAGE_MAX_ENUM] = {};
bool validstages[ShaderStage::STAGE_MAX_ENUM] = {}; bool validstages[SHADERSTAGE_MAX_ENUM] = {};
validstages[ShaderStage::STAGE_VERTEX] = true; validstages[SHADERSTAGE_VERTEX] = true;
validstages[ShaderStage::STAGE_PIXEL] = true; validstages[SHADERSTAGE_PIXEL] = true;
// Don't use cached shader stages, since the gles flag may not match the // Don't use cached shader stages, since the gles flag may not match the
// current renderer. // current renderer.
@@ -340,9 +340,9 @@ bool Graphics::validateShader(bool gles, const std::vector<std::string> &stagess
Shader::SourceInfo info = Shader::getSourceInfo(source); Shader::SourceInfo info = Shader::getSourceInfo(source);
bool isanystage = false; 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]) if (!validstages[i])
continue; continue;
@@ -362,7 +362,7 @@ bool Graphics::validateShader(bool gles, const std::vector<std::string> &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 int Graphics::getWidth() const
+4 -4
View File
@@ -830,7 +830,7 @@ public:
static void flushBatchedDrawsGlobal(); static void flushBatchedDrawsGlobal();
void cleanupCachedShaderStage(ShaderStage::StageType type, const std::string &cachekey); void cleanupCachedShaderStage(ShaderStageType type, const std::string &cachekey);
template <typename T> template <typename T>
T *getScratchBuffer(size_t count) T *getScratchBuffer(size_t count)
@@ -927,8 +927,8 @@ protected:
{} {}
}; };
ShaderStage *newShaderStage(ShaderStage::StageType stage, const std::string &source, const Shader::SourceInfo &info); ShaderStage *newShaderStage(ShaderStageType 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; 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 Shader *newShaderInternal(ShaderStage *vertex, ShaderStage *pixel) = 0;
virtual StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) = 0; virtual StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) = 0;
@@ -994,7 +994,7 @@ private:
std::vector<uint8> scratchBuffer; std::vector<uint8> scratchBuffer;
std::unordered_map<std::string, ShaderStage *> cachedShaderStages[ShaderStage::STAGE_MAX_ENUM]; std::unordered_map<std::string, ShaderStage *> cachedShaderStages[SHADERSTAGE_MAX_ENUM];
}; // Graphics }; // Graphics
+8 -8
View File
@@ -405,7 +405,7 @@ static const StageInfo stageInfo[] =
{ "PIXEL", pixel_header, pixel_functions, pixel_main, pixel_main_custom, pixel_main_raw }, { "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 struct Version
{ {
@@ -478,12 +478,12 @@ Shader::SourceInfo Shader::getSourceInfo(const std::string &src)
{ {
SourceInfo info = {}; SourceInfo info = {};
info.language = glsl::getTargetLanguage(src); info.language = glsl::getTargetLanguage(src);
info.stages[ShaderStage::STAGE_VERTEX] = glsl::getVertexEntryPoint(src); info.stages[SHADERSTAGE_VERTEX] = glsl::getVertexEntryPoint(src);
info.stages[ShaderStage::STAGE_PIXEL] = glsl::getPixelEntryPoint(src, info.usesMRT); info.stages[SHADERSTAGE_PIXEL] = glsl::getPixelEntryPoint(src, info.usesMRT);
return info; 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) if (info.language == Shader::LANGUAGE_MAX_ENUM)
throw love::Exception("Invalid shader language"); throw love::Exception("Invalid shader language");
@@ -548,8 +548,8 @@ Shader::Shader(ShaderStage *vertex, ShaderStage *pixel)
if (!validateInternal(vertex, pixel, err, validationReflection)) if (!validateInternal(vertex, pixel, err, validationReflection))
throw love::Exception("%s", err.c_str()); throw love::Exception("%s", err.c_str());
stages[ShaderStage::STAGE_VERTEX] = vertex; stages[SHADERSTAGE_VERTEX] = vertex;
stages[ShaderStage::STAGE_PIXEL] = pixel; stages[SHADERSTAGE_PIXEL] = pixel;
} }
Shader::~Shader() 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) if (shader == STANDARD_POINTS)
return defaultPointsVertex; return defaultPointsVertex;
+4 -4
View File
@@ -102,7 +102,7 @@ public:
struct SourceInfo struct SourceInfo
{ {
Language language; Language language;
EntryPoint stages[ShaderStage::STAGE_MAX_ENUM]; EntryPoint stages[SHADERSTAGE_MAX_ENUM];
bool usesMRT; bool usesMRT;
}; };
@@ -212,14 +212,14 @@ public:
void validateDrawState(PrimitiveType primtype, Texture *maintexture) const; void validateDrawState(PrimitiveType primtype, Texture *maintexture) const;
static SourceInfo getSourceInfo(const std::string &src); 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 validate(ShaderStage *vertex, ShaderStage *pixel, std::string &err);
static bool initialize(); static bool initialize();
static void deinitialize(); 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(const char *in, Language &out);
static bool getConstant(Language in, const char *&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); static bool validateInternal(ShaderStage* vertex, ShaderStage* pixel, std::string& err, ValidationReflection &reflection);
StrongRef<ShaderStage> stages[ShaderStage::STAGE_MAX_ENUM]; StrongRef<ShaderStage> stages[SHADERSTAGE_MAX_ENUM];
ValidationReflection validationReflection; ValidationReflection validationReflection;
+10 -10
View File
@@ -137,16 +137,16 @@ namespace love
namespace graphics 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) : stageType(stage)
, source(glsl) , source(glsl)
, cacheKey(cachekey) , cacheKey(cachekey)
, glslangShader(nullptr) , glslangShader(nullptr)
{ {
EShLanguage glslangStage = EShLangCount; EShLanguage glslangStage = EShLangCount;
if (stage == STAGE_VERTEX) if (stage == SHADERSTAGE_VERTEX)
glslangStage = EShLangVertex; glslangStage = EShLangVertex;
else if (stage == STAGE_PIXEL) else if (stage == SHADERSTAGE_PIXEL)
glslangStage = EShLangFragment; glslangStage = EShLangFragment;
else else
throw love::Exception("Cannot compile shader stage: unknown stage type."); throw love::Exception("Cannot compile shader stage: unknown stage type.");
@@ -193,30 +193,30 @@ ShaderStage::~ShaderStage()
delete glslangShader; delete glslangShader;
} }
bool ShaderStage::getConstant(const char *in, StageType &out) bool ShaderStage::getConstant(const char *in, ShaderStageType &out)
{ {
return stageNames.find(in, 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); return stageNames.find(in, out);
} }
const char *ShaderStage::getConstant(StageType in) const char *ShaderStage::getConstant(ShaderStageType in)
{ {
const char *name = nullptr; const char *name = nullptr;
getConstant(in, name); getConstant(in, name);
return name; return name;
} }
StringMap<ShaderStage::StageType, ShaderStage::STAGE_MAX_ENUM>::Entry ShaderStage::stageNameEntries[] = StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM>::Entry ShaderStage::stageNameEntries[] =
{ {
{ "vertex", STAGE_VERTEX }, { "vertex", SHADERSTAGE_VERTEX },
{ "pixel", STAGE_PIXEL }, { "pixel", SHADERSTAGE_PIXEL },
}; };
StringMap<ShaderStage::StageType, ShaderStage::STAGE_MAX_ENUM> ShaderStage::stageNames(ShaderStage::stageNameEntries, sizeof(ShaderStage::stageNameEntries)); StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM> ShaderStage::stageNames(ShaderStage::stageNameEntries, sizeof(ShaderStage::stageNameEntries));
} // graphics } // graphics
} // love } // love
+17 -17
View File
@@ -40,29 +40,29 @@ namespace graphics
class 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 class ShaderStage : public love::Object, public Volatile, public Resource
{ {
public: public:
// Order is used for stages array in ShaderStage.cpp ShaderStage(Graphics *gfx, ShaderStageType stage, const std::string &glsl, bool gles, const std::string &cachekey);
enum StageType
{
STAGE_VERTEX,
STAGE_PIXEL,
STAGE_MAX_ENUM
};
ShaderStage(Graphics *gfx, StageType stage, const std::string &glsl, bool gles, const std::string &cachekey);
virtual ~ShaderStage(); virtual ~ShaderStage();
StageType getStageType() const { return stageType; } ShaderStageType getStageType() const { return stageType; }
const std::string &getSource() const { return source; } const std::string &getSource() const { return source; }
const std::string &getWarnings() const { return warnings; } const std::string &getWarnings() const { return warnings; }
glslang::TShader *getGLSLangShader() const { return glslangShader; } glslang::TShader *getGLSLangShader() const { return glslangShader; }
static bool getConstant(const char *in, StageType &out); static bool getConstant(const char *in, ShaderStageType &out);
static bool getConstant(StageType in, const char *&out); static bool getConstant(ShaderStageType in, const char *&out);
static const char *getConstant(StageType in); static const char *getConstant(ShaderStageType in);
protected: protected:
@@ -70,13 +70,13 @@ protected:
private: private:
StageType stageType; ShaderStageType stageType;
std::string source; std::string source;
std::string cacheKey; std::string cacheKey;
glslang::TShader *glslangShader; glslang::TShader *glslangShader;
static StringMap<StageType, STAGE_MAX_ENUM>::Entry stageNameEntries[]; static StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM>::Entry stageNameEntries[];
static StringMap<StageType, STAGE_MAX_ENUM> stageNames; static StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM> stageNames;
}; // ShaderStage }; // ShaderStage
@@ -84,7 +84,7 @@ class ShaderStageForValidation final : public ShaderStage
{ {
public: 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, "") : ShaderStage(gfx, stage, glsl, gles, "")
{} {}
+3 -3
View File
@@ -150,7 +150,7 @@ love::graphics::Texture *Graphics::newTexture(const Texture::Settings &settings,
return new Texture(settings, data); 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); 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]) if (!Shader::standardShaders[i])
{ {
std::vector<std::string> stages; std::vector<std::string> stages;
stages.push_back(Shader::getDefaultCode(stype, ShaderStage::STAGE_VERTEX)); stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_VERTEX));
stages.push_back(Shader::getDefaultCode(stype, ShaderStage::STAGE_PIXEL)); stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_PIXEL));
Shader::standardShaders[i] = newShader(stages); Shader::standardShaders[i] = newShader(stages);
} }
} }
+1 -1
View File
@@ -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::Shader *newShaderInternal(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage *pixel) override;
love::graphics::StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) 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; void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) override;
+4 -4
View File
@@ -27,7 +27,7 @@ namespace graphics
namespace opengl 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) : love::graphics::ShaderStage(gfx, stage, source, gles, cachekey)
, glShader(0) , glShader(0)
{ {
@@ -44,14 +44,14 @@ bool ShaderStage::loadVolatile()
if (glShader != 0) if (glShader != 0)
return true; return true;
StageType stage = getStageType(); ShaderStageType stage = getStageType();
const char *typestr = "unknown"; const char *typestr = "unknown";
getConstant(stage, typestr); getConstant(stage, typestr);
GLenum glstage = 0; GLenum glstage = 0;
if (stage == STAGE_VERTEX) if (stage == SHADERSTAGE_VERTEX)
glstage = GL_VERTEX_SHADER; glstage = GL_VERTEX_SHADER;
else if (stage == STAGE_PIXEL) else if (stage == SHADERSTAGE_PIXEL)
glstage = GL_FRAGMENT_SHADER; glstage = GL_FRAGMENT_SHADER;
else else
throw love::Exception("%s shader stage is not handled in OpenGL backend code.", typestr); throw love::Exception("%s shader stage is not handled in OpenGL backend code.", typestr);
+1 -1
View File
@@ -35,7 +35,7 @@ class ShaderStage final : public love::graphics::ShaderStage
{ {
public: 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(); virtual ~ShaderStage();
ptrdiff_t getHandle() const override { return glShader; } ptrdiff_t getHandle() const override { return glShader; }