1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGL_BUFFER_H_
7 #define WEBGL_BUFFER_H_
11 #include "CacheInvalidator.h"
13 #include "WebGLObjectModel.h"
14 #include "WebGLTypes.h"
18 class WebGLBuffer final
: public WebGLContextBoundObject
{
19 friend class WebGLContext
;
20 friend class WebGL2Context
;
21 friend class WebGLMemoryTracker
;
22 friend class WebGLTexture
;
24 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLBuffer
, override
)
27 enum class Kind
{ Undefined
, ElementArray
, OtherData
};
29 WebGLBuffer(WebGLContext
* webgl
, GLuint buf
);
31 void SetContentAfterBind(GLenum target
);
32 Kind
Content() const { return mContent
; }
34 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf
) const;
36 GLenum
Usage() const { return mUsage
; }
37 size_t ByteLength() const { return mByteLength
; }
39 Maybe
<uint32_t> GetIndexedFetchMaxVert(GLenum type
, uint64_t byteOffset
,
40 uint32_t indexCount
) const;
41 bool ValidateRange(size_t byteOffset
, size_t byteLen
) const;
43 bool ValidateCanBindToTarget(GLenum target
);
44 void BufferData(GLenum target
, uint64_t size
, const void* data
, GLenum usage
,
45 bool allowUninitialized
= false);
46 void BufferSubData(GLenum target
, uint64_t dstByteOffset
, uint64_t dataLen
,
47 const void* data
, bool unsynchronized
= false) const;
54 ~WebGLBuffer() override
;
56 void InvalidateCacheRange(uint64_t byteOffset
, uint64_t byteLength
) const;
58 Kind mContent
= Kind::Undefined
;
59 GLenum mUsage
= LOCAL_GL_STATIC_DRAW
;
60 size_t mByteLength
= 0;
61 mutable uint64_t mLastUpdateFenceId
= 0;
63 struct IndexRange final
{
68 bool operator<(const IndexRange
& x
) const {
69 if (type
!= x
.type
) return type
< x
.type
;
71 if (byteOffset
!= x
.byteOffset
) return byteOffset
< x
.byteOffset
;
73 return indexCount
< x
.indexCount
;
77 UniqueBuffer mIndexCache
;
78 mutable std::map
<IndexRange
, Maybe
<uint32_t>> mIndexRanges
;
81 CacheInvalidator mFetchInvalidator
;
83 void ResetLastUpdateFenceId() const;
86 } // namespace mozilla
88 #endif // WEBGL_BUFFER_H_