updated to latest mobile-common (should fix love.touch index problems)

This commit is contained in:
fysx
2014-05-03 14:13:40 +02:00
parent c40250e565
commit 97d9154e48
40 changed files with 321 additions and 199 deletions
@@ -286,8 +286,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);
@@ -312,7 +312,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];
}
@@ -920,11 +920,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();
@@ -937,7 +937,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
@@ -517,7 +517,7 @@ protected:
// Particles gravitate towards this point.
love::Vector origin;
love::Vector speed;
love::Vector velocity;
love::Vector linearAcceleration;
float radialAcceleration;
float tangentialAcceleration;
@@ -193,8 +193,16 @@ void Shader::createProgram(const std::vector<GLuint> &shaderids)
if (!GLAD_ES_VERSION_2_0 && i <= int(OpenGL::ATTRIB_COLOR))
continue;
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);
}
@@ -254,7 +262,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;
@@ -685,19 +693,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)];
@@ -725,9 +750,9 @@ bool Shader::sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *ve
return true;
}
bool Shader::sendBuiltinMatrix(BuiltinExtern builtin, int size, const GLfloat *m, int count)
bool Shader::sendBuiltinMatrix(BuiltinUniform builtin, int size, const GLfloat *m, int count)
{
if (!hasBuiltinExtern(builtin))
if (!hasBuiltinUniform(builtin))
return false;
GLint location = builtinUniforms[GLint(builtin)];
@@ -818,6 +843,16 @@ bool Shader::isSupported()
return GLAD_ES_VERSION_2_0 || (GLAD_VERSION_2_0 && 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},
@@ -826,6 +861,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[] =
{
{"VertexPosition", OpenGL::ATTRIB_POS},
@@ -836,7 +882,7 @@ 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[] =
{
{"TransformMatrix", Shader::BUILTIN_TRANSFORM_MATRIX},
{"ProjectionMatrix", Shader::BUILTIN_PROJECTION_MATRIX},
@@ -845,7 +891,7 @@ StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM>::Entry Shader::builti
{"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
+37 -18
View File
@@ -60,8 +60,8 @@ public:
TYPE_MAX_ENUM
};
// Built-in extern (uniform) variables.
enum BuiltinExtern
// Built-in uniform (extern) variables.
enum BuiltinUniform
{
BUILTIN_TRANSFORM_MATRIX = 0,
BUILTIN_PROJECTION_MATRIX,
@@ -71,6 +71,17 @@ public:
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;
@@ -143,13 +154,26 @@ 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 sendBuiltinMatrix(BuiltinExtern builtin, int size, const GLfloat *m, int count);
bool sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *m, int count);
bool hasBuiltinUniform(BuiltinUniform builtin) const;
bool sendBuiltinMatrix(BuiltinUniform builtin, int size, const GLfloat *m, int count);
bool sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *m, int count);
void checkSetScreenParams();
const std::map<std::string, Object *> &getBoundRetainables() const;
@@ -160,17 +184,10 @@ public:
// Default code used when renderers require code for a shader stage.
static ShaderSources defaultCode[Graphics::RENDERER_MAX_ENUM];
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
@@ -241,13 +258,15 @@ 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;
}; // Shader
@@ -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);
@@ -147,6 +147,9 @@ int w_Mesh_getVertices(lua_State *L)
size_t count = t->getVertexCount();
lua_createtable(L, count, 0);
if (count == 0 || vertices == nullptr)
return 1;
for (size_t i = 0; i < count; i++)
{
// Create vertex table.
@@ -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 },
// Deprecated since 0.9.1.
{ "sendImage", w_Shader_sendTexture },
@@ -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