1#include "../Util/Matrix.h"
3#include "../Util/GLProgramHandle.h"
6#include "../Util/Render/SEnvironmentMgr.h"
16OGLMgr::OGLMgr() : m_projectionRatio(-1) {
27void OGLMgr::setBuffers() {
29 glGenRenderbuffers(1, &m_colorRenderbuffer);
30 glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer);
38 glGenFramebuffers(1, &m_framebuffer);
39 glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
40 glFramebufferRenderbuffer(GL_FRAMEBUFFER,
44 glFramebufferRenderbuffer(GL_FRAMEBUFFER,
50 glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer);
52 glEnable(GL_DEPTH_TEST);
57 glBindFramebuffer(GL_FRAMEBUFFER, 0);
61void OGLMgr::setupEGLGraphics() {
63 setProjectionRatio(0, 0);
65 glEnable(GL_DEPTH_TEST);
66 glEnable(GL_CULL_FACE);
69 glDepthFunc(GL_LEQUAL);
71 glBindFramebuffer(GL_FRAMEBUFFER, 0);
75void OGLMgr::setProjectionRatio(
int width,
int height) {
76 m_projectionRatio =
static_cast<GLfloat
>(width) /
static_cast<GLfloat
>(height);
77 CORE->GetCore(
CameraMgr)->SetProjectionRatio(m_projectionRatio);
80void OGLMgr::Render()
const {
81 glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
82 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
85 glBindBuffer(GL_ARRAY_BUFFER, 0);
86 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
92void OGLMgr::ResizeWindow(GLuint width, GLuint height) {
93 if (m_depthRenderbuffer) {
94 glDeleteRenderbuffers(1, &m_depthRenderbuffer);
95 m_depthRenderbuffer = 0;
99 glGenRenderbuffers(1, &m_depthRenderbuffer);
100 glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderbuffer);
101 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
109 glViewport(0, 0,
static_cast<GLsizei
>(width),
static_cast<GLsizei
>(height));
111 SEnvironmentMgr::SetWidth(width);
112 SEnvironmentMgr::SetHeight(height);
114 setProjectionRatio(width, height);
117void OGLMgr::releaseBuffers() {
118 glDeleteRenderbuffers(1, &m_colorRenderbuffer);
119 m_colorRenderbuffer = 0;
121 if (m_depthRenderbuffer) {
122 glDeleteRenderbuffers(1, &m_depthRenderbuffer);
123 m_depthRenderbuffer = 0;
126 glDeleteFramebuffers(1, &m_framebuffer);