Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColoredStaticMesh"/> class.
        /// </summary>
        /// <param name="viewProjection">The provider for the view and projection matrices to use when rendering.</param>
        /// <param name="vertices">The vertices of the mesh.</param>
        /// <param name="indices">The indices (into the provided vertices) to use for actually rendering the mesh.</param>
        public ColoredStaticMesh(
            IViewProjection viewProjection,
            IEnumerable <Vertex> vertices,
            IEnumerable <uint> indices)
        {
            this.viewProjection = viewProjection;

            if (program == null && programBuilder == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null && programBuilder == null)
                    {
                        programBuilder = new GlProgramBuilder()
                                         .WithVertexShaderFromEmbeddedResource("Colored.Vertex.glsl")
                                         .WithFragmentShaderFromEmbeddedResource("Colored.Fragment.glsl")
                                         .WithDefaultUniformBlock <DefaultUniformBlock>()
                                         .WithSharedUniformBufferObject <CameraUniformBlock>("Camera", BufferUsageHint.DynamicDraw, 1);
                    }
                }
            }

            this.vertexArrayObjectBuilder = new VertexArrayObjectBuilder(PrimitiveType.Triangles)
                                            .WithNewAttributeBuffer(BufferUsageHint.StaticDraw, vertices.ToArray())
                                            .WithNewIndexBuffer(BufferUsageHint.StaticDraw, indices.ToArray());
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gui"/> class.
        /// </summary>
        /// <param name="view">The view from which to derive size and input.</param>
        /// <param name="initialCapacity">Initial capacity of the GUI, in vertices.</param>
        public Gui(MyOTKEWindow view, int initialCapacity)
        {
            this.view         = view;
            this.view.Resize += View_Resized;

            this.SubElements = new ElementCollection(this);

            if (program == null && programBuilder == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null && programBuilder == null)
                    {
                        programBuilder = new GlProgramBuilder()
                                         .WithVertexShaderFromEmbeddedResource("Gui.Vertex.glsl")
                                         .WithFragmentShaderFromEmbeddedResource("Gui.Fragment.glsl")
                                         .WithDefaultUniformBlock <Uniforms>();
                    }
                }
            }

            this.vertexBufferBuilder = new ReactiveBufferBuilder <Vertex>(
                PrimitiveType.Triangles,
                initialCapacity,
                new[] { 0, 2, 3, 0, 3, 1 },
                this.SubElements.Flatten());
        }
Exemple #3
0
        /// <inheritdoc />
        public void Load()
        {
            ThrowIfDisposed();

            if (program == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null)
                    {
                        program        = programBuilder.Build();
                        programBuilder = null;
                    }
                }
            }

            this.vertexArrayObject        = (GlVertexArrayObject <Vertex>) this.vertexArrayObjectBuilder.Build();
            this.vertexArrayObjectBuilder = null;
        }
Exemple #4
0
        /// <inheritdoc /> from IComponent
        public void Load()
        {
            ThrowIfDisposed();

            if (program == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null)
                    {
                        program        = programBuilder.Build();
                        programBuilder = null;
                    }
                }
            }

            this.vertexBuffer        = this.vertexBufferBuilder.Build();
            this.vertexBufferBuilder = null;
        }
Exemple #5
0
        /// <inheritdoc />
        public void Load()
        {
            ThrowIfDisposed();

            if (program == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null)
                    {
                        program        = programBuilder.Build();
                        programBuilder = null;
                    }
                }
            }

            this.coloredTriangleBuffer        = coloredTriangleBufferBuilder.Build();
            this.coloredTriangleBufferBuilder = null;

            this.coloredLineBuffer        = coloredLineBufferBuilder.Build();
            this.coloredLineBufferBuilder = null;
        }
Exemple #6
0
        /// <inheritdoc />
        public void Load()
        {
            ThrowIfDisposed();

            this.textures    = new int[1];
            this.textures[0] = Path.GetExtension(textureFilePath) == ".DDS" ? TextureLoader.LoadDDS(textureFilePath) : TextureLoader.LoadBMP(textureFilePath);

            if (program == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null)
                    {
                        program        = programBuilder.Build();
                        programBuilder = null;
                    }
                }
            }

            this.vertexArrayObject        = (GlVertexArrayObject <Vertex>) this.vertexArrayObjectBuilder.Build();
            this.vertexArrayObjectBuilder = null;
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrimitiveRenderer"/> class.
        /// </summary>
        /// <param name="camera">Provider for view and projection matrices.</param>
        /// <param name="source">Source data. Outer sequence pushes different renderable entities, each of which pushes each time its state changes.</param>
        /// <param name="capacity">The maximum number of triangles and lines that can be rendered at once.</param>
        public PrimitiveRenderer(
            IViewProjection camera,
            IObservable <IObservable <IList <Primitive> > > source,
            int capacity)
        {
            this.camera = camera;
            this.source = source;

            if (program == null && programBuilder == null)
            {
                lock (ProgramStateLock)
                {
                    if (program == null && programBuilder == null)
                    {
                        programBuilder = new GlProgramBuilder()
                                         .WithVertexShaderFromEmbeddedResource("Colored.Vertex.glsl")
                                         .WithFragmentShaderFromEmbeddedResource("Colored.Fragment.glsl")
                                         .WithDefaultUniformBlock <Uniforms>();
                    }
                }
            }

            // Re-use a single vertex list for every primitive to reduce GC burden - NB not re-entrant
            var triangleVertexList = new List <PrimitiveVertex>();

            this.coloredTriangleBufferBuilder = new ReactiveBufferBuilder <PrimitiveVertex>(
                PrimitiveType.Triangles,
                capacity,
                new[] { 0, 1, 2 },
                this.source.Select(pso => pso.Select(ps =>
            {
                triangleVertexList.Clear();
                for (int i = 0; i < ps.Count; i++)
                {
                    if (ps[i].IsTrianglePrimitive)
                    {
                        triangleVertexList.AddRange(ps[i].Vertices);
                    }
                }

                return(triangleVertexList);
            })));

            // Re-use a single vertex list for every primitive to reduce GC burden - NB not re-entrant
            var lineVertexList = new List <PrimitiveVertex>();

            this.coloredLineBufferBuilder = new ReactiveBufferBuilder <PrimitiveVertex>(
                PrimitiveType.Lines,
                capacity,
                new[] { 0, 1 },
                this.source.Select(pso => pso.Select(ps =>
            {
                lineVertexList.Clear();
                for (int i = 0; i < ps.Count; i++)
                {
                    if (!ps[i].IsTrianglePrimitive)
                    {
                        lineVertexList.AddRange(ps[i].Vertices);
                    }
                }

                return(lineVertexList);
            })));
        }