예제 #1
0
        private void Init(Type[] types)
        {
            this.types = types;

            usageIndices = new byte[types.Length];
            int index = 0;

            VertexElement[] vertexElements = new VertexElement[types.Length];
            semantics = new Semantic[types.Length];

            SortedList usages = new SortedList( );

            foreach (Type type in types)
            {
                VertexElement element = StreamFactory.Instance.VertexElement(type);
                element.Stream = (short)index;
                element.Offset = 0;
                if (!usages.Contains(element.DeclarationUsage))
                {
                    usages[element.DeclarationUsage] = (byte)0;
                }
                element.UsageIndex = usageIndices[index] = (byte)usages[element.DeclarationUsage];
                usages[element.DeclarationUsage] = (byte)((byte)usages[element.DeclarationUsage] + 1);
                vertexElements[index]            = element;
                semantics[index] = new Semantic(element.DeclarationUsage, element.UsageIndex);
                index++;
            }
            vertexDeclaration = Device.Instance.CreateVertexDeclaration(vertexElements);
        }
예제 #2
0
파일: Sprite.cs 프로젝트: Daramkun/Misty
        public Sprite( ITexture2D texture, IEffect effect )
        {
            if ( effect == null )
            {
                if ( baseSpriteEffect == null )
                    baseSpriteEffect = new SpriteEffect ();
                effect = baseSpriteEffect;
            }

            if ( projectionMatrix == null )
                projectionMatrix = new OrthographicOffCenterProjection ( 0, 800, 600, 0, 0.001f, 1000.0f );

            Effect = effect;

            if ( vertexDeclaration == null )
            {
                vertexDeclaration = Core.GraphicsDevice.CreateVertexDeclaration ( Utilities.CreateVertexElementArray<SpriteVertex> () );
            }
            indexReference++;

            vertexBuffer = Core.GraphicsDevice.CreateBuffer ( BufferType.VertexBuffer, typeof ( SpriteVertex ), 4 );

            textureArgument = new SamplerState ( texture, Graphics.TextureFilter.Nearest, TextureAddressing.Clamp, 0 );
            Reset ( texture );

            innerWorld = new World2();
        }
예제 #3
0
        private void EndVertexDeclaration( IVertexDeclaration decl )
        {
            for ( int i = 0; i < decl.Length; ++i )
                GL.DisableVertexAttribArray ( i );

            GL.BindBuffer ( BufferTarget.ArrayBuffer, 0 );
        }
예제 #4
0
 public InputAssembler( IBuffer vertexBuffer, IVertexDeclaration vertexDeclaration, PrimitiveType primitiveType = PrimitiveType.TriangleList, IBuffer indexBuffer = null )
     : this()
 {
     PrimitiveType = primitiveType;
     VertexBuffer = vertexBuffer;
     VertexDeclaration = vertexDeclaration;
     IndexBuffer = indexBuffer;
 }
예제 #5
0
 public void SetUp(IShaderProgram shaderProgram, IVertexDeclaration vertexDeclaration)
 {
     this.ThrowIfDisposed();
     if (shaderProgram == null)
     {
         throw new ArgumentNullException(nameof(shaderProgram));
     }
     if (vertexDeclaration == null)
     {
         throw new ArgumentNullException(nameof(vertexDeclaration));
     }
     vertexDeclaration.Apply(adapter, shaderProgram);
 }
예제 #6
0
        private void BeginVertexDeclaration( IBuffer buffer, IVertexDeclaration decl )
        {
            GL.BindBuffer ( BufferTarget.ArrayBuffer, ( int ) buffer.Handle );

            int i = 0, offset = 0;
            foreach ( VertexElement element in decl )
            {
                int size = ElementSizeToRealSize ( element.Size );
                GL.EnableVertexAttribArray ( i );
                GL.VertexAttribPointer ( i, size / 4, ElementSizeToRealType ( element.Size ),
                    false, buffer.RecordTypeSize, offset );
                ++i;
                offset += size;
            }
        }
