Merged default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2014-05-03 22:27:01 -03:00
39 changed files with 267 additions and 163 deletions
@@ -276,8 +276,8 @@ void ParticleSystem::initParticle(Particle *p, float t)
min = speedMin;
max = speedMax;
float speed = (float) rng.random(min, max);
p->speed = love::Vector(cosf(p->direction), sinf(p->direction));
p->speed *= speed;
p->velocity = love::Vector(cosf(p->direction), sinf(p->direction));
p->velocity *= speed;
p->linearAcceleration.x = (float) rng.random(linearAccelerationMin.x, linearAccelerationMax.x);
p->linearAcceleration.y = (float) rng.random(linearAccelerationMin.y, linearAccelerationMax.y);
@@ -302,7 +302,7 @@ void ParticleSystem::initParticle(Particle *p, float t)
p->angle = p->rotation;
if (relativeRotation)
p->angle += atan2f(p->speed.y, p->speed.x);
p->angle += atan2f(p->velocity.y, p->velocity.x);
p->color = colors[0];
}
@@ -907,11 +907,11 @@ void ParticleSystem::update(float dt)
// Resize tangential.
tangential *= p->tangentialAcceleration;
// Update position.
p->speed += (radial+tangential+p->linearAcceleration)*dt;
// Update velocity.
p->velocity += (radial + tangential + p->linearAcceleration) * dt;
// Modify position.
ppos += p->speed * dt;
ppos += p->velocity * dt;
p->position[0] = ppos.getX();
p->position[1] = ppos.getY();
@@ -924,7 +924,7 @@ void ParticleSystem::update(float dt)
p->angle = p->rotation;
if (relativeRotation)
p->angle += atan2f(p->speed.y, p->speed.x);
p->angle += atan2f(p->velocity.y, p->velocity.x);
// Change size according to given intervals:
// i = 0 1 2 3 n-1
+1 -1
View File
@@ -516,7 +516,7 @@ protected:
// Particles gravitate towards this point.
love::Vector origin;
love::Vector speed;
love::Vector velocity;
love::Vector linearAcceleration;
float radialAcceleration;
float tangentialAcceleration;
+53 -7
View File
@@ -186,8 +186,16 @@ void Shader::createProgram(const std::vector<GLuint> &shaderids)
// Bind generic vertex attribute indices to names in the shader.
for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++)
{
OpenGL::VertexAttrib attrib = (OpenGL::VertexAttrib) i;
// FIXME: We skip this both because pseudo-instancing is temporarily
// disabled (see graphics.lua), and because binding a non-existant
// attribute name to a location causes a shader linker warning.
if (attrib == OpenGL::ATTRIB_PSEUDO_INSTANCE_ID)
continue;
const char *name = nullptr;
if (attribNames.find((OpenGL::VertexAttrib) i, name))
if (attribNames.find(attrib, name))
glBindAttribLocation(program, i, (const GLchar *) name);
}
@@ -247,7 +255,7 @@ void Shader::mapActiveUniforms()
}
// If this is a built-in (LOVE-created) uniform, store the location.
BuiltinExtern builtin;
BuiltinUniform builtin;
if (builtinNames.find(u.name.c_str(), builtin))
builtinUniforms[int(builtin)] = u.location;
@@ -652,19 +660,36 @@ int Shader::getTextureUnit(const std::string &name)
return texunit;
}
Shader::UniformType Shader::getExternVariable(const std::string &name, int &components, int &count)
{
auto it = uniforms.find(name);
if (it == uniforms.end())
{
components = 0;
count = 0;
return UNIFORM_UNKNOWN;
}
components = getUniformTypeSize(it->second.type);
count = (int) it->second.count;
return it->second.baseType;
}
bool Shader::hasVertexAttrib(OpenGL::VertexAttrib attrib) const
{
return vertexAttributes[int(attrib)] != -1;
}
bool Shader::hasBuiltinExtern(BuiltinExtern builtin) const
bool Shader::hasBuiltinUniform(BuiltinUniform builtin) const
{
return builtinUniforms[int(builtin)] != -1;
}
bool Shader::sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *vec, int count)
bool Shader::sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *vec, int count)
{
if (!hasBuiltinExtern(builtin))
if (!hasBuiltinUniform(builtin))
return false;
GLint location = builtinUniforms[int(builtin)];
@@ -754,6 +779,16 @@ bool Shader::isSupported()
return getGLSLVersion() >= "1.2";
}
bool Shader::getConstant(const char *in, UniformType &out)
{
return uniformTypes.find(in, out);
}
bool Shader::getConstant(UniformType in, const char *&out)
{
return uniformTypes.find(in, out);
}
StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM>::Entry Shader::typeNameEntries[] =
{
{"vertex", Shader::TYPE_VERTEX},
@@ -762,6 +797,17 @@ StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM>::Entry Shader::typeNameEntr
StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM> Shader::typeNames(Shader::typeNameEntries, sizeof(Shader::typeNameEntries));
StringMap<Shader::UniformType, Shader::UNIFORM_MAX_ENUM>::Entry Shader::uniformTypeEntries[] =
{
{"float", Shader::UNIFORM_FLOAT},
{"int", Shader::UNIFORM_INT},
{"bool", Shader::UNIFORM_BOOL},
{"image", Shader::UNIFORM_SAMPLER},
{"unknown", Shader::UNIFORM_UNKNOWN},
};
StringMap<Shader::UniformType, Shader::UNIFORM_MAX_ENUM> Shader::uniformTypes(Shader::uniformTypeEntries, sizeof(Shader::uniformTypeEntries));
StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry Shader::attribNameEntries[] =
{
{"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID},
@@ -769,12 +815,12 @@ StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry Shader::attribNa
StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM> Shader::attribNames(Shader::attribNameEntries, sizeof(Shader::attribNameEntries));
StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM>::Entry Shader::builtinNameEntries[] =
StringMap<Shader::BuiltinUniform, Shader::BUILTIN_MAX_ENUM>::Entry Shader::builtinNameEntries[] =
{
{"love_ScreenSize", Shader::BUILTIN_SCREEN_SIZE},
};
StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM> Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries));
StringMap<Shader::BuiltinUniform, Shader::BUILTIN_MAX_ENUM> Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries));
} // opengl
} // graphics
+36 -16
View File
@@ -56,13 +56,24 @@ public:
TYPE_MAX_ENUM
};
// Built-in extern (uniform) variables.
enum BuiltinExtern
// Built-in uniform (extern) variables.
enum BuiltinUniform
{
BUILTIN_SCREEN_SIZE,
BUILTIN_MAX_ENUM
};
// Types of potential uniform (extern) variables used in love's shaders.
enum UniformType
{
UNIFORM_FLOAT,
UNIFORM_INT,
UNIFORM_BOOL,
UNIFORM_SAMPLER,
UNIFORM_UNKNOWN,
UNIFORM_MAX_ENUM
};
// Type for a list of shader source codes in the form of sources[shadertype] = code
typedef std::map<ShaderType, std::string> ShaderSources;
@@ -135,12 +146,25 @@ public:
**/
void sendTexture(const std::string &name, Texture *texture);
/**
* Gets the type, number of components, and number of array elements of
* an active 'extern' (uniform) variable in the shader. If a uniform
* variable with the specified name doesn't exist, returns UNIFORM_UNKNOWN
* and sets the 'components' and 'count' values to 0.
*
* @param name The name of the uniform variable in the source code.
* @param[out] components Number of components of the variable (2 for vec2.)
* @param[out] count Number of array elements, if the variable is an array.
* @return The base type of the uniform variable.
**/
UniformType getExternVariable(const std::string &name, int &components, int &count);
/**
* Internal use only.
**/
bool hasVertexAttrib(OpenGL::VertexAttrib attrib) const;
bool hasBuiltinExtern(BuiltinExtern builtin) const;
bool sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *m, int count);
bool hasBuiltinUniform(BuiltinUniform builtin) const;
bool sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *m, int count);
void checkSetScreenParams();
const std::map<std::string, Object *> &getBoundRetainables() const;
@@ -148,17 +172,10 @@ public:
static std::string getGLSLVersion();
static bool isSupported();
private:
static bool getConstant(const char *in, UniformType &out);
static bool getConstant(UniformType in, const char *&out);
// Types of potential uniform variables used in love's shaders.
enum UniformType
{
UNIFORM_FLOAT,
UNIFORM_INT,
UNIFORM_BOOL,
UNIFORM_SAMPLER,
UNIFORM_UNKNOWN
};
private:
// Represents a single uniform/extern shader variable.
struct Uniform
@@ -227,13 +244,16 @@ private:
static StringMap<ShaderType, TYPE_MAX_ENUM>::Entry typeNameEntries[];
static StringMap<ShaderType, TYPE_MAX_ENUM> typeNames;
static StringMap<UniformType, UNIFORM_MAX_ENUM>::Entry uniformTypeEntries[];
static StringMap<UniformType, UNIFORM_MAX_ENUM> uniformTypes;
// Names for the generic vertex attributes used by love.
static StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry attribNameEntries[];
static StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM> attribNames;
// Names for the built-in uniform variables.
static StringMap<BuiltinExtern, BUILTIN_MAX_ENUM>::Entry builtinNameEntries[];
static StringMap<BuiltinExtern, BUILTIN_MAX_ENUM> builtinNames;
static StringMap<BuiltinUniform, BUILTIN_MAX_ENUM>::Entry builtinNameEntries[];
static StringMap<BuiltinUniform, BUILTIN_MAX_ENUM> builtinNames;
};
} // opengl
+2 -2
View File
@@ -111,7 +111,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
// Transform.
static Matrix t;
Matrix t;
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
t.transform(sprite, sprite, 4);
@@ -138,7 +138,7 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy,
// Needed for colors.
memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4);
static Matrix t;
Matrix t;
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
t.transform(sprite, sprite, 4);
@@ -346,6 +346,38 @@ int w_Shader_send(lua_State *L)
return luaL_argerror(L, 3, "number, boolean, table, image, or canvas expected");
}
int w_Shader_getExternVariable(lua_State *L)
{
Shader *shader = luax_checkshader(L, 1);
const char *name = luaL_checkstring(L, 2);
int components = 0;
int arrayelements = 0;
Shader::UniformType type = Shader::UNIFORM_UNKNOWN;
type = shader->getExternVariable(name, components, arrayelements);
// Check if the variable exists (function will set components to 0 if not.)
if (components > 0)
{
const char *tname = nullptr;
if (!Shader::getConstant(type, tname))
return luaL_error(L, "Unknown extern variable type name.");
lua_pushstring(L, tname);
lua_pushinteger(L, components);
lua_pushinteger(L, arrayelements);
}
else
{
lua_pushnil(L);
lua_pushnil(L);
lua_pushnil(L);
}
return 3;
}
static const luaL_Reg functions[] =
{
{ "getWarnings", w_Shader_getWarnings },
@@ -355,6 +387,7 @@ static const luaL_Reg functions[] =
{ "sendMatrix", w_Shader_sendMatrix },
{ "sendTexture", w_Shader_sendTexture },
{ "send", w_Shader_send },
{ "getExternVariable", w_Shader_getExternVariable },
{ 0, 0 }
};
@@ -38,6 +38,7 @@ int w_Shader_sendFloat(lua_State *L);
int w_Shader_sendMatrix(lua_State *L);
int w_Shader_sendTexture(lua_State *L);
int w_Shader_send(lua_State *L);
int w_Shader_getExternVariable(lua_State *L);
extern "C" int luaopen_shader(lua_State *L);
} // opengl