Kale
Loading...
Searching...
No Matches
Core.cpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifdef KALE_OPENGL
18
19#include "Core.hpp"
20
22
23#include <string>
24#include <sstream>
25
26#include <glad/glad.h>
27
28using namespace Kale;
29using namespace Kale::OpenGL;
30
36 glViewport(0, 0, size.x, size.y);
37}
38
42void Core::setupCore() noexcept {
43 try {
45 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
46 glEnable(GL_BLEND);
47 glEnable(GL_DEPTH_TEST);
49 glViewport(0, 0, size.x, size.y);
52
53#ifdef KALE_DEBUG
54
55#ifdef KALE_OSX
56
57 console.warn("OpenGL Debug Callback not available on OSX. Errors, warnings, and undefined behavior will not be reported.");
58
59#else
60
61 glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message,
62 const void *userParam) -> void {
63
64 std::stringstream outMessage;
65
66 outMessage << "(" << enumStringValueMap.at(source) << ") Sent the following message -\n(Type: " <<
67 enumStringValueMap.at(type) << ")\n";
68
69 // String isn't null terminated
70 if (length < 0) outMessage.write(message, length);
71 else outMessage << message;
72
73 switch (severity) {
74#ifdef KALE_VERBOSE
75 case GL_DEBUG_SEVERITY_NOTIFICATION:
76 console.log(outMessage.str());
77 break;
78 case GL_DEBUG_SEVERITY_LOW:
79 console.info(outMessage.str());
80 break;
81#endif
82 case GL_DEBUG_SEVERITY_MEDIUM:
83 console.warn(outMessage.str());
84 break;
85 case GL_DEBUG_SEVERITY_HIGH:
86 console.error(outMessage.str());
87 break;
88 default:
89 return;
90 }
91
92 }, nullptr);
93
94 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
95 glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
96
97#endif
98
99#endif
100
101 }
102 catch (const std::exception& e) {
103 console.error(std::string("Unable to setup OpenGL/Glad - ") + e.what());
104 exit(0);
105 }
106}
107
111void Core::clearScreen(const Vector4f& color) noexcept {
112 glClearColor(color.x, color.y, color.z, color.w);
113 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
114}
115
119void Core::swapBuffers() noexcept {
121}
122
126void Core::cleanupCore() noexcept {
128 delete resizeHandler;
129}
130
131#endif
Window & getWindow() noexcept
void warn(T msg)
Definition Logger.hpp:182
void log(T msg)
Definition Logger.hpp:150
void error(T msg)
Definition Logger.hpp:198
void info(T msg)
Definition Logger.hpp:166
void onWindowResize(Vector2ui oldSize, Vector2ui newSize) override
Definition Core.cpp:34
static void clearScreen(const Vector4f &color) noexcept
Definition Core.cpp:111
static void swapBuffers() noexcept
Definition Core.cpp:119
static void setupCore() noexcept
Definition Core.cpp:42
static void cleanupCore() noexcept
Definition Core.cpp:126
static ResizeHandler * resizeHandler
Definition Core.hpp:49
void removeEvents(EventHandler *handler)
Definition Window.cpp:31
Vector2ui getFramebufferSize() const
void registerEvents(EventHandler *handler)
Definition Window.cpp:24
void setupGlad() const
void swapBuffers() const noexcept
Application * mainApp
Logger console
Definition Logger.hpp:317