Bug 1073216 - WebGL add strong GLenum support for VAO/Buffer bindings, and texture min/mag/wrap types. r=jgilbert

This commit is contained in:
Walter Litwinczyk 2014-09-26 13:11:51 -07:00
Родитель a028173cff
Коммит 6875e2a589
9 изменённых файлов: 51 добавлений и 19 удалений

Просмотреть файл

@ -13,7 +13,7 @@
using namespace mozilla; using namespace mozilla;
WebGLBuffer::WebGLBuffer(WebGLContext *context) WebGLBuffer::WebGLBuffer(WebGLContext *context)
: WebGLBindableName<GLenum>() : WebGLBindableName<BufferBinding>()
, WebGLContextBoundObject(context) , WebGLContextBoundObject(context)
, mByteLength(0) , mByteLength(0)
{ {

Просмотреть файл

@ -13,6 +13,7 @@
#include "WebGLBindableName.h" #include "WebGLBindableName.h"
#include "WebGLObjectModel.h" #include "WebGLObjectModel.h"
#include "WebGLTypes.h" #include "WebGLTypes.h"
#include "WebGLStrongTypes.h"
namespace mozilla { namespace mozilla {
@ -20,7 +21,7 @@ class WebGLElementArrayCache;
class WebGLBuffer MOZ_FINAL class WebGLBuffer MOZ_FINAL
: public nsWrapperCache : public nsWrapperCache
, public WebGLBindableName<GLenum> , public WebGLBindableName<BufferBinding>
, public WebGLRefCountedObject<WebGLBuffer> , public WebGLRefCountedObject<WebGLBuffer>
, public LinkedListElement<WebGLBuffer> , public LinkedListElement<WebGLBuffer>
, public WebGLContextBoundObject , public WebGLContextBoundObject

Просмотреть файл

@ -1272,7 +1272,7 @@ protected:
GLuint mGLName; GLuint mGLName;
public: public:
FakeBlackTexture(gl::GLContext* gl, GLenum target, GLenum format); FakeBlackTexture(gl::GLContext* gl, TexTarget target, GLenum format);
~FakeBlackTexture(); ~FakeBlackTexture();
GLuint GLName() const { return mGLName; } GLuint GLName() const { return mGLName; }
}; };

Просмотреть файл

@ -710,11 +710,10 @@ WebGLContext::UnbindFakeBlackTextures()
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture); gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
} }
WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, GLenum format) WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, TexTarget target, GLenum format)
: mGL(gl) : mGL(gl)
, mGLName(0) , mGLName(0)
{ {
MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D || target == LOCAL_GL_TEXTURE_CUBE_MAP);
MOZ_ASSERT(format == LOCAL_GL_RGB || format == LOCAL_GL_RGBA); MOZ_ASSERT(format == LOCAL_GL_RGB || format == LOCAL_GL_RGBA);
mGL->MakeCurrent(); mGL->MakeCurrent();
@ -724,7 +723,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G
: LOCAL_GL_TEXTURE_BINDING_CUBE_MAP, : LOCAL_GL_TEXTURE_BINDING_CUBE_MAP,
&formerBinding); &formerBinding);
gl->fGenTextures(1, &mGLName); gl->fGenTextures(1, &mGLName);
gl->fBindTexture(target, mGLName); gl->fBindTexture(target.get(), mGLName);
// we allocate our zeros on the heap, and we overallocate (16 bytes instead of 4) // we allocate our zeros on the heap, and we overallocate (16 bytes instead of 4)
// to minimize the risk of running into a driver bug in texImage2D, as it is // to minimize the risk of running into a driver bug in texImage2D, as it is
@ -732,7 +731,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G
// that texImage2D expects. // that texImage2D expects.
void* zeros = calloc(1, 16); void* zeros = calloc(1, 16);
if (target == LOCAL_GL_TEXTURE_2D) { if (target == LOCAL_GL_TEXTURE_2D) {
gl->fTexImage2D(target, 0, format, 1, 1, gl->fTexImage2D(target.get(), 0, format, 1, 1,
0, format, LOCAL_GL_UNSIGNED_BYTE, zeros); 0, format, LOCAL_GL_UNSIGNED_BYTE, zeros);
} else { } else {
for (GLuint i = 0; i < 6; ++i) { for (GLuint i = 0; i < 6; ++i) {
@ -742,7 +741,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G
} }
free(zeros); free(zeros);
gl->fBindTexture(target, formerBinding); gl->fBindTexture(target.get(), formerBinding);
} }
WebGLContext::FakeBlackTexture::~FakeBlackTexture() WebGLContext::FakeBlackTexture::~FakeBlackTexture()

