blob: 2a8d4c3255ae0642653c302773e5d0b49d9b9247 [file] [log] [blame]
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrTypesPriv_DEFINED
9#define GrTypesPriv_DEFINED
10
jvanverth@google.com054ae992013-04-01 20:06:51 +000011#include "GrTypes.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000012#include "SkTArray.h"
13
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000014/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000015 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
16 * but should be applicable to other shader languages.)
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000017 */
18enum GrSLType {
19 kVoid_GrSLType,
20 kFloat_GrSLType,
21 kVec2f_GrSLType,
22 kVec3f_GrSLType,
23 kVec4f_GrSLType,
24 kMat33f_GrSLType,
25 kMat44f_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000026 kSampler2D_GrSLType,
27
28 kLast_GrSLType = kSampler2D_GrSLType
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000029};
jvanverth@google.com054ae992013-04-01 20:06:51 +000030static const int kGrSLTypeCount = kLast_GrSLType + 1;
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000031
bsalomon17168df2014-12-09 09:00:49 -080032enum GrShaderType {
33 kVertex_GrShaderType,
34 kGeometry_GrShaderType,
35 kFragment_GrShaderType,
36
37 kLastkFragment_GrShaderType = kFragment_GrShaderType
38};
39static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
40
bsalomon@google.com31ec7982013-03-27 18:14:57 +000041/**
bsalomonc0bd6482014-12-09 10:04:14 -080042 * Precisions of shader language variables. Not all shading languages support precisions or actually
43 * vary the internal precision based on the qualifiers.
44 */
45enum GrSLPrecision {
46 kLow_GrSLPrecision,
47 kMedium_GrSLPrecision,
48 kHigh_GrSLPrecision,
49
50 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
51 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
52 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
53
54 kLast_GrSLPrecision = kHigh_GrSLPrecision
55};
56
57static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
58
59/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000060 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
61 */
62static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000063 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
jvanverth@google.com054ae992013-04-01 20:06:51 +000064 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 };
65 return kCounts[type];
66
67 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
68 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
69 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
70 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
71 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
72 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
73 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
74 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000075 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +000076}
77
bsalomon@google.com018f1792013-04-18 19:36:09 +000078/** Return the type enum for a vector of floats of length n (1..4),
79 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +000080static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000081 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +000082 return (GrSLType)(count);
83
84 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
85 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
86 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
87 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
88}
89
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +000090//////////////////////////////////////////////////////////////////////////////
91
jvanverth@google.com054ae992013-04-01 20:06:51 +000092/**
93 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +000094 */
95enum GrVertexAttribType {
96 kFloat_GrVertexAttribType = 0,
97 kVec2f_GrVertexAttribType,
98 kVec3f_GrVertexAttribType,
99 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800100
101 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000102 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
103
104 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType
105};
106static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
107
jvanverth@google.com054ae992013-04-01 20:06:51 +0000108/**
109 * Returns the vector size of the type.
110 */
111static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000112 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
egdaniel37b4d862014-11-03 10:07:07 -0800113 static const int kCounts[] = { 1, 2, 3, 4, 1, 4 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000114 return kCounts[type];
115
116 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
117 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
118 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
119 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800120 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
121 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000122 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000123}
124
125/**
126 * Returns the size of the attrib type in bytes.
127 */
128static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000129 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000130 static const size_t kSizes[] = {
131 sizeof(float), // kFloat_GrVertexAttribType
132 2*sizeof(float), // kVec2f_GrVertexAttribType
133 3*sizeof(float), // kVec3f_GrVertexAttribType
134 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800135 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000136 4*sizeof(char) // kVec4ub_GrVertexAttribType
137 };
138 return kSizes[type];
139
140 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
141 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
142 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
143 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800144 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
145 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000146 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000147}
148
149/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800150 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000151 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800152static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
153 switch (type) {
154 default:
155 SkFAIL("Unsupported type conversion");
156 case kUByte_GrVertexAttribType:
157 case kFloat_GrVertexAttribType:
158 return kFloat_GrSLType;
159 case kVec2f_GrVertexAttribType:
160 return kVec2f_GrSLType;
161 case kVec3f_GrVertexAttribType:
162 return kVec3f_GrSLType;
163 case kVec4ub_GrVertexAttribType:
164 case kVec4f_GrVertexAttribType:
165 return kVec4f_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000166 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800167}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000168
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000169//////////////////////////////////////////////////////////////////////////////
170
171/**
172* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000173* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700174* GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000175* a NULL return.
176*/
joshualittb0a8a372014-09-23 09:50:21 -0700177enum GrPrimitiveEdgeType {
178 kFillBW_GrProcessorEdgeType,
179 kFillAA_GrProcessorEdgeType,
180 kInverseFillBW_GrProcessorEdgeType,
181 kInverseFillAA_GrProcessorEdgeType,
182 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000183
joshualittb0a8a372014-09-23 09:50:21 -0700184 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000185};
186
joshualittb0a8a372014-09-23 09:50:21 -0700187static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000188
joshualittb0a8a372014-09-23 09:50:21 -0700189static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
190 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000191}
192
joshualittb0a8a372014-09-23 09:50:21 -0700193static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
194 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
195 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000196}
197
joshualittb0a8a372014-09-23 09:50:21 -0700198static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
199 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000200}
201
joshualittb0a8a372014-09-23 09:50:21 -0700202static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000203 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700204 case kFillBW_GrProcessorEdgeType:
205 return kInverseFillBW_GrProcessorEdgeType;
206 case kFillAA_GrProcessorEdgeType:
207 return kInverseFillAA_GrProcessorEdgeType;
208 case kInverseFillBW_GrProcessorEdgeType:
209 return kFillBW_GrProcessorEdgeType;
210 case kInverseFillAA_GrProcessorEdgeType:
211 return kFillAA_GrProcessorEdgeType;
212 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000213 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000214 }
joshualittb0a8a372014-09-23 09:50:21 -0700215 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000216}
217
bsalomonbcf0a522014-10-08 08:40:09 -0700218/**
219 * Indicates the type of pending IO operations that can be recorded for gpu resources.
220 */
221enum GrIOType {
222 kRead_GrIOType,
223 kWrite_GrIOType,
224 kRW_GrIOType
225};
226
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000227#endif