Beispiel #1
0
        /// <summary> Sets appropriate uniforms in the lighting shader using the stored next light ID, and increments the ID.
        /// <br/> !! Warning !! This means that the lighting uniform IDs are not ensured to be consistent from frame to frame!</summary>
        public override void DrawSelf()
        {
            if (Game.CurrentShader != Game.LightingShader)
            {
                return;
            }
            ShaderProgramLighting shader = Game.LightingShader;

            shader.SetLightUniform(shader.NextLightID, Strength, Position, Color, Direction);
            shader.NextLightID++;
        }
Beispiel #2
0
        /// <summary> Handles all graphics setup processing: creates shader program, drawables, sets flags, sets attribs.
        /// <br/> THREAD: OpenGL </summary>
        protected override void OnRenderThreadStarted()
        {
            Console.WriteLine("OnRenderThreadStarted(): start");

            // Misc GL flags and callbacks
            debugCallbackHandle = GCHandle.Alloc(debugCallback);
            GL.DebugMessageCallback(debugCallback, IntPtr.Zero);
            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DebugOutputSynchronous);
            GL.Enable(EnableCap.DepthTest);
            VSync = VSyncMode.Off;             // On seems to break?

            InterfaceShader = new ShaderProgramInterface(ShaderProgram.CreateShaderFromUnified("src/InterfaceShader.glsl")).use();
            GeometryShader  = new ShaderProgramGeometry(ShaderProgram.CreateShaderFromUnified("src/GeometryShader.glsl")).use();
            LightingShader  = new ShaderProgramLighting(ShaderProgram.CreateShaderFromUnified("src/LightingShader.glsl")).use();

            // Framebuffer setup for the geometry buffer
            FramebufferGeometry = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FramebufferGeometry);
            FramebufferTextures = new Texture[] {
                new Texture(0, GL.GetUniformLocation(LightingShader.ShaderProgram_ID, "gPosition")),
                new Texture(1, GL.GetUniformLocation(LightingShader.ShaderProgram_ID, "gNormal")),
                new Texture(2, GL.GetUniformLocation(LightingShader.ShaderProgram_ID, "gAlbedoSpec")),
            };
            int depth = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, depth);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent24, Game.WindowSize.X, Game.WindowSize.Y,
                          0, PixelFormat.DepthComponent, PixelType.UnsignedByte, new byte[0]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment,
                                    TextureTarget.Texture2D, depth, 0);
            DrawBuffersEnum[] attachments = new DrawBuffersEnum[FramebufferTextures.Length];
            for (int i = 0; i < attachments.Length; i++)
            {
                attachments[i] = DrawBuffersEnum.ColorAttachment0 + i;
            }
            GL.DrawBuffers(attachments.Length, attachments);

            SceneRoot      = DemoBuilder.BuildDemoScene_TextureTest();
            InterfaceRoot  = DemoBuilder.BuildDemoInterface_IngameTest();
            BackgroundRoot = DemoBuilder.BuildDemoInterface_BackgroundTest();

            // Interface VAO setup
            GL.BindVertexArray(InterfaceShader.VertexArrayObject_ID);
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0 * sizeof(float));             /* xy */
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float));             /* uv */

            // Geometry VAO setup
            GL.BindVertexArray(GeometryShader.VertexArrayObject_ID);
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);
            GL.EnableVertexAttribArray(3);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 12 * sizeof(float), 0 * sizeof(float));             /* xyz  */
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 12 * sizeof(float), 3 * sizeof(float));             /* uv   */
            GL.VertexAttribPointer(2, 4, VertexAttribPointerType.Float, false, 12 * sizeof(float), 5 * sizeof(float));             /* rgba */
            GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, 12 * sizeof(float), 9 * sizeof(float));             /* normal */

            Console.WriteLine("OnRenderThreadStarted(): end");
        }