remove unnecessary 'new' operators

This commit is contained in:
MihailRis
2024-07-01 06:00:33 +03:00
parent 26e2068164
commit fab124a2e2
9 changed files with 36 additions and 42 deletions
+4 -2
View File
@@ -254,7 +254,7 @@ void ImageData::fixAlphaColor() {
}
}
ImageData* add_atlas_margins(ImageData* image, int grid_size) {
std::unique_ptr<ImageData> add_atlas_margins(ImageData* image, int grid_size) {
// RGBA is only supported
assert(image->getFormat() == ImageFormat::rgba8888);
assert(image->getWidth() == image->getHeight());
@@ -300,5 +300,7 @@ ImageData* add_atlas_margins(ImageData* image, int grid_size) {
}
}
}
return new ImageData(image->getFormat(), dstwidth, dstheight, std::move(dstdata));
return std::make_unique<ImageData>(
image->getFormat(), dstwidth, dstheight, std::move(dstdata)
);
}
+1 -1
View File
@@ -47,6 +47,6 @@ public:
}
};
extern ImageData* add_atlas_margins(ImageData* image, int grid_size);
std::unique_ptr<ImageData> add_atlas_margins(ImageData* image, int grid_size);
#endif // GRAPHICS_CORE_IMAGE_DATA_HPP_
+3 -4
View File
@@ -7,13 +7,12 @@ inline constexpr uint LB_VERTEX_SIZE = (3+4);
LineBatch::LineBatch(size_t capacity) : capacity(capacity) {
const vattr attrs[] = { {3},{4}, {0} };
buffer = new float[capacity * LB_VERTEX_SIZE * 2];
mesh = std::make_unique<Mesh>(buffer, 0, attrs);
buffer = std::make_unique<float[]>(capacity * LB_VERTEX_SIZE * 2);
mesh = std::make_unique<Mesh>(buffer.get(), 0, attrs);
index = 0;
}
LineBatch::~LineBatch(){
delete[] buffer;
}
void LineBatch::line(
@@ -69,7 +68,7 @@ void LineBatch::box(float x, float y, float z, float w, float h, float d,
void LineBatch::render(){
if (index == 0)
return;
mesh->reload(buffer, index / LB_VERTEX_SIZE);
mesh->reload(buffer.get(), index / LB_VERTEX_SIZE);
mesh->draw(GL_LINES);
index = 0;
}
+4 -4
View File
@@ -9,7 +9,7 @@ class Mesh;
class LineBatch {
std::unique_ptr<Mesh> mesh;
float* buffer;
std::unique_ptr<float[]> buffer;
size_t index;
size_t capacity;
public:
@@ -20,13 +20,13 @@ public:
line(a.x, a.y, a.z, b.x, b.y, b.z, color.r, color.g, color.b, color.a);
}
void line(float x1, float y1, float z1, float x2, float y2, float z2,
float r, float g, float b, float a);
float r, float g, float b, float a);
void box(float x, float y, float z, float w, float h, float d,
float r, float g, float b, float a);
float r, float g, float b, float a);
inline void box(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) {
box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z,
rgba.r, rgba.g, rgba.b, rgba.a);
rgba.r, rgba.g, rgba.b, rgba.a);
}
void render();