cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / output / program_binding.h
blobee9d284fa7ff12a4c228f3a200c4bfbb19e8c314
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_
8 #include <string>
10 #include "base/logging.h"
11 #include "cc/output/shader.h"
13 namespace WebKit { class WebGraphicsContext3D; }
15 namespace cc {
17 class ProgramBindingBase {
18 public:
19 ProgramBindingBase();
20 ~ProgramBindingBase();
22 void Init(WebKit::WebGraphicsContext3D* context,
23 const std::string& vertex_shader,
24 const std::string& fragment_shader);
25 void Link(WebKit::WebGraphicsContext3D* context);
26 void Cleanup(WebKit::WebGraphicsContext3D* context);
28 unsigned program() const { return program_; }
29 bool initialized() const { return initialized_; }
31 protected:
32 unsigned LoadShader(WebKit::WebGraphicsContext3D* context,
33 unsigned type,
34 const std::string& shader_source);
35 unsigned CreateShaderProgram(WebKit::WebGraphicsContext3D* context,
36 unsigned vertex_shader,
37 unsigned fragment_shader);
38 void CleanupShaders(WebKit::WebGraphicsContext3D* context);
39 bool IsContextLost(WebKit::WebGraphicsContext3D* context);
41 unsigned program_;
42 unsigned vertex_shader_id_;
43 unsigned fragment_shader_id_;
44 bool initialized_;
46 private:
47 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase);
50 template <class VertexShader, class FragmentShader>
51 class ProgramBinding : public ProgramBindingBase {
52 public:
53 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context,
54 TexCoordPrecision precision) {
55 ProgramBindingBase::Init(
56 context,
57 vertex_shader_.GetShaderString(),
58 fragment_shader_.GetShaderString(precision));
61 void Initialize(WebKit::WebGraphicsContext3D* context,
62 bool using_bind_uniform) {
63 DCHECK(context);
64 DCHECK(!initialized_);
66 if (IsContextLost(context))
67 return;
69 // Need to bind uniforms before linking
70 if (!using_bind_uniform)
71 Link(context);
73 int base_uniform_index = 0;
74 vertex_shader_.Init(
75 context, program_, using_bind_uniform, &base_uniform_index);
76 fragment_shader_.Init(
77 context, program_, using_bind_uniform, &base_uniform_index);
79 // Link after binding uniforms
80 if (using_bind_uniform)
81 Link(context);
83 initialized_ = true;
86 const VertexShader& vertex_shader() const { return vertex_shader_; }
87 const FragmentShader& fragment_shader() const { return fragment_shader_; }
89 private:
90 VertexShader vertex_shader_;
91 FragmentShader fragment_shader_;
93 DISALLOW_COPY_AND_ASSIGN(ProgramBinding);
96 } // namespace cc
98 #endif // CC_OUTPUT_PROGRAM_BINDING_H_