OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "modules/webgl/WebGL2RenderingContextBase.h" | 6 #include "modules/webgl/WebGL2RenderingContextBase.h" |
7 | 7 |
8 #include "bindings/modules/v8/WebGLAny.h" | 8 #include "bindings/modules/v8/WebGLAny.h" |
9 #include "core/html/HTMLCanvasElement.h" | 9 #include "core/html/HTMLCanvasElement.h" |
10 #include "core/html/HTMLImageElement.h" | 10 #include "core/html/HTMLImageElement.h" |
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 WebGLVertexArrayObject* WebGL2RenderingContextBase::createVertexArray() | 2044 WebGLVertexArrayObject* WebGL2RenderingContextBase::createVertexArray() |
2045 { | 2045 { |
2046 if (isContextLost()) | 2046 if (isContextLost()) |
2047 return nullptr; | 2047 return nullptr; |
2048 | 2048 |
2049 WebGLVertexArrayObject* o = WebGLVertexArrayObject::create(this, WebGLVertex
ArrayObjectBase::VaoTypeUser); | 2049 WebGLVertexArrayObject* o = WebGLVertexArrayObject::create(this, WebGLVertex
ArrayObjectBase::VaoTypeUser); |
2050 addContextObject(o); | 2050 addContextObject(o); |
2051 return o; | 2051 return o; |
2052 } | 2052 } |
2053 | 2053 |
2054 void WebGL2RenderingContextBase::deleteVertexArray(WebGLVertexArrayObject* verte
xArray) | 2054 void WebGL2RenderingContextBase::deleteVertexArray(ScriptState* scriptState, Web
GLVertexArrayObject* vertexArray) |
2055 { | 2055 { |
2056 if (isContextLost() || !vertexArray) | 2056 if (isContextLost() || !vertexArray) |
2057 return; | 2057 return; |
2058 | 2058 |
2059 if (!vertexArray->isDefaultObject() && vertexArray == m_boundVertexArrayObje
ct) | 2059 if (!vertexArray->isDefaultObject() && vertexArray == m_boundVertexArrayObje
ct) |
2060 setBoundVertexArrayObject(nullptr); | 2060 setBoundVertexArrayObject(scriptState, nullptr); |
2061 | 2061 |
2062 vertexArray->deleteObject(webContext()); | 2062 vertexArray->deleteObject(webContext()); |
2063 } | 2063 } |
2064 | 2064 |
2065 GLboolean WebGL2RenderingContextBase::isVertexArray(WebGLVertexArrayObject* vert
exArray) | 2065 GLboolean WebGL2RenderingContextBase::isVertexArray(WebGLVertexArrayObject* vert
exArray) |
2066 { | 2066 { |
2067 if (isContextLost() || !vertexArray) | 2067 if (isContextLost() || !vertexArray) |
2068 return 0; | 2068 return 0; |
2069 | 2069 |
2070 if (!vertexArray->hasEverBeenBound()) | 2070 if (!vertexArray->hasEverBeenBound()) |
2071 return 0; | 2071 return 0; |
2072 | 2072 |
2073 return webContext()->isVertexArrayOES(vertexArray->object()); | 2073 return webContext()->isVertexArrayOES(vertexArray->object()); |
2074 } | 2074 } |
2075 | 2075 |
2076 void WebGL2RenderingContextBase::bindVertexArray(WebGLVertexArrayObject* vertexA
rray) | 2076 void WebGL2RenderingContextBase::bindVertexArray(ScriptState* scriptState, WebGL
VertexArrayObject* vertexArray) |
2077 { | 2077 { |
2078 if (isContextLost()) | 2078 if (isContextLost()) |
2079 return; | 2079 return; |
2080 | 2080 |
2081 if (vertexArray && (vertexArray->isDeleted() || !vertexArray->validate(0, th
is))) { | 2081 if (vertexArray && (vertexArray->isDeleted() || !vertexArray->validate(0, th
is))) { |
2082 webContext()->synthesizeGLError(GL_INVALID_OPERATION); | 2082 webContext()->synthesizeGLError(GL_INVALID_OPERATION); |
2083 return; | 2083 return; |
2084 } | 2084 } |
2085 | 2085 |
2086 if (vertexArray && !vertexArray->isDefaultObject() && vertexArray->object())
{ | 2086 if (vertexArray && !vertexArray->isDefaultObject() && vertexArray->object())
{ |
2087 webContext()->bindVertexArrayOES(objectOrZero(vertexArray)); | 2087 webContext()->bindVertexArrayOES(objectOrZero(vertexArray)); |
2088 | 2088 |
2089 vertexArray->setHasEverBeenBound(); | 2089 vertexArray->setHasEverBeenBound(); |
2090 setBoundVertexArrayObject(vertexArray); | 2090 setBoundVertexArrayObject(scriptState, vertexArray); |
2091 } else { | 2091 } else { |
2092 webContext()->bindVertexArrayOES(0); | 2092 webContext()->bindVertexArrayOES(0); |
2093 setBoundVertexArrayObject(nullptr); | 2093 setBoundVertexArrayObject(scriptState, nullptr); |
2094 } | 2094 } |
2095 } | 2095 } |
2096 | 2096 |
2097 void WebGL2RenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer
* buffer) | 2097 void WebGL2RenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenu
m target, WebGLFramebuffer* buffer) |
2098 { | 2098 { |
2099 bool deleted; | 2099 bool deleted; |
2100 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) | 2100 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) |
2101 return; | 2101 return; |
2102 | 2102 |
2103 if (deleted) | 2103 if (deleted) |
2104 buffer = 0; | 2104 buffer = 0; |
2105 | 2105 |
2106 switch (target) { | 2106 switch (target) { |
2107 case GL_DRAW_FRAMEBUFFER: | 2107 case GL_DRAW_FRAMEBUFFER: |
2108 break; | 2108 break; |
2109 case GL_FRAMEBUFFER: | 2109 case GL_FRAMEBUFFER: |
2110 case GL_READ_FRAMEBUFFER: | 2110 case GL_READ_FRAMEBUFFER: |
2111 m_readFramebufferBinding = buffer; | 2111 m_readFramebufferBinding = buffer; |
2112 break; | 2112 break; |
2113 default: | 2113 default: |
2114 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); | 2114 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); |
2115 return; | 2115 return; |
2116 } | 2116 } |
2117 | 2117 |
2118 setFramebuffer(target, buffer); | 2118 setFramebuffer(target, buffer); |
| 2119 if (scriptState) |
| 2120 preserveObjectWrapper(scriptState, this, "framebuffer", 0, buffer); |
2119 } | 2121 } |
2120 | 2122 |
2121 void WebGL2RenderingContextBase::deleteFramebuffer(WebGLFramebuffer* framebuffer
) | 2123 void WebGL2RenderingContextBase::deleteFramebuffer(WebGLFramebuffer* framebuffer
) |
2122 { | 2124 { |
2123 if (!deleteObject(framebuffer)) | 2125 if (!deleteObject(framebuffer)) |
2124 return; | 2126 return; |
2125 GLenum target = 0; | 2127 GLenum target = 0; |
2126 if (framebuffer == m_framebufferBinding) { | 2128 if (framebuffer == m_framebufferBinding) { |
2127 if (framebuffer == m_readFramebufferBinding) { | 2129 if (framebuffer == m_readFramebufferBinding) { |
2128 target = GL_FRAMEBUFFER; | 2130 target = GL_FRAMEBUFFER; |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2926 if (m_boundTransformFeedbackBuffer == buffer) | 2928 if (m_boundTransformFeedbackBuffer == buffer) |
2927 m_boundTransformFeedbackBuffer = nullptr; | 2929 m_boundTransformFeedbackBuffer = nullptr; |
2928 if (m_boundUniformBuffer == buffer) | 2930 if (m_boundUniformBuffer == buffer) |
2929 m_boundUniformBuffer = nullptr; | 2931 m_boundUniformBuffer = nullptr; |
2930 | 2932 |
2931 WebGLRenderingContextBase::removeBoundBuffer(buffer); | 2933 WebGLRenderingContextBase::removeBoundBuffer(buffer); |
2932 } | 2934 } |
2933 | 2935 |
2934 void WebGL2RenderingContextBase::restoreCurrentFramebuffer() | 2936 void WebGL2RenderingContextBase::restoreCurrentFramebuffer() |
2935 { | 2937 { |
2936 bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebufferBinding.get()); | 2938 bindFramebuffer(nullptr, GL_DRAW_FRAMEBUFFER, m_framebufferBinding.get()); |
2937 bindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBinding.get()); | 2939 bindFramebuffer(nullptr, GL_READ_FRAMEBUFFER, m_readFramebufferBinding.get()
); |
2938 } | 2940 } |
2939 | 2941 |
2940 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() | 2942 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() |
2941 { | 2943 { |
2942 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) | 2944 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) |
2943 return m_readFramebufferBinding->colorBufferFormat(); | 2945 return m_readFramebufferBinding->colorBufferFormat(); |
2944 if (m_requestedAttributes.alpha()) | 2946 if (m_requestedAttributes.alpha()) |
2945 return GL_RGBA; | 2947 return GL_RGBA; |
2946 return GL_RGB; | 2948 return GL_RGB; |
2947 } | 2949 } |
2948 | 2950 |
2949 } // namespace blink | 2951 } // namespace blink |
OLD | NEW |