restore depth based world mouse position

This commit is contained in:
milek7
2018-10-24 18:25:29 +02:00
parent 8abe898735
commit 56e9fa537b
8 changed files with 205 additions and 52 deletions

View File

@@ -55,26 +55,34 @@ void gl::framebuffer::clear(GLbitfield mask)
glClear(mask);
}
void gl::framebuffer::blit_to(framebuffer &other, int w, int h, GLbitfield mask, GLenum attachment)
void gl::framebuffer::blit_to(framebuffer *other, int w, int h, GLbitfield mask, GLenum attachment)
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, *this);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, other);
int attachment_n = attachment - GL_COLOR_ATTACHMENT0;
GLenum outputs[8] = { GL_NONE };
outputs[attachment_n] = attachment;
glReadBuffer(attachment);
glDrawBuffers(attachment_n + 1, outputs);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, mask, GL_NEAREST);
unbind();
blit(this, other, 0, 0, w, h, mask, attachment);
}
void gl::framebuffer::blit_from(framebuffer &other, int w, int h, GLbitfield mask, GLenum attachment)
void gl::framebuffer::blit_from(framebuffer *other, int w, int h, GLbitfield mask, GLenum attachment)
{
other.blit_to(*this, w, h, mask, attachment);
blit(other, this, 0, 0, w, h, mask, attachment);
}
void gl::framebuffer::blit(framebuffer *src, framebuffer *dst, int sx, int sy, int w, int h, GLbitfield mask, GLenum attachment)
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, src ? *src : 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst ? *dst : 0);
if (mask & GL_COLOR_BUFFER_BIT)
{
int attachment_n = attachment - GL_COLOR_ATTACHMENT0;
GLenum outputs[8] = { GL_NONE };
outputs[attachment_n] = attachment;
glReadBuffer(attachment);
glDrawBuffers(attachment_n + 1, outputs);
}
glBlitFramebuffer(sx, sy, sx + w, sy + h, 0, 0, w, h, mask, GL_NEAREST);
unbind();
}
void gl::framebuffer::setup_drawing(int attachments)

View File

@@ -22,8 +22,10 @@ namespace gl
void clear(GLbitfield mask);
bool is_complete();
void blit_to(framebuffer &other, int w, int h, GLbitfield mask, GLenum attachment);
void blit_from(framebuffer &other, int w, int h, GLbitfield mask, GLenum attachment);
void blit_to(framebuffer *other, int w, int h, GLbitfield mask, GLenum attachment);
void blit_from(framebuffer *other, int w, int h, GLbitfield mask, GLenum attachment);
static void blit(framebuffer *src, framebuffer *dst, int sx, int sy, int w, int h, GLbitfield mask, GLenum attachment);
using bindable::bind;
static void bind(GLuint id);

View File

@@ -1,8 +1,8 @@
#include "pbo.h"
void gl::pbo::request_read(int x, int y, int lx, int ly)
void gl::pbo::request_read(int x, int y, int lx, int ly, int pixsize, GLenum format, GLenum type)
{
int s = lx * ly * 4;
int s = lx * ly * pixsize;
if (s != size)
allocate(PIXEL_PACK_BUFFER, s, GL_STREAM_DRAW);
size = s;
@@ -11,20 +11,20 @@ void gl::pbo::request_read(int x, int y, int lx, int ly)
sync.reset();
bind(PIXEL_PACK_BUFFER);
glReadPixels(x, y, lx, ly, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glReadPixels(x, y, lx, ly, format, type, 0);
unbind(PIXEL_PACK_BUFFER);
sync.emplace();
}
bool gl::pbo::read_data(int lx, int ly, uint8_t *data)
bool gl::pbo::read_data(int lx, int ly, void *data, int pixsize)
{
is_busy();
if (!data_ready)
return false;
int s = lx * ly * 4;
int s = lx * ly * pixsize;
if (s != size)
return false;

View File

@@ -10,8 +10,8 @@ namespace gl {
bool data_ready;
public:
void request_read(int x, int y, int lx, int ly);
bool read_data(int lx, int ly, uint8_t *data);
void request_read(int x, int y, int lx, int ly, int pixsize = 4, GLenum format = GL_RGBA, GLenum type = GL_UNSIGNED_BYTE);
bool read_data(int lx, int ly, void *data, int pixsize = 4);
bool is_busy();
};
}