Просмотреть файл

@ -942,7 +942,7 @@ WebGLContext::GenerateMipmap(GLenum rawTarget)
// note that the choice of GL_NEAREST_MIPMAP_NEAREST really matters. See Chromium bug 101105. // note that the choice of GL_NEAREST_MIPMAP_NEAREST really matters. See Chromium bug 101105.
gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST_MIPMAP_NEAREST); gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST_MIPMAP_NEAREST);
gl->fGenerateMipmap(target.get()); gl->fGenerateMipmap(target.get());
gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter()); gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter().get());
} else { } else {
gl->fGenerateMipmap(target.get()); gl->fGenerateMipmap(target.get());
} }

Просмотреть файл

@ -252,6 +252,26 @@ STRONG_GLENUM_BEGIN(TexType)
STRONG_GLENUM_VALUE(FLOAT_32_UNSIGNED_INT_24_8_REV), STRONG_GLENUM_VALUE(FLOAT_32_UNSIGNED_INT_24_8_REV),
STRONG_GLENUM_END(TexType) STRONG_GLENUM_END(TexType)
STRONG_GLENUM_BEGIN(TexMinFilter)
STRONG_GLENUM_VALUE(NEAREST),
STRONG_GLENUM_VALUE(LINEAR),
STRONG_GLENUM_VALUE(NEAREST_MIPMAP_NEAREST),
STRONG_GLENUM_VALUE(LINEAR_MIPMAP_NEAREST),
STRONG_GLENUM_VALUE(NEAREST_MIPMAP_LINEAR),
STRONG_GLENUM_VALUE(LINEAR_MIPMAP_LINEAR),
STRONG_GLENUM_END(TexMinFilter)
STRONG_GLENUM_BEGIN(TexMagFilter)
STRONG_GLENUM_VALUE(NEAREST),
STRONG_GLENUM_VALUE(LINEAR),
STRONG_GLENUM_END(TexMagFilter)
STRONG_GLENUM_BEGIN(TexWrap)
STRONG_GLENUM_VALUE(REPEAT),
STRONG_GLENUM_VALUE(CLAMP_TO_EDGE),
STRONG_GLENUM_VALUE(MIRRORED_REPEAT),
STRONG_GLENUM_END(TexWrap)
STRONG_GLENUM_BEGIN(TexFormat) STRONG_GLENUM_BEGIN(TexFormat)
STRONG_GLENUM_VALUE(NONE), STRONG_GLENUM_VALUE(NONE),
STRONG_GLENUM_VALUE(DEPTH_COMPONENT), STRONG_GLENUM_VALUE(DEPTH_COMPONENT),
@ -405,4 +425,15 @@ STRONG_GLENUM_BEGIN(RBParam)
STRONG_GLENUM_VALUE(RENDERBUFFER_STENCIL_SIZE), STRONG_GLENUM_VALUE(RENDERBUFFER_STENCIL_SIZE),
STRONG_GLENUM_END(RBParam) STRONG_GLENUM_END(RBParam)
STRONG_GLENUM_BEGIN(VAOBinding)
STRONG_GLENUM_VALUE(NONE),
STRONG_GLENUM_VALUE(VERTEX_ARRAY_BINDING),
STRONG_GLENUM_END(VAOBinding)
STRONG_GLENUM_BEGIN(BufferBinding)
STRONG_GLENUM_VALUE(NONE),
STRONG_GLENUM_VALUE(ARRAY_BUFFER),
STRONG_GLENUM_VALUE(ELEMENT_ARRAY_BUFFER),
STRONG_GLENUM_END(BufferBinding)
#endif #endif

