mirror of https://github.com/axmolengine/axmol.git
remove unneeded function and rename function to more readable
This commit is contained in:
parent
375f52fc87
commit
7ca39dd08e
|
@ -73,9 +73,9 @@ MeshIndexData::MeshIndexData()
|
|||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom*){
|
||||
_indexBuffer->reloadBufferData((void*)_indexData.data(), _indexData.size() * sizeof(_indexData[0]));
|
||||
_indexBuffer->updateData((void*)_indexData.data(), _indexData.size() * sizeof(_indexData[0]));
|
||||
});
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
|
|||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
vertexdata->setVertexData(meshdata.vertex);
|
||||
vertexdata->_vertexBuffer->needReloadExternal(true);
|
||||
vertexdata->_vertexBuffer->usingDefaultStoredData(false);
|
||||
#endif
|
||||
vertexdata->_vertexBuffer->updateData((void*)&meshdata.vertex[0], meshdata.vertex.size() * sizeof(meshdata.vertex[0]));
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
|
|||
auto& index = meshdata.subMeshIndices[i];
|
||||
auto indexBuffer = backend::Device::getInstance()->newBuffer(index.size() * sizeof(index[0]), backend::BufferType::INDEX, backend::BufferUsage::STATIC);
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
indexBuffer->needReloadExternal(true);
|
||||
indexBuffer->usingDefaultStoredData(false);
|
||||
#endif
|
||||
indexBuffer->updateData((void*)index.data(), index.size() * sizeof(index[0]));
|
||||
|
||||
|
@ -179,9 +179,9 @@ MeshVertexData::MeshVertexData()
|
|||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom*){
|
||||
_vertexBuffer->reloadBufferData((void*)_vertexData.data(), _vertexData.size() * sizeof(_vertexData[0]));
|
||||
_vertexBuffer->updateData((void*)_vertexData.data(), _vertexData.size() * sizeof(_vertexData[0]));
|
||||
});
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,13 @@ class Buffer : public cocos2d::Ref
|
|||
public:
|
||||
virtual void updateData(void* data, unsigned int size) = 0;
|
||||
virtual void updateSubData(void* data, unsigned int offset, unsigned int size) = 0;
|
||||
|
||||
|
||||
/*
|
||||
* By default, static buffer data will automatically stored when it comes to foreground.
|
||||
* This function is used to indicate whether external data needs to be used to update the buffer instead of using the default stored data.
|
||||
*/
|
||||
virtual void usingDefaultStoredData(bool needDefaultStoredData) = 0;
|
||||
|
||||
unsigned int getSize() const { return _size; }
|
||||
|
||||
protected:
|
||||
|
@ -27,19 +33,10 @@ protected:
|
|||
{}
|
||||
|
||||
virtual ~Buffer() = default;
|
||||
|
||||
//using external data to reload buffer when it comes to foreground
|
||||
virtual void reloadBufferData(void* data, unsigned int size) = 0;
|
||||
|
||||
//true means reload data ouside the buffer, otherwise reload data from the inside of the buffer.
|
||||
virtual void needReloadExternal(bool needReloadExternal) = 0;
|
||||
|
||||
BufferUsage _usage = BufferUsage::DYNAMIC;
|
||||
BufferType _type = BufferType::VERTEX;
|
||||
unsigned int _size = 0;
|
||||
|
||||
friend class cocos2d::MeshVertexData;
|
||||
friend class cocos2d::MeshIndexData;
|
||||
};
|
||||
|
||||
CC_BACKEND_END
|
||||
|
|
|
@ -13,14 +13,13 @@ public:
|
|||
|
||||
virtual void updateData(void* data, unsigned int size) override;
|
||||
virtual void updateSubData(void* data, unsigned int offset, unsigned int size) override;
|
||||
virtual void usingDefaultStoredData(bool needDefaultStoredData) override {};
|
||||
|
||||
id<MTLBuffer> getMTLBuffer() const;
|
||||
void beginFrame();
|
||||
|
||||
private:
|
||||
void updateIndex();
|
||||
virtual void reloadBufferData(void* data, unsigned int size) override {}
|
||||
virtual void needReloadExternal(bool needReloadExternal) override {}
|
||||
|
||||
id<MTLBuffer> _mtlBuffer = nil;
|
||||
NSMutableArray* _dynamicDataBuffers = nil;
|
||||
|
|
|
@ -31,36 +31,28 @@ BufferGL::~BufferGL()
|
|||
#endif
|
||||
}
|
||||
|
||||
void BufferGL::reloadBufferData(void* data, unsigned int size)
|
||||
void BufferGL::usingDefaultStoredData(bool needDefaultStoredData)
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
assert(_bufferAllocated == size);
|
||||
glGenBuffers(1, &_buffer);
|
||||
updateData(data, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BufferGL::needReloadExternal(bool needReloadExternal)
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
_needReloadExternal = needReloadExternal;
|
||||
_needDefaultStoredData = needDefaultStoredData;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
void BufferGL::reloadBuffer()
|
||||
{
|
||||
if(_needReloadExternal)
|
||||
glGenBuffers(1, &_buffer);
|
||||
|
||||
if(!_needDefaultStoredData)
|
||||
return;
|
||||
|
||||
_bufferAlreadyFilled = true;
|
||||
glGenBuffers(1, &_buffer);
|
||||
updateData(_data, _bufferAllocated);
|
||||
}
|
||||
|
||||
void BufferGL::fillBuffer(void* data, unsigned int offset, unsigned int size)
|
||||
{
|
||||
if(_bufferAlreadyFilled || _needReloadExternal || BufferUsage::STATIC != _usage)
|
||||
if(_bufferAlreadyFilled || !_needDefaultStoredData || BufferUsage::STATIC != _usage)
|
||||
return;
|
||||
|
||||
if(_data == nullptr)
|
||||
|
|
|
@ -16,13 +16,10 @@ public:
|
|||
|
||||
virtual void updateData(void* data, unsigned int size) override;
|
||||
virtual void updateSubData(void* data, unsigned int offset, unsigned int size) override;
|
||||
virtual void usingDefaultStoredData(bool needDefaultStoredData) override ;
|
||||
|
||||
inline GLuint getHandler() const { return _buffer; }
|
||||
|
||||
private:
|
||||
virtual void reloadBufferData(void* data, unsigned int size) override ;
|
||||
virtual void needReloadExternal(bool needReloadExternal) override ;
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
void reloadBuffer();
|
||||
void fillBuffer(void* data, unsigned int offset, unsigned int size);
|
||||
|
@ -34,7 +31,7 @@ private:
|
|||
GLuint _buffer = 0;
|
||||
unsigned int _bufferAllocated = 0;
|
||||
char* _data = nullptr;
|
||||
bool _needReloadExternal = false;
|
||||
bool _needDefaultStoredData = true;
|
||||
};
|
||||
|
||||
CC_BACKEND_END
|
||||
|
|
Loading…
Reference in New Issue