Browse Source

Rename internal C++ Color struct to Color32 to help differentiate it from Colorf.

Alex Szpakowski 6 years ago
parent
commit
9ab2a94037

+ 4 - 4
src/common/Color.h

@@ -135,18 +135,18 @@ ColorT<T> operator/(const ColorT<T> &a, T s)
 	return tmp /= s;
 }
 
-typedef ColorT<unsigned char> Color;
+typedef ColorT<unsigned char> Color32;
 typedef ColorT<float> Colorf;
 
-inline Color toColor(Colorf cf)
+inline Color32 toColor32(Colorf cf)
 {
-	return Color((unsigned char) (cf.r * 255.0f),
+	return Color32((unsigned char) (cf.r * 255.0f),
 	             (unsigned char) (cf.g * 255.0f),
 	             (unsigned char) (cf.b * 255.0f),
 	             (unsigned char) (cf.a * 255.0f));
 }
 
-inline Colorf toColorf(Color c)
+inline Colorf toColorf(Color32 c)
 {
 	return Colorf(c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f);
 }

+ 6 - 6
src/modules/font/ImageRasterizer.cpp

@@ -29,7 +29,7 @@ namespace love
 namespace font
 {
 
-static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!");
+static_assert(sizeof(Color32) == 4, "sizeof(Color32) must equal 4 bytes!");
 
 ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float dpiscale)
 	: imageData(data)
@@ -76,17 +76,17 @@ GlyphData *ImageRasterizer::getGlyphData(uint32 glyph) const
 	// We don't want another thread modifying our ImageData mid-copy.
 	love::thread::Lock lock(imageData->getMutex());
 
-	Color *gdpixels = (Color *) g->getData();
-	const Color *imagepixels = (const Color *) imageData->getData();
+	Color32 *gdpixels = (Color32 *) g->getData();
+	const Color32 *imagepixels = (const Color32 *) imageData->getData();
 
 	// copy glyph pixels from imagedata to glyphdata
 	for (int i = 0; i < g->getWidth() * g->getHeight(); i++)
 	{
-		Color p = imagepixels[it->second.x + (i % gm.width) + (imageData->getWidth() * (i / gm.width))];
+		Color32 p = imagepixels[it->second.x + (i % gm.width) + (imageData->getWidth() * (i / gm.width))];
 
 		// Use transparency instead of the spacer color
 		if (p == spacer)
-			gdpixels[i] = Color(0, 0, 0, 0);
+			gdpixels[i] = Color32(0, 0, 0, 0);
 		else
 			gdpixels[i] = p;
 	}
@@ -96,7 +96,7 @@ GlyphData *ImageRasterizer::getGlyphData(uint32 glyph) const
 
 void ImageRasterizer::load()
 {
-	const Color *pixels = (const Color *) imageData->getData();
+	auto pixels = (const Color32 *) imageData->getData();
 
 	int imgw = imageData->getWidth();
 	int imgh = imageData->getHeight();

+ 1 - 1
src/modules/font/ImageRasterizer.h

@@ -76,7 +76,7 @@ private:
 	std::map<uint32, ImageGlyphData> imageGlyphs;
 
 	// Color used to identify glyph separation in the source ImageData
-	Color spacer;
+	Color32 spacer;
 
 }; // ImageRasterizer
 

+ 4 - 4
src/modules/graphics/Font.cpp

@@ -275,7 +275,7 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
 		double tX     = (double) textureX,     tY      = (double) textureY;
 		double tWidth = (double) textureWidth, tHeight = (double) textureHeight;
 
-		Color c(255, 255, 255, 255);
+		Color32 c(255, 255, 255, 255);
 
 		// Extrude the quad borders by 1 pixel. We have an extra pixel of
 		// transparent padding in the texture atlas, so the quad extrusion will
@@ -421,7 +421,7 @@ std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &c
 
 	Colorf linearconstantcolor = gammaCorrectColor(constantcolor);
 
-	Color curcolor = toColor(constantcolor);
+	Color32 curcolor = toColor32(constantcolor);
 	int curcolori = -1;
 	int ncolors = (int) codepoints.colors.size();
 
@@ -442,7 +442,7 @@ std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &c
 			c *= linearconstantcolor;
 			unGammaCorrectColor(c);
 
-			curcolor = toColor(c);
+			curcolor = toColor32(c);
 		}
 
 		if (g == '\n')
