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_PROGRAM_BINDING_H_
6 #define CC_OUTPUT_PROGRAM_BINDING_H_
10 #include "base/logging.h"
11 #include "cc/output/context_provider.h"
12 #include "cc/output/shader.h"
22 class ProgramBindingBase
{
25 ~ProgramBindingBase();
27 bool Init(gpu::gles2::GLES2Interface
* context
,
28 const std::string
& vertex_shader
,
29 const std::string
& fragment_shader
);
30 bool Link(gpu::gles2::GLES2Interface
* context
);
31 void Cleanup(gpu::gles2::GLES2Interface
* context
);
33 unsigned program() const { return program_
; }
34 bool initialized() const { return initialized_
; }
37 unsigned LoadShader(gpu::gles2::GLES2Interface
* context
,
39 const std::string
& shader_source
);
40 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface
* context
,
41 unsigned vertex_shader
,
42 unsigned fragment_shader
);
43 void CleanupShaders(gpu::gles2::GLES2Interface
* context
);
46 unsigned vertex_shader_id_
;
47 unsigned fragment_shader_id_
;
51 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase
);
54 template <class VertexShader
, class FragmentShader
>
55 class ProgramBinding
: public ProgramBindingBase
{
59 void Initialize(ContextProvider
* context_provider
,
60 TexCoordPrecision precision
,
61 SamplerType sampler
) {
62 DCHECK(context_provider
);
63 DCHECK(!initialized_
);
65 if (context_provider
->IsContextLost())
68 if (!ProgramBindingBase::Init(
69 context_provider
->ContextGL(),
70 vertex_shader_
.GetShaderString(),
71 fragment_shader_
.GetShaderString(precision
, sampler
))) {
72 DCHECK(context_provider
->IsContextLost());
76 int base_uniform_index
= 0;
77 vertex_shader_
.Init(context_provider
->ContextGL(),
78 program_
, &base_uniform_index
);
79 fragment_shader_
.Init(context_provider
->ContextGL(),
80 program_
, &base_uniform_index
);
82 // Link after binding uniforms
83 if (!Link(context_provider
->ContextGL())) {
84 DCHECK(context_provider
->IsContextLost());
91 const VertexShader
& vertex_shader() const { return vertex_shader_
; }
92 const FragmentShader
& fragment_shader() const { return fragment_shader_
; }
95 VertexShader vertex_shader_
;
96 FragmentShader fragment_shader_
;
98 DISALLOW_COPY_AND_ASSIGN(ProgramBinding
);
103 #endif // CC_OUTPUT_PROGRAM_BINDING_H_