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 "ProgramBinding.h" | 7 #include "ProgramBinding.h" |
8 | 8 |
| 9 #include "third_party/khronos/GLES2/gl2.h" |
9 #include "CCRendererGL.h" // For the GLC() macro. | 10 #include "CCRendererGL.h" // For the GLC() macro. |
10 #include "GeometryBinding.h" | 11 #include "GeometryBinding.h" |
11 #include "GraphicsContext3D.h" | |
12 #include "TraceEvent.h" | 12 #include "TraceEvent.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 ASSERT(!m_program); | 30 ASSERT(!m_program); |
31 ASSERT(!m_vertexShaderId); | 31 ASSERT(!m_vertexShaderId); |
32 ASSERT(!m_fragmentShaderId); | 32 ASSERT(!m_fragmentShaderId); |
33 ASSERT(!m_initialized); | 33 ASSERT(!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 ASSERT(m_program || contextLost(context)); | 62 ASSERT(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 return; | 76 return; |
77 } | 77 } |
78 #endif | 78 #endif |
79 } | 79 } |
80 | 80 |
81 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) | 81 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) |
(...skipping 11 matching lines...) Expand all Loading... |
93 | 93 |
94 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned
type, const std::string& shaderSource) | 94 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned
type, const std::string& shaderSource) |
95 { | 95 { |
96 unsigned shader = context->createShader(type); | 96 unsigned shader = context->createShader(type); |
97 if (!shader) | 97 if (!shader) |
98 return 0; | 98 return 0; |
99 GLC(context, context->shaderSource(shader, shaderSource.data())); | 99 GLC(context, context->shaderSource(shader, shaderSource.data())); |
100 GLC(context, context->compileShader(shader)); | 100 GLC(context, context->compileShader(shader)); |
101 #ifndef NDEBUG | 101 #ifndef NDEBUG |
102 int compiled = 0; | 102 int compiled = 0; |
103 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS,
&compiled)); | 103 GLC(context, context->getShaderiv(shader, GL_COMPILE_STATUS, &compiled)); |
104 if (!compiled) { | 104 if (!compiled) { |
105 GLC(context, context->deleteShader(shader)); | 105 GLC(context, context->deleteShader(shader)); |
106 return 0; | 106 return 0; |
107 } | 107 } |
108 #endif | 108 #endif |
109 return shader; | 109 return shader; |
110 } | 110 } |
111 | 111 |
112 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context,
unsigned vertexShader, unsigned fragmentShader) | 112 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context,
unsigned vertexShader, unsigned fragmentShader) |
113 { | 113 { |
(...skipping 20 matching lines...) Expand all Loading... |
134 GLC(context, context->deleteShader(m_vertexShaderId)); | 134 GLC(context, context->deleteShader(m_vertexShaderId)); |
135 m_vertexShaderId = 0; | 135 m_vertexShaderId = 0; |
136 } | 136 } |
137 if (m_fragmentShaderId) { | 137 if (m_fragmentShaderId) { |
138 GLC(context, context->deleteShader(m_fragmentShaderId)); | 138 GLC(context, context->deleteShader(m_fragmentShaderId)); |
139 m_fragmentShaderId = 0; | 139 m_fragmentShaderId = 0; |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 } // namespace cc | 143 } // namespace cc |
OLD | NEW |