예제 #7
0
파일: Container.cs 프로젝트: Daramkun/Misty
        public override void Intro( params object [] args )
        {
            Core.Window.Title = "Cube";

            contentManager = new ResourceTable ( FileSystemManager.GetFileSystem ( "ManifestFileSystem" ) );
            cubeEffect = contentManager.Load<IEffect> ( "Resources/Cube/CubeShader.xml", "i_pos", "i_col" );

            cubeVertices = Core.GraphicsDevice.CreateBuffer<CubeVertex>( BufferType.VertexBuffer, new CubeVertex []
            {
                new CubeVertex () { Position = new Vector3 ( -1, -1, -1 ), Diffuse = Color.Red },
                new CubeVertex () { Position = new Vector3 ( +1, -1, -1 ), Diffuse = Color.Blue },
                new CubeVertex () { Position = new Vector3 ( -1, -1, +1 ), Diffuse = Color.Green },
                new CubeVertex () { Position = new Vector3 ( +1, -1, +1 ), Diffuse = Color.White },

                new CubeVertex () { Position = new Vector3 ( -1, +1, -1 ), Diffuse = Color.Magenta },
                new CubeVertex () { Position = new Vector3 ( -1, +1, +1 ), Diffuse = Color.Cyan },
                new CubeVertex () { Position = new Vector3 ( +1, +1, -1 ), Diffuse = Color.Yellow },
                new CubeVertex () { Position = new Vector3 ( +1, +1, +1 ), Diffuse = Color.White },
            } );
            cubeIndices = Core.GraphicsDevice.CreateBuffer<CubeIndex> ( BufferType.IndexBuffer, new CubeIndex []
            {
                // TOP
                new CubeIndex () { I0 = 0, I1 = 1, I2 = 2 },
                new CubeIndex () { I0 = 1, I1 = 3, I2 = 2 },
                // LEFT
                new CubeIndex () { I0 = 0, I1 = 2, I2 = 4 },
                new CubeIndex () { I0 = 2, I1 = 5, I2 = 4 },
                // FRONT
                new CubeIndex () { I0 = 2, I1 = 3, I2 = 5 },
                new CubeIndex () { I0 = 3, I1 = 7, I2 = 5 },
                // RIGHT
                new CubeIndex () { I0 = 3, I1 = 1, I2 = 7 },
                new CubeIndex () { I0 = 1, I1 = 6, I2 = 7 },
                // BACK
                new CubeIndex () { I0 = 1, I1 = 0, I2 = 6 },
                new CubeIndex () { I0 = 6, I1 = 0, I2 = 4 },
                // BOTTOM
                new CubeIndex () { I0 = 5, I1 = 6, I2 = 4 },
                new CubeIndex () { I0 = 5, I1 = 7, I2 = 6 },
            } );
            vertexDeclarataion = Core.GraphicsDevice.CreateVertexDeclaration ( Utilities.CreateVertexElementArray<CubeVertex> () );

            proj = new PerspectiveFieldOfViewProjection ();
            lookAt = new LookAt ( new Vector3 ( 5, 5, 5 ), new Vector3 ( 0, 0, 0 ), new Vector3 ( 0, 1, 0 ) );
            world = World3.Identity;

            base.Intro ( args );
        }
