mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user