MetaCore/Source/MetaCoreRender/Private/MetaCoreRenderDevice.cpp
2026-03-20 10:39:34 +08:00

46 lines
1.1 KiB
C++

#include "MetaCoreRender/MetaCoreRenderDevice.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
namespace MetaCore {
bool MetaCoreRenderDevice::Initialize(GLFWwindow* nativeWindow) {
if (Initialized_) {
return true;
}
if (gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)) == 0) {
return false;
}
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glDisable(GL_BLEND);
Initialized_ = nativeWindow != nullptr;
return Initialized_;
}
void MetaCoreRenderDevice::Shutdown() {
Initialized_ = false;
}
void MetaCoreRenderDevice::BeginFrame(int width, int height, const glm::vec4& clearColor) const {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, width, height);
Clear(clearColor);
}
void MetaCoreRenderDevice::Clear(const glm::vec4& clearColor) const {
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
bool MetaCoreRenderDevice::IsInitialized() const {
return Initialized_;
}
} // namespace MetaCore