OLD | NEW |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 void WebGLDrawBuffers::drawBuffersWEBGL(const Vector<GC3Denum>& buffers) | 68 void WebGLDrawBuffers::drawBuffersWEBGL(const Vector<GC3Denum>& buffers) |
69 { | 69 { |
70 if (isLost()) | 70 if (isLost()) |
71 return; | 71 return; |
72 GC3Dsizei n = buffers.size(); | 72 GC3Dsizei n = buffers.size(); |
73 const GC3Denum* bufs = buffers.data(); | 73 const GC3Denum* bufs = buffers.data(); |
74 if (!m_context->m_framebufferBinding) { | 74 if (!m_context->m_framebufferBinding) { |
75 if (n != 1) { | 75 if (n != 1) { |
76 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "draw
BuffersWEBGL", "more than one buffer"); | 76 m_context->synthesizeGLError(GL_INVALID_VALUE, "drawBuffersWEBGL", "
more than one buffer"); |
77 return; | 77 return; |
78 } | 78 } |
79 if (bufs[0] != GraphicsContext3D::BACK && bufs[0] != GraphicsContext3D::
NONE) { | 79 if (bufs[0] != GL_BACK && bufs[0] != GL_NONE) { |
80 m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "
drawBuffersWEBGL", "BACK or NONE"); | 80 m_context->synthesizeGLError(GL_INVALID_OPERATION, "drawBuffersWEBGL
", "BACK or NONE"); |
81 return; | 81 return; |
82 } | 82 } |
83 // Because the backbuffer is simulated on all current WebKit ports, we n
eed to change BACK to COLOR_ATTACHMENT0. | 83 // Because the backbuffer is simulated on all current WebKit ports, we n
eed to change BACK to COLOR_ATTACHMENT0. |
84 GC3Denum value = (bufs[0] == GraphicsContext3D::BACK) ? GraphicsContext3
D::COLOR_ATTACHMENT0 : GraphicsContext3D::NONE; | 84 GC3Denum value = (bufs[0] == GL_BACK) ? GL_COLOR_ATTACHMENT0 : GL_NONE; |
85 m_context->graphicsContext3D()->extensions()->drawBuffersEXT(1, &value); | 85 m_context->graphicsContext3D()->extensions()->drawBuffersEXT(1, &value); |
86 m_context->setBackDrawBuffer(bufs[0]); | 86 m_context->setBackDrawBuffer(bufs[0]); |
87 } else { | 87 } else { |
88 if (n > m_context->maxDrawBuffers()) { | 88 if (n > m_context->maxDrawBuffers()) { |
89 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "draw
BuffersWEBGL", "more than max draw buffers"); | 89 m_context->synthesizeGLError(GL_INVALID_VALUE, "drawBuffersWEBGL", "
more than max draw buffers"); |
90 return; | 90 return; |
91 } | 91 } |
92 for (GC3Dsizei i = 0; i < n; ++i) { | 92 for (GC3Dsizei i = 0; i < n; ++i) { |
93 if (bufs[i] != GraphicsContext3D::NONE && bufs[i] != static_cast<GC3
Denum>(Extensions3D::COLOR_ATTACHMENT0_EXT + i)) { | 93 if (bufs[i] != GL_NONE && bufs[i] != static_cast<GC3Denum>(Extension
s3D::COLOR_ATTACHMENT0_EXT + i)) { |
94 m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATIO
N, "drawBuffersWEBGL", "COLOR_ATTACHMENTi_EXT or NONE"); | 94 m_context->synthesizeGLError(GL_INVALID_OPERATION, "drawBuffersW
EBGL", "COLOR_ATTACHMENTi_EXT or NONE"); |
95 return; | 95 return; |
96 } | 96 } |
97 } | 97 } |
98 m_context->m_framebufferBinding->drawBuffers(buffers); | 98 m_context->m_framebufferBinding->drawBuffers(buffers); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 // static | 102 // static |
103 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContext* webglCo
ntext) | 103 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContext* webglCo
ntext) |
104 { | 104 { |
105 GraphicsContext3D* context = webglContext->graphicsContext3D(); | 105 GraphicsContext3D* context = webglContext->graphicsContext3D(); |
106 | 106 |
107 // This is called after we make sure GL_EXT_draw_buffers is supported. | 107 // This is called after we make sure GL_EXT_draw_buffers is supported. |
108 GC3Dint maxDrawBuffers = 0; | 108 GC3Dint maxDrawBuffers = 0; |
109 GC3Dint maxColorAttachments = 0; | 109 GC3Dint maxColorAttachments = 0; |
110 context->getIntegerv(Extensions3D::MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); | 110 context->getIntegerv(Extensions3D::MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); |
111 context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttac
hments); | 111 context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttac
hments); |
112 if (maxDrawBuffers < 4 || maxColorAttachments < 4) | 112 if (maxDrawBuffers < 4 || maxColorAttachments < 4) |
113 return false; | 113 return false; |
114 | 114 |
115 Platform3DObject fbo = context->createFramebuffer(); | 115 Platform3DObject fbo = context->createFramebuffer(); |
116 context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, fbo); | 116 context->bindFramebuffer(GL_FRAMEBUFFER, fbo); |
117 | 117 |
118 const unsigned char* buffer = 0; // Chromium doesn't allow init data for dep
th/stencil tetxures. | 118 const unsigned char* buffer = 0; // Chromium doesn't allow init data for dep
th/stencil tetxures. |
119 bool supportsDepth = (context->extensions()->supports("GL_CHROMIUM_depth_tex
ture") | 119 bool supportsDepth = (context->extensions()->supports("GL_CHROMIUM_depth_tex
ture") |
120 || context->extensions()->supports("GL_OES_depth_texture") | 120 || context->extensions()->supports("GL_OES_depth_texture") |
121 || context->extensions()->supports("GL_ARB_depth_texture")); | 121 || context->extensions()->supports("GL_ARB_depth_texture")); |
122 bool supportsDepthStencil = (context->extensions()->supports("GL_EXT_packed_
depth_stencil") | 122 bool supportsDepthStencil = (context->extensions()->supports("GL_EXT_packed_
depth_stencil") |
123 || context->extensions()->supports("GL_OES_packed_depth_stencil")); | 123 || context->extensions()->supports("GL_OES_packed_depth_stencil")); |
124 Platform3DObject depthStencil = 0; | 124 Platform3DObject depthStencil = 0; |
125 if (supportsDepthStencil) { | 125 if (supportsDepthStencil) { |
126 depthStencil = context->createTexture(); | 126 depthStencil = context->createTexture(); |
127 context->bindTexture(GraphicsContext3D::TEXTURE_2D, depthStencil); | 127 context->bindTexture(GL_TEXTURE_2D, depthStencil); |
128 context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D:
:DEPTH_STENCIL, 1, 1, 0, GraphicsContext3D::DEPTH_STENCIL, GraphicsContext3D::UN
SIGNED_INT_24_8, buffer); | 128 context->texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, 1, 1, 0, GL_
DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, buffer); |
129 } | 129 } |
130 Platform3DObject depth = 0; | 130 Platform3DObject depth = 0; |
131 if (supportsDepth) { | 131 if (supportsDepth) { |
132 depth = context->createTexture(); | 132 depth = context->createTexture(); |
133 context->bindTexture(GraphicsContext3D::TEXTURE_2D, depth); | 133 context->bindTexture(GL_TEXTURE_2D, depth); |
134 context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D:
:DEPTH_COMPONENT, 1, 1, 0, GraphicsContext3D::DEPTH_COMPONENT, GraphicsContext3D
::UNSIGNED_INT, buffer); | 134 context->texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DE
PTH_COMPONENT, GL_UNSIGNED_INT, buffer); |
135 } | 135 } |
136 | 136 |
137 Vector<Platform3DObject> colors; | 137 Vector<Platform3DObject> colors; |
138 bool ok = true; | 138 bool ok = true; |
139 GC3Dint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments); | 139 GC3Dint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments); |
140 for (GC3Dint i = 0; i < maxAllowedBuffers; ++i) { | 140 for (GC3Dint i = 0; i < maxAllowedBuffers; ++i) { |
141 Platform3DObject color = context->createTexture(); | 141 Platform3DObject color = context->createTexture(); |
142 colors.append(color); | 142 colors.append(color); |
143 context->bindTexture(GraphicsContext3D::TEXTURE_2D, color); | 143 context->bindTexture(GL_TEXTURE_2D, color); |
144 context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D:
:RGBA, 1, 1, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, buffe
r); | 144 context->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSI
GNED_BYTE, buffer); |
145 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsCo
ntext3D::COLOR_ATTACHMENT0 + i, GraphicsContext3D::TEXTURE_2D, color, 0); | 145 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
GL_TEXTURE_2D, color, 0); |
146 if (context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != G
raphicsContext3D::FRAMEBUFFER_COMPLETE) { | 146 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_CO
MPLETE) { |
147 ok = false; | 147 ok = false; |
148 break; | 148 break; |
149 } | 149 } |
150 if (supportsDepth) { | 150 if (supportsDepth) { |
151 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::TEXTURE_2D, depth, 0); | 151 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, depth, 0); |
152 if (context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER)
!= GraphicsContext3D::FRAMEBUFFER_COMPLETE) { | 152 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { |
153 ok = false; | 153 ok = false; |
154 break; | 154 break; |
155 } | 155 } |
156 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::TEXTURE_2D, 0, 0); | 156 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, 0, 0); |
157 } | 157 } |
158 if (supportsDepthStencil) { | 158 if (supportsDepthStencil) { |
159 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::TEXTURE_2D, depthStencil, 0); | 159 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, depthStencil, 0); |
160 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::TEXTURE_2D, depthStencil, 0)
; | 160 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, depthStencil, 0); |
161 if (context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER)
!= GraphicsContext3D::FRAMEBUFFER_COMPLETE) { | 161 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { |
162 ok = false; | 162 ok = false; |
163 break; | 163 break; |
164 } | 164 } |
165 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::TEXTURE_2D, 0, 0); | 165 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, 0, 0); |
166 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::TEXTURE_2D, 0, 0); | 166 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, 0, 0); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 webglContext->restoreCurrentFramebuffer(); | 170 webglContext->restoreCurrentFramebuffer(); |
171 context->deleteFramebuffer(fbo); | 171 context->deleteFramebuffer(fbo); |
172 webglContext->restoreCurrentTexture2D(); | 172 webglContext->restoreCurrentTexture2D(); |
173 if (supportsDepth) | 173 if (supportsDepth) |
174 context->deleteTexture(depth); | 174 context->deleteTexture(depth); |
175 if (supportsDepthStencil) | 175 if (supportsDepthStencil) |
176 context->deleteTexture(depthStencil); | 176 context->deleteTexture(depthStencil); |
177 for (size_t i = 0; i < colors.size(); ++i) | 177 for (size_t i = 0; i < colors.size(); ++i) |
178 context->deleteTexture(colors[i]); | 178 context->deleteTexture(colors[i]); |
179 return ok; | 179 return ok; |
180 } | 180 } |
181 | 181 |
182 } // namespace WebCore | 182 } // namespace WebCore |
OLD | NEW |