some experimentation
This commit is contained in:
parent
9773103a18
commit
665a9a4078
8 changed files with 135 additions and 79 deletions
|
@ -12,6 +12,7 @@ set(srcs
|
||||||
src/script_system.cpp
|
src/script_system.cpp
|
||||||
src/script_scene.hpp
|
src/script_scene.hpp
|
||||||
src/script_scene.cpp
|
src/script_scene.cpp
|
||||||
|
src/script_visual.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(pwscripting
|
add_library(pwscripting
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include "pw/system/input.hpp"
|
#include "pw/system/input.hpp"
|
||||||
#include "pw/system/display.hpp"
|
#include "pw/system/display.hpp"
|
||||||
|
|
||||||
|
// hijacking
|
||||||
|
#include "pw/visual/pipeline.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
void script_system::load(sol::table &ns)
|
void script_system::load(sol::table &ns)
|
||||||
|
@ -29,6 +32,10 @@ void script_system::load(sol::table &ns)
|
||||||
"all",&display::all,
|
"all",&display::all,
|
||||||
"name",sol::readonly_property(&display::name)
|
"name",sol::readonly_property(&display::name)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ns.new_usertype<pipeline>("pipeline",
|
||||||
|
"create",&pipeline::create
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
0
src/scripting/src/script_visual.cpp
Normal file
0
src/scripting/src/script_visual.cpp
Normal file
|
@ -80,10 +80,14 @@ end
|
||||||
|
|
||||||
while w:update()
|
while w:update()
|
||||||
do
|
do
|
||||||
|
-- somehow works
|
||||||
|
if (pw.input.get().input_string == 'f') then
|
||||||
|
w.fullscreen = not w.fullscreen
|
||||||
|
end
|
||||||
|
|
||||||
|
-- just to check
|
||||||
if (pw.input:get().mouse_button == 1) then
|
if (pw.input:get().mouse_button == 1) then
|
||||||
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y)
|
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y)
|
||||||
-- w.fullscreen = not w.fullscreen
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print("update")
|
-- print("update")
|
||||||
|
|
|
@ -19,8 +19,6 @@ public:
|
||||||
|
|
||||||
std::string input_string() const { return _input_string; }
|
std::string input_string() const { return _input_string; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
~input() = default;
|
~input() = default;
|
||||||
|
|
||||||
enum mouse_button_state {
|
enum mouse_button_state {
|
||||||
|
|
|
@ -17,25 +17,25 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct window_context : context
|
//struct window_context : context
|
||||||
{
|
//{
|
||||||
virtual bool make_current() override;
|
// virtual bool make_current() override;
|
||||||
virtual void resize() override;
|
// virtual void resize() override;
|
||||||
// virtual context::size size() override;
|
// // virtual context::size size() override;
|
||||||
virtual void flush() override;
|
// virtual void flush() override;
|
||||||
};
|
//};
|
||||||
|
|
||||||
bool window_context::make_current()
|
//bool window_context::make_current()
|
||||||
{
|
//{
|
||||||
}
|
//}
|
||||||
|
|
||||||
void window_context::resize()
|
//void window_context::resize()
|
||||||
{
|
//{
|
||||||
}
|
//}
|
||||||
|
|
||||||
void window_context::flush()
|
//void window_context::flush()
|
||||||
{
|
//{
|
||||||
}
|
//}
|
||||||
|
|
||||||
struct window::impl {
|
struct window::impl {
|
||||||
|
|
||||||
|
@ -264,6 +264,11 @@ struct window::impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
window::window()
|
window::window()
|
||||||
: _impl(std::make_unique<window::impl>())
|
: _impl(std::make_unique<window::impl>())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef PW_VISUAL_PIPELINE_HPP
|
#ifndef PW_VISUAL_PIPELINE_HPP
|
||||||
#define PW_VISUAL_PIPELINE_HPP
|
#define PW_VISUAL_PIPELINE_HPP
|
||||||
|
|
||||||
|
#include <pw/core/size.hpp>
|
||||||
#include <pw/core/matrix.hpp>
|
#include <pw/core/matrix.hpp>
|
||||||
#include <pw/core/mesh.hpp>
|
#include <pw/core/mesh.hpp>
|
||||||
|
|
||||||
|
@ -8,6 +9,22 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
class pipeline {
|
||||||
|
|
||||||
|
public:
|
||||||
|
pipeline();
|
||||||
|
~pipeline() = default;
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
bool create(size s);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
struct impl;
|
||||||
|
std::unique_ptr<impl> _impl;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
|
||||||
#include "pw/core/size.hpp"
|
#include "pw/core/size.hpp"
|
||||||
#include "pw/core/matrix.hpp"
|
#include "pw/core/matrix.hpp"
|
||||||
|
|
||||||
|
#include "pw/visual/pipeline.hpp"
|
||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct pipeline {
|
struct pipeline::impl {
|
||||||
|
|
||||||
sizei _size;
|
sizei _size;
|
||||||
|
|
||||||
|
@ -15,70 +18,91 @@ struct pipeline {
|
||||||
GLuint rboColorId;
|
GLuint rboColorId;
|
||||||
GLuint rboDepthId;
|
GLuint rboDepthId;
|
||||||
|
|
||||||
bool create()
|
bool create(sizei size);
|
||||||
{
|
|
||||||
int max_msaa;
|
|
||||||
|
|
||||||
// query actual maximum MSAA
|
void draw();
|
||||||
glGetIntegerv(GL_MAX_SAMPLES,&max_msaa);
|
|
||||||
|
|
||||||
// create a 4x MSAA renderbuffer object for colorbuffer
|
impl() = default;
|
||||||
int msaa = 4;
|
~impl() = default;
|
||||||
|
|
||||||
// msaa = std::clamp(msaa,max_msaa);
|
|
||||||
|
|
||||||
glGenRenderbuffers(1, &rboColorId);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, rboColorId);
|
|
||||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGB8, _size.width, _size.height);
|
|
||||||
|
|
||||||
// create a 4x MSAA renderbuffer object for depthbuffer
|
|
||||||
|
|
||||||
glGenRenderbuffers(1, &rboDepthId);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, rboDepthId);
|
|
||||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_DEPTH_COMPONENT, _size.width, _size.height);
|
|
||||||
|
|
||||||
// create a 4x MSAA framebuffer object
|
|
||||||
glGenFramebuffers(1, &_fbo_msaa);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo_msaa);
|
|
||||||
|
|
||||||
// attach colorbuffer image to FBO
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER
|
|
||||||
GL_COLOR_ATTACHMENT0, // 2. color attachment point
|
|
||||||
GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER
|
|
||||||
rboColorId); // 4. rbo ID
|
|
||||||
|
|
||||||
// attach depthbuffer image to FBO
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER
|
|
||||||
GL_DEPTH_ATTACHMENT, // 2. depth attachment point
|
|
||||||
GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER
|
|
||||||
rboDepthId); // 4. rbo ID
|
|
||||||
|
|
||||||
// check FBO status
|
|
||||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw()
|
|
||||||
{
|
|
||||||
/* We are going to blit into the window (default framebuffer) */
|
|
||||||
glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0);
|
|
||||||
glDrawBuffer (GL_BACK); /* Use backbuffer as color dst. */
|
|
||||||
|
|
||||||
/* Read from your FBO */
|
|
||||||
glBindFramebuffer (GL_READ_FRAMEBUFFER, _fbo_draw );
|
|
||||||
glReadBuffer (GL_COLOR_ATTACHMENT0); /* Use Color Attachment 0 as color src. */
|
|
||||||
|
|
||||||
/* Copy the color and depth buffer from your FBO to the default framebuffer */
|
|
||||||
glBlitFramebuffer (0,0, _size.width, _size.height,
|
|
||||||
0,0, _size.width, _size.height,
|
|
||||||
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
|
|
||||||
GL_NEAREST);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool pipeline::impl::create(sizei size)
|
||||||
|
{
|
||||||
|
int max_msaa;
|
||||||
|
|
||||||
|
// query actual maximum MSAA
|
||||||
|
glGetIntegerv(GL_MAX_SAMPLES,&max_msaa);
|
||||||
|
|
||||||
|
// create a 4x MSAA renderbuffer object for colorbuffer
|
||||||
|
int msaa = 4;
|
||||||
|
|
||||||
|
// msaa = std::clamp(msaa,max_msaa);
|
||||||
|
|
||||||
|
glGenRenderbuffers(1, &rboColorId);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, rboColorId);
|
||||||
|
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGB8, _size.width, _size.height);
|
||||||
|
|
||||||
|
// create a 4x MSAA renderbuffer object for depthbuffer
|
||||||
|
|
||||||
|
glGenRenderbuffers(1, &rboDepthId);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, rboDepthId);
|
||||||
|
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_DEPTH_COMPONENT, _size.width, _size.height);
|
||||||
|
|
||||||
|
// create a 4x MSAA framebuffer object
|
||||||
|
glGenFramebuffers(1, &_fbo_msaa);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, _fbo_msaa);
|
||||||
|
|
||||||
|
// attach colorbuffer image to FBO
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER
|
||||||
|
GL_COLOR_ATTACHMENT0, // 2. color attachment point
|
||||||
|
GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER
|
||||||
|
rboColorId); // 4. rbo ID
|
||||||
|
|
||||||
|
// attach depthbuffer image to FBO
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER
|
||||||
|
GL_DEPTH_ATTACHMENT, // 2. depth attachment point
|
||||||
|
GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER
|
||||||
|
rboDepthId); // 4. rbo ID
|
||||||
|
|
||||||
|
// check FBO status
|
||||||
|
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pipeline::impl::draw()
|
||||||
|
{
|
||||||
|
/* We are going to blit into the window (default framebuffer) */
|
||||||
|
glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0);
|
||||||
|
glDrawBuffer (GL_BACK); /* Use backbuffer as color dst. */
|
||||||
|
|
||||||
|
/* Read from your FBO */
|
||||||
|
glBindFramebuffer (GL_READ_FRAMEBUFFER, _fbo_draw );
|
||||||
|
glReadBuffer (GL_COLOR_ATTACHMENT0); /* Use Color Attachment 0 as color src. */
|
||||||
|
|
||||||
|
/* Copy the color and depth buffer from your FBO to the default framebuffer */
|
||||||
|
glBlitFramebuffer (0,0, _size.width, _size.height,
|
||||||
|
0,0, _size.width, _size.height,
|
||||||
|
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
|
||||||
|
GL_NEAREST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
pipeline::pipeline()
|
||||||
|
: _impl(std::make_unique<pipeline::impl>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pipeline::create(size s)
|
||||||
|
{
|
||||||
|
return _impl->create(sizei(s.width,s.height));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue