Improve GLSL integer support
authorcdalton <cdalton@nvidia.com>
Sat, 6 Feb 2016 00:26:32 +0000 (16:26 -0800)
committerCommit bot <commit-bot@chromium.org>
Sat, 6 Feb 2016 00:26:32 +0000 (16:26 -0800)
 - Adds shader types for uint.
 - Adds a cap for integer support.
 - Uses glVertexAttribIPointer for integer attribs.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1669853002

Review URL: https://codereview.chromium.org/1669853002

17 files changed:
include/gpu/GrCaps.h
include/gpu/GrTypesPriv.h
include/gpu/gl/GrGLFunctions.h
include/gpu/gl/GrGLInterface.h
src/gpu/GrCaps.cpp
src/gpu/gl/GrGLAssembleInterface.cpp
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGLCreateNullInterface.cpp
src/gpu/gl/GrGLGpu.cpp
src/gpu/gl/GrGLInterface.cpp
src/gpu/gl/GrGLNoOpInterface.cpp
src/gpu/gl/GrGLNoOpInterface.h
src/gpu/gl/GrGLVertexArray.cpp
src/gpu/gl/GrGLVertexArray.h
src/gpu/gl/SkNullGLContext.cpp
src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
src/gpu/glsl/GrGLSL.h

index 944fb1481c1e9a4dd0391d5fad104666570eb34c..fc682069eac794bc88e9e57747f0c716890ad645 100644 (file)
@@ -62,6 +62,7 @@ public:
     bool pathRenderingSupport() const { return fPathRenderingSupport; }
     bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
     bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
+    bool integerSupport() const { return fIntegerSupport; }
 
     /**
     * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
@@ -109,6 +110,7 @@ protected:
     bool fPathRenderingSupport : 1;
     bool fDstReadInShaderSupport : 1;
     bool fDualSourceBlendingSupport : 1;
+    bool fIntegerSupport : 1;
 
     bool fShaderPrecisionVaries;
     PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
index bc107b5cf5aa6467b391f38c4fad1caf8a5ac526..4026eb7874dcbab4de91e3a732ea6865af07cb7c 100644 (file)
@@ -29,8 +29,9 @@ enum GrSLType {
     kSampler2DRect_GrSLType,
     kBool_GrSLType,
     kInt_GrSLType,
+    kUint_GrSLType,
 
-    kLast_GrSLType = kInt_GrSLType
+    kLast_GrSLType = kUint_GrSLType
 };
 static const int kGrSLTypeCount = kLast_GrSLType + 1;
 
@@ -67,7 +68,7 @@ static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
  */
 static inline int GrSLTypeVectorCount(GrSLType type) {
     SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
-    static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1 };
+    static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, 1, 1, 1 };
     return kCounts[type];
 
     GR_STATIC_ASSERT(0 == kVoid_GrSLType);
@@ -82,6 +83,7 @@ static inline int GrSLTypeVectorCount(GrSLType type) {
     GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
     GR_STATIC_ASSERT(10 == kBool_GrSLType);
     GR_STATIC_ASSERT(11 == kInt_GrSLType);
+    GR_STATIC_ASSERT(12 == kUint_GrSLType);
     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
 }
 