Просмотреть файл

@ -194,7 +194,9 @@ public:
protected: protected:
GLenum mMinFilter, mMagFilter, mWrapS, mWrapT; TexMinFilter mMinFilter;
TexMagFilter mMagFilter;
TexWrap mWrapS, mWrapT;
size_t mFacesCount, mMaxLevelWithCustomImages; size_t mFacesCount, mMaxLevelWithCustomImages;
nsTArray<ImageInfo> mImageInfos; nsTArray<ImageInfo> mImageInfos;
@ -227,23 +229,23 @@ public:
GLsizei aWidth, GLsizei aHeight, GLsizei aWidth, GLsizei aHeight,
TexInternalFormat aFormat, TexType aType, WebGLImageDataStatus aStatus); TexInternalFormat aFormat, TexType aType, WebGLImageDataStatus aStatus);
void SetMinFilter(GLenum aMinFilter) { void SetMinFilter(TexMinFilter aMinFilter) {
mMinFilter = aMinFilter; mMinFilter = aMinFilter;
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
} }
void SetMagFilter(GLenum aMagFilter) { void SetMagFilter(TexMagFilter aMagFilter) {
mMagFilter = aMagFilter; mMagFilter = aMagFilter;
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
} }
void SetWrapS(GLenum aWrapS) { void SetWrapS(TexWrap aWrapS) {
mWrapS = aWrapS; mWrapS = aWrapS;
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
} }
void SetWrapT(GLenum aWrapT) { void SetWrapT(TexWrap aWrapT) {
mWrapT = aWrapT; mWrapT = aWrapT;
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
} }
GLenum MinFilter() const { return mMinFilter; } TexMinFilter MinFilter() const { return mMinFilter; }
bool DoesMinFilterRequireMipmap() const { bool DoesMinFilterRequireMipmap() const {
return !(mMinFilter == LOCAL_GL_NEAREST || mMinFilter == LOCAL_GL_LINEAR); return !(mMinFilter == LOCAL_GL_NEAREST || mMinFilter == LOCAL_GL_LINEAR);

Просмотреть файл

@ -20,7 +20,7 @@ WebGLVertexArray::WrapObject(JSContext *cx) {
} }
WebGLVertexArray::WebGLVertexArray(WebGLContext* context) WebGLVertexArray::WebGLVertexArray(WebGLContext* context)
: WebGLBindableName<GLenum>() : WebGLBindableName<VAOBinding>()
, WebGLContextBoundObject(context) , WebGLContextBoundObject(context)
{ {
SetIsDOMBinding(); SetIsDOMBinding();

Просмотреть файл

@ -10,6 +10,7 @@
#include "WebGLObjectModel.h" #include "WebGLObjectModel.h"
#include "WebGLBuffer.h" #include "WebGLBuffer.h"
#include "WebGLVertexAttribData.h" #include "WebGLVertexAttribData.h"
#include "WebGLStrongTypes.h"
#include "nsWrapperCache.h" #include "nsWrapperCache.h"
@ -21,7 +22,7 @@ class WebGLVertexArrayFake;
class WebGLVertexArray class WebGLVertexArray
: public nsWrapperCache : public nsWrapperCache
, public WebGLBindableName<GLenum> , public WebGLBindableName<VAOBinding>
, public WebGLRefCountedObject<WebGLVertexArray> , public WebGLRefCountedObject<WebGLVertexArray>
, public LinkedListElement<WebGLVertexArray> , public LinkedListElement<WebGLVertexArray>
, public WebGLContextBoundObject , public WebGLContextBoundObject
@ -41,8 +42,6 @@ public:
virtual void GenVertexArray() = 0; virtual void GenVertexArray() = 0;
virtual void BindVertexArrayImpl() = 0; virtual void BindVertexArrayImpl() = 0;
GLuint GLName() const { return mGLName; }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// IMPLEMENT PARENT CLASSES // IMPLEMENT PARENT CLASSES