Browse Source

Explicitly pass also shader source sizes in Shader::compile().

Should avoid potentially costly `strlen` in glShaderSource() internals.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
da03d86e3e
  1. 17
      src/Shader.cpp

17
src/Shader.cpp

@ -25,6 +25,7 @@
#include "Shader.h" #include "Shader.h"
#include <fstream> #include <fstream>
#include <Containers/Array.h>
#include <Utility/Assert.h> #include <Utility/Assert.h>
#include "Extensions.h" #include "Extensions.h"
@ -625,17 +626,21 @@ Shader& Shader::addFile(const std::string& filename) {
bool Shader::compile() { bool Shader::compile() {
CORRADE_ASSERT(sources.size() > 1, "Shader::compile(): no files added", false); CORRADE_ASSERT(sources.size() > 1, "Shader::compile(): no files added", false);
/* Array of sources */ /* Array of source string pointers and their lengths */
const GLchar** _sources = new const GLchar*[sources.size()]; /** @todo Use `Containers::::ArrayTuple` to avoid one allocation if it ever
for(std::size_t i = 0; i != sources.size(); ++i) gets to be implemented (we need properly aligned memory too) */
_sources[i] = static_cast<const GLchar*>(sources[i].c_str()); Containers::Array<const GLchar*> pointers(sources.size());
Containers::Array<GLint> sizes(sources.size());
for(std::size_t i = 0; i != sources.size(); ++i) {
pointers[i] = static_cast<const GLchar*>(sources[i].data());
sizes[i] = sources[i].size();
}
/* Create shader and set its source */ /* Create shader and set its source */
glShaderSource(_id, sources.size(), _sources, nullptr); glShaderSource(_id, sources.size(), pointers, sizes);
/* Compile shader */ /* Compile shader */
glCompileShader(_id); glCompileShader(_id);
delete _sources;
/* Check compilation status */ /* Check compilation status */
GLint success, logLength; GLint success, logLength;

Loading…
Cancel
Save