| 133 | } |
| 134 | |
| 135 | HRenderContext NewRenderContext(dmGraphics::HContext graphics_context, const RenderContextParams& params) |
| 136 | { |
| 137 | RenderContext* context = new RenderContext; |
| 138 | |
| 139 | context->m_RenderObjects.SetCapacity(params.m_MaxInstances); |
| 140 | context->m_RenderObjects.SetSize(0); |
| 141 | |
| 142 | context->m_GraphicsContext = graphics_context; |
| 143 | |
| 144 | context->m_SystemFontMap = params.m_SystemFontMap; |
| 145 | |
| 146 | context->m_Material = 0; |
| 147 | context->m_CurrentRenderCamera = 0; |
| 148 | |
| 149 | UpdateRenderContextMatrices(context, Matrix4::identity(), Matrix4::identity()); |
| 150 | context->m_Time = 0.0f; |
| 151 | context->m_Dt = 0.0f; |
| 152 | |
| 153 | context->m_ScriptContext = params.m_ScriptContext; |
| 154 | InitializeRenderScriptContext(context->m_RenderScriptContext, graphics_context, params.m_ScriptContext, params.m_CommandBufferSize); |
| 155 | InitializeRenderScriptCameraContext(context, params.m_ScriptContext); |
| 156 | context->m_ScriptWorld = dmScript::NewScriptWorld(context->m_ScriptContext); |
| 157 | context->m_CallbackInfo = 0x0; |
| 158 | |
| 159 | context->m_DebugRenderer.m_RenderContext = 0; |
| 160 | if (params.m_ShaderProgramDesc != 0 && params.m_ShaderProgramDescSize != 0) { |
| 161 | InitializeDebugRenderer(context, params.m_MaxDebugVertexCount, params.m_ShaderProgramDesc, params.m_ShaderProgramDescSize); |
| 162 | } |
| 163 | |
| 164 | InitializeTextContext(context, params.m_MaxCharacters, params.m_MaxBatches); |
| 165 | |
| 166 | context->m_OutOfResources = 0; |
| 167 | |
| 168 | context->m_StencilBufferCleared = 0; |
| 169 | |
| 170 | context->m_MultiBufferingRequired = 0; |
| 171 | |
| 172 | context->m_IsRenderPaused = 0; |
| 173 | |
| 174 | // TODO: This should be a "context property" or something similar. |
| 175 | dmGraphics::AdapterFamily installed_adapter_family = dmGraphics::GetInstalledAdapterFamily(); |
| 176 | if (installed_adapter_family == dmGraphics::ADAPTER_FAMILY_VULKAN || |
| 177 | installed_adapter_family == dmGraphics::ADAPTER_FAMILY_WEBGPU || |
| 178 | installed_adapter_family == dmGraphics::ADAPTER_FAMILY_DIRECTX || |
| 179 | installed_adapter_family == dmGraphics::ADAPTER_FAMILY_VENDOR) |
| 180 | { |
| 181 | context->m_MultiBufferingRequired = 1; |
| 182 | } |
| 183 | |
| 184 | context->m_UseAdjustedNDC = installed_adapter_family == dmGraphics::ADAPTER_FAMILY_VULKAN || |
| 185 | installed_adapter_family == dmGraphics::ADAPTER_FAMILY_WEBGPU || |
| 186 | installed_adapter_family == dmGraphics::ADAPTER_FAMILY_DIRECTX || |
| 187 | installed_adapter_family == dmGraphics::ADAPTER_FAMILY_VENDOR; |
| 188 | |
| 189 | context->m_RenderListDispatch.SetCapacity(255); |
| 190 | |
| 191 | SetupContextEventCallback(context, &OnContextEvent); |
| 192 | |