MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _surface_set_data

Method _surface_set_data

servers/rendering_server.cpp:372–987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370}
371
372Error RenderingServer::_surface_set_data(Array p_arrays, uint64_t p_format, uint32_t *p_offsets, uint32_t p_vertex_stride, uint32_t p_normal_stride, uint32_t p_attrib_stride, uint32_t p_skin_stride, Vector<uint8_t> &r_vertex_array, Vector<uint8_t> &r_attrib_array, Vector<uint8_t> &r_skin_array, int p_vertex_array_len, Vector<uint8_t> &r_index_array, int p_index_array_len, AABB &r_aabb, Vector<AABB> &r_bone_aabb, Vector4 &r_uv_scale) {
373 uint8_t *vw = r_vertex_array.ptrw();
374 uint8_t *aw = r_attrib_array.ptrw();
375 uint8_t *sw = r_skin_array.ptrw();
376
377 uint8_t *iw = nullptr;
378 if (r_index_array.size()) {
379 iw = r_index_array.ptrw();
380 }
381
382 int max_bone = 0;
383
384 // Preprocess UVs if compression is enabled
385 if (p_format & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES && ((p_format & RS::ARRAY_FORMAT_TEX_UV) || (p_format & RS::ARRAY_FORMAT_TEX_UV2))) {
386 const Vector2 *uv_src = nullptr;
387 if (p_format & RS::ARRAY_FORMAT_TEX_UV) {
388 Vector<Vector2> array = p_arrays[RS::ARRAY_TEX_UV];
389 uv_src = array.ptr();
390 }
391
392 const Vector2 *uv2_src = nullptr;
393 if (p_format & RS::ARRAY_FORMAT_TEX_UV2) {
394 Vector<Vector2> array = p_arrays[RS::ARRAY_TEX_UV2];
395 uv2_src = array.ptr();
396 }
397
398 Vector2 max_val = Vector2(0.0, 0.0);
399 Vector2 min_val = Vector2(0.0, 0.0);
400 Vector2 max_val2 = Vector2(0.0, 0.0);
401 Vector2 min_val2 = Vector2(0.0, 0.0);
402
403 for (int i = 0; i < p_vertex_array_len; i++) {
404 if (p_format & RS::ARRAY_FORMAT_TEX_UV) {
405 max_val = max_val.max(uv_src[i]);
406 min_val = min_val.min(uv_src[i]);
407 }
408 if (p_format & RS::ARRAY_FORMAT_TEX_UV2) {
409 max_val2 = max_val2.max(uv2_src[i]);
410 min_val2 = min_val2.min(uv2_src[i]);
411 }
412 }
413
414 max_val = max_val.abs().max(min_val.abs());
415 max_val2 = max_val2.abs().max(min_val2.abs());
416
417 if (min_val.x >= 0.0 && min_val2.x >= 0.0 && max_val.x <= 1.0 && max_val2.x <= 1.0 &&
418 min_val.y >= 0.0 && min_val2.y >= 0.0 && max_val.y <= 1.0 && max_val2.y <= 1.0) {
419 // When all channels are in the 0-1 range, we will compress to 16-bit without scaling to
420 // preserve the bits as best as possible.
421 r_uv_scale = Vector4(0.0, 0.0, 0.0, 0.0);
422 } else {
423 r_uv_scale = Vector4(max_val.x, max_val.y, max_val2.x, max_val2.y) * Vector4(2.0, 2.0, 2.0, 2.0);
424 }
425 }
426
427 for (int ai = 0; ai < RS::ARRAY_MAX; ai++) {
428 if (!(p_format & (1ULL << ai))) { // No array
429 continue;

Callers

nothing calls this directly

Calls 15

CLAMPFunction · 0.85
_get_axis_angleFunction · 0.85
MAXFunction · 0.85
octahedron_encodeMethod · 0.80
sizeMethod · 0.65
Vector2Function · 0.50
Vector4Class · 0.50
Rect2Class · 0.50
AABBClass · 0.50
Vector3Function · 0.50

Tested by

no test coverage detected