Skip to content

Commit

Permalink
gl: Avoid issuing glDelete calls with m_id == GL_NONE
Browse files Browse the repository at this point in the history
Applies GL_NONE macro usage where it makes sense
  • Loading branch information
AniLeo committed May 15, 2020
1 parent d9d66fb commit 5250d19
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
9 changes: 6 additions & 3 deletions rpcs3/Emu/RSX/GL/GLHelpers.cpp
Expand Up @@ -202,13 +202,16 @@ namespace gl

void fbo::remove()
{
glDeleteFramebuffers(1, &m_id);
m_id = 0;
if (m_id != GL_NONE)
{
glDeleteFramebuffers(1, &m_id);
m_id = GL_NONE;
}
}

bool fbo::created() const
{
return m_id != 0;
return m_id != GL_NONE;
}

bool fbo::check() const
Expand Down
75 changes: 51 additions & 24 deletions rpcs3/Emu/RSX/GL/GLHelpers.h
Expand Up @@ -898,8 +898,11 @@ namespace gl

void remove()
{
glDeleteBuffers(1, &m_id);
m_id = 0;
if (m_id != GL_NONE)
{
glDeleteBuffers(1, &m_id);
m_id = GL_NONE;
}
}

GLsizeiptr size() const
Expand All @@ -919,7 +922,7 @@ namespace gl

bool created() const
{
return m_id != 0;
return m_id != GL_NONE;
}

explicit operator bool() const
Expand Down Expand Up @@ -1039,8 +1042,12 @@ namespace gl
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*/) {}
Expand Down Expand Up @@ -1308,8 +1315,11 @@ namespace gl

void remove() noexcept
{
glDeleteVertexArrays(1, &m_id);
m_id = GL_NONE;
if (m_id != GL_NONE)
{
glDeleteVertexArrays(1, &m_id);
m_id = GL_NONE;
}
}

uint id() const noexcept
Expand Down Expand Up @@ -1573,7 +1583,7 @@ namespace gl
};

protected:
GLuint m_id = 0;
GLuint m_id = GL_NONE;
GLuint m_width = 0;
GLuint m_height = 0;
GLuint m_depth = 0;
Expand Down Expand Up @@ -1728,7 +1738,11 @@ namespace gl

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)
Expand Down Expand Up @@ -1765,7 +1779,7 @@ namespace gl

explicit operator bool() const noexcept
{
return (m_id != 0);
return (m_id != GL_NONE);
}

GLuint width() const
Expand Down Expand Up @@ -1927,7 +1941,7 @@ namespace gl

class texture_view
{
GLuint m_id = 0;
GLuint m_id = GL_NONE;
GLenum m_target = 0;
GLenum m_format = 0;
GLenum m_aspect_flags = 0;
Expand Down Expand Up @@ -2005,7 +2019,11 @@ namespace gl

~texture_view()
{
glDeleteTextures(1, &m_id);
if (m_id != GL_NONE)
{
glDeleteTextures(1, &m_id);
m_id = GL_NONE;
}
}

GLuint id() const
Expand Down Expand Up @@ -2099,7 +2117,7 @@ namespace gl

class rbo
{
GLuint m_id = 0;
GLuint m_id = GL_NONE;

public:
rbo() = default;
Expand Down Expand Up @@ -2172,8 +2190,11 @@ namespace gl

void remove()
{
glDeleteRenderbuffers(1, &m_id);
m_id = 0;
if (m_id != GL_NONE)
{
glDeleteRenderbuffers(1, &m_id);
m_id = GL_NONE;
}
}

uint id() const
Expand All @@ -2188,7 +2209,7 @@ namespace gl

bool created() const
{
return m_id != 0;
return m_id != GL_NONE;
}

explicit operator bool() const
Expand Down Expand Up @@ -2289,7 +2310,7 @@ namespace gl
return found->second;
}

return GL_NONE;
return 0;
}

void operator = (const rbo& rhs)
Expand Down Expand Up @@ -2522,8 +2543,11 @@ namespace gl

void remove()
{
glDeleteShader(m_id);
m_id = 0;
if (m_id != GL_NONE)
{
glDeleteShader(m_id);
m_id = GL_NONE;
}
}

uint id() const
Expand All @@ -2538,7 +2562,7 @@ namespace gl

bool created() const
{
return m_id != 0;
return m_id != GL_NONE;
}

explicit operator bool() const
Expand All @@ -2549,7 +2573,7 @@ namespace gl

class program
{
GLuint m_id = 0;
GLuint m_id = GL_NONE;
fence m_fence;

public:
Expand Down Expand Up @@ -2697,8 +2721,11 @@ namespace gl

void remove()
{
glDeleteProgram(m_id);
m_id = 0;
if (m_id != GL_NONE)
{
glDeleteProgram(m_id);
m_id = GL_NONE;
}
uniforms.clear();
}

Expand Down Expand Up @@ -2784,7 +2811,7 @@ namespace gl

bool created() const
{
return m_id != 0;
return m_id != GL_NONE;
}

void sync()
Expand Down

0 comments on commit 5250d19

Please sign in to comment.