@@ -20,7 +20,8 @@ RenderObject::RenderObject(VkDevice& device, VkPhysicalDevice& physicalDevice,
20
20
: device(device), physicalDevice(physicalDevice), descriptorSetLayout(descriptorSetLayout),
21
21
texture(std::move(texture)), specularMap(std::move(specularMap)), model(std::move(model)),
22
22
position(0 , 0 , 0 ), scale(1 , 1 , 1 ), rotation(0 , 0 , 0 ),
23
- transformUniform(std::make_unique<UniformBuffer>(device, physicalDevice, MAX_FRAMES_IN_FLIGHT, sizeof (TransformUniform)))
23
+ transformUniform(std::make_unique<UniformBuffer>(device, physicalDevice, MAX_FRAMES_IN_FLIGHT, sizeof (TransformUniform))),
24
+ doRendering(false )
24
25
{
25
26
createDescriptorPool ();
26
27
createDescriptorSets ();
@@ -33,13 +34,23 @@ RenderObject::~RenderObject()
33
34
34
35
void RenderObject::draw (const VkCommandBuffer& commandBuffer, const VkPipelineLayout& pipelineLayout, const uint32_t currentFrame) const
35
36
{
37
+ if (!doRendering)
38
+ {
39
+ return ;
40
+ }
41
+
36
42
vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1 , 1 , &descriptorSets[currentFrame], 0 , nullptr );
37
43
38
44
model->draw (commandBuffer);
39
45
}
40
46
41
47
void RenderObject::updateUniformBuffer (const uint32_t currentFrame, const VkExtent2D& swapChainExtent, const std::shared_ptr<Camera>& camera) const
42
48
{
49
+ if (!doRendering)
50
+ {
51
+ return ;
52
+ }
53
+
43
54
auto projection = glm::perspective (glm::radians (45 .0f ),
44
55
static_cast <float >(swapChainExtent.width ) / static_cast <float >(swapChainExtent.height ),
45
56
0 .1f , 1000 .0f );
@@ -108,22 +119,32 @@ void RenderObject::createDescriptorSets()
108
119
}
109
120
}
110
121
111
- void RenderObject::setPosition (glm::vec3 position_)
122
+ void RenderObject::setPosition (const glm::vec3 position)
123
+ {
124
+ this ->position = position;
125
+ }
126
+
127
+ void RenderObject::setScale (const glm::vec3 scale)
128
+ {
129
+ this ->scale = scale;
130
+ }
131
+
132
+ void RenderObject::setScale (float scale)
112
133
{
113
- position = position_ ;
134
+ this -> scale = { scale, scale, scale } ;
114
135
}
115
136
116
- void RenderObject::setScale ( glm::vec3 scale_ )
137
+ void RenderObject::setRotation ( const glm::vec3 rotation )
117
138
{
118
- scale = scale_ ;
139
+ this -> rotation = rotation ;
119
140
}
120
141
121
- void RenderObject::setScale ( float scale_ )
142
+ void RenderObject::enableRendering ( )
122
143
{
123
- scale = { scale_, scale_, scale_ } ;
144
+ doRendering = true ;
124
145
}
125
146
126
- void RenderObject::setRotation (glm::vec3 rotation_ )
147
+ void RenderObject::disableRendering ( )
127
148
{
128
- rotation = rotation_ ;
149
+ doRendering = false ;
129
150
}
0 commit comments