Skip to content

Commit 558bcb6

Browse files
committed
Various OpenGL fixes
1 parent 9fa7527 commit 558bcb6

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

src/include/sndx/platform/windows.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define UNDEF_LEANMEAN
1313
#endif
1414

15-
#include <Windows.h>
15+
#include <windows.h>
1616

1717
#ifdef UNDEF_MINMAX
1818
#undef NOMINMAX

src/include/sndx/render/gl/shader.hpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace sndx::render {
4343
private:
4444
GLuint m_id{0};
4545

46+
friend class ShaderProgram;
47+
4648
public:
4749
constexpr Shader() noexcept = default;
4850

@@ -77,7 +79,7 @@ namespace sndx::render {
7779
protected:
7880
void destroy() {
7981
if (m_id != 0) {
80-
glDeleteShader(std::exchange(id, 0));
82+
glDeleteShader(std::exchange(m_id, 0));
8183
}
8284
}
8385

@@ -132,18 +134,18 @@ namespace sndx::render {
132134

133135
template <class T>
134136
explicit ShaderProgram(T& shaders) :
135-
id(glCreateProgram()), uniformCache{} {
137+
m_id(glCreateProgram()), uniformCache{} {
136138

137-
for (auto shader : shaders) {
138-
glAttachShader(id, shader.id);
139+
for (const auto& shader : shaders) {
140+
glAttachShader(m_id, shader.m_id);
139141
}
140142

141-
glLinkProgram(id);
143+
glLinkProgram(m_id);
142144

143145
auto err = checkErr();
144146

145-
for (auto shader : shaders) {
146-
glDetachShader(id, shader.id);
147+
for (const auto& shader : shaders) {
148+
glDetachShader(m_id, shader.m_id);
147149
}
148150

149151
if (err.has_value()) [[unlikely]] {
@@ -152,7 +154,7 @@ namespace sndx::render {
152154
}
153155

154156
void use() const {
155-
glUseProgram(id);
157+
glUseProgram(m_id);
156158
}
157159

158160
[[nodiscard]]
@@ -162,7 +164,7 @@ namespace sndx::render {
162164
return it->second;
163165
}
164166

165-
auto ret = glGetUniformLocation(id, uid.c_str());
167+
auto ret = glGetUniformLocation(m_id, uid.c_str());
166168
uniformCache.emplace(uid, ret);
167169
return ret;
168170
}
@@ -289,21 +291,13 @@ namespace sndx::render {
289291
shaders[i] = std::move(shdr.value());
290292
}
291293
else {
292-
for (; i > 0; --i) {
293-
shaders[i - 1].destroy();
294-
}
295294
return {};
296295
}
297296

298297
++i;
299298
}
300299

301300
auto out = ShaderProgram(shaders);
302-
303-
for (auto& shader : shaders) {
304-
shader.destroy();
305-
}
306-
307301
return out;
308302
}
309303
}

src/include/sndx/render/gl/texture.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ namespace sndx::render {
5151
GLenum m_target{GL_TEXTURE_2D};
5252

5353
public:
54+
55+
explicit Texture2D() = default;
56+
5457
Texture2D(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* data, GLint mipmaps = 0) :
5558
m_width(width), m_height(height), m_target(target) {
5659

5760
glGenTextures(1, &m_id);
5861
glBindTexture(m_target, m_id);
59-
glTexImage2D(m_target, mipmaps, internalFormat, m_width, m_height, 0, format, type, data);
62+
glTexImage2D(m_target, mipmaps, internalFormat, GLsizei(m_width), GLsizei(m_height), 0, format, type, data);
6063
}
6164

6265
Texture2D(const ImageData& image, GLint mipmaps = 0, bool compress = true) :
6366
Texture2D(GL_TEXTURE_2D, formatFromChannels(image.channels(), compress),
64-
image.width(), image.height(), formatFromChannels(image.channels(), false), GL_UNSIGNED_BYTE, image.data()) { }
67+
GLsizei(image.width()), GLsizei(image.height()), formatFromChannels(image.channels(), false), GL_UNSIGNED_BYTE, image.data()) { }
6568

6669
Texture2D(const Texture2D&) = delete;
6770
Texture2D(Texture2D&& other) noexcept :

src/include/sndx/render/gl/vao.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace sndx::render {
1010
GLuint m_id = 0;
1111

1212
void destroy() noexcept {
13-
glDeleteVertexArrays(&m_id);
13+
glDeleteVertexArrays(1, &m_id);
1414
curIdx = 0;
1515
m_id = 0;
1616
}
@@ -48,15 +48,15 @@ namespace sndx::render {
4848
template <class... Layout>
4949
void bindLayout(TypedVBO<Layout...>& vbo, GLuint divisor = 0) {
5050
bind();
51-
vbo.bind();
51+
vbo.bind(GL_ARRAY_BUFFER);
5252
curIdx += VboLayout<Layout...>::vertexAttribPointer(curIdx, divisor);
5353
}
5454

5555
void resetLayout() {
5656
if (m_id != 0) {
5757
bind();
5858
for (size_t i = 0; i < curIdx; ++i) {
59-
glDisableVertexAttribArray(i);
59+
glDisableVertexAttribArray(GLuint(i));
6060
}
6161
curIdx = 0;
6262
}
@@ -66,7 +66,7 @@ namespace sndx::render {
6666
if (m_id != 0) {
6767
destroy();
6868
}
69-
glGenVertexArrays(1, &m_idx);
69+
glGenVertexArrays(1, &m_id);
7070
}
7171
};
7272
}

0 commit comments

Comments
 (0)