Backout changeset b3928e24add23da69dcd90c34985cd6a05454be0

This commit is contained in:
Alex Szpakowski
2014-05-03 22:07:32 -03:00
parent 4bc96f1bf6
commit 5428a5d75f
7 changed files with 78 additions and 158 deletions
+2 -2
View File
@@ -544,9 +544,9 @@ Canvas *Graphics::newCanvas(int width, int height, Texture::Format format, int f
return NULL; // never reached
}
Shader *Graphics::newShader(const std::vector<std::string> &vertcode, const std::vector<std::string> &pixelcode)
Shader *Graphics::newShader(const Shader::ShaderSources &sources)
{
return new Shader(vertcode, pixelcode);
return new Shader(sources);
}
Mesh *Graphics::newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode mode)
+1 -1
View File
@@ -210,7 +210,7 @@ public:
Canvas *newCanvas(int width, int height, Texture::Format format = Texture::FORMAT_NORMAL, int fsaa = 0);
Shader *newShader(const std::vector<std::string> &vertcode, const std::vector<std::string> &pixelcode);
Shader *newShader(const Shader::ShaderSources &sources);
Mesh *newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN);
Mesh *newMesh(int vertexcount, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN);
+12 -27
View File
@@ -66,25 +66,21 @@ Shader *Shader::current = nullptr;
GLint Shader::maxTexUnits = 0;
std::vector<int> Shader::textureCounters;
Shader::Shader(const std::vector<std::string> &vertcode, const std::vector<std::string> &pixelcode)
: program(0)
Shader::Shader(const ShaderSources &sources)
: shaderSources(sources)
, program(0)
, builtinUniforms()
, vertexAttributes()
, lastCanvas((Canvas *) -1)
, lastViewport()
{
if (vertcode.empty() && pixelcode.empty())
if (shaderSources.empty())
throw love::Exception("Cannot create shader: no source code!");
shaderSources[TYPE_VERTEX] = vertcode;
shaderSources[TYPE_PIXEL] = pixelcode;
if (maxTexUnits <= 0)
{
GLint maxtexunits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
// TU 0 is never used for stored Shader images.
maxTexUnits = std::max(maxtexunits - 1, 0);
}
@@ -110,7 +106,7 @@ Shader::~Shader()
unloadVolatile();
}
GLuint Shader::compileCode(ShaderType type, const std::vector<std::string> &code)
GLuint Shader::compileCode(ShaderType type, const std::string &code)
{
GLenum glshadertype;
const char *typestr;
@@ -146,18 +142,9 @@ GLuint Shader::compileCode(ShaderType type, const std::vector<std::string> &code
throw love::Exception("Cannot create %s shader object.", typestr);
}
std::vector<const GLchar *> codelist;
std::vector<GLint> lengthlist;
for (size_t i = 0; i < code.size(); i++)
{
codelist.push_back((const GLchar *) code[i].c_str());
lengthlist.push_back((GLint) code[i].length());
}
// The code parameter is a list of source code "files." We can hand them
// all to OpenGL at once using glShaderSource.
glShaderSource(shaderid, codelist.size(), &codelist[0], &lengthlist[0]);
const char *src = code.c_str();
size_t srclen = code.length();
glShaderSource(shaderid, 1, (const GLchar **)&src, (GLint *)&srclen);
glCompileShader(shaderid);
@@ -289,12 +276,10 @@ bool Shader::loadVolatile()
std::vector<GLuint> shaderids;
for (int i = 0; i < (int) TYPE_MAX_ENUM; i++)
ShaderSources::const_iterator source;
for (source = shaderSources.begin(); source != shaderSources.end(); ++source)
{
if (shaderSources[i].empty())
continue;
GLuint shaderid = compileCode((ShaderType) i, shaderSources[i]);
GLuint shaderid = compileCode(source->first, source->second);
shaderids.push_back(shaderid);
}
@@ -303,7 +288,7 @@ bool Shader::loadVolatile()
createProgram(shaderids);
// Get all active uniform variables in this shader from OpenGL.
// Retreive all active uniform variables in this shader from OpenGL.
mapActiveUniforms();
for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++)
+8 -6
View File
@@ -74,11 +74,14 @@ public:
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;
/**
* Creates a new Shader using a list of source codes.
* The sources must contain either vertex or pixel shader code, or both.
* Sources must contain either vertex or pixel shader code, or both.
**/
Shader(const std::vector<std::string> &vertcode, const std::vector<std::string> &pixelcode);
Shader(const ShaderSources &sources);
virtual ~Shader();
@@ -193,7 +196,7 @@ private:
UniformType getUniformBaseType(GLenum type) const;
void checkSetUniformError(const Uniform &u, int size, int count, UniformType sendtype) const;
GLuint compileCode(ShaderType type, const std::vector<std::string> &code);
GLuint compileCode(ShaderType type, const std::string &code);
void createProgram(const std::vector<GLuint> &shaderids);
int getTextureUnit(const std::string &name);
@@ -203,9 +206,8 @@ private:
// Get any warnings or errors generated only by the shader program object.
std::string getProgramWarnings() const;
// List of all shader code attached to this Shader. Each shader type has its
// own list, which represents separate "files".
std::vector<std::string> shaderSources[TYPE_MAX_ENUM];
// List of all shader code attached to this Shader
ShaderSources shaderSources;
// Shader compiler warning strings for individual shader stages.
std::map<ShaderType, std::string> shaderWarnings;
+18 -51
View File
@@ -353,16 +353,16 @@ int w_newShader(lua_State *L)
if (!Shader::isSupported())
return luaL_error(L, "Sorry, your graphics card does not support shaders.");
// Clamp stack to 2 elements.
// clamp stack to 2 elements
lua_settop(L, 2);
// Read any filepath arguments.
// read any filepath arguments
for (int i = 1; i <= 2; i++)
{
if (!lua_isstring(L, i))
continue;
// Call love.filesystem.isFile(arg_i)
// call love.filesystem.isFile(arg_i)
luax_getfunction(L, "filesystem", "isFile");
lua_pushvalue(L, i);
lua_call(L, 1, 1);
@@ -382,76 +382,43 @@ int w_newShader(lua_State *L)
bool has_arg1 = lua_isstring(L, 1);
bool has_arg2 = lua_isstring(L, 2);
// Require at least one string argument.
// require at least one string argument
if (!(has_arg1 || has_arg2))
luaL_checkstring(L, 1);
luax_getfunction(L, "graphics", "_shaderCodeToGLSL");
// Push vertexcode and pixelcode strings to the top of the stack.
// push vertexcode and pixelcode strings to the top of the stack
lua_pushvalue(L, 1);
lua_pushvalue(L, 2);
// Call shaderCodeToGLSL, returned values will be at the top of the stack.
// call effectCodeToGLSL, returned values will be at the top of the stack
if (lua_pcall(L, 2, 2, 0) != 0)
return luaL_error(L, "%s", lua_tostring(L, -1));
// Each shader type might contain several source code strings.
std::vector<std::string> sources[Shader::TYPE_MAX_ENUM];
Shader::ShaderSources sources;
// Vertex shader code.
if (!lua_isnoneornil(L, -2))
// vertex shader code
if (lua_isstring(L, -2))
{
std::vector<std::string> &source = sources[Shader::TYPE_VERTEX];
// The argument might be a Lua array containing strings for the code.
if (lua_istable(L, -2))
{
// Convert table index to absolute.
int idx = lua_gettop(L) + 1 - 2;
// Get all the shader code strings from the Lua array.
for (size_t i = 1; i <= lua_objlen(L, idx); i++)
{
lua_rawgeti(L, idx, i);
source.push_back(luax_checkstring(L, -1));
lua_pop(L, 1);
}
}
else
source.push_back(luax_checkstring(L, -2));
std::string vertexcode(luaL_checkstring(L, -2));
sources[Shader::TYPE_VERTEX] = vertexcode;
}
else if (has_arg1 && has_arg2)
return luaL_error(L, "Could not parse vertex shader code (missing 'position' function?)");
// Pixel shader code.
if (!lua_isnoneornil(L, -1))
// pixel shader code
if (lua_isstring(L, -1))
{
std::vector<std::string> &source = sources[Shader::TYPE_PIXEL];
// The argument might be a Lua array containing strings for the code.
if (lua_istable(L, -1))
{
// Convert table index to absolute.
int idx = lua_gettop(L) + 1 - 1;
// Get all the shader code strings from the Lua array.
for (size_t i = 1; i <= lua_objlen(L, idx); i++)
{
lua_rawgeti(L, idx, i);
source.push_back(luax_checkstring(L, -1));
lua_pop(L, 1);
}
}
else
source.push_back(luax_checkstring(L, -1));
std::string pixelcode(luaL_checkstring(L, -1));
sources[Shader::TYPE_PIXEL] = pixelcode;
}
else if (has_arg1 && has_arg2)
return luaL_error(L, "Could not parse pixel shader code (missing 'effect' function?)");
if (sources[Shader::TYPE_VERTEX].empty() && sources[Shader::TYPE_PIXEL].empty())
if (sources.empty())
{
// Original args had source code, but shaderCodeToGLSL couldn't translate it
// Original args had source code, but effectCodeToGLSL couldn't translate it
for (int i = 1; i <= 2; i++)
{
if (lua_isstring(L, i))
@@ -462,7 +429,7 @@ int w_newShader(lua_State *L)
bool should_error = false;
try
{
Shader *shader = instance->newShader(sources[Shader::TYPE_VERTEX], sources[Shader::TYPE_PIXEL]);
Shader *shader = instance->newShader(sources);
luax_pushtype(L, "Shader", GRAPHICS_SHADER_T, shader);
}
catch (love::Exception &e)