protected override void OnUpdate()
        {
            if (!IsNativeRendererInitialized())
            {
                return;
            }

            var rendererType = bgfx.get_renderer_type();

            Entities
            .WithName("InitializeDefaultShader")
            .WithoutBurst()
            .ForEach((Entity e, ref BuiltInShader builtInShader, in ShaderBinData shaderBinData) =>
            {
                for (var i = 0; i < m_Shaders.Count; i++)
                {
                    if (m_Shaders[i].IsInitialized)
                    {
                        continue;
                    }

                    if (m_Shaders[i].Guid == builtInShader.Guid)
                    {
                        m_Shaders[i].Init(BGFXShaderHelper.GetPrecompiledShaderData(rendererType, shaderBinData, ref builtInShader.Name));
                    }
                }
            }).Run();
        }
Example #2
0
        bool EnsureInitialized()
        {
            // early-out assumption that if we initialized the shader, we're good to go
            if (m_TextShader.Initialized)
            {
                return(true);
            }

            if (!m_BGFXSystem.IsInitialized())
            {
                return(false);
            }

            m_BGFXInstance = m_BGFXSystem.InstancePointer();

            // TODO -- need a better way to find a shader given a guid
            int foundShaders = 0;

            Entities.ForEach((ref BuiltInShader builtInShader, ref ShaderBinData shaders) =>
            {
                foundShaders++;
                if (builtInShader.Guid == BitmapFontMaterial.ShaderGuid)
                {
                    m_TextShader.Init(BGFXShaderHelper.GetPrecompiledShaderData(m_BGFXInstance->m_rendererType, shaders, ref builtInShader.Name));
                }
                else if (builtInShader.Guid == SDFFontMaterial.ShaderGuid)
                {
                    m_TextSDFShader.Init(BGFXShaderHelper.GetPrecompiledShaderData(m_BGFXInstance->m_rendererType, shaders, ref builtInShader.Name));
                }
                else
                {
                    foundShaders--;
                }
            });

            // must have the shader
            if (foundShaders != 2)
            {
                throw new Exception("Couldn't find all needed Text precompiled shaders");
            }

            return(true);
        }