1
0
Fork 0

Codechange: Use std::array in OpenGLSprite to remove MemSetT.

pull/13829/head
Peter Nelson 2025-03-08 19:38:14 +00:00 committed by Peter Nelson
parent a87b804386
commit 653e886d26
2 changed files with 10 additions and 13 deletions

View File

@ -29,9 +29,7 @@
#include "opengl.h" #include "opengl.h"
#include "../core/geometry_func.hpp" #include "../core/geometry_func.hpp"
#include "../core/mem_func.hpp"
#include "../core/math_func.hpp" #include "../core/math_func.hpp"
#include "../core/mem_func.hpp"
#include "../gfx_func.h" #include "../gfx_func.h"
#include "../debug.h" #include "../debug.h"
#include "../blitter/factory.hpp" #include "../blitter/factory.hpp"
@ -1315,7 +1313,7 @@ void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int
} }
/* static */ GLuint OpenGLSprite::dummy_tex[] = { 0, 0 }; /* static */ std::array<GLuint, OpenGLSprite::NUM_TEX> OpenGLSprite::dummy_tex{};
/* static */ GLuint OpenGLSprite::pal_identity = 0; /* static */ GLuint OpenGLSprite::pal_identity = 0;
/* static */ GLuint OpenGLSprite::pal_tex = 0; /* static */ GLuint OpenGLSprite::pal_tex = 0;
/* static */ GLuint OpenGLSprite::pal_pbo = 0; /* static */ GLuint OpenGLSprite::pal_pbo = 0;
@ -1326,7 +1324,7 @@ void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int
*/ */
/* static */ bool OpenGLSprite::Create() /* static */ bool OpenGLSprite::Create()
{ {
_glGenTextures(NUM_TEX, OpenGLSprite::dummy_tex); _glGenTextures(NUM_TEX, OpenGLSprite::dummy_tex.data());
for (int t = TEX_RGBA; t < NUM_TEX; t++) { for (int t = TEX_RGBA; t < NUM_TEX; t++) {
_glBindTexture(GL_TEXTURE_2D, OpenGLSprite::dummy_tex[t]); _glBindTexture(GL_TEXTURE_2D, OpenGLSprite::dummy_tex[t]);
@ -1387,7 +1385,7 @@ void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int
/** Free all common resources for sprite rendering. */ /** Free all common resources for sprite rendering. */
/* static */ void OpenGLSprite::Destroy() /* static */ void OpenGLSprite::Destroy()
{ {
_glDeleteTextures(NUM_TEX, OpenGLSprite::dummy_tex); _glDeleteTextures(NUM_TEX, OpenGLSprite::dummy_tex.data());
_glDeleteTextures(1, &OpenGLSprite::pal_identity); _glDeleteTextures(1, &OpenGLSprite::pal_identity);
_glDeleteTextures(1, &OpenGLSprite::pal_tex); _glDeleteTextures(1, &OpenGLSprite::pal_tex);
if (_glDeleteBuffers != nullptr) _glDeleteBuffers(1, &OpenGLSprite::pal_pbo); if (_glDeleteBuffers != nullptr) _glDeleteBuffers(1, &OpenGLSprite::pal_pbo);
@ -1404,7 +1402,7 @@ OpenGLSprite::OpenGLSprite(const SpriteLoader::SpriteCollection &sprite) :
assert(levels > 0); assert(levels > 0);
(void)_glGetError(); (void)_glGetError();
MemSetT(this->tex, 0, NUM_TEX); this->tex = {};
_glActiveTexture(GL_TEXTURE0); _glActiveTexture(GL_TEXTURE0);
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
@ -1444,7 +1442,7 @@ OpenGLSprite::OpenGLSprite(const SpriteLoader::SpriteCollection &sprite) :
OpenGLSprite::~OpenGLSprite() OpenGLSprite::~OpenGLSprite()
{ {
_glDeleteTextures(NUM_TEX, this->tex); _glDeleteTextures(NUM_TEX, this->tex.data());
} }
/** /**

View File

@ -10,7 +10,6 @@
#ifndef VIDEO_OPENGL_H #ifndef VIDEO_OPENGL_H
#define VIDEO_OPENGL_H #define VIDEO_OPENGL_H
#include "../core/alloc_type.hpp"
#include "../core/geometry_type.hpp" #include "../core/geometry_type.hpp"
#include "../gfx_type.h" #include "../gfx_type.h"
#include "../spriteloader/spriteloader.hpp" #include "../spriteloader/spriteloader.hpp"
@ -121,12 +120,12 @@ private:
NUM_TEX NUM_TEX
}; };
Dimension dim; Dimension dim{};
GLuint tex[NUM_TEX]; ///< The texture objects. std::array<GLuint, NUM_TEX> tex{}; ///< The texture objects.
int16_t x_offs; ///< Number of pixels to shift the sprite to the right. int16_t x_offs = 0; ///< Number of pixels to shift the sprite to the right.
int16_t y_offs; ///< Number of pixels to shift the sprite downwards. int16_t y_offs = 0; ///< Number of pixels to shift the sprite downwards.
static GLuint dummy_tex[NUM_TEX]; ///< 1x1 dummy textures to substitute for unused sprite components. static std::array<GLuint, NUM_TEX> dummy_tex; ///< 1x1 dummy textures to substitute for unused sprite components.
static GLuint pal_identity; ///< Identity texture mapping. static GLuint pal_identity; ///< Identity texture mapping.
static GLuint pal_tex; ///< Texture for palette remap. static GLuint pal_tex; ///< Texture for palette remap.