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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLDrawBuffers.cpp

Issue 2711783003: Move the WebGL DrawBuffers support check to the command buffer service. (Closed)
Patch Set: Fix typo Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLDrawBuffers.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 27 matching lines...) Expand all
38 WebGLExtensionName WebGLDrawBuffers::name() const { 38 WebGLExtensionName WebGLDrawBuffers::name() const {
39 return WebGLDrawBuffersName; 39 return WebGLDrawBuffersName;
40 } 40 }
41 41
42 WebGLDrawBuffers* WebGLDrawBuffers::create(WebGLRenderingContextBase* context) { 42 WebGLDrawBuffers* WebGLDrawBuffers::create(WebGLRenderingContextBase* context) {
43 return new WebGLDrawBuffers(context); 43 return new WebGLDrawBuffers(context);
44 } 44 }
45 45
46 // static 46 // static
47 bool WebGLDrawBuffers::supported(WebGLRenderingContextBase* context) { 47 bool WebGLDrawBuffers::supported(WebGLRenderingContextBase* context) {
48 return (context->extensionsUtil()->supportsExtension("GL_EXT_draw_buffers") && 48 return context->extensionsUtil()->supportsExtension("GL_EXT_draw_buffers");
49 satisfiesWebGLRequirements(context));
50 } 49 }
51 50
52 // static 51 // static
53 const char* WebGLDrawBuffers::extensionName() { 52 const char* WebGLDrawBuffers::extensionName() {
54 return "WEBGL_draw_buffers"; 53 return "WEBGL_draw_buffers";
55 } 54 }
56 55
57 void WebGLDrawBuffers::drawBuffersWEBGL(const Vector<GLenum>& buffers) { 56 void WebGLDrawBuffers::drawBuffersWEBGL(const Vector<GLenum>& buffers) {
58 WebGLExtensionScopedContext scoped(this); 57 WebGLExtensionScopedContext scoped(this);
59 if (scoped.isLost()) 58 if (scoped.isLost())
(...skipping 29 matching lines...) Expand all
89 scoped.context()->synthesizeGLError(GL_INVALID_OPERATION, 88 scoped.context()->synthesizeGLError(GL_INVALID_OPERATION,
90 "drawBuffersWEBGL", 89 "drawBuffersWEBGL",
91 "COLOR_ATTACHMENTi_EXT or NONE"); 90 "COLOR_ATTACHMENTi_EXT or NONE");
92 return; 91 return;
93 } 92 }
94 } 93 }
95 scoped.context()->m_framebufferBinding->drawBuffers(buffers); 94 scoped.context()->m_framebufferBinding->drawBuffers(buffers);
96 } 95 }
97 } 96 }
98 97
99 // static
100 bool WebGLDrawBuffers::satisfiesWebGLRequirements(
101 WebGLRenderingContextBase* webglContext) {
102 gpu::gles2::GLES2Interface* gl = webglContext->contextGL();
103 Extensions3DUtil* extensionsUtil = webglContext->extensionsUtil();
104
105 // This is called after we make sure GL_EXT_draw_buffers is supported.
106 GLint maxDrawBuffers = 0;
107 GLint maxColorAttachments = 0;
108 gl->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers);
109 gl->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments);
110 if (maxDrawBuffers < 4 || maxColorAttachments < 4)
111 return false;
112
113 GLuint fbo;
114 gl->GenFramebuffers(1, &fbo);
115 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo);
116
117 const unsigned char* buffer =
118 0; // Chromium doesn't allow init data for depth/stencil tetxures.
119 bool supportsDepth =
120 (extensionsUtil->supportsExtension("GL_CHROMIUM_depth_texture") ||
121 extensionsUtil->supportsExtension("GL_OES_depth_texture") ||
122 extensionsUtil->supportsExtension("GL_ARB_depth_texture"));
123 bool supportsDepthStencil =
124 (extensionsUtil->supportsExtension("GL_EXT_packed_depth_stencil") ||
125 extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil"));
126 GLuint depthStencil = 0;
127 if (supportsDepthStencil) {
128 gl->GenTextures(1, &depthStencil);
129 gl->BindTexture(GL_TEXTURE_2D, depthStencil);
130 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, 1, 1, 0,
131 GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, buffer);
132 }
133 GLuint depth = 0;
134 if (supportsDepth) {
135 gl->GenTextures(1, &depth);
136 gl->BindTexture(GL_TEXTURE_2D, depth);
137 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0,
138 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, buffer);
139 }
140
141 Vector<GLuint> colors;
142 bool ok = true;
143 GLint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments);
144 for (GLint i = 0; i < maxAllowedBuffers; ++i) {
145 GLuint color;
146
147 gl->GenTextures(1, &color);
148 colors.push_back(color);
149 gl->BindTexture(GL_TEXTURE_2D, color);
150 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
151 GL_UNSIGNED_BYTE, buffer);
152 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
153 GL_TEXTURE_2D, color, 0);
154 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
155 ok = false;
156 break;
157 }
158 if (supportsDepth) {
159 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
160 GL_TEXTURE_2D, depth, 0);
161 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) !=
162 GL_FRAMEBUFFER_COMPLETE) {
163 ok = false;
164 break;
165 }
166 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
167 GL_TEXTURE_2D, 0, 0);
168 }
169 if (supportsDepthStencil) {
170 // For ES 2.0 contexts DEPTH_STENCIL is not available natively, so we
171 // emulate it at the command buffer level for WebGL contexts.
172 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
173 GL_TEXTURE_2D, depthStencil, 0);
174 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) !=
175 GL_FRAMEBUFFER_COMPLETE) {
176 ok = false;
177 break;
178 }
179 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
180 GL_TEXTURE_2D, 0, 0);
181 }
182 }
183
184 webglContext->restoreCurrentFramebuffer();
185 gl->DeleteFramebuffers(1, &fbo);
186 webglContext->restoreCurrentTexture2D();
187 if (supportsDepth)
188 gl->DeleteTextures(1, &depth);
189 if (supportsDepthStencil)
190 gl->DeleteTextures(1, &depthStencil);
191 gl->DeleteTextures(colors.size(), colors.data());
192
193 return ok;
194 }
195
196 } // namespace blink 98 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLDrawBuffers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698