Commits

Alex Szpakowski  committed 4df4415

Added a love.graphics.points function. love.graphics.point now uses it internally.

  • Participants
  • Parent commits 0ca63f4
  • Branches GLES2-compatibility

Comments (0)

Files changed (7)

File src/modules/graphics/opengl/Context.cpp

 	if (attrib == ATTRIB_NONE)
 		return;
 
+	// is this attribute already set to the state we want?
+	std::map<unsigned int, bool>::const_iterator attribenabled = state.enabledVertexAttribArrays.find(attrib);
+	if (attribenabled != state.enabledVertexAttribArrays.end() && attribenabled->second == use)
+		return;
+
 	// get the internal OpenGL representation for this attribute, if it exists
 	GLint glattrib = getVertexAttribID(attrib);
 	if (glattrib < 0)
 		return;
 
-	// is this attribute already set to the state we want?
-	std::map<unsigned int, bool>::const_iterator attribenabled = state.enabledVertexAttribArrays.find(attrib);
-	if (attribenabled != state.enabledVertexAttribArrays.end() && attribenabled->second == use)
-		return;
-
 	if (isGenericVertexAttrib(attrib))
 	{
 		if (use)

File src/modules/graphics/opengl/Graphics.cpp

  * Primitives
  **/
 
-void Graphics::point(float x, float y)
+void Graphics::points(const float *coords, size_t count)
 {
 	Context *ctx = getContext();
 
-	float vert[] = {x, y};
-
 	ctx->bindTexture(0);
 	ctx->useVertexAttribArrays(Context::ATTRIB_VERTEX);
-	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, vert);
+	ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, coords);
 
 	ctx->setupRender();
-	glDrawArrays(GL_POINTS, 0, 1);
+	glDrawArrays(GL_POINTS, 0, count / 2);
 }
 
 // Calculate line boundary points u1 and u2. Sketch:

File src/modules/graphics/opengl/Graphics.h

 	void printf(const char *str, float x, float y, float wrap, AlignMode align);
 
 	/**
-	 * Draws a point at (x,y).
-	 * @param x Point along x-axis.
-	 * @param y Point along y-axis.
+	 * Draws a series of points using the given vertices.
+	 * @param coords Vertex components (x1, y1, ..., xn, yn).
+	 * @param count Number of items in the array, i.e. count = 2 * n
 	 **/
-	void point(float x, float y);
+	void points(const float *coords, size_t count);
 
 	/**
 	 * Draws a series of lines connecting the given vertices.

File src/modules/graphics/opengl/wrap_Graphics.cpp

 	return 0;
 }
 
-int w_point(lua_State *L)
+int w_points(lua_State *L)
 {
-	float x = (float)luaL_checknumber(L, 1);
-	float y = (float)luaL_checknumber(L, 2);
-	instance->point(x, y);
+	int args = lua_gettop(L);
+
+	bool is_table = false;
+	if (args == 1 && lua_istable(L, 1))
+	{
+		args = lua_objlen(L, 1);
+		is_table = true;
+	}
+	if (args % 2 != 0)
+		return luaL_error(L, "Number of vertices must be a multiple of two");
+
+	float *coords = new float[args];
+
+	if (is_table)
+	{
+		for (int i = 0; i < args; ++i)
+		{
+			lua_pushnumber(L, i + 1);
+			lua_rawget(L, 1);
+			coords[i] = luax_tofloat(L, -1);
+			lua_pop(L, 1);
+		}
+	}
+	else
+	{
+		for (int i = 0; i < args; ++i)
+			coords[i] = luax_tofloat(L, i + 1);
+	}
+
+	instance->points(coords, args);
+
+	delete[] coords;
 	return 0;
 }
 
 	{ "setStencil", w_setStencil },
 	{ "setInvertedStencil", w_setInvertedStencil },
 
-	{ "point", w_point },
+	{ "points", w_points },
 	{ "line", w_line },
 	{ "triangle", w_triangle },
 	{ "rectangle", w_rectangle },

File src/modules/graphics/opengl/wrap_Graphics.h

 int w_drawq(lua_State *L);
 int w_print(lua_State *L);
 int w_printf(lua_State *L);
-int w_point(lua_State *L);
+int w_points(lua_State *L);
 int w_line(lua_State *L);
 int w_triangle(lua_State *L);
 int w_rectangle(lua_State *L);

File src/scripts/graphics.lua

 		return love.graphics.printf(...)
 	end
 
+	function love.graphics.point(x, y)
+		return love.graphics.points(x, y)
+	end
+
 
 	-- SHADERS
 

File src/scripts/graphics.lua.h

 	0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 
 	0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 
+	0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x28, 0x78, 0x2c, 0x20, 0x79, 0x29, 0x0a,
+	0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 
+	0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x28, 0x78, 0x2c, 0x20, 0x79, 0x29, 0x0a,
+	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x2d, 0x2d, 0x20, 0x53, 0x48, 0x41, 0x44, 0x45, 0x52, 0x53, 0x0a,
 	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 
 	0x4e, 0x20, 0x3d, 0x20, 0x22, 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x32, 0x30, 0x22, 0x0a,