Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_PROGRAM_H |
| 18 | #define ANDROID_HWUI_PROGRAM_H |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 19 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 20 | #include <utils/KeyedVector.h> |
| 21 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 22 | #include <GLES2/gl2.h> |
| 23 | #include <GLES2/gl2ext.h> |
| 24 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 25 | #include <SkXfermode.h> |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 26 | |
Romain Guy | 0b9db91 | 2010-07-09 18:53:25 -0700 | [diff] [blame] | 27 | #include "Matrix.h" |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 28 | #include "Properties.h" |
Romain Guy | 0b9db91 | 2010-07-09 18:53:25 -0700 | [diff] [blame] | 29 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | // Defines |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | |
| 37 | // Debug |
| 38 | #if DEBUG_PROGRAMS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 39 | #define PROGRAM_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 40 | #else |
| 41 | #define PROGRAM_LOGD(...) |
| 42 | #endif |
| 43 | |
Romain Guy | f877308 | 2012-07-12 18:01:00 -0700 | [diff] [blame] | 44 | #define COLOR_COMPONENT_THRESHOLD 1.0f |
| 45 | #define COLOR_COMPONENT_INV_THRESHOLD 0.0f |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 46 | |
| 47 | #define PROGRAM_KEY_TEXTURE 0x1 |
| 48 | #define PROGRAM_KEY_A8_TEXTURE 0x2 |
| 49 | #define PROGRAM_KEY_BITMAP 0x4 |
| 50 | #define PROGRAM_KEY_GRADIENT 0x8 |
| 51 | #define PROGRAM_KEY_BITMAP_FIRST 0x10 |
| 52 | #define PROGRAM_KEY_COLOR_MATRIX 0x20 |
| 53 | #define PROGRAM_KEY_COLOR_LIGHTING 0x40 |
| 54 | #define PROGRAM_KEY_COLOR_BLEND 0x80 |
| 55 | #define PROGRAM_KEY_BITMAP_NPOT 0x100 |
| 56 | #define PROGRAM_KEY_SWAP_SRC_DST 0x2000 |
| 57 | |
| 58 | #define PROGRAM_KEY_BITMAP_WRAPS_MASK 0x600 |
| 59 | #define PROGRAM_KEY_BITMAP_WRAPT_MASK 0x1800 |
| 60 | |
| 61 | // Encode the xfermodes on 6 bits |
| 62 | #define PROGRAM_MAX_XFERMODE 0x1f |
| 63 | #define PROGRAM_XFERMODE_SHADER_SHIFT 26 |
| 64 | #define PROGRAM_XFERMODE_COLOR_OP_SHIFT 20 |
| 65 | #define PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT 14 |
| 66 | |
| 67 | #define PROGRAM_BITMAP_WRAPS_SHIFT 9 |
| 68 | #define PROGRAM_BITMAP_WRAPT_SHIFT 11 |
| 69 | |
| 70 | #define PROGRAM_GRADIENT_TYPE_SHIFT 33 |
| 71 | #define PROGRAM_MODULATE_SHIFT 35 |
| 72 | |
| 73 | #define PROGRAM_IS_POINT_SHIFT 36 |
| 74 | |
| 75 | #define PROGRAM_HAS_AA_SHIFT 37 |
| 76 | |
| 77 | #define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38 |
| 78 | #define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39 |
| 79 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 80 | #define PROGRAM_HAS_GAMMA_CORRECTION 40 |
| 81 | |
Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 82 | #define PROGRAM_IS_SIMPLE_GRADIENT 41 |
| 83 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 84 | #define PROGRAM_HAS_COLORS 42 |
| 85 | |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 86 | #define PROGRAM_HAS_DEBUG_HIGHLIGHT 43 |
| 87 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 88 | /////////////////////////////////////////////////////////////////////////////// |
| 89 | // Types |
| 90 | /////////////////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | typedef uint64_t programid; |
| 93 | |
| 94 | /////////////////////////////////////////////////////////////////////////////// |
| 95 | // Program description |
| 96 | /////////////////////////////////////////////////////////////////////////////// |
| 97 | |
| 98 | /** |
| 99 | * Describe the features required for a given program. The features |
| 100 | * determine the generation of both the vertex and fragment shaders. |
| 101 | * A ProgramDescription must be used in conjunction with a ProgramCache. |
| 102 | */ |
| 103 | struct ProgramDescription { |
| 104 | enum ColorModifier { |
Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 105 | kColorNone = 0, |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 106 | kColorMatrix, |
| 107 | kColorLighting, |
| 108 | kColorBlend |
| 109 | }; |
| 110 | |
| 111 | enum Gradient { |
Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 112 | kGradientLinear = 0, |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 113 | kGradientCircular, |
| 114 | kGradientSweep |
| 115 | }; |
| 116 | |
| 117 | ProgramDescription() { |
| 118 | reset(); |
| 119 | } |
| 120 | |
| 121 | // Texturing |
| 122 | bool hasTexture; |
| 123 | bool hasAlpha8Texture; |
| 124 | bool hasExternalTexture; |
| 125 | bool hasTextureTransform; |
| 126 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 127 | // Color attribute |
| 128 | bool hasColors; |
| 129 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 130 | // Modulate, this should only be set when setColor() return true |
| 131 | bool modulate; |
| 132 | |
| 133 | // Shaders |
| 134 | bool hasBitmap; |
| 135 | bool isBitmapNpot; |
| 136 | |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 137 | bool isAA; // drawing with a per-vertex alpha |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 138 | |
| 139 | bool hasGradient; |
| 140 | Gradient gradientType; |
Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 141 | bool isSimpleGradient; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 142 | |
| 143 | SkXfermode::Mode shadersMode; |
| 144 | |
| 145 | bool isBitmapFirst; |
| 146 | GLenum bitmapWrapS; |
| 147 | GLenum bitmapWrapT; |
| 148 | |
| 149 | // Color operations |
| 150 | ColorModifier colorOp; |
| 151 | SkXfermode::Mode colorMode; |
| 152 | |
| 153 | // Framebuffer blending (requires Extensions.hasFramebufferFetch()) |
| 154 | // Ignored for all values < SkXfermode::kPlus_Mode |
| 155 | SkXfermode::Mode framebufferMode; |
| 156 | bool swapSrcDst; |
| 157 | |
| 158 | bool isPoint; |
| 159 | float pointSize; |
| 160 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 161 | bool hasGammaCorrection; |
| 162 | float gamma; |
| 163 | |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 164 | bool hasDebugHighlight; |
| 165 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 166 | /** |
| 167 | * Resets this description. All fields are reset back to the default |
| 168 | * values they hold after building a new instance. |
| 169 | */ |
| 170 | void reset() { |
| 171 | hasTexture = false; |
| 172 | hasAlpha8Texture = false; |
| 173 | hasExternalTexture = false; |
| 174 | hasTextureTransform = false; |
| 175 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 176 | hasColors = false; |
| 177 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 178 | isAA = false; |
| 179 | |
| 180 | modulate = false; |
| 181 | |
| 182 | hasBitmap = false; |
| 183 | isBitmapNpot = false; |
| 184 | |
| 185 | hasGradient = false; |
| 186 | gradientType = kGradientLinear; |
Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 187 | isSimpleGradient = false; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 188 | |
| 189 | shadersMode = SkXfermode::kClear_Mode; |
| 190 | |
| 191 | isBitmapFirst = false; |
| 192 | bitmapWrapS = GL_CLAMP_TO_EDGE; |
| 193 | bitmapWrapT = GL_CLAMP_TO_EDGE; |
| 194 | |
| 195 | colorOp = kColorNone; |
| 196 | colorMode = SkXfermode::kClear_Mode; |
| 197 | |
| 198 | framebufferMode = SkXfermode::kClear_Mode; |
| 199 | swapSrcDst = false; |
| 200 | |
| 201 | isPoint = false; |
| 202 | pointSize = 0.0f; |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 203 | |
| 204 | hasGammaCorrection = false; |
| 205 | gamma = 2.2f; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 206 | |
| 207 | hasDebugHighlight = false; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Indicates, for a given color, whether color modulation is required in |
| 212 | * the fragment shader. When this method returns true, the program should |
| 213 | * be provided with a modulation color. |
| 214 | */ |
| 215 | bool setColor(const float r, const float g, const float b, const float a) { |
Romain Guy | a938f56 | 2012-09-13 20:31:08 -0700 | [diff] [blame] | 216 | modulate = a < COLOR_COMPONENT_THRESHOLD; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 217 | return modulate; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Indicates, for a given color, whether color modulation is required in |
| 222 | * the fragment shader. When this method returns true, the program should |
| 223 | * be provided with a modulation color. |
| 224 | */ |
| 225 | bool setAlpha8Color(const float r, const float g, const float b, const float a) { |
| 226 | modulate = a < COLOR_COMPONENT_THRESHOLD || r > COLOR_COMPONENT_INV_THRESHOLD || |
| 227 | g > COLOR_COMPONENT_INV_THRESHOLD || b > COLOR_COMPONENT_INV_THRESHOLD; |
| 228 | return modulate; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Computes the unique key identifying this program. |
| 233 | */ |
| 234 | programid key() const { |
| 235 | programid key = 0; |
| 236 | if (hasTexture) key |= PROGRAM_KEY_TEXTURE; |
| 237 | if (hasAlpha8Texture) key |= PROGRAM_KEY_A8_TEXTURE; |
| 238 | if (hasBitmap) { |
| 239 | key |= PROGRAM_KEY_BITMAP; |
| 240 | if (isBitmapNpot) { |
| 241 | key |= PROGRAM_KEY_BITMAP_NPOT; |
| 242 | key |= getEnumForWrap(bitmapWrapS) << PROGRAM_BITMAP_WRAPS_SHIFT; |
| 243 | key |= getEnumForWrap(bitmapWrapT) << PROGRAM_BITMAP_WRAPT_SHIFT; |
| 244 | } |
| 245 | } |
| 246 | if (hasGradient) key |= PROGRAM_KEY_GRADIENT; |
| 247 | key |= programid(gradientType) << PROGRAM_GRADIENT_TYPE_SHIFT; |
| 248 | if (isBitmapFirst) key |= PROGRAM_KEY_BITMAP_FIRST; |
| 249 | if (hasBitmap && hasGradient) { |
| 250 | key |= (shadersMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_SHADER_SHIFT; |
| 251 | } |
| 252 | switch (colorOp) { |
| 253 | case kColorMatrix: |
| 254 | key |= PROGRAM_KEY_COLOR_MATRIX; |
| 255 | break; |
| 256 | case kColorLighting: |
| 257 | key |= PROGRAM_KEY_COLOR_LIGHTING; |
| 258 | break; |
| 259 | case kColorBlend: |
| 260 | key |= PROGRAM_KEY_COLOR_BLEND; |
| 261 | key |= (colorMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_COLOR_OP_SHIFT; |
| 262 | break; |
| 263 | case kColorNone: |
| 264 | break; |
| 265 | } |
| 266 | key |= (framebufferMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT; |
| 267 | if (swapSrcDst) key |= PROGRAM_KEY_SWAP_SRC_DST; |
| 268 | if (modulate) key |= programid(0x1) << PROGRAM_MODULATE_SHIFT; |
| 269 | if (isPoint) key |= programid(0x1) << PROGRAM_IS_POINT_SHIFT; |
| 270 | if (isAA) key |= programid(0x1) << PROGRAM_HAS_AA_SHIFT; |
| 271 | if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT; |
| 272 | if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT; |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 273 | if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION; |
Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 274 | if (isSimpleGradient) key |= programid(0x1) << PROGRAM_IS_SIMPLE_GRADIENT; |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 275 | if (hasColors) key |= programid(0x1) << PROGRAM_HAS_COLORS; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 276 | if (hasDebugHighlight) key |= programid(0x1) << PROGRAM_HAS_DEBUG_HIGHLIGHT; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 277 | return key; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Logs the specified message followed by the key identifying this program. |
| 282 | */ |
| 283 | void log(const char* message) const { |
| 284 | #if DEBUG_PROGRAMS |
| 285 | programid k = key(); |
| 286 | PROGRAM_LOGD("%s (key = 0x%.8x%.8x)", message, uint32_t(k >> 32), |
| 287 | uint32_t(k & 0xffffffff)); |
| 288 | #endif |
| 289 | } |
| 290 | |
| 291 | private: |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 292 | static inline uint32_t getEnumForWrap(GLenum wrap) { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 293 | switch (wrap) { |
| 294 | case GL_CLAMP_TO_EDGE: |
| 295 | return 0; |
| 296 | case GL_REPEAT: |
| 297 | return 1; |
| 298 | case GL_MIRRORED_REPEAT: |
| 299 | return 2; |
| 300 | } |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | }; // struct ProgramDescription |
| 305 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 306 | /** |
| 307 | * A program holds a vertex and a fragment shader. It offers several utility |
| 308 | * methods to query attributes and uniforms. |
| 309 | */ |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 310 | class Program { |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 311 | public: |
Romain Guy | 3e263fa | 2011-12-12 16:47:48 -0800 | [diff] [blame] | 312 | enum ShaderBindings { |
| 313 | kBindingPosition, |
| 314 | kBindingTexCoords |
| 315 | }; |
| 316 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 317 | /** |
| 318 | * Creates a new program with the specified vertex and fragment |
| 319 | * shaders sources. |
| 320 | */ |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 321 | Program(const ProgramDescription& description, const char* vertex, const char* fragment); |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 322 | virtual ~Program(); |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * Binds this program to the GL context. |
| 326 | */ |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 327 | virtual void use(); |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 328 | |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 329 | /** |
| 330 | * Marks this program as unused. This will not unbind |
| 331 | * the program from the GL context. |
| 332 | */ |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 333 | virtual void remove(); |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 334 | |
| 335 | /** |
Romain Guy | ac670c0 | 2010-07-27 17:39:27 -0700 | [diff] [blame] | 336 | * Returns the OpenGL name of the specified attribute. |
| 337 | */ |
| 338 | int getAttrib(const char* name); |
| 339 | |
| 340 | /** |
| 341 | * Returns the OpenGL name of the specified uniform. |
| 342 | */ |
| 343 | int getUniform(const char* name); |
| 344 | |
| 345 | /** |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 346 | * Indicates whether this program is currently in use with |
| 347 | * the GL context. |
| 348 | */ |
| 349 | inline bool isInUse() const { |
| 350 | return mUse; |
| 351 | } |
| 352 | |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 353 | /** |
Romain Guy | 67f2795 | 2010-12-07 20:09:23 -0800 | [diff] [blame] | 354 | * Indicates whether this program was correctly compiled and linked. |
| 355 | */ |
| 356 | inline bool isInitialized() const { |
| 357 | return mInitialized; |
| 358 | } |
| 359 | |
| 360 | /** |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 361 | * Binds the program with the specified projection, modelView and |
| 362 | * transform matrices. |
| 363 | */ |
| 364 | void set(const mat4& projectionMatrix, const mat4& modelViewMatrix, |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 365 | const mat4& transformMatrix, bool offset = false); |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 366 | |
| 367 | /** |
Romain Guy | 707b2f7 | 2010-10-11 16:34:59 -0700 | [diff] [blame] | 368 | * Sets the color associated with this shader. |
| 369 | */ |
| 370 | void setColor(const float r, const float g, const float b, const float a); |
| 371 | |
| 372 | /** |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 373 | * Name of the position attribute. |
| 374 | */ |
| 375 | int position; |
| 376 | |
| 377 | /** |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 378 | * Name of the texCoords attribute if it exists, -1 otherwise. |
| 379 | */ |
| 380 | int texCoords; |
| 381 | |
| 382 | /** |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 383 | * Name of the transform uniform. |
| 384 | */ |
| 385 | int transform; |
| 386 | |
Romain Guy | 39284b7 | 2012-09-26 16:39:40 -0700 | [diff] [blame] | 387 | /** |
| 388 | * Name of the projection uniform. |
| 389 | */ |
| 390 | int projection; |
| 391 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 392 | protected: |
| 393 | /** |
| 394 | * Adds an attribute with the specified name. |
| 395 | * |
| 396 | * @return The OpenGL name of the attribute. |
| 397 | */ |
| 398 | int addAttrib(const char* name); |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 399 | |
| 400 | /** |
Romain Guy | 3e263fa | 2011-12-12 16:47:48 -0800 | [diff] [blame] | 401 | * Binds the specified attribute name to the specified slot. |
| 402 | */ |
| 403 | int bindAttrib(const char* name, ShaderBindings bindingSlot); |
| 404 | |
| 405 | /** |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 406 | * Adds a uniform with the specified name. |
| 407 | * |
| 408 | * @return The OpenGL name of the uniform. |
| 409 | */ |
| 410 | int addUniform(const char* name); |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 411 | |
| 412 | private: |
| 413 | /** |
| 414 | * Compiles the specified shader of the specified type. |
| 415 | * |
| 416 | * @return The name of the compiled shader. |
| 417 | */ |
| 418 | GLuint buildShader(const char* source, GLenum type); |
| 419 | |
Romain Guy | 3e263fa | 2011-12-12 16:47:48 -0800 | [diff] [blame] | 420 | // Name of the OpenGL program and shaders |
Romain Guy | 05bbde7 | 2011-12-09 12:55:37 -0800 | [diff] [blame] | 421 | GLuint mProgramId; |
Romain Guy | 3e263fa | 2011-12-12 16:47:48 -0800 | [diff] [blame] | 422 | GLuint mVertexShader; |
| 423 | GLuint mFragmentShader; |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 424 | |
| 425 | // Keeps track of attributes and uniforms slots |
Romain Guy | 05bbde7 | 2011-12-09 12:55:37 -0800 | [diff] [blame] | 426 | KeyedVector<const char*, int> mAttributes; |
| 427 | KeyedVector<const char*, int> mUniforms; |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 428 | |
| 429 | bool mUse; |
Romain Guy | 67f2795 | 2010-12-07 20:09:23 -0800 | [diff] [blame] | 430 | bool mInitialized; |
Romain Guy | 05bbde7 | 2011-12-09 12:55:37 -0800 | [diff] [blame] | 431 | |
| 432 | bool mHasColorUniform; |
| 433 | int mColorUniform; |
Romain Guy | 2d4fd36 | 2011-12-13 22:00:19 -0800 | [diff] [blame] | 434 | |
| 435 | bool mHasSampler; |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 436 | }; // class Program |
| 437 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 438 | }; // namespace uirenderer |
| 439 | }; // namespace android |
| 440 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 441 | #endif // ANDROID_HWUI_PROGRAM_H |