MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / render_draw_queue

Function render_draw_queue

StereoKitC/systems/render.cpp:753–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

751///////////////////////////////////////////
752
753void render_draw_queue(const matrix *views, const matrix *projections, int32_t eye_offset, int32_t view_count, render_layer_ filter) {
754 skg_event_begin("Render List Setup");
755
756 // Copy camera information into the global buffer
757 for (int32_t i = 0; i < view_count; i++) {
758 XMMATRIX view_f, projection_f;
759 math_matrix_to_fast(views [i], &view_f );
760 math_matrix_to_fast(projections[i], &projection_f);
761
762 XMMATRIX view_inv = XMMatrixInverse(nullptr, view_f );
763 XMMATRIX proj_inv = XMMatrixInverse(nullptr, projection_f);
764
765 XMVECTOR cam_pos = XMVector3Transform (DirectX::g_XMIdentityR3, view_inv);
766 XMVECTOR cam_dir = XMVector3TransformNormal(DirectX::g_XMNegIdentityR2, view_inv);
767 XMStoreFloat3((XMFLOAT3*)&local.global_buffer.camera_pos[i], cam_pos);
768 XMStoreFloat3((XMFLOAT3*)&local.global_buffer.camera_dir[i], cam_dir);
769
770 local.global_buffer.view [i] = XMMatrixTranspose(view_f);
771 local.global_buffer.proj [i] = XMMatrixTranspose(projection_f);
772 local.global_buffer.proj_inv[i] = XMMatrixTranspose(proj_inv);
773 local.global_buffer.viewproj[i] = XMMatrixTranspose(view_f * projection_f);
774 }
775
776 // Copy in the other global shader variables
777 memcpy(local.global_buffer.lighting, local.lighting, sizeof(vec4) * 9);
778 local.global_buffer.time = time_totalf();
779 local.global_buffer.view_count = view_count;
780 local.global_buffer.eye_offset = eye_offset;
781 for (int32_t i = 0; i < handed_max; i++) {
782 const hand_t* hand = input_hand((handed_)i);
783 vec3 tip = hand->tracked_state & button_state_active ? hand->fingers[1][4].position : vec3{ 0,-1000,0 };
784 local.global_buffer.fingertip[i] = { tip.x, tip.y, tip.z, 0 };
785 }
786
787 // TODO: This is a little odd now that textures like this go through the
788 // render_global_textures system.
789 tex_t sky_tex = local.global_textures[render_skytex_register];
790 local.global_buffer.cubemap_i = sky_tex != nullptr
791 ? vec4{ (float)sky_tex->width, (float)sky_tex->height, floorf(log2f((float)sky_tex->width)), 0 }
792 : vec4{};
793
794 // Upload shader globals and set them active!
795 material_buffer_set_data(local.shader_globals, &local.global_buffer);
796
797 // Activate any material buffers we have
798 for (int32_t i = 0; i < _countof(material_buffers); i++) {
799 if (material_buffers[i].size != 0)
800 skg_buffer_bind(&material_buffers[i].buffer, { (uint16_t)i, skg_stage_vertex | skg_stage_pixel, skg_register_constant }, 0);
801 }
802
803 // Activate any global textures we have
804 for (int32_t i = 0; i < _countof(local.global_textures); i++) {
805 if (local.global_textures[i] != nullptr) {
806 skg_tex_t *tex = local.global_textures[i]->fallback == nullptr
807 ? &local.global_textures[i]->tex
808 : &local.global_textures[i]->fallback->tex;
809 skg_tex_bind(tex, { (uint16_t)i, skg_stage_vertex | skg_stage_pixel, skg_register_resource });
810 }

Callers 3

render_draw_matrixFunction · 0.85
render_check_screenshotsFunction · 0.85
render_check_viewpointsFunction · 0.85

Calls 9

skg_event_beginFunction · 0.85
math_matrix_to_fastFunction · 0.85
time_totalfFunction · 0.85
input_handFunction · 0.85
material_buffer_set_dataFunction · 0.85
skg_buffer_bindFunction · 0.85
skg_tex_bindFunction · 0.85
skg_event_endFunction · 0.85
render_list_executeFunction · 0.85

Tested by

no test coverage detected