OpenGL: use 4.1 core
necessary for modern Mac support
This commit is contained in:
parent
4b0d1cb90d
commit
d313a3ceb3
@ -305,6 +305,10 @@ public:
|
|||||||
int height;
|
int height;
|
||||||
SDL_GetWindowSize(m_sdlWindow, &width, &height);
|
SDL_GetWindowSize(m_sdlWindow, &width, &height);
|
||||||
m_windowSize = Vec2U(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);
|
m_sdlGlContext = SDL_GL_CreateContext(m_sdlWindow);
|
||||||
if (!m_sdlGlContext)
|
if (!m_sdlGlContext)
|
||||||
|
@ -80,6 +80,15 @@ void main() {
|
|||||||
}
|
}
|
||||||
)SHADER";
|
)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() {
|
OpenGlRenderer::OpenGlRenderer() {
|
||||||
if (glewInit() != GLEW_OK)
|
if (glewInit() != GLEW_OK)
|
||||||
throw RendererException("Could not initialize GLEW");
|
throw RendererException("Could not initialize GLEW");
|
||||||
@ -94,10 +103,11 @@ OpenGlRenderer::OpenGlRenderer() {
|
|||||||
(const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
(const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glDisable(GL_DEPTH_TEST);
|
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),
|
m_whiteTexture = createGlTexture(Image::filled({1, 1}, Vec4B(255, 255, 255, 255), PixelFormat::RGBA32),
|
||||||
TextureAddressing::Clamp,
|
TextureAddressing::Clamp,
|
||||||
@ -694,6 +704,10 @@ Vec2U OpenGlRenderer::GlLoneTexture::glTextureCoordinateOffset() const {
|
|||||||
return Vec2U();
|
return Vec2U();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenGlRenderer::GlRenderBuffer::GlRenderBuffer() {
|
||||||
|
glGenVertexArrays(1, &vertexArray);
|
||||||
|
}
|
||||||
|
|
||||||
OpenGlRenderer::GlRenderBuffer::~GlRenderBuffer() {
|
OpenGlRenderer::GlRenderBuffer::~GlRenderBuffer() {
|
||||||
for (auto const& texture : usedTextures) {
|
for (auto const& texture : usedTextures) {
|
||||||
if (auto gt = as<GlGroupedTexture>(texture.get()))
|
if (auto gt = as<GlGroupedTexture>(texture.get()))
|
||||||
@ -701,6 +715,7 @@ OpenGlRenderer::GlRenderBuffer::~GlRenderBuffer() {
|
|||||||
}
|
}
|
||||||
for (auto const& vb : vertexBuffers)
|
for (auto const& vb : vertexBuffers)
|
||||||
glDeleteBuffers(1, &vb.vertexBuffer);
|
glDeleteBuffers(1, &vb.vertexBuffer);
|
||||||
|
glDeleteVertexArrays(1, &vertexArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlRenderer::GlRenderBuffer::set(List<RenderPrimitive>& primitives) {
|
void OpenGlRenderer::GlRenderBuffer::set(List<RenderPrimitive>& primitives) {
|
||||||
@ -715,7 +730,7 @@ void OpenGlRenderer::GlRenderBuffer::set(List<RenderPrimitive>& primitives) {
|
|||||||
List<GLuint> currentTextures;
|
List<GLuint> currentTextures;
|
||||||
List<Vec2U> currentTextureSizes;
|
List<Vec2U> currentTextureSizes;
|
||||||
size_t currentVertexCount = 0;
|
size_t currentVertexCount = 0;
|
||||||
|
glBindVertexArray(vertexArray);
|
||||||
auto finishCurrentBuffer = [&]() {
|
auto finishCurrentBuffer = [&]() {
|
||||||
if (currentVertexCount > 0) {
|
if (currentVertexCount > 0) {
|
||||||
GlVertexBuffer vb;
|
GlVertexBuffer vb;
|
||||||
|
@ -143,6 +143,7 @@ private:
|
|||||||
size_t vertexCount = 0;
|
size_t vertexCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GlRenderBuffer();
|
||||||
~GlRenderBuffer();
|
~GlRenderBuffer();
|
||||||
|
|
||||||
void set(List<RenderPrimitive>& primitives) override;
|
void set(List<RenderPrimitive>& primitives) override;
|
||||||
@ -152,6 +153,7 @@ private:
|
|||||||
|
|
||||||
HashSet<TexturePtr> usedTextures;
|
HashSet<TexturePtr> usedTextures;
|
||||||
List<GlVertexBuffer> vertexBuffers;
|
List<GlVertexBuffer> vertexBuffers;
|
||||||
|
GLuint vertexArray = 0;
|
||||||
|
|
||||||
bool useMultiTexturing{true};
|
bool useMultiTexturing{true};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user