mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Add uniform cache in pixel effect. Remove a compiler warning and debug output.
This commit is contained in:
@@ -241,12 +241,18 @@ namespace opengl
|
|||||||
|
|
||||||
GLint PixelEffect::getUniformLocation(const std::string& name)
|
GLint PixelEffect::getUniformLocation(const std::string& name)
|
||||||
{
|
{
|
||||||
|
std::map<std::string, GLint>::const_iterator it = _uniforms.find(name);
|
||||||
|
if (it != _uniforms.end())
|
||||||
|
return it->second;
|
||||||
|
|
||||||
GLint location = glGetUniformLocation(_program, name.c_str());
|
GLint location = glGetUniformLocation(_program, name.c_str());
|
||||||
if (location == -1) {
|
if (location == -1) {
|
||||||
throw love::Exception(
|
throw love::Exception(
|
||||||
"Cannot get location of shader variable `%s'.\n"
|
"Cannot get location of shader variable `%s'.\n"
|
||||||
"A common error is to define but not use the variable.", name.c_str());
|
"A common error is to define but not use the variable.", name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_uniforms[name] = location;
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ namespace opengl
|
|||||||
GLuint _program;
|
GLuint _program;
|
||||||
std::string _code; // volatile and stuff
|
std::string _code; // volatile and stuff
|
||||||
|
|
||||||
|
// uniform location buffer
|
||||||
|
std::map<std::string, GLint> _uniforms;
|
||||||
|
|
||||||
// texture unit pool for setting images
|
// texture unit pool for setting images
|
||||||
static std::map<std::string, GLint> _texture_unit_pool;
|
static std::map<std::string, GLint> _texture_unit_pool;
|
||||||
static GLint _current_texture_unit;
|
static GLint _current_texture_unit;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace opengl
|
|||||||
|
|
||||||
static int _sendVectors(lua_State * L, PixelEffect * effect, const char * name, int count)
|
static int _sendVectors(lua_State * L, PixelEffect * effect, const char * name, int count)
|
||||||
{
|
{
|
||||||
int dimension = lua_objlen(L, 3);
|
size_t dimension = lua_objlen(L, 3);
|
||||||
float * values = new float[count * dimension];
|
float * values = new float[count * dimension];
|
||||||
|
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
@@ -61,7 +61,7 @@ namespace opengl
|
|||||||
3+i, dimension, lua_objlen(L, 3+i));
|
3+i, dimension, lua_objlen(L, 3+i));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int k = 1; k <= dimension; ++k) {
|
for (size_t k = 1; k <= dimension; ++k) {
|
||||||
lua_rawgeti(L, 3 + i, k);
|
lua_rawgeti(L, 3 + i, k);
|
||||||
values[i * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
values[i * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,6 @@ namespace opengl
|
|||||||
for (int k = 1; k <= dimension*dimension; ++k) {
|
for (int k = 1; k <= dimension*dimension; ++k) {
|
||||||
lua_rawgeti(L, 3+i, k);
|
lua_rawgeti(L, 3+i, k);
|
||||||
values[i * dimension * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
values[i * dimension * dimension + k - 1] = (float)lua_tonumber(L, -1);
|
||||||
cout << i << "." << k << " = " << (float)lua_tonumber(L, -1) << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop(L, 1 + dimension);
|
lua_pop(L, 1 + dimension);
|
||||||
|
|||||||
Reference in New Issue
Block a user