예제 #8
0
파일: Container.cs 프로젝트: Daramkun/Misty
        public override void Intro( params object [] args )
        {
            Core.GraphicsDevice.ImmediateContext.CullMode = CullMode.ClockWise;

            contentManager = new ResourceTable ( FileSystemManager.GetFileSystem ( "ManifestFileSystem" ) );
            contentManager.AddDefaultContentLoader ();

            texture1 = contentManager.Load<ITexture2D> ( "Resources/Terrain/terrain_02.png" );
            texture2 = contentManager.Load<ITexture2D> ( "Resources/Terrain/terrain_01.png" );
            Color [] colours = texture2.Buffer;
            effect = contentManager.Load<IEffect> ( "Resources/Terrain/TerrainShader.xml" );

            textureArgs = new SamplerState ( texture1, TextureFilter.Anisotropic, TextureAddressing.Clamp,
                Core.GraphicsDevice.Information.MaximumAnisotropicLevel );

            vertexBuffer = Core.GraphicsDevice.CreateBuffer ( BufferType.VertexBuffer, typeof ( TerrainVertex ), texture2.Width * texture2.Height );
            vertexDeclaration = Core.GraphicsDevice.CreateVertexDeclaration ( Utilities.CreateVertexElementArray<TerrainVertex> () );
            numOfIndices = ( texture2.Width - 1 ) * ( texture2.Height - 1 ) * 2;
            indexBuffer = Core.GraphicsDevice.CreateBuffer ( BufferType.IndexBuffer, typeof ( TerrainIndex ), numOfIndices );

            TerrainVertex [] vertices = new TerrainVertex [ texture2.Width * texture2.Height ];
            int index = 0;
            for ( int x = 0; x < texture2.Height; x++ )
            {
                for ( int z = 0; z < texture2.Width; z++ )
                {
                    int location = x * texture2.Width + z;
                    vertices [ index ] = new TerrainVertex ()
                    {
                        Position = new Vector3 (
                            ( x - texture2.Height / 2 ) * 5.0f,
                            colours [ location ].RedValue * 5.0f / 3,
                            ( z - texture2.Width / 2 ) * 5.0f
                        ),
                        UV = new Vector2 (
                            z / ( float ) texture2.Width,
                            x / ( float ) texture2.Height
                        )
                    };
                    ++index;
                }
            }
            vertexBuffer.SetBufferDatas<TerrainVertex> ( vertices );

            TerrainIndex [] indices = new TerrainIndex [ numOfIndices ];
            index = 0;
            for ( int z = 0; z < texture2.Height - 1; z++ )
            {
                for ( int x = 0; x < texture2.Width - 1; x++ )
                {
                    indices [ index ]._0 = z * texture2.Width + x;
                    indices [ index ]._1 = z * texture2.Width + ( x + 1 );
                    indices [ index ]._2 = ( z + 1 ) * texture2.Width + x;
                    ++index;
                    indices [ index ]._0 = ( z + 1 ) * texture2.Width + x;
                    indices [ index ]._1 = z * texture2.Width + ( x + 1 );
                    indices [ index ]._2 = ( z + 1 ) * texture2.Width + ( x + 1 );
                    ++index;
                }
            }
            indexBuffer.SetBufferDatas<TerrainIndex> ( indices );

            proj = new PerspectiveFieldOfViewProjection ( 3.141592f / 4, 4 / 3f, 1, 10000 );
            look = new LookAt ( new Vector3 ( 1000, 2000, 1000 ), new Vector3 ( 0, 0, 0 ), new Vector3 ( 0, 1, 0 ) );
            world = new World3 ();

            sprite = new Sprite ( null );
            spriteWorld = new World2 ();

            Add ( new FpsCalculator () );

            base.Intro ( args );
        }
예제 #9
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="declaration">declaration</param>
 /// <param name="streamIndex">index of current stream in format</param>
 public Key(IVertexDeclaration declaration, int streamIndex)
 {
     this.declaration = declaration;
     this.streamIndex = streamIndex;
 }
예제 #10
0
파일: Sprite.cs 프로젝트: Daramkun/Misty
        public void Dispose()
        {
            if ( vertexBuffer != null )
            {
                if ( --indexReference == 0 )
                {
                    vertexDeclaration.Dispose ();
                    vertexDeclaration = null;

                    if ( baseSpriteEffect != null )
                    {
                        baseSpriteEffect.Dispose ();
                        baseSpriteEffect = null;
                    }
                }

                vertexBuffer.Dispose ();
                vertexBuffer = null;
            }
        }