public MonoSpriteDrawing(GraphicsDevice graphicsDevice, KingdomShader shader)
        {
            _graphicsDevice = graphicsDevice;
            _shader         = shader;

            _defaultTexture = new Texture2D(_graphicsDevice, 2, 2);
            _defaultTexture.SetData(WhiteBitmap);

            _samplerState = new SamplerState
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter   = TextureFilter.Linear
            };

            _rasterizerState = new RasterizerState()
            {
                CullMode          = CullMode.None,
                ScissorTestEnable = false,
                DepthClipEnable   = false,
            };

            _depthStencilState = new DepthStencilState()
            {
                DepthBufferEnable = false
            };

            _vertexBuffer       = new VertexBuffer(graphicsDevice, MyVertex.VertexDeclaration, MaxSpriteCountPerDraw * 4, BufferUsage.WriteOnly);
            _indexBuffer        = CreateIndexBufferForSprites(graphicsDevice, MaxSpriteCountPerDraw);
            _vertices           = new MyVertex[MaxSpriteCountPerDraw * 4];
            _currentSpriteIndex = 0;
        }
        public static void RenderMeshNew(this GraphicsDevice graphics, KingdomShader shader,
                                         EffectPass pass, IMonoGameModel model, bool passRenderOpaque)
        {
            if (model?.MeshDescriptors == null)
            {
                return;
            }

            foreach (var meshDescriptor in model.MeshDescriptors)
            {
                if (meshDescriptor.Indices.Length == 0 || meshDescriptor.IsOpaque != passRenderOpaque)
                {
                    continue;
                }

                var textureIndex = meshDescriptor.TextureIndex & 0xffff;
                if (textureIndex < model.Textures.Length)
                {
                    shader.SetRenderTexture(pass, model.Textures[textureIndex]);
                }

                graphics.DrawUserIndexedPrimitives(
                    PrimitiveType.TriangleList,
                    meshDescriptor.Vertices,
                    0,
                    meshDescriptor.Vertices.Length,
                    meshDescriptor.Indices,
                    0,
                    meshDescriptor.Indices.Length / 3,
                    MeshLoader.PositionColoredTexturedVertexDeclaration);
            }
        }
Exemple #3
0
 public static void SetRenderTexture(this KingdomShader shader, EffectPass pass, Texture2D texture)
 {
     if (shader.Texture0 != texture)
     {
         shader.Texture0         = texture;
         shader.TextureRegionU   = KingdomShader.DefaultTextureRegion;
         shader.TextureRegionV   = KingdomShader.DefaultTextureRegion;
         shader.TextureWrapModeU = TextureWrapMode.Clamp;
         shader.TextureWrapModeV = TextureWrapMode.Clamp;
         pass.Apply();
     }
 }
Exemple #4
0
        public static void SetRenderTexture(this KingdomShader shader, EffectPass pass, IKingdomTexture texture)
        {
            if (shader.Texture0 != texture.Texture2D)
            {
                shader.Texture0 = texture.Texture2D;
                switch (texture.AddressU)
                {
                case ModelTexture.TextureWrapMode.Clamp:
                    shader.TextureRegionU   = KingdomShader.DefaultTextureRegion;
                    shader.TextureWrapModeU = TextureWrapMode.Clamp;
                    break;

                case ModelTexture.TextureWrapMode.Repeat:
                    shader.TextureRegionU   = KingdomShader.DefaultTextureRegion;
                    shader.TextureWrapModeU = TextureWrapMode.Repeat;
                    break;

                case ModelTexture.TextureWrapMode.RegionClamp:
                    shader.TextureRegionU   = texture.RegionU;
                    shader.TextureWrapModeU = TextureWrapMode.Clamp;
                    break;

                case ModelTexture.TextureWrapMode.RegionRepeat:
                    shader.TextureRegionU   = texture.RegionU;
                    shader.TextureWrapModeU = TextureWrapMode.Repeat;
                    break;
                }
                switch (texture.AddressV)
                {
                case ModelTexture.TextureWrapMode.Clamp:
                    shader.TextureRegionV   = KingdomShader.DefaultTextureRegion;
                    shader.TextureWrapModeV = TextureWrapMode.Clamp;
                    break;

                case ModelTexture.TextureWrapMode.Repeat:
                    shader.TextureRegionV   = KingdomShader.DefaultTextureRegion;
                    shader.TextureWrapModeV = TextureWrapMode.Repeat;
                    break;

                case ModelTexture.TextureWrapMode.RegionClamp:
                    shader.TextureRegionV   = texture.RegionV;
                    shader.TextureWrapModeV = TextureWrapMode.Clamp;
                    break;

                case ModelTexture.TextureWrapMode.RegionRepeat:
                    shader.TextureRegionV   = texture.RegionV;
                    shader.TextureWrapModeV = TextureWrapMode.Repeat;
                    break;
                }

                pass.Apply();
            }
        }