Beispiel #1
0
        public void SetVertices(Vector3f[] verts)
        {
            if (fVertexBufferObject != null)
            {
                fVertexBufferObject.Dispose();
                fVertexBufferObject = null;
            }


            // Write the vertex data to the buffer
            GCHandle dataPtr = GCHandle.Alloc(verts, GCHandleType.Pinned);
            int dataSize = Marshal.SizeOf(typeof(Vector3f)) * verts.Length;
            fVertexBufferObject = new VertexBufferObject(GI);
            fVertexBufferObject.Bind();
            fVertexBufferObject.Size = dataSize;
            
            try
            {
                fVertexBufferObject.Bind();
                fVertexBufferObject.Write(dataPtr.AddrOfPinnedObject(), 0, dataSize);
            }
            finally
            {
                fVertexBufferObject.Unbind();
                dataPtr.Free();
            }
       }
 public RenderableMesh(VertexBufferObject<Vertex3V3N> vertexBuffer, VertexBufferObject<uint> elementBuffer, VertexArrayObject vertexArrayObject, int length, ResourceAllocator resourceAllocator)
 {
     _resourceAllocator = resourceAllocator;
     Faces = length;
     _vertexArrayObject = vertexArrayObject;
     _elementBuffer = elementBuffer;
     _vertexBuffer = vertexBuffer;
 }
Beispiel #3
0
        private static void AddToVbo()
        {
            var vbo = _vao.VerticesVbo;

            vbo.Bind(BufferTarget.ArrayBuffer);
            vbo.SetData(BufferTarget.ArrayBuffer, GenerateFloatArray(), BufferUsageHint.StreamDraw);
            VertexBufferObject.Unbind(BufferTarget.ArrayBuffer);
        }
 public RenderableMesh(VertexBufferObject <Vertex3V3N> vertexBuffer, VertexBufferObject <uint> elementBuffer, VertexArrayObject vertexArrayObject, int length, ResourceAllocator resourceAllocator)
 {
     _resourceAllocator = resourceAllocator;
     Faces = length;
     _vertexArrayObject = vertexArrayObject;
     _elementBuffer     = elementBuffer;
     _vertexBuffer      = vertexBuffer;
 }
Beispiel #5
0
 public CrossBlockRender(ChunkRegion chunkRegion)
 {
     _chunkRegion = chunkRegion;
     _vao         = null;
     _dataBuffer  = null;
     _mapper      = new ArrayBlockVboMapper(chunkRegion, null, null, InstanceDataLength, MaxBlocks);
     _generated   = false;
 }
Beispiel #6
0
            public void CreateAttribute(int attribute, float[] data, int attrSize)
            {
                VertexBufferObject dataVbo = VertexBufferObject.Create(BufferTarget.ArrayBuffer);

                dataVbo.Bind();
                dataVbo.StoreData(data);
                GL.VertexAttribPointer(attribute, attrSize, VertexAttribPointerType.Float, false, attrSize * BYTES_PER_FLOAT, 0);
                dataVbo.Unbind();
                _dataVbos.Add(dataVbo);
            }
Beispiel #7
0
            public void CreateIntAttribute(int attribute, int[] data, int attrSize)
            {
                VertexBufferObject dataVbo = VertexBufferObject.Create(BufferTarget.ArrayBuffer);

                dataVbo.Bind();
                dataVbo.StoreData(data);
                GL.VertexAttribIPointer(attribute, attrSize, VertexAttribIntegerType.Int, attrSize * BYTES_PER_INT, System.IntPtr.Zero);

                dataVbo.Unbind();
                _dataVbos.Add(dataVbo);
            }
Beispiel #8
0
        /// <summary>
        /// Creates a VAO and VBO object from an array of vertices, the shader, an array of attributes
        /// </summary>
        /// <param name="vertices"> the vertex array</param>
        /// <param name="shaderIndex">index of the shader being used for that object</param>
        /// <param name="vbo">vbo object for output</param>
        /// <param name="vao">vao object for output</param>
        /// <param name="attributes">attribute or attributes(in an array if more than one)</param>
        public void CreateBufferObjects(Vertex[] vertices, string shaderName, out VertexBufferObject <Vertex> vbo, out VertexArrayObject <Vertex> vao,
                                        params BufferObjects.VertexAttribute[] attributes)
        {
            VertexArrayObject <Vertex>  thevao = new VertexArrayObject <Vertex>();
            VertexBufferObject <Vertex> thevbo = new VertexBufferObject <Vertex>(Vertex.Size, vertices);

            thevbo.CreateBuffer();
            thevao.SetAttributes(thevbo, shaderMgr.GetShader(shaderName), attributes);
            vbo = thevbo;
            vao = thevao;
        }
Beispiel #9
0
        public static void Init()
        {
            if (Length == 0)
            {
                int buffer = GL.GenBuffer();
                vao = new VertexBufferObject(buffer);
                vao.AddAttribute(0, 2, VertexAttribPointerType.Float, false, 8, 0);
                vao.Initialize();

                Length = 1;
            }
        }
