add GLShader class
This commit is contained in:
parent
92eea9e39c
commit
378c13c869
50
src/client/GLShader.cc
Normal file
50
src/client/GLShader.cc
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
#include "GLShader.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
GLShader::GLShader()
|
||||
{
|
||||
m_id = 0;
|
||||
}
|
||||
|
||||
GLShader::~GLShader()
|
||||
{
|
||||
if (m_id > 0)
|
||||
{
|
||||
glDeleteShader(m_id);
|
||||
}
|
||||
}
|
||||
|
||||
bool GLShader::create(GLenum shaderType, const char *source)
|
||||
{
|
||||
GLint status;
|
||||
|
||||
m_id = glCreateShader(shaderType);
|
||||
if (m_id > 0)
|
||||
{
|
||||
glShaderSource(m_id, 1, &source, NULL);
|
||||
|
||||
glCompileShader(m_id);
|
||||
|
||||
glGetShaderiv(m_id, GL_COMPILE_STATUS, &status);
|
||||
if (status == GL_TRUE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
GLint log_length;
|
||||
cerr << "Error compiling shader" << endl;
|
||||
glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if (log_length > 0)
|
||||
{
|
||||
char * log = new char[log_length];
|
||||
glGetShaderInfoLog(m_id, log_length, &log_length, log);
|
||||
cerr << "Shader Log:" << endl << log << endl;
|
||||
delete[] log;
|
||||
}
|
||||
glDeleteShader(m_id);
|
||||
}
|
||||
return false;
|
||||
}
|
19
src/client/GLShader.h
Normal file
19
src/client/GLShader.h
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
#ifndef GLSHADER_H
|
||||
#define GLSHADER_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
class GLShader
|
||||
{
|
||||
public:
|
||||
GLShader();
|
||||
~GLShader();
|
||||
bool create(GLenum shaderType, const char *source);
|
||||
GLuint get_id() { return m_id; }
|
||||
bool valid() { return m_id > 0; }
|
||||
protected:
|
||||
GLuint m_id;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user