/// <summary> /// Draws the specified context. /// </summary> /// <param name="context">The context.</param> public void Draw(IRenderContext context) { context.RenderState.Set(new ShaderPointSize(ShaderPointSize)); context.RenderState.Set(new DepthTest(ZBufferTest)); context.RenderState.Set(new FaceCullingModeState(BackfaceCulling ? FaceCullingMode.BACK_SIDE : FaceCullingMode.NONE)); context.RenderState.Set(new ActiveShader(ShaderProgram)); BindTextures(); ActivateBuffers(); var vao = Vao; if (vao is null) { if (1 == InstanceCount) { GL.DrawArrays(PrimitiveType.Quads, 0, 4); //TODO: make this general -> mesh with only vertex count? particle system, sprites } else { GL.DrawArrays(PrimitiveType.Points, 0, InstanceCount); } } else { Vao.Draw(InstanceCount); } DeactivateBuffers(); UnbindTextures(); }
public QuadRenderer(Quad <T>[] quads, Factory <Vao <T>, VaoArgs <T> > vaoFactory, Factory <Vbo <T>, VboArgs <T> > vboFactory, Factory <Ebo, EboArgs> eboFactory, VboRenderer <T> vboRenderer) { _vboRenderer = vboRenderer; var vertices = new T[quads.Length * 4]; var indices = new uint[quads.Length * 6]; for (uint i = 0; i < quads.Length; i++) { vertices[i * 4] = quads[i].FirstVertex; vertices[i * 4 + 1] = quads[i].SecondVertex; vertices[i * 4 + 2] = quads[i].ThirdVertex; vertices[i * 4 + 3] = quads[i].FourthVertex; indices[i * 6] = i * 4; indices[i * 6 + 1] = i * 4 + 2; indices[i * 6 + 2] = i * 4 + 3; indices[i * 6 + 3] = i * 4; indices[i * 6 + 4] = i * 4 + 1; indices[i * 6 + 5] = i * 4 + 2; } _vbo = vboFactory.Create(new VboArgs <T>(vertices)); _vao = vaoFactory.Create(new VaoArgs <T>(_vbo.VboId)); _ebo = eboFactory.Create(new EboArgs(indices)); }
public void BindAttribute(VertexAttrib attribute, int offset) { if (BufferInitialized) { Vao.BindAttribute(attribute, VertexBuffer, offset); } }
public void Draw(StateSetGL stateSetGL) { stateSetGL.BackfaceCulling = BackfaceCulling; stateSetGL.ShaderPointSize = ShaderPointSize; stateSetGL.ZBufferTest = ZBufferTest; stateSetGL.Shader = Shader; BindTextures(); ActivateBuffers(); var vao = Vao; if (ReferenceEquals(null, vao)) { if (1 == InstanceCount) { GL.DrawArrays(PrimitiveType.Quads, 0, 4); //todo: make this general -> mesh with only vertex count? particle system, sprites } else { GL.DrawArrays(PrimitiveType.Points, 0, InstanceCount); } } else { Vao.Draw(InstanceCount); } DeactivateBuffers(); UnbindTextures(); }
public Model(Vertex[] vertecies, int[] vertexIndices) { VAO = new Vao(); List <float> vertexPositionData = new List <float>(); List <float> vertexTextureCoordinate = new List <float>(); List <float> vertexNormals = new List <float>(); foreach (var v in vertecies) { vertexPositionData.Add(v.Position.X); vertexPositionData.Add(v.Position.Y); vertexPositionData.Add(v.Position.Z); vertexTextureCoordinate.Add(v.TextureCoordinate.X); vertexTextureCoordinate.Add(v.TextureCoordinate.Y); vertexNormals.Add(v.Normal.X); vertexNormals.Add(v.Normal.Y); vertexNormals.Add(v.Normal.Z); } VAO.SetIndecesBuffer(vertexIndices); VAO.StoreAttribute(0, vertexPositionData.ToArray(), 3); VAO.StoreAttribute(1, vertexTextureCoordinate.ToArray(), 2); VAO.StoreAttribute(2, vertexNormals.ToArray(), 3); VertexCount = vertexIndices.Length; }
/// <summary> /// Draws the specified context. /// </summary> /// <param name="context">The context.</param> public void Draw(IRenderContext context) { var stateManager = context.StateManager; context.RenderState.Set(new BoolState <IShaderPointSizeState>(ShaderPointSize)); context.RenderState.Set(new BoolState <IDepthState>(ZBufferTest)); context.RenderState.Set(new BoolState <IBackfaceCullingState>(BackfaceCulling)); stateManager.Get <StateActiveShaderGL, StateActiveShaderGL>().ShaderProgram = ShaderProgram; BindTextures(); ActivateBuffers(); var vao = Vao; if (vao is null) { if (1 == InstanceCount) { GL.DrawArrays(PrimitiveType.Quads, 0, 4); //TODO: make this general -> mesh with only vertex count? particle system, sprites } else { context.DrawPoints(InstanceCount); } } else { Vao.Draw(InstanceCount); } DeactivateBuffers(); UnbindTextures(); }
public void UnbindAttribute(VertexAttrib attribute) { if (BufferInitialized) { Vao.UnbindAttribute(attribute); } }
public void Bind() { if (BufferInitialized) { Vao.Bind(); } }
public virtual void draw(Matrix4 view) { if (picked) { //this.Scale = .75f; } GL.BindTexture(TextureTarget.Texture2D, this.Texture.Id); Shader.Use(); Shader.setUniform("model", this.transform); Shader.setUniform("view", view); Shader.setUniform("picked", picked); Shader.setUniform("l", l); Shader.setUniform("f", f); Shader.setUniform("r", r); Shader.setUniform("ba", ba); Shader.setUniform("t", t); Shader.setUniform("bo", bo); Vao.Bind(); GL.DrawArrays(PrimitiveType.Triangles, 0, Vao.Lenth); Vao.Unbind(); if (picked) { picked = false; //this.Scale = 1.0f; } }
public void SetUp() { var fakeVertex = new FakeVertex(); _quad = new Quad <FakeVertex>(fakeVertex, fakeVertex, fakeVertex, fakeVertex); _expectedVertices = new[] { _quad.FirstVertex, _quad.SecondVertex, _quad.ThirdVertex, _quad.FourthVertex, _quad.FirstVertex, _quad.SecondVertex, _quad.ThirdVertex, _quad.FourthVertex }; _expectedIndices = new uint[] { 0, 2, 3, 0, 1, 2, 4, 6, 7, 4, 5, 6 }; _fakeVao = new Vao <FakeVertex>(); _fakeVbo = new Vbo <FakeVertex>(3); _fakeEbo = new Ebo(); _vaoFactoryMock = new Mock <Factory <Vao <FakeVertex>, VaoArgs <FakeVertex> > >(); _vaoFactoryMock.Setup(m => m.Create(It.IsAny <VaoArgs <FakeVertex> >())).Returns(_fakeVao); _vboFactoryMock = new Mock <Factory <Vbo <FakeVertex>, VboArgs <FakeVertex> > >(); _vboFactoryMock.Setup(m => m.Create(It.IsAny <VboArgs <FakeVertex> >())).Returns(_fakeVbo); _eboFactoryMock = new Mock <Factory <Ebo, EboArgs> >(); _eboFactoryMock.Setup(m => m.Create(It.IsAny <EboArgs>())).Returns(_fakeEbo); _vboRendererMock = new Mock <VboRenderer <FakeVertex> >(); _quadRenderer = new QuadRenderer <FakeVertex>(new[] { _quad, _quad }, _vaoFactoryMock.Object, _vboFactoryMock.Object, _eboFactoryMock.Object, _vboRendererMock.Object); }
public void Draw(GL_ControlModern control, Pass pass, Vector4 highlightColor) { if (pass == Pass.PICKING) { control.CurrentShader = Framework.SolidColorShaderProgram; GL.LineWidth(5); control.CurrentShader.SetVector4("color", control.NextPickingColor()); } else if (pass == Pass) { control.CurrentShader = ExtraModelShaderProgram; if (pass == Pass.TRANSPARENT) { GL.Enable(EnableCap.Blend); } GL.LineWidth(3); control.CurrentShader.SetVector4("highlight_color", highlightColor); } else { return; } Vao.Use(control); GL.DrawElements(PrimitiveType, IndexCount, DrawElementsType.UnsignedInt, 0); GL.LineWidth(2); GL.Disable(EnableCap.Blend); }
public void UpdateVertexData() { List <float> list = new List <float>(); for (int i = 0; i < Faces.Count; i++) { for (int v = 0; v < Faces[i].Vertices.Length; v++) { var vertex = Faces[i].Vertices[v]; list.Add(vertex.Position.X); list.Add(vertex.Position.Y); list.Add(vertex.Position.Z); list.Add(vertex.Normal.X); list.Add(vertex.Normal.Y); list.Add(vertex.Normal.Z); list.Add(vertex.TexCoord.X); list.Add(vertex.TexCoord.Y); } } Vao.Bind(); float[] data = list.ToArray(); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); int[] indices = Indices.ToArray(); GL.BufferData(BufferTarget.ElementArrayBuffer, sizeof(int) * indices.Length, indices, BufferUsageHint.StaticDraw); }
public GLObjTextured(GL gl, float[] verts, uint[] indices, string vertPath, string fragPath, bool isDynamic, List <Texture> textures) : base(gl, verts, indices, vertPath, fragPath, isDynamic, 5) { this.textures = textures; this.verts = verts; Vao.VertexAttributePointer(1, 2, VertexAttribPointerType.Float, 5, 3); gl.EnableVertexAttribArray(1); }
public virtual void Draw(Camera cam, ShaderProgram shader) { Texture?.Bind(); shader.Bind(); shader.SetUniform("model", Transform); Vao.DrawElements(PrimitiveType.Quads); }
/// <summary> /// Uploads the data to GPU. /// </summary> public override void UploadDataToGPU() { Vao.ChangeData(BufferTarget.ArrayBuffer, Verticies.ToArray()); ChangeAttribute(BufferTarget.ArrayBuffer, "position", 2, VertexAttribPointerType.Float, true, 4 * sizeof(float), 0); ChangeAttribute(BufferTarget.ArrayBuffer, "texcoord", 2, VertexAttribPointerType.Float, true, 4 * sizeof(float), 2 * sizeof(float)); }
public override void UploadDataToGPU() { Vao.ChangeData(BufferTarget.ArrayBuffer, Verticies.ToArray()); this.ChangeAttribute(BufferTarget.ArrayBuffer, "position", 2, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0); this.ChangeAttribute(BufferTarget.ArrayBuffer, "vertexColor", 4, VertexAttribPointerType.Float, false, 6 * sizeof(float), 2 * sizeof(float)); }
public virtual void DrawToPickBuffer(Camera cam, ShaderProgram shader) { shader.Bind(); shader.SetUniform("model", Transform); shader.SetUniform("view", cam.Transfrom); shader.SetUniform("pickColor", pickColor); Vao.DrawElements(PrimitiveType.Quads); }
public void DrawArrays(PrimitiveType drawMode, int first, int count) { if (!BufferInitialized) { CreateBuffers(); } Vao.Bind(); Vao.DrawArrays(drawMode, first, count); }
public void DrawElements(PrimitiveType drawMode, int count) { if (!BufferInitialized) { CreateBuffers(); } Vao.Bind(); Vao.DrawElements(drawMode, count); }
public void DrawElementsBaseVertex(PrimitiveType mode, int baseVertex, int count, int offset = 0) { if (!BufferInitialized) { CreateBuffers(); } Vao.Bind(); Vao.DrawElementsBaseVertex(mode, baseVertex, count, DrawElementsType.UnsignedInt, offset); }
public void DrawElements(PrimitiveType drawMode = PrimitiveType.Triangles) { if (!BufferInitialized) { CreateBuffers(); } Vao.Bind(); Vao.DrawElements(drawMode, IndexBuffer.ElementCount); }
public unsafe override void Dispose() { Vbo.Dispose(); Ebo.Dispose(); Vao.Dispose(); shader.Dispose(); foreach (var item in textures) { item.Dispose(); } }
public void drawToPickBuffer(ShaderProgram shader, Matrix4 view) { shader.Use(); shader.setUniform("model", this.transform); shader.setUniform("view", view); shader.setUniform("pickColor", this.pickColor); Vao.Bind(); GL.DrawArrays(PrimitiveType.Triangles, 0, Vao.Lenth); Vao.Unbind(); }
public Renderer2D() { lastEntityOffset = 0; vao = new Vao(); vbo = new Vbo(BufferUsage.DynamicDraw, 100000); ibo = new Ibo(100000 * 6); // Set layouts for vbo vbo.PushLayout(new BufferLayout(2, VertexAttribType.Float, false)); // x, y vbo.PushLayout(new BufferLayout(4, VertexAttribType.Float, false)); // r, g, b, a vbo.PushLayout(new BufferLayout(2, VertexAttribType.Float, false)); // tx, ty vbo.PushLayout(new BufferLayout(1, VertexAttribType.Float, false)); // texture id }
public void Dispose() { if (ElementBuffer != null) { ElementBuffer.Dispose(); ElementBuffer = null; } if (Vao != null) { Vao.Dispose(); Vao = null; } IsDisposed = true; }
public unsafe override void Render() { Vao.Bind(); for (int i = 0; i < textures.Count; i++) { textures[i].Bind((TextureUnit)i); } shader.Use(); if (indices != null) { gl.DrawElements(PrimitiveType.Triangles, (uint)indices.Length, GLEnum.UnsignedInt, null); } else { gl.DrawArrays(PrimitiveType.Triangles, 0, (uint)verts.Length); } }
public void Dispose() { CheckersShader.Dispose(); Vao.Dispose(); samplerLinear.Dispose(); samplerLinearMip.Dispose(); samplerNearest.Dispose(); samplerNearestMip.Dispose(); TextureCache.Clear(); GetPixelShader.Dispose(); SrgbShader.Dispose(); ExportShader.Dispose(); LinearMaxStatistics.Dispose(); SrgbMaxStatistics.Dispose(); LinearMinStatistics.Dispose(); SrgbMinStatistics.Dispose(); }
internal FontShaderNormal() { byte[] shaderByteSource = Properties.Resources.FontVertex; string shaderStr = shaderByteSource.Aggregate("", (current, t) => current + Convert.ToChar(t)); if (!AddShader(ShaderType.VertexShader, shaderStr)) { throw new Exception("Cannot create vertex shader"); } shaderByteSource = Properties.Resources.FontFragmentSimple; shaderStr = shaderByteSource.Aggregate("", (current, t) => current + Convert.ToChar(t)); if (!AddShader(ShaderType.FragmentShader, shaderStr)) { throw new Exception("Cannot create fragment shader"); } LinkShaderProgram(); Vao.Resize(BufferTarget.ArrayBuffer, 10000); Uniform1("Texture", 4); }
public void Dispose() { if (IndexBuffer != null) { IndexBuffer.Dispose(); IndexBuffer = null; } if (VertexBuffer != null) { VertexBuffer.Dispose(); VertexBuffer = null; } if (Vao != null) { Vao.Dispose(); Vao = null; } IsDisposed = true; }
public override void Draw(Camera cam, ShaderProgram shader, ShaderProgram lineShader) { Texture?.Bind(0); specularT?.Bind(1); nightT?.Bind(2); shader.Bind(); shader.SetUniform("model", Transform); Vao.DrawElements(PrimitiveType.Quads); //if (drawClouds) //{ // scaleBy(1.005f); // cloudsT?.Bind(); // cloudShader.Bind(); // cloudShader.SetUniform("model", Transform); // cloudShader.SetUniform("view", cam.Transfrom); // cloudShader.SetUniform("proj", cam.Projection); // cloudShader.SetUniform("lightPos", cam.LightPos); // Vao.DrawElements(PrimitiveType.Quads); // scaleBy(1 / 1.005f); //} //draw axis line if (DrawAxisTilt) { lineShader.Bind(); lineShader.SetUniform("model", Transform); axisLine.DrawArrays(PrimitiveType.Lines); } //draw orbit if (Orbit != null && DrawOrbit) { Orbit.Draw(lineShader); } }