fix: optimization: PVS-Studio warning V813
Passing large objects by const reference avoids unnecessary copying and enhances efficiency. Reported by: PVS-Studio Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
@@ -59,8 +59,8 @@ void Batch2D::vertex(
|
||||
buffer[index++] = a;
|
||||
}
|
||||
void Batch2D::vertex(
|
||||
glm::vec2 point,
|
||||
glm::vec2 uvpoint,
|
||||
const glm::vec2& point,
|
||||
const glm::vec2& uvpoint,
|
||||
float r, float g, float b, float a
|
||||
) {
|
||||
buffer[index++] = point.x;
|
||||
@@ -138,7 +138,7 @@ void Batch2D::rect(
|
||||
UVRegion region,
|
||||
bool flippedX,
|
||||
bool flippedY,
|
||||
glm::vec4 tint
|
||||
const glm::vec4& tint
|
||||
) {
|
||||
if (index + 6*B2D_VERTEX_SIZE >= capacity) {
|
||||
flush();
|
||||
@@ -322,11 +322,13 @@ void Batch2D::rect(
|
||||
vertex(v1, glm::vec2(0, 0), r2,g2,b2,1.0f);
|
||||
}
|
||||
|
||||
void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region, glm::vec4 tint){
|
||||
void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region,
|
||||
const glm::vec4& tint){
|
||||
rect(x, y, w, h, region.u1, region.v1, region.u2-region.u1, region.v2-region.v1, tint.r, tint.g, tint.b, tint.a);
|
||||
}
|
||||
|
||||
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint){
|
||||
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index,
|
||||
const glm::vec4& tint){
|
||||
float scale = 1.0f / (float)atlasRes;
|
||||
float u = (index % atlasRes) * scale;
|
||||
float v = 1.0f - ((index / atlasRes) * scale) - scale;
|
||||
|
||||
@@ -31,8 +31,8 @@ class Batch2D : public Flushable {
|
||||
);
|
||||
|
||||
void vertex(
|
||||
glm::vec2 point,
|
||||
glm::vec2 uvpoint,
|
||||
const glm::vec2& point,
|
||||
const glm::vec2& uvpoint,
|
||||
float r, float g, float b, float a
|
||||
);
|
||||
|
||||
@@ -44,11 +44,13 @@ public:
|
||||
void texture(Texture* texture);
|
||||
void untexture();
|
||||
void setRegion(UVRegion region);
|
||||
void sprite(float x, float y, float w, float h, const UVRegion& region, glm::vec4 tint);
|
||||
void sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint);
|
||||
void sprite(float x, float y, float w, float h, const UVRegion& region,
|
||||
const glm::vec4& tint);
|
||||
void sprite(float x, float y, float w, float h, int atlasRes, int index,
|
||||
const glm::vec4& tint);
|
||||
void point(float x, float y, float r, float g, float b, float a);
|
||||
|
||||
inline void setColor(glm::vec4 color) {
|
||||
inline void setColor(const glm::vec4& color) {
|
||||
this->color = color;
|
||||
}
|
||||
inline glm::vec4 getColor() const {
|
||||
@@ -69,7 +71,7 @@ public:
|
||||
float ox, float oy,
|
||||
float angle, UVRegion region,
|
||||
bool flippedX, bool flippedY,
|
||||
glm::vec4 tint
|
||||
const glm::vec4& tint
|
||||
);
|
||||
|
||||
void rect(float x, float y, float w, float h);
|
||||
|
||||
@@ -51,7 +51,7 @@ void Batch3D::vertex(
|
||||
buffer[index++] = a;
|
||||
}
|
||||
void Batch3D::vertex(
|
||||
glm::vec3 coord, float u, float v,
|
||||
const glm::vec3& coord, float u, float v,
|
||||
float r, float g, float b, float a
|
||||
) {
|
||||
buffer[index++] = coord.x;
|
||||
@@ -65,8 +65,8 @@ void Batch3D::vertex(
|
||||
buffer[index++] = a;
|
||||
}
|
||||
void Batch3D::vertex(
|
||||
glm::vec3 point,
|
||||
glm::vec2 uvpoint,
|
||||
const glm::vec3& point,
|
||||
const glm::vec2& uvpoint,
|
||||
float r, float g, float b, float a
|
||||
) {
|
||||
buffer[index++] = point.x;
|
||||
@@ -118,12 +118,12 @@ void Batch3D::texture(Texture* new_texture){
|
||||
}
|
||||
|
||||
void Batch3D::sprite(
|
||||
glm::vec3 pos,
|
||||
glm::vec3 up,
|
||||
glm::vec3 right,
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& right,
|
||||
float w, float h,
|
||||
const UVRegion& uv,
|
||||
glm::vec4 color
|
||||
const UVRegion& uv,
|
||||
const glm::vec4& color
|
||||
){
|
||||
const float r = color.r;
|
||||
const float g = color.g;
|
||||
@@ -245,11 +245,11 @@ void Batch3D::blockCube(
|
||||
cube((1.0f - size) * -0.5f, size, texfaces, tint, shading);
|
||||
}
|
||||
|
||||
void Batch3D::point(glm::vec3 coord, glm::vec2 uv, glm::vec4 tint) {
|
||||
void Batch3D::point(const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint) {
|
||||
vertex(coord, uv, tint.r, tint.g, tint.b, tint.a);
|
||||
}
|
||||
|
||||
void Batch3D::point(glm::vec3 coord, glm::vec4 tint) {
|
||||
void Batch3D::point(const glm::vec3& coord, const glm::vec4& tint) {
|
||||
point(coord, glm::vec2(), tint);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,13 @@ class Batch3D : public Flushable {
|
||||
float r, float g, float b, float a
|
||||
);
|
||||
void vertex(
|
||||
glm::vec3 coord,
|
||||
const glm::vec3& coord,
|
||||
float u, float v,
|
||||
float r, float g, float b, float a
|
||||
);
|
||||
void vertex(
|
||||
glm::vec3 point, glm::vec2 uvpoint,
|
||||
const glm::vec3& point,
|
||||
const glm::vec2& uvpoint,
|
||||
float r, float g, float b, float a
|
||||
);
|
||||
void face(
|
||||
@@ -49,12 +50,18 @@ public:
|
||||
|
||||
void begin();
|
||||
void texture(Texture* texture);
|
||||
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, const UVRegion& uv, glm::vec4 tint);
|
||||
void sprite(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& right, float w, float h, const UVRegion& uv,
|
||||
const glm::vec4& color
|
||||
);
|
||||
void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true);
|
||||
void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
|
||||
void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
|
||||
void point(glm::vec3 pos, glm::vec2 uv, glm::vec4 tint);
|
||||
void point(glm::vec3 pos, glm::vec4 tint);
|
||||
void point(
|
||||
const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint);
|
||||
void point(const glm::vec3& coord, const glm::vec4& tint);
|
||||
void flush() override;
|
||||
void flushPoints();
|
||||
};
|
||||
|
||||
@@ -148,7 +148,7 @@ void DrawContext::setBlendMode(BlendMode mode) {
|
||||
set_blend_mode(mode);
|
||||
}
|
||||
|
||||
void DrawContext::setScissors(glm::vec4 area) {
|
||||
void DrawContext::setScissors(const glm::vec4& area) {
|
||||
Window::pushScissor(area);
|
||||
scissorsCount++;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
void setDepthTest(bool flag);
|
||||
void setCullFace(bool flag);
|
||||
void setBlendMode(BlendMode mode);
|
||||
void setScissors(glm::vec4 area);
|
||||
void setScissors(const glm::vec4& area);
|
||||
void setLineWidth(float width);
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
LineBatch(size_t capacity=4096);
|
||||
~LineBatch();
|
||||
|
||||
inline void line(const glm::vec3 a, const glm::vec3 b, const glm::vec4 color) {
|
||||
inline void line(const glm::vec3 &a, const glm::vec3 &b, const glm::vec4 &color) {
|
||||
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,
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
void box(float x, float y, float z, float w, float h, float d,
|
||||
float r, float g, float b, float a);
|
||||
|
||||
inline void box(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) {
|
||||
inline void box(const glm::vec3 &xyz, const glm::vec3 &whd, const glm::vec4 &rgba) {
|
||||
box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z,
|
||||
rgba.r, rgba.g, rgba.b, rgba.a);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@ inline constexpr glm::vec3 X(1, 0, 0);
|
||||
inline constexpr glm::vec3 Y(0, 1, 0);
|
||||
inline constexpr glm::vec3 Z(0, 0, 1);
|
||||
|
||||
void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) {
|
||||
void Mesh::addPlane(
|
||||
const glm::vec3 &pos,
|
||||
const glm::vec3 &right,
|
||||
const glm::vec3 &up,
|
||||
const glm::vec3 &norm) {
|
||||
vertices.push_back({pos-right-up, {0,0}, norm});
|
||||
vertices.push_back({pos+right-up, {1,0}, norm});
|
||||
vertices.push_back({pos+right+up, {1,1}, norm});
|
||||
@@ -18,7 +22,7 @@ void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm
|
||||
vertices.push_back({pos-right+up, {0,1}, norm});
|
||||
}
|
||||
|
||||
void Mesh::addBox(glm::vec3 pos, glm::vec3 size) {
|
||||
void Mesh::addBox(const glm::vec3 &pos, const glm::vec3 &size) {
|
||||
addPlane(pos+Z*size, X*size, Y*size, Z);
|
||||
addPlane(pos-Z*size, -X*size, Y*size, -Z);
|
||||
|
||||
|
||||
@@ -16,8 +16,12 @@ namespace model {
|
||||
std::string texture;
|
||||
std::vector<Vertex> vertices;
|
||||
|
||||
void addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm);
|
||||
void addBox(glm::vec3 pos, glm::vec3 size);
|
||||
void addPlane(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& right,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& norm);
|
||||
void addBox(const glm::vec3& pos, const glm::vec3& size);
|
||||
};
|
||||
|
||||
struct Model {
|
||||
|
||||
@@ -54,11 +54,11 @@ void Shader::uniform2f(const std::string& name, float x, float y){
|
||||
glUniform2f(getUniformLocation(name), x, y);
|
||||
}
|
||||
|
||||
void Shader::uniform2f(const std::string& name, glm::vec2 xy){
|
||||
void Shader::uniform2f(const std::string& name, const glm::vec2& xy){
|
||||
glUniform2f(getUniformLocation(name), xy.x, xy.y);
|
||||
}
|
||||
|
||||
void Shader::uniform2i(const std::string& name, glm::ivec2 xy){
|
||||
void Shader::uniform2i(const std::string& name, const glm::ivec2& xy){
|
||||
glUniform2i(getUniformLocation(name), xy.x, xy.y);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void Shader::uniform3f(const std::string& name, float x, float y, float z){
|
||||
glUniform3f(getUniformLocation(name), x,y,z);
|
||||
}
|
||||
|
||||
void Shader::uniform3f(const std::string& name, glm::vec3 xyz){
|
||||
void Shader::uniform3f(const std::string& name, const glm::vec3& xyz){
|
||||
glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ public:
|
||||
void uniform1i(const std::string& name, int x);
|
||||
void uniform1f(const std::string& name, float x);
|
||||
void uniform2f(const std::string& name, float x, float y);
|
||||
void uniform2f(const std::string& name, glm::vec2 xy);
|
||||
void uniform2i(const std::string& name, glm::ivec2 xy);
|
||||
void uniform2f(const std::string& name, const glm::vec2& xy);
|
||||
void uniform2i(const std::string& name, const glm::ivec2& xy);
|
||||
void uniform3f(const std::string& name, float x, float y, float z);
|
||||
void uniform3f(const std::string& name, glm::vec3 xyz);
|
||||
void uniform3f(const std::string& name, const glm::vec3& xyz);
|
||||
|
||||
/// @brief Create shader program using vertex and fragment shaders source.
|
||||
/// @param vertexFile vertex shader file name
|
||||
|
||||
@@ -35,7 +35,7 @@ struct DecomposedMat4 {
|
||||
glm::vec4 perspective;
|
||||
};
|
||||
|
||||
static glm::mat4 extract_rotation(glm::mat4 matrix) {
|
||||
static glm::mat4 extract_rotation(const glm::mat4& matrix) {
|
||||
DecomposedMat4 decomposed = {};
|
||||
glm::quat rotation;
|
||||
glm::decompose(
|
||||
@@ -66,8 +66,10 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
|
||||
|
||||
ModelBatch::~ModelBatch() = default;
|
||||
|
||||
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
||||
const glm::mat3& rotation, glm::vec3 tint,
|
||||
void ModelBatch::draw(const model::Mesh& mesh,
|
||||
const glm::mat4& matrix,
|
||||
const glm::mat3& rotation,
|
||||
const glm::vec3& tint,
|
||||
const texture_names_map* varTextures) {
|
||||
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z));
|
||||
@@ -94,8 +96,9 @@ void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
||||
}
|
||||
}
|
||||
|
||||
void ModelBatch::draw(glm::mat4 matrix,
|
||||
glm::vec3 tint,
|
||||
void ModelBatch::draw(
|
||||
const glm::mat4& matrix,
|
||||
const glm::vec3& tint,
|
||||
const model::Model* model,
|
||||
const texture_names_map* varTextures) {
|
||||
for (const auto& mesh : model->meshes) {
|
||||
|
||||
@@ -37,7 +37,10 @@ class ModelBatch {
|
||||
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
|
||||
|
||||
inline void vertex(
|
||||
glm::vec3 pos, glm::vec2 uv, glm::vec4 light, glm::vec3 tint
|
||||
const glm::vec3& pos,
|
||||
const glm::vec2& uv,
|
||||
const glm::vec4& light,
|
||||
const glm::vec3& tint
|
||||
) {
|
||||
float* buffer = this->buffer.get();
|
||||
buffer[index++] = pos.x;
|
||||
@@ -64,8 +67,8 @@ class ModelBatch {
|
||||
|
||||
void draw(const model::Mesh& mesh,
|
||||
const glm::mat4& matrix,
|
||||
const glm::mat3& rotation,
|
||||
glm::vec3 tint,
|
||||
const glm::mat3& rotation,
|
||||
const glm::vec3& tint,
|
||||
const texture_names_map* varTextures);
|
||||
void setTexture(const std::string& name,
|
||||
const texture_names_map* varTextures);
|
||||
@@ -84,8 +87,9 @@ public:
|
||||
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
|
||||
~ModelBatch();
|
||||
|
||||
void draw(glm::mat4 matrix,
|
||||
glm::vec3 tint,
|
||||
void draw(
|
||||
const glm::mat4& matrix,
|
||||
const glm::vec3& tint,
|
||||
const model::Model* model,
|
||||
const texture_names_map* varTextures);
|
||||
void render();
|
||||
|
||||
@@ -230,10 +230,12 @@ void WorldRenderer::renderBlockSelection() {
|
||||
: block->hitboxes;
|
||||
|
||||
lineBatch->lineWidth(2.0f);
|
||||
constexpr auto boxOffset = glm::vec3(0.02);
|
||||
constexpr auto boxColor = glm::vec4(0.f, 0.f, 0.f, 0.5f);
|
||||
for (auto& hitbox: hitboxes) {
|
||||
const glm::vec3 center = glm::vec3(pos) + hitbox.center();
|
||||
const glm::vec3 size = hitbox.size();
|
||||
lineBatch->box(center, size + glm::vec3(0.02), glm::vec4(0.f, 0.f, 0.f, 0.5f));
|
||||
lineBatch->box(center, size + boxOffset, boxColor);
|
||||
if (player->debug) {
|
||||
lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||
}
|
||||
@@ -340,12 +342,12 @@ void WorldRenderer::draw(
|
||||
ctx.setDepthTest(true);
|
||||
ctx.setCullFace(true);
|
||||
renderLevel(ctx, camera, settings, delta, pause);
|
||||
// Debug lines
|
||||
|
||||
if (hudVisible){
|
||||
renderLines(camera, linesShader, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug lines
|
||||
if (hudVisible && player->debug) {
|
||||
renderDebugLines(wctx, camera, linesShader);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ InventoryBuilder::InventoryBuilder() {
|
||||
|
||||
void InventoryBuilder::addGrid(
|
||||
int cols, int count,
|
||||
glm::vec2 pos,
|
||||
const glm::vec2 &pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
const SlotLayout& slotLayout
|
||||
@@ -381,7 +381,7 @@ void InventoryView::setPos(glm::vec2 pos) {
|
||||
Container::setPos(pos - origin);
|
||||
}
|
||||
|
||||
void InventoryView::setOrigin(glm::vec2 origin) {
|
||||
void InventoryView::setOrigin(const glm::vec2 &origin) {
|
||||
this->origin = origin;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace gui {
|
||||
|
||||
virtual void setPos(glm::vec2 pos) override;
|
||||
|
||||
void setOrigin(glm::vec2 origin);
|
||||
void setOrigin(const glm::vec2 &origin);
|
||||
glm::vec2 getOrigin() const;
|
||||
|
||||
void setSelected(int index);
|
||||
@@ -130,7 +130,7 @@ namespace gui {
|
||||
/// @param slotLayout slot settings (index and position are ignored)
|
||||
void addGrid(
|
||||
int cols, int count,
|
||||
glm::vec2 pos,
|
||||
const glm::vec2 &pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
const SlotLayout& slotLayout
|
||||
|
||||
Reference in New Issue
Block a user