예제 #1
0
        private void ReloadEffect()
        {
            // FIXME: We shouldn't be casting IAssetContentManager like this!
            var assetContentManager = _assetContentManager as AssetContentManager;

            if (assetContentManager == null)
            {
                throw new NoAssetContentManagerException();
            }

            var serviceProvider        = assetContentManager.ServiceProvider;
            var graphicsDeviceProvider =
                (IGraphicsDeviceService)serviceProvider.GetService(typeof(IGraphicsDeviceService));

            if (graphicsDeviceProvider != null && graphicsDeviceProvider.GraphicsDevice != null)
            {
                var graphicsDevice = graphicsDeviceProvider.GraphicsDevice;

                var compiledUnifiedShaderReader = new CompiledUnifiedShaderReader(this.PlatformData.Data);

                // Use the new EffectWithSemantics class that allows for extensible semantics.
                var availableSemantics = _kernel.GetAll <IEffectSemantic>();
                this.Effect = new ProtogameEffect(graphicsDevice, compiledUnifiedShaderReader, Name, availableSemantics);
            }
        }
예제 #2
0
        private void ReloadEffect()
        {
            // FIXME: We shouldn't be casting IAssetContentManager like this!
            var assetContentManager = _assetContentManager as AssetContentManager;

            if (assetContentManager == null)
            {
                throw new NoAssetContentManagerException();
            }

            var serviceProvider        = assetContentManager.ServiceProvider;
            var graphicsDeviceProvider =
                (IGraphicsDeviceService)serviceProvider.GetService(typeof(IGraphicsDeviceService));

            if (graphicsDeviceProvider != null && graphicsDeviceProvider.GraphicsDevice != null)
            {
                var graphicsDevice = graphicsDeviceProvider.GraphicsDevice;

                var compiledUnifiedShaderReader = new CompiledUnifiedShaderReader(this.PlatformData.Data);

                // Load the effect for the first time.
                var effect = new Effect(graphicsDevice, compiledUnifiedShaderReader);

                // Determine what kind of effect class we should use.
                var hasSeperatedMatrixes = effect.Parameters["World"] != null && effect.Parameters["View"] != null && effect.Parameters["Projection"] != null;
                var hasMatrix            = effect.Parameters["WorldViewProj"] != null || hasSeperatedMatrixes;
                var hasTexture           = effect.Parameters["Texture"] != null;
                var hasBones             = effect.Parameters["Bones"] != null;
                if (hasMatrix && hasTexture && hasBones)
                {
                    this.Effect = new EffectWithMatricesAndTextureAndBones(graphicsDevice, this.PlatformData.Data, hasSeperatedMatrixes);
                }
                else if (hasMatrix && hasTexture)
                {
                    this.Effect = new EffectWithMatricesAndTexture(graphicsDevice, this.PlatformData.Data, hasSeperatedMatrixes);
                }
                else if (hasMatrix)
                {
                    this.Effect = new EffectWithMatrices(graphicsDevice, this.PlatformData.Data, hasSeperatedMatrixes);
                }
                else if (hasTexture)
                {
                    this.Effect = new EffectWithTexture(graphicsDevice, this.PlatformData.Data);
                }
                else
                {
                    this.Effect = effect;
                }

                // Assign the asset name so we can trace it back.
                this.Effect.Name = this.Name;
            }
        }