public void Draw() { Vertex2f[] vertices = new Vertex2f[] { new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 0.0f), new Vertex2f(1.0f, 1.0f), new Vertex2f(0.0f, 1.0f), }; using (VertexArrayObject vao = new VertexArrayObject()) { // Setup ABO (Position) ArrayBufferObject abo = new ArrayBufferObject(VertexBaseType.Float, 2, BufferObjectHint.StaticCpuDraw); abo.Create(vertices); // Setup VAO vao.SetArray(abo, VertexArraySemantic.Position); vao.SetElementArray(PrimitiveType.TriangleStrip); vao.Create(_Context); using (State.GraphicsStateSet currentState = State.GraphicsStateSet.GetDefaultSet()) { // Set transform state State.TransformStateBase stateTransform = (State.TransformStateBase)currentState[State.TransformStateBase.StateId]; // Set normalized orthogonal projection stateTransform.LocalProjection = new OrthoProjectionMatrix(0.0f, 1.0f, 0.0f, 1.0f); // Apply state currentState.Apply(_Context); // Draw Assert.DoesNotThrow(delegate() { vao.Draw(_Context); }); } } }
internal IEnumerable <SceneObjectBatch> GetGeometries(State.GraphicsStateSet currentState) { if (_GeometryInstances.Count > 0) { foreach (Geometry sceneObjectBatch in _GeometryInstances) { State.GraphicsStateSet geometryState; if (sceneObjectBatch.State != null) { geometryState = currentState.Push(); geometryState.Merge(sceneObjectBatch.State); } else { geometryState = currentState; } yield return(new SceneObjectBatch( sceneObjectBatch.VertexArray ?? VertexArray, geometryState, sceneObjectBatch.Program ?? Program )); } } else { yield return(new SceneObjectBatch(VertexArray, currentState, Program)); } }
internal SceneObjectBatch(State.GraphicsStateSet state) { if (state == null) { throw new ArgumentNullException("state"); } State = state; }
/// <summary> /// Construct an Geometry. /// </summary> /// <param name="vertexArray"> /// /// </param> /// <param name="state"></param> /// <param name="program"></param> public Geometry(VertexArrays vertexArray, State.GraphicsStateSet state, ShaderProgram program) : base(vertexArray, state, program) { vertexArray.IncRef(); if (program != null) { program.IncRef(); } }
/// <summary> /// Construct an SceneObjectBatch. /// </summary> /// <param name="vertexArray"> /// /// </param> /// <param name="state"></param> /// <param name="program"></param> public SceneObjectBatch(VertexArrays vertexArray, State.GraphicsStateSet state, ShaderProgram program) { if (vertexArray == null) { throw new ArgumentNullException("vertexArray"); } if (state == null) { throw new ArgumentNullException("state"); } Program = program; // It may be null to support fixed pipeline VertexArray = vertexArray; State = state; }
internal IEnumerable <SceneObjectBatch> GetGeometries(State.GraphicsStateSet currentState, IEnumerable <Plane> clippingPlanes, IMatrix4x4 viewModel) { if (_GeometryInstances.Count > 0) { foreach (Geometry sceneObjectBatch in _GeometryInstances) { IBoundingVolume instanceVolume = sceneObjectBatch.BoundingVolume ?? _BoundingVolume; if (instanceVolume != null && instanceVolume.IsClipped(clippingPlanes, viewModel)) { continue; } State.GraphicsStateSet geometryState; if (sceneObjectBatch.State != null) { geometryState = currentState.Push(); geometryState.Merge(sceneObjectBatch.State); } else { geometryState = currentState; } yield return(new SceneObjectBatch( sceneObjectBatch.VertexArray ?? VertexArray, geometryState, sceneObjectBatch.Program ?? Program )); } } else { if (_BoundingVolume != null && _BoundingVolume.IsClipped(clippingPlanes, viewModel)) { yield break; } yield return(new SceneObjectBatch(VertexArray, currentState, Program)); } }
public void AddGeometry(State.GraphicsStateSet state) { _GeometryInstances.Add(new Geometry(state)); }
public void AddGeometry(VertexArrays vertexArray, State.GraphicsStateSet state) { _GeometryInstances.Add(new Geometry(vertexArray, state, null)); }
public Geometry(State.GraphicsStateSet state) : base(state) { }
/// <summary> /// Construct an Geometry. /// </summary> /// <param name="vertexArray"> /// /// </param> /// <param name="state"></param> /// <param name="program"></param> public Geometry(VertexArrayObject vertexArray, State.GraphicsStateSet state, ShaderProgram program) : base(vertexArray, state, program) { }