Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class.
        /// </summary>
        /// <param name="adapter">The graphics adapter.</param>
        /// <param name="graphicsProfile">The graphics profile.</param>
        /// <param name="presentationParameters">The presentation options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="presentationParameters"/> is <see langword="null"/>.
        /// </exception>
        public GraphicsDevice(
            GraphicsAdapter adapter,
            GraphicsProfile graphicsProfile,
            PresentationParameters presentationParameters
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException(nameof(presentationParameters));
            }

            // Set the properties from the constructor parameters.
            Adapter = adapter;
            PresentationParameters = presentationParameters;
            GraphicsProfile        = graphicsProfile;
            PresentationParameters.MultiSampleCount = MathHelper.ClosestMSAAPower(
                PresentationParameters.MultiSampleCount
                );

            // Set up the IGLDevice
            GLDevice = FNAPlatform.CreateGLDevice(PresentationParameters, adapter);

            // The mouse needs to know this for faux-backbuffer mouse scaling.
            Input.Mouse.INTERNAL_BackBufferWidth  = PresentationParameters.BackBufferWidth;
            Input.Mouse.INTERNAL_BackBufferHeight = PresentationParameters.BackBufferHeight;

            // Force set the default render states.
            BlendState        = BlendState.Opaque;
            DepthStencilState = DepthStencilState.Default;
            RasterizerState   = RasterizerState.CullCounterClockwise;

            // Initialize the Texture/Sampler state containers
            int maxTextures       = Math.Min(GLDevice.MaxTextureSlots, MAX_TEXTURE_SAMPLERS);
            int maxVertexTextures = MathHelper.Clamp(
                GLDevice.MaxTextureSlots - MAX_TEXTURE_SAMPLERS,
                0,
                MAX_VERTEXTEXTURE_SAMPLERS
                );

            vertexSamplerStart = GLDevice.MaxTextureSlots - maxVertexTextures;
            Textures           = new TextureCollection(
                maxTextures,
                modifiedSamplers
                );
            SamplerStates = new SamplerStateCollection(
                maxTextures,
                modifiedSamplers
                );
            VertexTextures = new TextureCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );
            VertexSamplerStates = new SamplerStateCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );

            // Set the default viewport and scissor rect.
            Viewport         = new Viewport(PresentationParameters.Bounds);
            ScissorRectangle = Viewport.Bounds;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                FNALoggerEXT.LogError("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                FNALoggerEXT.LogError("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[
                PresentationParameters.BackBufferWidth *
                PresentationParameters.BackBufferHeight *
                4
                            ];
#endif
        }
Пример #2
0
        public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create OpenGL context
            INTERNAL_GLContext = SDL.SDL_GL_CreateContext(Window.Handle);
            OpenTK.Graphics.GraphicsContext.CurrentContext = INTERNAL_GLContext;

#if THREADED_GL
            // Create a background context
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
            Threading.WindowInfo        = Window.Handle;
            Threading.BackgroundContext = new GL_ContextHandle()
            {
                context = SDL.SDL_GL_CreateContext(Window.Handle)
            };

            // Make the foreground context current.
            SDL.SDL_GL_MakeCurrent(Window.Handle, INTERNAL_GLContext);
#endif

            // Set up the OpenGL Device. Loads entry points.
            OpenGLDevice.Initialize();

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[
                OpenGLDevice.Instance.Backbuffer.Width *
                OpenGLDevice.Instance.Backbuffer.Height *
                4
                            ];
#endif
        }
Пример #3
0
 public Material ChangeColor(Illuminance Illuminance)
 {
     return(new Material(ARC.Mul(Illuminance), DRC.Mul(Illuminance), SRC.Mul(Illuminance), Shininess));
 }
Пример #4
0
        public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set any hints to match XNA4 behavior...
            string hint = SDL.SDL_GetHint(SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);

            if (String.IsNullOrEmpty(hint))
            {
                SDL.SDL_SetHint(
                    SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
                    "1"
                    );
            }

            // If available, load the SDL_GameControllerDB
            string mappingsDB = Path.Combine(
                TitleContainer.Location,
                "gamecontrollerdb.txt"
                );

            if (File.Exists(mappingsDB))
            {
                SDL.SDL_GameControllerAddMappingsFromFile(
                    mappingsDB
                    );
            }

            // Set and initialize the SDL2 window
            bool forceES2 = Environment.GetEnvironmentVariable(
                "FNA_OPENGL_FORCE_ES2"
                ) == "1";

            Window = new SDL2_GameWindow(
                forceES2 ||
                OSVersion.Equals("Emscripten") ||
                OSVersion.Equals("Android") ||
                OSVersion.Equals("iOS")
                );

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
                );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
        }
Пример #5
0
        internal SDL2_GameWindow(Game game, SDL2_GamePlatform platform)
        {
            Game = game;

            int startWidth  = GraphicsDeviceManager.DefaultBackBufferWidth;
            int startHeight = GraphicsDeviceManager.DefaultBackBufferHeight;

            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first SDL call we make...
            SDL.SDL_Init(SDL.SDL_INIT_VIDEO);

            INTERNAL_runApplication = true;

            // Initialize Active Key List
            keys = new List <Keys>();

            INTERNAL_sdlWindowFlags_Next = (
                SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL |
                SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN |
                SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS |
                SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS
                );
#if RESIZABLE_WINDOW
            AllowUserResizing = true;
#else
            AllowUserResizing = false;
#endif

            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
#if DEBUG
            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS,
                (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG
                );
#endif

            string title = MonoGame.Utilities.AssemblyHelper.GetDefaultWindowTitle();
            INTERNAL_sdlWindow = SDL.SDL_CreateWindow(
                title,
                SDL.SDL_WINDOWPOS_CENTERED,
                SDL.SDL_WINDOWPOS_CENTERED,
                startWidth,
                startHeight,
                INTERNAL_sdlWindowFlags_Next
                );
            INTERNAL_SetIcon(title);

            INTERNAL_sdlWindowFlags_Current = INTERNAL_sdlWindowFlags_Next;

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (platform.IsMouseVisible)
            {
                platform.IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (platform.OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Initialize OpenGL
            INTERNAL_GLContext = SDL.SDL_GL_CreateContext(INTERNAL_sdlWindow);
            OpenTK.Graphics.GraphicsContext.CurrentContext = INTERNAL_GLContext;

            // Assume we will have focus.
            platform.IsActive = true;

#if THREADED_GL
            // Create a background context
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
            Threading.WindowInfo        = INTERNAL_sdlWindow;
            Threading.BackgroundContext = new GL_ContextHandle()
            {
                context = SDL.SDL_GL_CreateContext(INTERNAL_sdlWindow)
            };

            // Make the foreground context current.
            SDL.SDL_GL_MakeCurrent(INTERNAL_sdlWindow, INTERNAL_GLContext);
#endif

            // Set up the OpenGL Device. Loads entry points.
            new OpenGLDevice();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[startWidth * startHeight * 4];
#endif
        }
Пример #6
0
        public SDL2_GamePlatform(Game game) : base(game, Fna.FnaPlatform.Platform.GetSDLPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
                );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
        }