Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include "stdafx.h"

#include "Headers/WindowManager.h"

#include "Core/Headers/Console.h"
#include "Core/Headers/Application.h"
#include "Core/Headers/Configuration.h"
#include "Core/Headers/PlatformContext.h"
#include "Utility/Headers/Localization.h"
#include "Platform/Video/Headers/GFXDevice.h"

namespace Divide {

WindowManager::WindowManager() : _displayIndex(0),
                                 _activeWindowGUID(-1),
                                 _context(nullptr)
{
    SDL_Init(SDL_INIT_VIDEO);
}

WindowManager::~WindowManager()
{
    MemoryManager::DELETE_VECTOR(_windows);
}

ErrorCode WindowManager::init(PlatformContext& context,
                              RenderAPI api,
                              ResolutionByType initialResolutions,
                              bool startFullScreen,
                              I32 targetDisplayIndex)
{
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
        return ErrorCode::WINDOW_INIT_ERROR;
    }

    _context = &context;

    targetDisplay(std::max(std::min(targetDisplayIndex, SDL_GetNumVideoDisplays() - 1), 0));

    SysInfo& systemInfo = sysInfo();
    SDL_DisplayMode displayMode;
    SDL_GetCurrentDisplayMode(targetDisplay(), &displayMode);
    systemInfo._systemResolutionWidth = displayMode.w;
    systemInfo._systemResolutionHeight = displayMode.h;

    initialResolutions[to_base(WindowType::FULLSCREEN)].set(to_U16(displayMode.w),
                                                                  to_U16(displayMode.h));
    initialResolutions[to_base(WindowType::FULLSCREEN_WINDOWED)].set(to_U16(displayMode.w),
                                                                           to_U16(displayMode.h));

    _windows.emplace_back(MemoryManager_NEW DisplayWindow(*this, context));

    ErrorCode err = initWindow(0,
                               createAPIFlags(api),
                               initialResolutions,
                               startFullScreen,
                               targetDisplayIndex,
                               _context->config().title.c_str());

    if (err == ErrorCode::NO_ERR) {
        setActiveWindow(0);
        GPUState& gState = _context->gfx().gpuState();
        // Query available display modes (resolution, bit depth per channel and
        // refresh rates)
        I32 numberOfDisplayModes = 0;
        I32 numDisplays = SDL_GetNumVideoDisplays();
        for (I32 display = 0; display < numDisplays; ++display) {
            numberOfDisplayModes = SDL_GetNumDisplayModes(display);
            for (I32 mode = 0; mode < numberOfDisplayModes; ++mode) {
                SDL_GetDisplayMode(display, mode, &displayMode);
                // Register the display modes with the GFXDevice object
                GPUState::GPUVideoMode tempDisplayMode;
                for (I32 i = 0; i < numberOfDisplayModes; ++i) {
                    tempDisplayMode._resolution.set(displayMode.w, displayMode.h);
                    tempDisplayMode._bitDepth = SDL_BITSPERPIXEL(displayMode.format);
                    tempDisplayMode._formatName = SDL_GetPixelFormatName(displayMode.format);
                    tempDisplayMode._refreshRate.push_back(to_U8(displayMode.refresh_rate));
                    Util::ReplaceStringInPlace(tempDisplayMode._formatName, "SDL_PIXELFORMAT_", "");
                    gState.registerDisplayMode(to_U8(display), tempDisplayMode);
                    tempDisplayMode._refreshRate.clear();
                }
            }
        }
    }

    return err;
}

void WindowManager::close() {
    for (DisplayWindow* window : _windows) {
        window->destroyWindow();
    }

    SDL_QuitSubSystem(SDL_INIT_VIDEO);
}

ErrorCode WindowManager::initWindow(U32 index,
                                    U32 windowFlags,
                                    const ResolutionByType& initialResolutions,
                                    bool startFullScreen,
                                    I32 targetDisplayIndex,
                                    const char* windowTitle) {
    index = std::min(index, to_U32(_windows.size() - 1));

    return _windows[index]->init(windowFlags,
                                 startFullScreen ? WindowType::FULLSCREEN
                                                 : WindowType::WINDOW,
                                 initialResolutions,
                                 windowTitle);
}

void WindowManager::setActiveWindow(U32 index) {
    index = std::min(index, to_U32(_windows.size() -1));
    _activeWindowGUID = _windows[index]->getGUID();
    SysInfo& systemInfo = sysInfo();
    getWindowHandle(_windows[index]->getRawWindow(), systemInfo);
}

