Shader uniforms keep their values after love.window.setMode (resolves issue #1174).

Also allow arrays of images/samplers in shaders, although driver support is iffy and you have to index into the array using a compile-time constant (which might exclude loop indexing).

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-11-21 18:28:16 -04:00
parent 639c229bd7
commit 9d2ee6d909
6 changed files with 351 additions and 242 deletions
+21 -30
View File
@@ -96,13 +96,24 @@ public:
{
int location;
int count;
union
{
int components;
MatrixSize matrix;
};
UniformType baseType;
std::string name;
union
{
void *data;
float *floats;
int *ints;
};
Texture **textures;
};
// Pointer to currently active Shader.
@@ -147,11 +158,9 @@ public:
std::string getWarnings() const;
const UniformInfo *getUniformInfo(const std::string &name) const;
void updateUniform(const UniformInfo *info, int count, bool internalUpdate = false);
void sendInts(const UniformInfo *info, const int *vec, int count);
void sendFloats(const UniformInfo *info, const float *vec, int count);
void sendMatrices(const UniformInfo *info, const float *m, int count);
void sendTexture(const UniformInfo *info, Texture *texture);
void sendTextures(const UniformInfo *info, Texture **textures, int count, bool internalUpdate = false);
/**
* Gets whether a uniform with the specified name exists and is actively
@@ -171,24 +180,11 @@ public:
void checkSetPointSize(float size);
void checkSetBuiltinUniforms();
const std::map<std::string, Object *> &getBoundRetainables() const;
GLuint getProgram() const
{
return program;
}
template <typename T>
T *getScratchBuffer(size_t count)
{
size_t bytes = sizeof(T) * count;
if (scratchBuffer.size() < bytes)
scratchBuffer.resize(bytes);
return (T *) scratchBuffer.data();
}
static std::string getGLSLVersion();
static bool isSupported();
@@ -200,6 +196,12 @@ public:
private:
struct TextureUnit
{
GLuint texture = 0;
bool active = false;
};
// Map active uniform names to their locations.
void mapActiveUniforms();
@@ -209,9 +211,7 @@ private:
GLuint compileCode(ShaderStage stage, const std::string &code);
int getTextureUnit(const std::string &name);
void retainObject(const std::string &name, Object *object);
int getFreeTextureUnits(int count);
// Get any warnings or errors generated only by the shader program object.
std::string getProgramWarnings() const;
@@ -237,11 +237,7 @@ private:
std::map<std::string, UniformInfo> uniforms;
// Texture unit pool for setting images
std::map<std::string, GLint> texUnitPool; // texUnitPool[name] = textureunit
std::vector<GLuint> activeTexUnits; // activeTexUnits[textureunit-1] = textureid
// Uniform name to retainable objects
std::map<std::string, Object*> boundRetainables;
std::vector<TextureUnit> textureUnits;
bool canvasWasActive;
OpenGL::Viewport lastViewport;
@@ -253,11 +249,6 @@ private:
GLuint videoTextureUnits[3];
std::vector<char> scratchBuffer;
// Counts total number of textures bound to each texture unit in all shaders
static std::vector<int> textureCounters;
static StringMap<ShaderStage, STAGE_MAX_ENUM>::Entry stageNameEntries[];
static StringMap<ShaderStage, STAGE_MAX_ENUM> stageNames;