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
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom*){
|
_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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
|
||||||
{
|
{
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
vertexdata->setVertexData(meshdata.vertex);
|
vertexdata->setVertexData(meshdata.vertex);
|
||||||
vertexdata->_vertexBuffer->needReloadExternal(true);
|
vertexdata->_vertexBuffer->usingDefaultStoredData(false);
|
||||||
#endif
|
#endif
|
||||||
vertexdata->_vertexBuffer->updateData((void*)&meshdata.vertex[0], meshdata.vertex.size() * sizeof(meshdata.vertex[0]));
|
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& index = meshdata.subMeshIndices[i];
|
||||||
auto indexBuffer = backend::Device::getInstance()->newBuffer(index.size() * sizeof(index[0]), backend::BufferType::INDEX, backend::BufferUsage::STATIC);
|
auto indexBuffer = backend::Device::getInstance()->newBuffer(index.size() * sizeof(index[0]), backend::BufferType::INDEX, backend::BufferUsage::STATIC);
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
indexBuffer->needReloadExternal(true);
|
indexBuffer->usingDefaultStoredData(false);
|
||||||
#endif
|
#endif
|
||||||
indexBuffer->updateData((void*)index.data(), index.size() * sizeof(index[0]));
|
indexBuffer->updateData((void*)index.data(), index.size() * sizeof(index[0]));
|
||||||
|
|
||||||
|
@ -179,9 +179,9 @@ MeshVertexData::MeshVertexData()
|
||||||
{
|
{
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom*){
|
_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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,12 @@ public:
|
||||||
virtual void updateData(void* data, unsigned int size) = 0;
|
virtual void updateData(void* data, unsigned int size) = 0;
|
||||||
virtual void updateSubData(void* data, unsigned int offset, 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; }
|
unsigned int getSize() const { return _size; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -28,18 +34,9 @@ protected:
|
||||||
|
|
||||||
virtual ~Buffer() = default;
|
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;
|
BufferUsage _usage = BufferUsage::DYNAMIC;
|
||||||
BufferType _type = BufferType::VERTEX;
|
BufferType _type = BufferType::VERTEX;
|
||||||
unsigned int _size = 0;
|
unsigned int _size = 0;
|
||||||
|
|
||||||
friend class cocos2d::MeshVertexData;
|
|
||||||
friend class cocos2d::MeshIndexData;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CC_BACKEND_END
|
CC_BACKEND_END
|
||||||
|
|
|
@ -13,14 +13,13 @@ public:
|
||||||
|
|
||||||
virtual void updateData(void* data, unsigned int size) override;
|
virtual void updateData(void* data, unsigned int size) override;
|
||||||
virtual void updateSubData(void* data, unsigned int offset, 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;
|
id<MTLBuffer> getMTLBuffer() const;
|
||||||
void beginFrame();
|
void beginFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateIndex();
|
void updateIndex();
|
||||||
virtual void reloadBufferData(void* data, unsigned int size) override {}
|
|
||||||
virtual void needReloadExternal(bool needReloadExternal) override {}
|
|
||||||
|
|
||||||
id<MTLBuffer> _mtlBuffer = nil;
|
id<MTLBuffer> _mtlBuffer = nil;
|
||||||
NSMutableArray* _dynamicDataBuffers = nil;
|
NSMutableArray* _dynamicDataBuffers = nil;
|
||||||
|
|
|
@ -31,36 +31,28 @@ BufferGL::~BufferGL()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferGL::reloadBufferData(void* data, unsigned int size)
|
void BufferGL::usingDefaultStoredData(bool needDefaultStoredData)
|
||||||
{
|
{
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
assert(_bufferAllocated == size);
|
_needDefaultStoredData = needDefaultStoredData;
|
||||||
glGenBuffers(1, &_buffer);
|
|
||||||
updateData(data, size);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void BufferGL::needReloadExternal(bool needReloadExternal)
|
|
||||||
{
|
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
|
||||||
_needReloadExternal = needReloadExternal;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
void BufferGL::reloadBuffer()
|
void BufferGL::reloadBuffer()
|
||||||
{
|
{
|
||||||
if(_needReloadExternal)
|
glGenBuffers(1, &_buffer);
|
||||||
|
|
||||||
|
if(!_needDefaultStoredData)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_bufferAlreadyFilled = true;
|
_bufferAlreadyFilled = true;
|
||||||
glGenBuffers(1, &_buffer);
|
|
||||||
updateData(_data, _bufferAllocated);
|
updateData(_data, _bufferAllocated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferGL::fillBuffer(void* data, unsigned int offset, unsigned int size)
|
void BufferGL::fillBuffer(void* data, unsigned int offset, unsigned int size)
|
||||||
{
|
{
|
||||||
if(_bufferAlreadyFilled || _needReloadExternal || BufferUsage::STATIC != _usage)
|
if(_bufferAlreadyFilled || !_needDefaultStoredData || BufferUsage::STATIC != _usage)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(_data == nullptr)
|
if(_data == nullptr)
|
||||||
|
|
|
@ -16,13 +16,10 @@ public:
|
||||||
|
|
||||||
virtual void updateData(void* data, unsigned int size) override;
|
virtual void updateData(void* data, unsigned int size) override;
|
||||||
virtual void updateSubData(void* data, unsigned int offset, 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; }
|
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
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
void reloadBuffer();
|
void reloadBuffer();
|
||||||
void fillBuffer(void* data, unsigned int offset, unsigned int size);
|
void fillBuffer(void* data, unsigned int offset, unsigned int size);
|
||||||
|
@ -34,7 +31,7 @@ private:
|
||||||
GLuint _buffer = 0;
|
GLuint _buffer = 0;
|
||||||
unsigned int _bufferAllocated = 0;
|
unsigned int _bufferAllocated = 0;
|
||||||
char* _data = nullptr;
|
char* _data = nullptr;
|
||||||
bool _needReloadExternal = false;
|
bool _needDefaultStoredData = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
CC_BACKEND_END
|
CC_BACKEND_END
|
||||||
|
|
Loading…
Reference in New Issue