U32 WindowManager::createAPIFlags(RenderAPI api) {
    U32 windowFlags = 0;

    if (api == RenderAPI::OpenGL || api == RenderAPI::OpenGLES) {
        Uint32 OpenGLFlags = SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG;
        if (Config::ENABLE_GPU_VALIDATION) {
            // OpenGL error handling is available in any build configuration
            // if the proper defines are in place.
            OpenGLFlags |= SDL_GL_CONTEXT_DEBUG_FLAG |
                           SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG |
                           SDL_GL_CONTEXT_RESET_ISOLATION_FLAG;
        }

        auto validate = [](I32 errCode) -> bool {
            if (errCode != 0) {
                Console::errorfn(Locale::get(_ID("SDL_ERROR")), SDL_GetError());
                return false;
            }

            return true;
        };

        auto validateAssert = [&validate](I32 errCode) -> bool {
            if (!validate(errCode)) {
                assert(errCode == 0);
                return false;
            }

            return true;
        };

        validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, OpenGLFlags));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1));
        // 32Bit RGBA (R8G8B8A8), 24bit Depth, 8bit Stencil
        validateAssert(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24));
        validateAssert(SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1));
        // Toggle multi-sampling if requested.
        // This options requires a client-restart, sadly.
        I32 msaaSamples = to_I32(_context->config().rendering.msaaSamples);
        if (msaaSamples > 0) {
            if (validate(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1))) {
                while (!validate(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaaSamples))) {
                    msaaSamples = msaaSamples / 2;
                    if (msaaSamples == 0) {
                        validate(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0));
                        break;
                    }
                }
            } else {
                msaaSamples = 0;
            }
        }
        _context->config().rendering.msaaSamples = to_U8(msaaSamples);

        // OpenGL ES is not yet supported, but when added, it will need to mirror
        // OpenGL functionality 1-to-1
        if (api == RenderAPI::OpenGLES) {
            validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1));
            validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES));
            validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3));
            validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1));
        }  else {
            validate(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE));
            validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4));
            validateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5));
        }

        windowFlags |= SDL_WINDOW_OPENGL;
    } 

    windowFlags |= SDL_WINDOW_HIDDEN;
    windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
    if (_context->config().runtime.windowResizable) {
        windowFlags |= SDL_WINDOW_RESIZABLE;
    }

    return windowFlags;
}

void WindowManager::setCursorPosition(I32 x, I32 y) const {
    getActiveWindow().setCursorPosition(x, y);
}

void WindowManager::handleWindowEvent(WindowEvent event, I64 winGUID, I32 data1, I32 data2) {
    switch (event) {
        case WindowEvent::HIDDEN: {
        } break;
        case WindowEvent::SHOWN: {
        } break;
        case WindowEvent::MINIMIZED: {
            _context->app().mainLoopPaused(true);
            getWindow(winGUID).minimized(true);
        } break;
        case WindowEvent::MAXIMIZED: {
            getWindow(winGUID).minimized(false);
        } break;
        case WindowEvent::RESTORED: {
            getWindow(winGUID).minimized(false);
        } break;
        case WindowEvent::LOST_FOCUS: {
            getWindow(winGUID).hasFocus(false);
        } break;
        case WindowEvent::GAINED_FOCUS: {
            getWindow(winGUID).hasFocus(true);
        } break;
        case WindowEvent::RESIZED_INTERNAL: {
            // Only if rendering window
            if (_activeWindowGUID == winGUID) {
                _context->app().onChangeWindowSize(to_U16(data1), to_U16(data2));
            }
        } break;
        case WindowEvent::RESIZED_EXTERNAL: {
        } break;
        case WindowEvent::RESOLUTION_CHANGED: {
            // Only if rendering window
            if (_activeWindowGUID == winGUID) {
                _context->app().onChangeRenderResolution(to_U16(data1), to_U16(data2));
            }
        } break;
        case WindowEvent::APP_LOOP: {
            for (DisplayWindow* win : _windows) {
                win->update();
            }
        } break;
    };
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Core/WindowManager.cpp

Diff revisions: vs.
Revision Author Commited Message
909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

908 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 15:56:53 +0000

[Ionut]
- Texture’s MSAA sample count is now a property of the TextureDescriptor
- Add extra SDL validation as well as fallback for too high MSAA sample count specified

902 Diff Diff IonutCava picture IonutCava Sun 25 Jun, 2017 16:56:57 +0000

[Ionut]
- Rework input system a bit for easier maintenance and readability
- Toggle AntTweakBar display using CTRL+F11

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

837 Diff Diff IonutCava picture IonutCava Sun 29 Jan, 2017 15:45:58 +0000

[IonutCava]
- File system updates

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

829 Diff Diff IonutCava picture IonutCava Tue 24 Jan, 2017 17:28:39 +0000

[IonutCava]
- Separate resourceLocation for resources into resourceLocation and resourceName.
- More XML config loading refactoring

818 IonutCava picture IonutCava Mon 16 Jan, 2017 17:23:20 +0000

[IonutCava]
- Units get their bound node setup by the SGN UnitComponent and not during creation
- Profile guided optimizations