예제 #1
0
        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); });
                }
            }
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
 internal SceneObjectBatch(State.GraphicsStateSet state)
 {
     if (state == null)
     {
         throw new ArgumentNullException("state");
     }
     State = state;
 }
예제 #4
0
 /// <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();
     }
 }
예제 #5
0
        /// <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;
        }
예제 #6
0
        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));
            }
        }
예제 #7
0
 public void AddGeometry(State.GraphicsStateSet state)
 {
     _GeometryInstances.Add(new Geometry(state));
 }
예제 #8
0
 public void AddGeometry(VertexArrays vertexArray, State.GraphicsStateSet state)
 {
     _GeometryInstances.Add(new Geometry(vertexArray, state, null));
 }
예제 #9
0
 public Geometry(State.GraphicsStateSet state) :
     base(state)
 {
 }
예제 #10
0
 /// <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)
 {
 }