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
parent 92372d8ff6
commit fcbc7ad7ba
9 changed files with 51 additions and 19 deletions

View File

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

View File

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

View File

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

View File

@ -710,11 +710,10 @@ WebGLContext::UnbindFakeBlackTextures()
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)
, 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);
mGL->MakeCurrent();
@ -724,7 +723,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G
: LOCAL_GL_TEXTURE_BINDING_CUBE_MAP,
&formerBinding);
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)
// 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.
void* zeros = calloc(1, 16);
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);
} else {
for (GLuint i = 0; i < 6; ++i) {
@ -742,7 +741,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G
}
free(zeros);
gl->fBindTexture(target, formerBinding);
gl->fBindTexture(target.get(), formerBinding);
}
WebGLContext::FakeBlackTexture::~FakeBlackTexture()

View File

@ -942,7 +942,7 @@ WebGLContext::GenerateMipmap(GLenum rawTarget)
// 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->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 {
gl->fGenerateMipmap(target.get());
}

View File

@ -252,6 +252,26 @@ STRONG_GLENUM_BEGIN(TexType)
STRONG_GLENUM_VALUE(FLOAT_32_UNSIGNED_INT_24_8_REV),
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_VALUE(NONE),
STRONG_GLENUM_VALUE(DEPTH_COMPONENT),
@ -405,4 +425,15 @@ STRONG_GLENUM_BEGIN(RBParam)
STRONG_GLENUM_VALUE(RENDERBUFFER_STENCIL_SIZE),
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

View File

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

View File

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

View File

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