@@ -114,13 +116,14 @@ static inline bool GrSLTypeIsFloatType(GrSLType type) {
     GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
     GR_STATIC_ASSERT(10 == kBool_GrSLType);
     GR_STATIC_ASSERT(11 == kInt_GrSLType);
-    GR_STATIC_ASSERT(12 == kGrSLTypeCount);
+    GR_STATIC_ASSERT(12 == kUint_GrSLType);
+    GR_STATIC_ASSERT(13 == kGrSLTypeCount);
 }
 
 /** Is the shading language type integral (including vectors/matrices)? */
 static inline bool GrSLTypeIsIntType(GrSLType type) {
     SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
-    return type == kInt_GrSLType;
+    return type >= kInt_GrSLType;
 
     GR_STATIC_ASSERT(0 == kVoid_GrSLType);
     GR_STATIC_ASSERT(1 == kFloat_GrSLType);
@@ -134,7 +137,8 @@ static inline bool GrSLTypeIsIntType(GrSLType type) {
     GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
     GR_STATIC_ASSERT(10 == kBool_GrSLType);
     GR_STATIC_ASSERT(11 == kInt_GrSLType);
-    GR_STATIC_ASSERT(12 == kGrSLTypeCount);
+    GR_STATIC_ASSERT(12 == kUint_GrSLType);
+    GR_STATIC_ASSERT(13 == kGrSLTypeCount);
 }
 
 /** Is the shading language type numeric (including vectors/matrices)? */
@@ -158,6 +162,7 @@ static inline size_t GrSLTypeSize(GrSLType type) {
         0,                        // kSampler2DRect_GrSLType
         0,                        // kBool_GrSLType
         0,                        // kInt_GrSLType
+        0,                        // kUint_GrSLType
     };
     return kSizes[type];
 
@@ -173,7 +178,8 @@ static inline size_t GrSLTypeSize(GrSLType type) {
     GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
     GR_STATIC_ASSERT(10 == kBool_GrSLType);
     GR_STATIC_ASSERT(11 == kInt_GrSLType);
-    GR_STATIC_ASSERT(12 == kGrSLTypeCount);
+    GR_STATIC_ASSERT(12 == kUint_GrSLType);
+    GR_STATIC_ASSERT(13 == kGrSLTypeCount);
 }
 
 static inline bool GrSLTypeIsSamplerType(GrSLType type) {
@@ -202,8 +208,9 @@ enum GrVertexAttribType {
     kVec2s_GrVertexAttribType,   // vector of 2 shorts, e.g. texture coordinates
 
     kInt_GrVertexAttribType,
+    kUint_GrVertexAttribType,
     
-    kLast_GrVertexAttribType = kInt_GrVertexAttribType
+    kLast_GrVertexAttribType = kUint_GrVertexAttribType
 };
 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
 
@@ -211,7 +218,8 @@ static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
  * Returns the vector size of the type.
  */
 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
-    static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1 };
+    SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
+    static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
     return kCounts[type];
 
     GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
@@ -222,6 +230,7 @@ static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
     GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
     GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
     GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
+    GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
 }
 
@@ -237,7 +246,8 @@ static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
         1*sizeof(char),         // kUByte_GrVertexAttribType
         4*sizeof(char),         // kVec4ub_GrVertexAttribType
         2*sizeof(int16_t),      // kVec2s_GrVertexAttribType
-        sizeof(int32_t)         // kInt_GrVertexAttribType
+        sizeof(int32_t),        // kInt_GrVertexAttribType
+        sizeof(uint32_t)        // kUint_GrVertexAttribType
     };
     return kSizes[type];
 
@@ -249,9 +259,29 @@ static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
     GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
     GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
     GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
+    GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
 }
 
+/**
+ * Is the attrib type integral?
+ */
+static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
+    SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
+    return type >= kInt_GrVertexAttribType;
+
+    GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
+    GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
+    GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
+    GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
+    GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
+    GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
+    GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
+    GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
+    GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
+    GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
+}
+
 /**
  * converts a GrVertexAttribType to a GrSLType
  */
@@ -273,6 +303,8 @@ static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
             return kVec4f_GrSLType;
         case kInt_GrVertexAttribType:
             return kInt_GrSLType;
+        case kUint_GrVertexAttribType:
+            return kUint_GrSLType;
     }
 }
 
index ad59ec0c00b702200e87f7d0934ade1b840cf6ae..3fd912f222e236bf97fbde3b00a78aaf9b827b5c 100644 (file)
@@ -176,6 +176,7 @@ typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttrib2fvProc)(GrGLuint indx, c
 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttrib3fvProc)(GrGLuint indx, const GrGLfloat* values);
 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttribDivisorProc)(GrGLuint index, GrGLuint divisor);
+typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttribIPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* ptr);
 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
 
