From 44a26af2705c45c04d5776e06ce91bdc459c8e95 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 16 Oct 2023 15:36:42 +0100 Subject: [PATCH] Fixed various compilation issues: shadow variables & uninitilised members Change-Id: I385b31d045a2c0cb377e4b5f9f3991bd4d3870c0 --- examples/bullet-physics/ball-renderer.cpp | 36 ++++++-------- examples/camera-test/camera-test-example.cpp | 38 +++++++-------- examples/direct-rendering/native-renderer.cpp | 70 ++++++++++++++++----------- examples/drawable-actor/native-renderer.cpp | 3 +- 4 files changed, 77 insertions(+), 70 deletions(-) diff --git a/examples/bullet-physics/ball-renderer.cpp b/examples/bullet-physics/ball-renderer.cpp index c5feeff..6da4448 100644 --- a/examples/bullet-physics/ball-renderer.cpp +++ b/examples/bullet-physics/ball-renderer.cpp @@ -49,15 +49,9 @@ void SubDivide(std::vector& vertices, std::vector& indices) auto v5 = v2 + (v3 - v2) * 0.5f; auto v6 = v3 + (v1 - v3) * 0.5f; uint16_t j = vertices.size(); - vertices.emplace_back(Vertex{ - {v4}, - }); - vertices.emplace_back(Vertex{ - {v5}, - }); - vertices.emplace_back(Vertex{ - {v6}, - }); + vertices.emplace_back(Vertex{v4, Vector2::ZERO}); + vertices.emplace_back(Vertex{v5, Vector2::ZERO}); + vertices.emplace_back(Vertex{v6, Vector2::ZERO}); // Now, original tri breaks into 4, so replace this tri, and add 3 more uint16_t i1 = indices[i * 3 + 1]; uint16_t i2 = indices[i * 3 + 2]; @@ -102,21 +96,21 @@ Geometry BallRenderer::CreateBallGeometry() // add vertices std::vector vertices; - vertices.emplace_back(Vertex{Vector3{0, b, -a}}); - vertices.emplace_back(Vertex{Vector3{b, a, 0}}); - vertices.emplace_back(Vertex{Vector3{-b, a, -a}}); + vertices.emplace_back(Vertex{Vector3{0, b, -a}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{b, a, 0}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{-b, a, -a}, Vector2::ZERO}); - vertices.emplace_back(Vertex{Vector3{0, b, a}}); - vertices.emplace_back(Vertex{Vector3{0, -b, a}}); - vertices.emplace_back(Vertex{Vector3{-a, 0, b}}); + vertices.emplace_back(Vertex{Vector3{0, b, a}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{0, -b, a}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{-a, 0, b}, Vector2::ZERO}); - vertices.emplace_back(Vertex{Vector3{0, -b, -a}}); - vertices.emplace_back(Vertex{Vector3{a, 0, -b}}); - vertices.emplace_back(Vertex{Vector3{a, 0, b}}); + vertices.emplace_back(Vertex{Vector3{0, -b, -a}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{a, 0, -b}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{a, 0, b}, Vector2::ZERO}); - vertices.emplace_back(Vertex{Vector3{-a, 0, -b}}); - vertices.emplace_back(Vertex{Vector3{b, -a, 0}}); - vertices.emplace_back(Vertex{Vector3{-b, -a, 0}}); + vertices.emplace_back(Vertex{Vector3{-a, 0, -b}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{b, -a, 0}, Vector2::ZERO}); + vertices.emplace_back(Vertex{Vector3{-b, -a, 0}, Vector2::ZERO}); for(auto& vertex : vertices) { diff --git a/examples/camera-test/camera-test-example.cpp b/examples/camera-test/camera-test-example.cpp index 166d960..760b030 100644 --- a/examples/camera-test/camera-test-example.cpp +++ b/examples/camera-test/camera-test-example.cpp @@ -41,10 +41,10 @@ struct CameraPosConstraint struct BoundaryConstraint { - BoundaryConstraint(std::string name, Vector2 size, bool centered) - : name(name), + BoundaryConstraint(std::string nameParam, Vector2 size, bool centeredParam) + : name(nameParam), boundarySize(size), - centered(centered) + centered(centeredParam) { } void operator()(Vector3& current, const PropertyInputContainer& inputs) @@ -214,7 +214,7 @@ public: Dali::ParentOrigin::CENTER, }; - Layer viewLayer = Layer::New(); + viewLayer = Layer::New(); window.Add(viewLayer); viewLayer.SetProperty(Actor::Property::POSITION, Vector3(position)); @@ -372,7 +372,7 @@ public: return renderTask; } - void ConstrainSceneViewportCamera(RenderTask sceneRenderTask, Vector2 viewportOrigin) + void ConstrainSceneViewportCamera(RenderTask renderTask, Vector2 viewportOrigin) { Constraint constraint = Constraint::New(cameraActor, Actor::Property::POSITION, CameraPosConstraint()); constraint.AddSource(Source(cameraFrame, Actor::Property::POSITION)); @@ -382,11 +382,11 @@ public: constraint.AddSource(Source(cameraFrame, Actor::Property::SIZE)); constraint.Apply(); - constraint = Constraint::New(sceneRenderTask, RenderTask::Property::VIEWPORT_POSITION, ViewportPositionConstraint(viewportOrigin)); + constraint = Constraint::New(renderTask, RenderTask::Property::VIEWPORT_POSITION, ViewportPositionConstraint(viewportOrigin)); constraint.AddSource(Source(viewportFrame, Actor::Property::POSITION)); constraint.Apply(); - constraint = Constraint::New(sceneRenderTask, RenderTask::Property::VIEWPORT_SIZE, ViewportSizeConstraint()); + constraint = Constraint::New(renderTask, RenderTask::Property::VIEWPORT_SIZE, ViewportSizeConstraint()); constraint.AddSource(Source(viewportFrame, Actor::Property::SIZE)); constraint.Apply(); } @@ -403,20 +403,20 @@ public: overlayCameraActor.SetPerspectiveProjection(windowSize); window.Add(overlayCameraActor); - RenderTask overlayRenderTask = window.GetRenderTaskList().CreateTask(); + RenderTask renderTask = window.GetRenderTaskList().CreateTask(); - overlayRenderTask.SetCameraActor(overlayCameraActor); - overlayRenderTask.SetInputEnabled(true); - overlayRenderTask.SetClearEnabled(false); - overlayRenderTask.SetSourceActor(source); - overlayRenderTask.SetExclusive(true); + renderTask.SetCameraActor(overlayCameraActor); + renderTask.SetInputEnabled(true); + renderTask.SetClearEnabled(false); + renderTask.SetSourceActor(source); + renderTask.SetExclusive(true); - overlayRenderTask.SetViewportPosition(Vector2(0, 0)); - overlayRenderTask.SetViewportSize(windowSize); + renderTask.SetViewportPosition(Vector2(0, 0)); + renderTask.SetViewportSize(windowSize); - overlayRenderTask.SetCullMode(false); + renderTask.SetCullMode(false); - return overlayRenderTask; + return renderTask; } Actor CreateFrame(Vector2 position, Vector2 size, std::string label) @@ -567,8 +567,8 @@ public: if(actorIdIndex != Property::INVALID_INDEX) { int actorIndex = slider["actorId"]; - float value = slider["value"]; - imageViews[actorIndex].SetProperty(Actor::Property::ORIENTATION, AngleAxis(Degree(value), Vector3::ZAXIS)); + float newValue = slider["value"]; + imageViews[actorIndex].SetProperty(Actor::Property::ORIENTATION, AngleAxis(Degree(newValue), Vector3::ZAXIS)); } return true; } diff --git a/examples/direct-rendering/native-renderer.cpp b/examples/direct-rendering/native-renderer.cpp index 2c83427..27255c2 100644 --- a/examples/direct-rendering/native-renderer.cpp +++ b/examples/direct-rendering/native-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +23,17 @@ */ namespace { - [[maybe_unused]] std::vector split(const std::string& s, char seperator) { std::vector output; - std::string::size_type prev_pos = 0, pos = 0; + std::string::size_type prev_pos = 0, pos = 0; while((pos = s.find(seperator, pos)) != std::string::npos) { - std::string substring( s.substr(prev_pos, pos-prev_pos) ); + std::string substring(s.substr(prev_pos, pos - prev_pos)); output.push_back(substring); prev_pos = ++pos; } - output.push_back(s.substr(prev_pos, pos-prev_pos)); // Last word + output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word return output; } @@ -52,8 +51,18 @@ int GetEnvInt(const char* name, int def) const uint32_t MAX_CUBES = GetEnvInt("MAX_CUBES", 200); -#define GL(x) {glGetError();{x;};auto err = glGetError();if(err){ \ -printf("%p:%d: ERROR: 0x%X\n", this, __LINE__, int(err));} } +#define GL(x) \ + { \ + glGetError(); \ + { \ + x; \ + }; \ + auto err = glGetError(); \ + if(err) \ + { \ + printf("%p:%d: ERROR: 0x%X\n", this, __LINE__, int(err)); \ + } \ + } constexpr GLfloat CUBE_VERTICES[] = {-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f}; @@ -63,23 +72,29 @@ constexpr GLushort CUBE_INDICES[] = {0, 2, 3, 0, 1, 3, 4, 6, 7, 4, 5, 7, 8, 9, 1 constexpr float QUAD_VERTS[] = { // positions // colors // texture coords - 1.0f, 1.0f, - 1.0f, -1.0f, - -1.0f, -1.0f, - -1.0f, 1.0f, + 1.0f, + 1.0f, + 1.0f, + -1.0f, + -1.0f, + -1.0f, + -1.0f, + 1.0f, }; constexpr unsigned short QUAD_INDICES[] = { - 0, 1, 2, - 3, 0, 2 -}; + 0, 1, 2, 3, 0, 2}; constexpr float QUAD_UV[] = { // positions // colors // texture coords - 1.0f, 1.0f, // top right - 1.0f, 0.0f, // bottom right - 0.0f, 0.0f, // bottom left - 0.0f, 1.0f // top left + 1.0f, + 1.0f, // top right + 1.0f, + 0.0f, // bottom right + 0.0f, + 0.0f, // bottom left + 0.0f, + 1.0f // top left }; float matrixDegreesToRadians(float degrees) @@ -123,7 +138,7 @@ float matrixDegreesToRadians(float degrees) operand1[8 + j] * operand2[4 * i + 2] + operand1[12 + j] * operand2[4 * i + 3]; } } - for(int i = 0; i < 16; i++) + for(i = 0; i < 16; i++) { destination[i] = theResult[i]; } @@ -210,7 +225,7 @@ void matrixFrustum(float* matrix, float left, float right, float bottom, float t NativeRenderer::~NativeRenderer() = default; -NativeRenderer::NativeRenderer(const CreateInfo& info ) +NativeRenderer::NativeRenderer(const CreateInfo& info) : mWidth(info.width), mHeight(info.height), mCreateInfo(info) @@ -338,7 +353,7 @@ void NativeRenderer::RenderCube(const Dali::RenderCallbackInput& input) [[maybe_unused]] auto y = mCreateInfo.viewportY; // float(mHeight - input.size.height) * 0.5f; auto w = mCreateInfo.width; auto h = mCreateInfo.height; - + matrixPerspective(mProjectionMatrix, 45, (float)w / (float)h, 0.1f, 100); GL(glViewport(x, y, w, h)); @@ -355,8 +370,7 @@ void NativeRenderer::RenderCube(const Dali::RenderCallbackInput& input) GL(glClearColor(mCreateInfo.clearColor[0], mCreateInfo.clearColor[1], mCreateInfo.clearColor[2], - mCreateInfo.clearColor[3] - )); + mCreateInfo.clearColor[3])); { GL(glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)); } @@ -370,7 +384,7 @@ void NativeRenderer::RenderCube(const Dali::RenderCallbackInput& input) const auto maxCubes = int(MAX_CUBES); - for( int i = 0; i < int(maxCubes); ++i) + for(int i = 0; i < int(maxCubes); ++i) { GL(matrixIdentityFunction(mModelViewMatrix)); matrixScale(mModelViewMatrix, 0.2f, 0.2f, 0.2f); @@ -379,10 +393,10 @@ void NativeRenderer::RenderCube(const Dali::RenderCallbackInput& input) auto max = 7000; if(mPosX.size() == uint32_t(i)) { - auto x = float((rand() % max) - (max / 2)) / 1000.0f; - auto y = float((rand() % max) - (max / 2)) / 1000.0f; - mPosX.emplace_back(x); - mPosY.emplace_back(y); + auto xPos = float((rand() % max) - (max / 2)) / 1000.0f; + auto yPos = float((rand() % max) - (max / 2)) / 1000.0f; + mPosX.emplace_back(xPos); + mPosY.emplace_back(yPos); } matrixTranslate(mModelViewMatrix, mPosX[i], mPosY[i], -5.0f); GL(glUniformMatrix4fv(mProjectionLocation, 1, GL_FALSE, mProjectionMatrix)); diff --git a/examples/drawable-actor/native-renderer.cpp b/examples/drawable-actor/native-renderer.cpp index 82dbcaa..cb1a892 100644 --- a/examples/drawable-actor/native-renderer.cpp +++ b/examples/drawable-actor/native-renderer.cpp @@ -8,7 +8,6 @@ */ namespace { - constexpr GLfloat CUBE_VERTICES[] = {-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f}; constexpr GLfloat CUBE_COLOURS[] = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; @@ -56,7 +55,7 @@ float matrixDegreesToRadians(float degrees) operand1[8 + j] * operand2[4 * i + 2] + operand1[12 + j] * operand2[4 * i + 3]; } } - for(int i = 0; i < 16; i++) + for(i = 0; i < 16; i++) { destination[i] = theResult[i]; } -- 2.7.4