Beispiel #10
0
        public static void Initialize(GLContext control)
        {
            if (DefaultShaderProgram != null)
            {
                return;
            }

            if (DefaultShaderProgram == null)
            {
                string frag = System.IO.File.ReadAllText("Shaders/FinalHDR.frag");
                string vert = System.IO.File.ReadAllText("Shaders/FinalHDR.vert");

                DefaultShaderProgram = new ShaderProgram(
                    new FragmentShader(frag),
                    new VertexShader(vert));

                int buffer = GL.GenBuffer();
                vao = new VertexBufferObject(buffer);
                vao.AddAttribute(0, 2, VertexAttribPointerType.Float, false, 16, 0);
                vao.AddAttribute(1, 2, VertexAttribPointerType.Float, false, 16, 8);
                vao.Initialize();

                Vector2[] positions = new Vector2[4]
                {
                    new Vector2(-1.0f, 1.0f),
                    new Vector2(-1.0f, -1.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, -1.0f),
                };

                Vector2[] texCoords = new Vector2[4]
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.0f, 0.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, 0.0f),
                };

                List <float> list = new List <float>();
                for (int i = 0; i < 4; i++)
                {
                    list.Add(positions[i].X);
                    list.Add(positions[i].Y);
                    list.Add(texCoords[i].X);
                    list.Add(texCoords[i].Y);
                }

                Length = 4;

                float[] data = list.ToArray();
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);
            }
        }
Beispiel #11
0
 private void InitializeBuffer <T>(VertexBufferObject <T> buffer, bool setPointer)
     where T : struct
 {
     buffer.Create();
     using (buffer.Use())
     {
         buffer.Upload();
         if (setPointer)
         {
             buffer.SetPointer();
         }
     }
 }
        private void CheckBuffers(GLContext control)
        {
            bool buffersWereInitialized = vbo_position != 0;

            if (!buffersWereInitialized)
            {
                GL.GenBuffers(1, out vbo_position);

                vbo = new VertexBufferObject(vbo_position);
                vbo.AddAttribute("point", 4, VertexAttribPointerType.Float, false, 16, 0);
                vbo.Initialize();

                UpdateVertexData(control);
            }
        }
Beispiel #13
0
        public void RenderObject(VertexBufferObject <Vertex> item, VertexArrayObject <Vertex> vao, int shaderIndex)
        {
            if (settingschanged)
            {
                ApplySettingsNow();
            }
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            shaderMgr.InitialiseAShader(shaderIndex);
            Shader shader = shaderMgr.GetShader(shaderIndex);

            shader.Use();
            vao.Bind();
            item.BindBuffer();
            item.Draw(PrimitiveType.Triangles);
        }
Beispiel #14
0
        private static VertexArrayObject LoadVao()
        {
            var vao = new VertexArrayObject();
            var vbo = new VertexBufferObject();

            vao.Bind();
            vbo.Bind(BufferTarget.ArrayBuffer);
            vao.LinkBuffer(vbo);
            vbo.SetData(BufferTarget.ArrayBuffer, Vertices, BufferUsageHint.StaticDraw);
            var builder = new AttributePointerBuilder(vao, 3, 0);

            builder.AddPointer(3, false);
            VertexBufferObject.Unbind(BufferTarget.ArrayBuffer);
            VertexArrayObject.Unbind();
            return(vao);
        }
Beispiel #15
0
        public UiRenderCommand(DrawCmd drawCmd, Matrix4 modelmatrix, VertexBufferObject vbo, IndexBufferObject ibo)
            : base()
        {
            myElementCount  = (int)drawCmd.elementCount;
            myElementOffset = (int)drawCmd.elementOffset;

            pipelineState = thePipelineState;

            renderState.scissorTest.enabled = true;
            renderState.scissorTest.rect    = drawCmd.clipRect;
            renderState.setVertexBuffer(vbo.id, 0, 0, V2T2B4.stride);
            renderState.setIndexBuffer(ibo.id);

            renderState.setUniform(new UniformData(0, Uniform.UniformType.Int, 0));
            renderState.setUniform(new UniformData(0, Uniform.UniformType.Mat4, modelmatrix));
            renderState.setTexture((int)drawCmd.texture.id(), 0, TextureTarget.Texture2D);
        }
Beispiel #16
0
        private void SetupMesh()
        {
            VertexBuffer_ = new VertexBufferObject(VertexBufferFormat.PositionUvNormal, Vertices);
            IndexBuffer_  = new IndexBufferObject(Indices);

            for (var Index = 0; Index < Textures.Length; ++Index)
            {
                if (Textures[Index].Type == "texture_diffuse")
                {
                    TexDiffuse_ = Textures[Index].Tex;
                }
                else if (Textures[Index].Type == "texture_specular")
                {
                    TexSpecular_ = Textures[Index].Tex;
                }
            }
        }
Beispiel #17
0
        private void Initialize(float[] vertexes, uint[] indices, Action bindAttributes)
        {
            _vao = new VertexArrayObject();

            _vao.Bind();

            _vbo = new VertexBufferObject(vertexes);

            if (indices != null)
            {
                _ebo = new ElementBufferObject(indices);
            }

            bindAttributes();

            _vao.Unbind();
        }
