Templated the Color structure so it can be used for the new integer and unsigned integer color types.

TRAC #23256

Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
Author: Geoff Lang
diff --git a/src/common/utilities.h b/src/common/utilities.h
index 8f78ec6..f55f6a0 100644
--- a/src/common/utilities.h
+++ b/src/common/utilities.h
@@ -22,8 +22,6 @@
 namespace gl
 {
 
-struct Color;
-
 int UniformComponentCount(GLenum type);
 GLenum UniformComponentType(GLenum type);
 size_t UniformComponentSize(GLenum type);
diff --git a/src/libGLESv2/Context.h b/src/libGLESv2/Context.h
index bc0dd31..fbacb8f 100644
--- a/src/libGLESv2/Context.h
+++ b/src/libGLESv2/Context.h
@@ -148,7 +148,7 @@
 // Helper structure to store all raw state
 struct State
 {
-    Color colorClearValue;
+    ColorF colorClearValue;
     GLclampf depthClearValue;
     int stencilClearValue;
 
@@ -157,7 +157,7 @@
     Rectangle scissor;
 
     BlendState blend;
-    Color blendColor;
+    ColorF blendColor;
     bool sampleCoverage;
     GLclampf sampleCoverageValue;
     bool sampleCoverageInvert;
diff --git a/src/libGLESv2/angletypes.h b/src/libGLESv2/angletypes.h
index d2bf87e..7278090 100644
--- a/src/libGLESv2/angletypes.h
+++ b/src/libGLESv2/angletypes.h
@@ -29,14 +29,19 @@
     SAMPLER_VERTEX
 };
 
+template <typename T>
 struct Color
 {
-    float red;
-    float green;
-    float blue;
-    float alpha;
+    T red;
+    T green;
+    T blue;
+    T alpha;
 };
 
+typedef Color<float> ColorF;
+typedef Color<int> ColorI;
+typedef Color<unsigned int> ColorUI;
+
 struct Rectangle
 {
     int x;
@@ -125,7 +130,7 @@
 {
     GLbitfield mask;
 
-    Color colorClearValue;
+    ColorF colorClearValue;
     bool colorMaskRed;
     bool colorMaskGreen;
     bool colorMaskBlue;
diff --git a/src/libGLESv2/renderer/Renderer.h b/src/libGLESv2/renderer/Renderer.h
index 29769e5..fc1e696 100644
--- a/src/libGLESv2/renderer/Renderer.h
+++ b/src/libGLESv2/renderer/Renderer.h
@@ -118,7 +118,7 @@
     virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
 
     virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
-    virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
+    virtual void setBlendState(const gl::BlendState &blendState, const gl::ColorF &blendColor,
                                unsigned int sampleMask) = 0;
     virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
                                       int stencilBackRef, bool frontFaceCCW) = 0;
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
index 684c2c5..15aed65 100644
--- a/src/libGLESv2/renderer/Renderer11.cpp
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -700,12 +700,12 @@
     mForceSetRasterState = false;
 }
 
-void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
+void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::ColorF &blendColor,
                                unsigned int sampleMask)
 {
     if (mForceSetBlendState ||
         memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 ||
-        memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 ||
+        memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0 ||
         sampleMask != mCurSampleMask)
     {
         ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState);
@@ -3500,7 +3500,7 @@
 }
 
 static inline void readPixelColor(const unsigned char *data, DXGI_FORMAT format, unsigned int x,
-                                  unsigned int y, int inputPitch, gl::Color *outColor)
+                                  unsigned int y, int inputPitch, gl::ColorF *outColor)
 {
     switch (format)
     {
@@ -3616,7 +3616,7 @@
     }
 }
 
