mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
Rename internal enum
This commit is contained in:
@@ -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<std::string> &stagessource)
|
||||
{
|
||||
StrongRef<ShaderStage> stages[ShaderStage::STAGE_MAX_ENUM] = {};
|
||||
StrongRef<ShaderStage> 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<std::string> &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<std::string> &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<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)
|
||||
@@ -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<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] = {};
|
||||
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<std::string> &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<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
|
||||
|
||||
@@ -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 <typename T>
|
||||
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<uint8> scratchBuffer;
|
||||
|
||||
std::unordered_map<std::string, ShaderStage *> cachedShaderStages[ShaderStage::STAGE_MAX_ENUM];
|
||||
std::unordered_map<std::string, ShaderStage *> cachedShaderStages[SHADERSTAGE_MAX_ENUM];
|
||||
|
||||
}; // Graphics
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<ShaderStage> stages[ShaderStage::STAGE_MAX_ENUM];
|
||||
StrongRef<ShaderStage> stages[SHADERSTAGE_MAX_ENUM];
|
||||
|
||||
ValidationReflection validationReflection;
|
||||
|
||||
|
||||
@@ -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<ShaderStage::StageType, ShaderStage::STAGE_MAX_ENUM>::Entry ShaderStage::stageNameEntries[] =
|
||||
StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM>::Entry ShaderStage::stageNameEntries[] =
|
||||
{
|
||||
{ "vertex", STAGE_VERTEX },
|
||||
{ "pixel", STAGE_PIXEL },
|
||||
{ "vertex", SHADERSTAGE_VERTEX },
|
||||
{ "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
|
||||
} // love
|
||||
|
||||
@@ -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<StageType, STAGE_MAX_ENUM>::Entry stageNameEntries[];
|
||||
static StringMap<StageType, STAGE_MAX_ENUM> stageNames;
|
||||
static StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM>::Entry stageNameEntries[];
|
||||
static StringMap<ShaderStageType, SHADERSTAGE_MAX_ENUM> 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, "")
|
||||
{}
|
||||
|
||||
|
||||
@@ -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<std::string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user