Ejemplo n.º 1
0
        internal BatchBuffer(Renderer.RenderSystem renderSystem, Renderer.VertexFormat vertexFormat = null, int initialTriangleCount = 128)
        {
            if (renderSystem == null)
                throw new ArgumentNullException("renderSystem");
            if (initialTriangleCount <= 0)
                throw new ArgumentException("invalid initialTriangleCount");

            RenderSystem = renderSystem;

            var dataCount = initialTriangleCount * (3 + 3 + 3 + 2); // vec3 pos, vec3 normal, vec3 tangent, vec2 texcoord
            VertexData = new float[dataCount];
            IndexData = new int[initialTriangleCount];

            if (vertexFormat != null)
            {
                VertexFormat = vertexFormat;
            }
            else
            {
                VertexFormat = new Renderer.VertexFormat(new Renderer.VertexFormatElement[]
                {
                    new Renderer.VertexFormatElement(Renderer.VertexFormatSemantic.Position, Renderer.VertexPointerType.Float, 3, 0),
                    new Renderer.VertexFormatElement(Renderer.VertexFormatSemantic.TexCoord, Renderer.VertexPointerType.Float, 2, sizeof(float) * 3),
                });
            }

            VertexBufferHandle = RenderSystem.CreateBuffer(Renderer.BufferTarget.ArrayBuffer, VertexFormat);
            IndexBufferHandle = RenderSystem.CreateBuffer(Renderer.BufferTarget.ElementArrayBuffer);

            RenderSystem.SetBufferData(VertexBufferHandle, new byte[0], true, true);
            RenderSystem.SetBufferData(IndexBufferHandle, new byte[0], true, true);

            MeshHandle = RenderSystem.CreateMesh(0, VertexBufferHandle, IndexBufferHandle, true);
        }
Ejemplo n.º 2
0
        public Backend(ResourceManager resourceManager, int width, int height, OpenTK.Platform.IWindowInfo windowInfo)
        {
            if (resourceManager == null)
                throw new ArgumentNullException("resourceManager");

            Width = width;
            Height = height;

            ResourceManager = resourceManager;

            // Setup the render system
            RenderSystem = new Renderer.RenderSystem(windowInfo, ProcessQueue.Enqueue);
            Watch = new System.Diagnostics.Stopwatch();

            DefaultSampler = RenderSystem.CreateSampler(new Dictionary<SamplerParameterName, int>
            {
                { SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear },
                { SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear },
                { SamplerParameterName.TextureMaxAnisotropyExt, 8 },
                { SamplerParameterName.TextureWrapS, (int)TextureWrapMode.Repeat },
                { SamplerParameterName.TextureWrapT, (int)TextureWrapMode.Repeat },
                { SamplerParameterName.TextureWrapR, (int)TextureWrapMode.Repeat }
            });

            DefaultSamplerNoFiltering = RenderSystem.CreateSampler(new Dictionary<SamplerParameterName, int>
            {
                { SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest },
                { SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest },
                { SamplerParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge },
                { SamplerParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge }
            });

            DefaultSamplerMipMapNearest = RenderSystem.CreateSampler(new Dictionary<SamplerParameterName, int>
            {
                { SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapNearest },
                { SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest },
                { SamplerParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge },
                { SamplerParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge }
            });

            ElapsedTime = 0;
        }