blob: d5227ae6f12b6b05e2f973f150265b45f5c4f67c [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
bsalomon422f56f2014-12-09 10:18:12 -080043 * vary the internal precision based on the qualifiers. These currently only apply to float types (
44 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080045 */
46enum GrSLPrecision {
47 kLow_GrSLPrecision,
48 kMedium_GrSLPrecision,
49 kHigh_GrSLPrecision,
50
51 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
52 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
53 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
54
55 kLast_GrSLPrecision = kHigh_GrSLPrecision
56};
57
58static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
59
60/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000061 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
62 */
63static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000064 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
jvanverth@google.com054ae992013-04-01 20:06:51 +000065 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 };
66 return kCounts[type];
67
68 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
69 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
70 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
71 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
72 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
73 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
74 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
75 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000076 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +000077}
78
bsalomon@google.com018f1792013-04-18 19:36:09 +000079/** Return the type enum for a vector of floats of length n (1..4),
80 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +000081static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000082 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +000083 return (GrSLType)(count);
84
85 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
86 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
87 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
88 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
89}
90
bsalomon422f56f2014-12-09 10:18:12 -080091/** Is the shading language type floating point (or vector/matrix of fp)? */
92static inline bool GrSLTypeIsFloatType(GrSLType type) {
93 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
94 return type >= 1 && type <= 6;
95
96 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
97 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
98 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
99 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
100 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
101 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
102 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
103 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
104 GR_STATIC_ASSERT(8 == kGrSLTypeCount);
105}
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000106//////////////////////////////////////////////////////////////////////////////
107
jvanverth@google.com054ae992013-04-01 20:06:51 +0000108/**
109 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000110 */
111enum GrVertexAttribType {
112 kFloat_GrVertexAttribType = 0,
113 kVec2f_GrVertexAttribType,
114 kVec3f_GrVertexAttribType,
115 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800116
117 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000118 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
119
120 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType
121};
122static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
123
jvanverth@google.com054ae992013-04-01 20:06:51 +0000124/**
125 * Returns the vector size of the type.
126 */
127static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000128 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
egdaniel37b4d862014-11-03 10:07:07 -0800129 static const int kCounts[] = { 1, 2, 3, 4, 1, 4 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000130 return kCounts[type];
131
132 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
133 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
134 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
135 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800136 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
137 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000138 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000139}
140
141/**
142 * Returns the size of the attrib type in bytes.
143 */
144static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000145 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000146 static const size_t kSizes[] = {
147 sizeof(float), // kFloat_GrVertexAttribType
148 2*sizeof(float), // kVec2f_GrVertexAttribType
149 3*sizeof(float), // kVec3f_GrVertexAttribType
150 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800151 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000152 4*sizeof(char) // kVec4ub_GrVertexAttribType
153 };
154 return kSizes[type];
155
156 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
157 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
158 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
159 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800160 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
161 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000162 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000163}
164
165/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800166 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000167 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800168static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
169 switch (type) {
170 default:
171 SkFAIL("Unsupported type conversion");
172 case kUByte_GrVertexAttribType:
173 case kFloat_GrVertexAttribType:
174 return kFloat_GrSLType;
175 case kVec2f_GrVertexAttribType:
176 return kVec2f_GrSLType;
177 case kVec3f_GrVertexAttribType:
178 return kVec3f_GrSLType;
179 case kVec4ub_GrVertexAttribType:
180 case kVec4f_GrVertexAttribType:
181 return kVec4f_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000182 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800183}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000184
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000185//////////////////////////////////////////////////////////////////////////////
186
187/**
188* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000189* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700190* 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 +0000191* a NULL return.
192*/
joshualittb0a8a372014-09-23 09:50:21 -0700193enum GrPrimitiveEdgeType {
194 kFillBW_GrProcessorEdgeType,
195 kFillAA_GrProcessorEdgeType,
196 kInverseFillBW_GrProcessorEdgeType,
197 kInverseFillAA_GrProcessorEdgeType,
198 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000199
joshualittb0a8a372014-09-23 09:50:21 -0700200 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000201};
202
joshualittb0a8a372014-09-23 09:50:21 -0700203static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000204
joshualittb0a8a372014-09-23 09:50:21 -0700205static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
206 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000207}
208
joshualittb0a8a372014-09-23 09:50:21 -0700209static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
210 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
211 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000212}
213
joshualittb0a8a372014-09-23 09:50:21 -0700214static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
215 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000216}
217
joshualittb0a8a372014-09-23 09:50:21 -0700218static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000219 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700220 case kFillBW_GrProcessorEdgeType:
221 return kInverseFillBW_GrProcessorEdgeType;
222 case kFillAA_GrProcessorEdgeType:
223 return kInverseFillAA_GrProcessorEdgeType;
224 case kInverseFillBW_GrProcessorEdgeType:
225 return kFillBW_GrProcessorEdgeType;
226 case kInverseFillAA_GrProcessorEdgeType:
227 return kFillAA_GrProcessorEdgeType;
228 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000229 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000230 }
joshualittb0a8a372014-09-23 09:50:21 -0700231 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000232}
233
bsalomonbcf0a522014-10-08 08:40:09 -0700234/**
235 * Indicates the type of pending IO operations that can be recorded for gpu resources.
236 */
237enum GrIOType {
238 kRead_GrIOType,
239 kWrite_GrIOType,
240 kRW_GrIOType
241};
242
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000243#endif