Beispiel #1
0
        public OpenGLESRenderContext(Window window, OpenGLPlatformContextInfo platformContext)
        {
            ResourceFactory    = new OpenGLESResourceFactory();
            RenderCapabilities = new RenderCapabilities(false, false);
            _swapBufferFunc    = platformContext.SwapBuffer;
            GraphicsContext.GetAddressDelegate        getAddressFunc        = s => platformContext.GetProcAddress(s);
            GraphicsContext.GetCurrentContextDelegate getCurrentContextFunc = () => new ContextHandle(platformContext.GetCurrentContext());
            _openGLGraphicsContext = new GraphicsContext(new ContextHandle(platformContext.ContextHandle), getAddressFunc, getCurrentContextFunc);

            _openGLGraphicsContext.LoadAll();

            _defaultFramebuffer = new OpenGLESDefaultFramebuffer(window.Width, window.Height);
            OnWindowResized(window.Width, window.Height);

            _textureSamplerManager = new OpenGLESTextureSamplerManager();

            _maxConstantBufferSlots = GL.GetInteger(GetPName.MaxUniformBufferBindings);
            Utilities.CheckLastGLES3Error();
            _constantBuffersBySlot    = new OpenGLESConstantBuffer[_maxConstantBufferSlots];
            _newConstantBuffersBySlot = new OpenGLESConstantBuffer[_maxConstantBufferSlots];

            SetInitialStates();

            PostContextCreated();
        }
Beispiel #2
0
        private static OpenGLESRenderContext CreateDefaultOpenGLESRenderContext(Sdl2Window window)
        {
            bool debugContext = false;

            debugContext |= s_allowDebugContexts;

            if (debugContext)
            {
                Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextFlags, (int)SDL_GLContextFlag.Debug);
            }

            IntPtr sdlHandle = window.SdlWindowHandle;

            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextProfileMask, (int)SDL_GLProfile.ES);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMajorVersion, 3);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMinorVersion, 0);
            IntPtr contextHandle = Sdl2Native.SDL_GL_CreateContext(sdlHandle);

            Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, contextHandle);

            if (contextHandle == IntPtr.Zero)
            {
                unsafe
                {
                    byte * error       = Sdl2Native.SDL_GetError();
                    string errorString = Utilities.GetString(error);
                    throw new InvalidOperationException("Unable to create GL Context: " + errorString);
                }
            }

            Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, contextHandle);
            OpenGLPlatformContextInfo ci = new OpenGLPlatformContextInfo(
                contextHandle,
                Sdl2Native.SDL_GL_GetProcAddress,
                Sdl2Native.SDL_GL_GetCurrentContext,
                () => Sdl2Native.SDL_GL_SwapWindow(sdlHandle));
            var rc = new OpenGLESRenderContext(window, ci);

            if (debugContext)
            {
                rc.EnableDebugCallback(OpenTK.Graphics.ES30.DebugSeverity.DebugSeverityNotification);
            }
            return(rc);
        }
        public OpenGLRenderContext(Window window, OpenGLPlatformContextInfo platformContext)
        {
            _resourceFactory   = new OpenGLResourceFactory();
            RenderCapabilities = new RenderCapabilities(true, true);
            _swapBufferFunc    = platformContext.SwapBuffer;
            GraphicsContext.GetAddressDelegate        getAddressFunc        = s => platformContext.GetProcAddress(s);
            GraphicsContext.GetCurrentContextDelegate getCurrentContextFunc = () => new ContextHandle(platformContext.GetCurrentContext());
            _openGLGraphicsContext = new GraphicsContext(new ContextHandle(platformContext.ContextHandle), getAddressFunc, getCurrentContextFunc);

            _openGLGraphicsContext.LoadAll();

            // NOTE: I am binding a single VAO globally.
            _vertexArrayID = GL.GenVertexArray();
            GL.BindVertexArray(_vertexArrayID);

            _defaultFramebuffer = new OpenGLDefaultFramebuffer(window.Width, window.Height);
            OnWindowResized(window.Width, window.Height);

            SetInitialStates();

            PostContextCreated();

            int extensionCount          = GL.GetInteger(GetPName.NumExtensions);
            HashSet <string> extensions = new HashSet <string>();

            for (int i = 0; i < extensionCount; i++)
            {
                extensions.Add(GL.GetString(StringNameIndexed.Extensions, i));
            }
            _extensions = new OpenGLExtensions(extensions);

            _textureSamplerManager = new OpenGLTextureSamplerManager(_extensions);

            _maxConstantBufferSlots   = GL.GetInteger(GetPName.MaxUniformBufferBindings);
            _constantBuffersBySlot    = new OpenGLConstantBuffer[_maxConstantBufferSlots];
            _newConstantBuffersBySlot = new OpenGLConstantBuffer[_maxConstantBufferSlots];

            _maxTextureUnits = GL.GetInteger(GetPName.MaxTextureImageUnits);

            _maxVertexAttributeSlots = GL.GetInteger(GetPName.MaxVertexAttribs);
            _vertexAttribDivisors    = new int[_maxVertexAttributeSlots];
        }
Beispiel #4
0
        private static OpenGLRenderContext CreateDefaultOpenGLRenderContext(Sdl2Window window)
        {
            bool debugContext = false;

#if DEBUG
            debugContext = Preferences.Instance.AllowOpenGLDebugContexts;
#endif
            IntPtr sdlHandle = window.SdlWindowHandle;
            if (debugContext)
            {
                Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextFlags, (int)SDL_GLContextFlag.Debug);
            }

            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextProfileMask, (int)SDL_GLProfile.Core);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMajorVersion, 4);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMinorVersion, 0);

            IntPtr contextHandle = Sdl2Native.SDL_GL_CreateContext(sdlHandle);
            if (contextHandle == IntPtr.Zero)
            {
                unsafe
                {
                    byte * error       = Sdl2Native.SDL_GetError();
                    string errorString = Utilities.GetString(error);
                    throw new InvalidOperationException("Unable to create GL Context: " + errorString);
                }
            }

            Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, contextHandle);
            OpenGLPlatformContextInfo ci = new OpenGLPlatformContextInfo(
                contextHandle,
                Sdl2Native.SDL_GL_GetProcAddress,
                Sdl2Native.SDL_GL_GetCurrentContext,
                () => Sdl2Native.SDL_GL_SwapWindow(sdlHandle));
            var rc = new OpenGLRenderContext(window, ci);
            if (debugContext)
            {
                // Slows things down significantly -- Only use when debugging something specific.
                rc.EnableDebugCallback(OpenTK.Graphics.OpenGL.DebugSeverity.DebugSeverityNotification);
            }
            return(rc);
        }