gl: Avoid issuing glDelete calls with m_id == GL_NONE

Applies GL_NONE macro usage where it makes sense
This commit is contained in:
AniLeo 2020-05-14 13:53:40 +01:00 committed by Ani
parent d4333788e2
commit 3ad12cf5f8
2 changed files with 57 additions and 27 deletions

View file

@ -202,13 +202,16 @@ namespace gl
void fbo::remove() void fbo::remove()
{ {
glDeleteFramebuffers(1, &m_id); if (m_id != GL_NONE)
m_id = 0; {
glDeleteFramebuffers(1, &m_id);
m_id = GL_NONE;
}
} }
bool fbo::created() const bool fbo::created() const
{ {
return m_id != 0; return m_id != GL_NONE;
} }
bool fbo::check() const bool fbo::check() const

View file

@ -898,8 +898,11 @@ namespace gl
void remove() void remove()
{ {
glDeleteBuffers(1, &m_id); if (m_id != GL_NONE)
m_id = 0; {
glDeleteBuffers(1, &m_id);
m_id = GL_NONE;
}
} }
GLsizeiptr size() const GLsizeiptr size() const
@ -919,7 +922,7 @@ namespace gl
bool created() const bool created() const
{ {
return m_id != 0; return m_id != GL_NONE;
} }
explicit operator bool() const explicit operator bool() const
@ -1039,8 +1042,12 @@ namespace gl
m_size = 0; m_size = 0;
} }
glDeleteBuffers(1, &m_id);
m_id = 0; if (m_id != GL_NONE)
{
glDeleteBuffers(1, &m_id);
m_id = GL_NONE;
}
} }
virtual void reserve_storage_on_heap(u32 /*alloc_size*/) {} virtual void reserve_storage_on_heap(u32 /*alloc_size*/) {}
@ -1308,8 +1315,11 @@ namespace gl
void remove() noexcept void remove() noexcept
{ {
glDeleteVertexArrays(1, &m_id); if (m_id != GL_NONE)
m_id = GL_NONE; {
glDeleteVertexArrays(1, &m_id);
m_id = GL_NONE;
}
} }
uint id() const noexcept uint id() const noexcept
@ -1573,7 +1583,7 @@ namespace gl
}; };
protected: protected:
GLuint m_id = 0; GLuint m_id = GL_NONE;
GLuint m_width = 0; GLuint m_width = 0;
GLuint m_height = 0; GLuint m_height = 0;
GLuint m_depth = 0; GLuint m_depth = 0;
@ -1728,7 +1738,11 @@ namespace gl
virtual ~texture() virtual ~texture()
{ {
glDeleteTextures(1, &m_id); if (m_id != GL_NONE)
{
glDeleteTextures(1, &m_id);
m_id = GL_NONE;
}
} }
void set_native_component_layout(const std::array<GLenum, 4>& layout) void set_native_component_layout(const std::array<GLenum, 4>& layout)
@ -1765,7 +1779,7 @@ namespace gl
explicit operator bool() const noexcept explicit operator bool() const noexcept
{ {
return (m_id != 0); return (m_id != GL_NONE);
} }
GLuint width() const GLuint width() const
@ -1927,7 +1941,7 @@ namespace gl
class texture_view class texture_view
{ {
GLuint m_id = 0; GLuint m_id = GL_NONE;
GLenum m_target = 0; GLenum m_target = 0;
GLenum m_format = 0; GLenum m_format = 0;
GLenum m_aspect_flags = 0; GLenum m_aspect_flags = 0;
@ -2005,7 +2019,11 @@ namespace gl
~texture_view() ~texture_view()
{ {
glDeleteTextures(1, &m_id); if (m_id != GL_NONE)
{
glDeleteTextures(1, &m_id);
m_id = GL_NONE;
}
} }
GLuint id() const GLuint id() const
@ -2099,7 +2117,7 @@ public:
class rbo class rbo
{ {
GLuint m_id = 0; GLuint m_id = GL_NONE;
public: public:
rbo() = default; rbo() = default;
@ -2172,8 +2190,11 @@ public:
void remove() void remove()
{ {
glDeleteRenderbuffers(1, &m_id); if (m_id != GL_NONE)
m_id = 0; {
glDeleteRenderbuffers(1, &m_id);
m_id = GL_NONE;
}
} }
uint id() const uint id() const
@ -2188,7 +2209,7 @@ public:
bool created() const bool created() const
{ {
return m_id != 0; return m_id != GL_NONE;
} }
explicit operator bool() const explicit operator bool() const
@ -2289,7 +2310,7 @@ public:
return found->second; return found->second;
} }
return GL_NONE; return 0;
} }
void operator = (const rbo& rhs) void operator = (const rbo& rhs)
@ -2522,8 +2543,11 @@ public:
void remove() void remove()
{ {
glDeleteShader(m_id); if (m_id != GL_NONE)
m_id = 0; {
glDeleteShader(m_id);
m_id = GL_NONE;
}
} }
uint id() const uint id() const
@ -2538,7 +2562,7 @@ public:
bool created() const bool created() const
{ {
return m_id != 0; return m_id != GL_NONE;
} }
explicit operator bool() const explicit operator bool() const
@ -2549,7 +2573,7 @@ public:
class program class program
{ {
GLuint m_id = 0; GLuint m_id = GL_NONE;
fence m_fence; fence m_fence;
public: public:
@ -2697,8 +2721,11 @@ public:
void remove() void remove()
{ {
glDeleteProgram(m_id); if (m_id != GL_NONE)
m_id = 0; {
glDeleteProgram(m_id);
m_id = GL_NONE;
}
uniforms.clear(); uniforms.clear();
} }
@ -2784,7 +2811,7 @@ public:
bool created() const bool created() const
{ {
return m_id != 0; return m_id != GL_NONE;
} }
void sync() void sync()