2012-11-21 01:38:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#ifndef WEBGL_BUFFER_H_
|
|
|
|
#define WEBGL_BUFFER_H_
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
#include <map>
|
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
#include "GLDefs.h"
|
2012-11-21 01:38:20 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "WebGLObjectModel.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLTypes.h"
|
2012-11-21 01:38:20 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class WebGLBuffer final
|
2013-08-29 19:39:17 +04:00
|
|
|
: public nsWrapperCache
|
2012-11-21 01:38:20 +04:00
|
|
|
, public WebGLRefCountedObject<WebGLBuffer>
|
|
|
|
, public LinkedListElement<WebGLBuffer>
|
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
friend class WebGLContext;
|
|
|
|
friend class WebGL2Context;
|
|
|
|
friend class WebGLTexture;
|
2015-05-21 02:59:14 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
public:
|
2015-05-21 02:59:14 +03:00
|
|
|
enum class Kind {
|
|
|
|
Undefined,
|
|
|
|
ElementArray,
|
|
|
|
OtherData
|
|
|
|
};
|
|
|
|
|
2016-07-22 09:29:19 +03:00
|
|
|
WebGLBuffer(WebGLContext* webgl, GLuint buf);
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
void SetContentAfterBind(GLenum target);
|
2015-05-21 02:59:14 +03:00
|
|
|
Kind Content() const { return mContent; }
|
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
void Delete();
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2016-09-28 00:03:48 +03:00
|
|
|
GLenum Usage() const { return mUsage; }
|
2016-09-10 07:02:54 +03:00
|
|
|
size_t ByteLength() const { return mByteLength; }
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
bool ValidateIndexedFetch(GLenum type, uint32_t max_allowed, size_t first, size_t count) const;
|
2016-10-12 03:37:29 +03:00
|
|
|
bool ValidateRange(const char* funcName, size_t byteOffset, size_t byteLen) const;
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext* GetParentObject() const {
|
2015-11-25 07:15:29 +03:00
|
|
|
return mContext;
|
2015-01-16 02:40:39 +03:00
|
|
|
}
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2016-09-18 02:44:56 +03:00
|
|
|
bool ValidateCanBindToTarget(const char* funcName, GLenum target);
|
2016-09-10 07:02:54 +03:00
|
|
|
void BufferData(GLenum target, size_t size, const void* data, GLenum usage);
|
2017-02-10 07:32:58 +03:00
|
|
|
void BufferSubData(GLenum target, size_t dstByteOffset, size_t dataLen,
|
|
|
|
const void* data) const;
|
2016-09-10 07:02:54 +03:00
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
static void AddBindCount(GLenum target, WebGLBuffer* buffer, int8_t addVal) {
|
|
|
|
if (!buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER) {
|
|
|
|
MOZ_ASSERT_IF(addVal < 0, buffer->mTFBindCount >= size_t(-addVal));
|
|
|
|
buffer->mTFBindCount += addVal;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_IF(addVal < 0, buffer->mNonTFBindCount >= size_t(-addVal));
|
|
|
|
buffer->mNonTFBindCount += addVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetSlot(GLenum target, WebGLBuffer* newBuffer,
|
|
|
|
WebGLRefPtr<WebGLBuffer>* const out_slot)
|
|
|
|
{
|
|
|
|
WebGLBuffer* const oldBuffer = *out_slot;
|
|
|
|
AddBindCount(target, oldBuffer, -1);
|
|
|
|
AddBindCount(target, newBuffer, +1);
|
|
|
|
*out_slot = newBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsBoundForTF() const { return bool(mTFBindCount); }
|
|
|
|
bool IsBoundForNonTF() const { return bool(mNonTFBindCount); }
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2015-05-22 08:49:30 +03:00
|
|
|
const GLenum mGLName;
|
|
|
|
|
2013-08-29 19:39:17 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLBuffer)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLBuffer)
|
2012-11-21 01:38:20 +04:00
|
|
|
|
|
|
|
protected:
|
2014-06-26 17:30:49 +04:00
|
|
|
~WebGLBuffer();
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
void InvalidateCacheRange(size_t offset, size_t length) const;
|
|
|
|
|
2015-05-21 02:59:14 +03:00
|
|
|
Kind mContent;
|
2016-09-28 00:03:48 +03:00
|
|
|
GLenum mUsage;
|
2016-09-10 07:02:54 +03:00
|
|
|
size_t mByteLength;
|
2016-12-29 11:08:39 +03:00
|
|
|
size_t mTFBindCount;
|
|
|
|
size_t mNonTFBindCount;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
struct IndexRange final {
|
|
|
|
GLenum type;
|
|
|
|
size_t first;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
bool operator<(const IndexRange& x) const {
|
|
|
|
if (type != x.type)
|
|
|
|
return type < x.type;
|
|
|
|
|
|
|
|
if (first != x.first)
|
|
|
|
return first < x.first;
|
|
|
|
|
|
|
|
return count < x.count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UniqueBuffer mIndexCache;
|
|
|
|
mutable std::map<IndexRange, size_t> mIndexRanges;
|
2012-11-21 01:38:20 +04:00
|
|
|
};
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // WEBGL_BUFFER_H_
|