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>
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
#include "CacheMap.h"
|
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-10-21 01:40:12 +03:00
|
|
|
Maybe<uint32_t> GetIndexedFetchMaxVert(GLenum type, uint64_t byteOffset,
|
|
|
|
uint32_t indexCount) 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;
|
2017-10-21 01:40:12 +03:00
|
|
|
buffer->mFetchInvalidator.InvalidateCaches();
|
2016-12-29 11:08:39 +03:00
|
|
|
} 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-10-21 01:40:12 +03:00
|
|
|
void InvalidateCacheRange(uint64_t byteOffset, uint64_t byteLength) const;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
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-12-21 03:31:58 +03:00
|
|
|
mutable uint64_t mLastUpdateFenceId = 0;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
struct IndexRange final {
|
|
|
|
GLenum type;
|
2017-10-21 01:40:12 +03:00
|
|
|
uint64_t byteOffset;
|
|
|
|
uint32_t indexCount;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
bool operator<(const IndexRange& x) const {
|
|
|
|
if (type != x.type)
|
|
|
|
return type < x.type;
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
if (byteOffset != x.byteOffset)
|
|
|
|
return byteOffset < x.byteOffset;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
return indexCount < x.indexCount;
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UniqueBuffer mIndexCache;
|
2017-10-21 01:40:12 +03:00
|
|
|
mutable std::map<IndexRange, Maybe<uint32_t>> mIndexRanges;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CacheMapInvalidator mFetchInvalidator;
|
2017-12-21 03:31:58 +03:00
|
|
|
|
|
|
|
void ResetLastUpdateFenceId() const;
|
2012-11-21 01:38:20 +04:00
|
|
|
};
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // WEBGL_BUFFER_H_
|