begin on GLProgram

This commit is contained in:
Josh Holtrop 2014-07-22 18:36:16 -04:00
parent bf15a702ab
commit 6aef5dab75
3 changed files with 39 additions and 36 deletions

View File

@ -1,27 +1,47 @@
#if 0
#include "GLProgram.h" #include "GLProgram.h"
#include <stdint.h> #include "ruby.h"
#include <iostream> #include "gl3w.h"
using namespace std; typedef struct
GLProgram::GLProgram()
{ {
m_id = glCreateProgram(); GLuint id;
if (m_id == 0u) } GLProgram;
static VALUE ruby_class;
static void GLProgram_free(void * ptr)
{
GLProgram * program = (GLProgram *)ptr;
if (program->id > 0u)
{ {
cerr << "Error allocating GL program object" << endl; glDeleteProgram(program->id);
} }
delete program;
} }
GLProgram::~GLProgram() static VALUE GLProgram_new(VALUE klass)
{ {
if (m_id > 0u) GLProgram * glprogram = new GLProgram();
glprogram->id = glCreateProgram();
if (glprogram->id == 0u)
{ {
glDeleteProgram(m_id); rb_raise(rb_eRuntimeError, "Error allocating GL program object");
} }
return Data_Wrap_Struct(klass, NULL, GLProgram_free, glprogram);
} }
void GLProgram_Init()
{
ruby_class = rb_define_class("GLProgram", rb_cObject);
rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))GLProgram_new, 0);
rb_define_attr(ruby_class, "id", 0, 1);
}
#if 0
GLProgram & GLProgram::attach_shader(GLShaderRef shader) GLProgram & GLProgram::attach_shader(GLShaderRef shader)
{ {
if (m_id > 0u) if (m_id > 0u)

View File

@ -1,29 +1,6 @@
#if 0
#ifndef GLPROGRAM_H #ifndef GLPROGRAM_H
#define GLPROGRAM_H #define GLPROGRAM_H
#include "Ref.h" void GLProgram_Init();
#include "GLShader.h"
#include <map>
#include <string>
#include <vector>
class GLProgram
{
public:
GLProgram();
~GLProgram();
GLProgram & attach_shader(GLShaderRef shader);
GLProgram & bind_attribute(const char * attribute, GLuint index);
bool link();
GLuint get_id() { return m_id; }
void use() { glUseProgram(m_id); }
GLint get_uniform(const std::string & uniform_name);
protected:
GLuint m_id;
std::map<std::string, GLint> m_uniforms;
};
typedef Ref<GLProgram> GLProgramRef;
#endif #endif
#endif

View File

@ -1,6 +1,8 @@
#include <iostream> #include <iostream>
#include "ruby.h" #include "ruby.h"
#include "Window.h" #include "Window.h"
#include "GLShader.h"
#include "GLProgram.h"
using namespace std; using namespace std;
@ -47,7 +49,11 @@ static int bootstrap()
{ {
int rv = 0; int rv = 0;
int err_state = 0; int err_state = 0;
Window_Init(); Window_Init();
GLShader_Init();
GLProgram_Init();
rb_eval_string_protect( rb_eval_string_protect(
"load File.expand_path('../../runtime/main.rb', $0)", "load File.expand_path('../../runtime/main.rb', $0)",
&err_state); &err_state);