You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VXR Release 0.1.1. Bugfixes. Removed some misleading error messages. Added documentation to examples. Cleaned up some code. Added Math Utility class. Added more colors to Colors class. Started development on biomes for Planet Editor. Removed Release configuration from genie.lua. Removed some warnings.
// 4. Initialize shader data. The engine uses UBO for the objects, so the correct syntax to use custom uniforms can be found below.
91
94
gpu::Material::Info mat_info;
92
95
mat_info.shader.vert = GLSL(
93
96
in vec3 a_position;
@@ -121,34 +124,41 @@ namespace vxr
121
124
}
122
125
);
123
126
127
+
// 5. Initialize vertex attributes. This time, we'll pass three different buffers. One with positions normals and uvs data, another with the instance positions and a last one with instance colors.
// 11. Create a render command display list to fill the index and vertex buffers with the appropriate data once.
152
162
DisplayList frame;
153
163
frame.fillBufferCommand()
154
164
.set_buffer(vertex_buffer_)
@@ -158,14 +168,17 @@ namespace vxr
158
168
.set_buffer(index_buffer_)
159
169
.set_data(index_data)
160
170
.set_size(sizeof(index_data));
171
+
// 12. Fill the instance colors buffer (we will be filling the positions in the update, as the buffer requires a dynamic update).
161
172
frame.fillBufferCommand()
162
173
.set_buffer(instance_colors_buffer_)
163
174
.set_data(instance_colors_)
164
175
.set_size(sizeof(instance_colors_));
176
+
// 13. Fill the uniform data once.
165
177
frame.fillBufferCommand()
166
178
.set_buffer(uniform_buffer_)
167
179
.set_data(&u_state_static_)
168
180
.set_size(sizeof(UniformState_Static));
181
+
// 14. Upload texture data to the GPU.
169
182
frame.fillTextureCommand()
170
183
.set_texture(texture_)
171
184
.set_data(tex_data_);
@@ -174,6 +187,7 @@ namespace vxr
174
187
175
188
voidMain::update()
176
189
{
190
+
// 15. Update instances position. This operations are performed in the update() instead of the renderUpdate() for them to take into account deltaTime() and be framerate independent.
177
191
staticfloat v = 0;
178
192
for (int i = 0; i < kNUM_INSTANCES; ++i)
179
193
{
@@ -191,27 +205,23 @@ namespace vxr
191
205
192
206
voidMain::renderUpdate()
193
207
{
194
-
sprintf(window_title_,
195
-
"%s: %d FPS @ 1280 x 720, Number of instances: %d",
196
-
"VXR Instancing Test",
197
-
fps(), kNUM_INSTANCES);
198
-
199
-
Engine::ref().window()->set_title(window_title_);
200
-
201
208
DisplayList frame;
202
209
frame.clearCommand()
203
210
.set_color({ 0.1f, 0.1f, 0.1f, 1.0f });
211
+
// 16. Re-upload instance position data to the GPU once each frame.
204
212
frame.fillBufferCommand()
205
213
.set_buffer(instance_positions_buffer_)
206
214
.set_data(instance_positions_)
207
215
.set_size(sizeof(instance_positions_));
216
+
// 17. Setup material for rendering. This time, all the buffers and textures need to be set as parameters.
208
217
frame.setupMaterialCommand()
209
218
.set_material(material_)
210
219
.set_buffer(0, vertex_buffer_)
211
220
.set_buffer(1, instance_positions_buffer_)
212
221
.set_buffer(2, instance_colors_buffer_)
213
222
.set_uniform_buffer(0, uniform_buffer_)
214
223
.set_texture(0, texture_);
224
+
// 18. Add render command with the number of instances to be rendered.
215
225
frame.renderCommand()
216
226
.set_index_buffer(index_buffer_)
217
227
.set_count(sizeof(index_data) / sizeof(uint16))
@@ -224,6 +234,7 @@ namespace vxr
224
234
225
235
voidMain::stop()
226
236
{
237
+
// 19. Free the texture data at the end of the application.
0 commit comments