-static inline void writePixelColor(const gl::Color &color, GLenum format, GLenum type, unsigned int x,
+static inline void writePixelColor(const gl::ColorF &color, GLenum format, GLenum type, unsigned int x,
                                    unsigned int y, int outputPitch, void *outData)
 {
     unsigned char* byteData = reinterpret_cast<unsigned char*>(outData);
@@ -3846,7 +3846,7 @@
     }
     else
     {
-        gl::Color pixelColor;
+        gl::ColorF pixelColor;
         for (int j = 0; j < area.height; j++)
         {
             for (int i = 0; i < area.width; i++)
diff --git a/src/libGLESv2/renderer/Renderer11.h b/src/libGLESv2/renderer/Renderer11.h
index 5738b85..e83258b 100644
--- a/src/libGLESv2/renderer/Renderer11.h
+++ b/src/libGLESv2/renderer/Renderer11.h
@@ -60,7 +60,7 @@
     virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
 
     virtual void setRasterizerState(const gl::RasterizerState &rasterState);
-    virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
+    virtual void setBlendState(const gl::BlendState &blendState, const gl::ColorF &blendColor,
                                unsigned int sampleMask);
     virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
                                       int stencilBackRef, bool frontFaceCCW);
@@ -291,7 +291,7 @@
     // Currently applied blend state
     bool mForceSetBlendState;
     gl::BlendState mCurBlendState;
-    gl::Color mCurBlendColor;
+    gl::ColorF mCurBlendColor;
     unsigned int mCurSampleMask;
 
     // Currently applied rasterizer state
diff --git a/src/libGLESv2/renderer/Renderer9.cpp b/src/libGLESv2/renderer/Renderer9.cpp
index 159e5db..96597be 100644
--- a/src/libGLESv2/renderer/Renderer9.cpp
+++ b/src/libGLESv2/renderer/Renderer9.cpp
@@ -7,6 +7,8 @@
 
 // Renderer9.cpp: Implements a back-end specific class for the D3D9 renderer.
 
+#include "common/utilities.h"
+
 #include "libGLESv2/main.h"
 #include "libGLESv2/Buffer.h"
 #include "libGLESv2/Texture.h"
@@ -815,10 +817,10 @@
     mForceSetRasterState = false;
 }
 
-void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, unsigned int sampleMask)
+void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::ColorF &blendColor, unsigned int sampleMask)
 {
     bool blendStateChanged = mForceSetBlendState || memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0;
-    bool blendColorChanged = mForceSetBlendState || memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0;
+    bool blendColorChanged = mForceSetBlendState || memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0;
     bool sampleMaskChanged = mForceSetBlendState || sampleMask != mCurSampleMask;
 
     if (blendStateChanged || blendColorChanged)
diff --git a/src/libGLESv2/renderer/Renderer9.h b/src/libGLESv2/renderer/Renderer9.h
index 4b7e1a3..7f046af 100644
--- a/src/libGLESv2/renderer/Renderer9.h
+++ b/src/libGLESv2/renderer/Renderer9.h
@@ -74,7 +74,7 @@
     virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
 
     virtual void setRasterizerState(const gl::RasterizerState &rasterState);
-    virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
+    virtual void setBlendState(const gl::BlendState &blendState, const gl::ColorF &blendColor,
                                unsigned int sampleMask);
     virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
                                       int stencilBackRef, bool frontFaceCCW);
@@ -334,7 +334,7 @@
 
     bool mForceSetBlendState;
     gl::BlendState mCurBlendState;
-    gl::Color mCurBlendColor;
+    gl::ColorF mCurBlendColor;
     GLuint mCurSampleMask;
 
     // Currently applied sampler states
diff --git a/src/libGLESv2/renderer/renderer11_utils.cpp b/src/libGLESv2/renderer/renderer11_utils.cpp
index 2944a55..4861f82 100644
--- a/src/libGLESv2/renderer/renderer11_utils.cpp
+++ b/src/libGLESv2/renderer/renderer11_utils.cpp
@@ -236,7 +236,7 @@
 }
 
 void SetPositionDepthColorVertex(PositionDepthColorVertex* vertex, float x, float y, float z,
-                                 const gl::Color &color)
+                                 const gl::ColorF &color)
 {
     vertex->x = x;
     vertex->y = y;
diff --git a/src/libGLESv2/renderer/renderer11_utils.h b/src/libGLESv2/renderer/renderer11_utils.h
index 107cc2e..cb35b74 100644
--- a/src/libGLESv2/renderer/renderer11_utils.h
+++ b/src/libGLESv2/renderer/renderer11_utils.h
@@ -61,7 +61,7 @@
     float r, g, b, a;
 };
 void SetPositionDepthColorVertex(PositionDepthColorVertex* vertex, float x, float y, float z,
-                                 const gl::Color &color);
+                                 const gl::ColorF &color);
 
 HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name);
 
diff --git a/src/libGLESv2/renderer/renderer9_utils.cpp b/src/libGLESv2/renderer/renderer9_utils.cpp
index b78f5f5..a0d4c8e 100644
--- a/src/libGLESv2/renderer/renderer9_utils.cpp
+++ b/src/libGLESv2/renderer/renderer9_utils.cpp
@@ -39,7 +39,7 @@
     return d3dComp;
 }
 
-D3DCOLOR ConvertColor(gl::Color color)
+D3DCOLOR ConvertColor(gl::ColorF color)
 {
     return D3DCOLOR_RGBA(gl::unorm<8>(color.red),
                          gl::unorm<8>(color.green),
diff --git a/src/libGLESv2/renderer/renderer9_utils.h b/src/libGLESv2/renderer/renderer9_utils.h
index 9bd6526..a115f9e 100644
--- a/src/libGLESv2/renderer/renderer9_utils.h
+++ b/src/libGLESv2/renderer/renderer9_utils.h
@@ -10,7 +10,7 @@
 #ifndef LIBGLESV2_RENDERER_RENDERER9_UTILS_H
 #define LIBGLESV2_RENDERER_RENDERER9_UTILS_H
 
-#include "common/utilities.h"
+#include "libGLESv2/angletypes.h"
 
 namespace rx
 {
@@ -19,7 +19,7 @@
 {
 
 D3DCMPFUNC ConvertComparison(GLenum comparison);
-D3DCOLOR ConvertColor(gl::Color color);
+D3DCOLOR ConvertColor(gl::ColorF color);
 D3DBLEND ConvertBlendFunc(GLenum blend);
 D3DBLENDOP ConvertBlendOp(GLenum blendOp);
 D3DSTENCILOP ConvertStencilOp(GLenum stencilOp);