fix: Disable postprocessing shaders in Web version
This commit is contained in:
parent
637cdd7084
commit
69c5d553b5
@ -77,7 +77,10 @@ namespace hex {
|
|||||||
this->initImGui();
|
this->initImGui();
|
||||||
this->setupNativeWindow();
|
this->setupNativeWindow();
|
||||||
this->registerEventHandlers();
|
this->registerEventHandlers();
|
||||||
this->loadPostProcessingShader();
|
|
||||||
|
#if !defined(OS_WEB)
|
||||||
|
this->loadPostProcessingShader();
|
||||||
|
#endif
|
||||||
|
|
||||||
ContentRegistry::Settings::impl::store();
|
ContentRegistry::Settings::impl::store();
|
||||||
ContentRegistry::Settings::impl::load();
|
ContentRegistry::Settings::impl::load();
|
||||||
@ -791,10 +794,14 @@ namespace hex {
|
|||||||
glfwMakeContextCurrent(backupContext);
|
glfwMakeContextCurrent(backupContext);
|
||||||
|
|
||||||
if (shouldRender) {
|
if (shouldRender) {
|
||||||
if (m_postProcessingShader.isValid())
|
#if !defined(OS_WEB)
|
||||||
drawWithShader();
|
if (m_postProcessingShader.isValid())
|
||||||
else
|
drawWithShader();
|
||||||
|
else
|
||||||
|
drawImGui();
|
||||||
|
#else
|
||||||
drawImGui();
|
drawImGui();
|
||||||
|
#endif
|
||||||
|
|
||||||
glfwSwapBuffers(m_window);
|
glfwSwapBuffers(m_window);
|
||||||
}
|
}
|
||||||
@ -823,74 +830,76 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Window::drawWithShader() {
|
void Window::drawWithShader() {
|
||||||
int displayWidth, displayHeight;
|
#if !defined(OS_WEB)
|
||||||
glfwGetFramebufferSize(m_window, &displayWidth, &displayHeight);
|
int displayWidth, displayHeight;
|
||||||
|
glfwGetFramebufferSize(m_window, &displayWidth, &displayHeight);
|
||||||
|
|
||||||
GLuint fbo, texture;
|
GLuint fbo, texture;
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
// Create a texture to render into
|
// Create a texture to render into
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, displayWidth, displayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, displayWidth, displayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Attach the texture to the framebuffer
|
// Attach the texture to the framebuffer
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||||
|
|
||||||
// Check if framebuffer is complete
|
// Check if framebuffer is complete
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
log::error("Framebuffer is not complete!");
|
log::error("Framebuffer is not complete!");
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
drawImGui();
|
drawImGui();
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
GLuint quadVAO, quadVBO;
|
GLuint quadVAO, quadVBO;
|
||||||
float quadVertices[] = {
|
float quadVertices[] = {
|
||||||
// positions // texCoords
|
// positions // texCoords
|
||||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||||
-1.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f, -1.0f, 0.0f, 0.0f,
|
||||||
1.0f, -1.0f, 1.0f, 0.0f,
|
1.0f, -1.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||||
1.0f, -1.0f, 1.0f, 0.0f,
|
1.0f, -1.0f, 1.0f, 0.0f,
|
||||||
1.0f, 1.0f, 1.0f, 1.0f
|
1.0f, 1.0f, 1.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
glGenVertexArrays(1, &quadVAO);
|
glGenVertexArrays(1, &quadVAO);
|
||||||
glGenBuffers(1, &quadVBO);
|
glGenBuffers(1, &quadVBO);
|
||||||
glBindVertexArray(quadVAO);
|
glBindVertexArray(quadVAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), quadVertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), quadVertices, GL_STATIC_DRAW);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
m_postProcessingShader.bind();
|
m_postProcessingShader.bind();
|
||||||
|
|
||||||
glBindVertexArray(quadVAO);
|
glBindVertexArray(quadVAO);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glClearColor(0.00F, 0.00F, 0.00F, 0.00F);
|
glClearColor(0.00F, 0.00F, 0.00F, 0.00F);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
m_postProcessingShader.unbind();
|
m_postProcessingShader.unbind();
|
||||||
|
|
||||||
glDeleteVertexArrays(1, &quadVAO);
|
glDeleteVertexArrays(1, &quadVAO);
|
||||||
glDeleteBuffers(1, &quadVBO);
|
glDeleteBuffers(1, &quadVBO);
|
||||||
glDeleteTextures(1, &texture);
|
glDeleteTextures(1, &texture);
|
||||||
glDeleteFramebuffers(1, &fbo);
|
glDeleteFramebuffers(1, &fbo);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::initGLFW() {
|
void Window::initGLFW() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user