2009-09-02 17:47:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
|
2009-09-17 23:01:12 -07:00
|
|
|
* Mark Steele <mwsteele@gmail.com>
|
2009-09-02 17:47:49 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef WEBGLCONTEXT_H_
|
|
|
|
#define WEBGLCONTEXT_H_
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2010-06-10 10:45:00 -07:00
|
|
|
#include <vector>
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
|
|
|
|
#include "nsICanvasRenderingContextWebGL.h"
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "nsHTMLCanvasElement.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2009-09-17 23:01:07 -07:00
|
|
|
#include "nsIJSNativeInitializer.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "GLContext.h"
|
|
|
|
#include "Layers.h"
|
2010-01-22 18:29:49 -08:00
|
|
|
|
2010-06-15 08:59:39 -07:00
|
|
|
#define UNPACK_FLIP_Y_WEBGL 0x9240
|
|
|
|
#define UNPACK_PREMULTIPLY_ALPHA_WEBGL 0x9241
|
|
|
|
#define CONTEXT_LOST_WEBGL 0x9242
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
class nsIDocShell;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class WebGLTexture;
|
|
|
|
class WebGLBuffer;
|
|
|
|
class WebGLProgram;
|
|
|
|
class WebGLShader;
|
|
|
|
class WebGLFramebuffer;
|
|
|
|
class WebGLRenderbuffer;
|
2010-06-01 23:09:19 -07:00
|
|
|
class WebGLUniformLocation;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
class WebGLZeroingObject;
|
2010-06-10 10:45:00 -07:00
|
|
|
class WebGLContextBoundObject;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
class WebGLObjectBaseRefPtr
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
friend class WebGLZeroingObject;
|
|
|
|
|
|
|
|
WebGLObjectBaseRefPtr()
|
|
|
|
: mRawPtr(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLObjectBaseRefPtr(nsISupports *rawPtr)
|
|
|
|
: mRawPtr(rawPtr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Zero() {
|
|
|
|
if (mRawPtr) {
|
|
|
|
// Note: RemoveRefOwner isn't called here, because
|
|
|
|
// the entire owner array will be cleared.
|
|
|
|
mRawPtr->Release();
|
|
|
|
mRawPtr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsISupports *mRawPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class WebGLObjectRefPtr
|
|
|
|
: public WebGLObjectBaseRefPtr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T element_type;
|
|
|
|
|
|
|
|
WebGLObjectRefPtr()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
WebGLObjectRefPtr(const WebGLObjectRefPtr<T>& aSmartPtr)
|
|
|
|
: WebGLObjectBaseRefPtr(aSmartPtr.mRawPtr)
|
|
|
|
{
|
|
|
|
if (mRawPtr) {
|
|
|
|
RawPtr()->AddRef();
|
|
|
|
RawPtr()->AddRefOwner(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLObjectRefPtr(T *aRawPtr)
|
|
|
|
: WebGLObjectBaseRefPtr(aRawPtr)
|
|
|
|
{
|
|
|
|
if (mRawPtr) {
|
|
|
|
RawPtr()->AddRef();
|
|
|
|
RawPtr()->AddRefOwner(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLObjectRefPtr(const already_AddRefed<T>& aSmartPtr)
|
|
|
|
: WebGLObjectBaseRefPtr(aSmartPtr.mRawPtr)
|
|
|
|
// construct from |dont_AddRef(expr)|
|
|
|
|
{
|
|
|
|
if (mRawPtr) {
|
|
|
|
RawPtr()->AddRef();
|
|
|
|
RawPtr()->AddRefOwner(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~WebGLObjectRefPtr() {
|
|
|
|
if (mRawPtr) {
|
|
|
|
RawPtr()->RemoveRefOwner(this);
|
|
|
|
RawPtr()->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLObjectRefPtr<T>&
|
|
|
|
operator=(const WebGLObjectRefPtr<T>& rhs)
|
|
|
|
{
|
|
|
|
assign_with_AddRef(static_cast<T*>(rhs.mRawPtr));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLObjectRefPtr<T>&
|
|
|
|
operator=(T* rhs)
|
|
|
|
{
|
|
|
|
assign_with_AddRef(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLObjectRefPtr<T>&
|
|
|
|
operator=(const already_AddRefed<T>& rhs)
|
|
|
|
{
|
|
|
|
assign_assuming_AddRef(static_cast<T*>(rhs.mRawPtr));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* get() const {
|
|
|
|
return const_cast<T*>(static_cast<T*>(mRawPtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
operator T*() const {
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
T* operator->() const {
|
|
|
|
NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL WebGLObjectRefPtr with operator->()!");
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
T& operator*() const {
|
|
|
|
NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL WebGLObjectRefPtr with operator*()!");
|
|
|
|
return *get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T* RawPtr() { return static_cast<T*>(mRawPtr); }
|
|
|
|
|
|
|
|
void assign_with_AddRef(T* rawPtr) {
|
|
|
|
if (rawPtr) {
|
|
|
|
rawPtr->AddRef();
|
|
|
|
rawPtr->AddRefOwner(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
assign_assuming_AddRef(rawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void assign_assuming_AddRef(T* newPtr) {
|
|
|
|
T* oldPtr = RawPtr();
|
|
|
|
mRawPtr = newPtr;
|
|
|
|
if (oldPtr) {
|
|
|
|
oldPtr->RemoveRefOwner(this);
|
|
|
|
oldPtr->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class WebGLBuffer;
|
|
|
|
|
|
|
|
struct WebGLVertexAttribData {
|
|
|
|
WebGLVertexAttribData()
|
2010-06-01 23:09:18 -07:00
|
|
|
: buf(0), stride(0), size(0), byteOffset(0), type(0), enabled(PR_FALSE)
|
2009-09-02 17:47:49 -07:00
|
|
|
{ }
|
|
|
|
|
|
|
|
WebGLObjectRefPtr<WebGLBuffer> buf;
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint stride;
|
|
|
|
WebGLuint size;
|
2010-06-01 23:09:18 -07:00
|
|
|
GLuint byteOffset;
|
|
|
|
GLenum type;
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool enabled;
|
2010-06-01 23:09:18 -07:00
|
|
|
|
2010-06-08 15:14:43 -07:00
|
|
|
GLuint componentSize() const {
|
2010-06-01 23:09:18 -07:00
|
|
|
switch(type) {
|
|
|
|
case LOCAL_GL_BYTE:
|
2010-06-08 15:14:43 -07:00
|
|
|
return sizeof(GLbyte);
|
2010-06-01 23:09:18 -07:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
2010-06-08 15:14:43 -07:00
|
|
|
return sizeof(GLubyte);
|
2010-06-01 23:09:18 -07:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_SHORT:
|
2010-06-08 15:14:43 -07:00
|
|
|
return sizeof(GLshort);
|
2010-06-01 23:09:18 -07:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
2010-06-08 15:14:43 -07:00
|
|
|
return sizeof(GLushort);
|
2010-06-01 23:09:18 -07:00
|
|
|
break;
|
|
|
|
// XXX case LOCAL_GL_FIXED:
|
|
|
|
case LOCAL_GL_FLOAT:
|
2010-06-08 15:14:43 -07:00
|
|
|
return sizeof(GLfloat);
|
2010-06-01 23:09:18 -07:00
|
|
|
break;
|
2010-06-08 15:14:43 -07:00
|
|
|
default:
|
|
|
|
NS_ERROR("Should never get here!");
|
|
|
|
return 0;
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
2010-06-08 15:14:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GLuint actualStride() const {
|
|
|
|
if (stride) return stride;
|
|
|
|
return size * componentSize();
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class WebGLContext :
|
|
|
|
public nsICanvasRenderingContextWebGL,
|
|
|
|
public nsICanvasRenderingContextInternal,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLContext();
|
|
|
|
virtual ~WebGLContext();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICANVASRENDERINGCONTEXTWEBGL
|
|
|
|
|
|
|
|
// nsICanvasRenderingContextInternal
|
2010-05-17 21:04:22 -07:00
|
|
|
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas);
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
|
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, PRInt32 width, PRInt32 height)
|
|
|
|
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
|
|
|
NS_IMETHOD Render(gfxContext *ctx, gfxPattern::GraphicsFilter f);
|
|
|
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
|
|
|
const PRUnichar* aEncoderOptions,
|
|
|
|
nsIInputStream **aStream);
|
|
|
|
NS_IMETHOD GetThebesSurface(gfxASurface **surface);
|
|
|
|
NS_IMETHOD SetIsOpaque(PRBool b) { return NS_OK; };
|
|
|
|
|
2010-05-28 15:52:39 -07:00
|
|
|
nsresult SynthesizeGLError(WebGLenum err);
|
|
|
|
nsresult SynthesizeGLError(WebGLenum err, const char *fmt, ...);
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
nsresult ErrorInvalidEnum(const char *fmt = 0, ...);
|
|
|
|
nsresult ErrorInvalidOperation(const char *fmt = 0, ...);
|
|
|
|
nsresult ErrorInvalidValue(const char *fmt = 0, ...);
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
already_AddRefed<CanvasLayer> GetCanvasLayer(LayerManager *manager);
|
|
|
|
void MarkContextClean() { }
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// a number that increments every time we have an event that causes
|
|
|
|
// all context resources to be lost.
|
|
|
|
PRUint32 Generation() { return mGeneration; }
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2010-05-17 21:04:22 -07:00
|
|
|
nsHTMLCanvasElement* mCanvasElement;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
nsRefPtr<gl::GLContext> gl;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
PRInt32 mWidth, mHeight;
|
2010-06-04 12:03:37 -07:00
|
|
|
PRUint32 mGeneration;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
PRBool mInvalidated;
|
|
|
|
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mActiveTexture;
|
|
|
|
WebGLenum mSynthesizedGLError;
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
PRBool SafeToCreateCanvas3DContext(nsHTMLCanvasElement *canvasElement);
|
2010-06-14 11:44:12 -07:00
|
|
|
PRBool InitAndValidateGL();
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool ValidateBuffers(PRUint32 count);
|
2010-06-08 11:45:23 -07:00
|
|
|
static PRBool ValidateCapabilityEnum(WebGLenum cap);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Invalidate();
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
void MakeContextCurrent() { gl->MakeCurrent(); }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
// helpers
|
2010-05-28 15:52:39 -07:00
|
|
|
nsresult TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLint border,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2010-01-22 13:34:25 -08:00
|
|
|
void *data, PRUint32 byteLength);
|
2010-05-28 15:52:39 -07:00
|
|
|
nsresult TexSubImage2D_base(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2010-01-22 13:34:25 -08:00
|
|
|
void *pixels, PRUint32 byteLength);
|
|
|
|
|
|
|
|
nsresult DOMElementToImageSurface(nsIDOMElement *imageOrCanvas,
|
|
|
|
gfxImageSurface **imageOut,
|
|
|
|
PRBool flipY, PRBool premultiplyAlpha);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// Conversion from public nsI* interfaces to concrete objects
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool GetConcreteObject(BaseInterfaceType *aInterface,
|
|
|
|
ConcreteObjectType **aConcreteObject,
|
|
|
|
PRBool *isNull = 0,
|
|
|
|
PRBool *isDeleted = 0);
|
|
|
|
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool GetConcreteObjectAndGLName(BaseInterfaceType *aInterface,
|
|
|
|
ConcreteObjectType **aConcreteObject,
|
|
|
|
WebGLuint *aGLObjectName,
|
|
|
|
PRBool *isNull = 0,
|
|
|
|
PRBool *isDeleted = 0);
|
|
|
|
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool GetGLName(BaseInterfaceType *aInterface,
|
|
|
|
WebGLuint *aGLObjectName,
|
|
|
|
PRBool *isNull = 0,
|
|
|
|
PRBool *isDeleted = 0);
|
|
|
|
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool CheckConversion(BaseInterfaceType *aInterface,
|
|
|
|
PRBool *isNull = 0,
|
|
|
|
PRBool *isDeleted = 0);
|
|
|
|
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
// the buffers bound to the current program's attribs
|
|
|
|
nsTArray<WebGLVertexAttribData> mAttribBuffers;
|
|
|
|
|
|
|
|
// the textures bound to any sampler uniforms
|
|
|
|
nsTArray<WebGLObjectRefPtr<WebGLTexture> > mUniformTextures;
|
|
|
|
|
|
|
|
// textures bound to
|
|
|
|
nsTArray<WebGLObjectRefPtr<WebGLTexture> > mBound2DTextures;
|
|
|
|
nsTArray<WebGLObjectRefPtr<WebGLTexture> > mBoundCubeMapTextures;
|
|
|
|
|
|
|
|
WebGLObjectRefPtr<WebGLBuffer> mBoundArrayBuffer;
|
|
|
|
WebGLObjectRefPtr<WebGLBuffer> mBoundElementArrayBuffer;
|
|
|
|
WebGLObjectRefPtr<WebGLProgram> mCurrentProgram;
|
|
|
|
|
2009-12-07 15:10:04 -08:00
|
|
|
// XXX these 3 are wrong types, and aren't used atm (except for the length of the attachments)
|
|
|
|
nsTArray<WebGLObjectRefPtr<WebGLTexture> > mFramebufferColorAttachments;
|
|
|
|
nsRefPtr<WebGLFramebuffer> mFramebufferDepthAttachment;
|
|
|
|
nsRefPtr<WebGLFramebuffer> mFramebufferStencilAttachment;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2009-12-07 15:10:04 -08:00
|
|
|
nsRefPtr<WebGLFramebuffer> mBoundFramebuffer;
|
2009-09-02 17:47:49 -07:00
|
|
|
nsRefPtr<WebGLRenderbuffer> mBoundRenderbuffer;
|
|
|
|
|
|
|
|
// lookup tables for GL name -> object wrapper
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLTexture> mMapTextures;
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLBuffer> mMapBuffers;
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLProgram> mMapPrograms;
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLShader> mMapShaders;
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLFramebuffer> mMapFramebuffers;
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLRenderbuffer> mMapRenderbuffers;
|
|
|
|
|
2010-06-15 08:59:39 -07:00
|
|
|
// WebGL-specific PixelStore parameters
|
|
|
|
PRBool mPixelStoreFlipY, mPixelStorePremultiplyAlpha;
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
public:
|
2009-09-02 17:47:49 -07:00
|
|
|
// console logging helpers
|
2010-05-19 13:46:08 -07:00
|
|
|
static void LogMessage (const char *fmt, ...);
|
2010-05-15 06:55:45 -07:00
|
|
|
static void LogMessage(const char *fmt, va_list ap);
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// this class is a mixin for the named type wrappers, and is used
|
|
|
|
// by WebGLObjectRefPtr to tell the object who holds references, so that
|
|
|
|
// we can zero them out appropriately when the object is deleted, because
|
|
|
|
// it will be unbound in the GL.
|
|
|
|
class WebGLZeroingObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLZeroingObject()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void AddRefOwner(WebGLObjectBaseRefPtr *owner) {
|
|
|
|
mRefOwners.AppendElement(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveRefOwner(WebGLObjectBaseRefPtr *owner) {
|
|
|
|
mRefOwners.RemoveElement(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZeroOwners() {
|
|
|
|
WebGLObjectBaseRefPtr **owners = mRefOwners.Elements();
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mRefOwners.Length(); i++) {
|
|
|
|
owners[i]->Zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
mRefOwners.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsTArray<WebGLObjectBaseRefPtr *> mRefOwners;
|
|
|
|
};
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// this class is a mixin for GL objects that have dimensions
|
|
|
|
// that we need to track.
|
2010-05-15 05:07:30 -07:00
|
|
|
class WebGLRectangleObject
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
WebGLRectangleObject()
|
|
|
|
: mWidth(0), mHeight(0) { }
|
|
|
|
|
|
|
|
public:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLsizei width() { return mWidth; }
|
|
|
|
void width(WebGLsizei value) { mWidth = value; }
|
2010-05-15 05:07:30 -07:00
|
|
|
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLsizei height() { return mHeight; }
|
|
|
|
void height(WebGLsizei value) { mHeight = value; }
|
2010-05-15 05:07:30 -07:00
|
|
|
|
2010-05-28 15:52:39 -07:00
|
|
|
void setDimensions(WebGLsizei width, WebGLsizei height) {
|
2010-05-15 05:07:30 -07:00
|
|
|
mWidth = width;
|
|
|
|
mHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDimensions(WebGLRectangleObject *rect) {
|
|
|
|
if (rect) {
|
|
|
|
mWidth = rect->width();
|
|
|
|
mHeight = rect->height();
|
|
|
|
} else {
|
|
|
|
mWidth = 0;
|
|
|
|
mHeight = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLsizei mWidth;
|
|
|
|
WebGLsizei mHeight;
|
2010-05-15 05:07:30 -07:00
|
|
|
};
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
// This class is a mixin for objects that are tied to a specific
|
|
|
|
// context (which is to say, all of them). They provide initialization
|
|
|
|
// as well as comparison with the current context.
|
|
|
|
class WebGLContextBoundObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLContextBoundObject(WebGLContext *context) {
|
|
|
|
mContext = context;
|
|
|
|
mContextGeneration = context->Generation();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool IsCompatibleWithContext(WebGLContext *other) {
|
|
|
|
return mContext == other &&
|
|
|
|
mContextGeneration == other->Generation();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
WebGLContext *mContext;
|
|
|
|
PRUint32 mContextGeneration;
|
|
|
|
};
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
#define WEBGLBUFFER_PRIVATE_IID \
|
|
|
|
{0xd69f22e9, 0x6f98, 0x48bd, {0xb6, 0x94, 0x34, 0x17, 0xed, 0x06, 0x11, 0xab}}
|
2009-09-02 17:47:49 -07:00
|
|
|
class WebGLBuffer :
|
|
|
|
public nsIWebGLBuffer,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLZeroingObject,
|
|
|
|
public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLBUFFER_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLBuffer(WebGLContext *context, WebGLuint name) :
|
|
|
|
WebGLContextBoundObject(context),
|
|
|
|
mName(name), mDeleted(PR_FALSE),
|
|
|
|
mByteLength(0), mTarget(LOCAL_GL_NONE), mData(nsnull)
|
2009-09-02 17:47:49 -07:00
|
|
|
{ }
|
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
~WebGLBuffer() {
|
|
|
|
Delete();
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
void Delete() {
|
|
|
|
if (mDeleted)
|
|
|
|
return;
|
|
|
|
ZeroOwners();
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
free(mData);
|
|
|
|
mData = nsnull;
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
mDeleted = PR_TRUE;
|
2010-01-22 13:34:25 -08:00
|
|
|
mByteLength = 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
PRBool Deleted() const { return mDeleted; }
|
|
|
|
GLuint GLName() const { return mName; }
|
|
|
|
GLuint ByteLength() const { return mByteLength; }
|
|
|
|
GLenum Target() const { return mTarget; }
|
|
|
|
const void *Data() const { return mData; }
|
|
|
|
|
|
|
|
void SetByteLength(GLuint byteLength) { mByteLength = byteLength; }
|
|
|
|
void SetTarget(GLenum target) { mTarget = target; }
|
|
|
|
|
|
|
|
// element array buffers are the only buffers for which we need to keep a copy of the data.
|
|
|
|
// this method assumes that the byte length has previously been set by calling SetByteLength.
|
|
|
|
void CopyDataIfElementArray(const void* data) {
|
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
mData = realloc(mData, mByteLength);
|
|
|
|
memcpy(mData, data, mByteLength);
|
|
|
|
}
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
// same comments as for CopyElementArrayData
|
|
|
|
void ZeroDataIfElementArray() {
|
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
mData = realloc(mData, mByteLength);
|
|
|
|
memset(mData, 0, mByteLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// same comments as for CopyElementArrayData
|
|
|
|
void CopySubDataIfElementArray(GLuint byteOffset, GLuint byteLength, const void* data) {
|
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
memcpy((void*) (size_t(mData)+byteOffset), data, byteLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// this method too is only for element array buffers. It returns the maximum value in the part of
|
|
|
|
// the buffer starting at given offset, consisting of given count of elements. The type T is the type
|
|
|
|
// to interprete the array elements as, must be GLushort or GLubyte.
|
|
|
|
template<typename T>
|
|
|
|
T FindMaximum(GLuint count, GLuint byteOffset)
|
|
|
|
{
|
|
|
|
const T* start = reinterpret_cast<T*>(reinterpret_cast<size_t>(mData) + byteOffset);
|
|
|
|
const T* stop = start + count;
|
|
|
|
T result = 0;
|
|
|
|
for(const T* ptr = start; ptr != stop; ++ptr) {
|
|
|
|
if (*ptr > result) result = *ptr;
|
|
|
|
}
|
|
|
|
return result;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLBUFFER
|
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mName;
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool mDeleted;
|
2010-06-01 23:09:18 -07:00
|
|
|
GLuint mByteLength;
|
|
|
|
GLenum mTarget;
|
|
|
|
void* mData; // in the case of an Element Array Buffer, we keep a copy.
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLBuffer, WEBGLBUFFER_PRIVATE_IID)
|
|
|
|
|
|
|
|
#define WEBGLTEXTURE_PRIVATE_IID \
|
|
|
|
{0x4c19f189, 0x1f86, 0x4e61, {0x96, 0x21, 0x0a, 0x11, 0xda, 0x28, 0x10, 0xdd}}
|
2009-09-02 17:47:49 -07:00
|
|
|
class WebGLTexture :
|
|
|
|
public nsIWebGLTexture,
|
2010-05-15 05:07:30 -07:00
|
|
|
public WebGLZeroingObject,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLRectangleObject,
|
|
|
|
public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLTEXTURE_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLTexture(WebGLContext *context, WebGLuint name) :
|
|
|
|
WebGLContextBoundObject(context),
|
|
|
|
mName(name), mDeleted(PR_FALSE)
|
|
|
|
{ }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
|
|
|
if (mDeleted)
|
|
|
|
return;
|
|
|
|
ZeroOwners();
|
|
|
|
mDeleted = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool Deleted() { return mDeleted; }
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint GLName() { return mName; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLTEXTURE
|
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mName;
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool mDeleted;
|
|
|
|
};
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLTexture, WEBGLTEXTURE_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
#define WEBGLSHADER_PRIVATE_IID \
|
|
|
|
{0x48cce975, 0xd459, 0x4689, {0x83, 0x82, 0x37, 0x82, 0x6e, 0xac, 0xe0, 0xa7}}
|
|
|
|
class WebGLShader :
|
|
|
|
public nsIWebGLShader,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLZeroingObject,
|
|
|
|
public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLSHADER_PRIVATE_IID)
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLShader(WebGLContext *context, WebGLuint name, WebGLenum stype) :
|
|
|
|
WebGLContextBoundObject(context),
|
2010-06-04 12:03:33 -07:00
|
|
|
mName(name), mDeleted(PR_FALSE), mType(stype)
|
|
|
|
{ }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
|
|
|
if (mDeleted)
|
|
|
|
return;
|
|
|
|
ZeroOwners();
|
|
|
|
mDeleted = PR_TRUE;
|
|
|
|
}
|
2010-06-04 12:03:37 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool Deleted() { return mDeleted; }
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint GLName() { return mName; }
|
2010-06-04 12:03:33 -07:00
|
|
|
WebGLenum ShaderType() { return mType; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DECL_NSIWEBGLSHADER
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mName;
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool mDeleted;
|
2010-06-04 12:03:33 -07:00
|
|
|
WebGLenum mType;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLShader, WEBGLSHADER_PRIVATE_IID)
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
#define WEBGLPROGRAM_PRIVATE_IID \
|
|
|
|
{0xb3084a5b, 0xa5b4, 0x4ee0, {0xa0, 0xf0, 0xfb, 0xdd, 0x64, 0xaf, 0x8e, 0x82}}
|
|
|
|
class WebGLProgram :
|
|
|
|
public nsIWebGLProgram,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLZeroingObject,
|
|
|
|
public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLPROGRAM_PRIVATE_IID)
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLProgram(WebGLContext *context, WebGLuint name) :
|
|
|
|
WebGLContextBoundObject(context),
|
2010-06-10 10:45:00 -07:00
|
|
|
mName(name), mDeleted(PR_FALSE), mLinkStatus(PR_FALSE), mGeneration(0),
|
|
|
|
mUniformMaxNameLength(0), mAttribMaxNameLength(0),
|
|
|
|
mUniformCount(0), mAttribCount(0)
|
2010-06-08 14:25:27 -07:00
|
|
|
{
|
|
|
|
mMapUniformLocations.Init();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
|
|
|
if (mDeleted)
|
|
|
|
return;
|
|
|
|
ZeroOwners();
|
|
|
|
mDeleted = PR_TRUE;
|
|
|
|
}
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool Deleted() { return mDeleted; }
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint GLName() { return mName; }
|
2010-06-15 08:49:34 -07:00
|
|
|
const nsTArray<WebGLShader*>& AttachedShaders() const { return mAttachedShaders; }
|
2010-06-04 12:03:33 -07:00
|
|
|
PRBool LinkStatus() { return mLinkStatus; }
|
2010-06-08 14:25:27 -07:00
|
|
|
GLuint Generation() const { return mGeneration; }
|
2010-06-04 12:03:33 -07:00
|
|
|
void SetLinkStatus(PRBool val) { mLinkStatus = val; }
|
|
|
|
|
|
|
|
PRBool ContainsShader(WebGLShader *shader) {
|
|
|
|
return mAttachedShaders.Contains(shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the shader wasn't already attached
|
|
|
|
PRBool AttachShader(WebGLShader *shader) {
|
|
|
|
if (ContainsShader(shader))
|
|
|
|
return PR_FALSE;
|
|
|
|
mAttachedShaders.AppendElement(shader);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the shader was found and removed
|
|
|
|
PRBool DetachShader(WebGLShader *shader) {
|
|
|
|
return mAttachedShaders.RemoveElement(shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool HasBothShaderTypesAttached() {
|
|
|
|
PRBool haveVertex = PR_FALSE;
|
|
|
|
PRBool haveFrag = PR_FALSE;
|
|
|
|
for (PRUint32 i = 0; i < mAttachedShaders.Length(); ++i) {
|
|
|
|
if (mAttachedShaders[i]->ShaderType() == LOCAL_GL_FRAGMENT_SHADER)
|
|
|
|
haveFrag = PR_TRUE;
|
|
|
|
else if (mAttachedShaders[i]->ShaderType() == LOCAL_GL_VERTEX_SHADER)
|
|
|
|
haveVertex = PR_TRUE;
|
|
|
|
if (haveFrag && haveVertex)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-08 14:25:27 -07:00
|
|
|
PRBool NextGeneration()
|
|
|
|
{
|
|
|
|
GLuint nextGeneration = mGeneration + 1;
|
|
|
|
if (nextGeneration == 0)
|
|
|
|
return PR_FALSE; // must exit without changing mGeneration
|
|
|
|
mGeneration = nextGeneration;
|
|
|
|
mMapUniformLocations.Clear();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLUniformLocation> GetUniformLocationObject(GLint glLocation);
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
/* Called only after LinkProgram */
|
|
|
|
PRBool UpdateInfo(gl::GLContext *gl);
|
|
|
|
|
|
|
|
/* Getters for cached program info */
|
|
|
|
WebGLint UniformMaxNameLength() const { return mUniformMaxNameLength; }
|
|
|
|
WebGLint AttribMaxNameLength() const { return mAttribMaxNameLength; }
|
|
|
|
WebGLint UniformCount() const { return mUniformCount; }
|
|
|
|
WebGLint AttribCount() const { return mAttribCount; }
|
|
|
|
bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; }
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DECL_NSIWEBGLPROGRAM
|
2009-09-02 17:47:49 -07:00
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mName;
|
2010-06-04 12:03:33 -07:00
|
|
|
PRPackedBool mDeleted;
|
|
|
|
PRPackedBool mLinkStatus;
|
|
|
|
nsTArray<WebGLShader*> mAttachedShaders;
|
2010-06-08 14:25:27 -07:00
|
|
|
nsRefPtrHashtable<nsUint32HashKey, WebGLUniformLocation> mMapUniformLocations;
|
|
|
|
GLuint mGeneration;
|
2010-06-10 10:45:00 -07:00
|
|
|
GLint mUniformMaxNameLength;
|
|
|
|
GLint mAttribMaxNameLength;
|
|
|
|
GLint mUniformCount;
|
|
|
|
GLint mAttribCount;
|
|
|
|
std::vector<bool> mAttribsInUse;
|
2009-09-02 17:47:49 -07:00
|
|
|
};
|
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLProgram, WEBGLPROGRAM_PRIVATE_IID)
|
2010-05-19 13:46:08 -07:00
|
|
|
|
|
|
|
#define WEBGLFRAMEBUFFER_PRIVATE_IID \
|
|
|
|
{0x0052a16f, 0x4bc9, 0x4a55, {0x9d, 0xa3, 0x54, 0x95, 0xaa, 0x4e, 0x80, 0xb9}}
|
2009-09-02 17:47:49 -07:00
|
|
|
class WebGLFramebuffer :
|
|
|
|
public nsIWebGLFramebuffer,
|
2010-05-15 05:07:30 -07:00
|
|
|
public WebGLZeroingObject,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLRectangleObject,
|
|
|
|
public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLFRAMEBUFFER_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLFramebuffer(WebGLContext *context, WebGLuint name) :
|
|
|
|
WebGLContextBoundObject(context),
|
|
|
|
mName(name), mDeleted(PR_FALSE)
|
|
|
|
{ }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
|
|
|
if (mDeleted)
|
|
|
|
return;
|
|
|
|
ZeroOwners();
|
|
|
|
mDeleted = PR_TRUE;
|
|
|
|
}
|
|
|
|
PRBool Deleted() { return mDeleted; }
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint GLName() { return mName; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLFRAMEBUFFER
|
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mName;
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool mDeleted;
|
|
|
|
};
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLFramebuffer, WEBGLFRAMEBUFFER_PRIVATE_IID)
|
|
|
|
|
|
|
|
#define WEBGLRENDERBUFFER_PRIVATE_IID \
|
|
|
|
{0x3cbc2067, 0x5831, 0x4e3f, {0xac, 0x52, 0x7e, 0xf4, 0x5c, 0x04, 0xff, 0xae}}
|
2009-09-02 17:47:49 -07:00
|
|
|
class WebGLRenderbuffer :
|
|
|
|
public nsIWebGLRenderbuffer,
|
2010-05-15 05:07:30 -07:00
|
|
|
public WebGLZeroingObject,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLRectangleObject,
|
|
|
|
public WebGLContextBoundObject
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLRENDERBUFFER_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLRenderbuffer(WebGLContext *context, WebGLuint name) :
|
|
|
|
WebGLContextBoundObject(context),
|
|
|
|
mName(name), mDeleted(PR_FALSE)
|
|
|
|
{ }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
void Delete() {
|
|
|
|
if (mDeleted)
|
|
|
|
return;
|
|
|
|
ZeroOwners();
|
|
|
|
mDeleted = PR_TRUE;
|
|
|
|
}
|
|
|
|
PRBool Deleted() { return mDeleted; }
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint GLName() { return mName; }
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLRENDERBUFFER
|
|
|
|
protected:
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLuint mName;
|
2009-09-02 17:47:49 -07:00
|
|
|
PRBool mDeleted;
|
|
|
|
};
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLRenderbuffer, WEBGLRENDERBUFFER_PRIVATE_IID)
|
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
#define WEBGLUNIFORMLOCATION_PRIVATE_IID \
|
|
|
|
{0x01a8a614, 0xb109, 0x42f1, {0xb4, 0x40, 0x8d, 0x8b, 0x87, 0x0b, 0x43, 0xa7}}
|
|
|
|
class WebGLUniformLocation :
|
|
|
|
public nsIWebGLUniformLocation,
|
2010-06-04 12:03:37 -07:00
|
|
|
public WebGLZeroingObject,
|
|
|
|
public WebGLContextBoundObject
|
2010-06-01 23:09:19 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(WEBGLUNIFORMLOCATION_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
WebGLUniformLocation(WebGLContext *context, WebGLProgram *program, GLint location) :
|
2010-06-08 14:25:27 -07:00
|
|
|
WebGLContextBoundObject(context), mProgram(program), mProgramGeneration(program->Generation()),
|
|
|
|
mLocation(location) { }
|
2010-06-01 23:09:19 -07:00
|
|
|
|
|
|
|
WebGLProgram *Program() const { return mProgram; }
|
|
|
|
GLint Location() const { return mLocation; }
|
2010-06-08 14:25:27 -07:00
|
|
|
GLuint ProgramGeneration() const { return mProgramGeneration; }
|
2010-06-01 23:09:19 -07:00
|
|
|
|
|
|
|
// needed for our generic helpers to check nsIxxx parameters, see GetConcreteObject.
|
|
|
|
PRBool Deleted() { return PR_FALSE; }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBGLUNIFORMLOCATION
|
|
|
|
protected:
|
|
|
|
WebGLObjectRefPtr<WebGLProgram> mProgram;
|
2010-06-08 14:25:27 -07:00
|
|
|
GLuint mProgramGeneration;
|
2010-06-01 23:09:19 -07:00
|
|
|
GLint mLocation;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(WebGLUniformLocation, WEBGLUNIFORMLOCATION_PRIVATE_IID)
|
|
|
|
|
2010-06-04 12:03:37 -07:00
|
|
|
/**
|
|
|
|
** Template implementations
|
|
|
|
**/
|
|
|
|
|
|
|
|
/* Helper function taking a BaseInterfaceType pointer and check that
|
|
|
|
* it matches the required concrete implementation type (if it's
|
|
|
|
* non-null), that it's not null/deleted unless we allowed it to, and
|
|
|
|
* obtain a pointer to the concrete object.
|
|
|
|
*
|
|
|
|
* By default, null (respectively: deleted) aInterface pointers are
|
|
|
|
* not allowed, but if you pass a non-null isNull (respectively:
|
|
|
|
* isDeleted) pointer, then they become allowed and the value at
|
|
|
|
* isNull (respecively isDeleted) is overwritten. In case of a null
|
|
|
|
* pointer, the resulting
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool
|
|
|
|
WebGLContext::GetConcreteObject(BaseInterfaceType *aInterface,
|
|
|
|
ConcreteObjectType **aConcreteObject,
|
|
|
|
PRBool *isNull,
|
|
|
|
PRBool *isDeleted)
|
|
|
|
{
|
|
|
|
if (!aInterface) {
|
|
|
|
if (NS_LIKELY(isNull)) {
|
|
|
|
// non-null isNull means that the caller will accept a null arg
|
|
|
|
*isNull = PR_TRUE;
|
|
|
|
if(isDeleted) *isDeleted = PR_FALSE;
|
|
|
|
*aConcreteObject = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
LogMessage("Null object passed to WebGL function");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNull)
|
|
|
|
*isNull = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<ConcreteObjectType> tmp(do_QueryInterface(aInterface, &rv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
*aConcreteObject = tmp;
|
|
|
|
|
|
|
|
if (!(*aConcreteObject)->IsCompatibleWithContext(this)) {
|
|
|
|
// the object doesn't belong to this WebGLContext
|
|
|
|
LogMessage("Object from different WebGL context given as argument (or older generation of this one)");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*aConcreteObject)->Deleted()) {
|
|
|
|
if (NS_LIKELY(isDeleted)) {
|
|
|
|
// non-null isDeleted means that the caller will accept a deleted arg
|
|
|
|
*isDeleted = PR_TRUE;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
LogMessage("Deleted object passed to WebGL function");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDeleted)
|
|
|
|
*isDeleted = PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same as GetConcreteObject, and in addition gets the GL object name.
|
|
|
|
* Null objects give the name 0.
|
|
|
|
*/
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool
|
|
|
|
WebGLContext::GetConcreteObjectAndGLName(BaseInterfaceType *aInterface,
|
|
|
|
ConcreteObjectType **aConcreteObject,
|
|
|
|
WebGLuint *aGLObjectName,
|
|
|
|
PRBool *isNull,
|
|
|
|
PRBool *isDeleted)
|
|
|
|
{
|
|
|
|
PRBool result = GetConcreteObject(aInterface, aConcreteObject, isNull, isDeleted);
|
|
|
|
if (result == PR_FALSE) return PR_FALSE;
|
|
|
|
*aGLObjectName = *aConcreteObject ? (*aConcreteObject)->GLName() : 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same as GetConcreteObjectAndGLName when you don't need the concrete object pointer.
|
|
|
|
*/
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool
|
|
|
|
WebGLContext::GetGLName(BaseInterfaceType *aInterface,
|
|
|
|
WebGLuint *aGLObjectName,
|
|
|
|
PRBool *isNull,
|
|
|
|
PRBool *isDeleted)
|
|
|
|
{
|
|
|
|
ConcreteObjectType *aConcreteObject;
|
|
|
|
return GetConcreteObjectAndGLName(aInterface, &aConcreteObject, aGLObjectName, isNull, isDeleted);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same as GetConcreteObject when you only want to check if the conversion succeeds.
|
|
|
|
*/
|
|
|
|
template<class ConcreteObjectType, class BaseInterfaceType>
|
|
|
|
PRBool
|
|
|
|
WebGLContext::CheckConversion(BaseInterfaceType *aInterface,
|
|
|
|
PRBool *isNull,
|
|
|
|
PRBool *isDeleted)
|
|
|
|
{
|
|
|
|
ConcreteObjectType *aConcreteObject;
|
|
|
|
return GetConcreteObject(aInterface, &aConcreteObject, isNull, isDeleted);
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|