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
|
||||
|
||||
Reference in New Issue
Block a user