Beispiel #18
0
        public TestObject(GraphicsDevice Device)
            : base(Device)
        {
            Rand_ = new Random((int)DateTime.Now.Ticks);

            var Vertices = new[]
            {
                -1f, 1f, 0f, 0f, 0f, 0f, 0f, 1f,  // 0
                1f, 1f, 0f, 1f, 0f, 0f, 0f, 1f,   // 1
                1f, -1f, 0f, 1f, 1f, 0f, 0f, 1f,  // 2
                -1f, -1f, 0f, 0f, 1f, 0f, 0f, 1f  // 3
            };

            var Indices = new[]
            {
                0, 3, 1, // first triangle
                1, 3, 2  // second triangle
            };

            VertexBuffer_ = new VertexBufferObject(VertexBufferFormat.PositionUvNormal, Vertices);
            IndexBuffer_  = new IndexBufferObject(Indices);

            var DirLight = new Light();

            DirLight.Type      = LightType.Direction;
            DirLight.Direction = new Vector3(0.2f, 0.2f, -1f);
            DirLight.Ambient   = new Colorf(0.05f, 0.05f, 0.05f);
            DirLight.Diffuse   = new Colorf(0.4f, 0.4f, 0.4f);
            DirLight.Specular  = new Colorf(0.5f, 0.5f, 0.5f);
            DirLight.Enabled   = true;
            DirLight.UpdateSIMD();

            Shader_           = new ShaderLight();
            Shader_.Lights    = new Light[1];
            Shader_.Lights[0] = DirLight;

            Shader_.TexDiffuse    = TextureHelper.Load("container2.png");
            Shader_.TexSpecular   = TextureHelper.Load("container2_specular.png");
            Shader_.SpecularPower = 32;

            //Camera_ = new Camera(new Vector3(0, 0, 3), new Vector3(0, 0, -1), new Vector3(0, 1, 0), 60.0f, 800.0f / 600.0f, 0.3f, 100.0f);
            Camera_ = new Camera(800, 600);
        }
Beispiel #19
0
        private void CreateBuffers()
        {
            vertexArrayObject.Bind();

            vertexPositions = new VertexBufferObject <Vector3>(Mesh.Vertices.ToArray(), 3, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
            var vertexAttribute = new VertexAttribute("aPosition", 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);

            vertexAttribute.Set(Material.Shader);

            vertexUVs       = new VertexBufferObject <Vector2>(Mesh.Uvs.ToArray(), 2, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
            vertexAttribute = new VertexAttribute("aTexCoord", 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0);
            vertexAttribute.Set(Material.Shader);

            vertexNormals   = new VertexBufferObject <Vector3>(Mesh.Normals.ToArray(), 3, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
            vertexAttribute = new VertexAttribute("aNormal", 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
            vertexAttribute.Set(Material.Shader);

            elementBufferObject = new VertexBufferObject <uint>(Mesh.Indices.ToArray(), 1, BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticDraw);
        }
        public static void Init()
        {
            if (Length == 0)
            {
                int buffer = GL.GenBuffer();
                vao = new VertexBufferObject(buffer);
                vao.AddAttribute(0, 2, VertexAttribPointerType.Float, false, 16, 0);
                vao.AddAttribute(1, 2, VertexAttribPointerType.Float, false, 16, 8);
                vao.Initialize();

                Vector2[] positions = new Vector2[4]
                {
                    new Vector2(-1.0f, 1.0f),
                    new Vector2(-1.0f, -1.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, -1.0f),
                };

                Vector2[] texCoords = new Vector2[4]
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.0f, 0.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, 0.0f),
                };

                List <float> list = new List <float>();
                for (int i = 0; i < 4; i++)
                {
                    list.Add(positions[i].X);
                    list.Add(positions[i].Y);
                    list.Add(texCoords[i].X);
                    list.Add(texCoords[i].Y);
                }

                Length = 4;

                float[] data = list.ToArray();
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);
            }
        }
Beispiel #21
0
        private VertexBufferObject InitArrayBufferForLaterUse(float[] data, int num, VertexAttribPointerType type)
        {
            // Create a buffer object
            VertexBufferObject buffer = new VertexBufferObject();

            GL.GenBuffers(1, out buffer.id);
            if (buffer.id < 0)
            {
                Logger.Append("Failed to create the buffer object");
                return(null);
            }
            // Write date into the buffer object
            GL.BindBuffer(BufferTarget.ArrayBuffer, buffer.id);
            GL.BufferData(BufferTarget.ArrayBuffer, data.Length * sizeof(float), data, BufferUsageHint.StaticDraw);

            // Store the necessary information to assign the object to the attribute variable later
            buffer.num  = num;
            buffer.type = type;

            return(buffer);
        }
Beispiel #22
0
        public void RenderObject(VertexBufferObject <Vertex> vbo, VertexArrayObject <Vertex> vao, int shaderIndex, Matrix4 modelTransform)
        {
            ApplySettingsNow();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            shaderMgr.InitialiseAShader(shaderIndex);
            Uniform.Matrix4Uniform model = new Uniform.Matrix4Uniform("model");
            model.Matrix = modelTransform;
            Uniform.Matrix4Uniform view = new Uniform.Matrix4Uniform("view");
            view.Matrix = cameraMgr.GetActiveCamera().GetVeiwMatrix();
            Uniform.Matrix4Uniform projection = new Uniform.Matrix4Uniform("projection");
            projection.Matrix = GetProjectionMatrix();
            Shader shader = shaderMgr.GetShader(shaderIndex);

            shader.Use();
            model.Set(shader);
            view.Set(shader);
            projection.Set(shader);
            vao.Bind();
            vbo.BindBuffer();
            vbo.Draw(PrimitiveType.Triangles);
        }
Beispiel #23
0
        public void UpdateVertexData()
        {
            Vector3[] vertices = new Vector3[3];
            vertices[0] = new Vector3(-1f, -1f, 1f);
            vertices[1] = new Vector3(3f, -1f, 1f);
            vertices[2] = new Vector3(-1f, 3f, 1f);

            GL.GenBuffers(1, out vbo_position);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
            GL.BufferData <Vector3>(BufferTarget.ArrayBuffer,
                                    new IntPtr(vertices.Length * Vector3.SizeInBytes),
                                    vertices, BufferUsageHint.StaticDraw);

            vao = new VertexBufferObject(vbo_position);
            vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 12, 0);
            vao.Initialize();

            Prepare();

            GLErrorHandler.CheckGLError();
        }
        public VertexArrayObject CreateAndSetupVertexArrayObject(VertexBufferObject<Vertex3V3N> vertexBuffer, VertexBufferObject<uint> elementBuffer)
        {
            var vertexArrayObject = _resourceFactory.CreateVertexArrayObject();

            vertexArrayObject.Bind();
            vertexBuffer.Bind();
            elementBuffer.Bind();

            var dummy = new Vertex3V3N();
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, dummy.SizeInBytes, dummy.PositionOffset);
            GL.EnableVertexAttribArray(0);

            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, dummy.SizeInBytes, dummy.NormalOffset);
            GL.EnableVertexAttribArray(1);

            vertexArrayObject.Unbind();
            vertexBuffer.Unbind();
            elementBuffer.Unbind();

            return vertexArrayObject;
        }
Beispiel #25
0
        public override void Initialize()
        {
            _lines=new []
                       {
                           new VertexC4ubV3f(-_length,0,0,_xColor),
                           new VertexC4ubV3f(_length,0,0,_xColor),
                           new VertexC4ubV3f(0,-_length,0,_yColor),
                           new VertexC4ubV3f(0,_length,0,_yColor),
                           new VertexC4ubV3f(0,0,-_length,_zColor),
                           new VertexC4ubV3f(0,0,_length,_zColor),

                       };
            _indices=new short[]
                         {
                             0,1,
                             2,3,
                             4,5
                         };
            _coordVertexBufferObject = WorldFramework.VertexBufferObject.LoadVBO(_lines, _indices, BufferUsageHint.StaticDraw);
            base.Initialize();
        }
        public VertexArrayObject CreateAndSetupVertexArrayObject(VertexBufferObject <Vertex3V3N> vertexBuffer, VertexBufferObject <uint> elementBuffer)
        {
            var vertexArrayObject = _resourceFactory.CreateVertexArrayObject();

            vertexArrayObject.Bind();
            vertexBuffer.Bind();
            elementBuffer.Bind();

            var dummy = new Vertex3V3N();

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, dummy.SizeInBytes, dummy.PositionOffset);
            GL.EnableVertexAttribArray(0);

            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, dummy.SizeInBytes, dummy.NormalOffset);
            GL.EnableVertexAttribArray(1);

            vertexArrayObject.Unbind();
            vertexBuffer.Unbind();
            elementBuffer.Unbind();

            return(vertexArrayObject);
        }
Beispiel #27
0
        public RenderCommand debugRender()
        {
            if (myVbo == null)
            {
                myVbo = new VertexBufferObject <V3>(BufferUsageHint.DynamicDraw);
                myIbo = new IndexBufferObject(BufferUsageHint.DynamicDraw);
            }

            uint vi = 0;
            uint ii = 0;

            V3[]   verts = new V3[1024 * 1024];
            uint[] index = new uint[1024 * 1024 * 2];

            myNodes[0].debugRender(ref verts, ref vi, ref index, ref ii);

            myVbo.setData(verts, (int)vi);
            myIbo.setData(index, (int)ii);
            RenderVboCommand cmd = new RenderVboCommand(myVbo, myIbo, Color4.Blue, PrimitiveType.Quads);

            return(cmd);
        }
Beispiel #28
0
        private void Generate()
        {
            _shader = ShaderManager.GetOrCreateShader("cubic_block", Shaders.block_vertex, Shaders.block_fragment);
            _vao    = new VertexArrayObject(GenTransformedVertices(), Indices);
            _vao.Bind();
            _dataBuffer = new VertexBufferObject();
            _vao.LinkBuffer(_dataBuffer);
            _dataBuffer.Bind(BufferTarget.ArrayBuffer);
            _dataBuffer.SetData(BufferTarget.ArrayBuffer, MaxBlocks * InstanceFloatDataLength,
                                BufferUsageHint.StreamDraw);
            var builder = new AttributePointerBuilder(_vao, InstanceDataLength, 3);

            builder.AddPointer(3, true);
            builder.AddPointer(1, true);
            builder.AddPointer(1, true);
            builder.AddPointer(1, true);
            builder.AddPointer(1, true);
            VertexBufferObject.Unbind(BufferTarget.ArrayBuffer);
            VertexArrayObject.Unbind();

            _mapper.Vao = _vao;
            _mapper.Vbo = _dataBuffer;
        }
Beispiel #29
0
        public GenericVboMapper(VertexBufferObject vbo, VertexArrayObject vao, int elementSize, int maximumAmount,
                                OnResize onResize, BufferTarget bufferTarget = BufferTarget.ArrayBuffer)
        {
            _vbo = vbo;
            _vao = vao;

            _elementSize = elementSize;

            _onResize = onResize;

            _bufferTarget = bufferTarget;

            _amount        = 0;
            _maximumAmount = maximumAmount;

            _updates        = 0;
            _onBackground   = false;
            _requiresResize = false;

            _tasks   = new ConcurrentQueue <VboMapperTask <TKey> >();
            _offsets = new ConcurrentDictionary <TKey, int>();
            _keys    = new ConcurrentDictionary <int, TKey>();
        }
Beispiel #30
0
        public GraphicsContext(GraphicsDevice Device, Box Viewport)
        {
            this.CoreNum = 6;

            this.Device     = Device;
            this.Viewport   = Viewport;
            this.FrameCount = 0;

            this.ColorBuffer = null;
            this.ZBuffer     = new float[Viewport.Width * Viewport.Height];

            this.Vertices  = new ListCore <Vertex>(this.CoreNum);
            this.Fragments = new ListCore <Fragment>(this.CoreNum);
            this.Indices   = null;

            this.ClearColor         = Colorf.Black;
            this.FillModeState      = FillMode.Solid;
            this.CullFaceModeState  = CullFaceMode.Back;
            this.FrontFaceModeState = FrontFaceMode.CCW;
            this.Shader             = null;
            this.VertexBuffer       = null;
            this.IndexBuffer        = null;
        }
Beispiel #31
0
        public BlockVboMapper(ChunkRegion chunkRegion, VertexBufferObject vbo, VertexArrayObject vao, int elementSize,
                              int maximumAmount,
                              OnResize onResize, BufferTarget bufferTarget = BufferTarget.ArrayBuffer)
        {
            _chunkRegion         = chunkRegion;
            _regionWorldPosition = chunkRegion.Position << World2dRegion.WorldPositionShift;
            _vbo = vbo;
            _vao = vao;

            _elementSize = elementSize;

            _onResize = onResize;

            _bufferTarget = bufferTarget;

            _amount        = 0;
            _maximumAmount = maximumAmount;

            _updates        = 0;
            _onBackground   = false;
            _requiresResize = false;

            _tasks   = new ConcurrentQueue <VboMapperTask <Block> >();
            _offsets = new int[ChunkRegion.RegionLength, ChunkRegion.RegionLength, ChunkRegion.RegionLength];
            _keys    = new Dictionary <int, Vector3i>();
            for (var x = 0; x < ChunkRegion.RegionLength; x++)
            {
                for (var y = 0; y < ChunkRegion.RegionLength; y++)
                {
                    for (var z = 0; z < ChunkRegion.RegionLength; z++)
                    {
                        _offsets[x, y, z] = -1;
                    }
                }
            }
        }
Beispiel #32
0
        private void Generate()
        {
            _shader      = ShaderManager.GetOrCreateShader("water_block", Shaders.water_vertex, Shaders.water_fragment);
            _waterShader = ShaderManager.GetOrCreateShader("water_water_block", Shaders.water_vertex,
                                                           Shaders.water_water_fragment);
            _shader.Use();
            _shader.SetupForWater();
            _waterShader.Use();
            _waterShader.SetupForWater();
            foreach (var face in BlockFaceMethods.All)
            {
                var vao = BlockFaceVertices.CreateVao(face);
                vao.Bind();
                var vbo = new VertexBufferObject();
                vao.LinkBuffer(vbo);
                vbo.Bind(BufferTarget.ArrayBuffer);
                vbo.SetData(BufferTarget.ArrayBuffer, MaxFaces * InstanceFloatDataLength, BufferUsageHint.StreamDraw);
                var builder = new AttributePointerBuilder(vao, InstanceDataLength, 3);
                builder.AddPointer(3, true);
                builder.AddPointer(1, true);
                builder.AddPointer(1, true);
                builder.AddPointer(1, true);
                builder.AddPointer(1, true);
                builder.AddPointer(1, true);
                VertexBufferObject.Unbind(BufferTarget.ArrayBuffer);
                VertexArrayObject.Unbind();

                var i = (int)face;

                _vaos[i]        = vao;
                _dataBuffers[i] = vbo;
                var mapper = _mappers[i];
                mapper.Vao = vao;
                mapper.Vbo = vbo;
            }
        }
        static void Main(string[] args)
        {
            Skybox       skybox       = null;
            VertexBuffer vertexBuffer = null;
            IndexBuffer  indexBuffer  = null;
            Material     material     = null;
            int          renderable   = -1;
            Camera       camera       = null;
            int          cameraEntity = -1;

            var vbo = new VertexBufferObject();

            vbo.Write(new Vector2(1, 0));
            vbo.Write(0xffff0000u);
            vbo.Write(new Vector2(MathF.Cos(MathF.PI * 2 / 3), MathF.Sin(MathF.PI * 2 / 3)));
            vbo.Write(0xff00ff00u);
            vbo.Write(new Vector2(MathF.Cos(MathF.PI * 4 / 3), MathF.Sin(MathF.PI * 4 / 3)));
            vbo.Write(0xff0000ffu);

            var app = new Application(
                new WindowConfig()
            {
                Title = "hellotriangle",
            },
                new ApplicationConfig()
                );

            app.Setup = (engine, view, scene) => {
                skybox = SkyboxBuilder.Create()
                         .WithColor(new Color(0.1f, 0.125f, 0.25f, 1.0f))
                         .Build(engine);

                scene.Skybox = skybox;
                view.PostProcessingEnabled = false;

                vertexBuffer = VertexBufferBuilder.Create()
                               .WithVertexCount(3)
                               .WithBufferCount(1)
                               .WithAttribute(VertexAttribute.Position, 0, ElementType.Float2, 0, 12)
                               .WithAttribute(VertexAttribute.Color, 0, ElementType.UByte4, 8, 12)
                               .WithNormalized(VertexAttribute.Color)
                               .Build(engine);
                vertexBuffer.SetBufferAt(engine, 0, vbo);

                indexBuffer = IndexBufferBuilder.Create()
                              .WithIndexCount(3)
                              .WithBufferType(IndexType.UShort)
                              .Build(engine);
                indexBuffer.SetBuffer(engine, TRIANGLE_INDICES);

                var sampleData = new SampleDataLoader();

                material = MaterialBuilder.Create()
                           .WithPackage(sampleData.LoadBakedColor())
                           .Build(engine);

                renderable = EntityManager.Create();

                RenderableBuilder.Create()
                .WithBoundingBox(
                    new Box(
                        new Vector3(-1, -1, -1),
                        new Vector3(1, 1, 1)
                        )
                    )
                .WithMaterial(0, material.DefaultInstance)
                .WithGeometry(0, PrimitiveType.Triangles, vertexBuffer, indexBuffer, 0, 3)
                .WithCulling(false)
                .WithReceiveShadows(false)
                .WithCastShadows(false)
                .Build(engine, renderable);

                scene.AddEntity(renderable);

                cameraEntity = EntityManager.Create();
                camera       = engine.CreateCamera(cameraEntity);
                view.Camera  = camera;
            };

            app.Cleanup = (engine, view, scene) => {
                engine.Destroy(skybox);
                engine.Destroy(renderable);
                engine.Destroy(material);
                engine.Destroy(vertexBuffer);
                engine.Destroy(indexBuffer);
                engine.DestroyCameraComponent(cameraEntity);

                EntityManager.Destroy(cameraEntity);
            };

            app.Animate = (engine, view, now) => {
                var ZOOM = 1.5f;
                var w    = view.Viewport.Width;
                var h    = view.Viewport.Height;
                ;
                var aspect = (float)w / h;

                camera.SetProjection(Projection.Ortho, -aspect * ZOOM, aspect * ZOOM, -ZOOM, ZOOM, 0, 1);

                var tcm = engine.TransformManager;
                tcm.SetTransform(tcm.GetInstance(renderable), Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, now));
            };

            app.Run();
        }
Beispiel #34
0
        public override void Initialize()
        {
            _vertices=new []
                          {
                              //new VertexN3fV3f(new Vector3(-1,-1,-1), MinBounding.X,MinBounding.Y,MinBounding.Z),
                              //new VertexN3fV3f(new Vector3(-1,-1,1),MinBounding.X,MinBounding.Y,MaxBounding.Z),
                              //new VertexN3fV3f(new Vector3(1,-1,1),MaxBounding.X,MinBounding.Y,MaxBounding.Z),
                              //new VertexN3fV3f(new Vector3(1,-1,-1),MaxBounding.X,MinBounding.Y,MinBounding.Z),
                              //new VertexN3fV3f(new Vector3(-1,1,-1),MinBounding.X,MaxBounding.Y,MinBounding.Z),
                              //new VertexN3fV3f(new Vector3(-1,1,1),MinBounding.X,MaxBounding.Y,MaxBounding.Z),
                              //new VertexN3fV3f(new Vector3(1,1,1),MaxBounding.X,MaxBounding.Y,MaxBounding.Z),
                              //new VertexN3fV3f(new Vector3(1,1,-1),MaxBounding.X,MaxBounding.Y,MinBounding.Z),

                              new VertexC4ubV3f(MinBounding.X,MinBounding.Y,MinBounding.Z,Color.LightSteelBlue),
                              new VertexC4ubV3f(MinBounding.X,MinBounding.Y,MaxBounding.Z,Color.LightSteelBlue),
                              new VertexC4ubV3f(MaxBounding.X,MinBounding.Y,MaxBounding.Z,Color.LightSteelBlue),
                              new VertexC4ubV3f(MaxBounding.X,MinBounding.Y,MinBounding.Z,Color.LightSteelBlue),
                              new VertexC4ubV3f(MinBounding.X,MaxBounding.Y,MinBounding.Z,Color.DodgerBlue),
                              new VertexC4ubV3f(MinBounding.X,MaxBounding.Y,MaxBounding.Z,Color.DodgerBlue),
                              new VertexC4ubV3f(MaxBounding.X,MaxBounding.Y,MaxBounding.Z,Color.DodgerBlue),
                              new VertexC4ubV3f(MaxBounding.X,MaxBounding.Y,MinBounding.Z,Color.DodgerBlue),

                          };
            _indices = new short[]
                           {
                               0, 1, 5, 5, 4, 0,
                               1, 2, 6, 6, 5, 1,
                               2, 3, 7, 7, 6, 2,
                               3, 0, 4, 4, 7, 3,
                               4, 5, 6, 6, 7, 4,
                           };

            _boundingBoxVertexBufferObject = VertexBufferObject.LoadVBO(_vertices, _indices, BufferUsageHint.StaticDraw);

            Textures.TextureLoaderParameters.FlipImages = false;
            Textures.TextureLoaderParameters.MagnificationFilter = TextureMagFilter.Linear;
            Textures.TextureLoaderParameters.MinificationFilter = TextureMinFilter.Linear;
            Textures.TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge;
            Textures.TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge;
            Textures.TextureLoaderParameters.EnvMode = TextureEnvMode.Modulate;
            ImageDDS.LoadFromDisk(_texture, out _textureIndex, out _textureTarget);

            _shaderParameters = Shaders.ShaderTextureParameters.GetShaderTextureParameters(this.GetType());

            _boundingBoxShader.UseShader = false;
            base.Initialize();
        }
Beispiel #35
0
        public override void Initialize()
        {
            _terrainShader.UseShader = true;
            _triangleVertices = new VertexT2fC3fV3f[_xNumber * _zNumber];

            vertexHeight = LoadTerrain(terrainFile, out minHeight, out maxHeight);
            if (vertexHeight != null)
            {
                InitializeVertices();
                triangleElements = rectangleIndices.ToArray();
                _terrainVertexBufferObject = VertexBufferObject.LoadVBO(_triangleVertices, triangleElements, BufferUsageHint.StaticDraw);
            }
            _shaderParameters = Shaders.ShaderTextureParameters.GetShaderTextureParameters(this.GetType());

            Textures.LoadGLTextures(_textures, ref _textureIndices);

            GL.Enable(EnableCap.Light0);
            GL.Light(LightName.Light0, LightParameter.SpotDirection, 0);
            GL.Light(LightName.Light0, LightParameter.Position, _sunVector);
            GL.Light(LightName.Light0, LightParameter.Ambient, Color.White);
            GL.Light(LightName.Light0, LightParameter.Diffuse, _sunColor);
            GL.Light(LightName.Light0, LightParameter.Specular, _sunColor);
            base.Initialize();
        }
Beispiel #36
0
 private void CreateBackgroundConeBuffers(Vertex[] vertices)
 {
     //first set up the attributes
     BufferObjects.VertexAttribute[] attribute = new BufferObjects.VertexAttribute[3];
     attribute[0] = new BufferObjects.VertexAttribute("position", 3, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                                                      Vertex.Size, 0);
     attribute[1] = new BufferObjects.VertexAttribute("normal", 3, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                                                      Vertex.Size, Vector3.SizeInBytes);
     attribute[2] = new BufferObjects.VertexAttribute("texcoord", 2, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                                                      Vertex.Size, 2 * Vector3.SizeInBytes);
     BGvao = new VertexArrayObject <Vertex>();
     BGvbo = new VertexBufferObject <Vertex>(Vertex.Size, vertices);
     BGvbo.CreateBuffer(BufferUsageHint.StaticDraw);
     BGvao.SetAttributes(BGvbo, shaderMgr.GetShader("BackgroundNoFog"), attribute);
     BGvao.Bind();
     // create the EBO
     int[] EBOindices = new int[]
                        #region
     { 0, 1, 3, 2,
       2, 3, 5, 4,
       4, 5, 7, 6,
       6, 7, 9, 8,
       8, 9, 11, 10,
       10, 11, 13, 12,
       12, 13, 15, 14,
       14, 15, 17, 16,
       16, 17, 19, 18,
       18, 19, 21, 20,
       20, 21, 23, 22,
       22, 23, 25, 24,
       24, 25, 27, 26,
       26, 27, 29, 28,
       28, 29, 31, 30,
       30, 31, 33, 32,
       32, 33, 35, 34,
       34, 35, 37, 36,
       36, 37, 39, 38,
       38, 39, 41, 40,
       40, 41, 43, 42,
       42, 43, 45, 44,
       44, 45, 47, 46,
       46, 47, 49, 48,
       48, 49, 51, 50,
       50, 51, 53, 52,
       52, 53, 55, 54,
       54, 55, 57, 56,
       56, 57, 59, 58,
       58, 59, 61, 60,
       60, 61, 63, 62,
       62, 63, 1, 0 };
     #endregion
     //side walls
     BGSideWallebo = new ElementBufferObject(EBOindices);
     BGSideWallebo.CreateBuffer(BufferUsageHint.StaticDraw);
     EBOindices = null;
     //caps
     EBOindices = new int[]
                  #region
     {
         0, 2, 64,
         2, 4, 64,
         4, 6, 64,
         6, 8, 64,
         8, 10, 64,
         10, 12, 64,
         12, 14, 64,
         14, 16, 64,
         16, 18, 64,
         18, 20, 64,
         20, 22, 64,
         22, 24, 64,
         24, 26, 64,
         26, 28, 64,
         28, 30, 64,
         30, 32, 64,
         32, 34, 64,
         34, 36, 64,
         36, 38, 64,
         38, 40, 64,
         40, 42, 64,
         42, 44, 64,
         44, 46, 64,
         46, 48, 64,
         48, 50, 64,
         50, 52, 64,
         52, 54, 64,
         54, 56, 64,
         56, 58, 64,
         58, 60, 64,
         60, 62, 64,
         62, 0, 64,
         65, 3, 1,
         65, 5, 3,
         65, 7, 5,
         65, 9, 7,
         65, 11, 9,
         65, 13, 11,
         65, 15, 13,
         65, 17, 15,
         65, 19, 17,
         65, 21, 19,
         65, 23, 21,
         65, 25, 23,
         65, 27, 25,
         65, 29, 27,
         65, 31, 29,
         65, 33, 31,
         65, 35, 33,
         65, 37, 35,
         65, 39, 37,
         65, 41, 39,
         65, 43, 41,
         65, 45, 43,
         65, 47, 45,
         65, 49, 47,
         65, 51, 49,
         65, 53, 51,
         65, 55, 53,
         65, 57, 55,
         65, 59, 57,
         65, 61, 59,
         65, 63, 61,
         65, 1, 63,
     };
     #endregion
     BGCapsebo = new ElementBufferObject(EBOindices);
     BGCapsebo.CreateBuffer(BufferUsageHint.StaticDraw);
     BGvao.UnBind();
     BGvbo.UnBind();
     BGSideWallebo.Unbind();
     BGCapsebo.Unbind();
 }
