MCPcopy Create free account
hub / github.com/defold/defold / SetTextureBindingByHash

Function SetTextureBindingByHash

engine/render/src/render/render.cpp:810–859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808 }
809
810 void SetTextureBindingByHash(dmRender::HRenderContext render_context, dmhash_t sampler_hash, dmGraphics::HTexture texture)
811 {
812 uint32_t num_bindings = render_context->m_TextureBindTable.Size();
813 int32_t first_free_index = -1;
814
815 // First pass
816 // Check if the the sampler is already bound to this texture, if so we reuse or unbind the current binding
817 for (int i = 0; i < num_bindings; ++i)
818 {
819 if (render_context->m_TextureBindTable[i].m_Samplerhash == sampler_hash)
820 {
821 if (texture == 0)
822 {
823 render_context->m_TextureBindTable[i].m_Samplerhash = 0;
824 }
825 render_context->m_TextureBindTable[i].m_Texture = texture;
826 return;
827 }
828 // Store the free index for later
829 else if (render_context->m_TextureBindTable[i].m_Texture == 0 && first_free_index == -1)
830 {
831 first_free_index = i;
832 }
833 }
834
835 // If we are unassigning the sampler, but it wasn't found we can exit here.
836 if (texture == 0)
837 {
838 return;
839 }
840
841 // Take the first free index we found
842 if (first_free_index != -1)
843 {
844 render_context->m_TextureBindTable[first_free_index].m_Texture = texture;
845 render_context->m_TextureBindTable[first_free_index].m_Samplerhash = sampler_hash;
846 return;
847 }
848
849 // Otherwise, we add a new binding to the end of the list
850 if (render_context->m_TextureBindTable.Full())
851 {
852 render_context->m_TextureBindTable.OffsetCapacity(4);
853 }
854
855 TextureBinding new_binding;
856 new_binding.m_Samplerhash = sampler_hash;
857 new_binding.m_Texture = texture;
858 render_context->m_TextureBindTable.Push(new_binding);
859 }
860
861 void SetTextureBindingByUnit(HRenderContext render_context, uint32_t unit, dmGraphics::HTexture texture)
862 {

Callers 2

TEST_FFunction · 0.85
ParseCommandsFunction · 0.85

Calls 4

SizeMethod · 0.45
FullMethod · 0.45
OffsetCapacityMethod · 0.45
PushMethod · 0.45

Tested by 1

TEST_FFunction · 0.68