public GLOmnidirectionalShadowmap()
        {
            Cubemap = GL.GenTexture();

            GL.BindTexture(TextureTarget.TextureCubeMap, Cubemap);

            for (uint i = 0; i < 6; i++)
            {
                GL.TexImage2D((TextureTarget)((uint)TextureTarget.TextureCubeMapPositiveX + i),
                              0, PixelInternalFormat.DepthComponent, SHADOW_WIDTH, SHADOW_HEIGHT, 0,
                              PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero);
            }

            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (uint)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (uint)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (uint)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (uint)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (uint)TextureWrapMode.ClampToEdge);

            GL.CreateFramebuffers(1, out int DepthMapFBO);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, DepthMapFBO);
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment,
                                  Cubemap, 0);

            // We dc abt the colour data
            GL.DrawBuffer(DrawBufferMode.None);
            GL.ReadBuffer(ReadBufferMode.None);

            var vsource = File.ReadAllText("EngineResources/Shaders/Shading/shadow_omnidir.vert");
            var fsource = File.ReadAllText("EngineResources/Shaders/Shading/shadow_omnidir.frag");
            var gsource = File.ReadAllText("EngineResources/Shaders/Shading/shadow_omnidir.geom");

            var vshader = new GLShader(vsource, GLShaderType.Vertex);
            var fshader = new GLShader(fsource, GLShaderType.Fragment);
            var gshader = new GLShader(gsource, GLShaderType.Geometry);

            ShadowShader = new GLShaderProgram()
                           .Attach(vshader)
                           .Attach(fshader)
                           .Attach(gshader)
                           .Label("Omnidirectional Shadowmap Shader")
                           .Link();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); // And unbind
        }
Esempio n. 2
0
 public GLShaderProgram Attach(GLShader shader)
 {
     GL.AttachShader(GLObject, shader.GLObject);
     return(this);
 }
