Sha256: e098c9865cf132c01a8a64d7872969f0e8c6505a35ed892373ca1ecf36259124
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
#include "rays/shader.h" #include <boost/scoped_array.hpp> #include "rays/exception.h" namespace Rays { struct Shader::Data { int id; Data () : id(-1) { } ~Data () { clear(); } void clear () { if (id >= 0) glDeleteShader((GLuint) id); id = -1; } bool is_valid () const { return id >= 0; } };// Shader::Data void compile_shader (Shader* this_, const char* source) { if (!this_ || !source) argument_error(__FILE__, __LINE__); Shader::Data* self = this_->self.get(); if (self->is_valid()) invalid_state_error(__FILE__, __LINE__); self->id = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(self->id, 1, &source, NULL); glCompileShader(self->id); GLint status = GL_FALSE; glGetShaderiv(self->id, GL_COMPILE_STATUS, &status); if (status == GL_FALSE) { int len = 0; glGetShaderiv(self->id, GL_INFO_LOG_LENGTH, &len); boost::scoped_array<char> buffer(new char[len]); int written = 0; glGetShaderInfoLog(self->id, len, &written, &buffer[0]); opengl_error(__FILE__, __LINE__, &buffer[0]); } check_error(__FILE__, __LINE__); } Shader::Shader () { } Shader::Shader (const char* source) { compile_shader(this, source); } Shader::~Shader () { } GLuint Shader::id () const { return self->id; } bool Shader::operator == (const Shader& rhs) const { return self->id == rhs.self->id; } bool Shader::operator != (const Shader& rhs) const { return !operator==(rhs); } Shader::operator bool () const { return self->is_valid(); } bool Shader::operator ! () const { return !operator bool(); } }// Rays
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rays-0.1.9 | src/shader.cpp |
rays-0.1.8 | src/shader.cpp |
rays-0.1.7 | src/shader.cpp |