1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_SHADER_H_
6 #define CC_OUTPUT_SHADER_H_
10 #include "base/basictypes.h"
11 #include "cc/base/cc_export.h"
26 enum TexCoordPrecision
{
27 TexCoordPrecisionNA
= 0,
28 TexCoordPrecisionMedium
= 1,
29 TexCoordPrecisionHigh
= 2,
30 NumTexCoordPrecisions
= 3
36 SamplerType2DRect
= 2,
37 SamplerTypeExternalOES
= 3,
41 // Note: The highp_threshold_cache must be provided by the caller to make
42 // the caching multi-thread/context safe in an easy low-overhead manner.
43 // The caller must make sure to clear highp_threshold_cache to 0, so it can be
44 // reinitialized, if a new or different context is used.
45 CC_EXPORT TexCoordPrecision
46 TexCoordPrecisionRequired(gpu::gles2::GLES2Interface
* context
,
47 int* highp_threshold_cache
,
48 int highp_threshold_min
,
49 const gfx::Point
& max_coordinate
);
51 CC_EXPORT TexCoordPrecision
TexCoordPrecisionRequired(
52 gpu::gles2::GLES2Interface
* context
,
53 int *highp_threshold_cache
,
54 int highp_threshold_min
,
55 const gfx::Size
& max_size
);
57 class VertexShaderPosTex
{
61 void Init(gpu::gles2::GLES2Interface
* context
,
63 int* base_uniform_index
);
64 std::string
GetShaderString() const;
66 int matrix_location() const { return matrix_location_
; }
71 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex
);
74 class VertexShaderPosTexYUVStretchOffset
{
76 VertexShaderPosTexYUVStretchOffset();
78 void Init(gpu::gles2::GLES2Interface
* context
,
80 int* base_uniform_index
);
81 std::string
GetShaderString() const;
83 int matrix_location() const { return matrix_location_
; }
84 int tex_scale_location() const { return tex_scale_location_
; }
85 int tex_offset_location() const { return tex_offset_location_
; }
89 int tex_scale_location_
;
90 int tex_offset_location_
;
92 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretchOffset
);
95 class VertexShaderPos
{
99 void Init(gpu::gles2::GLES2Interface
* context
,
101 int* base_uniform_index
);
102 std::string
GetShaderString() const;
104 int matrix_location() const { return matrix_location_
; }
107 int matrix_location_
;
109 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos
);
112 class VertexShaderPosTexIdentity
{
114 void Init(gpu::gles2::GLES2Interface
* context
,
116 int* base_uniform_index
) {}
117 std::string
GetShaderString() const;
120 class VertexShaderPosTexTransform
{
122 VertexShaderPosTexTransform();
124 void Init(gpu::gles2::GLES2Interface
* context
,
126 int* base_uniform_index
);
127 std::string
GetShaderString() const;
129 int matrix_location() const { return matrix_location_
; }
130 int tex_transform_location() const { return tex_transform_location_
; }
131 int vertex_opacity_location() const { return vertex_opacity_location_
; }
134 int matrix_location_
;
135 int tex_transform_location_
;
136 int vertex_opacity_location_
;
138 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform
);
141 class VertexShaderQuad
{
145 void Init(gpu::gles2::GLES2Interface
* context
,
147 int* base_uniform_index
);
148 std::string
GetShaderString() const;
150 int matrix_location() const { return matrix_location_
; }
151 int viewport_location() const { return -1; }
152 int quad_location() const { return quad_location_
; }
153 int edge_location() const { return -1; }
156 int matrix_location_
;
159 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad
);
162 class VertexShaderQuadAA
{
164 VertexShaderQuadAA();
166 void Init(gpu::gles2::GLES2Interface
* context
,
168 int* base_uniform_index
);
169 std::string
GetShaderString() const;
171 int matrix_location() const { return matrix_location_
; }
172 int viewport_location() const { return viewport_location_
; }
173 int quad_location() const { return quad_location_
; }
174 int edge_location() const { return edge_location_
; }
177 int matrix_location_
;
178 int viewport_location_
;
182 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA
);
186 class VertexShaderQuadTexTransformAA
{
188 VertexShaderQuadTexTransformAA();
190 void Init(gpu::gles2::GLES2Interface
* context
,
192 int* base_uniform_index
);
193 std::string
GetShaderString() const;
195 int matrix_location() const { return matrix_location_
; }
196 int viewport_location() const { return viewport_location_
; }
197 int quad_location() const { return quad_location_
; }
198 int edge_location() const { return edge_location_
; }
199 int tex_transform_location() const { return tex_transform_location_
; }
202 int matrix_location_
;
203 int viewport_location_
;
206 int tex_transform_location_
;
208 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA
);
211 class VertexShaderTile
{
215 void Init(gpu::gles2::GLES2Interface
* context
,
217 int* base_uniform_index
);
218 std::string
GetShaderString() const;
220 int matrix_location() const { return matrix_location_
; }
221 int viewport_location() const { return -1; }
222 int quad_location() const { return quad_location_
; }
223 int edge_location() const { return -1; }
224 int vertex_tex_transform_location() const {
225 return vertex_tex_transform_location_
;
229 int matrix_location_
;
231 int vertex_tex_transform_location_
;
233 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile
);
236 class VertexShaderTileAA
{
238 VertexShaderTileAA();
240 void Init(gpu::gles2::GLES2Interface
* context
,
242 int* base_uniform_index
);
243 std::string
GetShaderString() const;
245 int matrix_location() const { return matrix_location_
; }
246 int viewport_location() const { return viewport_location_
; }
247 int quad_location() const { return quad_location_
; }
248 int edge_location() const { return edge_location_
; }
249 int vertex_tex_transform_location() const {
250 return vertex_tex_transform_location_
;
254 int matrix_location_
;
255 int viewport_location_
;
258 int vertex_tex_transform_location_
;
260 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA
);
263 class VertexShaderVideoTransform
{
265 VertexShaderVideoTransform();
267 void Init(gpu::gles2::GLES2Interface
* context
,
269 int* base_uniform_index
);
270 std::string
GetShaderString() const;
272 int matrix_location() const { return matrix_location_
; }
273 int tex_matrix_location() const { return tex_matrix_location_
; }
276 int matrix_location_
;
277 int tex_matrix_location_
;
279 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform
);
282 class FragmentTexAlphaBinding
{
284 FragmentTexAlphaBinding();
286 void Init(gpu::gles2::GLES2Interface
* context
,
288 int* base_uniform_index
);
289 int alpha_location() const { return alpha_location_
; }
290 int fragment_tex_transform_location() const { return -1; }
291 int sampler_location() const { return sampler_location_
; }
294 int sampler_location_
;
297 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding
);
300 class FragmentTexColorMatrixAlphaBinding
{
302 FragmentTexColorMatrixAlphaBinding();
304 void Init(gpu::gles2::GLES2Interface
* context
,
306 int* base_uniform_index
);
307 int alpha_location() const { return alpha_location_
; }
308 int color_matrix_location() const { return color_matrix_location_
; }
309 int color_offset_location() const { return color_offset_location_
; }
310 int fragment_tex_transform_location() const { return -1; }
311 int sampler_location() const { return sampler_location_
; }
314 int sampler_location_
;
316 int color_matrix_location_
;
317 int color_offset_location_
;
320 class FragmentTexOpaqueBinding
{
322 FragmentTexOpaqueBinding();
324 void Init(gpu::gles2::GLES2Interface
* context
,
326 int* base_uniform_index
);
327 int alpha_location() const { return -1; }
328 int fragment_tex_transform_location() const { return -1; }
329 int background_color_location() const { return -1; }
330 int sampler_location() const { return sampler_location_
; }
333 int sampler_location_
;
335 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding
);
338 class FragmentTexBackgroundBinding
{
340 FragmentTexBackgroundBinding();
342 void Init(gpu::gles2::GLES2Interface
* context
,
344 int* base_uniform_index
);
345 int background_color_location() const { return background_color_location_
; }
346 int sampler_location() const { return sampler_location_
; }
349 int background_color_location_
;
350 int sampler_location_
;
352 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding
);
355 class FragmentShaderRGBATexVaryingAlpha
: public FragmentTexOpaqueBinding
{
357 std::string
GetShaderString(
358 TexCoordPrecision precision
, SamplerType sampler
) const;
361 class FragmentShaderRGBATexPremultiplyAlpha
: public FragmentTexOpaqueBinding
{
363 std::string
GetShaderString(
364 TexCoordPrecision precision
, SamplerType sampler
) const;
367 class FragmentShaderTexBackgroundVaryingAlpha
368 : public FragmentTexBackgroundBinding
{
370 std::string
GetShaderString(
371 TexCoordPrecision precision
, SamplerType sampler
) const;
374 class FragmentShaderTexBackgroundPremultiplyAlpha
375 : public FragmentTexBackgroundBinding
{
377 std::string
GetShaderString(
378 TexCoordPrecision precision
, SamplerType sampler
) const;
381 class FragmentShaderRGBATexAlpha
: public FragmentTexAlphaBinding
{
383 std::string
GetShaderString(
384 TexCoordPrecision precision
, SamplerType sampler
) const;
387 class FragmentShaderRGBATexColorMatrixAlpha
388 : public FragmentTexColorMatrixAlphaBinding
{
390 std::string
GetShaderString(
391 TexCoordPrecision precision
, SamplerType sampler
) const;
394 class FragmentShaderRGBATexOpaque
: public FragmentTexOpaqueBinding
{
396 std::string
GetShaderString(
397 TexCoordPrecision precision
, SamplerType sampler
) const;
400 class FragmentShaderRGBATex
: public FragmentTexOpaqueBinding
{
402 std::string
GetShaderString(
403 TexCoordPrecision precision
, SamplerType sampler
) const;
406 // Swizzles the red and blue component of sampled texel with alpha.
407 class FragmentShaderRGBATexSwizzleAlpha
: public FragmentTexAlphaBinding
{
409 std::string
GetShaderString(
410 TexCoordPrecision precision
, SamplerType sampler
) const;
413 // Swizzles the red and blue component of sampled texel without alpha.
414 class FragmentShaderRGBATexSwizzleOpaque
: public FragmentTexOpaqueBinding
{
416 std::string
GetShaderString(
417 TexCoordPrecision precision
, SamplerType sampler
) const;
420 class FragmentShaderRGBATexAlphaAA
{
422 FragmentShaderRGBATexAlphaAA();
424 void Init(gpu::gles2::GLES2Interface
* context
,
426 int* base_uniform_index
);
427 std::string
GetShaderString(
428 TexCoordPrecision precision
, SamplerType sampler
) const;
430 int alpha_location() const { return alpha_location_
; }
431 int sampler_location() const { return sampler_location_
; }
434 int sampler_location_
;
437 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA
);
440 class FragmentTexClampAlphaAABinding
{
442 FragmentTexClampAlphaAABinding();
444 void Init(gpu::gles2::GLES2Interface
* context
,
446 int* base_uniform_index
);
447 int alpha_location() const { return alpha_location_
; }
448 int sampler_location() const { return sampler_location_
; }
449 int fragment_tex_transform_location() const {
450 return fragment_tex_transform_location_
;
454 int sampler_location_
;
456 int fragment_tex_transform_location_
;
458 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding
);
461 class FragmentShaderRGBATexClampAlphaAA
462 : public FragmentTexClampAlphaAABinding
{
464 std::string
GetShaderString(
465 TexCoordPrecision precision
, SamplerType sampler
) const;
468 // Swizzles the red and blue component of sampled texel.
469 class FragmentShaderRGBATexClampSwizzleAlphaAA
470 : public FragmentTexClampAlphaAABinding
{
472 std::string
GetShaderString(
473 TexCoordPrecision precision
, SamplerType sampler
) const;
476 class FragmentShaderRGBATexAlphaMask
{
478 FragmentShaderRGBATexAlphaMask();
479 std::string
GetShaderString(
480 TexCoordPrecision precision
, SamplerType sampler
) const;
482 void Init(gpu::gles2::GLES2Interface
* context
,
484 int* base_uniform_index
);
485 int alpha_location() const { return alpha_location_
; }
486 int sampler_location() const { return sampler_location_
; }
487 int mask_sampler_location() const { return mask_sampler_location_
; }
488 int mask_tex_coord_scale_location() const {
489 return mask_tex_coord_scale_location_
;
491 int mask_tex_coord_offset_location() const {
492 return mask_tex_coord_offset_location_
;
496 int sampler_location_
;
497 int mask_sampler_location_
;
499 int mask_tex_coord_scale_location_
;
500 int mask_tex_coord_offset_location_
;
502 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask
);
505 class FragmentShaderRGBATexAlphaMaskAA
{
507 FragmentShaderRGBATexAlphaMaskAA();
508 std::string
GetShaderString(
509 TexCoordPrecision precision
, SamplerType sampler
) const;
511 void Init(gpu::gles2::GLES2Interface
* context
,
513 int* base_uniform_index
);
514 int alpha_location() const { return alpha_location_
; }
515 int sampler_location() const { return sampler_location_
; }
516 int mask_sampler_location() const { return mask_sampler_location_
; }
517 int mask_tex_coord_scale_location() const {
518 return mask_tex_coord_scale_location_
;
520 int mask_tex_coord_offset_location() const {
521 return mask_tex_coord_offset_location_
;
525 int sampler_location_
;
526 int mask_sampler_location_
;
528 int mask_tex_coord_scale_location_
;
529 int mask_tex_coord_offset_location_
;
531 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA
);
534 class FragmentShaderRGBATexAlphaMaskColorMatrixAA
{
536 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
537 std::string
GetShaderString(
538 TexCoordPrecision precision
, SamplerType sampler
) const;
540 void Init(gpu::gles2::GLES2Interface
* context
,
542 int* base_uniform_index
);
543 int alpha_location() const { return alpha_location_
; }
544 int sampler_location() const { return sampler_location_
; }
545 int mask_sampler_location() const { return mask_sampler_location_
; }
546 int mask_tex_coord_scale_location() const {
547 return mask_tex_coord_scale_location_
;
549 int mask_tex_coord_offset_location() const {
550 return mask_tex_coord_offset_location_
;
552 int color_matrix_location() const { return color_matrix_location_
; }
553 int color_offset_location() const { return color_offset_location_
; }
556 int sampler_location_
;
557 int mask_sampler_location_
;
559 int mask_tex_coord_scale_location_
;
560 int mask_tex_coord_offset_location_
;
561 int color_matrix_location_
;
562 int color_offset_location_
;
565 class FragmentShaderRGBATexAlphaColorMatrixAA
{
567 FragmentShaderRGBATexAlphaColorMatrixAA();
568 std::string
GetShaderString(
569 TexCoordPrecision precision
, SamplerType sampler
) const;
571 void Init(gpu::gles2::GLES2Interface
* context
,
573 int* base_uniform_index
);
574 int alpha_location() const { return alpha_location_
; }
575 int sampler_location() const { return sampler_location_
; }
576 int color_matrix_location() const { return color_matrix_location_
; }
577 int color_offset_location() const { return color_offset_location_
; }
580 int sampler_location_
;
582 int color_matrix_location_
;
583 int color_offset_location_
;
586 class FragmentShaderRGBATexAlphaMaskColorMatrix
{
588 FragmentShaderRGBATexAlphaMaskColorMatrix();
589 std::string
GetShaderString(
590 TexCoordPrecision precision
, SamplerType sampler
) const;
592 void Init(gpu::gles2::GLES2Interface
* context
,
594 int* base_uniform_index
);
595 int alpha_location() const { return alpha_location_
; }
596 int sampler_location() const { return sampler_location_
; }
597 int mask_sampler_location() const { return mask_sampler_location_
; }
598 int mask_tex_coord_scale_location() const {
599 return mask_tex_coord_scale_location_
;
601 int mask_tex_coord_offset_location() const {
602 return mask_tex_coord_offset_location_
;
604 int color_matrix_location() const { return color_matrix_location_
; }
605 int color_offset_location() const { return color_offset_location_
; }
608 int sampler_location_
;
609 int mask_sampler_location_
;
611 int mask_tex_coord_scale_location_
;
612 int mask_tex_coord_offset_location_
;
613 int color_matrix_location_
;
614 int color_offset_location_
;
617 class FragmentShaderYUVVideo
{
619 FragmentShaderYUVVideo();
620 std::string
GetShaderString(
621 TexCoordPrecision precision
, SamplerType sampler
) const;
623 void Init(gpu::gles2::GLES2Interface
* context
,
625 int* base_uniform_index
);
626 int y_texture_location() const { return y_texture_location_
; }
627 int u_texture_location() const { return u_texture_location_
; }
628 int v_texture_location() const { return v_texture_location_
; }
629 int alpha_location() const { return alpha_location_
; }
630 int yuv_matrix_location() const { return yuv_matrix_location_
; }
631 int yuv_adj_location() const { return yuv_adj_location_
; }
634 int y_texture_location_
;
635 int u_texture_location_
;
636 int v_texture_location_
;
638 int yuv_matrix_location_
;
639 int yuv_adj_location_
;
641 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo
);
645 class FragmentShaderYUVAVideo
{
647 FragmentShaderYUVAVideo();
648 std::string
GetShaderString(
649 TexCoordPrecision precision
, SamplerType sampler
) const;
651 void Init(gpu::gles2::GLES2Interface
* context
,
653 int* base_uniform_index
);
655 int y_texture_location() const { return y_texture_location_
; }
656 int u_texture_location() const { return u_texture_location_
; }
657 int v_texture_location() const { return v_texture_location_
; }
658 int a_texture_location() const { return a_texture_location_
; }
659 int alpha_location() const { return alpha_location_
; }
660 int yuv_matrix_location() const { return yuv_matrix_location_
; }
661 int yuv_adj_location() const { return yuv_adj_location_
; }
664 int y_texture_location_
;
665 int u_texture_location_
;
666 int v_texture_location_
;
667 int a_texture_location_
;
669 int yuv_matrix_location_
;
670 int yuv_adj_location_
;
672 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo
);
675 class FragmentShaderColor
{
677 FragmentShaderColor();
678 std::string
GetShaderString(
679 TexCoordPrecision precision
, SamplerType sampler
) const;
681 void Init(gpu::gles2::GLES2Interface
* context
,
683 int* base_uniform_index
);
684 int color_location() const { return color_location_
; }
689 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor
);
692 class FragmentShaderColorAA
{
694 FragmentShaderColorAA();
695 std::string
GetShaderString(
696 TexCoordPrecision precision
, SamplerType sampler
) const;
698 void Init(gpu::gles2::GLES2Interface
* context
,
700 int* base_uniform_index
);
701 int color_location() const { return color_location_
; }
706 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA
);
709 class FragmentShaderCheckerboard
{
711 FragmentShaderCheckerboard();
712 std::string
GetShaderString(
713 TexCoordPrecision precision
, SamplerType sampler
) const;
715 void Init(gpu::gles2::GLES2Interface
* context
,
717 int* base_uniform_index
);
718 int alpha_location() const { return alpha_location_
; }
719 int tex_transform_location() const { return tex_transform_location_
; }
720 int frequency_location() const { return frequency_location_
; }
721 int color_location() const { return color_location_
; }
725 int tex_transform_location_
;
726 int frequency_location_
;
729 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard
);
734 #endif // CC_OUTPUT_SHADER_H_