| 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 ProgramBinding_h | 5 #ifndef ProgramBinding_h |
| 6 #define ProgramBinding_h | 6 #define ProgramBinding_h |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" |
| 11 |
| 10 namespace WebKit { | 12 namespace WebKit { |
| 11 class WebGraphicsContext3D; | 13 class WebGraphicsContext3D; |
| 12 } | 14 } |
| 13 | 15 |
| 14 namespace cc { | 16 namespace cc { |
| 15 | 17 |
| 16 class ProgramBindingBase { | 18 class ProgramBindingBase { |
| 17 public: | 19 public: |
| 18 ProgramBindingBase(); | 20 ProgramBindingBase(); |
| 19 ~ProgramBindingBase(); | 21 ~ProgramBindingBase(); |
| 20 | 22 |
| 21 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); |
| 22 void link(WebKit::WebGraphicsContext3D*); | 24 void link(WebKit::WebGraphicsContext3D*); |
| 23 void cleanup(WebKit::WebGraphicsContext3D*); | 25 void cleanup(WebKit::WebGraphicsContext3D*); |
| 24 | 26 |
| 25 unsigned program() const { ASSERT(m_initialized); return m_program; } | 27 unsigned program() const { DCHECK(m_initialized); return m_program; } |
| 26 bool initialized() const { return m_initialized; } | 28 bool initialized() const { return m_initialized; } |
| 27 | 29 |
| 28 protected: | 30 protected: |
| 29 | 31 |
| 30 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std:
:string& shaderSource); | 32 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std:
:string& shaderSource); |
| 31 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexS
hader, unsigned fragmentShader); | 33 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexS
hader, unsigned fragmentShader); |
| 32 void cleanupShaders(WebKit::WebGraphicsContext3D*); | 34 void cleanupShaders(WebKit::WebGraphicsContext3D*); |
| 33 | 35 |
| 34 unsigned m_program; | 36 unsigned m_program; |
| 35 unsigned m_vertexShaderId; | 37 unsigned m_vertexShaderId; |
| 36 unsigned m_fragmentShaderId; | 38 unsigned m_fragmentShaderId; |
| 37 bool m_initialized; | 39 bool m_initialized; |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 template<class VertexShader, class FragmentShader> | 42 template<class VertexShader, class FragmentShader> |
| 41 class ProgramBinding : public ProgramBindingBase { | 43 class ProgramBinding : public ProgramBindingBase { |
| 42 public: | 44 public: |
| 43 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context) | 45 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context) |
| 44 { | 46 { |
| 45 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fr
agmentShader.getShaderString()); | 47 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fr
agmentShader.getShaderString()); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform
) | 50 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform
) |
| 49 { | 51 { |
| 50 ASSERT(context); | 52 DCHECK(context); |
| 51 ASSERT(m_program); | 53 DCHECK(m_program); |
| 52 ASSERT(!m_initialized); | 54 DCHECK(!m_initialized); |
| 53 | 55 |
| 54 // Need to bind uniforms before linking | 56 // Need to bind uniforms before linking |
| 55 if (!usingBindUniform) | 57 if (!usingBindUniform) |
| 56 link(context); | 58 link(context); |
| 57 | 59 |
| 58 int baseUniformIndex = 0; | 60 int baseUniformIndex = 0; |
| 59 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIn
dex); | 61 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIn
dex); |
| 60 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniform
Index); | 62 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniform
Index); |
| 61 | 63 |
| 62 // Link after binding uniforms | 64 // Link after binding uniforms |
| 63 if (usingBindUniform) | 65 if (usingBindUniform) |
| 64 link(context); | 66 link(context); |
| 65 | 67 |
| 66 m_initialized = true; | 68 m_initialized = true; |
| 67 } | 69 } |
| 68 | 70 |
| 69 const VertexShader& vertexShader() const { return m_vertexShader; } | 71 const VertexShader& vertexShader() const { return m_vertexShader; } |
| 70 const FragmentShader& fragmentShader() const { return m_fragmentShader; } | 72 const FragmentShader& fragmentShader() const { return m_fragmentShader; } |
| 71 | 73 |
| 72 private: | 74 private: |
| 73 | 75 |
| 74 VertexShader m_vertexShader; | 76 VertexShader m_vertexShader; |
| 75 FragmentShader m_fragmentShader; | 77 FragmentShader m_fragmentShader; |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 } // namespace cc | 80 } // namespace cc |
| 79 | 81 |
| 80 #endif | 82 #endif |
| OLD | NEW |