index dd9a9fb386619d1079b4238b97b0e221ed39f90a..5dd3b61e56e506f7cd2fd7b39cf41cf2e2b74174 100644 (file)
@@ -332,6 +332,7 @@ public:
         GLPtr<GrGLVertexAttrib3fvProc> fVertexAttrib3fv;
         GLPtr<GrGLVertexAttrib4fvProc> fVertexAttrib4fv;
         GLPtr<GrGLVertexAttribDivisorProc> fVertexAttribDivisor;
+        GLPtr<GrGLVertexAttribIPointerProc> fVertexAttribIPointer;
         GLPtr<GrGLVertexAttribPointerProc> fVertexAttribPointer;
         GLPtr<GrGLViewportProc> fViewport;
 
index 46f49357c77d4d6fd09a25a63ff4a03ac606f99f..2568e567fc5926b71d58d487d878f46e56a74980 100644 (file)
@@ -15,6 +15,7 @@ GrShaderCaps::GrShaderCaps() {
     fPathRenderingSupport = false;
     fDstReadInShaderSupport = false;
     fDualSourceBlendingSupport = false;
+    fIntegerSupport = false;
     fShaderPrecisionVaries = false;
 }
 
@@ -50,6 +51,7 @@ SkString GrShaderCaps::dump() const {
     r.appendf("Path Rendering Support             : %s\n", gNY[fPathRenderingSupport]);
     r.appendf("Dst Read In Shader Support         : %s\n", gNY[fDstReadInShaderSupport]);
     r.appendf("Dual Source Blending Support       : %s\n", gNY[fDualSourceBlendingSupport]);
+    r.appendf("Integer Support                    : %s\n", gNY[fIntegerSupport]);
 
     r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
 
index 30eed62c5e49f05387a21117e492d647919a1145..e52d302190d099e8e6c03e0fec17ff153ad898ee 100644 (file)
@@ -246,6 +246,10 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) {
         GET_PROC(VertexAttribDivisor);
     }
 
+    if (glVer >= GR_GL_VER(3,0)) {
+        GET_PROC(VertexAttribIPointer);
+    }
+
     GET_PROC(VertexAttribPointer);
     GET_PROC(Viewport);
     GET_PROC(BindFragDataLocationIndexed);
@@ -678,6 +682,10 @@ const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
         GET_PROC_SUFFIX(VertexAttribDivisor, EXT);
     }
 
+    if (version >= GR_GL_VER(3,0)) {
+        GET_PROC(VertexAttribIPointer);
+    }
+
     GET_PROC(VertexAttribPointer);
     GET_PROC(Viewport);
     GET_PROC(BindFramebuffer);
index a913fbeca2fff8b052e15b33fa45a853cf61b315..cb3f5dd55f7329503a97703a9cd25f9f9f9cf759 100644 (file)
@@ -279,12 +279,17 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
         // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
         glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
             ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
+        glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
+            ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
     }
     else {
         glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
 
         glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
             ctxInfo.hasExtension("GL_OES_standard_derivatives");
+
+        glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
+            ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
     }
 
     if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
index f0a3e7d4bdd13ae9884f45879eee6c45c6df17ff..f56b1d97733b9b11b06b98929723332848150509 100644 (file)
@@ -465,8 +465,9 @@ const GrGLInterface* GrGLCreateNullInterface() {
     functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv;
     functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv;
     functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
-    functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
     functions->fVertexAttribDivisor = noOpGLVertexAttribDivisor;
+    functions->fVertexAttribIPointer = noOpGLVertexAttribIPointer;
+    functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
     functions->fViewport = nullGLViewport;
     functions->fBindFramebuffer = nullGLBindFramebuffer;
     functions->fBindRenderbuffer = nullGLBindRenderbuffer;
index ad85707b3bf47636fd8f09bb4b5452e9887f767e..e29a7f81f317aa189e7263dc23416263cb264e8e 100644 (file)
@@ -1807,9 +1807,7 @@ void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
             attribState->set(this,
                              attribIndex,
                              vbuf->bufferID(),
-                             GrGLAttribTypeToLayout(attribType).fCount,
-                             GrGLAttribTypeToLayout(attribType).fType,
-                             GrGLAttribTypeToLayout(attribType).fNormalized,
+                             attribType,
                              stride,
                              reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + offset));
             offset += attrib.fOffset;
