Created
July 1, 2021 02:57
-
-
Save hsdk123/0e88dada6e5e5f88e23d64fb82481397 to your computer and use it in GitHub Desktop.
problem code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace { | |
void check_status(Magnum::GL::Framebuffer& frame_buffer) | |
{ | |
const auto stat1 = frame_buffer.checkStatus(Magnum::GL::FramebufferTarget::Read); | |
if (stat1 != Magnum::GL::Framebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
const auto stat2 = frame_buffer.checkStatus(Magnum::GL::FramebufferTarget::Draw); | |
if (stat2 != Magnum::GL::Framebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
const auto status1 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Read); | |
if (status1 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
const auto status2 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw); | |
if (status2 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
SECORE_CHECK_RENDERER_STATUS_FORCE(); | |
} | |
} | |
void CRenderMgr::Init(const int render_w, const int render_h) | |
{ | |
{ | |
const auto status1 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Read); | |
if (status1 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
const auto status2 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw); | |
if (status2 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
} | |
// reference: https://doc.magnum.graphics/magnum/classMagnu_1_1GL_1_1Framebuffer.html | |
{ | |
// note: changing this to rgb 'could' make this lighter | |
// default | |
{ | |
const auto rendertex = std::make_shared<Magnum::GL::Texture2D>(); | |
rendertex->setStorage(1, Magnum::GL::TextureFormat::RGBA8, { render_w, render_h }); | |
rendertex->setWrapping(Magnum::SamplerWrapping::ClampToEdge); | |
_rendertex = rendertex; | |
const auto depth_buffer = std::make_shared<Magnum::GL::Renderbuffer>(); | |
{ | |
/*#ifdef SECORE_TARGET_EMSCRIPTEN | |
depth_buffer->setStorage(Magnum::GL::RenderbufferFormat::DepthComponent24, { render_w, render_h }); | |
#else | |
depth_buffer->setStorage(Magnum::GL::RenderbufferFormat::DepthComponent32F, { render_w, render_h }); | |
#endif */ | |
depth_buffer->setStorage(Magnum::GL::RenderbufferFormat::DepthComponent32F, { render_w, render_h }); | |
//depth_buffer->setStorage(Magnum::GL::RenderbufferFormat::DepthComponent24, { render_w, render_h }); | |
_depthbuffer = depth_buffer; | |
{ | |
const auto status1 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Read); | |
if (status1 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
const auto status2 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw); | |
if (status2 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
SECORE_CHECK_RENDERER_STATUS_FORCE(); | |
} | |
} | |
const auto frame_buffer = std::make_shared<Magnum::GL::Framebuffer>(Magnum::Range2Di{ {}, { render_w, render_h } }); | |
{ | |
check_status(*frame_buffer); | |
frame_buffer->attachTexture( | |
Magnum::GL::Framebuffer::ColorAttachment{ 0 }, *rendertex, 0); | |
check_status(*frame_buffer); | |
frame_buffer->attachRenderbuffer( | |
Magnum::GL::Framebuffer::BufferAttachment::Depth, *depth_buffer); | |
/*frame_buffer->attachRenderbuffer( | |
Magnum::GL::Framebuffer::BufferAttachment::DepthStencil, *depth_buffer);*/ | |
check_status(*frame_buffer); | |
} | |
_frame_buffer = frame_buffer; | |
check_status(*frame_buffer); | |
} | |
// shader auto | |
{ | |
const auto rendertex = std::make_shared<Magnum::GL::Texture2D>(); | |
rendertex->setStorage(1, Magnum::GL::TextureFormat::RGBA8 /*have to use rgba here.*/, { render_w, render_h }); | |
rendertex->setWrapping(Magnum::SamplerWrapping::ClampToEdge); | |
_rendertex_shader_auto = rendertex; | |
const auto frame_buffer = std::make_shared<Magnum::GL::Framebuffer>(Magnum::Range2Di{ {}, { render_w, render_h } }); | |
frame_buffer->attachTexture(Magnum::GL::Framebuffer::ColorAttachment{ 0 }, *rendertex, 0); | |
_frame_buffer_shader_auto = frame_buffer; | |
const auto view = CoreMath::TransformMatrix::lookAt( | |
{ render_w / 2.f, render_h / 2.f, 0.f }, /*eye*/ | |
{ render_w / 2.f, render_h / 2.f, 1.f }, /*target direction*/ | |
{ 0.f, -1.f, 0.f } /*up*/).invertedRigid(); | |
_mat_shader_auto = CoreMath::TransformMatrix::orthographicProjection({ render_w * 1.f, render_h * 1.f }, -100.f, 100.f) * view; | |
if (frame_buffer->checkStatus(Magnum::GL::FramebufferTarget::Read) != Magnum::GL::Framebuffer::Status::Complete) { | |
CLogMgr::GetInstance().Log(L"something wrong"); | |
} | |
if (frame_buffer->checkStatus(Magnum::GL::FramebufferTarget::Draw) != Magnum::GL::Framebuffer::Status::Complete) { | |
CLogMgr::GetInstance().Log(L"something wrong"); | |
} | |
{ | |
const auto status1 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Read); | |
if (status1 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
const auto status2 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw); | |
if (status2 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
Magnum::Debug{} << "something wrong"; | |
} | |
SECORE_CHECK_RENDERER_STATUS_FORCE(); | |
} | |
} | |
_buffer = std::make_shared<BufferImpl>(CoreMath::Vector2<int>{ render_w, render_h }); | |
} | |
// shaderctrl for post-processing | |
_shaderctrl = std::make_shared<CShaderCtrl>(); | |
{ | |
const auto status1 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Read); | |
if (status1 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
CLogMgr::GetInstance().Log(L"something wrong"); | |
} | |
const auto status2 = Magnum::GL::defaultFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw); | |
if (status2 != Magnum::GL::DefaultFramebuffer::Status::Complete) { | |
CLogMgr::GetInstance().Log(L"something wrong"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment