コード例 #1
0
        internal BasicLightRenderer(GraphicsDevice device)
        {
            // Piirretään valot omaan tekstuuriin, joka sitten piirretään muiden elementtien päälle.
            RenderTarget = device.CreateRenderTarget((uint)Game.Instance.Window.Size.X, (uint)Game.Instance.Window.Size.Y);

            Game.Instance.Window.Resize += (v) => ResizeRenderTarget();

            int maxAmountOfLights = 1000; // TODO: Mikä olisi hyvä rajoitus?

            lightData    = new LightData[maxAmountOfLights];
            gl           = ((GraphicsDevice)device).Gl;
            vertexbuffer = new BufferObject <VertexPositionColorTexture>(gl, Graphics.TextureVertices, Silk.NET.OpenGL.BufferTargetARB.ArrayBuffer);
            Vao          = new VertexArrayObject <VertexPositionColorTexture, Vector4>(gl, vertexbuffer, null);

            // TODO: Tämä on hieman ruma ja kaipaisi jonkinlaista abstraktiota.
            Vao.VertexAttributePointer(0, 3, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(VertexPositionColorTexture), 0);
            Vao.VertexAttributePointer(1, 4, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(VertexPositionColorTexture), 12);
            Vao.VertexAttributePointer(2, 2, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(VertexPositionColorTexture), 28);

            databuffer = new BufferObject <LightData>(gl, lightData, Silk.NET.OpenGL.BufferTargetARB.ArrayBuffer);
            databuffer.VertexAttributePointer(3, 2, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(LightData), 0);
            databuffer.VertexAttributePointer(4, 1, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(LightData), 8);
            databuffer.VertexAttributePointer(5, 1, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(LightData), 12);
            databuffer.VertexAttributePointer(6, 4, Silk.NET.OpenGL.VertexAttribPointerType.Float, (uint)sizeof(LightData), 16);

            gl.BindBuffer(Silk.NET.OpenGL.BufferTargetARB.ArrayBuffer, 0);
        }
コード例 #2
0
        public VertexArrayObject(GL gl, BufferObject <TVertexType> vbo, BufferObject <TIndexType> ebo)
        {
            //Saving the GL instance.
            _gl = gl;

            //Setting out handle and binding the VBO and EBO to this VAO.
            _handle = _gl.GenVertexArray();
            Bind();
            vbo.Bind();
            ebo?.Bind();
        }