Esempio n. 3
0
        public static unsafe void Initialise()
        {
            GL.LoadBindings(new SDLBindingsContext());

            Context = ImGui.CreateContext();

            ImGui.SetCurrentContext(Context);

            var io = ImGui.GetIO();

            io.DisplaySize.X = Engine.Width;
            io.DisplaySize.Y = Engine.Height;

            io.KeyMap[(int)ImGuiKey.Tab]         = (int)SC.SDL_SCANCODE_TAB;
            io.KeyMap[(int)ImGuiKey.LeftArrow]   = (int)SC.SDL_SCANCODE_LEFT;
            io.KeyMap[(int)ImGuiKey.RightArrow]  = (int)SC.SDL_SCANCODE_RIGHT;
            io.KeyMap[(int)ImGuiKey.UpArrow]     = (int)SC.SDL_SCANCODE_UP;
            io.KeyMap[(int)ImGuiKey.DownArrow]   = (int)SC.SDL_SCANCODE_DOWN;
            io.KeyMap[(int)ImGuiKey.PageUp]      = (int)SC.SDL_SCANCODE_PAGEUP;
            io.KeyMap[(int)ImGuiKey.PageDown]    = (int)SC.SDL_SCANCODE_PAGEDOWN;
            io.KeyMap[(int)ImGuiKey.Home]        = (int)SC.SDL_SCANCODE_HOME;
            io.KeyMap[(int)ImGuiKey.End]         = (int)SC.SDL_SCANCODE_END;
            io.KeyMap[(int)ImGuiKey.Insert]      = (int)SC.SDL_SCANCODE_INSERT;
            io.KeyMap[(int)ImGuiKey.Delete]      = (int)SC.SDL_SCANCODE_DELETE;
            io.KeyMap[(int)ImGuiKey.Backspace]   = (int)SC.SDL_SCANCODE_BACKSPACE;
            io.KeyMap[(int)ImGuiKey.Space]       = (int)SC.SDL_SCANCODE_SPACE;
            io.KeyMap[(int)ImGuiKey.Enter]       = (int)SC.SDL_SCANCODE_RETURN;
            io.KeyMap[(int)ImGuiKey.Escape]      = (int)SC.SDL_SCANCODE_ESCAPE;
            io.KeyMap[(int)ImGuiKey.KeyPadEnter] = (int)SC.SDL_SCANCODE_KP_ENTER;
            io.KeyMap[(int)ImGuiKey.A]           = (int)SC.SDL_SCANCODE_A;
            io.KeyMap[(int)ImGuiKey.C]           = (int)SC.SDL_SCANCODE_C;
            io.KeyMap[(int)ImGuiKey.V]           = (int)SC.SDL_SCANCODE_V;
            io.KeyMap[(int)ImGuiKey.X]           = (int)SC.SDL_SCANCODE_X;
            io.KeyMap[(int)ImGuiKey.Y]           = (int)SC.SDL_SCANCODE_Y;
            io.KeyMap[(int)ImGuiKey.Z]           = (int)SC.SDL_SCANCODE_Z;

            var maj = GL.GetInteger(GetPName.MajorVersion);
            var min = GL.GetInteger(GetPName.MinorVersion);

            Log.Info($"OpenGLManager: This appears to be OpenGL {maj}.{min}.");

            VtxBufSize = 10000;
            IdxBufSize = 2000;

            IG_VAO = new("ImGui");

            IG_VAO.Bind();

            VertexSource = File.ReadAllText("EngineResources/2D.vert");
            FragSource   = File.ReadAllText("EngineResources/standard.frag");

            VS = new GLShader(VertexSource, GLShaderType.VERTEX);
            FS = new GLShader(FragSource, GLShaderType.FRAGMENT);

            VS.Compile();
            FS.Compile();

            ImGuiProgram = new GLShaderProgram().Attach(VS).Attach(FS).Link();

            GLHelper.VertexBuffer("ImGui VBO", out VertexBuffer);
            GLHelper.ElementBuffer("ImGui EBO", out IndexBuffer);

            GL.NamedBufferData(VertexBuffer, VtxBufSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            GL.NamedBufferData(IndexBuffer, IdxBufSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);

            var va = IG_VAO.GLObject;

            GL.VertexArrayVertexBuffer(va, 0, VertexBuffer, IntPtr.Zero, Unsafe.SizeOf <ImDrawVert>());
            GL.VertexArrayElementBuffer(va, IndexBuffer);

            GL.EnableVertexArrayAttrib(va, 0);
            GL.VertexArrayAttribBinding(va, 0, 0);
            GL.VertexArrayAttribFormat(va, 0, 2, VertexAttribType.Float, false, 0);

            GL.EnableVertexArrayAttrib(va, 1);
            GL.VertexArrayAttribBinding(va, 1, 0);
            GL.VertexArrayAttribFormat(va, 1, 2, VertexAttribType.Float, false, 8);

            GL.EnableVertexArrayAttrib(va, 2);
            GL.VertexArrayAttribBinding(va, 2, 0);
            GL.VertexArrayAttribFormat(va, 2, 4, VertexAttribType.UnsignedByte, true, 16);

            Initialised = true;

            OnInitGL?.Invoke();
        }
Esempio n. 4
0
        public static unsafe void Initialise()
        {
            GL.LoadBindings(new SDLBindingsContext());

            Context = ImGui.CreateContext();

            ImGui.SetCurrentContext(Context);

            ImGuizmo.SetImGuiContext(Context);

            var io = ImGui.GetIO();

            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DebugOutputSynchronous);
            GL.DebugMessageCallback(_DebugCb, IntPtr.Zero);

            io.DisplaySize.X = Engine.Width;
            io.DisplaySize.Y = Engine.Height;

            io.KeyMap[(int)ImGuiKey.Tab]         = (int)SC.SDL_SCANCODE_TAB;
            io.KeyMap[(int)ImGuiKey.LeftArrow]   = (int)SC.SDL_SCANCODE_LEFT;
            io.KeyMap[(int)ImGuiKey.RightArrow]  = (int)SC.SDL_SCANCODE_RIGHT;
            io.KeyMap[(int)ImGuiKey.UpArrow]     = (int)SC.SDL_SCANCODE_UP;
            io.KeyMap[(int)ImGuiKey.DownArrow]   = (int)SC.SDL_SCANCODE_DOWN;
            io.KeyMap[(int)ImGuiKey.PageUp]      = (int)SC.SDL_SCANCODE_PAGEUP;
            io.KeyMap[(int)ImGuiKey.PageDown]    = (int)SC.SDL_SCANCODE_PAGEDOWN;
            io.KeyMap[(int)ImGuiKey.Home]        = (int)SC.SDL_SCANCODE_HOME;
            io.KeyMap[(int)ImGuiKey.End]         = (int)SC.SDL_SCANCODE_END;
            io.KeyMap[(int)ImGuiKey.Insert]      = (int)SC.SDL_SCANCODE_INSERT;
            io.KeyMap[(int)ImGuiKey.Delete]      = (int)SC.SDL_SCANCODE_DELETE;
            io.KeyMap[(int)ImGuiKey.Backspace]   = (int)SC.SDL_SCANCODE_BACKSPACE;
            io.KeyMap[(int)ImGuiKey.Space]       = (int)SC.SDL_SCANCODE_SPACE;
            io.KeyMap[(int)ImGuiKey.Enter]       = (int)SC.SDL_SCANCODE_RETURN;
            io.KeyMap[(int)ImGuiKey.Escape]      = (int)SC.SDL_SCANCODE_ESCAPE;
            io.KeyMap[(int)ImGuiKey.KeyPadEnter] = (int)SC.SDL_SCANCODE_KP_ENTER;
            io.KeyMap[(int)ImGuiKey.A]           = (int)SC.SDL_SCANCODE_A;
            io.KeyMap[(int)ImGuiKey.C]           = (int)SC.SDL_SCANCODE_C;
            io.KeyMap[(int)ImGuiKey.V]           = (int)SC.SDL_SCANCODE_V;
            io.KeyMap[(int)ImGuiKey.X]           = (int)SC.SDL_SCANCODE_X;
            io.KeyMap[(int)ImGuiKey.Y]           = (int)SC.SDL_SCANCODE_Y;
            io.KeyMap[(int)ImGuiKey.Z]           = (int)SC.SDL_SCANCODE_Z;

            var maj = GL.GetInteger(GetPName.MajorVersion);
            var min = GL.GetInteger(GetPName.MinorVersion);

            Log.Info($"OpenGLManager: This appears to be OpenGL {maj}.{min}.");

            var t = new GLVersion()
            {
                Major         = maj,
                Minor         = min,
                VersionString = $"{maj}.{min}"
            };

            Version = t;

            if (Version.Major < 4 || (Version.Major == 4 && Version.Minor < 5))
            {
                // This is not OpenGL 4.5 or higher.
                Log.Fatal("This version of OpenGL is too old! Luminal applications require at least GL 4.5.");
                Log.Fatal("Showing message box and exiting.");
                MessageBox.Error("Sorry, applications built with Luminal cannot run on your graphics card.\n" +
                                 $"Your graphics card only supports OpenGL {Version.VersionString}, and at least OpenGL 4.5 is required.",
                                 "Engine incompatible: OpenGL version too old");

                Engine.Quit(1);
            }

            VtxBufSize = 10000;
            IdxBufSize = 2000;

            IG_VAO = new("ImGui");

            IG_VAO.Bind();

            VertexSource = File.ReadAllText("EngineResources/Shaders/2D/2D.vert");
            FragSource   = File.ReadAllText("EngineResources/Shaders/2D/2D.frag");

            VS = new GLShader(VertexSource, GLShaderType.Vertex);
            FS = new GLShader(FragSource, GLShaderType.Fragment);

            VS.Compile();
            FS.Compile();

            ImGuiProgram = new GLShaderProgram().Attach(VS).Attach(FS).Link();

            GLHelper.VertexBuffer("ImGui VBO", out VertexBuffer);
            GLHelper.ElementBuffer("ImGui EBO", out IndexBuffer);

            GL.NamedBufferData(VertexBuffer, VtxBufSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            GL.NamedBufferData(IndexBuffer, IdxBufSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);

            var va = IG_VAO.GLObject;

            GL.VertexArrayVertexBuffer(va, 0, VertexBuffer, IntPtr.Zero, Unsafe.SizeOf <ImDrawVert>());
            GL.VertexArrayElementBuffer(va, IndexBuffer);

            GL.EnableVertexArrayAttrib(va, 0);
            GL.VertexArrayAttribBinding(va, 0, 0);
            GL.VertexArrayAttribFormat(va, 0, 2, VertexAttribType.Float, false, 0);

            GL.EnableVertexArrayAttrib(va, 1);
            GL.VertexArrayAttribBinding(va, 1, 0);
            GL.VertexArrayAttribFormat(va, 1, 2, VertexAttribType.Float, false, 8);

            GL.EnableVertexArrayAttrib(va, 2);
            GL.VertexArrayAttribBinding(va, 2, 0);
            GL.VertexArrayAttribFormat(va, 2, 4, VertexAttribType.UnsignedByte, true, 16);

            _SetClipboard         = SetClipboard;
            io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_SetClipboard);

            _GetClipboard         = GetClipboard;
            io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_GetClipboard);

            Initialised = true;

            OnInitGL?.Invoke();
        }