Exemplo n.º 1
0
 public OpenGLTextureSamplerManager(OpenGLExtensions extensions)
 {
     _dsaAvailable        = extensions.ARB_DirectStateAccess;
     _maxTextureUnits     = GL.GetInteger(GetPName.MaxCombinedTextureImageUnits);
     _maxTextureUnits     = Math.Max(_maxTextureUnits, 8); // OpenGL spec indicates that implementations must support at least 8.
     _textureUnitTextures = new OpenGLTextureBinding[_maxTextureUnits];
     _textureUnitSamplers = new BoundSamplerStateInfo[_maxTextureUnits];
 }
        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];
        }