Beispiel #1
0
        public static void Initialize()
        {
            // glGetError and glGetString are used in our error handlers
            // so we want these to be available early.
            openGLDebugDelegate = OpenGLDebugCallback;
            try
            {
                glGetError          = Bind <GetError>("glGetError");
                glGetStringInternal = Bind <GetString>("glGetString");
            }
            catch (Exception)
            {
                throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available");
            }


            DetectGLFeatures();
            if (!Features.HasFlag(GLFeatures.GL2OrGreater) || !Features.HasFlag(GLFeatures.FramebufferExt))
            {
                WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION));
                throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details.");
            }
            else
            {
                Console.WriteLine("OpenGL version: " + glGetString(GL_VERSION));
            }

            try
            {
                glDeleteProgram        = Bind <DeleteProgramDelegate>("glDeleteProgram");
                glDeleteShader         = Bind <DeleteShaderDelegate>("glDeleteShader");
                glDetachShader         = Bind <DetachShaderDelegate>("glDetachShader");
                glDebugMessageControl  = Bind <glDebugMessageControlDelegate>("glDebugMessageControl");
                glDebugMessageCallback = Bind <glDebugMessageCallbackDelegate>("glDebugMessageCallback");
                glDebugMessageCallback(openGLDebugDelegate, IntPtr.Zero);
                glDebugMessageControl(DebugSourceControl.GL_DONT_CARE, DebugTypeControl.GL_DONT_CARE, DebugSeverityControl.GL_DEBUG_SEVERITY_LOW, 0, new uint[0], true);

                glGenVertexArrays          = Bind <glGenVertexArraysDeleagte>("glGenVertexArrays");
                glBindVertexArray          = Bind <glBindVertexArrayDelegate>("glBindVertexArray");
                glFlush                    = Bind <Flush>("glFlush");
                glViewport                 = Bind <Viewport>("glViewport");
                glClear                    = Bind <Clear>("glClear");
                glClearColor               = Bind <ClearColor>("glClearColor");
                glGetIntegerv              = Bind <GetIntegerv>("glGetIntegerv");
                glFinish                   = Bind <Finish>("glFinish");
                glCreateProgram            = Bind <CreateProgram>("glCreateProgram");
                glUseProgram               = Bind <UseProgram>("glUseProgram");
                glGetProgramiv             = Bind <GetProgramiv>("glGetProgramiv");
                glCreateShader             = Bind <CreateShader>("glCreateShader");
                glShaderSource             = Bind <ShaderSource>("glShaderSource");
                glCompileShader            = Bind <CompileShader>("glCompileShader");
                glGetShaderiv              = Bind <GetShaderiv>("glGetShaderiv");
                glAttachShader             = Bind <AttachShader>("glAttachShader");
                glGetShaderInfoLog         = Bind <GetShaderInfoLog>("glGetShaderInfoLog");
                glLinkProgram              = Bind <LinkProgram>("glLinkProgram");
                glGetProgramInfoLog        = Bind <GetProgramInfoLog>("glGetProgramInfoLog");
                glGetUniformLocation       = Bind <GetUniformLocation>("glGetUniformLocation");
                glGetActiveUniform         = Bind <GetActiveUniform>("glGetActiveUniform");
                glUniform1i                = Bind <Uniform1i>("glUniform1i");
                glUniform1f                = Bind <Uniform1f>("glUniform1f");
                glUniform2f                = Bind <Uniform2f>("glUniform2f");
                glUniform3f                = Bind <Uniform3f>("glUniform3f");
                glUniform1fv               = Bind <Uniform1fv>("glUniform1fv");
                glUniform2fv               = Bind <Uniform2fv>("glUniform2fv");
                glUniform3fv               = Bind <Uniform3fv>("glUniform3fv");
                glUniform4fv               = Bind <Uniform4fv>("glUniform4fv");
                glUniformMatrix4fv         = Bind <UniformMatrix4fv>("glUniformMatrix4fv");
                glGenBuffers               = Bind <GenBuffers>("glGenBuffers");
                glBindBuffer               = Bind <BindBuffer>("glBindBuffer");
                glBufferData               = Bind <BufferData>("glBufferData");
                glBufferSubData            = Bind <BufferSubData>("glBufferSubData");
                glDeleteBuffers            = Bind <DeleteBuffers>("glDeleteBuffers");
                glBindAttribLocation       = Bind <BindAttribLocation>("glBindAttribLocation");
                glVertexAttribPointer      = Bind <VertexAttribPointer>("glVertexAttribPointer");
                glEnableVertexAttribArray  = Bind <EnableVertexAttribArray>("glEnableVertexAttribArray");
                glDisableVertexAttribArray = Bind <DisableVertexAttribArray>("glDisableVertexAttribArray");
                glDrawArrays               = Bind <DrawArrays>("glDrawArrays");
                glEnable                   = Bind <Enable>("glEnable");
                glDisable                  = Bind <Disable>("glDisable");
                glBlendEquation            = Bind <BlendEquation>("glBlendEquation");
                glBlendFunc                = Bind <BlendFunc>("glBlendFunc");
                glDepthFunc                = Bind <DepthFunc>("glDepthFunc");
                glScissor                  = Bind <Scissor>("glScissor");
                glPushClientAttrib         = Bind <PushClientAttrib>("glPushClientAttrib");
                glPopClientAttrib          = Bind <PopClientAttrib>("glPopClientAttrib");
                glPixelStoref              = Bind <PixelStoref>("glPixelStoref");
                glReadPixels               = Bind <ReadPixels>("glReadPixels");
                glGenTextures              = Bind <GenTextures>("glGenTextures");
                glDeleteTextures           = Bind <DeleteTextures>("glDeleteTextures");
                glBindTexture              = Bind <BindTexture>("glBindTexture");
                glActiveTexture            = Bind <ActiveTexture>("glActiveTexture");
                glTexImage2D               = Bind <TexImage2D>("glTexImage2D");
                glTexSubImage3D            = Bind <TexSubImage3D>("glTexSubImage3D");
                glTexImage3D               = Bind <TexImage3D>("glTexImage3D");
                glGetTexImage              = Bind <GetTexImage>("glGetTexImage");
                glTexParameteri            = Bind <TexParameteri>("glTexParameteri");
                glTexParameterf            = Bind <TexParameterf>("glTexParameterf");
                glGenFramebuffers          = Bind <GenFramebuffers>("glGenFramebuffersEXT");
                glBindFramebuffer          = Bind <BindFramebuffer>("glBindFramebufferEXT");
                glFramebufferTexture2D     = Bind <FramebufferTexture2D>("glFramebufferTexture2DEXT");
                glDeleteFramebuffers       = Bind <DeleteFramebuffers>("glDeleteFramebuffersEXT");
                glGenRenderbuffers         = Bind <GenRenderbuffers>("glGenRenderbuffersEXT");
                glBindRenderbuffer         = Bind <BindRenderbuffer>("glBindRenderbufferEXT");
                glRenderbufferStorage      = Bind <RenderbufferStorage>("glRenderbufferStorageEXT");
                glDeleteRenderbuffers      = Bind <DeleteRenderbuffers>("glDeleteRenderbuffersEXT");
                glFramebufferRenderbuffer  = Bind <FramebufferRenderbuffer>("glFramebufferRenderbufferEXT");
                glCheckFramebufferStatus   = Bind <CheckFramebufferStatus>("glCheckFramebufferStatusEXT");
            }
            catch (Exception e)
            {
                WriteGraphicsLog("Failed to initialize OpenGL bindings.\nInner exception was: {0}".F(e));
                throw new InvalidProgramException("Failed to initialize OpenGL. See graphics.log for details.");
            }

            glEnable(GL_DEBUG_OUTPUT);
            glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
        }
 static void OpenGLNativeVERSION_2_0Init()
 {
     _BlendEquationSeparate = GetProcAdress< BlendEquationSeparateDelegate >( "glBlendEquationSeparate" );
     _DrawBuffers = GetProcAdress< DrawBuffersDelegate >( "glDrawBuffers" );
     _StencilOpSeparate = GetProcAdress< StencilOpSeparateDelegate >( "glStencilOpSeparate" );
     _StencilFuncSeparate = GetProcAdress< StencilFuncSeparateDelegate >( "glStencilFuncSeparate" );
     _StencilMaskSeparate = GetProcAdress< StencilMaskSeparateDelegate >( "glStencilMaskSeparate" );
     _AttachShader = GetProcAdress< AttachShaderDelegate >( "glAttachShader" );
     _BindAttribLocation = GetProcAdress< BindAttribLocationDelegate >( "glBindAttribLocation" );
     _CompileShader = GetProcAdress< CompileShaderDelegate >( "glCompileShader" );
     _CreateProgram = GetProcAdress< CreateProgramDelegate >( "glCreateProgram" );
     _CreateShader = GetProcAdress< CreateShaderDelegate >( "glCreateShader" );
     _DeleteProgram = GetProcAdress< DeleteProgramDelegate >( "glDeleteProgram" );
     _DeleteShader = GetProcAdress< DeleteShaderDelegate >( "glDeleteShader" );
     _DetachShader = GetProcAdress< DetachShaderDelegate >( "glDetachShader" );
     _DisableVertexAttribArray = GetProcAdress< DisableVertexAttribArrayDelegate >( "glDisableVertexAttribArray" );
     _EnableVertexAttribArray = GetProcAdress< EnableVertexAttribArrayDelegate >( "glEnableVertexAttribArray" );
     _GetActiveAttrib = GetProcAdress< GetActiveAttribDelegate >( "glGetActiveAttrib" );
     _GetActiveUniform = GetProcAdress< GetActiveUniformDelegate >( "glGetActiveUniform" );
     _GetAttachedShaders = GetProcAdress< GetAttachedShadersDelegate >( "glGetAttachedShaders" );
     _GetAttribLocation = GetProcAdress< GetAttribLocationDelegate >( "glGetAttribLocation" );
     _GetProgramiv = GetProcAdress< GetProgramivDelegate >( "glGetProgramiv" );
     _GetProgramInfoLog = GetProcAdress< GetProgramInfoLogDelegate >( "glGetProgramInfoLog" );
     _GetShaderiv = GetProcAdress< GetShaderivDelegate >( "glGetShaderiv" );
     _GetShaderInfoLog = GetProcAdress< GetShaderInfoLogDelegate >( "glGetShaderInfoLog" );
     _GetShaderSource = GetProcAdress< GetShaderSourceDelegate >( "glGetShaderSource" );
     _GetUniformLocation = GetProcAdress< GetUniformLocationDelegate >( "glGetUniformLocation" );
     _GetUniformfv = GetProcAdress< GetUniformfvDelegate >( "glGetUniformfv" );
     _GetUniformiv = GetProcAdress< GetUniformivDelegate >( "glGetUniformiv" );
     _GetVertexAttribdv = GetProcAdress< GetVertexAttribdvDelegate >( "glGetVertexAttribdv" );
     _GetVertexAttribfv = GetProcAdress< GetVertexAttribfvDelegate >( "glGetVertexAttribfv" );
     _GetVertexAttribiv = GetProcAdress< GetVertexAttribivDelegate >( "glGetVertexAttribiv" );
     _GetVertexAttribPointerv = GetProcAdress< GetVertexAttribPointervDelegate >( "glGetVertexAttribPointerv" );
     _IsProgram = GetProcAdress< IsProgramDelegate >( "glIsProgram" );
     _IsShader = GetProcAdress< IsShaderDelegate >( "glIsShader" );
     _LinkProgram = GetProcAdress< LinkProgramDelegate >( "glLinkProgram" );
     _ShaderSource = GetProcAdress< ShaderSourceDelegate >( "glShaderSource" );
     _UseProgram = GetProcAdress< UseProgramDelegate >( "glUseProgram" );
     _Uniform1f = GetProcAdress< Uniform1fDelegate >( "glUniform1f" );
     _Uniform2f = GetProcAdress< Uniform2fDelegate >( "glUniform2f" );
     _Uniform3f = GetProcAdress< Uniform3fDelegate >( "glUniform3f" );
     _Uniform4f = GetProcAdress< Uniform4fDelegate >( "glUniform4f" );
     _Uniform1i = GetProcAdress< Uniform1iDelegate >( "glUniform1i" );
     _Uniform2i = GetProcAdress< Uniform2iDelegate >( "glUniform2i" );
     _Uniform3i = GetProcAdress< Uniform3iDelegate >( "glUniform3i" );
     _Uniform4i = GetProcAdress< Uniform4iDelegate >( "glUniform4i" );
     _Uniform1fv = GetProcAdress< Uniform1fvDelegate >( "glUniform1fv" );
     _Uniform2fv = GetProcAdress< Uniform2fvDelegate >( "glUniform2fv" );
     _Uniform3fv = GetProcAdress< Uniform3fvDelegate >( "glUniform3fv" );
     _Uniform4fv = GetProcAdress< Uniform4fvDelegate >( "glUniform4fv" );
     _Uniform1iv = GetProcAdress< Uniform1ivDelegate >( "glUniform1iv" );
     _Uniform2iv = GetProcAdress< Uniform2ivDelegate >( "glUniform2iv" );
     _Uniform3iv = GetProcAdress< Uniform3ivDelegate >( "glUniform3iv" );
     _Uniform4iv = GetProcAdress< Uniform4ivDelegate >( "glUniform4iv" );
     _UniformMatrix2fv = GetProcAdress< UniformMatrix2fvDelegate >( "glUniformMatrix2fv" );
     _UniformMatrix3fv = GetProcAdress< UniformMatrix3fvDelegate >( "glUniformMatrix3fv" );
     _UniformMatrix4fv = GetProcAdress< UniformMatrix4fvDelegate >( "glUniformMatrix4fv" );
     _ValidateProgram = GetProcAdress< ValidateProgramDelegate >( "glValidateProgram" );
     _VertexAttrib1d = GetProcAdress< VertexAttrib1dDelegate >( "glVertexAttrib1d" );
     _VertexAttrib1dv = GetProcAdress< VertexAttrib1dvDelegate >( "glVertexAttrib1dv" );
     _VertexAttrib1f = GetProcAdress< VertexAttrib1fDelegate >( "glVertexAttrib1f" );
     _VertexAttrib1fv = GetProcAdress< VertexAttrib1fvDelegate >( "glVertexAttrib1fv" );
     _VertexAttrib1s = GetProcAdress< VertexAttrib1sDelegate >( "glVertexAttrib1s" );
     _VertexAttrib1sv = GetProcAdress< VertexAttrib1svDelegate >( "glVertexAttrib1sv" );
     _VertexAttrib2d = GetProcAdress< VertexAttrib2dDelegate >( "glVertexAttrib2d" );
     _VertexAttrib2dv = GetProcAdress< VertexAttrib2dvDelegate >( "glVertexAttrib2dv" );
     _VertexAttrib2f = GetProcAdress< VertexAttrib2fDelegate >( "glVertexAttrib2f" );
     _VertexAttrib2fv = GetProcAdress< VertexAttrib2fvDelegate >( "glVertexAttrib2fv" );
     _VertexAttrib2s = GetProcAdress< VertexAttrib2sDelegate >( "glVertexAttrib2s" );
     _VertexAttrib2sv = GetProcAdress< VertexAttrib2svDelegate >( "glVertexAttrib2sv" );
     _VertexAttrib3d = GetProcAdress< VertexAttrib3dDelegate >( "glVertexAttrib3d" );
     _VertexAttrib3dv = GetProcAdress< VertexAttrib3dvDelegate >( "glVertexAttrib3dv" );
     _VertexAttrib3f = GetProcAdress< VertexAttrib3fDelegate >( "glVertexAttrib3f" );
     _VertexAttrib3fv = GetProcAdress< VertexAttrib3fvDelegate >( "glVertexAttrib3fv" );
     _VertexAttrib3s = GetProcAdress< VertexAttrib3sDelegate >( "glVertexAttrib3s" );
     _VertexAttrib3sv = GetProcAdress< VertexAttrib3svDelegate >( "glVertexAttrib3sv" );
     _VertexAttrib4Nbv = GetProcAdress< VertexAttrib4NbvDelegate >( "glVertexAttrib4Nbv" );
     _VertexAttrib4Niv = GetProcAdress< VertexAttrib4NivDelegate >( "glVertexAttrib4Niv" );
     _VertexAttrib4Nsv = GetProcAdress< VertexAttrib4NsvDelegate >( "glVertexAttrib4Nsv" );
     _VertexAttrib4Nub = GetProcAdress< VertexAttrib4NubDelegate >( "glVertexAttrib4Nub" );
     _VertexAttrib4Nubv = GetProcAdress< VertexAttrib4NubvDelegate >( "glVertexAttrib4Nubv" );
     _VertexAttrib4Nuiv = GetProcAdress< VertexAttrib4NuivDelegate >( "glVertexAttrib4Nuiv" );
     _VertexAttrib4Nusv = GetProcAdress< VertexAttrib4NusvDelegate >( "glVertexAttrib4Nusv" );
     _VertexAttrib4bv = GetProcAdress< VertexAttrib4bvDelegate >( "glVertexAttrib4bv" );
     _VertexAttrib4d = GetProcAdress< VertexAttrib4dDelegate >( "glVertexAttrib4d" );
     _VertexAttrib4dv = GetProcAdress< VertexAttrib4dvDelegate >( "glVertexAttrib4dv" );
     _VertexAttrib4f = GetProcAdress< VertexAttrib4fDelegate >( "glVertexAttrib4f" );
     _VertexAttrib4fv = GetProcAdress< VertexAttrib4fvDelegate >( "glVertexAttrib4fv" );
     _VertexAttrib4iv = GetProcAdress< VertexAttrib4ivDelegate >( "glVertexAttrib4iv" );
     _VertexAttrib4s = GetProcAdress< VertexAttrib4sDelegate >( "glVertexAttrib4s" );
     _VertexAttrib4sv = GetProcAdress< VertexAttrib4svDelegate >( "glVertexAttrib4sv" );
     _VertexAttrib4ubv = GetProcAdress< VertexAttrib4ubvDelegate >( "glVertexAttrib4ubv" );
     _VertexAttrib4uiv = GetProcAdress< VertexAttrib4uivDelegate >( "glVertexAttrib4uiv" );
     _VertexAttrib4usv = GetProcAdress< VertexAttrib4usvDelegate >( "glVertexAttrib4usv" );
     _VertexAttribPointer = GetProcAdress< VertexAttribPointerDelegate >( "glVertexAttribPointer" );
 }