Alex Szpakowski avatar Alex Szpakowski committed bd006b0

Better boolean shader extern support

Comments (0)

Files changed (3)

src/modules/graphics/opengl/wrap_ShaderEffect.cpp

 	float *values = new float[count];
 	for (int i = 0; i < count; ++i)
 	{
-		if (!lua_isnumber(L, 3 + i))
+		if (lua_isnumber(L, 3 + i))
+			values[i] = (float)lua_tonumber(L, 3 + i);
+		else if (lua_isboolean(L, 3 + i))
+			values[i] = (float)lua_toboolean(L, 3 + i);
+		else
 		{
 			delete[] values;
-			return luaL_typerror(L, 3 + i, "number");
+			return luaL_typerror(L, 3 + i, "number or boolean");
 		}
 		values[i] = (float)lua_tonumber(L, 3 + i);
 	}
 		for (size_t k = 1; k <= dimension; ++k)
 		{
 			lua_rawgeti(L, 3 + i, k);
-			values[i * dimension + k - 1] = (float)lua_tonumber(L, -1);
+			if (lua_isboolean(L, -1))
+				values[i * dimension + k - 1] = (float)lua_toboolean(L, -1);
+			else
+				values[i * dimension + k - 1] = (float)lua_tonumber(L, -1);
 		}
 		lua_pop(L, int(dimension));
 	}
 	if (count < 1)
 		return luaL_error(L, "No variable to send.");
 
-	if (lua_isnumber(L, 3))
+	if (lua_isnumber(L, 3) || lua_isboolean(L, 3))
 		return _sendScalars(L, effect, name, count);
 	else if (lua_istable(L, 3))
 		return _sendVectors(L, effect, name, count);
 
-	return luaL_typerror(L, 3, "number or table");
+	return luaL_typerror(L, 3, "number, boolean or table");
 }
 
 int w_ShaderEffect_sendMatrix(lua_State *L)

src/scripts/graphics.lua

 	-- automagic uniform setter
 	local function shadereffect_dispatch_send(self, name, value, ...)
 		local valuetype = type(value)
-		if valuetype == "number" then         -- scalar
+		if valuetype == "number" or valuetype == "boolean" then -- scalar
 			self:sendFloat(name, value, ...)
 		elseif valuetype == "userdata" and value:typeOf("Image") then
 			self:sendImage(name, value)
 		elseif valuetype == "userdata" and value:typeOf("Canvas") then
 			self:sendCanvas(name, value)
 		elseif valuetype == "table" then      -- vector or matrix
-			if type(value[1]) == "number" then
+			valuetype = type(value[1])
+			if valuetype == "number" or valuetype == "boolean" then
 				self:sendFloat(name, value, ...)
-			elseif type(value[1]) == "table" then
+			elseif valuetype == "table" then
 				self:sendMatrix(name, flattenMatrices(value, ...))
 			else
-				error("Cannot send value (unsupported type: {"..type(value[1]).."}).")
+				error("Cannot send value (unsupported type: {"..valuetype.."}).")
 			end
-		elseif valuetype == "boolean" then
-			self:sendFloat(name, value and 1 or 0)
 		else
 			if valuetype == "userdata" and value.type then valuetype = value.type end
 			error("Cannot send value (unsupported type: "..valuetype..").")
 		local effect = love.graphics.newShaderEffect(vertcode, fragcode)
 		local meta = getmetatable(effect)
 		meta.send = shadereffect_dispatch_send
+		meta.sendBoolean = meta.sendFloat
 		return effect
 	end
 

src/scripts/graphics.lua.h

 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 
 	0x3d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x29, 0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 
-	0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x20, 0x20, 0x20, 0x20, 
-	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x72, 0x0a,
+	0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 
+	0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x20, 0x74, 
+	0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x72, 0x0a,
 	0x09, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x65, 0x6e, 0x64, 0x46, 0x6c, 0x6f, 0x61, 0x74, 0x28, 
 	0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2c, 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a,
 	0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 
 	0x20, 0x3d, 0x3d, 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x20, 
 	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x6f, 0x72, 0x20, 0x6d, 
 	0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
-	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5b, 0x31, 
-	0x5d, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 
-	0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 
+	0x65, 0x28, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5b, 0x31, 0x5d, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 
+	0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 
+	0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x20, 
+	0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x65, 0x6e, 0x64, 0x46, 0x6c, 0x6f, 0x61, 0x74, 
 	0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2c, 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a,
-	0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x61, 0x6c, 
-	0x75, 0x65, 0x5b, 0x31, 0x5d, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 
-	0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 
+	0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x61, 0x74, 0x72, 0x69, 
 	0x78, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x66, 0x6c, 0x61, 0x74, 0x74, 0x65, 0x6e, 0x4d, 0x61, 0x74, 
 	0x72, 0x69, 0x63, 0x65, 0x73, 0x28, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2c, 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x43, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 
 	0x73, 0x65, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x28, 0x75, 0x6e, 0x73, 0x75, 0x70, 0x70, 
-	0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x7b, 0x22, 0x2e, 0x2e, 0x74, 0x79, 
-	0x70, 0x65, 0x28, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5b, 0x31, 0x5d, 0x29, 0x2e, 0x2e, 0x22, 0x7d, 0x29, 0x2e, 
-	0x22, 0x29, 0x0a,
+	0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x7b, 0x22, 0x2e, 0x2e, 0x76, 0x61, 
+	0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x7d, 0x29, 0x2e, 0x22, 0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
-	0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 
-	0x20, 0x3d, 0x3d, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
-	0x09, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x65, 0x6e, 0x64, 0x46, 0x6c, 0x6f, 0x61, 0x74, 0x28, 
-	0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x31, 0x20, 
-	0x6f, 0x72, 0x20, 0x30, 0x29, 0x0a,
 	0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
 	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 
 	0x20, 0x22, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 
 	0x09, 0x09, 0x6d, 0x65, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x68, 0x61, 0x64, 
 	0x65, 0x72, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x5f, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x5f, 
 	0x73, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x6d, 0x65, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x6e, 0x64, 0x42, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 
+	0x20, 0x3d, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x6e, 0x64, 0x46, 0x6c, 0x6f, 0x61, 0x74, 0x0a,
 	0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x2d, 0x2d, 0x20, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x45, 0x66, 0x66, 0x65, 0x63, 0x74, 0x20, 0x63, 0x6f, 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.