Beispiel #37
0
 public override void Initialize()
 {
     InitializeParticles();
     ConstructParticles();
     Textures.LoadGLTextures("Star.bmp", ref texture);
     TexturedVerticeArrays = TexturedVertices.ToArray();
     _vertexBufferObjectHanle = VertexBufferObject.LoadVBO(TexturedVerticeArrays, TexturedElements.ToArray(),
                                           BufferUsageHint.StreamDraw);
     base.Initialize();
 }
Beispiel #38
0
        /// <summary>
        /// Disposes all resources
        /// </summary>
        public void Dispose()
        {
            if(_isDisposed) return;

            _storage[GraphicsConstant.MeshFolderName].Unload(Name);
            _vbo = null;
            _internalMesh = null;

            _isDisposed = true;
        }
Beispiel #39
0
        /// <summary>
        /// Initializes mesh
        /// </summary>
        private void InitializeMesh()
        {
            _internalMesh.Begin(PrimitiveType.LineList, true, false, true);
            _internalMesh.EstimateBufferSize(VertexCount, IndexCount);
            _internalMesh.Position(0.0f, 0.0f, 0.0f);
            _internalMesh.Index(0);
            _internalMesh.End();

            _vbo = _internalMesh.VertexData.GetBuffer(0);
            GenerateIndices(_internalMesh.IndexData.IndexBuffer);

            SubMesh sub = _internalMesh.GetSubMesh(0);
            sub.RenderInfo.VertexCount = VertexCount;
            sub.IndexData.IndexCount = IndexCount;
            sub.RenderInfo.ComputePrimitiveCount();

            _internalMesh.UpdateMeshInfo();
        }
        private void SetupGeometryBuffers()
        {
            verts = new VertexBufferObject (VertexBufferType.ArrayBuffer, VertexBufferUsageHint.StaticDraw);
            indices = new VertexBufferObject (VertexBufferType.ElementArrayBuffer, VertexBufferUsageHint.StaticDraw);

            float[] points =
            {
                0.0f, 0.0f, 0.0f,
            };

            ushort[] idx = { 0 };

            verts.push_data (ref points);
            verts.Bind ();
            GL.VertexPointer (3, VertexPointerType.Float, 0, 0);

            indices.push_data (ref idx);
            indices.Bind();
        }
Beispiel #41
0
        public void SetTextureCoordinates(TextureCoordinates[] coords)
        {
            if (fTextureBufferObject != null)
            {
                fTextureBufferObject.Dispose();
                fTextureBufferObject = null;
            }


            // Write the vertex data to the buffer
            GCHandle dataPtr = GCHandle.Alloc(coords, GCHandleType.Pinned);
            int dataSize = Marshal.SizeOf(typeof(TextureCoordinates)) * coords.Length;
            fTextureBufferObject = new VertexBufferObject(GI);
            fTextureBufferObject.Bind();
            fTextureBufferObject.Size = dataSize;

            try
            {
                fTextureBufferObject.Bind();
                fTextureBufferObject.Write(dataPtr.AddrOfPinnedObject(), 0, dataSize);
            }
            finally
            {
                fTextureBufferObject.Unbind();
                dataPtr.Free();
            }
        }