diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/30-game/GraphicsTags.cpp | 4 | ||||
-rw-r--r-- | source/30-game/Renderer.cpp | 10 | ||||
-rw-r--r-- | source/30-game/main.cpp | 35 |
3 files changed, 40 insertions, 9 deletions
diff --git a/source/30-game/GraphicsTags.cpp b/source/30-game/GraphicsTags.cpp index eb9a079..83d52f8 100644 --- a/source/30-game/GraphicsTags.cpp +++ b/source/30-game/GraphicsTags.cpp @@ -152,7 +152,7 @@ GLenum Tags::FindGLType(IndexType type) { case IT_16Bit: return GL_UNSIGNED_SHORT; case IT_32Bit: return GL_UNSIGNED_BYTE; } - return GL_NONE; + return 0; } namespace ProjectBrussel_UNITY_ID { @@ -266,7 +266,7 @@ GLenum Tags::GLTypeFromString(std::string_view name) { if (iter != kGLTypeInfo.name2Enum.end()) { return iter->second; } else { - return GL_NONE; + return 0; } } diff --git a/source/30-game/Renderer.cpp b/source/30-game/Renderer.cpp index ad8bf35..0454efe 100644 --- a/source/30-game/Renderer.cpp +++ b/source/30-game/Renderer.cpp @@ -14,7 +14,7 @@ using namespace std::literals; RenderObject::RenderObject() - : mVao{ GL_NONE } { + : mVao{ 0 } { } RenderObject::~RenderObject() { @@ -26,7 +26,7 @@ GLuint RenderObject::GetGLVao() const { } void RenderObject::RebuildIfNecessary() { - if (mVao != GL_NONE) { + if (mVao != 0) { return; } @@ -63,7 +63,7 @@ void RenderObject::RebuildIfNecessary() { // Setup index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuf->handle); - glBindVertexArray(GL_NONE); + glBindVertexArray(0); } void RenderObject::SetMaterial(Material* material) { @@ -101,9 +101,9 @@ void RenderObject::SetFormat(VertexFormat* vertexFormat, Tags::IndexType indexFo } void RenderObject::DeleteGLObjects() { - if (mVao != GL_NONE) { + if (mVao != 0) { glDeleteVertexArrays(1, &mVao); - mVao = GL_NONE; + mVao = 0; } } diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp index c49fc0b..89f0e97 100644 --- a/source/30-game/main.cpp +++ b/source/30-game/main.cpp @@ -36,6 +36,10 @@ void GlfwErrorCallback(int error, const char* description) { fprintf(stderr, "[GLFW] Error %d: %s\n", error, description); } +void OpenGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam​) { + fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message); +} + void GlfwFramebufferResizeCallback(GLFWwindow* window, int width, int height) { AppConfig::mainWindowWidth = width; AppConfig::mainWindowHeight = height; @@ -102,6 +106,7 @@ fs::path GetEnvVar(const char* name, const char* backup) { int main(int argc, char* argv[]) { using namespace Tags; + constexpr auto kOpenGLDebug = "opengl-debug"; constexpr auto kImGuiBackend = "imgui-backend"; constexpr auto kGameDataDir = "game-data-directory"; constexpr auto kGameAssetDir = "game-asset-directory"; @@ -109,6 +114,7 @@ int main(int argc, char* argv[]) { cxxopts::Options options(std::string(AppConfig::kAppName), ""); // clang-format off options.add_options() + (kOpenGLDebug, "Enable OpenGL debugging messages.") (kImGuiBackend, "ImGui backend. Options: opengl2, opengl3. Leave empty to default.", cxxopts::value<std::string>()) (kGameAssetDir, "Directory in which assets are looked up from. Can be relative paths to the executable.", cxxopts::value<std::string>()->default_value(".")) (kGameDataDir, "Directory in which game data (such as saves and options) are saved to. Leave empty to use the default directory on each platform.", cxxopts::value<std::string>()) @@ -206,7 +212,7 @@ int main(int argc, char* argv[]) { GlfwUserData glfwUserData; - GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui Command Palette Example", nullptr, nullptr); + GLFWwindow* window = glfwCreateWindow(1280, 720, "Project Brussel", nullptr, nullptr); if (window == nullptr) { return -2; } @@ -228,11 +234,36 @@ int main(int argc, char* argv[]) { glfwMakeContextCurrent(window); glfwSwapInterval(1); - // TODO setup opengl debug context if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { return -3; } +#if defined(BRUSSEL_DEV_ENV) + { + auto glVersionString = glGetString(GL_VERSION); + + int glMajorVersion; + glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion); + int glMinorVersion; + glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion); + + printf("OpenGL version (via glGetString(GL_VERSION)): %s\n", glVersionString); + printf("OpenGL version (via glGetIntegerv() with GL_MAJOR_VERSION and GL_MINOR_VERSION): %d.%d\n", glMajorVersion, glMinorVersion); + } +#endif + + bool useOpenGLDebug = args[kOpenGLDebug].as<bool>(); + if (useOpenGLDebug) { + printf("Using OpenGL debugging\n --%s", kOpenGLDebug); + + // TODO check extension KHR_debug availability + // TODO conan glad is not including any extensions + // NOTE: KHR_debug is a core extension, which means it may be available in lower version even though the feature is added in 4.3 + + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(&OpenGLDebugCallback, 0); + } + IMGUI_CHECKVERSION(); auto ctx = ImGui::CreateContext(); auto& io = ImGui::GetIO(); |