blob: 2becfcb709c3763e9e36d37251c3059ec78745af [file] [log] [blame]
Romain Guy5cbbce52010-06-27 22:59:20 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_PROGRAM_H
18#define ANDROID_HWUI_PROGRAM_H
Romain Guy5cbbce52010-06-27 22:59:20 -070019
Romain Guyf3a910b42011-12-12 20:35:21 -080020#include <utils/KeyedVector.h>
21
Romain Guy5cbbce52010-06-27 22:59:20 -070022#include <GLES2/gl2.h>
23#include <GLES2/gl2ext.h>
24
Mike Reedc2f31df2016-10-28 17:21:45 -040025#include <SkBlendMode.h>
Romain Guy5cbbce52010-06-27 22:59:20 -070026
Chris Craik096b8d92013-03-01 11:08:11 -080027#include "Debug.h"
Chris Craik0519c812015-02-11 13:17:06 -080028#include "FloatColor.h"
Romain Guy0b9db912010-07-09 18:53:25 -070029#include "Matrix.h"
Romain Guyf3a910b42011-12-12 20:35:21 -080030#include "Properties.h"
Romain Guycaaaa662017-03-27 00:40:21 -070031#include "utils/Color.h"
Romain Guy0b9db912010-07-09 18:53:25 -070032
Romain Guy5cbbce52010-06-27 22:59:20 -070033namespace android {
34namespace uirenderer {
35
Romain Guyf3a910b42011-12-12 20:35:21 -080036///////////////////////////////////////////////////////////////////////////////
37// Defines
38///////////////////////////////////////////////////////////////////////////////
39
40// Debug
41#if DEBUG_PROGRAMS
Steve Block5baa3a62011-12-20 16:23:08 +000042 #define PROGRAM_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyf3a910b42011-12-12 20:35:21 -080043#else
44 #define PROGRAM_LOGD(...)
45#endif
46
Romain Guyf8773082012-07-12 18:01:00 -070047#define COLOR_COMPONENT_THRESHOLD 1.0f
48#define COLOR_COMPONENT_INV_THRESHOLD 0.0f
Romain Guyf3a910b42011-12-12 20:35:21 -080049
Chris Craikdeeda3d2014-05-05 19:09:33 -070050#define PROGRAM_KEY_TEXTURE 0x01
51#define PROGRAM_KEY_A8_TEXTURE 0x02
52#define PROGRAM_KEY_BITMAP 0x04
53#define PROGRAM_KEY_GRADIENT 0x08
54#define PROGRAM_KEY_BITMAP_FIRST 0x10
55#define PROGRAM_KEY_COLOR_MATRIX 0x20
56#define PROGRAM_KEY_COLOR_BLEND 0x40
57#define PROGRAM_KEY_BITMAP_NPOT 0x80
sergeyv9c97e482016-12-12 16:14:11 -080058#define PROGRAM_KEY_BITMAP_EXTERNAL 0x100
Romain Guyf3a910b42011-12-12 20:35:21 -080059
Chris Craikdeeda3d2014-05-05 19:09:33 -070060#define PROGRAM_KEY_BITMAP_WRAPS_MASK 0x600
Romain Guyf3a910b42011-12-12 20:35:21 -080061#define PROGRAM_KEY_BITMAP_WRAPT_MASK 0x1800
62
Romain Guycaaaa662017-03-27 00:40:21 -070063#define PROGRAM_KEY_SWAP_SRC_DST_SHIFT 13
64
Romain Guyf3a910b42011-12-12 20:35:21 -080065// Encode the xfermodes on 6 bits
66#define PROGRAM_MAX_XFERMODE 0x1f
67#define PROGRAM_XFERMODE_SHADER_SHIFT 26
68#define PROGRAM_XFERMODE_COLOR_OP_SHIFT 20
69#define PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT 14
70
71#define PROGRAM_BITMAP_WRAPS_SHIFT 9
72#define PROGRAM_BITMAP_WRAPT_SHIFT 11
73
Chris Craik6d29c8d2013-05-08 18:35:44 -070074#define PROGRAM_GRADIENT_TYPE_SHIFT 33 // 2 bits for gradient type
Romain Guyf3a910b42011-12-12 20:35:21 -080075#define PROGRAM_MODULATE_SHIFT 35
76
Chris Craik91a8c7c2014-08-12 14:31:35 -070077#define PROGRAM_HAS_VERTEX_ALPHA_SHIFT 36
78#define PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT 37
Romain Guyf3a910b42011-12-12 20:35:21 -080079
Chris Craikbf759452014-08-11 16:00:44 -070080#define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38
81#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39
Romain Guyf3a910b42011-12-12 20:35:21 -080082
Chris Craik11718bc2015-09-22 11:50:13 -070083#define PROGRAM_IS_SIMPLE_GRADIENT 40
Romain Guyf3a910b42011-12-12 20:35:21 -080084
Chris Craik11718bc2015-09-22 11:50:13 -070085#define PROGRAM_HAS_COLORS 41
Romain Guy41210632012-07-16 17:04:24 -070086
Chris Craik11718bc2015-09-22 11:50:13 -070087#define PROGRAM_HAS_DEBUG_HIGHLIGHT 42
88#define PROGRAM_HAS_ROUND_RECT_CLIP 43
Romain Guy3ff0bfd2013-02-25 14:15:37 -080089
Romain Guy253f2c22016-09-28 17:34:42 -070090#define PROGRAM_HAS_GAMMA_CORRECTION 44
Romain Guy636afc12017-02-07 11:21:05 -080091#define PROGRAM_HAS_LINEAR_TEXTURE 45
Romain Guy253f2c22016-09-28 17:34:42 -070092
Romain Guycaaaa662017-03-27 00:40:21 -070093#define PROGRAM_HAS_COLOR_SPACE_CONVERSION 46
94#define PROGRAM_TRANSFER_FUNCTION 47 // 2 bits for transfer function
95#define PROGRAM_HAS_TRANSLUCENT_CONVERSION 49
96
Romain Guyf3a910b42011-12-12 20:35:21 -080097///////////////////////////////////////////////////////////////////////////////
98// Types
99///////////////////////////////////////////////////////////////////////////////
100
101typedef uint64_t programid;
102
103///////////////////////////////////////////////////////////////////////////////
104// Program description
105///////////////////////////////////////////////////////////////////////////////
106
107/**
108 * Describe the features required for a given program. The features
109 * determine the generation of both the vertex and fragment shaders.
110 * A ProgramDescription must be used in conjunction with a ProgramCache.
111 */
112struct ProgramDescription {
Romain Guycaaaa662017-03-27 00:40:21 -0700113 enum class ColorFilterMode : int8_t {
Chris Craikb9ce116d2015-08-20 15:14:06 -0700114 None = 0,
115 Matrix,
116 Blend
Romain Guyf3a910b42011-12-12 20:35:21 -0800117 };
118
Romain Guycaaaa662017-03-27 00:40:21 -0700119 enum Gradient : int8_t {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700120 kGradientLinear = 0,
Romain Guyf3a910b42011-12-12 20:35:21 -0800121 kGradientCircular,
122 kGradientSweep
123 };
124
125 ProgramDescription() {
126 reset();
127 }
128
129 // Texturing
130 bool hasTexture;
131 bool hasAlpha8Texture;
132 bool hasExternalTexture;
133 bool hasTextureTransform;
134
Romain Guyff316ec2013-02-13 18:39:43 -0800135 // Color attribute
136 bool hasColors;
137
Romain Guyf3a910b42011-12-12 20:35:21 -0800138 // Modulate, this should only be set when setColor() return true
139 bool modulate;
140
141 // Shaders
142 bool hasBitmap;
sergeyv9c97e482016-12-12 16:14:11 -0800143 bool isShaderBitmapExternal;
sergeyv554ffeb2016-11-15 18:01:21 -0800144 bool useShaderBasedWrap;
Romain Guyf3a910b42011-12-12 20:35:21 -0800145
Chris Craik91a8c7c2014-08-12 14:31:35 -0700146 bool hasVertexAlpha;
147 bool useShadowAlphaInterp;
Romain Guyf3a910b42011-12-12 20:35:21 -0800148
149 bool hasGradient;
150 Gradient gradientType;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700151 bool isSimpleGradient;
Romain Guyf3a910b42011-12-12 20:35:21 -0800152
Mike Reedc2f31df2016-10-28 17:21:45 -0400153 SkBlendMode shadersMode;
Romain Guyf3a910b42011-12-12 20:35:21 -0800154
155 bool isBitmapFirst;
156 GLenum bitmapWrapS;
157 GLenum bitmapWrapT;
158
159 // Color operations
Chris Craik117bdbc2015-02-05 10:12:38 -0800160 ColorFilterMode colorOp;
Mike Reedc2f31df2016-10-28 17:21:45 -0400161 SkBlendMode colorMode;
Romain Guyf3a910b42011-12-12 20:35:21 -0800162
163 // Framebuffer blending (requires Extensions.hasFramebufferFetch())
Mike Reedc2f31df2016-10-28 17:21:45 -0400164 // Ignored for all values < SkBlendMode::kPlus
165 SkBlendMode framebufferMode;
Romain Guyf3a910b42011-12-12 20:35:21 -0800166 bool swapSrcDst;
167
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800168 bool hasDebugHighlight;
Chris Craikdeeda3d2014-05-05 19:09:33 -0700169 bool hasRoundRectClip;
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800170
Romain Guy636afc12017-02-07 11:21:05 -0800171 // Extra gamma correction used for text
Romain Guy253f2c22016-09-28 17:34:42 -0700172 bool hasGammaCorrection;
Romain Guy636afc12017-02-07 11:21:05 -0800173 // Set when sampling an image in linear space
174 bool hasLinearTexture;
Romain Guy253f2c22016-09-28 17:34:42 -0700175
Romain Guycaaaa662017-03-27 00:40:21 -0700176 bool hasColorSpaceConversion;
177 TransferFunctionType transferFunction;
178 // Indicates whether the bitmap to convert between color spaces is translucent
179 bool hasTranslucentConversion;
180
Romain Guyf3a910b42011-12-12 20:35:21 -0800181 /**
182 * Resets this description. All fields are reset back to the default
183 * values they hold after building a new instance.
184 */
185 void reset() {
186 hasTexture = false;
187 hasAlpha8Texture = false;
188 hasExternalTexture = false;
189 hasTextureTransform = false;
190
Romain Guyff316ec2013-02-13 18:39:43 -0800191 hasColors = false;
192
Chris Craik91a8c7c2014-08-12 14:31:35 -0700193 hasVertexAlpha = false;
194 useShadowAlphaInterp = false;
Romain Guyf3a910b42011-12-12 20:35:21 -0800195
196 modulate = false;
197
198 hasBitmap = false;
sergeyv9c97e482016-12-12 16:14:11 -0800199 isShaderBitmapExternal = false;
sergeyv554ffeb2016-11-15 18:01:21 -0800200 useShaderBasedWrap = false;
Romain Guyf3a910b42011-12-12 20:35:21 -0800201
202 hasGradient = false;
203 gradientType = kGradientLinear;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700204 isSimpleGradient = false;
Romain Guyf3a910b42011-12-12 20:35:21 -0800205
Mike Reedc2f31df2016-10-28 17:21:45 -0400206 shadersMode = SkBlendMode::kClear;
Romain Guyf3a910b42011-12-12 20:35:21 -0800207
208 isBitmapFirst = false;
209 bitmapWrapS = GL_CLAMP_TO_EDGE;
210 bitmapWrapT = GL_CLAMP_TO_EDGE;
211
Chris Craikb9ce116d2015-08-20 15:14:06 -0700212 colorOp = ColorFilterMode::None;
Mike Reedc2f31df2016-10-28 17:21:45 -0400213 colorMode = SkBlendMode::kClear;
Romain Guyf3a910b42011-12-12 20:35:21 -0800214
Mike Reedc2f31df2016-10-28 17:21:45 -0400215 framebufferMode = SkBlendMode::kClear;
Romain Guyf3a910b42011-12-12 20:35:21 -0800216 swapSrcDst = false;
217
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800218 hasDebugHighlight = false;
Chris Craikdeeda3d2014-05-05 19:09:33 -0700219 hasRoundRectClip = false;
Romain Guy253f2c22016-09-28 17:34:42 -0700220
221 hasGammaCorrection = false;
Romain Guy636afc12017-02-07 11:21:05 -0800222 hasLinearTexture = false;
Romain Guycaaaa662017-03-27 00:40:21 -0700223
224 hasColorSpaceConversion = false;
225 transferFunction = TransferFunctionType::None;
226 hasTranslucentConversion = false;
Romain Guyf3a910b42011-12-12 20:35:21 -0800227 }
228
229 /**
230 * Indicates, for a given color, whether color modulation is required in
231 * the fragment shader. When this method returns true, the program should
232 * be provided with a modulation color.
233 */
Chris Craike63f7c622013-10-17 10:30:55 -0700234 bool setColorModulate(const float a) {
Romain Guya938f562012-09-13 20:31:08 -0700235 modulate = a < COLOR_COMPONENT_THRESHOLD;
Romain Guyf3a910b42011-12-12 20:35:21 -0800236 return modulate;
237 }
238
239 /**
240 * Indicates, for a given color, whether color modulation is required in
241 * the fragment shader. When this method returns true, the program should
242 * be provided with a modulation color.
243 */
Chris Craike63f7c622013-10-17 10:30:55 -0700244 bool setAlpha8ColorModulate(const float r, const float g, const float b, const float a) {
Romain Guyf3a910b42011-12-12 20:35:21 -0800245 modulate = a < COLOR_COMPONENT_THRESHOLD || r > COLOR_COMPONENT_INV_THRESHOLD ||
246 g > COLOR_COMPONENT_INV_THRESHOLD || b > COLOR_COMPONENT_INV_THRESHOLD;
247 return modulate;
248 }
249
250 /**
251 * Computes the unique key identifying this program.
252 */
253 programid key() const {
254 programid key = 0;
255 if (hasTexture) key |= PROGRAM_KEY_TEXTURE;
256 if (hasAlpha8Texture) key |= PROGRAM_KEY_A8_TEXTURE;
257 if (hasBitmap) {
258 key |= PROGRAM_KEY_BITMAP;
sergeyv554ffeb2016-11-15 18:01:21 -0800259 if (useShaderBasedWrap) {
Romain Guyf3a910b42011-12-12 20:35:21 -0800260 key |= PROGRAM_KEY_BITMAP_NPOT;
261 key |= getEnumForWrap(bitmapWrapS) << PROGRAM_BITMAP_WRAPS_SHIFT;
262 key |= getEnumForWrap(bitmapWrapT) << PROGRAM_BITMAP_WRAPT_SHIFT;
263 }
sergeyv9c97e482016-12-12 16:14:11 -0800264 if (isShaderBitmapExternal) {
265 key |= PROGRAM_KEY_BITMAP_EXTERNAL;
266 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800267 }
268 if (hasGradient) key |= PROGRAM_KEY_GRADIENT;
269 key |= programid(gradientType) << PROGRAM_GRADIENT_TYPE_SHIFT;
270 if (isBitmapFirst) key |= PROGRAM_KEY_BITMAP_FIRST;
271 if (hasBitmap && hasGradient) {
Mike Reedc2f31df2016-10-28 17:21:45 -0400272 key |= ((int)shadersMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_SHADER_SHIFT;
Romain Guyf3a910b42011-12-12 20:35:21 -0800273 }
274 switch (colorOp) {
Chris Craikb9ce116d2015-08-20 15:14:06 -0700275 case ColorFilterMode::Matrix:
Romain Guyf3a910b42011-12-12 20:35:21 -0800276 key |= PROGRAM_KEY_COLOR_MATRIX;
277 break;
Chris Craikb9ce116d2015-08-20 15:14:06 -0700278 case ColorFilterMode::Blend:
Romain Guyf3a910b42011-12-12 20:35:21 -0800279 key |= PROGRAM_KEY_COLOR_BLEND;
Romain Guycaaaa662017-03-27 00:40:21 -0700280 key |= ((int) colorMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_COLOR_OP_SHIFT;
Romain Guyf3a910b42011-12-12 20:35:21 -0800281 break;
Chris Craikb9ce116d2015-08-20 15:14:06 -0700282 case ColorFilterMode::None:
Romain Guyf3a910b42011-12-12 20:35:21 -0800283 break;
284 }
Romain Guycaaaa662017-03-27 00:40:21 -0700285 key |= ((int) framebufferMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT;
286 key |= programid(swapSrcDst) << PROGRAM_KEY_SWAP_SRC_DST_SHIFT;
287 key |= programid(modulate) << PROGRAM_MODULATE_SHIFT;
288 key |= programid(hasVertexAlpha) << PROGRAM_HAS_VERTEX_ALPHA_SHIFT;
289 key |= programid(useShadowAlphaInterp) << PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT;
290 key |= programid(hasExternalTexture) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT;
291 key |= programid(hasTextureTransform) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT;
292 key |= programid(isSimpleGradient) << PROGRAM_IS_SIMPLE_GRADIENT;
293 key |= programid(hasColors) << PROGRAM_HAS_COLORS;
294 key |= programid(hasDebugHighlight) << PROGRAM_HAS_DEBUG_HIGHLIGHT;
295 key |= programid(hasRoundRectClip) << PROGRAM_HAS_ROUND_RECT_CLIP;
296 key |= programid(hasGammaCorrection) << PROGRAM_HAS_GAMMA_CORRECTION;
297 key |= programid(hasLinearTexture) << PROGRAM_HAS_LINEAR_TEXTURE;
298 key |= programid(hasColorSpaceConversion) << PROGRAM_HAS_COLOR_SPACE_CONVERSION;
299 key |= programid(transferFunction) << PROGRAM_TRANSFER_FUNCTION;
300 key |= programid(hasTranslucentConversion) << PROGRAM_HAS_TRANSLUCENT_CONVERSION;
Romain Guyf3a910b42011-12-12 20:35:21 -0800301 return key;
302 }
303
304 /**
305 * Logs the specified message followed by the key identifying this program.
306 */
307 void log(const char* message) const {
308#if DEBUG_PROGRAMS
309 programid k = key();
310 PROGRAM_LOGD("%s (key = 0x%.8x%.8x)", message, uint32_t(k >> 32),
311 uint32_t(k & 0xffffffff));
312#endif
313 }
314
315private:
Romain Guy41210632012-07-16 17:04:24 -0700316 static inline uint32_t getEnumForWrap(GLenum wrap) {
Romain Guyf3a910b42011-12-12 20:35:21 -0800317 switch (wrap) {
318 case GL_CLAMP_TO_EDGE:
319 return 0;
320 case GL_REPEAT:
321 return 1;
322 case GL_MIRRORED_REPEAT:
323 return 2;
324 }
325 return 0;
326 }
327
328}; // struct ProgramDescription
329
Romain Guy5cbbce52010-06-27 22:59:20 -0700330/**
331 * A program holds a vertex and a fragment shader. It offers several utility
332 * methods to query attributes and uniforms.
333 */
Romain Guy889f8d12010-07-29 14:37:42 -0700334class Program {
Romain Guy5cbbce52010-06-27 22:59:20 -0700335public:
Romain Guy3e263fa2011-12-12 16:47:48 -0800336 enum ShaderBindings {
337 kBindingPosition,
338 kBindingTexCoords
339 };
340
Romain Guy5cbbce52010-06-27 22:59:20 -0700341 /**
342 * Creates a new program with the specified vertex and fragment
343 * shaders sources.
344 */
Romain Guyf3a910b42011-12-12 20:35:21 -0800345 Program(const ProgramDescription& description, const char* vertex, const char* fragment);
Romain Guy6926c722010-07-12 20:20:03 -0700346 virtual ~Program();
Romain Guy5cbbce52010-06-27 22:59:20 -0700347
348 /**
349 * Binds this program to the GL context.
350 */
Romain Guy6926c722010-07-12 20:20:03 -0700351 virtual void use();
Romain Guy5cbbce52010-06-27 22:59:20 -0700352
Romain Guy260e1022010-07-12 14:41:06 -0700353 /**
354 * Marks this program as unused. This will not unbind
355 * the program from the GL context.
356 */
Romain Guy6926c722010-07-12 20:20:03 -0700357 virtual void remove();
Romain Guy260e1022010-07-12 14:41:06 -0700358
359 /**
Romain Guyac670c02010-07-27 17:39:27 -0700360 * Returns the OpenGL name of the specified attribute.
361 */
362 int getAttrib(const char* name);
363
364 /**
365 * Returns the OpenGL name of the specified uniform.
366 */
367 int getUniform(const char* name);
368
369 /**
Romain Guy260e1022010-07-12 14:41:06 -0700370 * Indicates whether this program is currently in use with
371 * the GL context.
372 */
373 inline bool isInUse() const {
374 return mUse;
375 }
376
Romain Guy889f8d12010-07-29 14:37:42 -0700377 /**
Romain Guy67f27952010-12-07 20:09:23 -0800378 * Indicates whether this program was correctly compiled and linked.
379 */
380 inline bool isInitialized() const {
381 return mInitialized;
382 }
383
384 /**
Romain Guy889f8d12010-07-29 14:37:42 -0700385 * Binds the program with the specified projection, modelView and
386 * transform matrices.
387 */
388 void set(const mat4& projectionMatrix, const mat4& modelViewMatrix,
Chet Haase8a5cc922011-04-26 07:28:09 -0700389 const mat4& transformMatrix, bool offset = false);
Romain Guy889f8d12010-07-29 14:37:42 -0700390
391 /**
Romain Guy707b2f72010-10-11 16:34:59 -0700392 * Sets the color associated with this shader.
393 */
Chris Craik0519c812015-02-11 13:17:06 -0800394 void setColor(FloatColor color);
Romain Guy707b2f72010-10-11 16:34:59 -0700395
396 /**
Chris Craik6c15ffa2015-02-02 13:50:55 -0800397 * Name of the texCoords attribute if it exists (kBindingTexCoords), -1 otherwise.
Romain Guyf3a910b42011-12-12 20:35:21 -0800398 */
399 int texCoords;
400
401 /**
Romain Guy889f8d12010-07-29 14:37:42 -0700402 * Name of the transform uniform.
403 */
404 int transform;
405
Romain Guy39284b72012-09-26 16:39:40 -0700406 /**
407 * Name of the projection uniform.
408 */
409 int projection;
410
Romain Guy5cbbce52010-06-27 22:59:20 -0700411protected:
412 /**
413 * Adds an attribute with the specified name.
414 *
415 * @return The OpenGL name of the attribute.
416 */
417 int addAttrib(const char* name);
Romain Guy5cbbce52010-06-27 22:59:20 -0700418
419 /**
Romain Guy3e263fa2011-12-12 16:47:48 -0800420 * Binds the specified attribute name to the specified slot.
421 */
422 int bindAttrib(const char* name, ShaderBindings bindingSlot);
423
424 /**
Romain Guy5cbbce52010-06-27 22:59:20 -0700425 * Adds a uniform with the specified name.
426 *
427 * @return The OpenGL name of the uniform.
428 */
429 int addUniform(const char* name);
Romain Guy5cbbce52010-06-27 22:59:20 -0700430
431private:
432 /**
433 * Compiles the specified shader of the specified type.
434 *
435 * @return The name of the compiled shader.
436 */
437 GLuint buildShader(const char* source, GLenum type);
438
Romain Guy3e263fa2011-12-12 16:47:48 -0800439 // Name of the OpenGL program and shaders
Romain Guy05bbde72011-12-09 12:55:37 -0800440 GLuint mProgramId;
Romain Guy3e263fa2011-12-12 16:47:48 -0800441 GLuint mVertexShader;
442 GLuint mFragmentShader;
Romain Guy5cbbce52010-06-27 22:59:20 -0700443
444 // Keeps track of attributes and uniforms slots
Romain Guy05bbde72011-12-09 12:55:37 -0800445 KeyedVector<const char*, int> mAttributes;
446 KeyedVector<const char*, int> mUniforms;
Romain Guy260e1022010-07-12 14:41:06 -0700447
448 bool mUse;
Romain Guy67f27952010-12-07 20:09:23 -0800449 bool mInitialized;
Romain Guy05bbde72011-12-09 12:55:37 -0800450
Romain Guy3b748a42013-04-17 18:54:38 -0700451 // Uniforms caching
Romain Guy05bbde72011-12-09 12:55:37 -0800452 bool mHasColorUniform;
453 int mColorUniform;
Romain Guy2d4fd362011-12-13 22:00:19 -0800454
455 bool mHasSampler;
Romain Guy3b748a42013-04-17 18:54:38 -0700456
457 mat4 mProjection;
Chris Craikd04a6b12014-01-29 13:00:33 -0800458 bool mOffset;
Romain Guy5cbbce52010-06-27 22:59:20 -0700459}; // class Program
460
Romain Guy5cbbce52010-06-27 22:59:20 -0700461}; // namespace uirenderer
462}; // namespace android
463
Romain Guy5b3b3522010-10-27 18:57:51 -0700464#endif // ANDROID_HWUI_PROGRAM_H