OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_PROGRAM_BINDING_H_ | 5 #ifndef CC_PROGRAM_BINDING_H_ |
6 #define CC_PROGRAM_BINDING_H_ | 6 #define CC_PROGRAM_BINDING_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 | 11 |
12 namespace WebKit { | 12 namespace WebKit { |
13 class WebGraphicsContext3D; | 13 class WebGraphicsContext3D; |
14 } | 14 } |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 class ProgramBindingBase { | 18 class ProgramBindingBase { |
19 public: | 19 public: |
20 ProgramBindingBase(); | 20 ProgramBindingBase(); |
21 ~ProgramBindingBase(); | 21 ~ProgramBindingBase(); |
22 | 22 |
23 void init(WebKit::WebGraphicsContext3D*, const std::string& vertexShader, co nst std::string& fragmentShader); | 23 void init(WebKit::WebGraphicsContext3D*, const std::string& vertexShader, co nst std::string& fragmentShader); |
24 void link(WebKit::WebGraphicsContext3D*); | 24 void link(WebKit::WebGraphicsContext3D*); |
25 void cleanup(WebKit::WebGraphicsContext3D*); | 25 void cleanup(WebKit::WebGraphicsContext3D*); |
26 | 26 |
27 unsigned program() const { DCHECK(m_initialized); return m_program; } | 27 unsigned program() const { return m_program; } |
28 bool initialized() const { return m_initialized; } | 28 bool initialized() const { return m_initialized; } |
29 | 29 |
30 protected: | 30 protected: |
31 | 31 |
32 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std: :string& shaderSource); | 32 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std: :string& shaderSource); |
33 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexS hader, unsigned fragmentShader); | 33 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexS hader, unsigned fragmentShader); |
34 void cleanupShaders(WebKit::WebGraphicsContext3D*); | 34 void cleanupShaders(WebKit::WebGraphicsContext3D*); |
35 bool IsContextLost(WebKit::WebGraphicsContext3D*); | |
35 | 36 |
36 unsigned m_program; | 37 unsigned m_program; |
37 unsigned m_vertexShaderId; | 38 unsigned m_vertexShaderId; |
38 unsigned m_fragmentShaderId; | 39 unsigned m_fragmentShaderId; |
39 bool m_initialized; | 40 bool m_initialized; |
40 }; | 41 }; |
41 | 42 |
42 template<class VertexShader, class FragmentShader> | 43 template<class VertexShader, class FragmentShader> |
43 class ProgramBinding : public ProgramBindingBase { | 44 class ProgramBinding : public ProgramBindingBase { |
44 public: | 45 public: |
45 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context) | 46 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context) |
46 { | 47 { |
47 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fr agmentShader.getShaderString()); | 48 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fr agmentShader.getShaderString()); |
48 } | 49 } |
49 | 50 |
50 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform ) | 51 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform ) |
51 { | 52 { |
52 DCHECK(context); | 53 DCHECK(context); |
53 DCHECK(m_program); | |
54 DCHECK(!m_initialized); | 54 DCHECK(!m_initialized); |
55 | 55 |
56 if (IsContextLost(context)) | |
nduca
2012/11/17 17:02:50
Is this oen needed to sidestep a really hard case
Ken Russell (switch to Gerrit)
2012/11/17 20:23:42
I actually didn't try without it -- seemed best to
| |
57 return; | |
58 | |
56 // Need to bind uniforms before linking | 59 // Need to bind uniforms before linking |
57 if (!usingBindUniform) | 60 if (!usingBindUniform) |
58 link(context); | 61 link(context); |
59 | 62 |
60 int baseUniformIndex = 0; | 63 int baseUniformIndex = 0; |
61 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIn dex); | 64 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIn dex); |
62 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniform Index); | 65 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniform Index); |
63 | 66 |
64 // Link after binding uniforms | 67 // Link after binding uniforms |
65 if (usingBindUniform) | 68 if (usingBindUniform) |
66 link(context); | 69 link(context); |
67 | 70 |
68 m_initialized = true; | 71 m_initialized = true; |
69 } | 72 } |
70 | 73 |
71 const VertexShader& vertexShader() const { return m_vertexShader; } | 74 const VertexShader& vertexShader() const { return m_vertexShader; } |
72 const FragmentShader& fragmentShader() const { return m_fragmentShader; } | 75 const FragmentShader& fragmentShader() const { return m_fragmentShader; } |
73 | 76 |
74 private: | 77 private: |
75 | 78 |
76 VertexShader m_vertexShader; | 79 VertexShader m_vertexShader; |
77 FragmentShader m_fragmentShader; | 80 FragmentShader m_fragmentShader; |
78 }; | 81 }; |
79 | 82 |
80 } // namespace cc | 83 } // namespace cc |
81 | 84 |
82 #endif // CC_PROGRAM_BINDING_H_ | 85 #endif // CC_PROGRAM_BINDING_H_ |
OLD | NEW |