Пример #1
0
        /// <summary>
        /// Creates a cached shader for the specifed shader, using the specified shader enumeration
        /// as a lookup key.
        /// </summary>
        private ShaderProgram CreateCachedShader(EverlookShader shader)
        {
            if (!Enum.IsDefined(typeof(EverlookShader), shader))
            {
                throw new ArgumentException("An unknown shader was passed to the rendering cache.", nameof(shader));
            }

            Log.Info($"Creating cached shader for \"{shader}\"");

            ShaderProgram shaderProgram;

            switch (shader)
            {
            case EverlookShader.Plain2D:
            {
                shaderProgram = new Plain2DShader();
                break;
            }

            case EverlookShader.WorldModel:
            {
                shaderProgram = new WorldModelShader();
                break;
            }

            case EverlookShader.BoundingBox:
            {
                shaderProgram = new BoundingBoxShader();
                break;
            }

            case EverlookShader.GameModel:
            {
                shaderProgram = new GameModelShader();
                break;
            }

            case EverlookShader.BaseGrid:
            {
                shaderProgram = new BaseGridShader();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException
                      (
                          nameof(shader),
                          "No implemented shader class for this shader."
                      );
            }
            }

            _shaderCache.Add(shader, shaderProgram);
            return(shaderProgram);
        }
Пример #2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="RenderableBoundingBox"/> class. The bounds data is taken from
		/// the given <see cref="Box"/>, and the world translation is set to <paramref name="transform"/>.
		/// </summary>
		/// <param name="boundingBox">The BoundingBox to get data from.</param>
		/// <param name="transform">The world transform of the box.</param>
		public RenderableBoundingBox(Box boundingBox, Transform transform)
		{
			this.BoundingBoxData = boundingBox;
			this.LineColour = Color4.LimeGreen;

			this.ActorTransform = transform;
			this.BoxShader = RenderCache.Instance.GetShader(EverlookShader.BoundingBox) as BoundingBoxShader;

			this.IsInitialized = false;
		}
Пример #3
0
        private void RenderBoundingBox(ModelGroup modelGroup, Matrix4 modelViewProjection, Color4 colour)
        {
            BoundingBoxShader boxShader = this.Cache.GetShader(EverlookShader.BoundingBox) as BoundingBoxShader;

            if (boxShader == null)
            {
                throw new ShaderNullException(typeof(BoundingBoxShader));
            }

            boxShader.Enable();
            boxShader.SetMVPMatrix(modelViewProjection);
            boxShader.SetLineColour(colour);

            GL.Disable(EnableCap.CullFace);

            // Render the object
            // Send the vertices to the shader
            GL.EnableVertexAttribArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, this.BoundingBoxVertexBufferLookup[modelGroup]);
            GL.VertexAttribPointer
            (
                0,
                3,
                VertexAttribPointerType.Float,
                false,
                0,
                0
            );

            // Bind the index buffer
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.BoundingBoxVertexIndexBufferID);

            // Now draw the box
            GL.DrawRangeElements
            (
                PrimitiveType.LineLoop,
                0,
                23,
                24,
                DrawElementsType.UnsignedByte,
                new IntPtr(0)
            );

            GL.DisableVertexAttribArray(0);
        }