mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Eliminates a couple of instances of manual memory management.
This commit is contained in:
parent
4c8781c762
commit
c73445199c
@ -239,17 +239,16 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, bool transp
|
||||
|
||||
void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values) {
|
||||
std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size) * static_cast<std::size_t>(size);
|
||||
GLfloat *values_copy = new GLfloat[number_of_values];
|
||||
std::memcpy(values_copy, values, sizeof(*values) * number_of_values);
|
||||
std::vector<GLfloat> values_copy(number_of_values);
|
||||
std::memcpy(values_copy.data(), values, sizeof(*values) * number_of_values);
|
||||
|
||||
enqueue_function([name, size, count, transpose, values_copy, this] {
|
||||
GLboolean glTranspose = transpose ? GL_TRUE : GL_FALSE;
|
||||
switch(size) {
|
||||
case 2: glUniformMatrix2fv(location(), count, glTranspose, values_copy); break;
|
||||
case 3: glUniformMatrix3fv(location(), count, glTranspose, values_copy); break;
|
||||
case 4: glUniformMatrix4fv(location(), count, glTranspose, values_copy); break;
|
||||
case 2: glUniformMatrix2fv(location(), count, glTranspose, values_copy.data()); break;
|
||||
case 3: glUniformMatrix3fv(location(), count, glTranspose, values_copy.data()); break;
|
||||
case 4: glUniformMatrix4fv(location(), count, glTranspose, values_copy.data()); break;
|
||||
}
|
||||
delete[] values_copy;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -173,10 +173,8 @@ void FileHolder::ensure_is_at_least_length(long length) {
|
||||
std::fseek(file_, 0, SEEK_END);
|
||||
long bytes_to_write = length - ftell(file_);
|
||||
if(bytes_to_write > 0) {
|
||||
uint8_t *empty = new uint8_t[static_cast<std::size_t>(bytes_to_write)];
|
||||
std::memset(empty, 0, static_cast<std::size_t>(bytes_to_write));
|
||||
std::fwrite(empty, sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
|
||||
delete[] empty;
|
||||
std::vector<uint8_t> empty(static_cast<std::size_t>(bytes_to_write), 0);
|
||||
std::fwrite(empty.data(), sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user