@@ -2588,7 +2586,7 @@ void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL
 
     GrGLAttribArrayState* attribs =
             this->fHWGeometryState.bindArrayAndBufferToDraw(this, arrayBuffer);
-    attribs->set(this, 0, arrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeof(GrGLfloat), 0);
+    attribs->set(this, 0, arrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat), 0);
     attribs->disableUnusedArrays(this, 0x1);
 
     GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.left(), 
@@ -3529,7 +3527,8 @@ void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor
 
     GrGLAttribArrayState* attribs =
         fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer);
-    attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeof(GrGLfloat), 0);
+    attribs->set(this, 0, fWireRectArrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat),
+                 0);
     attribs->disableUnusedArrays(this, 0x1);
 
     GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges));
@@ -3574,7 +3573,8 @@ void GrGLGpu::copySurfaceAsDraw(GrSurface* dst,
 
     GrGLAttribArrayState* attribs =
         fHWGeometryState.bindArrayAndBufferToDraw(this, fCopyProgramArrayBuffer);
-    attribs->set(this, 0, fCopyProgramArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeof(GrGLfloat), 0);
+    attribs->set(this, 0, fCopyProgramArrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat),
+                 0);
     attribs->disableUnusedArrays(this, 0x1);
 
     // dst rect edges in NDC (-1 to 1)
index 925f081b342bb733001829bc9edb51719292de5b..c09efae2b88bd87007efdcfdda0209fd368d44f2 100644 (file)
@@ -416,6 +416,13 @@ bool GrGLInterface::validate() const {
         }
     }
 
