Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Side by Side Diff: Source/core/html/canvas/WebGLProgram.cpp

Issue 17230006: Implement WEBGL_shared_resources Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (m_vertexShader) { 57 if (m_vertexShader) {
58 m_vertexShader->onDetached(context3d); 58 m_vertexShader->onDetached(context3d);
59 m_vertexShader = 0; 59 m_vertexShader = 0;
60 } 60 }
61 if (m_fragmentShader) { 61 if (m_fragmentShader) {
62 m_fragmentShader->onDetached(context3d); 62 m_fragmentShader->onDetached(context3d);
63 m_fragmentShader = 0; 63 m_fragmentShader = 0;
64 } 64 }
65 } 65 }
66 66
67 unsigned WebGLProgram::numActiveAttribLocations() 67 unsigned WebGLProgram::numActiveAttribLocations(WebGLRenderingContext* context)
68 { 68 {
69 cacheInfoIfNeeded(); 69 cacheInfoIfNeeded(context);
70 return m_activeAttribLocations.size(); 70 return m_activeAttribLocations.size();
71 } 71 }
72 72
73 GC3Dint WebGLProgram::getActiveAttribLocation(GC3Duint index) 73 GC3Dint WebGLProgram::getActiveAttribLocation(WebGLRenderingContext* context, GC 3Duint index)
74 { 74 {
75 cacheInfoIfNeeded(); 75 cacheInfoIfNeeded(context);
76 if (index >= numActiveAttribLocations()) 76 if (index >= numActiveAttribLocations(context))
77 return -1; 77 return -1;
78 return m_activeAttribLocations[index]; 78 return m_activeAttribLocations[index];
79 } 79 }
80 80
81 bool WebGLProgram::isUsingVertexAttrib0() 81 bool WebGLProgram::isUsingVertexAttrib0(WebGLRenderingContext* context)
82 { 82 {
83 cacheInfoIfNeeded(); 83 cacheInfoIfNeeded(context);
84 for (unsigned ii = 0; ii < numActiveAttribLocations(); ++ii) { 84 unsigned numLocations = numActiveAttribLocations(context);
85 if (!getActiveAttribLocation(ii)) 85 for (unsigned ii = 0; ii < numLocations; ++ii) {
86 if (!getActiveAttribLocation(context, ii))
86 return true; 87 return true;
87 } 88 }
88 return false; 89 return false;
89 } 90 }
90 91
91 bool WebGLProgram::getLinkStatus() 92 bool WebGLProgram::getLinkStatus(WebGLRenderingContext* context)
92 { 93 {
93 cacheInfoIfNeeded(); 94 cacheInfoIfNeeded(context);
94 return m_linkStatus; 95 return m_linkStatus;
95 } 96 }
96 97
97 void WebGLProgram::setLinkStatus(bool status) 98 void WebGLProgram::setLinkStatus(WebGLRenderingContext* context, bool status)
98 { 99 {
99 cacheInfoIfNeeded(); 100 cacheInfoIfNeeded(context);
100 m_linkStatus = status; 101 m_linkStatus = status;
101 } 102 }
102 103
103 void WebGLProgram::increaseLinkCount() 104 void WebGLProgram::increaseLinkCount()
104 { 105 {
105 ++m_linkCount; 106 ++m_linkCount;
106 m_infoValid = false; 107 m_infoValid = false;
107 } 108 }
108 109
109 WebGLShader* WebGLProgram::getAttachedShader(GC3Denum type) 110 WebGLShader* WebGLProgram::getAttachedShader(GC3Denum type)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 GC3Dint numAttribs = 0; 166 GC3Dint numAttribs = 0;
166 context3d->getProgramiv(object(), GraphicsContext3D::ACTIVE_ATTRIBUTES, &num Attribs); 167 context3d->getProgramiv(object(), GraphicsContext3D::ACTIVE_ATTRIBUTES, &num Attribs);
167 m_activeAttribLocations.resize(static_cast<size_t>(numAttribs)); 168 m_activeAttribLocations.resize(static_cast<size_t>(numAttribs));
168 for (int i = 0; i < numAttribs; ++i) { 169 for (int i = 0; i < numAttribs; ++i) {
169 ActiveInfo info; 170 ActiveInfo info;
170 context3d->getActiveAttrib(object(), i, info); 171 context3d->getActiveAttrib(object(), i, info);
171 m_activeAttribLocations[i] = context3d->getAttribLocation(object(), info .name.charactersWithNullTermination()); 172 m_activeAttribLocations[i] = context3d->getAttribLocation(object(), info .name.charactersWithNullTermination());
172 } 173 }
173 } 174 }
174 175
175 void WebGLProgram::cacheInfoIfNeeded() 176 void WebGLProgram::cacheSamplerLocations(GraphicsContext3D* context3d)
177 {
178 m_samplerLocationToTextureUnit.clear();
179
180 GC3Dint numUniforms = 0;
181 context3d->getProgramiv(object(), GraphicsContext3D::ACTIVE_UNIFORMS, &numUn iforms);
182 for (int i = 0; i < numUniforms; ++i) {
183 ActiveInfo info;
184 context3d->getActiveUniform(object(), i, info);
185 if (info.type != GraphicsContext3D::SAMPLER_2D && info.type != GraphicsC ontext3D::SAMPLER_CUBE) {
186 continue;
187 }
188 GC3Dint location = context3d->getUniformLocation(object(), info.name.cha ractersWithNullTermination());
189 for (int j = 0; location >= 0 && j < info.size; ++j) {
Ken Russell (switch to Gerrit) 2013/06/19 03:51:24 This inner loop is tricky to understand. Can you a
greggman 2013/06/21 19:54:21 Done.
190 GC3Dint nextLocation = -1;
191 if (j < info.size - 1) {
192 String elementName(info.name + "[" + String::number(j + 1) + "]" );
193 nextLocation = context3d->getUniformLocation(object(), elementNa me.charactersWithNullTermination());
194 }
195 // Add one because HashMap can't store 0
196 m_samplerLocationToTextureUnit.add(location + 1, SamplerInfo(info.ty pe, nextLocation));
197 location = nextLocation;
198 }
199 }
200 }
201
202 void WebGLProgram::cacheInfoIfNeeded(WebGLRenderingContext* context)
176 { 203 {
177 if (m_infoValid) 204 if (m_infoValid)
178 return; 205 return;
179 206
180 if (!object()) 207 if (!object())
181 return; 208 return;
182 209
183 GraphicsContext3D* context = getAGraphicsContext3D(); 210 GraphicsContext3D* gc3d = context->graphicsContext3D();
184 if (!context) 211 if (!context)
185 return; 212 return;
186 GC3Dint linkStatus = 0; 213 GC3Dint linkStatus = 0;
187 context->getProgramiv(object(), GraphicsContext3D::LINK_STATUS, &linkStatus) ; 214 gc3d->getProgramiv(object(), GraphicsContext3D::LINK_STATUS, &linkStatus);
188 m_linkStatus = linkStatus; 215 m_linkStatus = linkStatus;
189 if (m_linkStatus) 216 if (m_linkStatus) {
190 cacheActiveAttribLocations(context); 217 cacheActiveAttribLocations(gc3d);
218 cacheSamplerLocations(gc3d);
219 }
191 m_infoValid = true; 220 m_infoValid = true;
192 } 221 }
193 222
223 void WebGLProgram::setSampler(WebGLRenderingContext* context, GC3Dint location, GC3Dsizei size, const GC3Dint* v)
224 {
225 cacheInfoIfNeeded(context);
226
227 for (; location >= 0 && size > 0; --size) {
228 // Add one because HashMap can't store 0.
229 SamplerTextureUnitMap::iterator it = m_samplerLocationToTextureUnit.find (location + 1);
230 if (it == m_samplerLocationToTextureUnit.end()) {
231 return;
232 }
233 it->value.unit = *v++;
234 location = it->value.nextLocation;
Ken Russell (switch to Gerrit) 2013/06/19 03:51:24 This chaining together of the locations of uniform
greggman 2013/06/21 19:54:21 added a comment. Or are you suggesting I should us
235 }
194 } 236 }
237
238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698