From 5b4913acf0afb2415096997bc233e6deb589b66a Mon Sep 17 00:00:00 2001 From: Dan Glastonbury Date: Fri, 3 Jul 2015 11:54:07 +1000 Subject: [PATCH] Bug 1170842 - Part 3: Implement GetInternalformatParameter. r=jgilbert, r=smaug --- dom/canvas/WebGL2Context.h | 11 +++- dom/canvas/WebGL2ContextFramebuffers.cpp | 15 ------ dom/canvas/WebGL2ContextRenderbuffers.cpp | 66 +++++++++++++++++++++++ dom/canvas/moz.build | 1 + dom/webidl/WebGL2RenderingContext.webidl | 5 +- 5 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 dom/canvas/WebGL2ContextRenderbuffers.cpp diff --git a/dom/canvas/WebGL2Context.h b/dom/canvas/WebGL2Context.h index fe4ddab7cbe3..045cbb11b40a 100644 --- a/dom/canvas/WebGL2Context.h +++ b/dom/canvas/WebGL2Context.h @@ -55,13 +55,20 @@ public: void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); - void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); - void GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat, GLenum pname, JS::MutableHandleValue retval); + void FramebufferTextureLayer(GLenum target, GLenum attachment, WebGLTexture* texture, GLint level, GLint layer); void InvalidateFramebuffer(GLenum target, const dom::Sequence& attachments, ErrorResult& rv); void InvalidateSubFramebuffer (GLenum target, const dom::Sequence& attachments, GLint x, GLint y, GLsizei width, GLsizei height, ErrorResult& rv); void ReadBuffer(GLenum mode); + + + // ------------------------------------------------------------------------- + // Renderbuffer objects - WebGL2ContextRenderbuffers.cpp + + void GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat, + GLenum pname, JS::MutableHandleValue retval, + ErrorResult& rv); void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); diff --git a/dom/canvas/WebGL2ContextFramebuffers.cpp b/dom/canvas/WebGL2ContextFramebuffers.cpp index a50071e089bb..ab09fc1eb9a3 100644 --- a/dom/canvas/WebGL2ContextFramebuffers.cpp +++ b/dom/canvas/WebGL2ContextFramebuffers.cpp @@ -336,12 +336,6 @@ WebGL2Context::FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint GenerateWarning("framebufferTextureLayer: Not Implemented."); } -void -WebGL2Context::GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat, GLenum pname, JS::MutableHandleValue retval) -{ - GenerateWarning("getInternalformatParameter: Not Implemented."); -} - // Map attachments intended for the default buffer, to attachments for a non- // default buffer. static bool @@ -536,13 +530,4 @@ WebGL2Context::ReadBuffer(GLenum mode) gl->Screen()->SetReadBuffer(mode); } -void -WebGL2Context::RenderbufferStorageMultisample(GLenum target, GLsizei samples, - GLenum internalFormat, - GLsizei width, GLsizei height) -{ - RenderbufferStorage_base("renderbufferStorageMultisample", target, samples, - internalFormat, width, height); -} - } // namespace mozilla diff --git a/dom/canvas/WebGL2ContextRenderbuffers.cpp b/dom/canvas/WebGL2ContextRenderbuffers.cpp new file mode 100644 index 000000000000..7ad686414a3a --- /dev/null +++ b/dom/canvas/WebGL2ContextRenderbuffers.cpp @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebGL2Context.h" + +#include "GLContext.h" +#include "WebGLContextUtils.h" + +namespace mozilla { + +void +WebGL2Context::GetInternalformatParameter(JSContext* cx, GLenum target, + GLenum internalformat, GLenum pname, + JS::MutableHandleValue retval, + ErrorResult& rv) +{ + if (IsContextLost()) + return; + + if (target != LOCAL_GL_RENDERBUFFER) { + return ErrorInvalidEnumInfo("getInternalfomratParameter: target must be " + "RENDERBUFFER. Was:", target); + } + + // GL_INVALID_ENUM is generated if internalformat is not color-, + // depth-, or stencil-renderable. + // TODO: When format table queries lands. + + if (pname != LOCAL_GL_SAMPLES) { + return ErrorInvalidEnumInfo("getInternalformatParameter: pname must be SAMPLES. " + "Was:", pname); + } + + GLint* samples = nullptr; + GLint sampleCount = 0; + gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat, + LOCAL_GL_NUM_SAMPLE_COUNTS, 1, &sampleCount); + if (sampleCount > 0) { + samples = new GLint[sampleCount]; + gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat, LOCAL_GL_SAMPLES, + sampleCount, samples); + } + + JSObject* obj = dom::Int32Array::Create(cx, this, sampleCount, samples); + if (!obj) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + + delete[] samples; + + retval.setObjectOrNull(obj); +} + +void +WebGL2Context::RenderbufferStorageMultisample(GLenum target, GLsizei samples, + GLenum internalFormat, + GLsizei width, GLsizei height) +{ + RenderbufferStorage_base("renderbufferStorageMultisample", target, samples, + internalFormat, width, height); +} + +} // namespace mozilla diff --git a/dom/canvas/moz.build b/dom/canvas/moz.build index 57984a648eb5..c859d726e986 100644 --- a/dom/canvas/moz.build +++ b/dom/canvas/moz.build @@ -60,6 +60,7 @@ UNIFIED_SOURCES += [ 'WebGL2ContextMRTs.cpp', 'WebGL2ContextPrograms.cpp', 'WebGL2ContextQueries.cpp', + 'WebGL2ContextRenderbuffers.cpp', 'WebGL2ContextSamplers.cpp', 'WebGL2ContextState.cpp', 'WebGL2ContextSync.cpp', diff --git a/dom/webidl/WebGL2RenderingContext.webidl b/dom/webidl/WebGL2RenderingContext.webidl index 30e4c9e16a7f..3be96123809f 100644 --- a/dom/webidl/WebGL2RenderingContext.webidl +++ b/dom/webidl/WebGL2RenderingContext.webidl @@ -323,8 +323,7 @@ interface WebGL2RenderingContext : WebGLRenderingContext /* Framebuffer objects */ void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); - void framebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); - any getInternalformatParameter(GLenum target, GLenum internalformat, GLenum pname); + void framebufferTextureLayer(GLenum target, GLenum attachment, WebGLTexture? texture, GLint level, GLint layer); [Throws] void invalidateFramebuffer(GLenum target, sequence attachments); @@ -336,6 +335,8 @@ interface WebGL2RenderingContext : WebGLRenderingContext void readBuffer(GLenum src); /* Renderbuffer objects */ + [Throws] + any getInternalformatParameter(GLenum target, GLenum internalformat, GLenum pname); void renderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); /* Texture objects */