+    // glVertexAttribIPointer was added in version 3.0 of both desktop and ES.
+    if (glVer >= GR_GL_VER(3, 0)) {
+        if (NULL == fFunctions.fVertexAttribIPointer) {
+            RETURN_FALSE_INTERFACE
+        }
+    }
+
     if (kGL_GrGLStandard == fStandard) {
         if (glVer >= GR_GL_VER(3, 0) || fExtensions.has("GL_ARB_vertex_array_object")) {
             if (nullptr == fFunctions.fBindVertexArray ||
index 113c47d05428dfc4684936b0e6f65605d0c7a821..f08d737d588183bdb661f6aa7f5f5bf3d60c6c9f 100644 (file)
@@ -394,6 +394,13 @@ GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniformMatrix4fv(GrGLint location,
  GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttrib4fv(GrGLuint indx, const GrGLfloat* values) {
 }
 
+GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttribIPointer(GrGLuint indx,
+                                                        GrGLint size,
+                                                        GrGLenum type,
+                                                        GrGLsizei stride,
+                                                        const GrGLvoid* ptr) {
+}
+
 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttribPointer(GrGLuint indx,
                                                        GrGLint size,
                                                        GrGLenum type,
index 627de63d7d330131eb78d62b24d221563892643a..44894b763a62f5e008fd11430501d26c7db0adc2 100644 (file)
@@ -287,6 +287,12 @@ GrGLvoid GR_GL_FUNCTION_TYPE noOpGLUniformMatrix4fv(GrGLint location,
 
  GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttrib4fv(GrGLuint indx, const GrGLfloat* values);
 
+GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttribIPointer(GrGLuint indx,
+                                                        GrGLint size,
+                                                        GrGLenum type,
+                                                        GrGLsizei stride,
+                                                        const GrGLvoid* ptr);
+
 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLVertexAttribPointer(GrGLuint indx,
                                                        GrGLint size,
                                                        GrGLenum type,
index 8cfa8d655050fa5b69e453970c035e6af7d534fe..fdb395d37a33c47a75b7687b939fd988c39e6a34 100644 (file)
@@ -8,14 +8,38 @@
 #include "GrGLVertexArray.h"
 #include "GrGLGpu.h"
 
+struct AttribLayout {
+    GrGLint     fCount;
+    GrGLenum    fType;
+    GrGLboolean fNormalized;  // Only used by floating point types.
+};
 
+static const AttribLayout gLayouts[kGrVertexAttribTypeCount] = {
+    {1, GR_GL_FLOAT, false},         // kFloat_GrVertexAttribType
+    {2, GR_GL_FLOAT, false},         // kVec2f_GrVertexAttribType
+    {3, GR_GL_FLOAT, false},         // kVec3f_GrVertexAttribType
+    {4, GR_GL_FLOAT, false},         // kVec4f_GrVertexAttribType
+    {1, GR_GL_UNSIGNED_BYTE, true},  // kUByte_GrVertexAttribType
+    {4, GR_GL_UNSIGNED_BYTE, true},  // kVec4ub_GrVertexAttribType
+    {2, GR_GL_SHORT, false},         // kVec2s_GrVertexAttribType
+    {1, GR_GL_INT, false},           // kInt_GrVertexAttribType
+    {1, GR_GL_UNSIGNED_INT, false},  // kUint_GrVertexAttribType
+};
+
+GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
+GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
+GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
+GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
+GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
+GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
+GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
+GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
+GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
 
 void GrGLAttribArrayState::set(GrGLGpu* gpu,
                                int index,
                                GrGLuint vertexBufferID,
-                               GrGLint size,
-                               GrGLenum type,
-                               GrGLboolean normalized,
+                               GrVertexAttribType type,
                                GrGLsizei stride,
                                GrGLvoid* offset) {
     SkASSERT(index >= 0 && index < fAttribArrayStates.count());
@@ -27,23 +51,31 @@ void GrGLAttribArrayState::set(GrGLGpu* gpu,
     }
     if (!array->fAttribPointerIsValid ||
         array->fVertexBufferID != vertexBufferID ||
-        array->fSize != size ||
-        array->fNormalized != normalized ||
+        array->fType != type ||
         array->fStride != stride ||
         array->fOffset != offset) {
 
         gpu->bindVertexBuffer(vertexBufferID);
-        GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index,
-                                                           size,
-                                                           type,
-                                                           normalized,
-                                                           stride,
-                                                           offset));
+        const AttribLayout& layout = gLayouts[type];
+        if (!GrVertexAttribTypeIsIntType(type)) {
+            GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index,
+                                                               layout.fCount,
+                                                               layout.fType,
+                                                               layout.fNormalized,
+                                                               stride,
+                                                               offset));
+        } else {
+            SkASSERT(gpu->caps()->shaderCaps()->integerSupport());
+            SkASSERT(!layout.fNormalized);
+            GR_GL_CALL(gpu->glInterface(), VertexAttribIPointer(index,
+                                                                layout.fCount,
+                                                                layout.fType,
+                                                                stride,
+                                                                offset));
+        }
         array->fAttribPointerIsValid = true;
         array->fVertexBufferID = vertexBufferID;
-        array->fSize = size;
-        array->fNormalized = normalized;
-        array->fStride = stride;
+        array->fType = type;
         array->fOffset = offset;
     }
 }
index 0a5dea6a1ebf22830b3d4e7bcf0fab090ad08947..f5a97672f3b05b5c6053a819740b3744616467ac 100644 (file)
@@ -17,35 +17,6 @@ class GrGLVertexBuffer;
 class GrGLIndexBuffer;
 class GrGLGpu;
 
-struct GrGLAttribLayout {
-    GrGLint     fCount;
-    GrGLenum    fType;
-    GrGLboolean fNormalized;
-};
-
-static inline const GrGLAttribLayout& GrGLAttribTypeToLayout(GrVertexAttribType type) {
-    static const GrGLAttribLayout kLayouts[kGrVertexAttribTypeCount] = {
-        {1, GR_GL_FLOAT, false},         // kFloat_GrVertexAttribType
-        {2, GR_GL_FLOAT, false},         // kVec2f_GrVertexAttribType
-        {3, GR_GL_FLOAT, false},         // kVec3f_GrVertexAttribType
-        {4, GR_GL_FLOAT, false},         // kVec4f_GrVertexAttribType
-        {1, GR_GL_UNSIGNED_BYTE, true},  // kUByte_GrVertexAttribType
-        {4, GR_GL_UNSIGNED_BYTE, true},  // kVec4ub_GrVertexAttribType
-        {2, GR_GL_SHORT, false},         // kVec2s_GrVertexAttribType
-        {4, GR_GL_INT, false},           // kInt_GrVertexAttribType
-    };
-    GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
-    GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
-    GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
-    GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
-    GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
-    GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
-    GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
-    GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
-    GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayouts) == kGrVertexAttribTypeCount);
-    return kLayouts[type];
-}
-
 /**
  * This sets and tracks the vertex attribute array state. It is used internally by GrGLVertexArray
  * (below) but is separate because it is also used to track the state of vertex array object 0.
@@ -71,9 +42,7 @@ public:
     void set(GrGLGpu*,
              int attribIndex,
              GrGLuint vertexBufferID,
-             GrGLint size,
-             GrGLenum type,
-             GrGLboolean normalized,
+             GrVertexAttribType type,
              GrGLsizei stride,
              GrGLvoid* offset);
 
@@ -115,15 +84,13 @@ private:
                 fAttribPointerIsValid = false;
             }
 
-            bool        fEnableIsValid;
-            bool        fAttribPointerIsValid;
-            bool        fEnabled;
-            GrGLuint    fVertexBufferID;
-            GrGLint     fSize;
-            GrGLenum    fType;
-            GrGLboolean fNormalized;
-            GrGLsizei   fStride;
-            GrGLvoid*   fOffset;
+            bool                  fEnableIsValid;
+            bool                  fAttribPointerIsValid;
+            bool                  fEnabled;
+            GrGLuint              fVertexBufferID;
+            GrVertexAttribType    fType;
+            GrGLsizei             fStride;
+            GrGLvoid*             fOffset;
     };
 
     SkSTArray<16, AttribArrayState, true> fAttribArrayStates;
index dafa1ef0bc2c61bce33de698df356690ce66350c..68b19ce9905dd8dbbaca15a27c21b4697bc9afa6 100644 (file)
@@ -514,8 +514,9 @@ static GrGLInterface* create_null_interface(State* state) {
     functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv;
     functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv;
     functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
-    functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
     functions->fVertexAttribDivisor = noOpGLVertexAttribDivisor;
+    functions->fVertexAttribIPointer = noOpGLVertexAttribIPointer;
+    functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
     functions->fViewport = nullGLViewport;
     functions->fBindFramebuffer = nullGLBindFramebuffer;
     functions->fBindRenderbuffer = nullGLBindRenderbuffer;
index bcc3007650906656c1af1c0458fc2498c238813a..2118c02fa7fbf5b564d941bfb8ebf26535b60dc6 100644 (file)
@@ -956,8 +956,9 @@ const GrGLInterface* GrGLCreateDebugInterface() {
     functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv;
     functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv;
     functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
-    functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
     functions->fVertexAttribDivisor = noOpGLVertexAttribDivisor;
+    functions->fVertexAttribIPointer = noOpGLVertexAttribIPointer;
+    functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
     functions->fViewport = noOpGLViewport;
     functions->fBindFramebuffer = debugGLBindFramebuffer;
     functions->fBindRenderbuffer = debugGLBindRenderbuffer;
index dc53d7befaa65e551d77058c7854f5ba0691fd72..6fc8f83c7a3ca1be80fada8a9ef72a12d923ca02 100644 (file)
@@ -104,6 +104,8 @@ static inline const char* GrGLSLTypeString(GrSLType t) {
             return "bool";
         case kInt_GrSLType:
             return "int";
+        case kUint_GrSLType:
+            return "uint";
         default:
             SkFAIL("Unknown shader var type.");
             return ""; // suppress warning