Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/application
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-07-07 04:44:01 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-07-07 04:44:01 +1000
commitd313a3ceb35e167c1f47399ec5c787f94140a5b1 (patch)
tree77545287d4fe3b3e21d73c40a58486abe09f1732 /source/application
parent4b0d1cb90d774e31f50a13ced58aad9ab4768490 (diff)
OpenGL: use 4.1 core
necessary for modern Mac support
Diffstat (limited to 'source/application')
-rw-r--r--source/application/StarMainApplication_sdl.cpp4
-rw-r--r--source/application/StarRenderer_opengl.cpp19
-rw-r--r--source/application/StarRenderer_opengl.hpp2
3 files changed, 23 insertions, 2 deletions
diff --git a/source/application/StarMainApplication_sdl.cpp b/source/application/StarMainApplication_sdl.cpp
index d0b3dc3..d6cea76 100644
--- a/source/application/StarMainApplication_sdl.cpp
+++ b/source/application/StarMainApplication_sdl.cpp
@@ -305,6 +305,10 @@ public:
int height;
SDL_GetWindowSize(m_sdlWindow, &width, &height);
m_windowSize = Vec2U(width, height);
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
m_sdlGlContext = SDL_GL_CreateContext(m_sdlWindow);
if (!m_sdlGlContext)
diff --git a/source/application/StarRenderer_opengl.cpp b/source/application/StarRenderer_opengl.cpp
index e640e53..411bfa5 100644
--- a/source/application/StarRenderer_opengl.cpp
+++ b/source/application/StarRenderer_opengl.cpp
@@ -80,6 +80,15 @@ void main() {
}
)SHADER";
+/*
+static void GLAPIENTRY GlMessageCallback(GLenum, GLenum type, GLuint, GLenum, GLsizei, const GLchar* message, const void* renderer) {
+ if (type == GL_DEBUG_TYPE_ERROR) {
+ Logger::error("GL ERROR: {}", message);
+ __debugbreak();
+ }
+}
+*/
+
OpenGlRenderer::OpenGlRenderer() {
if (glewInit() != GLEW_OK)
throw RendererException("Could not initialize GLEW");
@@ -94,10 +103,11 @@ OpenGlRenderer::OpenGlRenderer() {
(const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
glClearColor(0.0, 0.0, 0.0, 1.0);
- glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
+ //glEnable(GL_DEBUG_OUTPUT);
+ //glDebugMessageCallback(GlMessageCallback, this);
m_whiteTexture = createGlTexture(Image::filled({1, 1}, Vec4B(255, 255, 255, 255), PixelFormat::RGBA32),
TextureAddressing::Clamp,
@@ -694,6 +704,10 @@ Vec2U OpenGlRenderer::GlLoneTexture::glTextureCoordinateOffset() const {
return Vec2U();
}
+OpenGlRenderer::GlRenderBuffer::GlRenderBuffer() {
+ glGenVertexArrays(1, &vertexArray);
+}
+
OpenGlRenderer::GlRenderBuffer::~GlRenderBuffer() {
for (auto const& texture : usedTextures) {
if (auto gt = as<GlGroupedTexture>(texture.get()))
@@ -701,6 +715,7 @@ OpenGlRenderer::GlRenderBuffer::~GlRenderBuffer() {
}
for (auto const& vb : vertexBuffers)
glDeleteBuffers(1, &vb.vertexBuffer);
+ glDeleteVertexArrays(1, &vertexArray);
}
void OpenGlRenderer::GlRenderBuffer::set(List<RenderPrimitive>& primitives) {
@@ -715,7 +730,7 @@ void OpenGlRenderer::GlRenderBuffer::set(List<RenderPrimitive>& primitives) {
List<GLuint> currentTextures;
List<Vec2U> currentTextureSizes;
size_t currentVertexCount = 0;
-
+ glBindVertexArray(vertexArray);
auto finishCurrentBuffer = [&]() {
if (currentVertexCount > 0) {
GlVertexBuffer vb;
diff --git a/source/application/StarRenderer_opengl.hpp b/source/application/StarRenderer_opengl.hpp
index 61c67c9..035b906 100644
--- a/source/application/StarRenderer_opengl.hpp
+++ b/source/application/StarRenderer_opengl.hpp
@@ -143,6 +143,7 @@ private:
size_t vertexCount = 0;
};
+ GlRenderBuffer();
~GlRenderBuffer();
void set(List<RenderPrimitive>& primitives) override;
@@ -152,6 +153,7 @@ private:
HashSet<TexturePtr> usedTextures;
List<GlVertexBuffer> vertexBuffers;
+ GLuint vertexArray = 0;
bool useMultiTexturing{true};
};