dealing with webgl is getting annoying
parent
7c61323a05
commit
6fb5d48ba9
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
|
||||
set(BLT_GRAPHICS_VERSION 0.13.6)
|
||||
set(BLT_GRAPHICS_VERSION 0.13.7)
|
||||
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
||||
|
||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||
|
|
|
@ -94,12 +94,19 @@ namespace blt::gfx
|
|||
pp_in_place_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to): from(from), to(to)
|
||||
{}
|
||||
|
||||
void draw(frame_buffer_t& previous) override;
|
||||
|
||||
void post_draw(frame_buffer_t& previous) override;
|
||||
|
||||
void create() override;
|
||||
|
||||
bool requests(blt::gfx::pp_request_t request) override
|
||||
{
|
||||
return static_cast<u64>(request) & ~(static_cast<u64>(pp_request_t::BIND_BUFFER) | static_cast<u64>(pp_request_t::CLEAR_BUFFER));
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<shader_t> shader_pass;
|
||||
frame_buffer_t::attachment_t from;
|
||||
frame_buffer_t::attachment_t to;
|
||||
};
|
||||
|
@ -142,76 +149,37 @@ namespace blt::gfx
|
|||
matrix_state_manager& manager;
|
||||
};
|
||||
|
||||
class pp_blur_step_base_t : public pp_step_t
|
||||
{
|
||||
public:
|
||||
pp_blur_step_base_t(frame_buffer_t::attachment_t from, i32 x_blur = 2, i32 y_blur = 2):
|
||||
from(from), to(from), x_blur(x_blur), y_blur(y_blur)
|
||||
{}
|
||||
|
||||
pp_blur_step_base_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to, i32 x_blur = 2, i32 y_blur = 2):
|
||||
from(from), to(to), x_blur(x_blur), y_blur(y_blur)
|
||||
{}
|
||||
|
||||
protected:
|
||||
frame_buffer_t::attachment_t from;
|
||||
frame_buffer_t::attachment_t to;
|
||||
i32 x_blur;
|
||||
i32 y_blur;
|
||||
};
|
||||
|
||||
class pp_blur_step_t : public pp_blur_step_base_t
|
||||
{
|
||||
public:
|
||||
pp_blur_step_t(frame_buffer_t::attachment_t from, i32 x_blur = 2, i32 y_blur = 2): pp_blur_step_base_t(from, x_blur, y_blur)
|
||||
{}
|
||||
|
||||
pp_blur_step_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to, i32 x_blur = 2, i32 y_blur = 2):
|
||||
pp_blur_step_base_t(from, to, x_blur, y_blur)
|
||||
{}
|
||||
|
||||
void create() override;
|
||||
|
||||
void draw(frame_buffer_t& previous);
|
||||
};
|
||||
|
||||
class pp_blur_step_inplace_t : public pp_blur_step_base_t
|
||||
class pp_blur_step_inplace_t : public pp_in_place_t
|
||||
{
|
||||
public:
|
||||
pp_blur_step_inplace_t(matrix_state_manager& manager, frame_buffer_t::attachment_t from, i32 x_blur = 2, i32 y_blur = 2):
|
||||
pp_blur_step_base_t(from, x_blur, y_blur), manager(manager)
|
||||
pp_in_place_t(from), manager(manager), x_blur(x_blur), y_blur(y_blur)
|
||||
{}
|
||||
|
||||
pp_blur_step_inplace_t(matrix_state_manager& manager, frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to, i32 x_blur = 2,
|
||||
i32 y_blur = 2):
|
||||
pp_blur_step_base_t(from, to, x_blur, y_blur), manager(manager)
|
||||
pp_in_place_t(from, to), manager(manager), x_blur(x_blur), y_blur(y_blur)
|
||||
{}
|
||||
|
||||
void create() override;
|
||||
|
||||
void draw(frame_buffer_t& previous);
|
||||
|
||||
void post_draw(frame_buffer_t& previous) override;
|
||||
|
||||
bool requests(blt::gfx::pp_request_t request) override
|
||||
{
|
||||
return static_cast<u64>(request) & ~(static_cast<u64>(pp_request_t::BIND_BUFFER) | static_cast<u64>(pp_request_t::CLEAR_BUFFER));
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<shader_t> shader_pass;
|
||||
matrix_state_manager& manager;
|
||||
i32 x_blur;
|
||||
i32 y_blur;
|
||||
};
|
||||
|
||||
class pp_expansion_step_inplace_t : public pp_in_place_t
|
||||
{
|
||||
public:
|
||||
pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, const vec4& multiplier = vec4{2,2,2,2}):
|
||||
pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, const vec4& multiplier = vec4{2, 2, 2, 2}):
|
||||
pp_in_place_t(from), multiplier(multiplier)
|
||||
{}
|
||||
|
||||
pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to,
|
||||
const vec4& multiplier = vec4{2,2,2,2}):
|
||||
const vec4& multiplier = vec4{2, 2, 2, 2}):
|
||||
pp_in_place_t(from, to), multiplier(multiplier)
|
||||
{}
|
||||
|
||||
|
|
|
@ -154,6 +154,8 @@ namespace blt::gfx
|
|||
{
|
||||
if (width == width_ && height == height_)
|
||||
return;
|
||||
if (fboID == 0)
|
||||
return;
|
||||
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
@ -208,7 +210,7 @@ namespace blt::gfx
|
|||
//glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
//glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
||||
glReadBuffer(static_cast<GLenum>(attachment_t::COLOR0));
|
||||
GLenum buffers[] {static_cast<GLenum>(attachment_t::COLOR0)};
|
||||
GLenum buffers[] {GL_BACK};
|
||||
glDrawBuffers(1, buffers);
|
||||
glBlitFramebuffer(0, 0, width_, height_, 0, 0, width, height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
|
|
|
@ -137,6 +137,41 @@ namespace blt::gfx
|
|||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
void pp_in_place_t::create()
|
||||
{
|
||||
shader_pass = pp_engine_t::createShader(shader_pp_screen_frag);
|
||||
draw_buffer = frame_buffer_t::make_render_texture(getWindowWidth(), getWindowHeight());
|
||||
}
|
||||
|
||||
void pp_in_place_t::post_draw(frame_buffer_t& previous)
|
||||
{
|
||||
//draw_buffer.blitTexture(previous, 0, 0, 0, 0, GL_NEAREST, from, to);
|
||||
previous.bind();
|
||||
GLenum buf[32];
|
||||
auto buff_val = static_cast<GLenum>(to);
|
||||
auto size = buff_val - GL_COLOR_ATTACHMENT0;
|
||||
for (GLenum i = 0; i < size; i++)
|
||||
buf[i] = GL_NONE;
|
||||
buf[size] = buff_val;
|
||||
glDrawBuffers(static_cast<int>(size) + 1, buf);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
shader_pass->bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
draw_buffer.getTexture(frame_buffer_t::attachment_t::COLOR0).bind();
|
||||
pp_engine_t::render_quad();
|
||||
}
|
||||
|
||||
void pp_in_place_t::draw(frame_buffer_t& previous)
|
||||
{
|
||||
draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight());
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
previous.getTexture(from).bind();
|
||||
draw_buffer.bind();
|
||||
GLenum buf[]{static_cast<GLenum>(frame_buffer_t::attachment_t::COLOR0)};
|
||||
glDrawBuffers(1, buf);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void pp_to_screen_step_t::create()
|
||||
{
|
||||
shader = pp_engine_t::createShader(shader_pp_screen_frag);
|
||||
|
@ -146,7 +181,7 @@ namespace blt::gfx
|
|||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
previous.getTexture(frame_buffer_t::attachment_t::COLOR0).bind();
|
||||
GLenum buf[]{static_cast<GLenum>(frame_buffer_t::attachment_t::COLOR0)};
|
||||
GLenum buf[]{GL_BACK};
|
||||
glDrawBuffers(1, buf);
|
||||
}
|
||||
|
||||
|
@ -204,78 +239,38 @@ namespace blt::gfx
|
|||
glActiveTexture(GL_TEXTURE1);
|
||||
previous.getTexture(frame_buffer_t::attachment_t::COLOR1).bind();
|
||||
shader->bind();
|
||||
auto v = vec2(getWindowWidth(), getWindowHeight()) * (1.0 / blt::make_vec2(manager.getScale2D()));
|
||||
//auto v = vec2(getWindowWidth(), getWindowHeight()) * (1.0 / blt::make_vec2(manager.getScale2D()));
|
||||
//BLT_TRACE_STREAM << v << '\n';
|
||||
//shader->setVec2("viewportSize", static_cast<f32>(v.x()), static_cast<f32>(v.y()));
|
||||
GLenum buf[]{static_cast<GLenum>(frame_buffer_t::attachment_t::COLOR0)};
|
||||
glDrawBuffers(1, buf);
|
||||
}
|
||||
|
||||
void pp_blur_step_t::create()
|
||||
{
|
||||
draw_buffer = frame_buffer_t::make_render_texture(getWindowWidth(), getWindowHeight());
|
||||
shader = pp_engine_t::createShader(shader_gaussian_blur_frag);
|
||||
}
|
||||
|
||||
void pp_blur_step_t::draw(frame_buffer_t& previous)
|
||||
{
|
||||
draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight());
|
||||
shader->bind();
|
||||
shader->setVec4i("size", {getWindowWidth(), getWindowHeight(), x_blur, y_blur});
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
previous.getTexture(from).bind();
|
||||
GLenum buf[]{static_cast<GLenum>(to)};
|
||||
glDrawBuffers(1, buf);
|
||||
}
|
||||
|
||||
void pp_blur_step_inplace_t::create()
|
||||
{
|
||||
draw_buffer = frame_buffer_t::make_render_texture(getWindowWidth(), getWindowHeight());
|
||||
pp_in_place_t::create();
|
||||
shader = pp_engine_t::createShader(shader_gaussian_blur_frag);
|
||||
shader_pass = pp_engine_t::createShader(shader_pp_screen_frag);
|
||||
}
|
||||
|
||||
void pp_blur_step_inplace_t::draw(frame_buffer_t& previous)
|
||||
{
|
||||
draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight());
|
||||
pp_in_place_t::draw(previous);
|
||||
shader->bind();
|
||||
//auto v = vec2(getWindowWidth(), getWindowHeight()) * (1.0 / blt::make_vec2(manager.getScale2D()));
|
||||
auto v = vec2(getWindowWidth(), getWindowHeight());
|
||||
shader->setVec4i("size", {static_cast<i32>(v.x()), static_cast<i32>(v.y()), x_blur, y_blur});
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
previous.getTexture(from).bind();
|
||||
//GLenum buf[]{static_cast<GLenum>(to)};
|
||||
GLenum buf[]{static_cast<GLenum>(frame_buffer_t::attachment_t::COLOR0)};
|
||||
glDrawBuffers(1, buf);
|
||||
draw_buffer.bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void pp_blur_step_inplace_t::post_draw(frame_buffer_t& previous)
|
||||
{
|
||||
//draw_buffer.blitTexture(previous, 0, 0, 0, 0, GL_NEAREST, from, to);
|
||||
previous.bind();
|
||||
GLenum buf[]{static_cast<GLenum>(to)};
|
||||
glDrawBuffers(1, buf);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
shader_pass->bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
draw_buffer.getTexture(frame_buffer_t::attachment_t::COLOR0).bind();
|
||||
pp_engine_t::render_quad();
|
||||
}
|
||||
|
||||
void pp_expansion_step_inplace_t::create()
|
||||
{
|
||||
pp_in_place_t::create();
|
||||
shader = pp_engine_t::createShader(shader_multiplier_frag);
|
||||
}
|
||||
|
||||
void pp_expansion_step_inplace_t::draw(frame_buffer_t& previous)
|
||||
{
|
||||
pp_in_place_t::draw(previous);
|
||||
shader->bind();
|
||||
shader->setVec4("multiplier", multiplier);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
previous.getTexture(from).bind();
|
||||
GLenum buf[]{static_cast<u32>(to)};
|
||||
glDrawBuffers(1, buf);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue