<commit_before>/*
 * This file is part of `et engine`
 * Copyright 2009-2013 by <NAME>
 * Please, do not modify content without approval.
 *
 */

#include <et/rendering/rendercontext.h>
#include <et/apiobjects/vertexbufferdata.h>

using namespace et;

VertexBufferData::VertexBufferData(RenderContext* rc, const VertexArray::Description& desc,
	BufferDrawType vertexDrawType, const std::string& aName) : Object(aName), _rc(rc), _vertexBuffer(0),
	_decl(desc.declaration), _dataSize(desc.data.dataSize()), _sourceTag(0), _drawType(vertexDrawType)
{
	glGenBuffers(1, &_vertexBuffer);
	setData(desc.data.data(), desc.data.dataSize());
}

VertexBufferData::VertexBufferData(RenderContext* rc, const VertexDeclaration& decl, const void* vertexData,
	size_t vertexDataSize, BufferDrawType vertexDrawType, const std::string& aName) : Object(aName), _rc(rc),
	_vertexBuffer(0), _decl(decl), _dataSize(vertexDataSize), _sourceTag(0), _drawType(vertexDrawType)
{
	glGenBuffers(1, &_vertexBuffer);
	setData(vertexData, vertexDataSize);
}

VertexBufferData::~VertexBufferData()
{
	if (_vertexBuffer)
		glDeleteBuffers(1, &_vertexBuffer);

	_rc->renderState().vertexBufferDeleted(_vertexBuffer);
}

void VertexBufferData::setData(const void* data, size_t dataSize)
{
	_dataSize = dataSize;
	
	if (_dataSize > 0)
	{
		_rc->renderState().bindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
		glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(_dataSize), data, drawTypeValue(_drawType));
		checkOpenGLError("glBufferData(GL_ARRAY_BUFFER, %u, 0x%08X, ..,)", _dataSize, data);
	}
}

void VertexBufferData::serialize(std::ostream&)
{
	ET_FAIL("Unsupported");
}

void VertexBufferData::deserialize(std::istream&)<commit_msg>vertex buffer data - new setData method - performance improved<commit_after>/*
 * This file is part of `et engine`
 * Copyright 2009-2013 by <NAME>
 * Please, do not modify content without approval.
 *
 */

#include <et/rendering/rendercontext.h>
#include <et/apiobjects/vertexbufferdata.h>

using namespace et;

VertexBufferData::VertexBufferData(RenderContext* rc, const VertexArray::Description& desc,
	BufferDrawType vertexDrawType, const std::string& aName) : Object(aName), _rc(rc), _vertexBuffer(0),
	_decl(desc.declaration), _dataSize(0), _sourceTag(0), _drawType(vertexDrawType)
{
	glGenBuffers(1, &_vertexBuffer);
	setData(desc.data.data(), desc.data.dataSize());
}

VertexBufferData::VertexBufferData(RenderContext* rc, const VertexDeclaration& decl, const void* vertexData,
	size_t vertexDataSize, BufferDrawType vertexDrawType, const std::string& aName) : Object(aName), _rc(rc),
	_vertexBuffer(0), _decl(decl), _dataSize(0), _sourceTag(0), _drawType(vertexDrawType)
{
	glGenBuffers(1, &_vertexBuffer);
	setData(vertexData, vertexDataSize);
}

VertexBufferData::~VertexBufferData()
{
	if (_vertexBuffer)
		glDeleteBuffers(1, &_vertexBuffer);

	_rc->renderState().vertexBufferDeleted(_vertexBuffer);
}

void VertexBufferData::setData(const void* data, size_t dataSize)
{
	_rc->renderState().bindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
	
	glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(_dataSize), nullptr, drawTypeValue(_drawType));
	checkOpenGLError("glBufferData(GL_ARRAY_BUFFER, %u, 0x%08X, %d)", _dataSize, data, _drawType);
	
	_dataSize = dataSize;
	
	glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(_dataSize), data, drawTypeValue(_drawType));
	checkOpenGLError("glBufferData(GL_ARRAY_BUFFER, %u, 0x%08X, %d)", _dataSize, data, _drawType);
}

void VertexBufferData::serialize(std::ostream&)
{
	ET_FAIL("Unsupported");
}

void VertexBufferData::deserialize(std::istream&)
{'fraction_non_alphanumeric': 0.13496251041377394, 'fraction_numerical': 0.0116634268258817, 'mean_word_length': 8.188775510204081, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5755979', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1216, 'n_words': 228}