Esempio n. 1
0
        /// <summary>
        /// Actually create this GraphicsResource resources.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for allocating resources.
        /// </param>
        /// <remarks>
        /// All resources linked with <see cref="LinkResource(IGraphicsResource)"/> will be automatically created.
        /// </remarks>
        protected override void CreateObject(GraphicsContext ctx)
        {
            // Bounding box - Shared program
            LinkResource(_BoundingVolumeProgram = ctx.CreateProgram("OpenGL.Standard"));

            // Bounding box - Shared arrays
            const string BoundBoxArraysId = "SceneObjectGeometry.BoundingVolumeArrays";

            VertexArrays boundingBoxArrays = (VertexArrays)ctx.GetSharedResource(BoundBoxArraysId);

            if (_BoundingVolume != null && boundingBoxArrays == null)
            {
                boundingBoxArrays = CreateBoundingVolumeArrays(_BoundingVolume);
                ctx.SetSharedResource(BoundBoxArraysId, boundingBoxArrays);
            }
            if (boundingBoxArrays != null)
            {
                LinkResource(_BoundingVolumeArray = boundingBoxArrays);
            }

            // Create geometry state, if necessary
            if (VertexArray != null && VertexArray.Exists(ctx) == false)
            {
                VertexArray.Create(ctx);
            }
            // Define program, if necessary
            if (Program == null && ProgramTag != null)
            {
                Program = ctx.CreateProgram(ProgramTag);
            }
            // Create program, if necessary
            if (Program != null && Program.Exists(ctx) == false)
            {
                Program.Create(ctx);
            }

            // Create instance-only resources
            foreach (Geometry geometry in _GeometryInstances)
            {
                geometry.Create(ctx);
            }

            // Create object state, but associating state to program
            ObjectState.Create(ctx, Program);
            // Base implementation
            base.CreateObject(ctx);
        }
Esempio n. 2
0
        /// <summary>
        /// Actually create this GraphicsResource resources.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for allocating resources.
        /// </param>
        /// <remarks>
        /// All resources linked with <see cref="LinkResource(IGraphicsResource)"/> will be automatically created.
        /// </remarks>
        protected override void CreateObject(GraphicsContext ctx)
        {
            // Create geometry state, if necessary
            if (VertexArray != null && VertexArray.Exists(ctx) == false)
            {
                VertexArray.Create(ctx);
            }
            // Define program, if necessary
            if (Program == null && ProgramTag != null)
            {
                Program = ctx.CreateProgram(ProgramTag);
            }
            // Create program, if necessary
            if (Program != null && Program.Exists(ctx) == false)
            {
                Program.Create(ctx);
            }

            // Create instance-only resources
            foreach (Geometry geometry in _GeometryInstances)
            {
                geometry.Create(ctx);
            }

            // In place base.CreateObject implementation

            // Create object state
            ObjectState.Create(ctx, Program);
            // Base implementation
            base.CreateObject(ctx);
            // Propagate creation to hierarchy
            foreach (SceneObject sceneGraphObject in _Children)
            {
                sceneGraphObject.Create(ctx);
            }
        }