Optimize DrawNode (#2165)

* DrawNode: refactor buffer update

* DrawNode: optimize transform application

* DrawNode: remove unused variables

* DrawNode: use reinterpret_cast

* DrawNode: fix crash on render context loss
This commit is contained in:
smilediver 2024-09-21 18:55:26 +03:00 committed by GitHub
parent f98b776dc0
commit 5c31ecb3c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 180 additions and 217 deletions

View File

@ -72,6 +72,13 @@ static bool isConvex(const Vec2* verts, int count)
return true; // is convex
}
static V2F_C4B_T2F* expandBufferAndGetPointer(axstd::pod_vector<V2F_C4B_T2F>& buffer, size_t count)
{
size_t oldSize = buffer.size();
buffer.expand(count);
return buffer.data() + oldSize;
}
DrawNode::DrawNode(float lineWidth) : _lineWidth(lineWidth), _defaultLineWidth(lineWidth)
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@ -93,13 +100,8 @@ DrawNode::DrawNode(float lineWidth) : _lineWidth(lineWidth), _defaultLineWidth(l
DrawNode::~DrawNode()
{
AX_SAFE_FREE(_bufferTriangle);
freeShaderInternal(_customCommandTriangle);
AX_SAFE_FREE(_bufferPoint);
freeShaderInternal(_customCommandPoint);
AX_SAFE_FREE(_bufferLine);
freeShaderInternal(_customCommandLine);
}
@ -117,62 +119,14 @@ DrawNode* DrawNode::create(float defaultLineWidth)
return ret;
}
void DrawNode::ensureCapacityTriangle(int count)
{
AXASSERT(count >= 0, "capacity must be >= 0");
if (_bufferCountTriangle + count > _bufferCapacityTriangle)
{
_bufferCapacityTriangle += MAX(_bufferCapacityTriangle, count);
_bufferTriangle = (V2F_C4B_T2F*)realloc(_bufferTriangle, _bufferCapacityTriangle * sizeof(V2F_C4B_T2F));
_customCommandTriangle.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityTriangle,
CustomCommand::BufferUsage::STATIC);
_customCommandTriangle.updateVertexBuffer(_bufferTriangle, _bufferCapacityTriangle * sizeof(V2F_C4B_T2F));
}
}
void DrawNode::ensureCapacityPoint(int count)
{
AXASSERT(count >= 0, "capacity must be >= 0");
if (_bufferCountPoint + count > _bufferCapacityPoint)
{
_bufferCapacityPoint += MAX(_bufferCapacityPoint, count);
_bufferPoint = (V2F_C4B_T2F*)realloc(_bufferPoint, _bufferCapacityPoint * sizeof(V2F_C4B_T2F));
_customCommandPoint.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityPoint,
CustomCommand::BufferUsage::STATIC);
_customCommandPoint.updateVertexBuffer(_bufferPoint, _bufferCapacityPoint * sizeof(V2F_C4B_T2F));
}
}
void DrawNode::ensureCapacityLine(int count)
{
AXASSERT(count >= 0, "capacity must be >= 0");
if (_bufferCountLine + count > _bufferCapacityLine)
{
_bufferCapacityLine += MAX(_bufferCapacityLine, count);
_bufferLine = (V2F_C4B_T2F*)realloc(_bufferLine, _bufferCapacityLine * sizeof(V2F_C4B_T2F));
_customCommandLine.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityLine,
CustomCommand::BufferUsage::STATIC);
_customCommandLine.updateVertexBuffer(_bufferLine, _bufferCapacityLine * sizeof(V2F_C4B_T2F));
}
}
bool DrawNode::init()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
updateShader();
ensureCapacityTriangle(512);
_dirtyTriangle = true;
ensureCapacityPoint(64);
ensureCapacityLine(256);
_dirtyLine = true;
_dirtyPoint = true;
_trianglesDirty = true;
_pointsDirty = true;
_linesDirty = true;
return true;
}
@ -253,7 +207,10 @@ void DrawNode::updateUniforms(const Mat4& transform, CustomCommand& cmd)
void DrawNode::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
{
if (_bufferCountTriangle)
if (_trianglesDirty || _pointsDirty || _linesDirty)
updateBuffers();
if (_customCommandTriangle.getVertexDrawCount() > 0)
{
updateBlendState(_customCommandTriangle);
updateUniforms(transform, _customCommandTriangle);
@ -261,7 +218,7 @@ void DrawNode::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
renderer->addCommand(&_customCommandTriangle);
}
if (_bufferCountPoint)
if (_customCommandPoint.getVertexDrawCount() > 0)
{
updateBlendState(_customCommandPoint);
updateUniforms(transform, _customCommandPoint);
@ -269,7 +226,7 @@ void DrawNode::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
renderer->addCommand(&_customCommandPoint);
}
if (_bufferCountLine)
if (_customCommandLine.getVertexDrawCount() > 0)
{
updateBlendState(_customCommandLine);
updateUniforms(transform, _customCommandLine);
@ -278,6 +235,42 @@ void DrawNode::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
}
}
static void udpateCommand(CustomCommand& cmd, const axstd::pod_vector<V2F_C4B_T2F>& buffer)
{
if (buffer.empty())
{
cmd.setVertexBuffer(nullptr);
}
else
{
cmd.createVertexBuffer(sizeof(V2F_C4B_T2F), buffer.size(), CustomCommand::BufferUsage::STATIC);
cmd.updateVertexBuffer(buffer.data(), buffer.size() * sizeof(V2F_C4B_T2F));
}
cmd.setVertexDrawInfo(0, buffer.size());
}
void DrawNode::updateBuffers()
{
if (_trianglesDirty)
{
_trianglesDirty = false;
udpateCommand(_customCommandTriangle, _triangles);
}
if (_pointsDirty)
{
_pointsDirty = false;
udpateCommand(_customCommandPoint, _points);
}
if (_linesDirty)
{
_linesDirty = false;
udpateCommand(_customCommandLine, _lines);
}
}
void DrawNode::drawPoint(const Vec2& position,
const float pointSize,
const Color4B& color,
@ -746,19 +739,19 @@ void DrawNode::drawSolidCircle(const Vec2& center,
_drawCircle(center, radius, angle, segments, false, 1.0f, 1.0f, Color4B(), color, true);
}
void DrawNode::drawTriangle(const Vec2* _vertices3, const Color4B& color)
void DrawNode::drawTriangle(const Vec2* vertices3, const Color4B& color)
{
_drawTriangle(_vertices3, Color4B::TRANSPARENT, color, false, 0.0f);
Vec2 vertices[3] = {vertices3[0], vertices3[1], vertices3[2]};
_drawTriangle(vertices, Color4B::TRANSPARENT, color, false, 0.0f);
}
void DrawNode::drawTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color4B& color)
{
Vec2 _vertices3[3] = {p1, p2, p3};
_drawTriangle(_vertices3, Color4B::TRANSPARENT, color, false, 0.0f);
Vec2 vertices[3] = {p1, p2, p3};
_drawTriangle(vertices, Color4B::TRANSPARENT, color, false, 0.0f);
}
void DrawNode::drawSolidTriangle(const Vec2* _vertices3,
void DrawNode::drawSolidTriangle(const Vec2* vertices3,
const Color4B& fillColor,
const Color4B& borderColor,
float thickness)
@ -768,7 +761,8 @@ void DrawNode::drawSolidTriangle(const Vec2* _vertices3,
AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__);
thickness = 0.0f;
}
_drawTriangle(_vertices3, fillColor, borderColor, true, thickness);
Vec2 vertices[3] = {vertices3[0], vertices3[1], vertices3[2]};
_drawTriangle(vertices, fillColor, borderColor, true, thickness);
}
void DrawNode::drawSolidTriangle(const Vec2& p1,
@ -783,18 +777,19 @@ void DrawNode::drawSolidTriangle(const Vec2& p1,
AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__);
thickness = 0.0f;
}
Vec2 _vertices3[3] = {p1, p2, p3};
_drawTriangle(_vertices3, fillColor, borderColor, false, thickness);
Vec2 vertices[3] = {p1, p2, p3};
_drawTriangle(vertices, fillColor, borderColor, false, thickness);
}
void DrawNode::clear()
{
_bufferCountTriangle = 0;
_dirtyTriangle = true;
_bufferCountLine = 0;
_dirtyLine = true;
_bufferCountPoint = 0;
_dirtyPoint = true;
_trianglesDirty = true;
_pointsDirty = true;
_linesDirty = true;
_triangles.clear();
_points.clear();
_lines.clear();
_lineWidth = _defaultLineWidth;
}
@ -900,8 +895,9 @@ void DrawNode::_drawPolygon(const Vec2* verts,
}
vertex_count *= 3;
ensureCapacityTriangle(vertex_count);
V2F_C4B_T2F_Triangle* triangles = (V2F_C4B_T2F_Triangle*)(_bufferTriangle + _bufferCountTriangle);
auto triangles = reinterpret_cast<V2F_C4B_T2F_Triangle*>(expandBufferAndGetPointer(_triangles, vertex_count));
_trianglesDirty = true;
// start drawing...
int ii = 0;
@ -1028,12 +1024,6 @@ void DrawNode::_drawPolygon(const Vec2* verts,
}
}
}
_customCommandTriangle.updateVertexBuffer(triangles, _bufferCountTriangle * sizeof(V2F_C4B_T2F),
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountTriangle += vertex_count;
_customCommandTriangle.setVertexDrawInfo(0, _bufferCountTriangle);
_dirtyTriangle = true;
}
void DrawNode::_drawPoly(const Vec2* verts,
@ -1049,8 +1039,8 @@ void DrawNode::_drawPoly(const Vec2* verts,
unsigned int vertex_count = (closedPolygon) ? 2 * count : 2 * (count - 1);
ensureCapacityLine(vertex_count);
V2F_C4B_T2F* line = _bufferLine + _bufferCountLine;
auto line = expandBufferAndGetPointer(_lines, vertex_count);
_linesDirty = true;
int ii = 0;
for (unsigned int i = 0; i < count - 1; i++)
@ -1063,11 +1053,6 @@ void DrawNode::_drawPoly(const Vec2* verts,
line[ii++] = {_vertices[count - 1], color, Vec2::ZERO};
line[ii++] = line[0];
}
_customCommandLine.updateVertexBuffer(line, _bufferCountLine * sizeof(V2F_C4B_T2F),
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountLine += vertex_count;
_customCommandLine.setVertexDrawInfo(0, _bufferCountLine);
}
else
{
@ -1082,29 +1067,21 @@ void DrawNode::_drawSegment(const Vec2& from,
DrawNode::EndType etStart,
DrawNode::EndType etEnd)
{
unsigned int count = 2;
Vec2 line[] = {from, to};
auto _vertices = _transform(line, count, false);
Vec2 vertices[2] = {from, to};
applyTransform(vertices, vertices, 2);
if (thickness == 1.0f && !properties.drawOrder)
{
ensureCapacityLine(count);
auto line = expandBufferAndGetPointer(_lines, 2);
_linesDirty = true;
V2F_C4B_T2F* line = _bufferLine + _bufferCountLine;
line[0] = {_vertices[0], color, Vec2::ZERO};
line[1] = {_vertices[1], color, Vec2::ZERO};
_customCommandLine.updateVertexBuffer(line, _bufferCountLine * sizeof(V2F_C4B_T2F), 2 * sizeof(V2F_C4B_T2F));
_bufferCountLine += count;
_dirtyLine = true;
_customCommandLine.setVertexDrawInfo(0, _bufferCountLine);
line[0] = {vertices[0], color, Vec2::ZERO};
line[1] = {vertices[1], color, Vec2::ZERO};
}
else
{
Vec2 a = _vertices[0];
Vec2 b = _vertices[1];
Vec2 a = vertices[0];
Vec2 b = vertices[1];
Vec2 n = ((b - a).getPerp()).getNormalized();
Vec2 t = n.getPerp();
Vec2 nw = n * thickness;
@ -1120,8 +1097,8 @@ void DrawNode::_drawSegment(const Vec2& from,
unsigned int vertex_count = 3 * ((etStart != DrawNode::EndType::Butt) ? 2 : 0) + 3 * 2 +
3 * ((etEnd != DrawNode::EndType::Butt) ? 2 : 0);
ensureCapacityTriangle(vertex_count);
V2F_C4B_T2F_Triangle* triangles = (V2F_C4B_T2F_Triangle*)(_bufferTriangle + _bufferCountTriangle);
auto triangles = reinterpret_cast<V2F_C4B_T2F_Triangle*>(expandBufferAndGetPointer(_triangles, vertex_count));
_trianglesDirty = true;
int ii = 0;
switch (etEnd)
@ -1210,34 +1187,22 @@ void DrawNode::_drawSegment(const Vec2& from,
default:
break;
}
_customCommandTriangle.updateVertexBuffer(triangles, _bufferCountTriangle * sizeof(V2F_C4B_T2F),
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountTriangle += vertex_count; // ii * 3;
_dirtyTriangle = true;
_customCommandTriangle.setVertexDrawInfo(0, _bufferCountTriangle);
}
}
void DrawNode::_drawDot(const Vec2& pos, float radius, const Color4B& color)
{
unsigned int vertex_count = 2 * 3;
ensureCapacityTriangle(vertex_count);
auto triangles = reinterpret_cast<V2F_C4B_T2F_Triangle*>(expandBufferAndGetPointer(_triangles, vertex_count));
_trianglesDirty = true;
V2F_C4B_T2F a = {Vec2(pos.x - radius, pos.y - radius), color, Vec2(-1.0f, -1.0f)};
V2F_C4B_T2F b = {Vec2(pos.x - radius, pos.y + radius), color, Vec2(-1.0f, 1.0f)};
V2F_C4B_T2F c = {Vec2(pos.x + radius, pos.y + radius), color, Vec2(1.0f, 1.0f)};
V2F_C4B_T2F d = {Vec2(pos.x + radius, pos.y - radius), color, Vec2(1.0f, -1.0f)};
V2F_C4B_T2F_Triangle* triangles = (V2F_C4B_T2F_Triangle*)(_bufferTriangle + _bufferCountTriangle);
triangles[0] = {a, b, c};
triangles[1] = {a, c, d};
_customCommandTriangle.updateVertexBuffer(triangles, _bufferCountTriangle * sizeof(V2F_C4B_T2F),
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountTriangle += vertex_count;
_dirtyTriangle = true;
_customCommandTriangle.setVertexDrawInfo(0, _bufferCountTriangle);
triangles[0] = {a, b, c};
triangles[1] = {a, c, d};
}
void DrawNode::_drawCircle(const Vec2& center,
@ -1278,7 +1243,7 @@ void DrawNode::_drawCircle(const Vec2& center,
AX_SAFE_DELETE_ARRAY(_vertices);
}
void DrawNode::_drawTriangle(const Vec2* _vertices3,
void DrawNode::_drawTriangle(Vec2* vertices3,
const Color4B& borderColor,
const Color4B& fillColor,
bool solid,
@ -1288,24 +1253,18 @@ void DrawNode::_drawTriangle(const Vec2* _vertices3,
if (thickness != 0.0f)
{
_drawPolygon(_vertices3, vertex_count, fillColor, borderColor, true, thickness, true);
_drawPolygon(vertices3, vertex_count, fillColor, borderColor, true, thickness, true);
}
else
{
auto _vertices = _transform(_vertices3, vertex_count, false);
applyTransform(vertices3, vertices3, vertex_count);
ensureCapacityTriangle(vertex_count);
auto triangles = reinterpret_cast<V2F_C4B_T2F_Triangle*>(expandBufferAndGetPointer(_triangles, vertex_count));
_trianglesDirty = true;
V2F_C4B_T2F_Triangle* triangles = (V2F_C4B_T2F_Triangle*)(_bufferTriangle + _bufferCountTriangle);
triangles[0] = {{_vertices[0], fillColor, Vec2::ZERO},
{_vertices[1], fillColor, Vec2::ZERO},
{_vertices[2], fillColor, Vec2::ZERO}};
_customCommandTriangle.updateVertexBuffer(triangles, _bufferCountTriangle * sizeof(V2F_C4B_T2F),
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountTriangle += vertex_count;
_dirtyTriangle = true;
_customCommandTriangle.setVertexDrawInfo(0, _bufferCountTriangle);
triangles[0] = {{vertices3[0], fillColor, Vec2::ZERO},
{vertices3[1], fillColor, Vec2::ZERO},
{vertices3[2], fillColor, Vec2::ZERO}};
}
}
@ -1376,19 +1335,14 @@ void DrawNode::_drawPoints(const Vec2* position,
}
return;
}
ensureCapacityPoint(numberOfPoints);
V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint;
auto point = expandBufferAndGetPointer(_points, numberOfPoints);
_pointsDirty = true;
for (unsigned int i = 0; i < numberOfPoints; i++)
{
*(point + i) = {position[i], color, Vec2(pointSize, 0.0f)};
}
_customCommandPoint.updateVertexBuffer(point, _bufferCountPoint * sizeof(V2F_C4B_T2F),
numberOfPoints * sizeof(V2F_C4B_T2F));
_bufferCountPoint += numberOfPoints;
_dirtyPoint = true;
_customCommandPoint.setVertexDrawInfo(0, _bufferCountPoint);
}
void DrawNode::_drawPoint(const Vec2& position,
@ -1434,15 +1388,10 @@ void DrawNode::_drawPoint(const Vec2& position,
}
else
{
ensureCapacityPoint(1);
auto point = expandBufferAndGetPointer(_points, 1);
_pointsDirty = true;
V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint;
*point = {position, color, Vec2(pointSize, 0.0f)};
_customCommandPoint.updateVertexBuffer(point, _bufferCountPoint * sizeof(V2F_C4B_T2F), sizeof(V2F_C4B_T2F));
_bufferCountPoint += 1;
_dirtyPoint = true;
_customCommandPoint.setVertexDrawInfo(0, _bufferCountPoint);
}
}
@ -1562,36 +1511,7 @@ axstd::pod_vector<Vec2> DrawNode::_transform(const Vec2* _vertices, unsigned int
return vert;
}
const float sinRot = sin(properties.rotation);
const float cosRot = cos(properties.rotation);
for (unsigned int i = 0; i < count; i++)
{
if (properties.rotation == 0.0f)
{
vert[i].x = _vertices[i].x * properties.scale.x + properties.position.x;
vert[i].y = _vertices[i].y * properties.scale.y + properties.position.y;
}
else // https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d
{
// translate point back to origin:
vert[i].x = _vertices[i].x - properties.center.x;
vert[i].y = _vertices[i].y - properties.center.y;
// rotate point
float xnew = vert[i].x * cosRot - vert[i].y * sinRot;
float ynew = vert[i].x * sinRot + vert[i].y * cosRot;
// translate point back:
vert[i].x = xnew + properties.center.x;
vert[i].y = ynew + properties.center.y;
// scale and position
vert[i].x = vert[i].x * properties.scale.x + properties.position.x;
vert[i].y = vert[i].y * properties.scale.y + properties.position.y;
}
}
applyTransform(_vertices, vert.data(), count);
if (closedCounter)
{
@ -1601,6 +1521,50 @@ axstd::pod_vector<Vec2> DrawNode::_transform(const Vec2* _vertices, unsigned int
return vert;
}
void DrawNode::applyTransform(const Vec2* from, Vec2* to, unsigned int count)
{
if (properties.transform == false)
return;
auto scale = properties.scale;
auto position = properties.position;
if (properties.rotation == 0.0f)
{
for (unsigned int i = 0; i < count; i++)
{
to[i].x = from[i].x * scale.x + position.x;
to[i].y = from[i].y * scale.y + position.y;
}
}
else
{
const float sinRot = sin(properties.rotation);
const float cosRot = cos(properties.rotation);
auto center = properties.center;
// https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d
for (unsigned int i = 0; i < count; i++)
{
// translate point to origin
float x = from[i].x - center.x;
float y = from[i].y - center.y;
// rotate point
float rx = x * cosRot - y * sinRot;
float ry = x * sinRot + y * cosRot;
// translate point back
x = rx + center.x;
y = ry + center.y;
// scale and position
to[i].x = x * scale.x + position.x;
to[i].y = y * scale.y + position.y;
}
}
}
#if defined(_WIN32)
# pragma pop_macro("TRANSPARENT")
#endif

View File

@ -448,7 +448,7 @@ public:
void setIsConvex(bool isConvex)
{
AXLOGW("'setIsConvex()' No longer supported. Use the new drawPolygon API.");
};
};
/** draw a segment with a radius and color.
@ -556,10 +556,7 @@ public:
virtual bool init() override;
protected:
void ensureCapacityTriangle(int count);
void ensureCapacityPoint(int count);
void ensureCapacityLine(int count);
void updateBuffers();
void updateShader();
void updateShaderInternal(CustomCommand& cmd,
uint32_t programType,
@ -572,32 +569,25 @@ protected:
void updateBlendState(CustomCommand& cmd);
void updateUniforms(const Mat4& transform, CustomCommand& cmd);
int _bufferCapacityTriangle = 0;
int _bufferCountTriangle = 0;
V2F_C4B_T2F* _bufferTriangle = nullptr;
CustomCommand _customCommandTriangle;
bool _dirtyTriangle = false;
bool _trianglesDirty: 1 = false;
bool _pointsDirty: 1 = false;
bool _linesDirty: 1 = false;
int _bufferCapacityPoint = 0;
int _bufferCountPoint = 0;
V2F_C4B_T2F* _bufferPoint = nullptr;
Color4B _pointColor;
int _pointSize = 0;
int _bufferCapacityLine = 0;
int _bufferCountLine = 0;
V2F_C4B_T2F* _bufferLine = nullptr;
CustomCommand _customCommandPoint;
CustomCommand _customCommandLine;
bool _dirtyPoint = false;
bool _dirtyLine = false;
bool _isolated: 1 = false;
BlendFunc _blendFunc;
bool _isolated = false;
CustomCommand _customCommandTriangle;
CustomCommand _customCommandPoint;
CustomCommand _customCommandLine;
axstd::pod_vector<V2F_C4B_T2F> _triangles;
axstd::pod_vector<V2F_C4B_T2F> _points;
axstd::pod_vector<V2F_C4B_T2F> _lines;
float _lineWidth = 1.0f;
float _defaultLineWidth = 1.0f;
private:
// Internal function _drawPoint
void _drawPoint(const Vec2& position,
@ -616,7 +606,8 @@ private:
void _drawDot(const Vec2& pos, float radius, const Color4B& color);
// Internal function _drawTriangle
void _drawTriangle(const Vec2* vertices3,
// Note: modifies supplied vertex array
void _drawTriangle(Vec2* vertices3,
const Color4B& borderColor,
const Color4B& fillColor,
bool solid = true,
@ -691,6 +682,8 @@ private:
*/
axstd::pod_vector<Vec2> _transform(const Vec2* vertices, unsigned int& count, bool closedPolygon = false);
void applyTransform(const Vec2* from, Vec2* to, unsigned int count);
private:
AX_DISALLOW_COPY_AND_ASSIGN(DrawNode);
@ -711,7 +704,7 @@ public:
float defaultLineWidth = 1.0f;
// Drawing flags
bool transform = true;
bool transform = false;
bool drawOrder = false;
/** Set the DrawNode drawOrder

View File

@ -157,13 +157,13 @@ void CustomCommand::createIndexBuffer(IndexFormat format, std::size_t capacity,
_indexBuffer = backend::DriverBase::getInstance()->newBuffer(_indexSize * capacity, backend::BufferType::INDEX, usage);
}
void CustomCommand::updateVertexBuffer(void* data, std::size_t offset, std::size_t length)
void CustomCommand::updateVertexBuffer(const void* data, std::size_t offset, std::size_t length)
{
assert(_vertexBuffer);
_vertexBuffer->updateSubData(data, offset, length);
}
void CustomCommand::updateIndexBuffer(void* data, std::size_t offset, std::size_t length)
void CustomCommand::updateIndexBuffer(const void* data, std::size_t offset, std::size_t length)
{
assert(_indexBuffer);
_indexBuffer->updateSubData(data, offset, length);
@ -192,13 +192,13 @@ void CustomCommand::setIndexBuffer(backend::Buffer* indexBuffer, IndexFormat for
_indexSize = computeIndexSize();
}
void CustomCommand::updateVertexBuffer(void* data, std::size_t length)
void CustomCommand::updateVertexBuffer(const void* data, std::size_t length)
{
assert(_vertexBuffer);
_vertexBuffer->updateData(data, length);
}
void CustomCommand::updateIndexBuffer(void* data, std::size_t length)
void CustomCommand::updateIndexBuffer(const void* data, std::size_t length)
{
assert(_indexBuffer);
_indexBuffer->updateData(data, length);

View File

@ -129,13 +129,13 @@ TODO: should remove it.
@param data Specifies a pointer to the new data that will be copied into the data store.
@param length Specifies the length in bytes of the data store region being replaced.
*/
void updateVertexBuffer(void* data, std::size_t length);
void updateVertexBuffer(const void* data, std::size_t length);
/**
Update index buffer contents.
@param data Specifies a pointer to the new data that will be copied into the data store.
@param length Specifies the size in bytes of the data store region being replaced.
*/
void updateIndexBuffer(void* data, std::size_t length);
void updateIndexBuffer(const void* data, std::size_t length);
/**
Update some or all contents of vertex buffer.
@param data Specifies a pointer to the new data that will be copied into the data store.
@ -143,7 +143,7 @@ TODO: should remove it.
in bytes.
@param length Specifies the size in bytes of the data store region being replaced.
*/
void updateVertexBuffer(void* data, std::size_t offset, std::size_t length);
void updateVertexBuffer(const void* data, std::size_t offset, std::size_t length);
/**
Update some or call contents of index buffer
@param data Specifies a pointer to the new data that will be copied into the data store.
@ -151,7 +151,7 @@ TODO: should remove it.
in bytes.
@param length Specifies the size in bytes of the data store region being replaced.
*/
void updateIndexBuffer(void* data, std::size_t offset, std::size_t length);
void updateIndexBuffer(const void* data, std::size_t offset, std::size_t length);
/**
Get vertex buffer capacity.

View File

@ -1387,6 +1387,7 @@ DrawNodeBaseTest::DrawNodeBaseTest()
if (!drawNode)
{
drawNode = DrawNode::create();
drawNode->properties.setTransform(true);
addChild(drawNode);
}
menuItemDrawOrder->setFontSize(10);
@ -1585,6 +1586,7 @@ DrawNodeMorphTest_SolidPolygon::DrawNodeMorphTest_SolidPolygon()
{
drawNodeArray[n] = DrawNode::create();
drawNodeArray[n]->properties.setTransform(true);
addChild(drawNodeArray[n]);
drawNodeArray[n]->setPosition(
Vec2(AXRANDOM_MINUS1_1() * size.width / 4, AXRANDOM_MINUS1_1() * size.height / 4) + Vec2(100, 100));
@ -1714,6 +1716,7 @@ DrawNodeMorphTest_Polygon::DrawNodeMorphTest_Polygon()
for (size_t n = 0; n < 10; n++)
{
drawNodeArray[n] = DrawNode::create();
drawNodeArray[n]->properties.setTransform(true);
addChild(drawNodeArray[n]);
drawNodeArray[n]->setPosition(
Vec2(AXRANDOM_MINUS1_1() * size.width / 4, AXRANDOM_MINUS1_1() * size.height / 4) + Vec2(100, 100));
@ -3112,6 +3115,7 @@ DrawNodeAxmolTest2::DrawNodeAxmolTest2()
}
drawNode = DrawNode::create();
drawNode->properties.setTransform(true);
addChild(drawNode, 10);
scheduleUpdate();
@ -3432,9 +3436,11 @@ DrawNodeSpLinesTest::DrawNodeSpLinesTest()
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
drawNodeCP = DrawNode::create();
drawNodeCP->properties.setTransform(true);
addChild(drawNodeCP, 50);
drawNode = DrawNode::create();
drawNode->properties.setTransform(true);
addChild(drawNode, 30);
screen = Director::getInstance()->getVisibleSize();