@@ -476,7 +476,7 @@ std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &c
 			vertices.resize(vertstartsize);
 			prevglyph = 0;
 			curcolori = -1;
-			curcolor = toColor(constantcolor);
+			curcolor = toColor32(constantcolor);
 			continue;
 		}
 

+ 6 - 6
src/modules/graphics/Graphics.cpp

@@ -1275,7 +1275,7 @@ void Graphics::points(const Vector2 *positions, const Colorf *colors, size_t num
 	else
 		t.transformXY0((Vector3 *) data.stream[0], positions, cmd.vertexCount);
 
-	Color *colordata = (Color *) data.stream[1];
+	Color32 *colordata = (Color32 *) data.stream[1];
 
 	if (colors)
 	{
@@ -1290,18 +1290,18 @@ void Graphics::points(const Vector2 *positions, const Colorf *colors, size_t num
 				gammaCorrectColor(ci);
 				ci *= nc;
 				unGammaCorrectColor(ci);
-				colordata[i] = toColor(ci);
+				colordata[i] = toColor32(ci);
 			}
 		}
 		else
 		{
 			for (int i = 0; i < cmd.vertexCount; i++)
-				colordata[i] = toColor(nc * colors[i]);
+				colordata[i] = toColor32(nc * colors[i]);
 		}
 	}
 	else
 	{
-		Color c = toColor(getColor());
+		Color32 c = toColor32(getColor());
 
 		for (int i = 0; i < cmd.vertexCount; i++)
 			colordata[i] = c;
@@ -1571,8 +1571,8 @@ void Graphics::polygon(DrawMode mode, const Vector2 *coords, size_t count, bool
 		else
 			t.transformXY0((Vector3 *) data.stream[0], coords, cmd.vertexCount);
 
-		Color c = toColor(getColor());
-		Color *colordata = (Color *) data.stream[1];
+		Color32 c = toColor32(getColor());
+		Color32 *colordata = (Color32 *) data.stream[1];
 		for (int i = 0; i < cmd.vertexCount; i++)
 			colordata[i] = c;
 	}

+ 2 - 2
src/modules/graphics/Mesh.cpp

@@ -34,7 +34,7 @@ namespace love
 namespace graphics
 {
 
-static const char *getBuiltinAttribName(VertexAttribID attribid)
+static const char *getBuiltinAttribName(BuiltinVertexAttribute attribid)
 {
 	const char *name = "";
 	vertex::getConstant(attribid, name);
@@ -602,7 +602,7 @@ void Mesh::drawInstanced(Graphics *gfx, const Matrix4 &m, int instancecount)
 
 		// If the attribute is one of the LOVE-defined ones, use the constant
 		// attribute index for it, otherwise query the index from the shader.
-		VertexAttribID builtinattrib;
+		BuiltinVertexAttribute builtinattrib;
 		if (vertex::getConstant(attrib.first.c_str(), builtinattrib))
 			attributeindex = (int) builtinattrib;
 		else if (Shader::current)

+ 3 - 3
src/modules/graphics/ParticleSystem.cpp

@@ -1062,7 +1062,7 @@ void ParticleSystem::draw(Graphics *gfx, const Matrix4 &m)
 
 		// Particle colors are stored as floats (0-1) but vertex colors are
 		// unsigned bytes (0-255).
-		Color c = toColor(p->color);
+		Color32 c = toColor32(p->color);
 
 		// set the texture coordinate and color data for particle vertices
 		for (int v = 0; v < 4; v++)
@@ -1076,10 +1076,10 @@ void ParticleSystem::draw(Graphics *gfx, const Matrix4 &m)
 		p = p->next;
 	}
 
-	Graphics::TempTransform transform(gfx, m);
-
 	buffer->unmap();
 
+	Graphics::TempTransform transform(gfx, m);
+
 	vertex::BufferBindings vertexbuffers;
 	vertexbuffers.set(0, buffer, 0);
 

+ 6 - 6
src/modules/graphics/Polyline.cpp

@@ -387,8 +387,8 @@ void Polyline::draw(love::graphics::Graphics *gfx)
 	else
 		t.transformXY0((Vector3 *) data.stream[0], vertices, total_vertex_count);
 
-	Color curcolor = toColor(gfx->getColor());
-	Color *colordata = (Color *) data.stream[1];
+	Color32 curcolor = toColor32(gfx->getColor());
+	Color32 *colordata = (Color32 *) data.stream[1];
 
 	for (int i = 0; i < (int) vertex_count; i++)
 		colordata[i] = curcolor;
@@ -397,21 +397,21 @@ void Polyline::draw(love::graphics::Graphics *gfx)
 		fill_color_array(curcolor, colordata + overdraw_vertex_start);
 }
 
-void Polyline::fill_color_array(Color constant_color, Color *colors)
+void Polyline::fill_color_array(Color32 constant_color, Color32 *colors)
 {
 	for (size_t i = 0; i < overdraw_vertex_count; ++i)
 	{
-		Color c = constant_color;
+		Color32 c = constant_color;
 		c.a *= (i+1) % 2; // avoids branching. equiv to if (i%2 == 1) c.a = 0;
 		colors[i] = c;
 	}
 }
 
-void NoneJoinPolyline::fill_color_array(Color constant_color, Color *colors)
+void NoneJoinPolyline::fill_color_array(Color32 constant_color, Color32 *colors)
 {
 	for (size_t i = 0; i < overdraw_vertex_count; ++i)
 	{
-		Color c = constant_color;
+		Color32 c = constant_color;
 		c.a *= (i & 3) < 2; // if (i % 4 == 2 || i % 4 == 3) c.a = 0
 		colors[i] = c;
 	}

+ 2 - 2
src/modules/graphics/Polyline.h

@@ -73,7 +73,7 @@ protected:
 
 	virtual void calc_overdraw_vertex_count(bool is_looping);
 	virtual void render_overdraw(const std::vector<Vector2> &normals, float pixel_size, bool is_looping);
-	virtual void fill_color_array(Color constant_color, Color *colors);
+	virtual void fill_color_array(Color32 constant_color, Color32 *colors);
 
 	/** Calculate line boundary points.
 	 *
@@ -133,7 +133,7 @@ protected:
 
 	virtual void calc_overdraw_vertex_count(bool is_looping);
 	virtual void render_overdraw(const std::vector<Vector2> &normals, float pixel_size, bool is_looping);
-	virtual void fill_color_array(Color constant_color, Color *colors);
+	virtual void fill_color_array(Color32 constant_color, Color32 *colors);
 	virtual void renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
 	                        Vector2 &s, float &len_s, Vector2 &ns,
 	                        const Vector2 &q, const Vector2 &r, float hw);

+ 3 - 3
src/modules/graphics/SpriteBatch.cpp

@@ -196,13 +196,13 @@ void SpriteBatch::setColor(const Colorf &c)
 	cclamped.b = std::min(std::max(c.b, 0.0f), 1.0f);
 	cclamped.a = std::min(std::max(c.a, 0.0f), 1.0f);
 
-	this->color = toColor(cclamped);
+	this->color = toColor32(cclamped);
 }
 
 void SpriteBatch::setColor()
 {
 	color_active = false;
-	color = Color(255, 255, 255, 255);
+	color = Color32(255, 255, 255, 255);
 }
 
 Colorf SpriteBatch::getColor(bool &active) const
@@ -357,7 +357,7 @@ void SpriteBatch::draw(Graphics *gfx, const Matrix4 &m)
 
 		// If the attribute is one of the LOVE-defined ones, use the constant
 		// attribute index for it, otherwise query the index from the shader.
-		VertexAttribID builtinattrib;
+		BuiltinVertexAttribute builtinattrib;
 		if (vertex::getConstant(it.first.c_str(), builtinattrib))
 			attributeindex = (int) builtinattrib;
 		else if (Shader::current)

+ 1 - 1
src/modules/graphics/SpriteBatch.h

@@ -133,7 +133,7 @@ private:
 
 	// Current color. This color, if present, will be applied to the next
 	// added sprite.
-	Color color;
+	Color32 color;
 	bool color_active;
 
 	vertex::CommonFormat vertex_format;

+ 2 - 2
src/modules/graphics/Texture.cpp

@@ -150,7 +150,7 @@ void Texture::draw(Graphics *gfx, Quad *q, const Matrix4 &localTransform)
 	const Vector2 *texcoords = q->getVertexTexCoords();
 	vertex::STf_RGBAub *vertexdata = (vertex::STf_RGBAub *) data.stream[1];
 
-	Color c = toColor(gfx->getColor());
+	Color32 c = toColor32(gfx->getColor());
 
 	for (int i = 0; i < 4; i++)
 	{
@@ -178,7 +178,7 @@ void Texture::drawLayer(Graphics *gfx, int layer, Quad *q, const Matrix4 &m)
 	if (layer < 0 || layer >= layers)
 		throw love::Exception("Invalid layer: %d (Texture has %d layers)", layer + 1, layers);
 
-	Color c = toColor(gfx->getColor());
+	Color32 c = toColor32(gfx->getColor());
 
 	const Matrix4 &tm = gfx->getTransform();
 	bool is2D = tm.isAffine2DTransform();

+ 2 - 2
src/modules/graphics/Video.cpp

@@ -42,7 +42,7 @@ Video::Video(Graphics *gfx, love::video::VideoStream *stream, float dpiscale)
 	stream->fillBackBuffer();
 
 	for (int i = 0; i < 4; i++)
-		vertices[i].color = Color(255, 255, 255, 255);
+		vertices[i].color = Color32(255, 255, 255, 255);
 
 	// Vertices are ordered for use with triangle strips:
 	// 0---2
@@ -130,7 +130,7 @@ void Video::draw(Graphics *gfx, const Matrix4 &m)
 
 	vertex::STf_RGBAub *verts = (vertex::STf_RGBAub *) data.stream[1];
 
-	Color c = toColor(gfx->getColor());
+	Color32 c = toColor32(gfx->getColor());
 
 	for (int i = 0; i < 4; i++)
 	{

+ 2 - 2
src/modules/graphics/opengl/Shader.cpp

@@ -333,7 +333,7 @@ bool Shader::loadVolatile()
 	for (int i = 0; i < int(ATTRIB_MAX_ENUM); i++)
 	{
 		const char *name = nullptr;
-		if (vertex::getConstant((VertexAttribID) i, name))
+		if (vertex::getConstant((BuiltinVertexAttribute) i, name))
 			glBindAttribLocation(program, i, (const GLchar *) name);
 	}
 
@@ -356,7 +356,7 @@ bool Shader::loadVolatile()
 	for (int i = 0; i < int(ATTRIB_MAX_ENUM); i++)
 	{
 		const char *name = nullptr;
-		if (vertex::getConstant(VertexAttribID(i), name))
+		if (vertex::getConstant(BuiltinVertexAttribute(i), name))
 			builtinAttributes[i] = glGetAttribLocation(program, name);
 		else
 			builtinAttributes[i] = -1;

+ 10 - 10
src/modules/graphics/vertex.cpp

@@ -28,14 +28,14 @@ namespace graphics
 namespace vertex
 {
 
-static_assert(sizeof(Color) == 4, "sizeof(Color) incorrect!");
-static_assert(sizeof(STf_RGBAub) == sizeof(float)*2 + sizeof(Color), "sizeof(STf_RGBAub) incorrect!");
-static_assert(sizeof(STPf_RGBAub) == sizeof(float)*3 + sizeof(Color), "sizeof(STPf_RGBAub) incorrect!");
+static_assert(sizeof(Color32) == 4, "sizeof(Color32) incorrect!");
+static_assert(sizeof(STf_RGBAub) == sizeof(float)*2 + sizeof(Color32), "sizeof(STf_RGBAub) incorrect!");
+static_assert(sizeof(STPf_RGBAub) == sizeof(float)*3 + sizeof(Color32), "sizeof(STPf_RGBAub) incorrect!");
 static_assert(sizeof(XYf_STf) == sizeof(float)*2 + sizeof(float)*2, "sizeof(XYf_STf) incorrect!");
 static_assert(sizeof(XYf_STPf) == sizeof(float)*2 + sizeof(float)*3, "sizeof(XYf_STPf) incorrect!");
-static_assert(sizeof(XYf_STf_RGBAub) == sizeof(float)*2 + sizeof(float)*2 + sizeof(Color), "sizeof(XYf_STf_RGBAub) incorrect!");
-static_assert(sizeof(XYf_STus_RGBAub) == sizeof(float)*2 + sizeof(uint16)*2 + sizeof(Color), "sizeof(XYf_STus_RGBAub) incorrect!");
-static_assert(sizeof(XYf_STPf_RGBAub) == sizeof(float)*2 + sizeof(float)*3 + sizeof(Color), "sizeof(XYf_STPf_RGBAub) incorrect!");
+static_assert(sizeof(XYf_STf_RGBAub) == sizeof(float)*2 + sizeof(float)*2 + sizeof(Color32), "sizeof(XYf_STf_RGBAub) incorrect!");
+static_assert(sizeof(XYf_STus_RGBAub) == sizeof(float)*2 + sizeof(uint16)*2 + sizeof(Color32), "sizeof(XYf_STus_RGBAub) incorrect!");
+static_assert(sizeof(XYf_STPf_RGBAub) == sizeof(float)*2 + sizeof(float)*3 + sizeof(Color32), "sizeof(XYf_STPf_RGBAub) incorrect!");
 
 size_t getFormatStride(CommonFormat format)
 {
@@ -277,7 +277,7 @@ void Attributes::setCommonFormat(CommonFormat format, uint8 bufferindex)
 	}
 }
 
-static StringMap<VertexAttribID, ATTRIB_MAX_ENUM>::Entry attribNameEntries[] =
+static StringMap<BuiltinVertexAttribute, ATTRIB_MAX_ENUM>::Entry attribNameEntries[] =
 {
 	{ "VertexPosition", ATTRIB_POS           },
 	{ "VertexTexCoord", ATTRIB_TEXCOORD      },
@@ -285,7 +285,7 @@ static StringMap<VertexAttribID, ATTRIB_MAX_ENUM>::Entry attribNameEntries[] =
 	{ "ConstantColor",  ATTRIB_CONSTANTCOLOR },
 };
 
-static StringMap<VertexAttribID, ATTRIB_MAX_ENUM> attribNames(attribNameEntries, sizeof(attribNameEntries));
+static StringMap<BuiltinVertexAttribute, ATTRIB_MAX_ENUM> attribNames(attribNameEntries, sizeof(attribNameEntries));
 
 static StringMap<IndexDataType, INDEX_MAX_ENUM>::Entry indexTypeEntries[] =
 {
@@ -348,12 +348,12 @@ static StringMap<Winding, WINDING_MAX_ENUM>::Entry windingEntries[] =
 
 static StringMap<Winding, WINDING_MAX_ENUM> windings(windingEntries, sizeof(windingEntries));
 
-bool getConstant(const char *in, VertexAttribID &out)
+bool getConstant(const char *in, BuiltinVertexAttribute &out)
 {
 	return attribNames.find(in, out);
 }
 
-bool getConstant(VertexAttribID in, const char *&out)
+bool getConstant(BuiltinVertexAttribute in, const char *&out)
 {
 	return attribNames.find(in, out);
 }

+ 9 - 9
src/modules/graphics/vertex.h

@@ -38,7 +38,7 @@ class Resource;
 
 // Vertex attribute indices used in shaders by LOVE. The values map to GPU
 // generic vertex attribute indices.
-enum VertexAttribID
+enum BuiltinVertexAttribute
 {
 	ATTRIB_POS = 0,
 	ATTRIB_TEXCOORD,
@@ -47,7 +47,7 @@ enum VertexAttribID
 	ATTRIB_MAX_ENUM
 };
 
-enum VertexAttribFlags
+enum BuiltinVertexAttributeFlag
 {
 	ATTRIBFLAG_POS = 1 << ATTRIB_POS,
 	ATTRIBFLAG_TEXCOORD = 1 << ATTRIB_TEXCOORD,
@@ -147,13 +147,13 @@ enum class CommonFormat
 struct STf_RGBAub
 {
 	float s, t;
-	Color color;
+	Color32 color;
 };
 
 struct STPf_RGBAub
 {
 	float s, t, p;
-	Color color;
+	Color32 color;
 };
 
 struct XYf_STf
@@ -172,21 +172,21 @@ struct XYf_STf_RGBAub
 {
 	float x, y;
 	float s, t;
-	Color color;
+	Color32 color;
 };
 
 struct XYf_STus_RGBAub
 {
 	float  x, y;
 	uint16 s, t;
-	Color  color;
+	Color32 color;
 };
 
 struct XYf_STPf_RGBAub
 {
 	float x, y;
 	float s, t, p;
-	Color color;
+	Color32 color;
 };
 
 struct BufferBindings
@@ -306,8 +306,8 @@ int getIndexCount(TriangleIndexMode mode, int vertexCount);
 void fillIndices(TriangleIndexMode mode, uint16 vertexStart, uint16 vertexCount, uint16 *indices);
 void fillIndices(TriangleIndexMode mode, uint32 vertexStart, uint32 vertexCount, uint32 *indices);
 
-bool getConstant(const char *in, VertexAttribID &out);
-bool getConstant(VertexAttribID in, const char *&out);
+bool getConstant(const char *in, BuiltinVertexAttribute &out);
+bool getConstant(BuiltinVertexAttribute in, const char *&out);
 
 bool getConstant(const char *in, IndexDataType &out);
 bool getConstant(IndexDataType in, const char *&out);

+ 2 - 2
src/modules/image/magpie/STBHandler.cpp

@@ -50,7 +50,7 @@ namespace image
 namespace magpie
 {
 
-static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!");
+static_assert(sizeof(Color32) == 4, "sizeof(Color32) must equal 4 bytes!");
 
 bool STBHandler::canDecode(Data *data)
 {
@@ -147,7 +147,7 @@ FormatHandler::EncodedImage STBHandler::encode(const DecodedImage &img, EncodedF
 	memcpy(encimg.data + headerlen, img.data, img.width * img.height * bpp);
 
 	// convert the pixels from RGBA to BGRA.
-	Color *encodedpixels = (Color *) (encimg.data + headerlen);
+	Color32 *encodedpixels = (Color32 *) (encimg.data + headerlen);
 	for (int y = 0; y < img.height; y++)
 	{
 		for (int x = 0; x < img.width; x++)