/// <summary>
        /// Creates a new <see cref="GLHardwareRenderer"/> that will use the specified <see cref="IRenderStrategy"/>
        /// to render the contents of the libretro core's framebuffer to the specified <see cref="IRenderContext"/>.
        /// </summary>
        /// <param name="renderStrategy">The render strategy to use to render to the <paramref name="frontendContext"/>.</param>
        /// <param name="frontendContext">The render context to render to.</param>
        public GLHardwareRenderer(IRenderStrategy renderStrategy, IRenderContext frontendContext)
        {
            // We can't reference the GetCurrentFramebuffer method from a field initializer, so need to set it here
            _getCurrentFramebufferDlgt = new retro_hw_get_current_framebuffer_t(GetCurrentFramebuffer);

            _renderStrategy  = renderStrategy;
            _frontendContext = frontendContext;
        }
Esempio n. 2
0
        public bool Init()
        {
            if (!glfwInit())
            {
                return(false);
            }

            glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
            glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
            glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
            glfwWindowHint(GLFW_RED_BITS, 8);
            glfwWindowHint(GLFW_GREEN_BITS, 8);
            glfwWindowHint(GLFW_BLUE_BITS, 8);
            glfwWindowHint(GLFW_ALPHA_BITS, 8);
            glfwWindowHint(GLFW_DEPTH_BITS, 24);
            glfwWindowHint(GLFW_STENCIL_BITS, 8);
            glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
            glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
            glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE);
            glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);

            _windowHandle = glfwCreateWindow(800, 600, "LibretroOpenGLHelperWindow", IntPtr.Zero, IntPtr.Zero);
            if (_windowHandle == IntPtr.Zero)
            {
                glfwTerminate();
                return(false);
            }

            glfwMakeContextCurrent(_windowHandle);

            glReadPixels = Marshal.GetDelegateForFunctionPointer <glReadPixels_f>(glfwGetProcAddress("glReadPixels"));
            if (glReadPixels == null)
            {
                glfwTerminate();
                return(false);
            }

            GetCurrentFrameBufferCallback = GetCurrentFrameBuffer;
            GetProcAddressCallback        = GetProcAddress;

            return(true);
        }