| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include "common/Object.h" |
| 24 | #include "common/StringMap.h" |
| 25 | #include "Volatile.h" |
| 26 | #include "Resource.h" |
| 27 | |
| 28 | #include <stddef.h> |
| 29 | #include <string> |
| 30 | |
| 31 | namespace glslang |
| 32 | { |
| 33 | class TShader; |
| 34 | } |
| 35 | |
| 36 | namespace love |
| 37 | { |
| 38 | namespace graphics |
| 39 | { |
| 40 | |
| 41 | class Graphics; |
| 42 | |
| 43 | class ShaderStage : public love::Object, public Volatile, public Resource |
| 44 | { |
| 45 | public: |
| 46 | |
| 47 | enum StageType |
| 48 | { |
| 49 | STAGE_VERTEX, |
| 50 | STAGE_PIXEL, |
| 51 | STAGE_MAX_ENUM |
| 52 | }; |
| 53 | |
| 54 | ShaderStage(Graphics *gfx, StageType stage, const std::string &glsl, bool gles, const std::string &cachekey); |
| 55 | virtual ~ShaderStage(); |
| 56 | |
| 57 | StageType getStageType() const { return stageType; } |
| 58 | const std::string &getSource() const { return source; } |
| 59 | const std::string &getWarnings() const { return warnings; } |
| 60 | glslang::TShader *getGLSLangShader() const { return glslangShader; } |
| 61 | |
| 62 | static bool getConstant(const char *in, StageType &out); |
| 63 | static bool getConstant(StageType in, const char *&out); |
| 64 | |
| 65 | protected: |
| 66 | |
| 67 | std::string warnings; |
| 68 | |
| 69 | private: |
| 70 | |
| 71 | StageType stageType; |
| 72 | std::string source; |
| 73 | std::string cacheKey; |
| 74 | glslang::TShader *glslangShader; |
| 75 | |
| 76 | static StringMap<StageType, STAGE_MAX_ENUM>::Entry stageNameEntries[]; |
| 77 | static StringMap<StageType, STAGE_MAX_ENUM> stageNames; |
| 78 | |
| 79 | }; // ShaderStage |
| 80 | |
| 81 | class ShaderStageForValidation final : public ShaderStage |
| 82 | { |
| 83 | public: |
| 84 | |
| 85 | ShaderStageForValidation(Graphics *gfx, StageType stage, const std::string &glsl, bool gles) |
| 86 | : ShaderStage(gfx, stage, glsl, gles, "" ) |
| 87 | {} |
| 88 | |
| 89 | virtual ~ShaderStageForValidation() {} |
| 90 | |
| 91 | ptrdiff_t getHandle() const override { return 0; } |
| 92 | bool loadVolatile() override { return true; } |
| 93 | void unloadVolatile() override { } |
| 94 | |
| 95 | }; // ShaderStageForValidation |
| 96 | |
| 97 | } // graphics |
| 98 | } // love |
| 99 | |