Example #1
0
        public override void Create()
        {
            VAO = new("Cubemap VAO");
            VBO = new("Cubemap VBO");

            VAO.Bind();

            VBO.Bind(BufferTarget.ArrayBuffer);

            VBO.Data(skyboxVertices, BufferUsageHint.DynamicDraw);

            var VS = File.ReadAllText("EngineResources/Shaders/Cubemap/cubemap.vert");
            var FS = File.ReadAllText("EngineResources/Shaders/Cubemap/cubemap.frag");

            var VP = new GLShader(VS, GLShaderType.Vertex);
            var FP = new GLShader(FS, GLShaderType.Fragment);

            CubemapShader = new GLShaderProgram()
                            .Label("Cubemap Shader")
                            .Attach(VP)
                            .Attach(FP)
                            .Link();

            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);

            GL.BindVertexArray(0);
        }
Example #2
0
 void IRenderable.EnqueueDrawCalls(GLDrawCallBatch drawCallbatch)
 {
     if (_vertexArrayObjects == null)
     {
         _vertexArrayObjects =
             Model.GLMeshes.Select(glMesh =>
         {
             var vao = new GLVertexArrayObject(glMesh, Material.Program);
             vao.GpuAllocateDeferred();
             return(vao);
         }).ToArray();
     }
     for (var i = 0; i < Model.GLMeshes.Length; i++)
     {
         var glMesh = Model.GLMeshes[i];
         drawCallbatch.AddDrawCall(new GLDrawCall(
                                       Material.Program,
                                       Material.GenerateTexturebinds(),
                                       _vertexArrayObjects[i],
                                       Material.GenerateUniformBinds(Transform.GetWorldMatrix()),
                                       () =>
                                       GL.DrawElements(PrimitiveType.Triangles, glMesh.IndexBuffer.BufferCount, DrawElementsType.UnsignedInt,
                                                       IntPtr.Zero)));
     }
 }
Example #3
0
        private unsafe void SetUp()
        {
            VAO = new("Mesh VAO");
            VBO = new("Mesh VBO");
            EBO = new("Mesh EBO");

            VAO.Bind();
            VBO.Bind(BufferTarget.ArrayBuffer);

            // Buffer the vertex data into the VBO.
            var verarr = CollectionsMarshal.AsSpan(Vertices);

            GL.BufferData(BufferTarget.ArrayBuffer, verarr.Length * sizeof(Vertex), ref verarr[0], BufferUsageHint.StaticDraw);

            EBO.Bind(BufferTarget.ElementArrayBuffer);

            // Buffer the element array into the EBO.
            var indarr = CollectionsMarshal.AsSpan(Indices);

            GL.BufferData(BufferTarget.ElementArrayBuffer, indarr.Length * sizeof(uint), ref indarr[0], BufferUsageHint.StaticDraw);

            SetupPointers();

            GL.BindVertexArray(0);
        }
Example #4
0
        private void Render_CreateContext(object sender, GlControlEventArgs e)
        {
            //code executed when render context is created

            //get a reference to the object that contains our opengl crap
            Control senderControl = (Control)sender;

            //set the size of our OpenGL rendering area. we're startign in the very corner and
            //getting the height and the width of the blank canvas control in our form
            Gl.Viewport(0, 0, senderControl.Size.Width, senderControl.Size.Height);
            Gl.Enable(EnableCap.DepthTest);
            //create the shader, this compiles it and all that good stuff
            shaderProgram = new ShaderProgram(_VertexShader, _FragmentShader);
            vao           = new GLVertexArrayObject(shaderProgram, _PositionData, _ColorData);
        }
Example #5
0
 public void EnqueueDrawCalls(GLDrawCallBatch drawCallbatch)
 {
     if (_vertexArrayObject == null)
     {
         _vertexArrayObject = new GLVertexArrayObject(_glMesh, _textMaterial.Program);
         _vertexArrayObject.GpuAllocateDeferred();
     }
     drawCallbatch.AddDrawCall(new GLDrawCall(
                                   _textMaterial.Program,
                                   _textMaterial.GenerateTexturebinds(),
                                   _vertexArrayObject,
                                   _textMaterial.GenerateUniformBinds(Transform.GetWorldMatrix()),
                                   () =>
                                   GL.DrawElements(PrimitiveType.Triangles, _glMesh.IndexBuffer.BufferCount, DrawElementsType.UnsignedInt,
                                                   IntPtr.Zero)));
 }
Example #6
0
 public void EnqueueDrawCalls(GLDrawCallBatch drawCallbatch)
 {
     using (var graphics = Graphics.FromImage(_glTexture.Bitmap))
     {
         graphics.Clear(Color.Transparent);
         graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
         Draw(graphics);
     }
     if (_vertexArrayObject == null)
     {
         _vertexArrayObject = new GLVertexArrayObject(_glMesh, _guiShader);
         _vertexArrayObject.GpuAllocateDeferred();
     }
     drawCallbatch.AddDrawCall(new GLDrawCall(_guiShader,
                                              new[] { new GLDrawCall.GLTextureBind(_glTexture, TextureTarget.Texture2D, TextureUnit.Texture0) },
                                              _vertexArrayObject, new GLDrawCall.UniformBind[0],
                                              () =>
                                              GL.DrawElements(PrimitiveType.Triangles, _glMesh.IndexBuffer.BufferCount, DrawElementsType.UnsignedInt,
                                                              IntPtr.Zero)));
 }