16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 06:59:18 +02:00
This commit is contained in:
milek7
2018-07-11 00:30:33 +02:00
parent a13fc4e500
commit 94712f5c77
16 changed files with 297 additions and 91 deletions

View File

@@ -0,0 +1,41 @@
#include "stdafx.h"
#include "framebuffer.h"
gl::framebuffer::framebuffer()
{
glGenFramebuffers(1, *this);
}
gl::framebuffer::~framebuffer()
{
glDeleteFramebuffers(1, *this);
}
void gl::framebuffer::bind(GLuint id)
{
glBindFramebuffer(GL_FRAMEBUFFER, id);
}
void gl::framebuffer::attach(const opengl_texture &tex, GLenum location)
{
bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, location, GL_TEXTURE_2D, tex.id, 0);
}
void gl::framebuffer::attach(const renderbuffer &rb, GLenum location)
{
bind();
glFramebufferRenderbuffer(GL_FRAMEBUFFER, location, GL_RENDERBUFFER, *rb);
}
bool gl::framebuffer::is_complete()
{
bind();
return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
}
void gl::framebuffer::clear()
{
bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include "object.h"
#include "bindable.h"
#include "renderbuffer.h"
#include "Texture.h"
namespace gl
{
class framebuffer : public object, public bindable<framebuffer>
{
public:
framebuffer();
~framebuffer();
void attach(const opengl_texture &tex, GLenum location);
void attach(const renderbuffer &rb, GLenum location);
void clear();
bool is_complete();
using bindable::bind;
static void bind(GLuint id);
};
}

View File

@@ -0,0 +1,24 @@
#include "stdafx.h"
#include "renderbuffer.h"
gl::renderbuffer::renderbuffer()
{
glGenRenderbuffers(1, *this);
}
gl::renderbuffer::~renderbuffer()
{
glDeleteRenderbuffers(1, *this);
}
void gl::renderbuffer::bind(GLuint id)
{
glBindRenderbuffer(GL_RENDERBUFFER, id);
}
void gl::renderbuffer::alloc(GLuint format, int width, int height)
{
bind();
glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include "object.h"
#include "bindable.h"
namespace gl
{
class renderbuffer : public object, public bindable<renderbuffer>
{
public:
renderbuffer();
~renderbuffer();
void alloc(GLuint format, int width, int height);
static void bind(GLuint id);
using bindable::bind;
};
}

View File

@@ -55,8 +55,6 @@ gl::shader::shader(const std::string &filename)
std::string str = read_file(filename);
expand_includes(str);
std::cout << (str) << std::endl;;
const GLchar *cstr = str.c_str();
if (!cstr[0])

View File

@@ -19,7 +19,7 @@ void gl::ubo::bind(GLuint i)
glBindBuffer(GL_UNIFORM_BUFFER, i);
}
void gl::ubo::update(void *data, int offset, int size)
void gl::ubo::update(const uint8_t *data, int offset, int size)
{
bind();
glBufferSubData(GL_UNIFORM_BUFFER, offset, size, data);

View File

@@ -1,3 +1,5 @@
#pragma once
#include "object.h"
#include "bindable.h"
@@ -16,7 +18,11 @@ namespace gl
using bindable::bind;
static void bind(GLuint i);
void update(void *data, int offset, int size);
void update(const uint8_t *data, int offset, int size);
template <typename T> void update(const T &data, size_t offset = 0)
{
update(reinterpret_cast<const uint8_t*>(&data), offset, sizeof(data));
}
};
// layout std140