[shader] Shaders vertex and fragments are now GLchar*

This commit is contained in:
Bruno de Oliveira Abinader
2015-09-10 15:16:19 +03:00
committed by Konstantin Käfer
parent 7943b1b71c
commit 1f1b3fbbc2
3 changed files with 18 additions and 15 deletions

View File

@@ -34,11 +34,13 @@ def write_header():
#ifndef MBGL_SHADER_SHADERS
#define MBGL_SHADER_SHADERS
#include <mbgl/platform/gl.hpp>
namespace mbgl {
struct shader_source {
const char *vertex;
const char *fragment;
const GLchar *vertex;
const GLchar *fragment;
};
enum {

View File

@@ -14,20 +14,21 @@
using namespace mbgl;
Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource)
: name(name_),
program(0) {
: name(name_)
, program(0)
{
util::stopwatch stopwatch("shader compilation", Event::Shader);
program = MBGL_CHECK_ERROR(glCreateProgram());
if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) {
if (!compileShader(&vertShader, GL_VERTEX_SHADER, &vertSource)) {
Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource);
MBGL_CHECK_ERROR(glDeleteProgram(program));
program = 0;
throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile");
}
if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) {
if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, &fragSource)) {
Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource);
MBGL_CHECK_ERROR(glDeleteShader(vertShader));
vertShader = 0;
@@ -69,13 +70,12 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo
}
bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) {
bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source[]) {
GLint status;
*shader = MBGL_CHECK_ERROR(glCreateShader(type));
const GLchar *strings[] = { source };
const GLsizei lengths[] = { static_cast<GLsizei>(std::strlen(source)) };
MBGL_CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths));
const GLsizei lengths = static_cast<GLsizei>(std::strlen(*source));
MBGL_CHECK_ERROR(glShaderSource(*shader, 1, source, &lengths));
MBGL_CHECK_ERROR(glCompileShader(*shader));

View File

@@ -12,9 +12,10 @@ namespace mbgl {
class Shader : private util::noncopyable {
public:
Shader(const char *name, const char *vertex, const char *fragment);
Shader(const GLchar *name, const GLchar *vertex, const GLchar *fragment);
~Shader();
const char *name;
const GLchar *name;
uint32_t program;
inline uint32_t getID() const {
@@ -27,10 +28,10 @@ protected:
GLint a_pos = -1;
private:
bool compileShader(uint32_t *shader, uint32_t type, const char *source);
bool compileShader(GLuint *shader, GLenum type, const GLchar *source[]);
uint32_t vertShader = 0;
uint32_t fragShader = 0;
GLuint vertShader = 0;
GLuint fragShader = 0;
};
}