Add Sad Tab resources to the iOS build.
[chromium-blink-merge.git] / cc / program_binding.h
blob5bcf7b998f9d7f5d5d7aee2b4e3ebf09b2387658
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_PROGRAM_BINDING_H_
6 #define CC_PROGRAM_BINDING_H_
8 #include <string>
10 #include "base/logging.h"
12 namespace WebKit {
13 class WebGraphicsContext3D;
16 namespace cc {
18 class ProgramBindingBase {
19 public:
20 ProgramBindingBase();
21 ~ProgramBindingBase();
23 void init(WebKit::WebGraphicsContext3D*, const std::string& vertexShader, const std::string& fragmentShader);
24 void link(WebKit::WebGraphicsContext3D*);
25 void cleanup(WebKit::WebGraphicsContext3D*);
27 unsigned program() const { DCHECK(m_initialized); return m_program; }
28 bool initialized() const { return m_initialized; }
30 protected:
32 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std::string& shaderSource);
33 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexShader, unsigned fragmentShader);
34 void cleanupShaders(WebKit::WebGraphicsContext3D*);
36 unsigned m_program;
37 unsigned m_vertexShaderId;
38 unsigned m_fragmentShaderId;
39 bool m_initialized;
42 template<class VertexShader, class FragmentShader>
43 class ProgramBinding : public ProgramBindingBase {
44 public:
45 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context)
47 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fragmentShader.getShaderString());
50 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform)
52 DCHECK(context);
53 DCHECK(m_program);
54 DCHECK(!m_initialized);
56 // Need to bind uniforms before linking
57 if (!usingBindUniform)
58 link(context);
60 int baseUniformIndex = 0;
61 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIndex);
62 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniformIndex);
64 // Link after binding uniforms
65 if (usingBindUniform)
66 link(context);
68 m_initialized = true;
71 const VertexShader& vertexShader() const { return m_vertexShader; }
72 const FragmentShader& fragmentShader() const { return m_fragmentShader; }
74 private:
76 VertexShader m_vertexShader;
77 FragmentShader m_fragmentShader;
80 } // namespace cc
82 #endif // CC_PROGRAM_BINDING_H_