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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/program_binding.h" | 7 #include "cc/program_binding.h" |
8 | 8 |
9 #include "CCRendererGL.h" // For the GLC() macro. | 9 #include "CCRendererGL.h" // For the GLC() macro. |
10 #include "GraphicsContext3D.h" | |
11 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
12 #include "cc/geometry_binding.h" | 11 #include "cc/geometry_binding.h" |
| 12 #include "third_party/khronos/GLES2/gl2.h" |
13 #include <public/WebGraphicsContext3D.h> | 13 #include <public/WebGraphicsContext3D.h> |
14 | 14 |
15 using WebKit::WebGraphicsContext3D; | 15 using WebKit::WebGraphicsContext3D; |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 ProgramBindingBase::ProgramBindingBase() | 19 ProgramBindingBase::ProgramBindingBase() |
20 : m_program(0) | 20 : m_program(0) |
21 , m_vertexShaderId(0) | 21 , m_vertexShaderId(0) |
22 , m_fragmentShaderId(0) | 22 , m_fragmentShaderId(0) |
23 , m_initialized(false) | 23 , m_initialized(false) |
24 { | 24 { |
25 } | 25 } |
26 | 26 |
27 ProgramBindingBase::~ProgramBindingBase() | 27 ProgramBindingBase::~ProgramBindingBase() |
28 { | 28 { |
29 // If you hit these asserts, you initialized but forgot to call cleanup(). | 29 // If you hit these asserts, you initialized but forgot to call cleanup(). |
30 DCHECK(!m_program); | 30 DCHECK(!m_program); |
31 DCHECK(!m_vertexShaderId); | 31 DCHECK(!m_vertexShaderId); |
32 DCHECK(!m_fragmentShaderId); | 32 DCHECK(!m_fragmentShaderId); |
33 DCHECK(!m_initialized); | 33 DCHECK(!m_initialized); |
34 } | 34 } |
35 | 35 |
36 static bool contextLost(WebGraphicsContext3D* context) | 36 static bool contextLost(WebGraphicsContext3D* context) |
37 { | 37 { |
38 return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR)
; | 38 return (context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 void ProgramBindingBase::init(WebGraphicsContext3D* context, const std::string&
vertexShader, const std::string& fragmentShader) | 42 void ProgramBindingBase::init(WebGraphicsContext3D* context, const std::string&
vertexShader, const std::string& fragmentShader) |
43 { | 43 { |
44 TRACE_EVENT0("cc", "ProgramBindingBase::init"); | 44 TRACE_EVENT0("cc", "ProgramBindingBase::init"); |
45 m_vertexShaderId = loadShader(context, GraphicsContext3D::VERTEX_SHADER, ver
texShader); | 45 m_vertexShaderId = loadShader(context, GL_VERTEX_SHADER, vertexShader); |
46 if (!m_vertexShaderId) { | 46 if (!m_vertexShaderId) { |
47 if (!contextLost(context)) | 47 if (!contextLost(context)) |
48 LOG(ERROR) << "Failed to create vertex shader"; | 48 LOG(ERROR) << "Failed to create vertex shader"; |
49 return; | 49 return; |
50 } | 50 } |
51 | 51 |
52 m_fragmentShaderId = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER,
fragmentShader); | 52 m_fragmentShaderId = loadShader(context, GL_FRAGMENT_SHADER, fragmentShader)
; |
53 if (!m_fragmentShaderId) { | 53 if (!m_fragmentShaderId) { |
54 GLC(context, context->deleteShader(m_vertexShaderId)); | 54 GLC(context, context->deleteShader(m_vertexShaderId)); |
55 m_vertexShaderId = 0; | 55 m_vertexShaderId = 0; |
56 if (!contextLost(context)) | 56 if (!contextLost(context)) |
57 LOG(ERROR) << "Failed to create fragment shader"; | 57 LOG(ERROR) << "Failed to create fragment shader"; |
58 return; | 58 return; |
59 } | 59 } |
60 | 60 |
61 m_program = createShaderProgram(context, m_vertexShaderId, m_fragmentShaderI
d); | 61 m_program = createShaderProgram(context, m_vertexShaderId, m_fragmentShaderI
d); |
62 DCHECK(m_program || contextLost(context)); | 62 DCHECK(m_program || contextLost(context)); |
63 } | 63 } |
64 | 64 |
65 void ProgramBindingBase::link(WebGraphicsContext3D* context) | 65 void ProgramBindingBase::link(WebGraphicsContext3D* context) |
66 { | 66 { |
67 GLC(context, context->linkProgram(m_program)); | 67 GLC(context, context->linkProgram(m_program)); |
68 cleanupShaders(context); | 68 cleanupShaders(context); |
69 #ifndef NDEBUG | 69 #ifndef NDEBUG |
70 int linked = 0; | 70 int linked = 0; |
71 GLC(context, context->getProgramiv(m_program, GraphicsContext3D::LINK_STATUS
, &linked)); | 71 GLC(context, context->getProgramiv(m_program, GL_LINK_STATUS, &linked)); |
72 if (!linked) { | 72 if (!linked) { |
73 if (!contextLost(context)) | 73 if (!contextLost(context)) |
74 LOG(ERROR) << "Failed to link shader program"; | 74 LOG(ERROR) << "Failed to link shader program"; |
75 GLC(context, context->deleteProgram(m_program)); | 75 GLC(context, context->deleteProgram(m_program)); |
76 } | 76 } |
77 #endif | 77 #endif |
78 } | 78 } |
79 | 79 |
80 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) | 80 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) |
81 { | 81 { |
(...skipping 10 matching lines...) Expand all Loading... |
92 | 92 |
93 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned
type, const std::string& shaderSource) | 93 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned
type, const std::string& shaderSource) |
94 { | 94 { |
95 unsigned shader = context->createShader(type); | 95 unsigned shader = context->createShader(type); |
96 if (!shader) | 96 if (!shader) |
97 return 0; | 97 return 0; |
98 GLC(context, context->shaderSource(shader, shaderSource.data())); | 98 GLC(context, context->shaderSource(shader, shaderSource.data())); |
99 GLC(context, context->compileShader(shader)); | 99 GLC(context, context->compileShader(shader)); |
100 #ifndef NDEBUG | 100 #ifndef NDEBUG |
101 int compiled = 0; | 101 int compiled = 0; |
102 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS,
&compiled)); | 102 GLC(context, context->getShaderiv(shader, GL_COMPILE_STATUS, &compiled)); |
103 if (!compiled) { | 103 if (!compiled) { |
104 GLC(context, context->deleteShader(shader)); | 104 GLC(context, context->deleteShader(shader)); |
105 return 0; | 105 return 0; |
106 } | 106 } |
107 #endif | 107 #endif |
108 return shader; | 108 return shader; |
109 } | 109 } |
110 | 110 |
111 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context,
unsigned vertexShader, unsigned fragmentShader) | 111 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context,
unsigned vertexShader, unsigned fragmentShader) |
112 { | 112 { |
(...skipping 20 matching lines...) Expand all Loading... |
133 GLC(context, context->deleteShader(m_vertexShaderId)); | 133 GLC(context, context->deleteShader(m_vertexShaderId)); |
134 m_vertexShaderId = 0; | 134 m_vertexShaderId = 0; |
135 } | 135 } |
136 if (m_fragmentShaderId) { | 136 if (m_fragmentShaderId) { |
137 GLC(context, context->deleteShader(m_fragmentShaderId)); | 137 GLC(context, context->deleteShader(m_fragmentShaderId)); |
138 m_fragmentShaderId = 0; | 138 m_fragmentShaderId = 0; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 } // namespace cc | 142 } // namespace cc |
OLD | NEW |