diff --git a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp index be3f9d663cf..78ab041ddf4 100644 --- a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp +++ b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp @@ -487,16 +487,16 @@ void ofxAppEmscriptenWindow::setWindowShape(int w, int h){ } //------------------------------------------------------------ -glm::vec2 ofxAppEmscriptenWindow::getWindowPosition(){ - return glm::vec2(0,0); +glm::ivec2 ofxAppEmscriptenWindow::getWindowPosition(){ + return { 0, 0 }; } //------------------------------------------------------------ -glm::vec2 ofxAppEmscriptenWindow::getWindowSize(){ +glm::ivec2 ofxAppEmscriptenWindow::getWindowSize(){ if(mCurrentWindowMode == OF_GAME_MODE) { double twidth, theight; emscripten_get_element_css_size("canvas", &twidth, &theight); - return glm::vec2((int)twidth,(int)theight); + return { (int)twidth, (int)theight }; } int width; int height; @@ -509,7 +509,7 @@ glm::vec2 ofxAppEmscriptenWindow::getWindowSize(){ } //------------------------------------------------------------ -glm::vec2 ofxAppEmscriptenWindow::getScreenSize(){ +glm::ivec2 ofxAppEmscriptenWindow::getScreenSize(){ return getWindowSize(); } diff --git a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.h b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.h index 850abd02d83..768834d522e 100644 --- a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.h +++ b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.h @@ -16,7 +16,7 @@ #include #include // For Emscripten WebGL API headers (see also webgl/webgl1_ext.h and webgl/webgl2.h) -class ofxAppEmscriptenWindow: public ofAppBaseGLESWindow { +class ofxAppEmscriptenWindow: public ofAppBaseWindow { public: ofxAppEmscriptenWindow(); ~ofxAppEmscriptenWindow(); @@ -30,7 +30,7 @@ class ofxAppEmscriptenWindow: public ofAppBaseGLESWindow { static void loop(); - void setup(const ofGLESWindowSettings & settings); + void setup(const ofWindowSettings & settings); void hideCursor(); // void showCursor(); @@ -38,9 +38,9 @@ class ofxAppEmscriptenWindow: public ofAppBaseGLESWindow { // void setWindowPosition(int x, int y); void setWindowShape(int w, int h); - glm::vec2 getWindowPosition(); - glm::vec2 getWindowSize(); - glm::vec2 getScreenSize(); + glm::ivec2 getWindowPosition(); + glm::ivec2 getWindowSize(); + glm::ivec2 getScreenSize(); ofOrientation getOrientation(); diff --git a/addons/ofxiOS/src/app/ofAppiOSWindow.h b/addons/ofxiOS/src/app/ofAppiOSWindow.h index 15ffecb469f..3575d3c4227 100644 --- a/addons/ofxiOS/src/app/ofAppiOSWindow.h +++ b/addons/ofxiOS/src/app/ofAppiOSWindow.h @@ -37,7 +37,7 @@ #include "ofxiOSConstants.h" #include "ofEvents.h" -class ofiOSWindowSettings: public ofGLESWindowSettings{ +class ofiOSWindowSettings: public ofWindowSettings{ public: ofiOSWindowSettings() :enableRetina(true) @@ -112,40 +112,6 @@ class ofiOSWindowSettings: public ofGLESWindowSettings{ } } - ofiOSWindowSettings(const ofGLESWindowSettings & settings) - :ofGLESWindowSettings(settings) - ,enableRetina(true) - ,retinaScale(0) - ,enableDepth(false) - ,enableAntiAliasing(false) - ,numOfAntiAliasingSamples(0) - ,enableHardwareOrientation(false) - ,enableHardwareOrientationAnimation(false) - ,enableSetupScreen(true) - ,windowControllerType(ofxiOSWindowControllerType::CORE_ANIMATION) - ,colorType(ofxiOSRendererColorFormat::RGBA8888) - ,depthType(ofxiOSRendererDepthFormat::DEPTH_NONE) - ,stencilType(ofxiOSRendererStencilFormat::STENCIL_NONE) - ,enableMultiTouch(false){ - const ofiOSWindowSettings * iosSettings = dynamic_cast(&settings); - if(iosSettings){ - enableRetina = iosSettings->enableRetina; - retinaScale = iosSettings->retinaScale; - enableDepth = iosSettings->enableDepth; - enableAntiAliasing = iosSettings->enableAntiAliasing; - numOfAntiAliasingSamples = iosSettings->numOfAntiAliasingSamples; - enableHardwareOrientation = iosSettings->enableHardwareOrientation; - enableHardwareOrientationAnimation = iosSettings->enableHardwareOrientationAnimation; - enableSetupScreen = iosSettings->enableSetupScreen; - setupOrientation = iosSettings->setupOrientation; - windowControllerType = iosSettings->windowControllerType; - colorType = iosSettings->colorType; - depthType = iosSettings->depthType; - stencilType = iosSettings->stencilType; - enableMultiTouch = iosSettings->enableMultiTouch; - } - } - virtual ~ofiOSWindowSettings(){}; bool enableRetina; @@ -166,7 +132,7 @@ class ofiOSWindowSettings: public ofGLESWindowSettings{ }; -class ofAppiOSWindow : public ofAppBaseGLESWindow { +class ofAppiOSWindow : public ofAppBaseWindow { public: static ofAppiOSWindow * getInstance(); @@ -181,7 +147,6 @@ class ofAppiOSWindow : public ofAppBaseGLESWindow { static void pollEvents(){ } void setup(const ofWindowSettings & _settings); - void setup(const ofGLESWindowSettings & _settings); void setup(const ofiOSWindowSettings & _settings); void setup(); @@ -200,9 +165,9 @@ class ofAppiOSWindow : public ofAppBaseGLESWindow { virtual void setWindowPosition(int x, int y); virtual void setWindowShape(int w, int h); - virtual glm::vec2 getWindowPosition(); - virtual glm::vec2 getWindowSize(); - virtual glm::vec2 getScreenSize(); + virtual glm::ivec2 getWindowPosition(); + virtual glm::ivec2 getWindowSize(); + virtual glm::ivec2 getScreenSize(); #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) virtual void setOrientation(ofOrientation orientation); diff --git a/addons/ofxiOS/src/app/ofAppiOSWindow.mm b/addons/ofxiOS/src/app/ofAppiOSWindow.mm index 53a3856e6d4..aff4bce59ef 100644 --- a/addons/ofxiOS/src/app/ofAppiOSWindow.mm +++ b/addons/ofxiOS/src/app/ofAppiOSWindow.mm @@ -1,5 +1,5 @@ /*********************************************************************** - + Copyright (c) 2008, 2009, Memo Akten, www.memo.tv *** The Mega Super Awesome Visuals Company *** * All rights reserved. @@ -12,22 +12,22 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of MSA Visuals nor the names of its contributors + * * Neither the name of MSA Visuals nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THE POSSIBILITY OF SUCH DAMAGE. * - * ***********************************************************************/ + * ***********************************************************************/ #include #include "ofxiOSConstants.h" #if defined(TARGET_OF_IOS) @@ -35,13 +35,13 @@ #include "ofGLRenderer.h" #include "ofGLProgrammableRenderer.h" #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) - #include "ofxiOSAppDelegate.h" - #include "ofxiOSViewController.h" - const std::string appDelegateName = "ofxiOSAppDelegate"; + #include "ofxiOSAppDelegate.h" + #include "ofxiOSViewController.h" + const std::string appDelegateName = "ofxiOSAppDelegate"; #elif TARGET_OS_TV - #include "ofxtvOSAppDelegate.h" - #include "ofxtvOSViewController.h" - const std::string appDelegateName = "ofxtvOSAppDelegate"; + #include "ofxtvOSAppDelegate.h" + #include "ofxtvOSViewController.h" + const std::string appDelegateName = "ofxtvOSAppDelegate"; #endif #include "ofxiOSGLKView.h" #include "ofxiOSEAGLView.h" @@ -55,53 +55,42 @@ //----------------------------------------------------------------------------------- constructor / destructor. ofAppiOSWindow::ofAppiOSWindow() : hasExited(false) { if(_instance == NULL) { - _instance = this; - } else { - ofLog(OF_LOG_ERROR, "ofAppiOSWindow instantiated more than once"); - } - bRetinaSupportedOnDevice = false; - bRetinaSupportedOnDeviceChecked = false; + _instance = this; + } else { + ofLog(OF_LOG_ERROR, "ofAppiOSWindow instantiated more than once"); + } + bRetinaSupportedOnDevice = false; + bRetinaSupportedOnDeviceChecked = false; } ofAppiOSWindow::~ofAppiOSWindow() { - close(); + close(); _instance = NULL; } void ofAppiOSWindow::close() { - if(hasExited == false){ - hasExited = true; - events().notifyExit(); - events().disable(); - } + if(hasExited == false){ + hasExited = true; + events().notifyExit(); + events().disable(); + } } void ofAppiOSWindow::setup(const ofWindowSettings & _settings) { - const ofiOSWindowSettings * iosSettings = dynamic_cast(&_settings); - if(iosSettings){ - setup(*iosSettings); - } else{ - setup(ofiOSWindowSettings(_settings)); - } -} - -void ofAppiOSWindow::setup(const ofGLESWindowSettings & _settings) { - const ofiOSWindowSettings * iosSettings = dynamic_cast(&_settings); - if(iosSettings){ - setup(*iosSettings); - } else{ - setup(ofiOSWindowSettings(_settings)); - } + const ofiOSWindowSettings * iosSettings = dynamic_cast(&_settings); + if(iosSettings){ + setup(*iosSettings); + } else{ + setup(ofiOSWindowSettings(_settings)); + } } void ofAppiOSWindow::setup(const ofiOSWindowSettings & _settings) { - settings = _settings; + settings = _settings; setup(); } void ofAppiOSWindow::setup() { - - if(settings.setupOrientation == OF_ORIENTATION_UNKNOWN) { settings.setupOrientation = OF_ORIENTATION_DEFAULT; } @@ -111,51 +100,50 @@ } else { currentRenderer = std::shared_ptr(new ofGLRenderer(this)); } - hasExited = false; } //----------------------------------------------------------------------------------- opengl setup. void ofAppiOSWindow::setupOpenGL(int w, int h, ofWindowMode screenMode) { settings.windowMode = screenMode; // use this as flag for displaying status bar or not - setup(settings); + setup(settings); } void ofAppiOSWindow::loop() { - startAppWithDelegate(appDelegateName); + startAppWithDelegate(appDelegateName); } void ofAppiOSWindow::run(ofBaseApp * appPtr){ - startAppWithDelegate(appDelegateName); + startAppWithDelegate(appDelegateName); } void ofAppiOSWindow::startAppWithDelegate(std::string appDelegateClassName) { - static bool bAppCreated = false; - if(bAppCreated == true) { - return; - } - bAppCreated = true; - - @autoreleasepool { - UIApplicationMain(0, nil, nil, [NSString stringWithUTF8String:appDelegateClassName.c_str()]); - } + static bool bAppCreated = false; + if(bAppCreated == true) { + return; + } + bAppCreated = true; + + @autoreleasepool { + UIApplicationMain(0, nil, nil, [NSString stringWithUTF8String:appDelegateClassName.c_str()]); + } } void ofAppiOSWindow::update() { - + } void ofAppiOSWindow::draw() { - + } //----------------------------------------------------------------------------------- cursor. void ofAppiOSWindow::hideCursor() { - // not supported on iOS. + // not supported on iOS. } void ofAppiOSWindow::showCursor() { - // not supported on iOS. + // not supported on iOS. } //----------------------------------------------------------------------------------- window / screen properties. @@ -167,21 +155,21 @@ // not supported on iOS. } -glm::vec2 ofAppiOSWindow::getWindowPosition() { +glm::ivec2 ofAppiOSWindow::getWindowPosition() { if(settings.windowControllerType == METAL_KIT || settings.windowControllerType == GL_KIT) return *[[ofxiOSGLKView getInstance] getWindowPosition]; else return *[[ofxiOSEAGLView getInstance] getWindowPosition]; } -glm::vec2 ofAppiOSWindow::getWindowSize() { +glm::ivec2 ofAppiOSWindow::getWindowSize() { if(settings.windowControllerType == METAL_KIT || settings.windowControllerType == GL_KIT) return *[[ofxiOSGLKView getInstance] getWindowSize]; else return *[[ofxiOSEAGLView getInstance] getWindowSize]; } -glm::vec2 ofAppiOSWindow::getScreenSize() { +glm::ivec2 ofAppiOSWindow::getScreenSize() { if(settings.windowControllerType == METAL_KIT || settings.windowControllerType == GL_KIT) return *[[ofxiOSGLKView getInstance] getScreenSize]; else @@ -190,8 +178,8 @@ int ofAppiOSWindow::getWidth(){ if(settings.enableHardwareOrientation == true || - orientation == OF_ORIENTATION_DEFAULT || - orientation == OF_ORIENTATION_180) { + orientation == OF_ORIENTATION_DEFAULT || + orientation == OF_ORIENTATION_180) { return (int)getWindowSize().x; } return (int)getWindowSize().y; @@ -199,8 +187,8 @@ int ofAppiOSWindow::getHeight(){ if(settings.enableHardwareOrientation == true || - orientation == OF_ORIENTATION_DEFAULT || - orientation == OF_ORIENTATION_180) { + orientation == OF_ORIENTATION_DEFAULT || + orientation == OF_ORIENTATION_180) { return (int)getWindowSize().y; } return (int)getWindowSize().x; @@ -213,39 +201,39 @@ #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) //----------------------------------------------------------------------------------- orientation. void ofAppiOSWindow::setOrientation(ofOrientation toOrientation) { - if(orientation == toOrientation) { - return; - } - bool bOrientationPortraitOne = (orientation == OF_ORIENTATION_DEFAULT) || (orientation == OF_ORIENTATION_180); - bool bOrientationPortraitTwo = (toOrientation == OF_ORIENTATION_DEFAULT) || (toOrientation == OF_ORIENTATION_180); - bool bResized = bOrientationPortraitOne != bOrientationPortraitTwo; - - orientation = toOrientation; + if(orientation == toOrientation) { + return; + } + bool bOrientationPortraitOne = (orientation == OF_ORIENTATION_DEFAULT) || (orientation == OF_ORIENTATION_180); + bool bOrientationPortraitTwo = (toOrientation == OF_ORIENTATION_DEFAULT) || (toOrientation == OF_ORIENTATION_180); + bool bResized = bOrientationPortraitOne != bOrientationPortraitTwo; + + orientation = toOrientation; #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) - UIInterfaceOrientation interfaceOrientation = UIInterfaceOrientationPortrait; - switch (orientation) { - case OF_ORIENTATION_DEFAULT: - interfaceOrientation = UIInterfaceOrientationPortrait; - break; - case OF_ORIENTATION_180: - interfaceOrientation = UIInterfaceOrientationPortraitUpsideDown; - break; - case OF_ORIENTATION_90_RIGHT: - interfaceOrientation = UIInterfaceOrientationLandscapeLeft; - break; - case OF_ORIENTATION_90_LEFT: - interfaceOrientation = UIInterfaceOrientationLandscapeRight; - break; - } - - - id appDelegate = [UIApplication sharedApplication].delegate; - if([appDelegate respondsToSelector:@selector(glViewController)] == NO) { - // check app delegate has glViewController, - // otherwise calling glViewController will cause a crash. - return; - } - UIViewController * uiViewController = ((ofxiOSAppDelegate *)appDelegate).uiViewController; + UIInterfaceOrientation interfaceOrientation = UIInterfaceOrientationPortrait; + switch (orientation) { + case OF_ORIENTATION_DEFAULT: + interfaceOrientation = UIInterfaceOrientationPortrait; + break; + case OF_ORIENTATION_180: + interfaceOrientation = UIInterfaceOrientationPortraitUpsideDown; + break; + case OF_ORIENTATION_90_RIGHT: + interfaceOrientation = UIInterfaceOrientationLandscapeLeft; + break; + case OF_ORIENTATION_90_LEFT: + interfaceOrientation = UIInterfaceOrientationLandscapeRight; + break; + } + + + id appDelegate = [UIApplication sharedApplication].delegate; + if([appDelegate respondsToSelector:@selector(glViewController)] == NO) { + // check app delegate has glViewController, + // otherwise calling glViewController will cause a crash. + return; + } + UIViewController * uiViewController = ((ofxiOSAppDelegate *)appDelegate).uiViewController; if([uiViewController isKindOfClass:[ofxiOSViewController class]] == YES) { ofxiOSViewController * glViewController = (ofxiOSViewController*)uiViewController; if(glViewController) { @@ -268,88 +256,88 @@ } bool ofAppiOSWindow::doesHWOrientation() { - return settings.enableHardwareOrientation; + return settings.enableHardwareOrientation; } //----------------------------------------------------------------------------------- bool ofAppiOSWindow::enableHardwareOrientation() { - return (settings.enableHardwareOrientation = true); + return (settings.enableHardwareOrientation = true); } bool ofAppiOSWindow::disableHardwareOrientation() { - return (settings.enableHardwareOrientation = false); + return (settings.enableHardwareOrientation = false); } bool ofAppiOSWindow::enableOrientationAnimation() { - return (settings.enableHardwareOrientationAnimation = true); + return (settings.enableHardwareOrientationAnimation = true); } bool ofAppiOSWindow::disableOrientationAnimation() { - return (settings.enableHardwareOrientationAnimation = false); + return (settings.enableHardwareOrientationAnimation = false); } #endif //----------------------------------------------------------------------------------- void ofAppiOSWindow::setWindowTitle(std::string title) { - // not supported on iOS. + // not supported on iOS. } void ofAppiOSWindow::setFullscreen(bool fullscreen) { #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) - [[UIApplication sharedApplication] setStatusBarHidden:fullscreen withAnimation:UIStatusBarAnimationSlide]; + [[UIApplication sharedApplication] setStatusBarHidden:fullscreen withAnimation:UIStatusBarAnimationSlide]; #endif - if(fullscreen) { - settings.windowMode = OF_FULLSCREEN; - } else { - settings.windowMode = OF_WINDOW; - } + if(fullscreen) { + settings.windowMode = OF_FULLSCREEN; + } else { + settings.windowMode = OF_WINDOW; + } } void ofAppiOSWindow::toggleFullscreen() { - if(settings.windowMode == OF_FULLSCREEN) { - setFullscreen(false); - } else { - setFullscreen(true); - } + if(settings.windowMode == OF_FULLSCREEN) { + setFullscreen(false); + } else { + setFullscreen(true); + } } //----------------------------------------------------------------------------------- bool ofAppiOSWindow::enableRendererES2() { - if(isRendererES2() == true) { - return false; - } - std::shared_ptrrenderer (new ofGLProgrammableRenderer(this)); - ofSetCurrentRenderer(renderer); - return true; + if(isRendererES2() == true) { + return false; + } + std::shared_ptrrenderer (new ofGLProgrammableRenderer(this)); + ofSetCurrentRenderer(renderer); + return true; } bool ofAppiOSWindow::enableRendererES1() { - if(isRendererES1() == true) { - return false; - } - std::shared_ptr renderer(new ofGLRenderer(this)); - ofSetCurrentRenderer(renderer); - return true; + if(isRendererES1() == true) { + return false; + } + std::shared_ptr renderer(new ofGLRenderer(this)); + ofSetCurrentRenderer(renderer); + return true; } bool ofAppiOSWindow::isProgrammableRenderer() { - return (currentRenderer && currentRenderer->getType()==ofGLProgrammableRenderer::TYPE); + return (currentRenderer && currentRenderer->getType()==ofGLProgrammableRenderer::TYPE); } ofxiOSRendererType ofAppiOSWindow::getGLESVersion() { - return (ofxiOSRendererType)settings.glesVersion; + return (ofxiOSRendererType)settings.glesVersion; } bool ofAppiOSWindow::isRendererES2() { - return (isProgrammableRenderer() && settings.glesVersion == 2); + return (isProgrammableRenderer() && settings.glesVersion == 2); } bool ofAppiOSWindow::isRendererES1() { - return !isProgrammableRenderer(); + return !isProgrammableRenderer(); } //----------------------------------------------------------------------------------- @@ -362,71 +350,71 @@ }; bool ofAppiOSWindow::isSetupScreenEnabled() { - return settings.enableSetupScreen; + return settings.enableSetupScreen; } void ofAppiOSWindow::setVerticalSync(bool enabled) { - // not supported on iOS. + // not supported on iOS. } //----------------------------------------------------------------------------------- retina. bool ofAppiOSWindow::enableRetina(float retinaScale) { - if(isRetinaSupportedOnDevice()) { - settings.enableRetina = true; - settings.retinaScale = retinaScale; - } - return settings.enableRetina; + if(isRetinaSupportedOnDevice()) { + settings.enableRetina = true; + settings.retinaScale = retinaScale; + } + return settings.enableRetina; } bool ofAppiOSWindow::disableRetina() { - return (settings.enableRetina = false); + return (settings.enableRetina = false); } bool ofAppiOSWindow::isRetinaEnabled() { - return settings.enableRetina; + return settings.enableRetina; } bool ofAppiOSWindow::isRetinaSupportedOnDevice() { - if(bRetinaSupportedOnDeviceChecked) { - return bRetinaSupportedOnDevice; - } - - bRetinaSupportedOnDeviceChecked = true; - - @autoreleasepool { - if([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){ - if ([[UIScreen mainScreen] scale] > 1){ - bRetinaSupportedOnDevice = true; - } - } - } - - return bRetinaSupportedOnDevice; + if(bRetinaSupportedOnDeviceChecked) { + return bRetinaSupportedOnDevice; + } + + bRetinaSupportedOnDeviceChecked = true; + + @autoreleasepool { + if([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){ + if ([[UIScreen mainScreen] scale] > 1){ + bRetinaSupportedOnDevice = true; + } + } + } + + return bRetinaSupportedOnDevice; } float ofAppiOSWindow::getRetinaScale() { - return settings.retinaScale; + return settings.retinaScale; } //----------------------------------------------------------------------------------- depth buffer. bool ofAppiOSWindow::enableDepthBuffer() { settings.depthType = ofxiOSRendererDepthFormat::DEPTH_24; - return (settings.enableDepth = true); + return (settings.enableDepth = true); } bool ofAppiOSWindow::disableDepthBuffer() { settings.depthType = ofxiOSRendererDepthFormat::DEPTH_NONE; - return (settings.enableDepth = false); + return (settings.enableDepth = false); } bool ofAppiOSWindow::isDepthBufferEnabled() { - return settings.enableDepth; + return settings.enableDepth; } //----------------------------------------------------------------------------------- anti aliasing. bool ofAppiOSWindow::enableAntiAliasing(int samples) { settings.numOfAntiAliasingSamples = samples; - return (settings.enableAntiAliasing = true); + return (settings.enableAntiAliasing = true); } void ofAppiOSWindow::enableMultiTouch(bool isOn) { @@ -448,15 +436,15 @@ } bool ofAppiOSWindow::disableAntiAliasing() { - return (settings.enableAntiAliasing = false); + return (settings.enableAntiAliasing = false); } bool ofAppiOSWindow::isAntiAliasingEnabled() { - return settings.enableAntiAliasing; + return settings.enableAntiAliasing; } int ofAppiOSWindow::getAntiAliasingSampleCount() { - return settings.numOfAntiAliasingSamples; + return settings.numOfAntiAliasingSamples; } ofxiOSWindowControllerType ofAppiOSWindow::getWindowControllerType() { @@ -477,16 +465,16 @@ //----------------------------------------------------------------------------------- ofCoreEvents & ofAppiOSWindow::events(){ - return coreEvents; + return coreEvents; } //----------------------------------------------------------------------------------- std::shared_ptr & ofAppiOSWindow::renderer(){ - return currentRenderer; + return currentRenderer; } ofiOSWindowSettings & ofAppiOSWindow::getSettings() { - return settings; + return settings; } #endif diff --git a/addons/ofxiOS/src/core/ofxiOSGLKView.mm b/addons/ofxiOS/src/core/ofxiOSGLKView.mm index 04e83cde705..d13ff55ce80 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKView.mm +++ b/addons/ofxiOS/src/core/ofxiOSGLKView.mm @@ -83,19 +83,19 @@ - (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegrou } - (void)setup { - if(window.get() == NULL) { + if(window.get() == nullptr) { ofLog(OF_LOG_FATAL_ERROR, "ofxiOSEAGLView setup. Failed setup. window is NULL"); return; } if(app.get() != ofGetAppPtr()) { // check if already running. - ofSetMainLoop(shared_ptr(NULL)); // destroy old main loop. + ofSetMainLoop(shared_ptr(nullptr)); // destroy old main loop. auto mainLoop = std::make_shared(); // make new main loop. ofSetMainLoop(mainLoop); ofiOSWindowSettings windowSettings = window->getSettings(); - window = NULL; + window = nullptr; window = dynamic_pointer_cast(ofCreateWindow(windowSettings)); diff --git a/examples/3d/assimp3DModelLoaderExample/src/ofApp.cpp b/examples/3d/assimp3DModelLoaderExample/src/ofApp.cpp index fe3fa2ceb2c..a8950f34d2a 100644 --- a/examples/3d/assimp3DModelLoaderExample/src/ofApp.cpp +++ b/examples/3d/assimp3DModelLoaderExample/src/ofApp.cpp @@ -5,6 +5,10 @@ //-------------------------------------------------------------- void ofApp::setup(){ + ofSetFrameRate(0); + ofSetVerticalSync(false); + + ofSetLogLevel(OF_LOG_VERBOSE); ofBackground(50, 0); diff --git a/examples/gl/pointLightsExample/src/main.cpp b/examples/gl/pointLightsExample/src/main.cpp index 108491824be..020743b8c1b 100644 --- a/examples/gl/pointLightsExample/src/main.cpp +++ b/examples/gl/pointLightsExample/src/main.cpp @@ -8,7 +8,8 @@ int main( ){ ofGLWindowSettings settings; settings.setSize(1024, 768); settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN - + settings.setGLVersion(3, 2); + auto window = ofCreateWindow(settings); ofRunApp(window, std::make_shared()); diff --git a/examples/templates/emptyExample/src/main.cpp b/examples/templates/emptyExample/src/main.cpp index 4e6518d49dc..1ac3c5eaf00 100644 --- a/examples/templates/emptyExample/src/main.cpp +++ b/examples/templates/emptyExample/src/main.cpp @@ -10,8 +10,8 @@ int main( ){ settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN auto window = ofCreateWindow(settings); - - ofRunApp(window, std::make_shared()); + auto app = std::make_shared(); + ofRunApp(window, app); ofRunMainLoop(); } diff --git a/examples/templates/emptyExample/src/ofApp.cpp b/examples/templates/emptyExample/src/ofApp.cpp index 710d6eacc68..74a2e36d813 100644 --- a/examples/templates/emptyExample/src/ofApp.cpp +++ b/examples/templates/emptyExample/src/ofApp.cpp @@ -2,7 +2,6 @@ //-------------------------------------------------------------- void ofApp::setup(){ - } //-------------------------------------------------------------- @@ -12,6 +11,9 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ + ofSetFrameRate(30); + + ofDrawBitmapString(ofToString(ofGetFrameRate()), 20, 20); } @@ -68,4 +70,4 @@ void ofApp::gotMessage(ofMessage msg){ //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ -} \ No newline at end of file +} diff --git a/libs/openFrameworks/3d/ofNode.h b/libs/openFrameworks/3d/ofNode.h index b53e7acef6b..5c6db3d8323 100644 --- a/libs/openFrameworks/3d/ofNode.h +++ b/libs/openFrameworks/3d/ofNode.h @@ -8,6 +8,8 @@ #include #include +// FIXME: unordered_set +#include class ofBaseRenderer; diff --git a/libs/openFrameworks/app/ofAppBaseWindow.h b/libs/openFrameworks/app/ofAppBaseWindow.h index 8823ca773b7..91a4aedce7f 100644 --- a/libs/openFrameworks/app/ofAppBaseWindow.h +++ b/libs/openFrameworks/app/ofAppBaseWindow.h @@ -3,6 +3,7 @@ #include "ofWindowSettings.h" // MARK: Target #include "ofConstants.h" +#include "ofRectangle.h" class ofBaseApp; class ofBaseRenderer; @@ -19,44 +20,49 @@ struct _XDisplay; typedef struct _XDisplay Display; #endif -class ofAppBaseWindow{ +class ofAppBaseWindow { public: ofAppBaseWindow(){} - virtual ~ofAppBaseWindow(){} +// virtual ~ofAppBaseWindow(){} + ~ofAppBaseWindow(){} virtual void setup(const ofWindowSettings & settings)=0; virtual void update()=0; virtual void draw()=0; + virtual std::shared_ptr & renderer() = 0; + virtual ofCoreEvents & events() = 0; + virtual bool getWindowShouldClose(){ return false; } virtual void setWindowShouldClose(){} virtual void close(){} - virtual ofCoreEvents & events() = 0; - virtual std::shared_ptr & renderer() = 0; virtual void hideCursor(){} virtual void showCursor(){} virtual void setWindowPosition(int x, int y){} virtual void setWindowShape(int w, int h){} + virtual void setWindowRect(const ofRectangle & rect){} - virtual glm::vec2 getWindowPosition(){ return glm::vec2(); } - virtual glm::vec2 getWindowSize(){ return glm::vec2(); } - virtual glm::vec2 getScreenSize(){ return glm::vec2(); } + virtual glm::ivec2 getWindowPosition() { return glm::ivec2(); } + virtual glm::ivec2 getWindowSize() { return glm::ivec2(); } + virtual glm::ivec2 getFramebufferSize() { return glm::ivec2(); } + virtual glm::ivec2 getScreenSize() { return glm::ivec2(); } + virtual ofRectangle getWindowRect() { return ofRectangle(); } - virtual void setOrientation(ofOrientation orientation){ } - virtual ofOrientation getOrientation(){ return OF_ORIENTATION_DEFAULT; } + virtual void setOrientation(ofOrientation orientationIn) { orientation = orientationIn; } + virtual ofOrientation getOrientation() { return orientation; } virtual bool doesHWOrientation(){ return false; } //this is used by ofGetWidth and now determines the window width based on orientation virtual int getWidth(){ return 0; } virtual int getHeight(){ return 0; } - virtual void setWindowTitle(std::string title){} + virtual void setWindowTitle(const std::string & title){} - virtual ofWindowMode getWindowMode(){ return OF_WINDOW; } + virtual ofWindowMode getWindowMode() { return settings.windowMode; } virtual void setFullscreen(bool fullscreen){} virtual void toggleFullscreen(){} @@ -75,6 +81,9 @@ class ofAppBaseWindow{ virtual void finishRender(){} virtual void * getWindowContext(){ return nullptr; } + + virtual void beginDraw(){} + virtual void endDraw(){} #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) virtual Display* getX11Display(){ return nullptr; } @@ -100,32 +109,12 @@ class ofAppBaseWindow{ virtual HGLRC getWGLContext(){ return 0; } virtual HWND getWin32Window(){ return 0; } #endif -}; - -class ofAppBaseGLWindow: public ofAppBaseWindow{ -public: - virtual ~ofAppBaseGLWindow(){} - virtual void setup(const ofGLWindowSettings & settings)=0; - void setup(const ofWindowSettings & settings){ - const ofGLWindowSettings * glSettings = dynamic_cast(&settings); - if(glSettings){ - setup(*glSettings); - }else{ - setup(ofGLWindowSettings(settings)); - } - } -}; - -class ofAppBaseGLESWindow: public ofAppBaseWindow{ -public: - virtual ~ofAppBaseGLESWindow(){} - virtual void setup(const ofGLESWindowSettings & settings)=0; - void setup(const ofWindowSettings & settings){ - const ofGLESWindowSettings * glSettings = dynamic_cast(&settings); - if(glSettings){ - setup(*glSettings); - }else{ - setup(ofGLESWindowSettings(settings)); - } - } + + ofWindowSettings settings; + +//private: + ofOrientation orientation = OF_ORIENTATION_DEFAULT; + ofWindowMode windowMode = OF_WINDOW; + + std::string name { "virgem" }; }; diff --git a/libs/openFrameworks/app/ofAppEGLWindow.cpp b/libs/openFrameworks/app/ofAppEGLWindow.cpp index 7b4c3709928..1dc21fdc242 100644 --- a/libs/openFrameworks/app/ofAppEGLWindow.cpp +++ b/libs/openFrameworks/app/ofAppEGLWindow.cpp @@ -386,7 +386,6 @@ void ofAppEGLWindow::setup(const ofAppEGLWindowSettings & _settings) { buttonInUse = 0; bEnableSetupScreen = true; eglDisplayString = ""; - orientation = OF_ORIENTATION_DEFAULT; //TODO: 2.0f is an arbitrary factor that makes mouse speed ok at 1024x768, // to be totally correct we might need to take into account screen size @@ -917,7 +916,7 @@ void ofAppEGLWindow::destroyNativeEvents() { } //------------------------------------------------------------ -void ofAppEGLWindow::setWindowRect(const ofRectangle& requestedWindowRect) { +void ofAppEGLWindow::setWindowRect(const ofRectangle & requestedWindowRect) { if(!isWindowInited) { ofLogError("ofAppEGLWindow") << "setWindowRect(): window not inited"; return; @@ -1087,17 +1086,17 @@ void ofAppEGLWindow::setWindowTitle(std::string title) { } //------------------------------------------------------------ -glm::vec2 ofAppEGLWindow::getWindowSize(){ +glm::ivec2 ofAppEGLWindow::getWindowSize(){ return {currentWindowRect.width, currentWindowRect.height}; } //------------------------------------------------------------ -glm::vec2 ofAppEGLWindow::getWindowPosition(){ +glm::ivec2 ofAppEGLWindow::getWindowPosition(){ return glm::vec2(currentWindowRect.getPosition()); } //------------------------------------------------------------ -glm::vec2 ofAppEGLWindow::getScreenSize(){ +glm::ivec2 ofAppEGLWindow::getScreenSize(){ unsigned int screenWidth = 0; unsigned int screenHeight = 0; @@ -1142,16 +1141,6 @@ int ofAppEGLWindow::getHeight(){ return currentWindowRect.width; } -//------------------------------------------------------------ -void ofAppEGLWindow::setOrientation(ofOrientation orientationIn){ - orientation = orientationIn; -} - -//------------------------------------------------------------ -ofOrientation ofAppEGLWindow::getOrientation(){ - return orientation; -} - //------------------------------------------------------------ bool ofAppEGLWindow::doesHWOrientation() { return false; @@ -1249,11 +1238,6 @@ void ofAppEGLWindow::setWindowShape(int w, int h){ } } -//------------------------------------------------------------ -ofWindowMode ofAppEGLWindow::getWindowMode(){ - return windowMode; -} - //------------------------------------------------------------ void ofAppEGLWindow::toggleFullscreen(){ if( windowMode == OF_GAME_MODE) return; diff --git a/libs/openFrameworks/app/ofAppEGLWindow.h b/libs/openFrameworks/app/ofAppEGLWindow.h index a70a35e2aff..0a1ff65efcc 100644 --- a/libs/openFrameworks/app/ofAppEGLWindow.h +++ b/libs/openFrameworks/app/ofAppEGLWindow.h @@ -53,7 +53,7 @@ struct ofAppEGLWindowSettings: public ofGLESWindowSettings { ofAppEGLWindowSettings(const ofGLESWindowSettings & settings); }; -class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { +class ofAppEGLWindow : public ofAppBaseWindow, public ofThread { public: /// ofAppEGLWindow::Settings is currently deprecated in favor of @@ -61,7 +61,7 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { typedef ofAppEGLWindowSettings Settings; ofAppEGLWindow(); - virtual ~ofAppEGLWindow(); + ~ofAppEGLWindow(); static void loop(){}; static bool doesLoop(){ return false; } @@ -69,7 +69,7 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { static bool needsPolling(){ return true; } static void pollEvents(); - using ofAppBaseGLESWindow::setup; +// using ofAppBaseWindow::setup; void setup(const ofAppEGLWindowSettings & settings); void setup(const ofGLESWindowSettings & settings); @@ -86,35 +86,32 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { void setThreadTimeout(long timeOut){ threadTimeout = timeOut; } - virtual void hideCursor(); - virtual void showCursor(); + void hideCursor(); + void showCursor(); - virtual void setWindowPosition(int x, int y); - virtual void setWindowShape(int w, int h); + void setWindowPosition(int x, int y); + void setWindowShape(int w, int h); + void setWindowRect(const ofRectangle & rect); - virtual glm::vec2 getWindowPosition(); - virtual glm::vec2 getWindowSize(); - virtual glm::vec2 getScreenSize(); + glm::ivec2 getWindowPosition(); + glm::ivec2 getWindowSize(); + glm::ivec2 getScreenSize(); - virtual void setOrientation(ofOrientation orientation); - virtual ofOrientation getOrientation(); - virtual bool doesHWOrientation(); + bool doesHWOrientation(); //this is used by ofGetWidth and now determines the window width based on orientation - virtual int getWidth(); - virtual int getHeight(); + int getWidth(); + int getHeight(); - virtual void setWindowTitle(std::string title); // TODO const correct + void setWindowTitle(const std::string & title); // TODO const correct - virtual ofWindowMode getWindowMode(); + void setFullscreen(bool fullscreen); + void toggleFullscreen(); - virtual void setFullscreen(bool fullscreen); - virtual void toggleFullscreen(); + void enableSetupScreen(); + void disableSetupScreen(); - virtual void enableSetupScreen(); - virtual void disableSetupScreen(); - - virtual void setVerticalSync(bool enabled); + void setVerticalSync(bool enabled); EGLDisplay getEglDisplay() const; EGLSurface getEglSurface() const; @@ -132,19 +129,18 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { protected: - void setWindowRect(const ofRectangle& requestedWindowRect); +// void setWindowRect(const ofRectangle & requestedWindowRect); + ofRectangle getScreenRect(); // bool create - virtual void setupPeripherals(); + void setupPeripherals(); - virtual ofRectangle getScreenRect(); int getWindowWidth(); int getWindowHeight(); - ofWindowMode windowMode; bool bNewScreenMode; ///< \brief This indicates if a (new) window rectangle has to be adjusted. int buttonInUse; ///< \brief Mouse button currently in use. bool bEnableSetupScreen; ///< \brief This indicates the need/intent to draw a setup screen. @@ -152,7 +148,6 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { std::string eglDisplayString; int nFramesSinceWindowResized; ///< \brief The number of frames passed/shown since the window got resized. - ofOrientation orientation; void threadedFunction(); diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index a44aacb0de2..b8ff15e0684 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -16,70 +16,67 @@ #else #define GLFW_EXPOSE_NATIVE_EGL #endif - #include #include #include #include #include #include + + #elif defined(TARGET_OSX) #include #define GLFW_EXPOSE_NATIVE_COCOA #define GLFW_EXPOSE_NATIVE_NSGL - #include #elif defined(TARGET_WIN32) #define GLFW_EXPOSE_NATIVE_WIN32 #define GLFW_EXPOSE_NATIVE_WGL - #include #endif +#include "GLFW/glfw3native.h" + using std::numeric_limits; using std::shared_ptr; using std::vector; +using std::cout; +using std::endl; //------------------------------------------------------- -ofAppGLFWWindow::ofAppGLFWWindow() - : coreEvents(new ofCoreEvents) { +ofAppGLFWWindow::ofAppGLFWWindow() : coreEvents(std::make_unique()){ bEnableSetupScreen = true; buttonInUse = 0; buttonPressed = false; bWindowNeedsShowing = true; - orientation = OF_ORIENTATION_DEFAULT; targetWindowMode = OF_WINDOW; ofAppPtr = nullptr; - pixelScreenCoordScale = 1; - nFramesSinceWindowResized = 0; iconSet = false; windowP = nullptr; - windowW = 0; - windowH = 0; - currentW = 0; - currentH = 0; glfwSetErrorCallback(error_cb); } ofAppGLFWWindow::~ofAppGLFWWindow() { + cout << "ofAppGLFWWindow::~ofAppGLFWWindow() " << settings.windowName << endl; close(); } void ofAppGLFWWindow::close() { - if (windowP) { + cout << "ofAppGLFWWindow::close! " << settings.windowName << endl; + if (windowP) { glfwSetMouseButtonCallback( windowP, nullptr ); glfwSetCursorPosCallback( windowP, nullptr ); glfwSetCursorEnterCallback( windowP, nullptr ); glfwSetKeyCallback( windowP, nullptr ); glfwSetWindowSizeCallback( windowP, nullptr ); - glfwSetWindowPosCallback(windowP, nullptr); + glfwSetWindowPosCallback(windowP, nullptr); glfwSetFramebufferSizeCallback( windowP, nullptr); glfwSetWindowCloseCallback( windowP, nullptr ); glfwSetScrollCallback( windowP, nullptr ); glfwSetDropCallback( windowP, nullptr ); - glfwSetWindowRefreshCallback(windowP, nullptr); + glfwSetWindowRefreshCallback(windowP, nullptr); //hide the window before we destroy it stops a flicker on OS X on exit. glfwHideWindow(windowP); @@ -97,323 +94,267 @@ void ofAppGLFWWindow::close() { } //------------------------------------------------------------ -void ofAppGLFWWindow::setNumSamples(int _samples) { - settings.numSamples = _samples; -} - -//------------------------------------------------------------ -void ofAppGLFWWindow::setMultiDisplayFullscreen(bool bMultiFullscreen) { - settings.multiMonitorFullScreen = bMultiFullscreen; -} - -//------------------------------------------------------------ -void ofAppGLFWWindow::setDoubleBuffering(bool doubleBuff) { - settings.doubleBuffering = doubleBuff; -} - -//------------------------------------------------------------ -void ofAppGLFWWindow::setColorBits(int r, int g, int b) { - settings.redBits = r; - settings.greenBits = g; - settings.blueBits = b; -} - -//------------------------------------------------------------ -void ofAppGLFWWindow::setAlphaBits(int a) { - settings.alphaBits = a; -} +void ofAppGLFWWindow::setup(const ofWindowSettings & _settings) { +// cout << "yes recompile OK" << endl; + if (windowP) { + ofLogError() << "window already setup, probably you are mixing old and new style setup"; + ofLogError() << "call only ofCreateWindow(settings) or ofSetupOpenGL(...)"; + ofLogError() << "calling window->setup() after ofCreateWindow() is not necessary and won't do anything"; + return; + } -//------------------------------------------------------------ -void ofAppGLFWWindow::setDepthBits(int depth) { - settings.depthBits = depth; -} + settings = _settings; + + if (!glfwInit()) { + ofLogError("ofAppGLFWWindow") << "couldn't init GLFW"; + return; + } -//------------------------------------------------------------ -void ofAppGLFWWindow::setStencilBits(int stencil) { - settings.stencilBits = stencil; -} -//------------------------------------------------------------ -#ifdef TARGET_OPENGLES -void ofAppGLFWWindow::setup(const ofGLESWindowSettings & settings) { -#else - void ofAppGLFWWindow::setup(const ofGLWindowSettings & settings) { -#endif - const ofGLFWWindowSettings * glSettings = dynamic_cast(&settings); - if (glSettings) { - setup(*glSettings); - } else { - setup(ofGLFWWindowSettings(settings)); - } - } - - void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings) { - if (windowP) { - ofLogError() << "window already setup, probably you are mixing old and new style setup"; - ofLogError() << "call only ofCreateWindow(settings) or ofSetupOpenGL(...)"; - ofLogError() << "calling window->setup() after ofCreateWindow() is not necessary and won't do anything"; - return; - } - settings = _settings; - - if (!glfwInit()) { - ofLogError("ofAppGLFWWindow") << "couldn't init GLFW"; - return; - } - - // ofLogNotice("ofAppGLFWWindow") << "WINDOW MODE IS " << screenMode; - - glfwDefaultWindowHints(); - glfwWindowHint(GLFW_RED_BITS, settings.redBits); - glfwWindowHint(GLFW_GREEN_BITS, settings.greenBits); - glfwWindowHint(GLFW_BLUE_BITS, settings.blueBits); - glfwWindowHint(GLFW_ALPHA_BITS, settings.alphaBits); - glfwWindowHint(GLFW_DEPTH_BITS, settings.depthBits); - glfwWindowHint(GLFW_STENCIL_BITS, settings.stencilBits); - glfwWindowHint(GLFW_STEREO, settings.stereo); - glfwWindowHint(GLFW_VISIBLE, GL_FALSE); - glfwWindowHint(GLFW_MAXIMIZED, settings.maximized); + glfwDefaultWindowHints(); + glfwWindowHint(GLFW_RED_BITS, settings.redBits); + glfwWindowHint(GLFW_GREEN_BITS, settings.greenBits); + glfwWindowHint(GLFW_BLUE_BITS, settings.blueBits); + glfwWindowHint(GLFW_ALPHA_BITS, settings.alphaBits); + glfwWindowHint(GLFW_DEPTH_BITS, settings.depthBits); + glfwWindowHint(GLFW_STENCIL_BITS, settings.stencilBits); + glfwWindowHint(GLFW_STEREO, settings.stereo); + glfwWindowHint(GLFW_VISIBLE, GL_FALSE); + glfwWindowHint(GLFW_MAXIMIZED, settings.maximized); + // FIXME: Review this. #ifndef TARGET_OSX - glfwWindowHint(GLFW_AUX_BUFFERS, settings.doubleBuffering ? 1 : 0); + glfwWindowHint(GLFW_AUX_BUFFERS, settings.doubleBuffering ? 1 : 0); #else - glfwWindowHint(GLFW_DOUBLEBUFFER, settings.doubleBuffering ? 1 : 0); + glfwWindowHint(GLFW_DOUBLEBUFFER, settings.doubleBuffering ? 1 : 0); #endif - glfwWindowHint(GLFW_SAMPLES, settings.numSamples); - glfwWindowHint(GLFW_RESIZABLE, settings.resizable); - glfwWindowHint(GLFW_DECORATED, settings.decorated); - + glfwWindowHint(GLFW_SAMPLES, settings.numSamples); + glfwWindowHint(GLFW_RESIZABLE, settings.resizable); + glfwWindowHint(GLFW_DECORATED, settings.decorated); + #ifdef TARGET_OPENGLES - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, settings.glesVersion); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); - if (settings.glesVersion >= 2) { - currentRenderer = std::make_shared(this); - } else { - currentRenderer = std::make_shared(this); - } + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, settings.glesVersion); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + if (settings.glesVersion >= 2) { + currentRenderer = std::make_shared(this); + } else { + currentRenderer = std::make_shared(this); + } #else - glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, settings.glVersionMajor); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, settings.glVersionMinor); - if ((settings.glVersionMajor == 3 && settings.glVersionMinor >= 2) || settings.glVersionMajor >= 4) { - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - } - if (settings.glVersionMajor >= 3) { - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -#if (GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR > 2) || (GLFW_VERSION_MAJOR > 3) - glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, settings.transparent); -#endif -#if (GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR >= 4) - if( settings.mousePassThrough && settings.transparent && settings.decorated) { - ofLogError("ofAppGLFWWindow") << "window is decorated and has transparent input pass through. use floating..."; - } - glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, settings.mousePassThrough); - glfwWindowHint(GLFW_FLOATING, settings.floating); -#endif - currentRenderer = std::make_shared(this); - } else { - currentRenderer = std::make_shared(this); - } -#endif - - GLFWwindow * sharedContext = nullptr; - if (settings.shareContextWith) { - sharedContext = (GLFWwindow *)settings.shareContextWith->getWindowContext(); - } - - if (settings.windowMode == OF_GAME_MODE) { - int count; - GLFWmonitor ** monitors = glfwGetMonitors(&count); - if (settings.monitor >= count) { - ofLogError("ofAppGLFWWindow") << "requested game mode monitor is: " << settings.monitor << " monitor count is: " << count; - } - settings.monitor = ofClamp(settings.monitor, 0, count - 1); - if (settings.isSizeSet()) { - currentW = settings.getWidth(); - currentH = settings.getHeight(); - } else { - auto mode = glfwGetVideoMode(monitors[settings.monitor]); - currentW = mode->width; - currentH = mode->height; - } - if (count > settings.monitor) { - windowP = glfwCreateWindow(currentW, currentH, settings.title.c_str(), monitors[settings.monitor], sharedContext); - } else { - ofLogError("ofAppGLFWWindow") << "couldn't find any monitors"; - return; - } - } else { - windowP = glfwCreateWindow(settings.getWidth(), settings.getHeight(), settings.title.c_str(), nullptr, sharedContext); - if (!windowP) { - ofLogError("ofAppGLFWWindow") << "couldn't create GLFW window"; - return; - } - if (settings.windowMode == OF_FULLSCREEN) { - int count = 0; - auto monitors = glfwGetMonitors(&count); - if (settings.monitor >= count) { - ofLogError("ofAppGLFWWindow") << "requested fullscreen monitor is: " << settings.monitor << " monitor count is: " << count; - } - settings.monitor = ofClamp(settings.monitor, 0, count - 1); - - auto mode = glfwGetVideoMode(monitors[settings.monitor]); - currentW = mode->width; - currentH = mode->height; - if (!settings.isPositionSet()) { - if (count > 0) { - int x = 0, y = 0; - glfwGetMonitorPos(monitors[settings.monitor], &x, &y); - settings.setPosition(glm::vec2(x, y)); - setWindowPosition(settings.getPosition().x, settings.getPosition().y); - auto mode = glfwGetVideoMode(monitors[settings.monitor]); -#ifdef TARGET_OSX - //for OS X we need to set this first as the window size affects the window positon - settings.setSize(mode->width, mode->height); -#endif - setWindowPosition(settings.getPosition().x, settings.getPosition().y); - currentW = mode->width; - currentH = mode->height; - } - } else { - setWindowPosition(settings.getPosition().x, settings.getPosition().y); -#ifdef TARGET_OSX - auto size = getScreenSize(); - settings.setSize(size.x, size.y); + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, settings.glVersionMajor); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, settings.glVersionMinor); + if ((settings.glVersionMajor == 3 && settings.glVersionMinor >= 2) || settings.glVersionMajor >= 4) { + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + } + if (settings.glVersionMajor >= 3) { + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + #if (GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR > 2) || (GLFW_VERSION_MAJOR > 3) + glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, settings.transparent); + #endif + currentRenderer = std::make_shared(this); + } else { + currentRenderer = std::make_shared(this); + } #endif - currentW = settings.getWidth(); - currentH = settings.getHeight(); - for (int i = 0; i < count; i++) { - int x = 0, y = 0; - glfwGetMonitorPos(monitors[i], &x, &y); - auto mode = glfwGetVideoMode(monitors[i]); - int w = mode->width; - int h = mode->height; - ofRectangle rect(x - 1, y - 1, w + 1, h + 1); - if (rect.inside(settings.getPosition())) { - currentW = mode->width; - currentH = mode->height; - break; - } - } - } - targetWindowMode = settings.windowMode; - settings.windowMode = OF_WINDOW; - if (settings.maximized) { - glfwMaximizeWindow(windowP); - } - } else { - if (settings.isPositionSet()) { - setWindowPosition(settings.getPosition().x, settings.getPosition().y); - } - glfwGetWindowSize(windowP, ¤tW, ¤tH); - } + + GLFWwindow * sharedContext = nullptr; + if (settings.shareContextWith) { + sharedContext = (GLFWwindow *)settings.shareContextWith->getWindowContext(); + } + + allMonitors.update(); + // ofLogNotice("ofAppGLFWWindow") << "WINDOW MODE IS " << screenMode; + + + GLFWmonitor *monitor = nullptr; + + + // FIXME: maybe use as a global variable for the window? + bool hideWindow = false; + + int monitorIndex = 0; + // Check to see if desired monitor is connected. + if (allMonitors.rects.size() > settings.monitor) { + monitorIndex = settings.monitor; + } else { + if (settings.showOnlyInSelectedMonitor) { + hideWindow = true; + } + ofLogError("ofAppGLFWWindow") << "requested monitor is: " << settings.monitor << " monitor count is: " << allMonitors.rects.size(); + } + + if (settings.windowMode == OF_GAME_MODE) + { + windowRect = allMonitors.rects[monitorIndex]; + monitor = allMonitors.monitors[monitorIndex]; + } + +// cout << "will create window" << endl; +// cout << "monitors size: " << allMonitors.rects.size() << endl; + bool displayOK = false; + if (settings.fullscreenDisplays.size()) { + for (auto & d : settings.fullscreenDisplays) { + cout << "GLFWWindow fullscreenDisplays " << d << " : " << allMonitors.rects.size() << endl; + if (d < allMonitors.rects.size()) { +// cout << "glfw ok opening " << endl; + displayOK = true; +// break; + } else { +// cout << "glfw not enough displays" << endl; +// return nullptr; + } +// cout << d << endl; + } + } else { + displayOK = true; + } + +// cout << "glfw displayok " << displayOK << endl; + windowP = glfwCreateWindow(settings.getWidth(), settings.getHeight(), settings.title.c_str(), monitor, sharedContext); + + if (displayOK) { + glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); + } else { + // MARK: - WINDOW +// cout << "glfw hint visible false" << endl; + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); +// return; + } + + + if (!windowP) { + ofLogError("ofAppGLFWWindow") << "couldn't create GLFW window"; + return; + } + + // saves window rectangle just created. + windowRect = getWindowRect(); + + + if (settings.windowMode == OF_WINDOW || settings.windowMode == OF_FULLSCREEN) { + if (settings.isPositionSet()) { + windowRect.x = settings.getPosition().x; + windowRect.y = settings.getPosition().y; + } + + if (monitorIndex > 0) { + windowRect.x += allMonitors.rects[monitorIndex].x; + windowRect.y += allMonitors.rects[monitorIndex].y; + // now it will trigger isPositionSet() as true + settings.setPosition({ windowRect.x, windowRect.y }); + } + + if (settings.isPositionSet()) { + setWindowRect(windowRect); + } else { + setWindowShape(windowRect.width, windowRect.height); + } + } + + + + + // MARK: - + if (settings.windowMode != OF_GAME_MODE) { + #ifdef TARGET_LINUX - if (!iconSet) { - ofPixels iconPixels; -#ifdef DEBUG - iconPixels.allocate(ofIconDebug.width, ofIconDebug.height, ofIconDebug.bytes_per_pixel); - GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(), ofIconDebug.rle_pixel_data, iconPixels.getWidth() * iconPixels.getHeight(), ofIconDebug.bytes_per_pixel); -#else - iconPixels.allocate(ofIcon.width, ofIcon.height, ofIcon.bytes_per_pixel); - GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(), ofIcon.rle_pixel_data, iconPixels.getWidth() * iconPixels.getHeight(), ofIcon.bytes_per_pixel); -#endif - setWindowIcon(iconPixels); - } -#endif - if (settings.iconified) { - iconify(true); - } - } - - //don't try and show a window if its been requsted to be hidden - bWindowNeedsShowing = settings.visible; - - glfwSetWindowUserPointer(windowP, this); - - windowW = settings.getWidth(); - windowH = settings.getHeight(); - -#ifdef TARGET_RASPBERRY_PI - windowRect.width = windowW; - windowRect.height = windowH; +// if (!iconSet) { +// ofPixels iconPixels; +// // FIXME: we can have this define in ofIcon.h instead +// #ifdef DEBUG +// iconPixels.allocate(ofIconDebug.width, ofIconDebug.height, ofIconDebug.bytes_per_pixel); +// GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(), ofIconDebug.rle_pixel_data, iconPixels.getWidth() * iconPixels.getHeight(), ofIconDebug.bytes_per_pixel); +// #else +// iconPixels.allocate(ofIcon.width, ofIcon.height, ofIcon.bytes_per_pixel); +// GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(), ofIcon.rle_pixel_data, iconPixels.getWidth() * iconPixels.getHeight(), ofIcon.bytes_per_pixel); +// #endif +// setWindowIcon(iconPixels); +// } #endif - - glfwMakeContextCurrent(windowP); - - int framebufferW, framebufferH, tmpWindowW, tmpWindowH; - glfwGetFramebufferSize(windowP, &framebufferW, &framebufferH); - glfwGetWindowSize(windowP, &tmpWindowW, &tmpWindowH); - - //this lets us detect if the window is running in a retina mode - if (framebufferW != tmpWindowW) { - pixelScreenCoordScale = (float)framebufferW / (float)tmpWindowW; - if (pixelScreenCoordScale < 1) { - pixelScreenCoordScale = 1; - } - - if (targetWindowMode == OF_WINDOW) { - auto position = getWindowPosition(); - setWindowShape(windowW, windowH); - setWindowPosition(position.x, position.y); - } - } - + + //FIXME: check if it works with hint GLFW_AUTO_ICONIFY + if (settings.iconified) { + iconify(true); + } + + //FIXME: check if it works with hint GLFW_MAXIMIZED + if (settings.maximized) { + glfwMaximizeWindow(windowP); + } + } + + //don't try and show a window if its been requsted to be hidden + bWindowNeedsShowing = settings.visible; + if (hideWindow) { + bWindowNeedsShowing = false; +// cout << "HIDE U" << endl; + } + + glfwSetWindowUserPointer(windowP, this); + glfwMakeContextCurrent(windowP); + +// windowMode = settings.windowMode; + #ifndef TARGET_OPENGLES - static bool inited = false; - if (!inited) { - glewExperimental = GL_TRUE; - GLenum err = glewInit(); - if (GLEW_OK != err) { - /* Problem: glewInit failed, something is seriously wrong. */ - ofLogError("ofAppRunner") << "couldn't init GLEW: " << glewGetErrorString(err); - return; - } - inited = true; - } + static bool inited = false; + if (!inited) { + glewExperimental = GL_TRUE; + GLenum err = glewInit(); + if (GLEW_OK != err) { + /* Problem: glewInit failed, something is seriously wrong. */ + ofLogError("ofAppRunner") << "couldn't init GLEW: " << glewGetErrorString(err); + return; + } + inited = true; + } #endif - - ofLogVerbose() << "GL Version: " << glGetString(GL_VERSION); - - if (currentRenderer->getType() == ofGLProgrammableRenderer::TYPE) { + + ofLogVerbose() << "GL Version: " << glGetString(GL_VERSION); + + if (currentRenderer->getType() == ofGLProgrammableRenderer::TYPE) { #ifndef TARGET_OPENGLES - static_cast(currentRenderer.get())->setup(settings.glVersionMajor, settings.glVersionMinor); + static_cast(currentRenderer.get())->setup(settings.glVersionMajor, settings.glVersionMinor); #else - static_cast(currentRenderer.get())->setup(settings.glesVersion, 0); + static_cast(currentRenderer.get())->setup(settings.glesVersion, 0); #endif - } else { - static_cast(currentRenderer.get())->setup(); - } - - setVerticalSync(true); - glfwSetMouseButtonCallback(windowP, mouse_cb); - glfwSetCursorPosCallback(windowP, motion_cb); - glfwSetCursorEnterCallback(windowP, entry_cb); - glfwSetKeyCallback(windowP, keyboard_cb); - glfwSetCharCallback(windowP, char_cb); - glfwSetWindowSizeCallback(windowP, resize_cb); - glfwSetWindowPosCallback(windowP,position_cb); - glfwSetFramebufferSizeCallback(windowP, framebuffer_size_cb); - glfwSetWindowCloseCallback(windowP, exit_cb); - glfwSetScrollCallback(windowP, scroll_cb); - glfwSetDropCallback(windowP, drop_cb); - glfwSetWindowRefreshCallback(windowP, refresh_cb); - + } else { + static_cast(currentRenderer.get())->setup(); + } + +// setVerticalSync(true); + glfwSetMonitorCallback( monitor_cb ); + + glfwSetMouseButtonCallback(windowP, mouse_cb); + glfwSetCursorPosCallback(windowP, motion_cb); + glfwSetCursorEnterCallback(windowP, entry_cb); + glfwSetKeyCallback(windowP, keyboard_cb); + glfwSetCharCallback(windowP, char_cb); + glfwSetWindowSizeCallback(windowP, resize_cb); + glfwSetWindowPosCallback(windowP,position_cb); + glfwSetFramebufferSizeCallback(windowP, framebuffer_size_cb); + glfwSetWindowCloseCallback(windowP, exit_cb); + glfwSetScrollCallback(windowP, scroll_cb); + glfwSetDropCallback(windowP, drop_cb); + glfwSetWindowRefreshCallback(windowP, refresh_cb); + #ifdef TARGET_LINUX - XSetLocaleModifiers(""); - xim = XOpenIM(getX11Display(), 0, 0, 0); - if (!xim) { - // fallback to internal input method - XSetLocaleModifiers("@im=none"); - xim = XOpenIM(getX11Display(), 0, 0, 0); - } - xic = XCreateIC(xim, - XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, getX11Window(), - XNFocusWindow, getX11Window(), - NULL); + XSetLocaleModifiers(""); + xim = XOpenIM(getX11Display(), 0, 0, 0); + if (!xim) { + // fallback to internal input method + XSetLocaleModifiers("@im=none"); + xim = XOpenIM(getX11Display(), 0, 0, 0); + } + xic = XCreateIC(xim, + XNInputStyle, XIMPreeditNothing | XIMStatusNothing, + XNClientWindow, getX11Window(), + XNFocusWindow, getX11Window(), + NULL); #endif - } - + +} + #ifdef TARGET_LINUX //------------------------------------------------------------ void ofAppGLFWWindow::setWindowIcon(const of::filesystem::path & path) { @@ -441,1301 +382,1034 @@ void ofAppGLFWWindow::setup(const ofGLESWindowSettings & settings) { XFlush(getX11Display()); } #endif - - //-------------------------------------------- - ofCoreEvents & ofAppGLFWWindow::events() { - return *coreEvents; - } - - //-------------------------------------------- - shared_ptr & ofAppGLFWWindow::renderer() { - return currentRenderer; - } - - //-------------------------------------------- - void ofAppGLFWWindow::update() { - events().notifyUpdate(); - - //show the window right before the first draw call. - if (bWindowNeedsShowing && windowP) { - glfwShowWindow(windowP); - bWindowNeedsShowing = false; - if (targetWindowMode == OF_FULLSCREEN) { - setFullscreen(true); - } - } - -#ifdef TARGET_RASPBERRY_PI - //needed for rpi. as good values don't come into resize_cb when coming out of fullscreen - if (needsResizeCheck && windowP) { - int winW, winH; - glfwGetWindowSize(windowP, &winW, &winH); - - //wait until the window size is the size it was before going fullscreen - //then stop the resize check - if (winW == windowRect.getWidth() && winH == windowRect.getHeight()) { - resize_cb(windowP, currentW, currentH); - needsResizeCheck = false; - } - } -#endif - } - - //-------------------------------------------- - void ofAppGLFWWindow::pollEvents() { - glfwPollEvents(); - } - - //-------------------------------------------- - void ofAppGLFWWindow::draw() { - currentRenderer->startRender(); - if (bEnableSetupScreen) currentRenderer->setupScreen(); - - events().notifyDraw(); - -#ifdef TARGET_WIN32 - if (currentRenderer->getBackgroundAuto() == false) { - // on a PC resizing a window with this method of accumulation (essentially single buffering) - // is BAD, so we clear on resize events. - if (nFramesSinceWindowResized < 3) { - currentRenderer->clear(); - } else { - if ((events().getFrameNum() < 3 || nFramesSinceWindowResized < 3) && settings.doubleBuffering) { - glfwSwapBuffers(windowP); - } else { - glFlush(); - } - } - } else { - if (settings.doubleBuffering) { - glfwSwapBuffers(windowP); - } else { - glFlush(); - } - } -#else - if (currentRenderer->getBackgroundAuto() == false) { - // in accum mode resizing a window is BAD, so we clear on resize events. - if (nFramesSinceWindowResized < 3) { - currentRenderer->clear(); - } - } - if (settings.doubleBuffering) { - glfwSwapBuffers(windowP); - } else { - glFlush(); - } -#endif - - currentRenderer->finishRender(); - - nFramesSinceWindowResized++; - } - - //-------------------------------------------- - void ofAppGLFWWindow::swapBuffers() { - glfwSwapBuffers(windowP); - } - - //-------------------------------------------- - void ofAppGLFWWindow::startRender() { - renderer()->startRender(); - } - - //-------------------------------------------- - void ofAppGLFWWindow::finishRender() { - renderer()->finishRender(); - } - - //-------------------------------------------- - bool ofAppGLFWWindow::getWindowShouldClose() { - return glfwWindowShouldClose(windowP); - } - - //-------------------------------------------- - void ofAppGLFWWindow::setWindowShouldClose() { - glfwSetWindowShouldClose(windowP, 1); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setWindowTitle(std::string title) { - settings.title = title; - glfwSetWindowTitle(windowP, settings.title.c_str()); - } - - //------------------------------------------------------------ - int ofAppGLFWWindow::getPixelScreenCoordScale() { - return pixelScreenCoordScale; - } - - //------------------------------------------------------------ - glm::vec2 ofAppGLFWWindow::getWindowSize() { - if (settings.windowMode == OF_GAME_MODE) { - const GLFWvidmode * desktopMode = glfwGetVideoMode(glfwGetWindowMonitor(windowP)); - if (desktopMode) { - return { desktopMode->width * pixelScreenCoordScale, desktopMode->height * pixelScreenCoordScale }; - } else { - return { currentW * pixelScreenCoordScale, currentH * pixelScreenCoordScale }; - } - } else { - return { currentW * pixelScreenCoordScale, currentH * pixelScreenCoordScale }; - } - } - - //------------------------------------------------------------ - glm::vec2 ofAppGLFWWindow::getWindowPosition() { - int x, y; - glfwGetWindowPos(windowP, &x, &y); - - x *= pixelScreenCoordScale; - y *= pixelScreenCoordScale; - - if (orientation == OF_ORIENTATION_DEFAULT || orientation == OF_ORIENTATION_180) { - return glm::vec2 { x, y }; - } else { - return glm::vec2(x, y); //NOTE: shouldn't this be (y,x) ?????? - } - } - - //------------------------------------------------------------ - int ofAppGLFWWindow::getCurrentMonitor() { - int numberOfMonitors; - GLFWmonitor ** monitors = glfwGetMonitors(&numberOfMonitors); - - int xW; - int yW; - glfwGetWindowPos(windowP, &xW, &yW); - - for (int iC = 0; iC < numberOfMonitors; iC++) { - int xM; - int yM; - glfwGetMonitorPos(monitors[iC], &xM, &yM); - const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[iC]); - ofRectangle monitorRect(xM, yM, desktopMode->width, desktopMode->height); - bool bPointMatch = xW >= monitorRect.getMinX() && yW >= monitorRect.getMinY() && xW < monitorRect.getMaxX() && yW < monitorRect.getMaxY(); - // if (monitorRect.inside(xW, yW)){ - if (bPointMatch) { - return iC; - break; - } - } - return 0; - } - - //------------------------------------------------------------ - glm::vec2 ofAppGLFWWindow::getScreenSize() { - int count; - GLFWmonitor ** monitors = glfwGetMonitors(&count); - if (count > 0) { - int currentMonitor = getCurrentMonitor(); - const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[currentMonitor]); - if (desktopMode) { - if (orientation == OF_ORIENTATION_DEFAULT || orientation == OF_ORIENTATION_180) { - return { desktopMode->width * pixelScreenCoordScale, desktopMode->height * pixelScreenCoordScale }; - } else { - return { desktopMode->height * pixelScreenCoordScale, desktopMode->width * pixelScreenCoordScale }; - } - } - } - return glm::vec2(); - } - - //------------------------------------------------------------ - int ofAppGLFWWindow::getWidth() { - if (orientation == OF_ORIENTATION_DEFAULT || orientation == OF_ORIENTATION_180) { - return currentW * pixelScreenCoordScale; - } else { - return currentH * pixelScreenCoordScale; - } - } - - //------------------------------------------------------------ - int ofAppGLFWWindow::getHeight() { - if (orientation == OF_ORIENTATION_DEFAULT || orientation == OF_ORIENTATION_180) { - return currentH * pixelScreenCoordScale; - } else { - return currentW * pixelScreenCoordScale; - } - } - - //------------------------------------------------------------ - GLFWwindow * ofAppGLFWWindow::getGLFWWindow() { - return windowP; - } - - //------------------------------------------------------------ - ofWindowMode ofAppGLFWWindow::getWindowMode() { - return settings.windowMode; - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setWindowPosition(int x, int y) { - glfwSetWindowPos(windowP, x / pixelScreenCoordScale, y / pixelScreenCoordScale); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setWindowShape(int w, int h) { - if (settings.windowMode == OF_WINDOW) { - windowW = w; - windowH = h; - } - currentW = w / pixelScreenCoordScale; - currentH = h / pixelScreenCoordScale; - + +//-------------------------------------------- +ofCoreEvents & ofAppGLFWWindow::events() { + return *coreEvents; +} + +//-------------------------------------------- +shared_ptr & ofAppGLFWWindow::renderer() { + return currentRenderer; +} + +//-------------------------------------------- +void ofAppGLFWWindow::update() { + events().notifyUpdate(); + //show the window right before the first draw call. + if (bWindowNeedsShowing && windowP) { + // not working. #ifdef TARGET_OSX - auto pos = getWindowPosition(); - glfwSetWindowSize(windowP, currentW, currentH); - if (pos != getWindowPosition()) { - setWindowPosition(pos.x, pos.y); - } -#else - glfwSetWindowSize(windowP, currentW, currentH); -#endif - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::hideCursor() { - if (settings.windowMode == OF_FULLSCREEN || settings.windowMode == OF_GAME_MODE) { - glfwSetInputMode(windowP, GLFW_CURSOR, GLFW_CURSOR_DISABLED); - } else { - glfwSetInputMode(windowP, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); - } - }; - - //------------------------------------------------------------ - void ofAppGLFWWindow::showCursor() { - glfwSetInputMode(windowP, GLFW_CURSOR, GLFW_CURSOR_NORMAL); - }; - - //------------------------------------------------------------ - void ofAppGLFWWindow::enableSetupScreen() { - bEnableSetupScreen = true; - }; - - //------------------------------------------------------------ - void ofAppGLFWWindow::disableSetupScreen() { - bEnableSetupScreen = false; - }; - - //------------------------------------------------------------ - void ofAppGLFWWindow::setFullscreen(bool fullscreen) { - if (fullscreen) { - targetWindowMode = OF_FULLSCREEN; - } else { - targetWindowMode = OF_WINDOW; - } - -#if defined(TARGET_OSX) - NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP); - if (([cocoaWindow styleMask] & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen) { - settings.windowMode = OF_FULLSCREEN; - if (targetWindowMode == OF_WINDOW) { - [cocoaWindow toggleFullScreen:nil]; - } - } else { - [cocoaWindow setHasShadow:NO]; - } -#endif - - //we only want to change window mode if the requested window is different to the current one. - bool bChanged = targetWindowMode != settings.windowMode; - if (!bChanged) { - return; - } - -#ifdef TARGET_LINUX -#include - - Window nativeWin = glfwGetX11Window(windowP); - Display * display = glfwGetX11Display(); - if (targetWindowMode == OF_FULLSCREEN) { - -#ifdef TARGET_RASPBERRY_PI - // save window shape before going fullscreen - if (windowP) { - int tmpW, tmpH; - glfwGetWindowSize(windowP, &tmpW, &tmpH); - windowRect.setSize(tmpW, tmpH); - } -#endif - - int monitorCount; - GLFWmonitor ** monitors = glfwGetMonitors(&monitorCount); - if (settings.multiMonitorFullScreen && monitorCount > 1) { - // find the monitors at the edges of the virtual desktop - int minx = numeric_limits::max(); - int miny = numeric_limits::max(); - int maxx = numeric_limits::min(); - int maxy = numeric_limits::min(); - int x, y, w, h; - int monitorLeft = 0, monitorRight = 0, monitorTop = 0, monitorBottom = 0; - for (int i = 0; i < monitorCount; i++) { - glfwGetMonitorPos(monitors[i], &x, &y); - auto videoMode = glfwGetVideoMode(monitors[i]); - w = videoMode->width; - h = videoMode->height; - if (x < minx) { - monitorLeft = i; - minx = x; - } - if (y < miny) { - monitorTop = i; - miny = y; - } - if (x + w > maxx) { - monitorRight = i; - maxx = x + w; - } - if (y + h > maxy) { - monitorBottom = i; - maxy = y + h; - } - } - - // send fullscreen_monitors event with the edges monitors - Atom m_net_fullscreen_monitors = XInternAtom(display, "_NET_WM_FULLSCREEN_MONITORS", false); - - XEvent xev; - - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.window = nativeWin; - xev.xclient.message_type = m_net_fullscreen_monitors; - xev.xclient.format = 32; - - xev.xclient.data.l[0] = monitorTop; - xev.xclient.data.l[1] = monitorBottom; - xev.xclient.data.l[2] = monitorLeft; - xev.xclient.data.l[3] = monitorRight; - xev.xclient.data.l[4] = 1; - XSendEvent(display, RootWindow(display, DefaultScreen(display)), - False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); - currentW = maxx - minx; - currentH = maxy - minx; - } else { - auto monitor = glfwGetWindowMonitor(windowP); - if (monitor) { - auto videoMode = glfwGetVideoMode(monitor); - if (videoMode) { - currentW = videoMode->width; - currentH = videoMode->height; - } - } - } - } - - // send fullscreen event - Atom m_net_state = XInternAtom(display, "_NET_WM_STATE", false); - Atom m_net_fullscreen = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", false); - - XEvent xev; - - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.window = nativeWin; - xev.xclient.message_type = m_net_state; - xev.xclient.format = 32; - - if (fullscreen) - xev.xclient.data.l[0] = 1; - else - xev.xclient.data.l[0] = 0; - - xev.xclient.data.l[1] = m_net_fullscreen; - xev.xclient.data.l[2] = 0; - xev.xclient.data.l[3] = 0; - xev.xclient.data.l[4] = 0; - XSendEvent(display, RootWindow(display, DefaultScreen(display)), - False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); - - // tell the window manager to bypass composition for this window in fullscreen for speed - // it'll probably help solving vsync issues - Atom m_bypass_compositor = XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False); - unsigned long value = fullscreen ? 1 : 0; - XChangeProperty(display, nativeWin, m_bypass_compositor, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&value, 1); - - XFlush(display); - -#ifdef TARGET_RASPBERRY_PI - if (!fullscreen) { - needsResizeCheck = true; - } + NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP); +// [cocoaWindow setLevel:NSScreenSaverWindowLevel + 1]; + [cocoaWindow orderFrontRegardless]; #endif - - // setWindowShape(windowW, windowH); - -#elif defined(TARGET_OSX) - - if (targetWindowMode == OF_FULLSCREEN) { - //---------------------------------------------------- - [NSApp setPresentationOptions:NSApplicationPresentationHideMenuBar | NSApplicationPresentationHideDock]; - NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP); - - [cocoaWindow setStyleMask:NSWindowStyleMaskBorderless]; - - int monitorCount; - GLFWmonitor ** monitors = glfwGetMonitors(&monitorCount); - - int currentMonitor = getCurrentMonitor(); - auto screenSize = getScreenSize(); - - if (orientation == OF_ORIENTATION_90_LEFT || orientation == OF_ORIENTATION_90_RIGHT) { - std::swap(screenSize.x, screenSize.y); - } - - ofRectangle allScreensSpace; - - // save window shape before going fullscreen - auto pos = getWindowPosition(); - auto size = getWindowSize(); - windowRect.x = pos.x; - windowRect.y = pos.y; - windowRect.width = size.x; - windowRect.height = size.y; - - if (settings.multiMonitorFullScreen && monitorCount > 1) { - - //calc the sum Rect of all the monitors - for (int i = 0; i < monitorCount; i++) { - const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[i]); - int x, y; - glfwGetMonitorPos(monitors[i], &x, &y); - ofRectangle screen = ofRectangle(x, y, desktopMode->width, desktopMode->height); - allScreensSpace = allScreensSpace.getUnion(screen); - } - //for OS X we need to set this first as the window size affects the window positon - //need to account for the pixel density factor when we're getting the values from glfw - setWindowShape(allScreensSpace.width * pixelScreenCoordScale, allScreensSpace.height * pixelScreenCoordScale); - setWindowPosition(allScreensSpace.x, allScreensSpace.y); - - } else if (monitorCount > 1 && currentMonitor < monitorCount) { - int xpos; - int ypos; - glfwGetMonitorPos(monitors[currentMonitor], &xpos, &ypos); - - // Scale (if needed) to physical pixels size, since setWindowPosition - // uses physical pixel dimensions. On HIDPI screens pixelScreenCoordScale - // is likely to be 2, on "normal" screens pixelScreenCoordScale will be 1: - xpos *= pixelScreenCoordScale; - ypos *= pixelScreenCoordScale; - - //we do this as setWindowShape affects the position of the monitor - //normally we would just call setWindowShape first, but on multi monitor you see the window bleed onto the second monitor as it first changes shape and is then repositioned. - //this first moves it over in X, does the screen resize and then by calling it again its set correctly in y. - setWindowPosition(xpos, ypos); - setWindowShape(screenSize.x, screenSize.y); - setWindowPosition(xpos, ypos); - } else { - //for OS X we need to set this first as the window size affects the window positon - setWindowShape(screenSize.x, screenSize.y); - setWindowPosition(0, 0); - } - - // make sure to save current pos if not specified in settings - if (settings.isPositionSet()) { - auto pos = getWindowPosition(); - settings.setPosition(ofVec2f(pos.x, pos.y)); - } - - //make sure the window is getting the mouse/key events - [cocoaWindow makeFirstResponder:cocoaWindow.contentView]; - - } else if (targetWindowMode == OF_WINDOW) { - - // set window shape if started in fullscreen - if (windowRect.width == 0 && windowRect.height == 0) { - windowRect.x = getWindowPosition().x; - windowRect.y = getWindowPosition().y; - windowRect.width = getWindowSize().x; - windowRect.height = getWindowSize().y; - } - - setWindowShape(windowRect.width, windowRect.height); - setWindowTitle(settings.title); - - [NSApp setPresentationOptions:NSApplicationPresentationDefault]; - NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP); - [cocoaWindow setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable]; - - //---------------------------------------------------- - // if we have recorded the screen position, put it there - // if not, better to let the system do it (and put it where it wants) - if (ofGetFrameNum() > 0) { - setWindowPosition(windowRect.x, windowRect.y); - } - - //---------------------------------------------------- - //make sure the window is getting the mouse/key events - [cocoaWindow makeFirstResponder:cocoaWindow.contentView]; - } + + bWindowNeedsShowing = false; + + if (settings.windowMode == OF_FULLSCREEN) { + // Meant to trigger fullscreen forced + settings.windowMode = OF_WINDOWMODE_UNDEFINED; + setFullscreen(true); + } else { + setFullscreen(false); + } + + // FIXME: Test only + if (settings.opacity != 1.0) { + glfwSetWindowOpacity(windowP, settings.opacity); + } + +// cout << "SHOW WINDOW! " << settings.windowName << endl; + glfwShowWindow(windowP); + +// cout << "after show window rect " << getWindowRect() << endl; + } +} + +//-------------------------------------------- +void ofAppGLFWWindow::pollEvents() { + glfwPollEvents(); +} + + +//-------------------------------------------- +void ofAppGLFWWindow::beginDraw() { + currentRenderer->startRender(); + if (bEnableSetupScreen) { + currentRenderer->setupScreen(); + } +} + +//-------------------------------------------- +void ofAppGLFWWindow::endDraw() { + if (settings.doubleBuffering) { + glfwSwapBuffers(windowP); + // std::cout << "swap buffers " << ofGetFrameNum() << std::endl; + } else { + std::cout << "flush " << ofGetFrameNum() << " : " << settings.windowName << std::endl; + glFlush(); + } + + currentRenderer->finishRender(); +} + +//-------------------------------------------- +void ofAppGLFWWindow::draw() { + currentRenderer->startRender(); + if (bEnableSetupScreen) { + currentRenderer->setupScreen(); + } + + events().notifyDraw(); + + if (settings.doubleBuffering) { + glfwSwapBuffers(windowP); + // std::cout << "swap buffers " << ofGetFrameNum() << std::endl; + } else { + glFlush(); + } + + currentRenderer->finishRender(); +} + +//-------------------------------------------- +void ofAppGLFWWindow::swapBuffers() { + glfwSwapBuffers(windowP); +} + +//-------------------------------------------- +void ofAppGLFWWindow::startRender() { + renderer()->startRender(); +} + +//-------------------------------------------- +void ofAppGLFWWindow::finishRender() { + renderer()->finishRender(); +} + +//-------------------------------------------- +bool ofAppGLFWWindow::getWindowShouldClose() { + return glfwWindowShouldClose(windowP); +} + +//-------------------------------------------- +void ofAppGLFWWindow::setWindowShouldClose() { + glfwSetWindowShouldClose(windowP, 1); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setWindowTitle(const std::string & title) { + settings.title = title; + glfwSetWindowTitle(windowP, settings.title.c_str()); +} + +//------------------------------------------------------------ +int ofAppGLFWWindow::getPixelScreenCoordScale() { + // FIXME: cache? + glm::vec2 contentScale; + glfwGetWindowContentScale(windowP, &contentScale.x, &contentScale.y); + return contentScale.x; +} + +//------------------------------------------------------------ +ofRectangle ofAppGLFWWindow::getWindowRect() { + glm::ivec2 pos; + glfwGetWindowPos( windowP, &pos.x, &pos.y ); + glm::ivec2 size; + glfwGetWindowSize(windowP, &size.x, &size.y); + return ofRectangle(pos.x, pos.y, size.x, size.y); +} + +//------------------------------------------------------------ +glm::ivec2 ofAppGLFWWindow::getWindowSize() { + glm::ivec2 size; + glfwGetWindowSize(windowP, &size.x, &size.y); + return size; +} + +//------------------------------------------------------------ +glm::ivec2 ofAppGLFWWindow::getFramebufferSize() { + // FIXME: cache size and handle in framebuffer_size_cb + glm::ivec2 size; + glfwGetFramebufferSize(windowP, &size.x, &size.y); +// cout << "getFramebufferSize " << settings.windowName << " : " << size << " : " << ofGetFrameNum() << endl; + return size; +} + +//------------------------------------------------------------ +glm::ivec2 ofAppGLFWWindow::getWindowPosition() { + glm::ivec2 pos; + glfwGetWindowPos( windowP, &pos.x, &pos.y ); + return pos; +} + +//------------------------------------------------------------ +glm::ivec2 ofAppGLFWWindow::getScreenSize() { + // it will return the monitor/screen size where the windows sit. + windowRect = getWindowRect(); + return allMonitors.getRectMonitorForScreenRect(windowRect).getSize(); +} + +//------------------------------------------------------------ +int ofAppGLFWWindow::getWidth() { + return windowRect.width; +} + +//------------------------------------------------------------ +int ofAppGLFWWindow::getHeight() { + return windowRect.height; +} + +//------------------------------------------------------------ +GLFWwindow * ofAppGLFWWindow::getGLFWWindow() { + return windowP; +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setWindowRect(const ofRectangle & rect) { +// cout << settings.windowName << " setWindowRect " << rect << endl; + + glfwSetWindowMonitor(windowP, NULL, rect.x, rect.y, rect.width, rect.height, GLFW_DONT_CARE); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setWindowPosition(int x, int y) { + glfwSetWindowPos(windowP, x, y); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setWindowShape(int w, int h) { +// cout << "setWindowShape " << w << " : " << h << endl; + glfwSetWindowSize(windowP, w, h); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::hideCursor() { + if (settings.windowMode == OF_FULLSCREEN || settings.windowMode == OF_GAME_MODE) { + glfwSetInputMode(windowP, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + } else { + glfwSetInputMode(windowP, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + } +}; + +//------------------------------------------------------------ +void ofAppGLFWWindow::showCursor() { + glfwSetInputMode(windowP, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +}; + +//------------------------------------------------------------ +void ofAppGLFWWindow::enableSetupScreen() { + bEnableSetupScreen = true; +}; + +//------------------------------------------------------------ +void ofAppGLFWWindow::disableSetupScreen() { + bEnableSetupScreen = false; +}; + +//------------------------------------------------------------ +void ofAppGLFWWindow::setFSTarget(ofWindowMode targetWindowMode) { +// cout << "setFSTarget " << targetWindowMode << endl; + if (targetWindowMode == OF_FULLSCREEN) { + // save window shape before going fullscreen + windowRect = getWindowRect(); +// cout << "saving window rect " << windowRect << endl; + + if (settings.multiMonitorFullScreen) { + windowRectFS = allMonitors.getRectForAllMonitors(); + } else { + windowRectFS = allMonitors.getRectMonitorForScreenRect(windowRect); + } + + // + if (settings.fullscreenDisplays.size()) { + windowRectFS = allMonitors.getRectFromMonitors(settings.fullscreenDisplays); + } +// cout << "windowRectFS " << windowRectFS << " : " << settings.windowName << endl; + setWindowRect(windowRectFS); + } + + else if (targetWindowMode == OF_WINDOW) { + setWindowRect(windowRect); + setWindowTitle(settings.title); + } +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setFullscreen(bool fullscreen) { +// cout << "setFullScreen " << fullscreen << " : " << settings.windowName << endl; + if (fullscreen) { + targetWindowMode = OF_FULLSCREEN; + } else { + targetWindowMode = OF_WINDOW; + } + + //we only want to change window mode if the requested window is different to the current one. + if (targetWindowMode == settings.windowMode) return; + +#ifdef TARGET_OSX + NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP); + + if (targetWindowMode == OF_FULLSCREEN) { + [NSApp setPresentationOptions:NSApplicationPresentationHideMenuBar | NSApplicationPresentationHideDock]; + [cocoaWindow setStyleMask:NSWindowStyleMaskBorderless]; + [cocoaWindow setHasShadow:NO]; + } else { + [NSApp setPresentationOptions:NSApplicationPresentationDefault]; + // to recover correctly from a green button fullscreen + if (([cocoaWindow styleMask] & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen) { + [cocoaWindow toggleFullScreen:nil]; + } + + [cocoaWindow setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable]; + [cocoaWindow setHasShadow:YES]; + } + setFSTarget(targetWindowMode); + + //---------------------------------------------------- + //make sure the window is getting the mouse/key events + [cocoaWindow makeFirstResponder:cocoaWindow.contentView]; + #elif defined(TARGET_WIN32) - if (targetWindowMode == OF_FULLSCREEN) { - // save window shape before going fullscreen - auto pos = getWindowPosition(); - auto size = getWindowSize(); - windowRect.x = pos.x; - windowRect.y = pos.y; - windowRect.width = size.x; - windowRect.height = size.y; - - //---------------------------------------------------- - HWND hwnd = glfwGetWin32Window(windowP); - - SetWindowLong(hwnd, GWL_EXSTYLE, 0); - SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); - SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); - - float fullscreenW = getScreenSize().x; - float fullscreenH = getScreenSize().y; - - if (orientation == OF_ORIENTATION_90_LEFT || orientation == OF_ORIENTATION_90_RIGHT) { - std::swap(fullscreenW, fullscreenH); - } - - int xpos = 0; - int ypos = 0; - - if (settings.multiMonitorFullScreen) { - - int minX = 0; - int maxX = 0; - int minY = 0; - int maxY = 0; - int monitorCount; - GLFWmonitor ** monitors = glfwGetMonitors(&monitorCount); - int tempXPos = 0; - int tempYPos = 0; - //lets find the total width of all the monitors - //and we'll make the window height the height of the largest monitor. - for (int i = 0; i < monitorCount; i++) { - const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[i]); - glfwGetMonitorPos(monitors[i], &tempXPos, &tempYPos); - minX = std::min(tempXPos, minX); - minY = std::min(tempYPos, minY); - maxX = std::max(maxX, tempXPos + desktopMode->width); - maxY = std::max(maxY, tempYPos + desktopMode->height); - - xpos = std::min(xpos, tempXPos); - ypos = std::min(ypos, tempYPos); - } - - fullscreenW = maxX - minX; - fullscreenH = maxY - minY; - } else { - - int monitorCount; - GLFWmonitor ** monitors = glfwGetMonitors(&monitorCount); - int currentMonitor = getCurrentMonitor(); - glfwGetMonitorPos(monitors[currentMonitor], &xpos, &ypos); - } - - SetWindowPos(hwnd, HWND_TOPMOST, xpos, ypos, fullscreenW, fullscreenH, SWP_SHOWWINDOW); - currentW = fullscreenW; - currentH = fullscreenH; - - } else if (targetWindowMode == OF_WINDOW) { - // set window shape if started in fullscreen - if (windowRect.width == 0 && windowRect.height == 0) { - windowRect.x = getWindowPosition().x; - windowRect.y = getWindowPosition().y; - windowRect.width = getWindowSize().x; - windowRect.height = getWindowSize().y; - } - - HWND hwnd = glfwGetWin32Window(windowP); - - DWORD EX_STYLE = WS_EX_OVERLAPPEDWINDOW; - DWORD STYLE = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SIZEBOX; - - ChangeDisplaySettings(0, 0); - SetWindowLong(hwnd, GWL_EXSTYLE, EX_STYLE); - SetWindowLong(hwnd, GWL_STYLE, STYLE); - SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); - - //not sure why this is - but if we don't do this the window shrinks by 4 pixels in x and y - //should look for a better fix. - setWindowPosition(windowRect.x - 2, windowRect.y - 2); - setWindowShape(windowRect.width + 4, windowRect.height + 4); - } -#endif - - settings.windowMode = targetWindowMode; - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::toggleFullscreen() { - if (settings.windowMode == OF_GAME_MODE) return; - - if (settings.windowMode == OF_WINDOW) { - setFullscreen(true); - } else { - setFullscreen(false); - } - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setWindowMousePassThrough(bool allowPassThrough) { - if(settings.mousePassThrough == allowPassThrough) return; - settings.mousePassThrough = allowPassThrough; -#if (GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR >= 4) - glfwSetWindowAttrib(getGLFWWindow(), GLFW_MOUSE_PASSTHROUGH, settings.mousePassThrough); + + HWND hwnd = glfwGetWin32Window(windowP); + + setFSTarget(targetWindowMode); + + if (targetWindowMode == OF_FULLSCREEN) { + SetWindowLong(hwnd, GWL_EXSTYLE, 0); + SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); + + // TODO: Here discover windows dimensions + // set window position, shape here. + +// SetWindowPos(hwnd, HWND_TOPMOST, xpos, ypos, fullscreenW, fullscreenH, SWP_SHOWWINDOW); + + } else if (targetWindowMode == OF_WINDOW) { + + DWORD EX_STYLE = WS_EX_OVERLAPPEDWINDOW; + DWORD STYLE = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SIZEBOX; + + ChangeDisplaySettings(0, 0); + SetWindowLong(hwnd, GWL_EXSTYLE, EX_STYLE); + SetWindowLong(hwnd, GWL_STYLE, STYLE); + SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); + + //not sure why this is - but if we don't do this the window shrinks by 4 pixels in x and y + //should look for a better fix. +// setWindowPosition(windowRect.x - 2, windowRect.y - 2); +// setWindowShape(windowRect.width + 4, windowRect.height + 4); + } + +// SetWindowPos(hwnd, HWND_TOPMOST, xpos, ypos, fullscreenW, fullscreenH, SWP_SHOWWINDOW); + SetWindowPos(hwnd, HWND_TOPMOST, windowRectFS.x, windowRectFS.y, windowRectFS.width, windowRectFS.height, SWP_SHOWWINDOW); + + +#elif defined(TARGET_LINUX) + setFSTarget(targetWindowMode); #endif - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setOrientation(ofOrientation orientation) { - this->orientation = orientation; - } - - //------------------------------------------------------------ - ofOrientation ofAppGLFWWindow::getOrientation() { - return orientation; - } - - //------------------------------------------------------------ - static void rotateMouseXY(ofOrientation orientation, int w, int h, double & x, double & y) { - int savedY; - switch (orientation) { - case OF_ORIENTATION_180: - x = w - x; - y = h - y; - break; - - case OF_ORIENTATION_90_RIGHT: - savedY = y; - y = x; - x = w - savedY; - break; - - case OF_ORIENTATION_90_LEFT: - savedY = y; - y = h - x; - x = savedY; - break; - - case OF_ORIENTATION_DEFAULT: - default: - break; - } - } - - //------------------------------------------------------------ - ofAppGLFWWindow * ofAppGLFWWindow::setCurrent(GLFWwindow * windowP) { - ofAppGLFWWindow * instance = static_cast(glfwGetWindowUserPointer(windowP)); - shared_ptr mainLoop = ofGetMainLoop(); - if (mainLoop) { - mainLoop->setCurrentWindow(instance); - } - instance->makeCurrent(); - return instance; - } - - namespace { - int glfwtToOFModifiers(int mods) { - int modifiers = 0; - if (mods & GLFW_MOD_SHIFT) { - modifiers |= OF_KEY_SHIFT; - } - if (mods & GLFW_MOD_ALT) { - modifiers |= OF_KEY_ALT; - } - if (mods & GLFW_MOD_CONTROL) { - modifiers |= OF_KEY_CONTROL; - } - if (mods & GLFW_MOD_SUPER) { - modifiers |= OF_KEY_SUPER; - } - return modifiers; - } - - unsigned long keycodeToUnicode(ofAppGLFWWindow * window, int scancode, int modifier) { + + settings.windowMode = targetWindowMode; +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::toggleFullscreen() { + if (settings.windowMode == OF_GAME_MODE) return; + + if (settings.windowMode == OF_WINDOW) { + setFullscreen(true); + } else { + setFullscreen(false); + } +} + +//------------------------------------------------------------ +// FIXME: this can be up on base class. it is not GLFW exclusive +static void rotateMouseXY(ofOrientation orientation, int w, int h, double & x, double & y) { + int savedY; + switch (orientation) { + case OF_ORIENTATION_180: + x = w - x; + y = h - y; + break; + + case OF_ORIENTATION_90_RIGHT: + savedY = y; + y = x; + x = w - savedY; + break; + + case OF_ORIENTATION_90_LEFT: + savedY = y; + y = h - x; + x = savedY; + break; + + case OF_ORIENTATION_DEFAULT: + default: + break; + } +} + +//------------------------------------------------------------ +ofAppGLFWWindow * ofAppGLFWWindow::setCurrent(GLFWwindow * windowP) { + auto instance { static_cast(glfwGetWindowUserPointer(windowP)) }; + if (ofCore.mainLoop) { + ofCore.mainLoop->setCurrentWindow(instance); + } + instance->makeCurrent(); + return instance; +} + +//------------------------------------------------------------ +ofAppGLFWWindow * ofAppGLFWWindow::getWindow(GLFWwindow * windowP) { + return static_cast(glfwGetWindowUserPointer(windowP)); + +// auto instance = static_cast(glfwGetWindowUserPointer(windowP)); +// auto mainLoop = ofGetMainLoop(); +// if (mainLoop) { +// mainLoop->setCurrentWindow(instance); +// } +// instance->makeCurrent(); +// return instance; +} + +namespace { +int glfwtToOFModifiers(int mods) { + int modifiers = 0; + if (mods & GLFW_MOD_SHIFT) { + modifiers |= OF_KEY_SHIFT; + } + if (mods & GLFW_MOD_ALT) { + modifiers |= OF_KEY_ALT; + } + if (mods & GLFW_MOD_CONTROL) { + modifiers |= OF_KEY_CONTROL; + } + if (mods & GLFW_MOD_SUPER) { + modifiers |= OF_KEY_SUPER; + } + return modifiers; +} + +unsigned long keycodeToUnicode(ofAppGLFWWindow * window, int scancode, int modifier) { #ifdef TARGET_LINUX - XkbStateRec xkb_state = {}; - XkbGetState(window->getX11Display(), XkbUseCoreKbd, &xkb_state); - XEvent ev = { 0 }; - ev.xkey.keycode = scancode; - ev.xkey.state = xkb_state.mods & ~ControlMask; - ev.xkey.display = window->getX11Display(); - ev.xkey.type = KeyPress; - KeySym keysym = NoSymbol; - int status; - char buffer[32] = { 0 }; - char * chars = buffer; - auto count = Xutf8LookupString(window->getX11XIC(), &ev.xkey, chars, sizeof(buffer) - 1, &keysym, &status); - if ((count > 0 && (status == XLookupChars || status == XLookupBoth)) || status == XLookupKeySym) { - char ** c = &chars; - unsigned int ch = 0, count = 0; - static const unsigned int offsets[] = { - 0x00000000u, 0x00003080u, 0x000e2080u, - 0x03c82080u, 0xfa082080u, 0x82082080u - }; - - do { - ch = (ch << 6) + (unsigned char)**c; - (*c)++; - count++; - } while ((**c & 0xc0) == 0x80); - - if (count > 6) { - return 0; - } else { - return ch - offsets[count - 1]; - } - } else { - return 0; - } + XkbStateRec xkb_state = {}; + XkbGetState(window->getX11Display(), XkbUseCoreKbd, &xkb_state); + XEvent ev = { 0 }; + ev.xkey.keycode = scancode; + ev.xkey.state = xkb_state.mods & ~ControlMask; + ev.xkey.display = window->getX11Display(); + ev.xkey.type = KeyPress; + KeySym keysym = NoSymbol; + int status; + char buffer[32] = { 0 }; + char * chars = buffer; + auto count = Xutf8LookupString(window->getX11XIC(), &ev.xkey, chars, sizeof(buffer) - 1, &keysym, &status); + if ((count > 0 && (status == XLookupChars || status == XLookupBoth)) || status == XLookupKeySym) { + char ** c = &chars; + unsigned int ch = 0, count = 0; + static const unsigned int offsets[] = { + 0x00000000u, 0x00003080u, 0x000e2080u, + 0x03c82080u, 0xfa082080u, 0x82082080u + }; + + do { + ch = (ch << 6) + (unsigned char)**c; + (*c)++; + count++; + } while ((**c & 0xc0) == 0x80); + + if (count > 6) { + return 0; + } else { + return ch - offsets[count - 1]; + } + } else { + return 0; + } #endif #ifdef TARGET_WIN32 - static WCHAR buf[2]; - static BYTE keyboardState[256]; - GetKeyboardState(keyboardState); - - // Careful: keycode arrives translated into GLFW key codes, - // but keycode needs to be a virtual key (VK_...) so we're - // in deep troble, since this information has been removed - // by GLFW... - // - // The way around this is to ask the operating system - // nicely to create a virtual key for us, based on - // the scancode and the currently bound keyboard layout. - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646306(v=vs.85).aspx - // - // create a "fake" virtual key - - UINT fakeVirtualKey = MapVirtualKey(scancode, MAPVK_VSC_TO_VK_EX); - - int ret = ToUnicode(fakeVirtualKey, scancode, keyboardState, buf, 2, 0); - - if (ret == 1) { - return buf[0]; - } else { - return 0; - } + static WCHAR buf[2]; + static BYTE keyboardState[256]; + GetKeyboardState(keyboardState); + + // Careful: keycode arrives translated into GLFW key codes, + // but keycode needs to be a virtual key (VK_...) so we're + // in deep troble, since this information has been removed + // by GLFW... + // + // The way around this is to ask the operating system + // nicely to create a virtual key for us, based on + // the scancode and the currently bound keyboard layout. + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646306(v=vs.85).aspx + // + // create a "fake" virtual key + + UINT fakeVirtualKey = MapVirtualKey(scancode, MAPVK_VSC_TO_VK_EX); + + int ret = ToUnicode(fakeVirtualKey, scancode, keyboardState, buf, 2, 0); + + if (ret == 1) { + return buf[0]; + } else { + return 0; + } #endif #ifdef TARGET_OSX - static UInt32 deadKeyState = 0; - static UniChar characters[8]; - static UniCharCount characterCount = 0; - - typedef struct __TISInputSource * TISInputSourceRef; - typedef TISInputSourceRef (*pFnGetInputSource)(void); // define function pointer that may return a input source ref, no arguments - typedef void * (*pFnGetInputSourceProperty)(TISInputSourceRef, CFStringRef); - typedef UInt8 (*pFnGetKeyboardType)(void); - - static const CFBundleRef tisBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIToolbox")); - - // We need to call some system methods, following GLFW's example - // in their OS X version of ```_glfwPlatformGetKeyName```. - // - // We know these methods must be available, since GLFW uses them - // internally. - // - // The most important method is ```UCKeyTranslate``` - everything - // else here is just a royal preparation party to feed it with the - // correct parameters. - // - // Since these methods are hidden deep within Carbon, - // we have to first request function pointers to make - // them callable. - // - // We do this only the first time, then we're re-using them, - // that's why these elements are marked static, and static const. - // - static pFnGetInputSource getInputSource = (pFnGetInputSource)CFBundleGetFunctionPointerForName(tisBundle, CFSTR("TISCopyCurrentKeyboardLayoutInputSource")); - static pFnGetKeyboardType getKeyboardType = (pFnGetKeyboardType)CFBundleGetFunctionPointerForName(tisBundle, CFSTR("LMGetKbdType")); - static pFnGetInputSourceProperty getInputSourceProperty = (pFnGetInputSourceProperty)CFBundleGetFunctionPointerForName(tisBundle, CFSTR("TISGetInputSourceProperty")); - - static const TISInputSourceRef sourceRef = getInputSource(); // note that for the first time, this creates a copy on the heap, then we're re-using it. - - static const CFStringRef * kPropertyUnicodeKeyLayoutData = (CFStringRef *)CFBundleGetDataPointerForName(tisBundle, CFSTR("kTISPropertyUnicodeKeyLayoutData")); - static const CFStringRef kTISPropertyUnicodeKeyLayoutData = *kPropertyUnicodeKeyLayoutData; - static const CFDataRef UnicodeKeyLayoutData = (CFDataRef)getInputSourceProperty(sourceRef, kTISPropertyUnicodeKeyLayoutData); - - static const UCKeyboardLayout * pKeyboardLayout = (UCKeyboardLayout *)CFDataGetBytePtr(UnicodeKeyLayoutData); - - UInt32 mod_OSX = 0; - { - // We have to translate the GLFW modifier bitflags back to OS X, - // so that SHIFT, CONTROL, etc can be taken into account when - // calculating the unicode codepoint. - - // UCKeyTranslate expects the Carbon-era modifier mask values, - // so use these instead of the NSEventModifierFlag enums - if (modifier & GLFW_MOD_SHIFT) - mod_OSX |= 512; // Carbon shiftKey value - if (modifier & GLFW_MOD_CONTROL) - mod_OSX |= 4096; // Carbon controlKey value - if (modifier & GLFW_MOD_ALT) - mod_OSX |= 2048; // Carbon optionKey value - if (modifier & GLFW_MOD_SUPER) - mod_OSX |= 256; // Carbon cmdKey - - // shift into 1 byte as per the Apple docs - mod_OSX = (mod_OSX >> 8) & 0xFF; - } - - // All this yak shaving was necessary to feed this diva of a function call: - // https://developer.apple.com/library/mac/documentation/Carbon/Reference/Unicode_Utilities_Ref/index.html#//apple_ref/c/func/UCKeyTranslate - - if (noErr == UCKeyTranslate(pKeyboardLayout, scancode, kUCKeyActionDisplay, mod_OSX, getKeyboardType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, sizeof(characters) / sizeof(characters[0]), &characterCount, characters)) { - // if successful, first character contains codepoint - return characters[0]; - } else { - return 0; - } - + static UInt32 deadKeyState = 0; + static UniChar characters[8]; + static UniCharCount characterCount = 0; + + typedef struct __TISInputSource * TISInputSourceRef; + typedef TISInputSourceRef (*pFnGetInputSource)(void); // define function pointer that may return a input source ref, no arguments + typedef void * (*pFnGetInputSourceProperty)(TISInputSourceRef, CFStringRef); + typedef UInt8 (*pFnGetKeyboardType)(void); + + static const CFBundleRef tisBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIToolbox")); + + // We need to call some system methods, following GLFW's example + // in their OS X version of ```_glfwPlatformGetKeyName```. + // + // We know these methods must be available, since GLFW uses them + // internally. + // + // The most important method is ```UCKeyTranslate``` - everything + // else here is just a royal preparation party to feed it with the + // correct parameters. + // + // Since these methods are hidden deep within Carbon, + // we have to first request function pointers to make + // them callable. + // + // We do this only the first time, then we're re-using them, + // that's why these elements are marked static, and static const. + // + static pFnGetInputSource getInputSource = (pFnGetInputSource)CFBundleGetFunctionPointerForName(tisBundle, CFSTR("TISCopyCurrentKeyboardLayoutInputSource")); + static pFnGetKeyboardType getKeyboardType = (pFnGetKeyboardType)CFBundleGetFunctionPointerForName(tisBundle, CFSTR("LMGetKbdType")); + static pFnGetInputSourceProperty getInputSourceProperty = (pFnGetInputSourceProperty)CFBundleGetFunctionPointerForName(tisBundle, CFSTR("TISGetInputSourceProperty")); + + static const TISInputSourceRef sourceRef = getInputSource(); // note that for the first time, this creates a copy on the heap, then we're re-using it. + + static const CFStringRef * kPropertyUnicodeKeyLayoutData = (CFStringRef *)CFBundleGetDataPointerForName(tisBundle, CFSTR("kTISPropertyUnicodeKeyLayoutData")); + static const CFStringRef kTISPropertyUnicodeKeyLayoutData = *kPropertyUnicodeKeyLayoutData; + static const CFDataRef UnicodeKeyLayoutData = (CFDataRef)getInputSourceProperty(sourceRef, kTISPropertyUnicodeKeyLayoutData); + + static const UCKeyboardLayout * pKeyboardLayout = (UCKeyboardLayout *)CFDataGetBytePtr(UnicodeKeyLayoutData); + + UInt32 mod_OSX = 0; + { + // We have to translate the GLFW modifier bitflags back to OS X, + // so that SHIFT, CONTROL, etc can be taken into account when + // calculating the unicode codepoint. + + // UCKeyTranslate expects the Carbon-era modifier mask values, + // so use these instead of the NSEventModifierFlag enums + if (modifier & GLFW_MOD_SHIFT) + mod_OSX |= 512; // Carbon shiftKey value + if (modifier & GLFW_MOD_CONTROL) + mod_OSX |= 4096; // Carbon controlKey value + if (modifier & GLFW_MOD_ALT) + mod_OSX |= 2048; // Carbon optionKey value + if (modifier & GLFW_MOD_SUPER) + mod_OSX |= 256; // Carbon cmdKey + + // shift into 1 byte as per the Apple docs + mod_OSX = (mod_OSX >> 8) & 0xFF; + } + + // All this yak shaving was necessary to feed this diva of a function call: + // https://developer.apple.com/library/mac/documentation/Carbon/Reference/Unicode_Utilities_Ref/index.html#//apple_ref/c/func/UCKeyTranslate + + if (noErr == UCKeyTranslate(pKeyboardLayout, scancode, kUCKeyActionDisplay, mod_OSX, getKeyboardType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, sizeof(characters) / sizeof(characters[0]), &characterCount, characters)) { + // if successful, first character contains codepoint + return characters[0]; + } else { + return 0; + } + #endif - return 0; - } - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::mouse_cb(GLFWwindow * windowP_, int button, int state, int mods) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - + return 0; +} +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::mouse_cb(GLFWwindow * windowP_, int button, int state, int mods) { + auto instance = setCurrent(windowP_); +// auto instance = getWindow(windowP_); + #ifdef TARGET_OSX - //we do this as unlike glut, glfw doesn't report right click for ctrl click or middle click for alt click - if (instance->events().getKeyPressed(OF_KEY_CONTROL) && button == GLFW_MOUSE_BUTTON_LEFT) { - button = GLFW_MOUSE_BUTTON_RIGHT; - } - if (instance->events().getKeyPressed(OF_KEY_ALT) && button == GLFW_MOUSE_BUTTON_LEFT) { - button = GLFW_MOUSE_BUTTON_MIDDLE; - } + //we do this as unlike glut, glfw doesn't report right click for ctrl click or middle click for alt click + if (instance->events().getKeyPressed(OF_KEY_CONTROL) && button == GLFW_MOUSE_BUTTON_LEFT) { + button = GLFW_MOUSE_BUTTON_RIGHT; + } + if (instance->events().getKeyPressed(OF_KEY_ALT) && button == GLFW_MOUSE_BUTTON_LEFT) { + button = GLFW_MOUSE_BUTTON_MIDDLE; + } #endif - - switch (button) { - case GLFW_MOUSE_BUTTON_LEFT: - button = OF_MOUSE_BUTTON_LEFT; - break; - case GLFW_MOUSE_BUTTON_RIGHT: - button = OF_MOUSE_BUTTON_RIGHT; - break; - case GLFW_MOUSE_BUTTON_MIDDLE: - button = OF_MOUSE_BUTTON_MIDDLE; - break; - } - instance->buttonInUse = button; - - ofMouseEventArgs::Type action; - if (state == GLFW_PRESS) { - action = ofMouseEventArgs::Pressed; - instance->buttonPressed = true; - } else { - action = ofMouseEventArgs::Released; - instance->buttonPressed = false; - } - - int modifiers = glfwtToOFModifiers(mods); - - ofMouseEventArgs args(action, instance->events().getMouseX(), instance->events().getMouseY(), button, modifiers); - - instance->events().notifyMouseEvent(args); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::motion_cb(GLFWwindow * windowP_, double x, double y) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - rotateMouseXY(instance->orientation, instance->getWidth(), instance->getHeight(), x, y); - - ofMouseEventArgs::Type action; - if (!instance->buttonPressed) { - action = ofMouseEventArgs::Moved; - } else { - action = ofMouseEventArgs::Dragged; - } - - ofMouseEventArgs args(action, - x * instance->pixelScreenCoordScale, - y * instance->pixelScreenCoordScale, - instance->buttonInUse, - instance->events().getModifiers()); - instance->events().notifyMouseEvent(args); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::entry_cb(GLFWwindow * windowP_, int entered) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - ofMouseEventArgs::Type action; - if (entered) { - action = ofMouseEventArgs::Entered; - } else { - action = ofMouseEventArgs::Exited; - } - - ofMouseEventArgs args(action, - instance->events().getMouseX(), - instance->events().getMouseY(), - instance->buttonInUse, - instance->events().getModifiers()); - instance->events().notifyMouseEvent(args); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::scroll_cb(GLFWwindow * windowP_, double x, double y) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - rotateMouseXY(instance->orientation, instance->getWidth(), instance->getHeight(), x, y); - - ofMouseEventArgs args(ofMouseEventArgs::Scrolled, - instance->events().getMouseX(), - instance->events().getMouseY(), - instance->buttonInUse, - instance->events().getModifiers()); - args.scrollX = x; - args.scrollY = y; - instance->events().notifyMouseEvent(args); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::drop_cb(GLFWwindow * windowP_, int numFiles, const char ** dropString) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - ofDragInfo drag; - drag.position = { instance->events().getMouseX(), instance->events().getMouseY() }; - drag.files.resize(numFiles); - for (int i = 0; i < (int)drag.files.size(); i++) { - drag.files[i] = dropString[i]; - } - instance->events().notifyDragEvent(drag); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::error_cb(int errorCode, const char * errorDescription) { - ofLogError("ofAppGLFWWindow") << errorCode << ": " << errorDescription; - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::keyboard_cb(GLFWwindow * windowP_, int keycode, int scancode, int action, int mods) { - int key = 0; - uint32_t codepoint = 0; - ofAppGLFWWindow * instance = setCurrent(windowP_); - switch (keycode) { - case GLFW_KEY_ESCAPE: - key = OF_KEY_ESC; - break; - case GLFW_KEY_F1: - key = OF_KEY_F1; - break; - case GLFW_KEY_F2: - key = OF_KEY_F2; - break; - case GLFW_KEY_F3: - key = OF_KEY_F3; - break; - case GLFW_KEY_F4: - key = OF_KEY_F4; - break; - case GLFW_KEY_F5: - key = OF_KEY_F5; - break; - case GLFW_KEY_F6: - key = OF_KEY_F6; - break; - case GLFW_KEY_F7: - key = OF_KEY_F7; - break; - case GLFW_KEY_F8: - key = OF_KEY_F8; - break; - case GLFW_KEY_F9: - key = OF_KEY_F9; - break; - case GLFW_KEY_F10: - key = OF_KEY_F10; - break; - case GLFW_KEY_F11: - key = OF_KEY_F11; - break; - case GLFW_KEY_F12: - key = OF_KEY_F12; - break; - case GLFW_KEY_LEFT: - key = OF_KEY_LEFT; - break; - case GLFW_KEY_RIGHT: - key = OF_KEY_RIGHT; - break; - case GLFW_KEY_UP: - key = OF_KEY_UP; - break; - case GLFW_KEY_DOWN: - key = OF_KEY_DOWN; - break; - case GLFW_KEY_PAGE_UP: - key = OF_KEY_PAGE_UP; - break; - case GLFW_KEY_PAGE_DOWN: - key = OF_KEY_PAGE_DOWN; - break; - case GLFW_KEY_HOME: - key = OF_KEY_HOME; - break; - case GLFW_KEY_END: - key = OF_KEY_END; - break; - case GLFW_KEY_INSERT: - key = OF_KEY_INSERT; - break; - case GLFW_KEY_LEFT_SHIFT: - key = OF_KEY_LEFT_SHIFT; - break; - case GLFW_KEY_LEFT_CONTROL: - key = OF_KEY_LEFT_CONTROL; - break; - case GLFW_KEY_LEFT_ALT: - key = OF_KEY_LEFT_ALT; - break; - case GLFW_KEY_LEFT_SUPER: - key = OF_KEY_LEFT_SUPER; - break; - case GLFW_KEY_RIGHT_SHIFT: - key = OF_KEY_RIGHT_SHIFT; - break; - case GLFW_KEY_RIGHT_CONTROL: - key = OF_KEY_RIGHT_CONTROL; - break; - case GLFW_KEY_RIGHT_ALT: - key = OF_KEY_RIGHT_ALT; - break; - case GLFW_KEY_RIGHT_SUPER: - key = OF_KEY_RIGHT_SUPER; - break; - case GLFW_KEY_BACKSPACE: - key = OF_KEY_BACKSPACE; - break; - case GLFW_KEY_DELETE: - key = OF_KEY_DEL; - break; - case GLFW_KEY_ENTER: - key = OF_KEY_RETURN; - codepoint = '\n'; - break; - case GLFW_KEY_KP_ENTER: - key = OF_KEY_RETURN; - codepoint = '\n'; - break; - case GLFW_KEY_TAB: - key = OF_KEY_TAB; - codepoint = '\t'; - break; - case GLFW_KEY_KP_0: - key = codepoint = '0'; - break; - case GLFW_KEY_KP_1: - key = codepoint = '1'; - break; - case GLFW_KEY_KP_2: - key = codepoint = '2'; - break; - case GLFW_KEY_KP_3: - key = codepoint = '3'; - break; - case GLFW_KEY_KP_4: - key = codepoint = '4'; - break; - case GLFW_KEY_KP_5: - key = codepoint = '5'; - break; - case GLFW_KEY_KP_6: - key = codepoint = '6'; - break; - case GLFW_KEY_KP_7: - key = codepoint = '7'; - break; - case GLFW_KEY_KP_8: - key = codepoint = '8'; - break; - case GLFW_KEY_KP_9: - key = codepoint = '9'; - break; - case GLFW_KEY_KP_DIVIDE: - key = codepoint = '/'; - break; - case GLFW_KEY_KP_MULTIPLY: - key = codepoint = '*'; - break; - case GLFW_KEY_KP_SUBTRACT: - key = codepoint = '-'; - break; - case GLFW_KEY_KP_ADD: - key = codepoint = '+'; - break; - case GLFW_KEY_KP_DECIMAL: - key = codepoint = '.'; - break; - case GLFW_KEY_KP_EQUAL: - key = codepoint = '='; - break; - case GLFW_KEY_SPACE: - key = codepoint = OF_KEY_SPACE; - break; - default: - codepoint = keycodeToUnicode(instance, scancode, mods); - key = codepoint; - break; - } - - int modifiers = glfwtToOFModifiers(mods); - - if (action == GLFW_PRESS) { - ofKeyEventArgs keyE(ofKeyEventArgs::Pressed, key, keycode, scancode, codepoint, modifiers); - instance->events().notifyKeyEvent(keyE); - } else if (action == GLFW_REPEAT) { - ofKeyEventArgs keyE(ofKeyEventArgs::Pressed, key, keycode, scancode, codepoint, modifiers); - keyE.isRepeat = true; - instance->events().notifyKeyEvent(keyE); - } else if (action == GLFW_RELEASE) { - ofKeyEventArgs keyE(ofKeyEventArgs::Released, key, keycode, scancode, codepoint, modifiers); - instance->events().notifyKeyEvent(keyE); - } - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::char_cb(GLFWwindow * windowP_, uint32_t key) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - instance->events().charEvent.notify(key); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::position_cb(GLFWwindow* windowP_, int x, int y){ - ofAppGLFWWindow * instance = setCurrent(windowP_); - - x *= instance->pixelScreenCoordScale; - y *= instance->pixelScreenCoordScale; - instance->events().notifyWindowMoved(x,y); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::refresh_cb(GLFWwindow * windowP_) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - instance->draw(); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::resize_cb(GLFWwindow * windowP_, int w, int h) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - - // Detect if the window is running in a retina mode - - int framebufferW, framebufferH; // <- physical pixel extents - glfwGetFramebufferSize(windowP_, &framebufferW, &framebufferH); - - int windowW, windowH; // <- screen coordinates, which may be scaled - glfwGetWindowSize(windowP_, &windowW, &windowH); - - // Find scale factor needed to transform from screen coordinates - // to physical pixel coordinates - instance->pixelScreenCoordScale = (float)framebufferW / (float)windowW; - - if (instance->settings.windowMode == OF_WINDOW) { - instance->windowW = framebufferW; - instance->windowH = framebufferH; - } - - instance->currentW = windowW; - instance->currentH = windowH; - instance->events().notifyWindowResized(framebufferW, framebufferH); - instance->nFramesSinceWindowResized = 0; - + + switch (button) { + case GLFW_MOUSE_BUTTON_LEFT: + button = OF_MOUSE_BUTTON_LEFT; + break; + case GLFW_MOUSE_BUTTON_RIGHT: + button = OF_MOUSE_BUTTON_RIGHT; + break; + case GLFW_MOUSE_BUTTON_MIDDLE: + button = OF_MOUSE_BUTTON_MIDDLE; + break; + } + instance->buttonInUse = button; + + ofMouseEventArgs::Type action; + if (state == GLFW_PRESS) { + action = ofMouseEventArgs::Pressed; + instance->buttonPressed = true; + } else { + action = ofMouseEventArgs::Released; + instance->buttonPressed = false; + } + + int modifiers = glfwtToOFModifiers(mods); + + ofMouseEventArgs args(action, instance->events().getMouseX(), instance->events().getMouseY(), button, modifiers); + + instance->events().notifyMouseEvent(args); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::motion_cb(GLFWwindow * windowP_, double x, double y) { +// auto instance = getWindow(windowP_); + ofAppGLFWWindow * instance = setCurrent(windowP_); + rotateMouseXY(instance->orientation, instance->getWidth(), instance->getHeight(), x, y); + + ofMouseEventArgs::Type action; + if (!instance->buttonPressed) { + action = ofMouseEventArgs::Moved; + } else { + action = ofMouseEventArgs::Dragged; + } + + ofMouseEventArgs args(action, + x, + y, + instance->buttonInUse, + instance->events().getModifiers()); + instance->events().notifyMouseEvent(args); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::entry_cb(GLFWwindow * windowP_, int entered) { + ofAppGLFWWindow * instance = setCurrent(windowP_); +// auto instance = getWindow(windowP_); + + ofMouseEventArgs::Type action; + if (entered) { + action = ofMouseEventArgs::Entered; + } else { + action = ofMouseEventArgs::Exited; + } + + ofMouseEventArgs args(action, + instance->events().getMouseX(), + instance->events().getMouseY(), + instance->buttonInUse, + instance->events().getModifiers()); + instance->events().notifyMouseEvent(args); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::scroll_cb(GLFWwindow * windowP_, double x, double y) { + ofAppGLFWWindow * instance = setCurrent(windowP_); +// auto instance = getWindow(windowP_); + rotateMouseXY(instance->orientation, instance->getWidth(), instance->getHeight(), x, y); + + ofMouseEventArgs args(ofMouseEventArgs::Scrolled, + instance->events().getMouseX(), + instance->events().getMouseY(), + instance->buttonInUse, + instance->events().getModifiers()); + args.scrollX = x; + args.scrollY = y; + instance->events().notifyMouseEvent(args); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::drop_cb(GLFWwindow * windowP_, int numFiles, const char ** dropString) { +// auto instance = getWindow(windowP_); + ofAppGLFWWindow * instance = setCurrent(windowP_); + ofDragInfo drag; + drag.position = { instance->events().getMouseX(), instance->events().getMouseY() }; + drag.files.resize(numFiles); + for (int i = 0; i < (int)drag.files.size(); i++) { + drag.files[i] = dropString[i]; + } + instance->events().notifyDragEvent(drag); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::error_cb(int errorCode, const char * errorDescription) { + ofLogError("ofAppGLFWWindow") << errorCode << ": " << errorDescription; +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::keyboard_cb(GLFWwindow * windowP_, int keycode, int scancode, int action, int mods) { + int key = 0; + uint32_t codepoint = 0; + ofAppGLFWWindow * instance = setCurrent(windowP_); +// auto instance = getWindow(windowP_); +// cout << "keyboard_cb " << instance->settings.windowName << endl; + switch (keycode) { + case GLFW_KEY_ESCAPE: + key = OF_KEY_ESC; + break; + case GLFW_KEY_F1: + key = OF_KEY_F1; + break; + case GLFW_KEY_F2: + key = OF_KEY_F2; + break; + case GLFW_KEY_F3: + key = OF_KEY_F3; + break; + case GLFW_KEY_F4: + key = OF_KEY_F4; + break; + case GLFW_KEY_F5: + key = OF_KEY_F5; + break; + case GLFW_KEY_F6: + key = OF_KEY_F6; + break; + case GLFW_KEY_F7: + key = OF_KEY_F7; + break; + case GLFW_KEY_F8: + key = OF_KEY_F8; + break; + case GLFW_KEY_F9: + key = OF_KEY_F9; + break; + case GLFW_KEY_F10: + key = OF_KEY_F10; + break; + case GLFW_KEY_F11: + key = OF_KEY_F11; + break; + case GLFW_KEY_F12: + key = OF_KEY_F12; + break; + case GLFW_KEY_LEFT: + key = OF_KEY_LEFT; + break; + case GLFW_KEY_RIGHT: + key = OF_KEY_RIGHT; + break; + case GLFW_KEY_UP: + key = OF_KEY_UP; + break; + case GLFW_KEY_DOWN: + key = OF_KEY_DOWN; + break; + case GLFW_KEY_PAGE_UP: + key = OF_KEY_PAGE_UP; + break; + case GLFW_KEY_PAGE_DOWN: + key = OF_KEY_PAGE_DOWN; + break; + case GLFW_KEY_HOME: + key = OF_KEY_HOME; + break; + case GLFW_KEY_END: + key = OF_KEY_END; + break; + case GLFW_KEY_INSERT: + key = OF_KEY_INSERT; + break; + case GLFW_KEY_LEFT_SHIFT: + key = OF_KEY_LEFT_SHIFT; + break; + case GLFW_KEY_LEFT_CONTROL: + key = OF_KEY_LEFT_CONTROL; + break; + case GLFW_KEY_LEFT_ALT: + key = OF_KEY_LEFT_ALT; + break; + case GLFW_KEY_LEFT_SUPER: + key = OF_KEY_LEFT_SUPER; + break; + case GLFW_KEY_RIGHT_SHIFT: + key = OF_KEY_RIGHT_SHIFT; + break; + case GLFW_KEY_RIGHT_CONTROL: + key = OF_KEY_RIGHT_CONTROL; + break; + case GLFW_KEY_RIGHT_ALT: + key = OF_KEY_RIGHT_ALT; + break; + case GLFW_KEY_RIGHT_SUPER: + key = OF_KEY_RIGHT_SUPER; + break; + case GLFW_KEY_BACKSPACE: + key = OF_KEY_BACKSPACE; + break; + case GLFW_KEY_DELETE: + key = OF_KEY_DEL; + break; + case GLFW_KEY_ENTER: + key = OF_KEY_RETURN; + codepoint = '\n'; + break; + case GLFW_KEY_KP_ENTER: + key = OF_KEY_RETURN; + codepoint = '\n'; + break; + case GLFW_KEY_TAB: + key = OF_KEY_TAB; + codepoint = '\t'; + break; + case GLFW_KEY_KP_0: + key = codepoint = '0'; + break; + case GLFW_KEY_KP_1: + key = codepoint = '1'; + break; + case GLFW_KEY_KP_2: + key = codepoint = '2'; + break; + case GLFW_KEY_KP_3: + key = codepoint = '3'; + break; + case GLFW_KEY_KP_4: + key = codepoint = '4'; + break; + case GLFW_KEY_KP_5: + key = codepoint = '5'; + break; + case GLFW_KEY_KP_6: + key = codepoint = '6'; + break; + case GLFW_KEY_KP_7: + key = codepoint = '7'; + break; + case GLFW_KEY_KP_8: + key = codepoint = '8'; + break; + case GLFW_KEY_KP_9: + key = codepoint = '9'; + break; + case GLFW_KEY_KP_DIVIDE: + key = codepoint = '/'; + break; + case GLFW_KEY_KP_MULTIPLY: + key = codepoint = '*'; + break; + case GLFW_KEY_KP_SUBTRACT: + key = codepoint = '-'; + break; + case GLFW_KEY_KP_ADD: + key = codepoint = '+'; + break; + case GLFW_KEY_KP_DECIMAL: + key = codepoint = '.'; + break; + case GLFW_KEY_KP_EQUAL: + key = codepoint = '='; + break; + default: + codepoint = keycodeToUnicode(instance, scancode, mods); +// codepoint = scancode; + key = codepoint; + break; + } + + int modifiers = glfwtToOFModifiers(mods); + + if (action == GLFW_PRESS) { + ofKeyEventArgs keyE(ofKeyEventArgs::Pressed, key, keycode, scancode, codepoint, modifiers); + instance->events().notifyKeyEvent(keyE); + } else if (action == GLFW_REPEAT) { + ofKeyEventArgs keyE(ofKeyEventArgs::Pressed, key, keycode, scancode, codepoint, modifiers); + keyE.isRepeat = true; + instance->events().notifyKeyEvent(keyE); + } else if (action == GLFW_RELEASE) { + ofKeyEventArgs keyE(ofKeyEventArgs::Released, key, keycode, scancode, codepoint, modifiers); + instance->events().notifyKeyEvent(keyE); + } +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::char_cb(GLFWwindow * windowP_, uint32_t key) { + ofAppGLFWWindow * instance = setCurrent(windowP_); +// auto instance = getWindow(windowP_); + instance->events().charEvent.notify(key); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::refresh_cb(GLFWwindow * windowP_) { +// auto instance = getWindow(windowP_); + ofAppGLFWWindow * instance = setCurrent(windowP_); + instance->draw(); +// thisWindow->draw(); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::monitor_cb(GLFWmonitor * monitor, int event) { + allMonitors.update(); +// cout << "monitor_cb!" << endl; +// cout << "monitors rect size: " << allMonitors.rects.size() << endl; + + for (auto & w : ofGetMainLoop()->getWindows()) { + if (w->settings.showOnlyInSelectedMonitor) { +// cout << "monitor_cb windowName " << w->settings.windowName << endl; + auto win = static_cast(w.get()); + if (allMonitors.rects.size() > w->settings.monitor) { + if (w->settings.windowMode == OF_FULLSCREEN) { + w->setWindowRect(allMonitors.rects[w->settings.monitor]); + } + // TODO: set window to monitor, if it is windowed. + glfwShowWindow(win->getGLFWWindow()); + } else { + glfwHideWindow(win->getGLFWWindow()); + } + } + } +// ofGetMainLoop()->getWindows().size() +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::position_cb(GLFWwindow* windowP_, int x, int y){ + ofAppGLFWWindow * instance = setCurrent(windowP_); +// auto instance = getWindow(windowP_); +// if (instance->settings.windowMode == OF_WINDOW) { +// instance->windowRect.x = x; +// instance->windowRect.y = y; +// } + instance->events().notifyWindowMoved(x, y); +} +//------------------------------------------------------------ +void ofAppGLFWWindow::resize_cb(GLFWwindow * windowP_, int w, int h) { +// auto instance = getWindow(windowP_); + ofAppGLFWWindow * instance = setCurrent(windowP_); + instance->events().notifyWindowResized(w, h); +// instance->nFramesSinceWindowResized = 0; + + #if defined(TARGET_OSX) - NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP_); - if (([cocoaWindow styleMask] & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen) { - instance->settings.windowMode = OF_FULLSCREEN; - } else { - instance->settings.windowMode = OF_WINDOW; - } + if (!instance->bWindowNeedsShowing) { +// FIXME - only after first update + NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP_); + if (([cocoaWindow styleMask] & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen) { + instance->settings.windowMode = OF_FULLSCREEN; + } else { + instance->settings.windowMode = OF_WINDOW; + } + } #endif - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::framebuffer_size_cb(GLFWwindow * windowP_, int w, int h) { - resize_cb(windowP_, w, h); - } - - //-------------------------------------------- - void ofAppGLFWWindow::exit_cb(GLFWwindow * windowP_) { - ofAppGLFWWindow * instance = setCurrent(windowP_); - instance->events().notifyExit(); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setVerticalSync(bool bVerticalSync) { - if (bVerticalSync) { - glfwSwapInterval(1); - } else { - glfwSwapInterval(0); - } - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::setClipboardString(const std::string & text) { - glfwSetClipboardString(ofAppGLFWWindow::windowP, text.c_str()); - } - - //------------------------------------------------------------ - std::string ofAppGLFWWindow::getClipboardString() { - const char * clipboard = glfwGetClipboardString(ofAppGLFWWindow::windowP); - - if (clipboard) { - return clipboard; - } else { - return ""; - } - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::listVideoModes() { - glfwInit(); - int numModes; - const GLFWvidmode * vidModes = glfwGetVideoModes(nullptr, &numModes); - for (int i = 0; i < numModes; i++) { - ofLogNotice() << vidModes[i].width << " x " << vidModes[i].height - << vidModes[i].redBits + vidModes[i].greenBits + vidModes[i].blueBits << "bit"; - } - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::listMonitors() { - glfwInit(); - int count; - const auto monitors = glfwGetMonitors(&count); - for (int i = 0; i < count; i++) { - auto monitor = monitors[i]; - int w, h, x, y; - glfwGetMonitorPhysicalSize(monitor, &w, &h); - glfwGetMonitorPos(monitor, &x, &y); - ofLogNotice() << i << ": " << glfwGetMonitorName(monitor) << ", physical size: " << w << "x" << h << "mm at " << x << ", " << y; - } - } - - //------------------------------------------------------------ - bool ofAppGLFWWindow::isWindowIconified() { - return glfwGetWindowAttrib(windowP, GLFW_ICONIFIED); - } - - //------------------------------------------------------------ - bool ofAppGLFWWindow::isWindowActive() { - // return glfwGetWindowParam(GLFW_ACTIVE); - return true; - } - - //------------------------------------------------------------ - bool ofAppGLFWWindow::isWindowResizeable() { - return !glfwGetWindowAttrib(windowP, GLFW_RESIZABLE); - } - - //------------------------------------------------------------ - void ofAppGLFWWindow::iconify(bool bIconify) { - if (bIconify) - glfwIconifyWindow(windowP); - else - glfwRestoreWindow(windowP); - } - - void ofAppGLFWWindow::makeCurrent() { - glfwMakeContextCurrent(windowP); - } - +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::framebuffer_size_cb(GLFWwindow * windowP_, int w, int h) { +// cout << "framebuffer_size_cb " << w << " : " << h << endl; +// auto instance = getWindow(windowP_); + ofAppGLFWWindow * instance = setCurrent(windowP_); + + instance->currentRenderer->clear(); + instance->events().notifyFramebufferResized(w, h); +} + +//-------------------------------------------- +void ofAppGLFWWindow::exit_cb(GLFWwindow * windowP_) { +// cout << "exit_cb " << endl; +// auto instance = getWindow(windowP_); + ofAppGLFWWindow * instance = setCurrent(windowP_); + instance->events().notifyExit(); + + // TODO: handle window closing correctly here. +// instance->close(); +// instance->setWindowShouldClose(); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setVerticalSync(bool bVerticalSync) { + if (bVerticalSync) { + glfwSwapInterval(1); + } else { + glfwSwapInterval(0); + } +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::setClipboardString(const std::string & text) { + glfwSetClipboardString(ofAppGLFWWindow::windowP, text.c_str()); +} + +//------------------------------------------------------------ +std::string ofAppGLFWWindow::getClipboardString() { + const char * clipboard = glfwGetClipboardString(ofAppGLFWWindow::windowP); + + if (clipboard) { + return clipboard; + } else { + return ""; + } +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::listVideoModes() { + glfwInit(); + int numModes; + const GLFWvidmode * vidModes = glfwGetVideoModes(nullptr, &numModes); + for (int i = 0; i < numModes; i++) { + ofLogNotice() << vidModes[i].width << " x " << vidModes[i].height + << vidModes[i].redBits + vidModes[i].greenBits + vidModes[i].blueBits << "bit"; + } +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::listMonitors() { + glfwInit(); + int count; + const auto monitors = glfwGetMonitors(&count); + for (int i = 0; i < count; i++) { + auto monitor = monitors[i]; + int w, h, x, y; + glfwGetMonitorPhysicalSize(monitor, &w, &h); + glfwGetMonitorPos(monitor, &x, &y); + ofLogNotice() << i << ": " << glfwGetMonitorName(monitor) << ", physical size: " << w << "x" << h << "mm at " << x << ", " << y; + } +} + +//------------------------------------------------------------ +bool ofAppGLFWWindow::isWindowIconified() { + return glfwGetWindowAttrib(windowP, GLFW_ICONIFIED); +} + +//------------------------------------------------------------ +bool ofAppGLFWWindow::isWindowActive() { + // return glfwGetWindowParam(GLFW_ACTIVE); + return true; +} + +//------------------------------------------------------------ +bool ofAppGLFWWindow::isWindowResizeable() { + return !glfwGetWindowAttrib(windowP, GLFW_RESIZABLE); +} + +//------------------------------------------------------------ +void ofAppGLFWWindow::iconify(bool bIconify) { + if (bIconify) + glfwIconifyWindow(windowP); + else + glfwRestoreWindow(windowP); +} + +void ofAppGLFWWindow::makeCurrent() { + glfwMakeContextCurrent(windowP); +} + #if defined(TARGET_LINUX) Display * ofAppGLFWWindow::getX11Display() { return glfwGetX11Display(); @@ -1792,3 +1466,36 @@ void ofAppGLFWWindow::setup(const ofGLESWindowSettings & settings) { #endif #endif + + +// DEPRECATED - REMOVE + +void ofAppGLFWWindow::setNumSamples(int _samples) { + settings.numSamples = _samples; +} + +void ofAppGLFWWindow::setDoubleBuffering(bool doubleBuff) { + settings.doubleBuffering = doubleBuff; +} + +void ofAppGLFWWindow::setColorBits(int r, int g, int b) { + settings.redBits = r; + settings.greenBits = g; + settings.blueBits = b; +} + +void ofAppGLFWWindow::setAlphaBits(int a) { + settings.alphaBits = a; +} + +void ofAppGLFWWindow::setDepthBits(int depth) { + settings.depthBits = depth; +} + +void ofAppGLFWWindow::setStencilBits(int stencil) { + settings.stencilBits = stencil; +} + +void ofAppGLFWWindow::setMultiDisplayFullscreen(bool bMultiFullscreen) { + settings.multiMonitorFullScreen = bMultiFullscreen; +} diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.h b/libs/openFrameworks/app/ofAppGLFWWindow.h index 1a58743cf84..cfd8cdfdc7a 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.h +++ b/libs/openFrameworks/app/ofAppGLFWWindow.h @@ -1,7 +1,6 @@ #pragma once #include "ofAppBaseWindow.h" -// MARK: Optimize to Pointer #include "ofRectangle.h" // MARK: Target #include "ofConstants.h" @@ -14,64 +13,23 @@ typedef struct _XIC * XIC; class ofBaseApp; struct GLFWwindow; +struct GLFWmonitor; class ofCoreEvents; + template class ofPixels_; typedef ofPixels_ ofPixels; -#ifdef TARGET_OPENGLES -class ofGLFWWindowSettings : public ofGLESWindowSettings { -#else -class ofGLFWWindowSettings : public ofGLWindowSettings { -#endif -public: - ofGLFWWindowSettings() { } - -#ifdef TARGET_OPENGLES - ofGLFWWindowSettings(const ofGLESWindowSettings & settings) - : ofGLESWindowSettings(settings) { } -#else - ofGLFWWindowSettings(const ofGLWindowSettings & settings) - : ofGLWindowSettings(settings) { } -#endif - -#ifdef TARGET_RASPBERRY_PI - int numSamples = 0; -#else - int numSamples = 4; -#endif - - bool doubleBuffering = true; - int redBits = 8; - int greenBits = 8; - int blueBits = 8; - int alphaBits = 8; - int depthBits = 24; - int stencilBits = 0; - bool stereo = false; - bool visible = true; - bool iconified = false; - bool decorated = true; - bool floating = false; - bool resizable = true; - bool transparent = false; - bool mousePassThrough = false; - bool maximized = false; - int monitor = 0; - bool multiMonitorFullScreen = false; - std::shared_ptr shareContextWith; -}; - -#ifdef TARGET_OPENGLES -class ofAppGLFWWindow : public ofAppBaseGLESWindow { -#else -class ofAppGLFWWindow : public ofAppBaseGLWindow { -#endif +[[deprecated ("In This Branch ~ use ofWindowSettings instead")]] +typedef ofWindowSettings ofGLFWWindowSettings; +class ofAppGLFWWindow : public ofAppBaseWindow { public: ofAppGLFWWindow(); ~ofAppGLFWWindow(); - + +// ofWindowMode getWindowMode() { return settings.windowMode; } + // Can't be copied, use shared_ptr ofAppGLFWWindow(ofAppGLFWWindow & w) = delete; ofAppGLFWWindow & operator=(ofAppGLFWWindow & w) = delete; @@ -83,13 +41,9 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow { static void pollEvents(); // this functions are only meant to be called from inside OF don't call them from your code - using ofAppBaseWindow::setup; -#ifdef TARGET_OPENGLES - void setup(const ofGLESWindowSettings & settings); -#else - void setup(const ofGLWindowSettings & settings); -#endif - void setup(const ofGLFWWindowSettings & settings); +// using ofAppBaseWindow::setup; + + void setup(const ofWindowSettings & settings); void update(); void draw(); bool getWindowShouldClose(); @@ -106,21 +60,20 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow { GLFWwindow * getGLFWWindow(); void * getWindowContext() { return getGLFWWindow(); } - ofGLFWWindowSettings getSettings() { return settings; } + ofWindowSettings getSettings() { return settings; } + + glm::ivec2 getScreenSize(); + glm::ivec2 getWindowSize(); + glm::ivec2 getFramebufferSize(); + glm::ivec2 getWindowPosition(); + ofRectangle getWindowRect(); - glm::vec2 getWindowSize(); - glm::vec2 getScreenSize(); - glm::vec2 getWindowPosition(); + void setWindowTitle(const std::string & title); - void setWindowTitle(std::string title); + void setWindowRect(const ofRectangle & rect); void setWindowPosition(int x, int y); void setWindowShape(int w, int h); - void setOrientation(ofOrientation orientation); - ofOrientation getOrientation(); - - ofWindowMode getWindowMode(); - void setFullscreen(bool fullscreen); void toggleFullscreen(); void setWindowMousePassThrough(bool allowPassThrough); @@ -147,24 +100,10 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow { bool isWindowResizeable(); void iconify(bool bIconify); - // window settings, this functions can only be called from main before calling ofSetupOpenGL - // TODO: remove specialized version of ofSetupOpenGL when these go away - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setNumSamples(int samples); - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setDoubleBuffering(bool doubleBuff); - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setColorBits(int r, int g, int b); - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setAlphaBits(int a); - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setDepthBits(int depth); - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setStencilBits(int stencil); - [[deprecated("use ofGLFWWindowSettings to create the window")]] - void setMultiDisplayFullscreen(bool bMultiFullscreen); //note this just enables the mode, you have to toggle fullscreen to activate it. - #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) + typedef struct _XIM * XIM; + typedef struct _XIC * XIC; + Display * getX11Display(); Window getX11Window(); XIC getX11XIC(); @@ -195,20 +134,22 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow { private: static ofAppGLFWWindow * setCurrent(GLFWwindow* windowP); - static void mouse_cb(GLFWwindow* windowP_, int button, int state, int mods); - static void motion_cb(GLFWwindow* windowP_, double x, double y); - static void entry_cb(GLFWwindow* windowP_, int entered); - static void keyboard_cb(GLFWwindow* windowP_, int key, int scancode, int action, int mods); - static void char_cb(GLFWwindow* windowP_, uint32_t key); - static void resize_cb(GLFWwindow* windowP_, int w, int h); - static void position_cb(GLFWwindow* windowP_, int x, int y); - static void framebuffer_size_cb(GLFWwindow* windowP_, int w, int h); - static void exit_cb(GLFWwindow* windowP_); - static void scroll_cb(GLFWwindow* windowP_, double x, double y); - static void drop_cb(GLFWwindow* windowP_, int numFiles, const char** dropString); - static void error_cb(int errorCode, const char* errorDescription); - static void refresh_cb(GLFWwindow * windowP_); - + static ofAppGLFWWindow * getWindow(GLFWwindow* windowP); + static void mouse_cb(GLFWwindow* windowP_, int button, int state, int mods); + static void motion_cb(GLFWwindow* windowP_, double x, double y); + static void entry_cb(GLFWwindow* windowP_, int entered); + static void keyboard_cb(GLFWwindow* windowP_, int key, int scancode, int action, int mods); + static void char_cb(GLFWwindow* windowP_, uint32_t key); + static void position_cb(GLFWwindow* windowP_, int x, int y); + static void resize_cb(GLFWwindow* windowP_, int w, int h); + static void framebuffer_size_cb(GLFWwindow* windowP_, int w, int h); + static void exit_cb(GLFWwindow * windowP_); + static void scroll_cb(GLFWwindow * windowP_, double x, double y); + static void drop_cb(GLFWwindow* windowP_, int numFiles, const char** dropString); + static void error_cb(int errorCode, const char * errorDescription); + static void refresh_cb(GLFWwindow * windowP_); + static void monitor_cb(GLFWmonitor * monitor, int event); + void close(); #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) @@ -216,42 +157,118 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow { XIC xic; #endif +// ofCoreEvents coreEvents; std::unique_ptr coreEvents; std::shared_ptr currentRenderer; - ofGLFWWindowSettings settings; ofWindowMode targetWindowMode; bool bEnableSetupScreen; - int windowW, windowH; /// Physical framebuffer pixels extents - int currentW, currentH; /// Extents of the window client area, which may be scaled by pixelsScreenCoordScale to map to physical framebuffer pixels. - float pixelScreenCoordScale; /// Scale factor from virtual operating-system defined client area extents (as seen in currentW, currentH) to physical framebuffer pixel coordinates (as seen in windowW, windowH). - ofRectangle windowRect; + ofRectangle windowRect { 20, 20, 800, 600 }; + ofRectangle windowRectFS { 0, 0, 1920, 1080 }; + void setFSTarget(ofWindowMode targetWindowMode); int buttonInUse; bool buttonPressed; - int nFramesSinceWindowResized; +// int nFramesSinceWindowResized; bool bWindowNeedsShowing; -#ifdef TARGET_RASPBERRY_PI - bool needsResizeCheck = false; /// Just for RPI at this point -#endif - GLFWwindow * windowP; + ofBaseApp * ofAppPtr; - int getCurrentMonitor(); + bool iconSet; + + + void beginDraw(); + void endDraw(); + +// static ofAppGLFWWindow * thisWindow = static_cast(this); + + // window settings, this functions can only be called from main before calling ofSetupOpenGL + // TODO: remove specialized version of ofSetupOpenGL when these go away + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setNumSamples(int samples); + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setDoubleBuffering(bool doubleBuff); + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setColorBits(int r, int g, int b); + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setAlphaBits(int a); + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setDepthBits(int depth); + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setStencilBits(int stencil); + [[deprecated("use ofGLFWWindowSettings to create the window")]] + void setMultiDisplayFullscreen(bool bMultiFullscreen); //note this just enables the mode, you have to toggle fullscreen to activate it. + +}; - ofBaseApp * ofAppPtr; - ofOrientation orientation; - bool iconSet; +// TEMPORARY +#include "GLFW/glfw3.h" +// TEMP oftostring +#include "ofUtils.h" +#include -#ifdef TARGET_WIN32 - LONG lExStyle, lStyle; -#endif // TARGET_WIN32 -}; +static struct ofMonitors { +public: + ofMonitors() {} + ~ofMonitors() {} + std::vector rects; + ofRectangle allMonitorsRect { 0, 0, 0, 0 }; + GLFWmonitor** monitors; + + ofRectangle getRectMonitorForScreenRect(const ofRectangle & rect) { + for (unsigned int a=0; awidth, desktopMode->height ); + rects.emplace_back(rect); + allMonitorsRect = allMonitorsRect.getUnion(rect); + } + } + + ofRectangle getRectFromMonitors(const std::vector monitors) { + bool first = true; + ofRectangle r; + std::string str { "" }; + for (auto & i : monitors) { + str += ofToString(i) + " "; + if (i < rects.size()) { + if (first) { + first = false; + r = rects[i]; + } else { + r = r.getUnion(rects[i]); + } + } + } + return r; + } +} allMonitors; #endif diff --git a/libs/openFrameworks/app/ofAppNoWindow.cpp b/libs/openFrameworks/app/ofAppNoWindow.cpp index b8632a343ea..5eaa72999e0 100644 --- a/libs/openFrameworks/app/ofAppNoWindow.cpp +++ b/libs/openFrameworks/app/ofAppNoWindow.cpp @@ -123,6 +123,7 @@ class ofNoopRenderer: public ofBaseRenderer{ void setupGraphicDefaults(){}; void setupScreen(){}; + // FIXME: this is not standard with the other window modes. void setOrientation(ofOrientation, bool){} bool isVFlipped() const{return true;} glm::mat4 getCurrentMatrix(ofMatrixMode) const{return glm::mat4(1.0);}; @@ -285,18 +286,18 @@ void ofAppNoWindow::exitApp(){ } //---------------------------------------------------------- -glm::vec2 ofAppNoWindow::getWindowPosition(){ +glm::ivec2 ofAppNoWindow::getWindowPosition(){ return {0.f, 0.f}; } //---------------------------------------------------------- -glm::vec2 ofAppNoWindow::getWindowSize(){ +glm::ivec2 ofAppNoWindow::getWindowSize(){ return {width, height}; } //---------------------------------------------------------- -glm::vec2 ofAppNoWindow::getScreenSize(){ - return {width, height}; +glm::ivec2 ofAppNoWindow::getScreenSize(){ + return { width, height }; } diff --git a/libs/openFrameworks/app/ofAppNoWindow.h b/libs/openFrameworks/app/ofAppNoWindow.h index b92df93d289..8e6235da25a 100644 --- a/libs/openFrameworks/app/ofAppNoWindow.h +++ b/libs/openFrameworks/app/ofAppNoWindow.h @@ -25,9 +25,9 @@ class ofAppNoWindow : public ofAppBaseWindow { void update(); void draw(); - glm::vec2 getWindowPosition(); - glm::vec2 getWindowSize(); - glm::vec2 getScreenSize(); + glm::ivec2 getWindowPosition(); + glm::ivec2 getWindowSize(); + glm::ivec2 getScreenSize(); int getWidth(); int getHeight(); diff --git a/libs/openFrameworks/app/ofAppRunner.cpp b/libs/openFrameworks/app/ofAppRunner.cpp index df84e27ffbb..1a1563b6aeb 100644 --- a/libs/openFrameworks/app/ofAppRunner.cpp +++ b/libs/openFrameworks/app/ofAppRunner.cpp @@ -10,6 +10,8 @@ #include "ofEvents.h" // of::priv #include "ofUtils.h" // initUtils +ofCoreInternal ofCore; + using std::shared_ptr; #if !defined(TARGET_NODISPLAY) @@ -23,14 +25,14 @@ using std::shared_ptr; auto settings = windowPtr->getSettings(); settings.setSize(w,h); settings.windowMode = screenMode; - ofGetMainLoop()->addWindow(windowPtr); + ofCore.mainLoop->addWindow(windowPtr); windowPtr->setup(settings); } #endif #endif #ifdef TARGET_LINUX -#include "ofGstUtils.h" + #include "ofGstUtils.h" #endif // adding this for vc2010 compile: error C3861: 'closeQuicktime': identifier not found @@ -43,29 +45,9 @@ using std::shared_ptr; #endif + //-------------------------------------- namespace{ - - shared_ptr & mainLoop(){ - static shared_ptr * mainLoop(new shared_ptr(new ofMainLoop)); - return *mainLoop; - } - - bool & initialized(){ - static bool * initialized = new bool(false); - return *initialized; - } - - bool & exiting(){ - static bool * exiting = new bool(false); - return *exiting; - } - - ofCoreEvents & noopEvents(){ - static auto * noopEvents = new ofCoreEvents(); - return *noopEvents; - } - #if defined(TARGET_LINUX) || defined(TARGET_OSX) #include #include @@ -84,9 +66,9 @@ namespace{ signal(SIGHUP, nullptr); signal(SIGABRT, nullptr); - if(mainLoop()){ - mainLoop()->shouldClose(signum); - } + if(ofCore.mainLoop){ + ofCore.mainLoop->shouldClose(signum); + } } #endif } @@ -105,9 +87,28 @@ void ofCloseFreeImage(); void ofInit(){ - if(initialized()) return; - initialized() = true; - exiting() = false; + ofCore.init(); + ofCore.shutdownFunctions = { + ofURLFileLoaderShutdown, + ofTrueTypeShutdown, + ofCloseFreeImage, + // not even needed. empty function + of::priv::endutils, +#ifndef TARGET_NO_SOUND + ofSoundShutdown, +#endif + +#if defined(OF_VIDEO_CAPTURE_QUICKTIME) || defined(OF_VIDEO_PLAYER_QUICKTIME) + closeQuicktime, +#endif + +#ifdef TARGET_LINUX + ofGstUtils::quitGstMainLoop, +#endif + }; + +// std::cout << "ofInit, shutdown functions size = " << ofCore.shutdownFunctions.size() << std::endl; +// #if defined(TARGET_ANDROID) || defined(TARGET_OF_IOS) // manage own exit @@ -160,31 +161,33 @@ void ofInit(){ setlocale(LC_ALL,""); ofLogWarning("ofInit") << "MSYS2 has limited support for UTF-8. using "<< std::string( setlocale(LC_ALL,NULL) ); #endif + return; + } //-------------------------------------- shared_ptr ofGetMainLoop(){ - return mainLoop(); + return ofCore.mainLoop; } //-------------------------------------- void ofSetMainLoop(const shared_ptr & newMainLoop) { - mainLoop() = newMainLoop; + ofCore.mainLoop = newMainLoop; } //-------------------------------------- int ofRunApp(ofBaseApp * OFSA){ - mainLoop()->run(shared_ptr(OFSA)); + ofCore.mainLoop->run(shared_ptr(OFSA)); auto ret = ofRunMainLoop(); #if !defined(TARGET_ANDROID) && !defined(TARGET_OF_IOS) ofExitCallback(); #endif return ret; } - -//-------------------------------------- -int ofRunApp(shared_ptr && app){ - mainLoop()->run(std::move(app)); +// +////-------------------------------------- +int ofRunApp(const shared_ptr & app){ + ofCore.mainLoop->run(app); auto ret = ofRunMainLoop(); #if !defined(TARGET_ANDROID) && !defined(TARGET_OF_IOS) ofExitCallback(); @@ -192,23 +195,29 @@ int ofRunApp(shared_ptr && app){ return ret; } -//-------------------------------------- -void ofRunApp(const shared_ptr & window, shared_ptr && app){ - mainLoop()->run(window, std::move(app)); +////-------------------------------------- +//void ofRunApp(const shared_ptr & window, shared_ptr && app){ +// ofCore.mainLoop->run(window, std::move(app)); +//} + +void ofRunApp( + const shared_ptr & window, + const shared_ptr & app){ + ofInit(); + ofCore.mainLoop->run(window, app); } int ofRunMainLoop(){ - auto ret = mainLoop()->loop(); + auto ret = ofCore.mainLoop->loop(); return ret; } //-------------------------------------- void ofSetupOpenGL(int w, int h, ofWindowMode screenMode){ + ofWindowSettings settings; #ifdef TARGET_OPENGLES - ofGLESWindowSettings settings; settings.glesVersion = 1; #else - ofGLWindowSettings settings; settings.glVersionMajor = 2; settings.glVersionMinor = 1; #endif @@ -218,104 +227,53 @@ void ofSetupOpenGL(int w, int h, ofWindowMode screenMode){ ofCreateWindow(settings); } + shared_ptr ofCreateWindow(const ofWindowSettings & settings){ - ofInit(); - return mainLoop()->createWindow(settings); + return ofCore.mainLoop->createWindow(settings); } -//----------------------- gets called when the app exits -// currently looking at who to turn off -// at the end of the application void ofExitCallback(){ - if(!initialized()) return; - - // controlled destruction of the mainLoop before - // any other deinitialization - mainLoop()->exit(); - - // everything should be destroyed here, except for - // static objects - - - // finish every library and subsystem - ofURLFileLoaderShutdown(); - - #ifndef TARGET_NO_SOUND - //------------------------ - // try to close engine if needed: - ofSoundShutdown(); - //------------------------ - #endif - - // try to close quicktime, for non-linux systems: - #if defined(OF_VIDEO_CAPTURE_QUICKTIME) || defined(OF_VIDEO_PLAYER_QUICKTIME) - closeQuicktime(); - #endif - - - //------------------------ - // try to close freeImage: - ofCloseFreeImage(); - - - #ifdef WIN32_HIGH_RES_TIMING - timeEndPeriod(1); - #endif - - //------------------------ - // try to close gstreamer - #ifdef TARGET_LINUX - ofGstUtils::quitGstMainLoop(); - #endif - - //------------------------ - // try to close font libraries - ofTrueTypeShutdown(); - - // static deinitialization happens after this finishes - // every object should have ended by now and won't receive any - // events - of::priv::endutils(); - - initialized() = false; - exiting() = true; + ofCore.exit(); +#ifdef WIN32_HIGH_RES_TIMING + timeEndPeriod(1); +#endif } //-------------------------------------- // core events instance & arguments ofCoreEvents & ofEvents(){ - auto window = mainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if(window){ return window->events(); }else{ - if(!exiting()){ + if(!ofCore.exiting){ ofLogError("ofEvents") << "Trying to call ofEvents() before a window has been setup"; ofLogError("ofEvents") << "We'll return a void events instance to avoid crashes but somethings might not work"; ofLogError("ofEvents") << "Set a breakpoint in " << __FILE__ << " line " << __LINE__ << " to check where is the wrong call"; } - return noopEvents(); + return ofCore.noopEvents; } } //-------------------------------------- void ofSetEscapeQuitsApp(bool bQuitOnEsc){ - mainLoop()->setEscapeQuitsLoop(bQuitOnEsc); + ofCore.mainLoop->setEscapeQuitsLoop(bQuitOnEsc); } //-------------------------------------- shared_ptr & ofGetCurrentRenderer(){ - return mainLoop()->getCurrentWindow()->renderer(); + return ofCore.getCurrentWindow()->renderer(); } //-------------------------------------- ofBaseApp * ofGetAppPtr(){ - return mainLoop()->getCurrentApp().get(); + return ofCore.mainLoop->getCurrentApp().get(); } //-------------------------------------- std::thread::id ofGetMainThreadId() { - return ofGetMainLoop()->get_thread_id() ; + return ofCore.mainLoop->get_thread_id() ; } bool ofIsCurrentThreadTheMainThread() { @@ -324,32 +282,34 @@ bool ofIsCurrentThreadTheMainThread() { //-------------------------------------- ofAppBaseWindow * ofGetWindowPtr(){ - return mainLoop()->getCurrentWindow().get(); + return ofGetCurrentWindow().get(); } //-------------------------------------- std::shared_ptr ofGetCurrentWindow() { - return mainLoop()->getCurrentWindow(); +// return ofCore.getCurrentWindow(); + return ofCore.mainLoop->getCurrentWindow(); } //-------------------------------------- void ofExit(int status){ - mainLoop()->shouldClose(status); + ofCore.mainLoop->shouldClose(status); } //-------------------------------------- void ofHideCursor(){ - mainLoop()->getCurrentWindow()->hideCursor(); + ofCore.getCurrentWindow()->hideCursor(); } //-------------------------------------- void ofShowCursor(){ - mainLoop()->getCurrentWindow()->showCursor(); + ofCore.getCurrentWindow()->showCursor(); } //-------------------------------------- +// FIXME: this is not standard with the other window modes. void ofSetOrientation(ofOrientation orientation, bool vFlip){ - mainLoop()->getCurrentWindow()->setOrientation(orientation); + ofCore.getCurrentWindow()->setOrientation(orientation); // TODO: every window should set orientation on it's renderer if(ofGetCurrentRenderer()){ ofGetCurrentRenderer()->setOrientation(orientation,vFlip); @@ -358,76 +318,92 @@ void ofSetOrientation(ofOrientation orientation, bool vFlip){ //-------------------------------------- ofOrientation ofGetOrientation(){ - return mainLoop()->getCurrentWindow()->getOrientation(); + return ofCore.getCurrentWindow()->getOrientation(); } //-------------------------------------- void ofSetWindowPosition(int x, int y){ - mainLoop()->getCurrentWindow()->setWindowPosition(x,y); + ofCore.getCurrentWindow()->setWindowPosition(x,y); } //-------------------------------------- void ofSetWindowShape(int width, int height){ - mainLoop()->getCurrentWindow()->setWindowShape(width, height); + ofCore.getCurrentWindow()->setWindowShape(width, height); +} + +//-------------------------------------- +void ofSetWindowRect(const ofRectangle & rect) { + ofCore.getCurrentWindow()->setWindowRect(rect); +} + +//-------------------------------------- +glm::ivec2 ofGetWindowPosition() { + return ofCore.getCurrentWindow()->getWindowPosition(); } //-------------------------------------- int ofGetWindowPositionX(){ - return (int)mainLoop()->getCurrentWindow()->getWindowPosition().x; + return (int)ofCore.getCurrentWindow()->getWindowPosition().x; } //-------------------------------------- int ofGetWindowPositionY(){ - return (int)mainLoop()->getCurrentWindow()->getWindowPosition().y; + return (int)ofCore.getCurrentWindow()->getWindowPosition().y; } //-------------------------------------- int ofGetScreenWidth(){ - return (int)mainLoop()->getCurrentWindow()->getScreenSize().x; + return ofCore.getCurrentWindow()->getScreenSize().x; } //-------------------------------------- int ofGetScreenHeight(){ - return (int)mainLoop()->getCurrentWindow()->getScreenSize().y; + return ofCore.getCurrentWindow()->getScreenSize().y; +} + +//-------------------------------------- +glm::ivec2 ofGetScreenSize() { + return ofCore.getCurrentWindow()->getScreenSize(); } //-------------------------------------------------- int ofGetWidth(){ - return (int)mainLoop()->getCurrentWindow()->getWidth(); + return (int)ofCore.getCurrentWindow()->getWidth(); } + //-------------------------------------------------- int ofGetHeight(){ - return (int)mainLoop()->getCurrentWindow()->getHeight(); + return (int)ofCore.getCurrentWindow()->getHeight(); } //-------------------------------------------------- int ofGetWindowWidth(){ - return (int)mainLoop()->getCurrentWindow()->getWindowSize().x; + return (int)ofCore.getCurrentWindow()->getWindowSize().x; } //-------------------------------------------------- int ofGetWindowHeight(){ - return (int)mainLoop()->getCurrentWindow()->getWindowSize().y; + return (int)ofCore.getCurrentWindow()->getWindowSize().y; } //-------------------------------------------------- std::string ofGetClipboardString(){ - return mainLoop()->getCurrentWindow()->getClipboardString(); + return ofCore.getCurrentWindow()->getClipboardString(); } //-------------------------------------------------- void ofSetClipboardString(const std::string & str){ - mainLoop()->getCurrentWindow()->setClipboardString(str); + ofCore.getCurrentWindow()->setClipboardString(str); } //-------------------------------------------------- bool ofDoesHWOrientation(){ - return mainLoop()->getCurrentWindow()->doesHWOrientation(); + return ofCore.getCurrentWindow()->doesHWOrientation(); } //-------------------------------------------------- -glm::vec2 ofGetWindowSize() { +glm::ivec2 ofGetWindowSize() { //this can't return glm::vec2(ofGetWidth(), ofGetHeight()) as width and height change based on orientation. - return mainLoop()->getCurrentWindow()->getWindowSize(); + return ofCore.getCurrentWindow()->getWindowSize(); } //-------------------------------------------------- @@ -441,96 +417,97 @@ float ofRandomHeight() { } //-------------------------------------------------- +// FIXME: This is wrong. doesn't consider window offset. ofRectangle ofGetWindowRect() { return ofRectangle(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); } //-------------------------------------- void ofSetWindowTitle(std::string title){ - mainLoop()->getCurrentWindow()->setWindowTitle(title); + ofCore.getCurrentWindow()->setWindowTitle(title); } //---------------------------------------------------------- void ofEnableSetupScreen(){ - mainLoop()->getCurrentWindow()->enableSetupScreen(); + ofCore.getCurrentWindow()->enableSetupScreen(); } //---------------------------------------------------------- void ofDisableSetupScreen(){ - mainLoop()->getCurrentWindow()->disableSetupScreen(); + ofCore.getCurrentWindow()->disableSetupScreen(); } //-------------------------------------- void ofToggleFullscreen(){ - mainLoop()->getCurrentWindow()->toggleFullscreen(); + ofCore.getCurrentWindow()->toggleFullscreen(); } //-------------------------------------- void ofSetWindowMousePassThrough(bool allowPassThrough){ - mainLoop()->getCurrentWindow()->setWindowMousePassthrough(allowPassThrough); + ofCore.getCurrentWindow()->setWindowMousePassthrough(allowPassThrough); } //-------------------------------------- void ofSetFullscreen(bool fullscreen){ - mainLoop()->getCurrentWindow()->setFullscreen(fullscreen); + ofCore.getCurrentWindow()->setFullscreen(fullscreen); } //-------------------------------------- int ofGetWindowMode(){ - return mainLoop()->getCurrentWindow()->getWindowMode(); + return ofCore.getCurrentWindow()->getWindowMode(); } //-------------------------------------- void ofSetVerticalSync(bool bSync){ - mainLoop()->getCurrentWindow()->setVerticalSync(bSync); + ofCore.getCurrentWindow()->setVerticalSync(bSync); } //-------------------------- native window handles #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) Display* ofGetX11Display(){ - return mainLoop()->getCurrentWindow()->getX11Display(); + return ofCore.getCurrentWindow()->getX11Display(); } Window ofGetX11Window(){ - return mainLoop()->getCurrentWindow()->getX11Window(); + return ofCore.getCurrentWindow()->getX11Window(); } #endif #if defined(TARGET_LINUX) && !defined(TARGET_OPENGLES) GLXContext ofGetGLXContext(){ - return mainLoop()->getCurrentWindow()->getGLXContext(); + return ofCore.getCurrentWindow()->getGLXContext(); } #endif #if defined(TARGET_LINUX) && defined(TARGET_OPENGLES) EGLDisplay ofGetEGLDisplay(){ - return mainLoop()->getCurrentWindow()->getEGLDisplay(); + return ofCore.getCurrentWindow()->getEGLDisplay(); } EGLContext ofGetEGLContext(){ - return mainLoop()->getCurrentWindow()->getEGLContext(); + return ofCore.getCurrentWindow()->getEGLContext(); } EGLSurface ofGetEGLSurface(){ - return mainLoop()->getCurrentWindow()->getEGLSurface(); + return ofCore.getCurrentWindow()->getEGLSurface(); } #endif #if defined(TARGET_OSX) void * ofGetNSGLContext(){ - return mainLoop()->getCurrentWindow()->getNSGLContext(); + return ofCore.getCurrentWindow()->getNSGLContext(); } void * ofGetCocoaWindow(){ - return mainLoop()->getCurrentWindow()->getCocoaWindow(); + return ofCore.getCurrentWindow()->getCocoaWindow(); } #endif #if defined(TARGET_WIN32) HGLRC ofGetWGLContext(){ - return mainLoop()->getCurrentWindow()->getWGLContext(); + return ofCore.getCurrentWindow()->getWGLContext(); } HWND ofGetWin32Window(){ - return mainLoop()->getCurrentWindow()->getWin32Window(); + return ofCore.getCurrentWindow()->getWin32Window(); } #endif diff --git a/libs/openFrameworks/app/ofAppRunner.h b/libs/openFrameworks/app/ofAppRunner.h index 86f4f01e1e8..55ffe5ad8dd 100644 --- a/libs/openFrameworks/app/ofAppRunner.h +++ b/libs/openFrameworks/app/ofAppRunner.h @@ -10,6 +10,64 @@ class ofBaseApp; class ofBaseRenderer; class ofCoreEvents; +using std::cout; +using std::endl; + +struct ofCoreInternal { +public: + ofCoreInternal() {}; + ~ofCoreInternal() {}; + + std::string name = "virgem"; + + std::vector > shutdownFunctions; + // ofAppRunner + bool initialized = false; + bool exiting = false; + ofCoreEvents noopEvents; +// ofMainLoop mainLoop; + std::shared_ptr mainLoop { std::make_shared() }; + + // ofFileUtils + + void exit() { + if(!initialized) return; + + // controlled destruction of the mainLoop before + // any other deinitialization + // mainLoop->exit(); +// mainLoop.exit(); + + // all shutdown functions called + for (const auto & func : shutdownFunctions) { + func(); + } + + initialized = false; + exiting = true; + } + + void init() { + name = "inicializado"; + if (initialized) return; + initialized = true; + exiting = false; + } + + std::shared_ptr getCurrentWindow(){ +// if (mainLoop) //mainLoop is always present. is it? + { + return mainLoop->currentWindow.lock(); + } + cout << "getCurrentWindow ofCore nullptr name=" << name << endl; + return nullptr; + } + +}; + +extern ofCoreInternal ofCore; + + void ofInit(); void ofSetupOpenGL(int w, int h, ofWindowMode screenMode); // sets up the opengl context! std::shared_ptr ofCreateWindow(const ofWindowSettings & settings); // sets up the opengl context! @@ -22,7 +80,7 @@ void ofSetupOpenGL(const std::shared_ptr & windowPtr, int w, int h, ofWi ofWindowSettings settings; settings.setSize(w, h); settings.windowMode = screenMode; - ofGetMainLoop()->addWindow(windowPtr); +// ofCore.mainLoop.addWindow(windowPtr); windowPtr->setup(settings); } @@ -39,9 +97,11 @@ void ofSetupOpenGL(Window * windowPtr, int w, int h, ofWindowMode screenMode) { ofSetupOpenGL(window, w, h, screenMode); } -int ofRunApp(std::shared_ptr && OFSA); +int ofRunApp(const std::shared_ptr & OFSA); + int ofRunApp(ofBaseApp * OFSA = nullptr); // will be deprecated -void ofRunApp(const std::shared_ptr & window, std::shared_ptr && app); +void ofRunApp(const std::shared_ptr & window, + const std::shared_ptr & app); int ofRunMainLoop(); ofBaseApp * ofGetAppPtr(); @@ -71,14 +131,16 @@ ofOrientation ofGetOrientation(); void ofHideCursor(); void ofShowCursor(); //-------------------------- window / screen +glm::ivec2 ofGetWindowPosition(); int ofGetWindowPositionX(); int ofGetWindowPositionY(); int ofGetScreenWidth(); int ofGetScreenHeight(); +glm::ivec2 ofGetScreenSize(); int ofGetWindowMode(); -int ofGetWidth(); // ofGetWidth is correct for orientation +int ofGetWidth(); int ofGetHeight(); -int ofGetWindowWidth(); // ofGetWindowWidth is correct for actual window coordinates - so doesn't change with orientation. +int ofGetWindowWidth(); int ofGetWindowHeight(); std::string ofGetClipboardString(); @@ -90,13 +152,14 @@ float ofRandomWidth(); /// \returns a random number between 0 and the height of the window. float ofRandomHeight(); bool ofDoesHWOrientation(); -glm::vec2 ofGetWindowSize(); +glm::ivec2 ofGetWindowSize(); ofRectangle ofGetWindowRect(); ofAppBaseWindow * ofGetWindowPtr(); std::shared_ptr ofGetCurrentWindow(); void ofSetWindowPosition(int x, int y); void ofSetWindowShape(int width, int height); +void ofSetWindowRect(const ofRectangle & rect); void ofSetWindowTitle(std::string title); void ofEnableSetupScreen(); void ofDisableSetupScreen(); @@ -107,7 +170,7 @@ void ofSetWindowMousePassThrough(bool allowPassThrough); void ofSetVerticalSync(bool bSync); ofCoreEvents & ofEvents(); -void ofSetCurrentRenderer(std::shared_ptr renderer, bool setDefaults = false); +void ofSetCurrentRenderer(const std::shared_ptr & renderer, bool setDefaults = false); std::shared_ptr & ofGetCurrentRenderer(); void ofSetEscapeQuitsApp(bool bQuitOnEsc); @@ -141,3 +204,5 @@ void * ofGetCocoaWindow(); HGLRC ofGetWGLContext(); HWND ofGetWin32Window(); #endif + + diff --git a/libs/openFrameworks/app/ofMainLoop.cpp b/libs/openFrameworks/app/ofMainLoop.cpp index 461a7f1c2e3..eaa732bf43d 100644 --- a/libs/openFrameworks/app/ofMainLoop.cpp +++ b/libs/openFrameworks/app/ofMainLoop.cpp @@ -7,34 +7,38 @@ #include "ofMainLoop.h" #include "ofBaseApp.h" -// #include "ofConstants.h" +// TEST WITHOUT +#include "ofConstants.h" +#include "ofAppBaseWindow.h" //======================================================================== // default windowing #ifdef TARGET_NODISPLAY #include "ofAppNoWindow.h" + typedef ofAppNoWindow ofWindow; + #elif defined(TARGET_OF_IOS) #include "ofAppiOSWindow.h" + typedef ofAppiOSWindow ofWindow; + #elif defined(TARGET_ANDROID) #include "ofAppAndroidWindow.h" #include "ofxAndroidUtils.h" #include "ofxAndroidApp.h" -#elif defined(TARGET_RASPBERRY_PI) && defined(TARGET_GLFW_WINDOW) - #include "ofAppGLFWWindow.h" -#elif defined(TARGET_RASPBERRY_PI) - #include "ofAppEGLWindow.h" + typedef ofAppAndroidWindow ofWindow; + +// Raspi removed to use GLFW +//#elif defined(TARGET_RASPBERRY_PI) +// #include "ofAppEGLWindow.h" #elif defined(TARGET_EMSCRIPTEN) #include "ofxAppEmscriptenWindow.h" + typedef ofxAppEmscriptenWindow ofWindow; #else #include "ofAppGLFWWindow.h" + typedef ofAppGLFWWindow ofWindow; #endif -ofMainLoop::ofMainLoop() -:bShouldClose(false) -,status(0) -,allowMultiWindow(true) -,escapeQuits(true){ - +ofMainLoop::ofMainLoop() : bShouldClose(false), status(0), allowMultiWindow(true), escapeQuits(true) { } ofMainLoop::~ofMainLoop() { @@ -42,32 +46,17 @@ ofMainLoop::~ofMainLoop() { } std::shared_ptr ofMainLoop::createWindow(const ofWindowSettings & settings){ -#ifdef TARGET_NODISPLAY - shared_ptr window = std::make_shared(); -#else - #if defined(TARGET_OF_IOS) - std::shared_ptr window = std::make_shared(); - #elif defined(TARGET_ANDROID) - std::shared_ptr window = std::make_shared(); - #elif (defined(TARGET_RASPBERRY_PI) && defined(TARGET_GLFW_WINDOW)) - std::shared_ptr window = std::make_shared(); - #elif defined(TARGET_RASPBERRY_PI) - std::shared_ptr window = std::make_shared(); - #elif defined(TARGET_EMSCRIPTEN) - std::shared_ptr window = std::make_shared(); - #elif defined(TARGET_OPENGLES) - std::shared_ptr window = std::make_shared(); - #else - std::shared_ptr window = std::make_shared(); - #endif -#endif + std::shared_ptr window { std::make_shared() }; addWindow(window); window->setup(settings); return window; } -void ofMainLoop::run(const std::shared_ptr & window, std::shared_ptr && app){ - windowsApps[window] = app; +void ofMainLoop::run( + const std::shared_ptr & window, + const std::shared_ptr & app) { + mainApp = app; +// windowsApps[window] = app; if(app){ ofAddListener(window->events().setup,app.get(),&ofBaseApp::setup,OF_EVENT_ORDER_APP); ofAddListener(window->events().update,app.get(),&ofBaseApp::update,OF_EVENT_ORDER_APP); @@ -107,21 +96,23 @@ void ofMainLoop::run(const std::shared_ptr & window, std::share #endif } currentWindow = window; + + // FIXME: remove? window->makeCurrent(); if(!windowLoop){ window->events().notifySetup(); } } -void ofMainLoop::run(std::shared_ptr && app){ - if(!windowsApps.empty()){ - run(windowsApps.begin()->first, std::move(app)); +void ofMainLoop::run(const std::shared_ptr & app){ + if(!windows.empty()){ + run(windows[0], app); } } int ofMainLoop::loop(){ if(!windowLoop){ - while(!bShouldClose && !windowsApps.empty()){ + while(!bShouldClose && !windows.empty()){ loopOnce(); pollEvents(); } @@ -134,19 +125,21 @@ int ofMainLoop::loop(){ void ofMainLoop::loopOnce(){ if(bShouldClose) return; - for(auto i = windowsApps.begin(); !windowsApps.empty() && i != windowsApps.end();){ - if(i->first->getWindowShouldClose()){ - const auto & window = i->first; - window->close(); - windowsApps.erase(i++); ///< i now points at the window after the one which was just erased - }else{ - currentWindow = i->first; - i->first->makeCurrent(); - i->first->update(); - i->first->draw(); - i++; ///< continue to next window + + auto i = windows.begin(); + for ( ; i != windows.end(); ) { + if (i->get()->getWindowShouldClose()) { + i = windows.erase(i); + } + else { + currentWindow = (*i); + i->get()->makeCurrent(); + i->get()->update(); + i->get()->draw(); + ++i; } } + loopEvent.notify(this); } @@ -159,55 +152,51 @@ void ofMainLoop::pollEvents(){ void ofMainLoop::exit(){ exitEvent.notify(this); - for(auto i: windowsApps){ - std::shared_ptr window = i.first; - std::shared_ptr app = i.second; - + for (auto window : windows) { if(window == nullptr) { continue; } - if(app == nullptr) { - continue; - } ofEventArgs args; ofNotifyEvent(window->events().exit, args, this); - ofRemoveListener(window->events().setup,app.get(),&ofBaseApp::setup,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().update,app.get(),&ofBaseApp::update,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().draw,app.get(),&ofBaseApp::draw,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().exit,app.get(),&ofBaseApp::exit,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().keyPressed,app.get(),&ofBaseApp::keyPressed,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().keyReleased,app.get(),&ofBaseApp::keyReleased,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mouseMoved,app.get(),&ofBaseApp::mouseMoved,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mouseDragged,app.get(),&ofBaseApp::mouseDragged,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mousePressed,app.get(),&ofBaseApp::mousePressed,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mouseReleased,app.get(),&ofBaseApp::mouseReleased,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mouseScrolled,app.get(),&ofBaseApp::mouseScrolled,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mouseEntered,app.get(),&ofBaseApp::mouseEntered,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().mouseExited,app.get(),&ofBaseApp::mouseExited,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().windowResized,app.get(),&ofBaseApp::windowResized,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().messageEvent,app.get(),&ofBaseApp::messageReceived,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().fileDragEvent,app.get(),&ofBaseApp::dragged,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().touchCancelled,app.get(),&ofBaseApp::touchCancelled,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().touchDoubleTap,app.get(),&ofBaseApp::touchDoubleTap,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().touchDown,app.get(),&ofBaseApp::touchDown,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().touchMoved,app.get(),&ofBaseApp::touchMoved,OF_EVENT_ORDER_APP); - ofRemoveListener(window->events().touchUp,app.get(),&ofBaseApp::touchUp,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().setup,app.get(),&ofBaseApp::setup,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().update,app.get(),&ofBaseApp::update,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().draw,app.get(),&ofBaseApp::draw,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().exit,app.get(),&ofBaseApp::exit,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().keyPressed,app.get(),&ofBaseApp::keyPressed,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().keyReleased,app.get(),&ofBaseApp::keyReleased,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mouseMoved,app.get(),&ofBaseApp::mouseMoved,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mouseDragged,app.get(),&ofBaseApp::mouseDragged,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mousePressed,app.get(),&ofBaseApp::mousePressed,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mouseReleased,app.get(),&ofBaseApp::mouseReleased,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mouseScrolled,app.get(),&ofBaseApp::mouseScrolled,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mouseEntered,app.get(),&ofBaseApp::mouseEntered,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().mouseExited,app.get(),&ofBaseApp::mouseExited,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().windowResized,app.get(),&ofBaseApp::windowResized,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().messageEvent,app.get(),&ofBaseApp::messageReceived,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().fileDragEvent,app.get(),&ofBaseApp::dragged,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().touchCancelled,app.get(),&ofBaseApp::touchCancelled,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().touchDoubleTap,app.get(),&ofBaseApp::touchDoubleTap,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().touchDown,app.get(),&ofBaseApp::touchDown,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().touchMoved,app.get(),&ofBaseApp::touchMoved,OF_EVENT_ORDER_APP); +// ofRemoveListener(window->events().touchUp,app.get(),&ofBaseApp::touchUp,OF_EVENT_ORDER_APP); #ifdef TARGET_ANDROID - auto androidApp = dynamic_cast(app.get()); - if(androidApp){ - ofRemoveListener(ofxAndroidEvents().okPressed,androidApp,&ofxAndroidApp::okPressed,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().cancelPressed,androidApp,&ofxAndroidApp::cancelPressed,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().backPressed,androidApp,&ofxAndroidApp::backPressed,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().networkConnected,androidApp,&ofxAndroidApp::networkConnectedEvent,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().pause,androidApp,&ofxAndroidApp::pause,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().resume,androidApp,&ofxAndroidApp::resume,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().unloadGL,androidApp,&ofxAndroidApp::unloadGL,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().reloadGL,androidApp,&ofxAndroidApp::reloadGL,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().swipe,androidApp,&ofxAndroidApp::swipe,OF_EVENT_ORDER_APP); - ofRemoveListener(ofxAndroidEvents().deviceOrientationChanged,androidApp,&ofxAndroidApp::deviceOrientationChangedEvent,OF_EVENT_ORDER_APP); - } + + // FIXME: how will this work with Android? +// auto androidApp = dynamic_cast(app.get()); +// if(androidApp){ +// ofRemoveListener(ofxAndroidEvents().okPressed,androidApp,&ofxAndroidApp::okPressed,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().cancelPressed,androidApp,&ofxAndroidApp::cancelPressed,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().backPressed,androidApp,&ofxAndroidApp::backPressed,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().networkConnected,androidApp,&ofxAndroidApp::networkConnectedEvent,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().pause,androidApp,&ofxAndroidApp::pause,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().resume,androidApp,&ofxAndroidApp::resume,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().unloadGL,androidApp,&ofxAndroidApp::unloadGL,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().reloadGL,androidApp,&ofxAndroidApp::reloadGL,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().swipe,androidApp,&ofxAndroidApp::swipe,OF_EVENT_ORDER_APP); +// ofRemoveListener(ofxAndroidEvents().deviceOrientationChanged,androidApp,&ofxAndroidApp::deviceOrientationChangedEvent,OF_EVENT_ORDER_APP); +// } #endif } @@ -215,10 +204,13 @@ void ofMainLoop::exit(){ // reset applications then windows // so events are present until the // end of the application - for(auto & window_app: windowsApps){ - window_app.second.reset(); - } - windowsApps.clear(); +// for(auto & window_app: windowsApps){ +// window_app.second.reset(); +// } +// windowsApps.clear(); + + mainApp.reset(); + windows.clear(); } std::shared_ptr ofMainLoop::getCurrentWindow(){ @@ -233,21 +225,26 @@ void ofMainLoop::setCurrentWindow(ofAppBaseWindow * window){ if(currentWindow.lock().get() == window){ return; } - for(auto i: windowsApps){ - if(i.first.get() == window){ - currentWindow = i.first; + + for (const auto & w : windows) { + if (w.get() == window) { + currentWindow = w; break; } } } std::shared_ptr ofMainLoop::getCurrentApp(){ - return windowsApps[currentWindow.lock()]; +// return windowsApps[currentWindow.lock()]; + return mainApp; } void ofMainLoop::shouldClose(int _status){ - for(auto i: windowsApps){ - i.first->setWindowShouldClose(); +// for(auto i: windowsApps){ +// i.first->setWindowShouldClose(); +// } + for(auto w : windows){ + w->setWindowShouldClose(); } bShouldClose = true; status = _status; @@ -262,3 +259,24 @@ void ofMainLoop::keyPressed(ofKeyEventArgs & key){ shouldClose(0); } } + +int thisWindow = 0; +void ofMainLoop::ofBeginWindow(int n) { + if (n < windows.size()) { + thisWindow = n; + currentWindow = windows[thisWindow]; + windows[thisWindow]->makeCurrent(); + windows[thisWindow]->update(); +// windows[n].draw(); + windows[thisWindow]->beginDraw(); + + } +// currentWindow.beginDraw(); +} + +void ofMainLoop::ofEndWindow() { + windows[thisWindow]->endDraw(); + thisWindow = 0; + currentWindow = windows[thisWindow]; + windows[thisWindow]->makeCurrent(); +} diff --git a/libs/openFrameworks/app/ofMainLoop.h b/libs/openFrameworks/app/ofMainLoop.h index 923a889033c..f47c5bf7b10 100644 --- a/libs/openFrameworks/app/ofMainLoop.h +++ b/libs/openFrameworks/app/ofMainLoop.h @@ -1,7 +1,7 @@ #pragma once #include "ofEvents.h" -#include +//#include class ofBaseApp; class ofAppBaseWindow; @@ -24,15 +24,18 @@ class ofMainLoop { windowPollEvents = Window::pollEvents; } if(!allowMultiWindow){ - windowsApps.clear(); + windows.clear(); +// windowsApps.clear(); } - windowsApps[window] = std::shared_ptr(); + windows.emplace_back(window); +// windowsApps[window] = std::shared_ptr(); currentWindow = window; ofAddListener(window->events().keyPressed,this,&ofMainLoop::keyPressed); } - void run(const std::shared_ptr & window, std::shared_ptr && app); - void run(std::shared_ptr && app); + void run(const std::shared_ptr & window, const std::shared_ptr & app); +// std::shared_ptr && app); + void run(const std::shared_ptr & app); int loop(); void loopOnce(); void pollEvents(); @@ -48,17 +51,29 @@ class ofMainLoop { ofEvent loopEvent; std::thread::id get_thread_id() { return thread_id; }; + + std::vector > getWindows() { return windows; } + + void ofBeginWindow(int n); + void ofEndWindow(); + + +public: + std::weak_ptr currentWindow; private: std::thread::id thread_id { std::this_thread::get_id() }; void keyPressed(ofKeyEventArgs & key); - std::unordered_map, std::shared_ptr > windowsApps; + std::vector > windows; + std::shared_ptr mainApp; + bool bShouldClose; - std::weak_ptr currentWindow; int status; bool allowMultiWindow; std::function windowLoop; std::function windowPollEvents; bool escapeQuits; + + }; diff --git a/libs/openFrameworks/app/ofWindowSettings.h b/libs/openFrameworks/app/ofWindowSettings.h index 48836d914ba..2d42baf3593 100644 --- a/libs/openFrameworks/app/ofWindowSettings.h +++ b/libs/openFrameworks/app/ofWindowSettings.h @@ -1,10 +1,14 @@ #pragma once +class ofAppBaseWindow; + #define GLM_FORCE_CTOR_INIT #define GLM_ENABLE_EXPERIMENTAL #include #include +#include +#include /// \brief Used to represent the available windowing modes for the application. enum ofWindowMode{ @@ -13,7 +17,9 @@ enum ofWindowMode{ /// \brief A fullscreen application window. OF_FULLSCREEN = 1, /// \brief A fullscreen application window with a custom width and height. - OF_GAME_MODE = 2 + OF_GAME_MODE = 2, + + OF_WINDOWMODE_UNDEFINED = 3 }; @@ -37,22 +43,21 @@ enum ofOrientation: short{ OF_ORIENTATION_UNKNOWN = 5 }; -class ofWindowSettings{ +class ofWindowSettings { public: - ofWindowSettings() - :windowMode(OF_WINDOW) - ,width(1024) - ,height(768) - ,sizeSet(false) - ,position(0,0) - ,positionSet(false){} - + ofWindowSettings(){} virtual ~ofWindowSettings(){}; - + std::string title; - ofWindowMode windowMode; - - void setPosition(const glm::vec2 & position) { + std::string windowName { "main" }; + ofWindowMode windowMode = OF_WINDOW; + +// void setRect(const ofRectangle & rect) { +// setPosition(rect.getPosition()); +// setSize(rect.width, rect.height); +// } + + void setPosition(const glm::ivec2 & position) { this->position = position; this->positionSet = true; } @@ -75,7 +80,7 @@ class ofWindowSettings{ return height; } - const glm::vec2 & getPosition() const { + const glm::ivec2 & getPosition() const { return position; } @@ -83,60 +88,57 @@ class ofWindowSettings{ return positionSet; } -protected: - int width; - int height; - bool sizeSet; - glm::vec2 position; - bool positionSet; -}; - -class ofGLWindowSettings: public ofWindowSettings{ -public: - ofGLWindowSettings() - :glVersionMajor(2) - ,glVersionMinor(1){} - - ofGLWindowSettings(const ofWindowSettings & settings) - :ofWindowSettings(settings) - ,glVersionMajor(2) - ,glVersionMinor(1){ - const ofGLWindowSettings * glSettings = dynamic_cast(&settings); - if(glSettings){ - glVersionMajor = glSettings->glVersionMajor; - glVersionMinor = glSettings->glVersionMinor; - } - } - - virtual ~ofGLWindowSettings(){}; - - void setGLVersion(int major, int minor){ + void setGLVersion(int major, int minor) { glVersionMajor = major; glVersionMinor = minor; } - - int glVersionMajor; - int glVersionMinor; -}; - -class ofGLESWindowSettings: public ofWindowSettings{ -public: - ofGLESWindowSettings() - :glesVersion(1){} - - ofGLESWindowSettings(const ofWindowSettings & settings) - :ofWindowSettings(settings), glesVersion(1) { - const ofGLESWindowSettings * glesSettings = dynamic_cast(&settings); - if(glesSettings){ - glesVersion = glesSettings->glesVersion; - } - } - - virtual ~ofGLESWindowSettings(){}; - + void setGLESVersion(int version){ glesVersion = version; } - int glesVersion; + int glVersionMajor = 2; + int glVersionMinor = 1; + + int glesVersion = 1; + + + // GLFW specific ones +#ifdef TARGET_RASPBERRY_PI + int numSamples = 0; +#else + int numSamples = 4; +#endif + + bool doubleBuffering = true; + int redBits = 8; + int greenBits = 8; + int blueBits = 8; + int alphaBits = 8; + int depthBits = 24; + int stencilBits = 0; + bool stereo = false; + bool visible = true; + bool iconified = false; + bool decorated = true; + bool resizable = true; + bool transparent = false; + bool maximized = false; + int monitor = 0; + bool multiMonitorFullScreen = false; + std::shared_ptr shareContextWith; + std::vector fullscreenDisplays; + // FIXME: Define proper variable name + bool showOnlyInSelectedMonitor = false; + float opacity { 1.0 }; + +protected: + bool sizeSet { false }; + bool positionSet { false }; + int width { 1024 }; + int height { 768 }; + glm::ivec2 position { 0, 0 }; }; + +typedef ofWindowSettings ofGLWindowSettings; +typedef ofWindowSettings ofGLESWindowSettings; diff --git a/libs/openFrameworks/events/ofEvents.cpp b/libs/openFrameworks/events/ofEvents.cpp index 644edadfeed..1ff989e8ffc 100644 --- a/libs/openFrameworks/events/ofEvents.cpp +++ b/libs/openFrameworks/events/ofEvents.cpp @@ -7,7 +7,7 @@ static ofEventArgs voidEventArgs; //-------------------------------------- void ofSetFrameRate(int targetRate) { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { window->events().setFrameRate(targetRate); } else { @@ -17,7 +17,7 @@ void ofSetFrameRate(int targetRate) { //-------------------------------------- float ofGetFrameRate() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getFrameRate(); } else { @@ -26,7 +26,7 @@ float ofGetFrameRate() { } bool ofGetTargetFrameRateEnabled() { - if (auto window = ofGetMainLoop()->getCurrentWindow()) { + if (auto window = ofCore.getCurrentWindow()) { return window->events().getTargetFrameRateEnabled(); } return false; @@ -34,7 +34,7 @@ bool ofGetTargetFrameRateEnabled() { //-------------------------------------- float ofGetTargetFrameRate() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getTargetFrameRate(); } else { @@ -44,7 +44,7 @@ float ofGetTargetFrameRate() { //-------------------------------------- double ofGetLastFrameTime() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getLastFrameTime(); } else { @@ -54,7 +54,7 @@ double ofGetLastFrameTime() { //-------------------------------------- uint64_t ofGetFrameNum() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getFrameNum(); } else { @@ -64,7 +64,7 @@ uint64_t ofGetFrameNum() { //-------------------------------------- bool ofGetMousePressed(int button) { //by default any button - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getMousePressed(button); } else { @@ -74,17 +74,24 @@ bool ofGetMousePressed(int button) { //by default any button //-------------------------------------- bool ofGetKeyPressed(int key) { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofGetCurrentWindow() }; +// auto window = ofCore.getCurrentWindow(); + if (window) { +// std::cout << "ofGetKeyPressed in window: " << window->name << std::endl; return window->events().getKeyPressed(key); } else { + std::cout << "ofGetKeyPressed null window, ofCore name=" << ofCore.name << ", ofCore pointer=" << &ofCore << std::endl; + return false; } } //-------------------------------------- int ofGetMouseX() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofGetCurrentWindow() }; + +// auto window { ofCore.mainLoop->getCurrentWindow() }; if (window) { return window->events().getMouseX(); } else { @@ -94,7 +101,8 @@ int ofGetMouseX() { //-------------------------------------- int ofGetMouseY() { - auto window = ofGetMainLoop()->getCurrentWindow(); +// auto window { ofCore.getCurrentWindow() }; + auto window { ofGetCurrentWindow() }; if (window) { return window->events().getMouseY(); } else { @@ -104,7 +112,7 @@ int ofGetMouseY() { //-------------------------------------- int ofGetPreviousMouseX() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getPreviousMouseX(); } else { @@ -114,7 +122,7 @@ int ofGetPreviousMouseX() { //-------------------------------------- int ofGetPreviousMouseY() { - auto window = ofGetMainLoop()->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (window) { return window->events().getPreviousMouseY(); } else { @@ -235,6 +243,7 @@ bool ofCoreEvents::getTargetFrameRateEnabled() const { //-------------------------------------- float ofCoreEvents::getFrameRate() const { return fps.getFps(); +// return fps2.getFps(); } //-------------------------------------- @@ -343,6 +352,10 @@ bool ofCoreEvents::notifyKeyReleased(int key, int keycode, int scancode, uint32_ //------------------------------------------ bool ofCoreEvents::notifyKeyEvent(ofKeyEventArgs & e) { + + using std::cout; + using std::endl; + bool attended = false; modifiers = e.modifiers; switch (e.type) { @@ -371,7 +384,13 @@ bool ofCoreEvents::notifyKeyEvent(ofKeyEventArgs & e) { attended = ofNotifyEvent(keyPressed, keyEventArgs); } - pressedKeys.insert(e.key); + + // OK - FIXME: mover este e o erase pra dentro do else + else { + pressedKeys.insert(e.key); + } + + if (!attended) { return ofNotifyEvent(keyPressed, e); } else { @@ -401,14 +420,18 @@ bool ofCoreEvents::notifyKeyEvent(ofKeyEventArgs & e) { keyEventArgs.key = OF_KEY_SUPER; attended = ofNotifyEvent(keyReleased, keyEventArgs); } + else { + pressedKeys.erase(e.key); + } - pressedKeys.erase(e.key); if (!attended) { return ofNotifyEvent(keyReleased, e); } else { return attended; } } + + return false; } @@ -611,6 +634,12 @@ bool ofCoreEvents::notifyWindowResized(int width, int height) { return ofNotifyEvent(windowResized, resizeEventArgs); } +//------------------------------------------ +bool ofCoreEvents::notifyFramebufferResized(int width, int height) { + ofResizeEventArgs resizeEventArgs(width, height); + return ofNotifyEvent(framebufferResized, resizeEventArgs); +} + //------------------------------------------ bool ofCoreEvents::notifyWindowMoved(int x, int y) { ofWindowPosEventArgs windowPosEventArgs(x, y); diff --git a/libs/openFrameworks/events/ofEvents.h b/libs/openFrameworks/events/ofEvents.h index 46425b4febc..0266b1589b4 100644 --- a/libs/openFrameworks/events/ofEvents.h +++ b/libs/openFrameworks/events/ofEvents.h @@ -9,7 +9,8 @@ #define GLM_ENABLE_EXPERIMENTAL #include -#include +//#include +#include //-------------------------- mouse/key query bool ofGetMousePressed(int button = -1); //by default any button @@ -328,6 +329,7 @@ class ofCoreEvents { ofEvent exit; ofEvent windowResized; + ofEvent framebufferResized; ofEvent windowMoved; ofEvent keyPressed; @@ -401,6 +403,8 @@ class ofCoreEvents { bool notifyExit(); bool notifyWindowResized(int width, int height); + // FIXME: Todo + bool notifyFramebufferResized(int width, int height); bool notifyWindowMoved(int x, int y); bool notifyDragEvent(ofDragInfo info); @@ -415,8 +419,8 @@ class ofCoreEvents { int currentMouseX, currentMouseY; int previousMouseX, previousMouseY; bool bPreMouseNotSet; - std::set pressedMouseButtons; - std::set pressedKeys; + std::unordered_set pressedMouseButtons; + std::unordered_set pressedKeys; int modifiers = 0; enum TimeMode { diff --git a/libs/openFrameworks/gl/ofBufferObject.cpp b/libs/openFrameworks/gl/ofBufferObject.cpp index db752728744..978eed98889 100644 --- a/libs/openFrameworks/gl/ofBufferObject.cpp +++ b/libs/openFrameworks/gl/ofBufferObject.cpp @@ -81,7 +81,7 @@ void ofBufferObject::unbind(GLenum target) const{ } } -#if !defined(TARGET_OPENGLES) || defined(TARGET_EMSCRIPTEN) +//#if !defined(TARGET_OPENGLES) || defined(TARGET_EMSCRIPTEN) void ofBufferObject::bindBase(GLenum target,GLuint index) const{ if(data){ glBindBufferBase(target,index,data->id); @@ -108,7 +108,7 @@ void ofBufferObject::bindRange(GLenum target,GLuint index, GLintptr offset, GLsi void ofBufferObject::unbindRange(GLenum target,GLuint index) const{ glBindBufferBase(target,index,0); } -#endif +//#endif GLuint ofBufferObject::getId() const{ if(data) return data->id; diff --git a/libs/openFrameworks/gl/ofBufferObject.h b/libs/openFrameworks/gl/ofBufferObject.h index d7d4fe15280..8130ba762c6 100644 --- a/libs/openFrameworks/gl/ofBufferObject.h +++ b/libs/openFrameworks/gl/ofBufferObject.h @@ -40,7 +40,7 @@ class ofBufferObject { /// binds the passed target to buffer 0 void unbind(GLenum target) const; -#if !defined(TARGET_OPENGLES) || defined(TARGET_EMSCRIPTEN) +//#if !defined(TARGET_OPENGLES) || defined(TARGET_EMSCRIPTEN) /// glBindBufferBase: https://www.opengl.org/sdk/docs/man4/html/glBindBufferBase.xhtml void bindBase(GLenum target,GLuint index) const; @@ -52,7 +52,7 @@ class ofBufferObject { /// binds the given target and index to 0 void unbindRange(GLenum target,GLuint index) const; -#endif +//#endif /// returns the id of the buffer if it's allocated or 0 otherwise GLuint getId() const; diff --git a/libs/openFrameworks/gl/ofFbo.cpp b/libs/openFrameworks/gl/ofFbo.cpp index fe9db48486d..b5042587e3a 100644 --- a/libs/openFrameworks/gl/ofFbo.cpp +++ b/libs/openFrameworks/gl/ofFbo.cpp @@ -1,4 +1,5 @@ #include "ofFbo.h" + // #include "ofAppRunner.h" // #include "ofUtils.h" // #include "ofGraphics.h" @@ -23,6 +24,8 @@ using std::unordered_map; using std::vector; +ofTexture depthBufferTex; + /* See diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp index 9ee3712a725..1d40d94db33 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp @@ -946,25 +946,47 @@ glm::vec3 ofGLProgrammableRenderer::getCurrentEyePosition() const { //---------------------------------------------------------- void ofGLProgrammableRenderer::uploadCurrentMatrix() { if (!currentShader) return; + + using std::cout; + using std::endl; + // uploads the current matrix to the current shader. switch (matrixStack.getCurrentMatrixMode()) { case OF_MATRIX_MODELVIEW: - currentShader->setUniformMatrix4f(MODEL_MATRIX_UNIFORM, matrixStack.getModelMatrix()); - currentShader->setUniformMatrix4f(VIEW_MATRIX_UNIFORM, matrixStack.getViewMatrix()); - currentShader->setUniformMatrix4f(MODELVIEW_MATRIX_UNIFORM, matrixStack.getModelViewMatrix()); - currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); +// std::cout << "here " << std::endl; + + currentShader->setUniformMatrix4f(MODEL_MATRIX_UNIFORM, matrixStack.getModelMatrix()); + currentShader->setUniformMatrix4f(VIEW_MATRIX_UNIFORM, matrixStack.getViewMatrix()); + currentShader->setUniformMatrix4f(MODELVIEW_MATRIX_UNIFORM, matrixStack.getModelViewMatrix()); + currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); + + if (currentMaterial) { currentMaterial->uploadMatrices(*currentShader, *this); } break; case OF_MATRIX_PROJECTION: +// cout << "owww OF_MATRIX_PROJECTION" << endl; currentShader->setUniformMatrix4f(PROJECTION_MATRIX_UNIFORM, matrixStack.getProjectionMatrix()); currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); break; case OF_MATRIX_TEXTURE: +// cout << "owww OF_MATRIX_PROJECTION" << endl; currentShader->setUniformMatrix4f(TEXTURE_MATRIX_UNIFORM, matrixStack.getTextureMatrix()); break; } + + +// matrices = { +// matrixStack.getModelMatrix(), +// matrixStack.getViewMatrix(), +// matrixStack.getModelViewMatrix(), +// matrixStack.getModelViewProjectionMatrix(), +// matrixStack.getProjectionMatrix(), +// matrixStack.getTextureMatrix(), +// }; +// +// currentShader->setUniformBufferObject("matrices", &matrices, sizeof(matrices)); } //---------------------------------------------------------- @@ -1819,12 +1841,26 @@ void ofGLProgrammableRenderer::unbind(const ofCamera & camera) { //---------------------------------------------------------- void ofGLProgrammableRenderer::uploadMatrices() { if (!currentShader) return; + +// matrices = { +// matrixStack.getModelMatrix(), +// matrixStack.getViewMatrix(), +// matrixStack.getModelViewMatrix(), +// matrixStack.getModelViewProjectionMatrix(), +// matrixStack.getProjectionMatrix(), +// matrixStack.getTextureMatrix(), +// }; +// currentShader->setUniformBufferObject("matrices", &matrices, sizeof(matrices)); + + currentShader->setUniformMatrix4f(MODEL_MATRIX_UNIFORM, matrixStack.getModelMatrix()); currentShader->setUniformMatrix4f(VIEW_MATRIX_UNIFORM, matrixStack.getViewMatrix()); currentShader->setUniformMatrix4f(MODELVIEW_MATRIX_UNIFORM, matrixStack.getModelViewMatrix()); + currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); currentShader->setUniformMatrix4f(PROJECTION_MATRIX_UNIFORM, matrixStack.getProjectionMatrix()); currentShader->setUniformMatrix4f(TEXTURE_MATRIX_UNIFORM, matrixStack.getTextureMatrix()); - currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); + + if (currentMaterial) { currentMaterial->uploadMatrices(*currentShader, *this); } @@ -1854,6 +1890,14 @@ void ofGLProgrammableRenderer::setDefaultUniforms() { //---------------------------------------------------------- void ofGLProgrammableRenderer::beginDefaultShader() { + // piece of code to avoid begin multiple times the same shader +// std::cout << "2 " << std::endl; +// if (ofGetFrameNum() == beginDefaultShaderFrame) { +// return; +// } +// beginDefaultShaderFrame = ofGetFrameNum(); +// +// std::cout << "ofGLProgrammableRenderer::beginDefaultShader() " << ofGetFrameNum() << std::endl; if (usingCustomShader && !currentMaterial && !currentShadow) return; if (currentShadow && bCustomShadowShader) return; @@ -2293,6 +2337,18 @@ static const string defaultVertexShader = vertex_shader_header + STRINGIFY( uniform mat4 modelViewMatrix; uniform mat4 textureMatrix; uniform mat4 modelViewProjectionMatrix; + + layout(std140) uniform testeDimitrao { + mat4 testando; + }; +// layout(std140) uniform matrices { +// mat4 modelMatrix; +// mat4 viewMatrix; +// mat4 modelViewMatrix; +// mat4 modelViewProjectionMatrix; +// mat4 projectionMatrix; +// mat4 textureMatrix; +// }; IN vec4 position; IN vec2 texcoord; diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.h b/libs/openFrameworks/gl/ofGLProgrammableRenderer.h index 4adac96f4ba..60a81b94ac0 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.h +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.h @@ -403,4 +403,18 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ std::deque framebufferIdStack; ///< keeps track of currently bound framebuffers GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0 GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target + + uint64_t beginDefaultShaderFrame; + + + + struct matricesBuffer { + glm::mat4 modelMatrix; + glm::mat4 viewMatrix; + glm::mat4 modelViewMatrix; + glm::mat4 modelViewProjectionMatrix; + glm::mat4 projectionMatrix; + glm::mat4 textureMatrix; + } matrices; + ofBufferObject buffer; }; diff --git a/libs/openFrameworks/gl/ofLight.h b/libs/openFrameworks/gl/ofLight.h index cbbb5150313..958f1601a5d 100644 --- a/libs/openFrameworks/gl/ofLight.h +++ b/libs/openFrameworks/gl/ofLight.h @@ -36,7 +36,7 @@ class ofLight : public ofNode { public: ofLight(); - void setup(); + void setup(); void enable(); void disable(); bool getIsEnabled() const; @@ -47,19 +47,19 @@ class ofLight : public ofNode { void setSpotlight( float spotCutOff=45.f, float exponent=0.f ); bool getIsSpotlight() const; void setSpotlightCutOff( float spotCutOff ); - float getSpotlightCutOff() const; + float getSpotlightCutOff() const; void setSpotConcentration( float exponent ); - float getSpotConcentration() const; + float getSpotConcentration() const; void setPointLight(); bool getIsPointLight() const; void setAttenuation( float constant=1.f, float linear=0.f, float quadratic=0.f ); - float getAttenuationConstant() const; - float getAttenuationLinear() const; - float getAttenuationQuadratic() const; - - void setAreaLight(float width, float height); - bool getIsAreaLight() const; + float getAttenuationConstant() const; + float getAttenuationLinear() const; + float getAttenuationQuadratic() const; + + void setAreaLight(float width, float height); + bool getIsAreaLight() const; int getType() const; @@ -81,31 +81,31 @@ class ofLight : public ofNode { bool endShadowDepthPass( GLenum aPassIndex ); ofShadow & getShadow() { return shadow; } - + class Data{ public: Data(); ~Data(); - + ofFloatColor ambientColor; ofFloatColor diffuseColor; ofFloatColor specularColor; - - float attenuation_constant; - float attenuation_linear; - float attenuation_quadratic; - + + float attenuation_constant; + float attenuation_linear; + float attenuation_quadratic; + ofLightType lightType; - + int glIndex; int isEnabled; - float spotCutOff; - float exponent; + float spotCutOff; + float exponent; glm::vec4 position; glm::vec3 direction; - - float width; - float height; + + float width; + float height; glm::vec3 up; glm::vec3 right; /// weak link back to renderer for which this light was created/setup @@ -118,10 +118,11 @@ class ofLight : public ofNode { private: void customDraw(const ofBaseRenderer * renderer) const; std::shared_ptr data; - // update opengl light + // update opengl light // this method overrides ofNode to catch the changes and update glLightv(GL_POSITION) virtual void onPositionChanged(); virtual void onOrientationChanged(); + }; diff --git a/libs/openFrameworks/gl/ofMaterial.cpp b/libs/openFrameworks/gl/ofMaterial.cpp index 83d565808a3..61e6c7cd8a7 100644 --- a/libs/openFrameworks/gl/ofMaterial.cpp +++ b/libs/openFrameworks/gl/ofMaterial.cpp @@ -1135,6 +1135,7 @@ void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & shared_ptr light = ofLightsData()[i].lock(); if(!light || !light->isEnabled){ shader.setUniform1f("lights["+idx+"].enabled",0); +// lights[i].enabled = 0; continue; } glm::vec4 lightEyePosition = light->position; @@ -1154,20 +1155,35 @@ void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & } if( light->lightType != OF_LIGHT_POINT ) { shader.setUniform3f("lights["+idx+"].direction", light->direction ); +// lights[i].direction = light->direction; } } +// lights[i].enabled = 1; +// lights[i].type = light->lightType; +// lights[i].position = lightEyePosition; + shader.setUniform1f("lights["+idx+"].enabled",1); shader.setUniform1f("lights["+idx+"].type", light->lightType); shader.setUniform4f("lights["+idx+"].position", lightEyePosition); if( !isPBR() ) { +// lights[i].ambient = light->ambientColor; +// lights[i].specular = light->specularColor; + shader.setUniform4f("lights["+idx+"].ambient", light->ambientColor); shader.setUniform4f("lights["+idx+"].specular", light->specularColor); } +// lights[idx].diffuse = light->diffuseColor; shader.setUniform4f("lights["+idx+"].diffuse", light->diffuseColor); if(light->lightType!=OF_LIGHT_DIRECTIONAL){ // TODO: add in light radius if pbr? + +// lights[idx].radius = 0.0f; +// lights[idx].constantAttenuation = light->attenuation_constant; +// lights[idx].linearAttenuation = light->attenuation_linear; +// lights[idx].quadraticAttenuation = light->attenuation_quadratic; + shader.setUniform1f("lights["+idx+"].radius", 0.0f); shader.setUniform1f("lights["+idx+"].constantAttenuation", light->attenuation_constant); shader.setUniform1f("lights["+idx+"].linearAttenuation", light->attenuation_linear); @@ -1182,9 +1198,16 @@ void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & glm::vec4 direction4 = renderer.getCurrentViewMatrix() * glm::vec4(direction,1.0); direction = glm::vec3(direction4) / direction4.w; direction = direction - glm::vec3(lightEyePosition); + shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction)); +// lights[idx].spotDirection = glm::normalize(direction); + } //shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction)); +// lights[idx].spotExponent = light->exponent; +// lights[idx].spotCutoff = light->spotCutOff; +// lights[idx].spotCosCutoff = std::cos(glm::radians(light->spotCutOff))); + shader.setUniform1f("lights["+idx+"].spotExponent", light->exponent); shader.setUniform1f("lights["+idx+"].spotCutoff", light->spotCutOff); shader.setUniform1f("lights["+idx+"].spotCosCutoff", std::cos(glm::radians(light->spotCutOff))); @@ -1192,8 +1215,15 @@ void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & if( !isPBR() ) { glm::vec3 halfVector(glm::normalize(glm::vec4(0.f, 0.f, 1.f, 0.f) + lightEyePosition)); shader.setUniform3f("lights["+idx+"].halfVector", halfVector); + +// lights[idx].halfVector = light->halfVector; + } }else if(light->lightType==OF_LIGHT_AREA){ + +// lights[idx].width = light->width; +// lights[idx].height = light->height; + shader.setUniform1f("lights["+idx+"].width", light->width); shader.setUniform1f("lights["+idx+"].height", light->height); glm::vec3 direction = light->direction; @@ -1202,6 +1232,9 @@ void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & glm::vec4 direction4 = renderer.getCurrentViewMatrix() * glm::vec4(direction, 1.0); direction = glm::vec3(direction4) / direction4.w; direction = direction - glm::vec3(lightEyePosition); + +// lights[idx].spotDirection = glm::normalize(direction); + shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction)); } @@ -1214,6 +1247,11 @@ void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & right = right - glm::vec3(lightEyePosition); up = glm::cross(right, direction); } + + // FIXME: why toGlm in one and not in another? +// lights[idx].right = glm::normalize(toGlm(right)); +// lights[idx].up = glm::normalize(up)); + shader.setUniform3f("lights["+idx+"].right", glm::normalize(toGlm(right))); shader.setUniform3f("lights["+idx+"].up", glm::normalize(up)); } diff --git a/libs/openFrameworks/gl/ofMaterial.h b/libs/openFrameworks/gl/ofMaterial.h index 14c0de49df0..19ffc4fd8c4 100644 --- a/libs/openFrameworks/gl/ofMaterial.h +++ b/libs/openFrameworks/gl/ofMaterial.h @@ -389,6 +389,36 @@ class ofMaterial : public ofBaseMaterial { const std::string getDefinesString() const; void setCustomShader(std::shared_ptr aCustomShader); + + + struct PbrLightData { + float enabled; + // 0 = pointlight 1 = directionlight, 2 = spotlight, 3 = area light + float type; + // where are we in world space + glm::vec4 position; + glm::vec4 direction; + // light color, intensity is stored in .w + glm::vec4 diffuse; + float radius;// = 0.0; + // attenuation + float constantAttenuation; + float linearAttenuation; + float quadraticAttenuation; + // // only for spot + float spotCutoff; + float spotCosCutoff; + float spotExponent; + // // only for area + float width; + float height; + glm::vec4 right; + glm::vec4 up; + }; + + PbrLightData lights[100]; + + protected: /// \brief unbind the material, override the default so we can set current shader to nullptr @@ -474,4 +504,6 @@ class ofMaterial : public ofBaseMaterial { mutable const ofShader * currentRenderShader = nullptr; bool bPrintedPBRRenderWarning = false; bool mBHasDepthShader = false; + + }; diff --git a/libs/openFrameworks/gl/ofShader.cpp b/libs/openFrameworks/gl/ofShader.cpp index b4df3358905..d3410484a02 100644 --- a/libs/openFrameworks/gl/ofShader.cpp +++ b/libs/openFrameworks/gl/ofShader.cpp @@ -112,9 +112,9 @@ ofShader::ofShader(const ofShader & mom) , shaders(mom.shaders) , uniformsCache(mom.uniformsCache) , attributesBindingsCache(mom.attributesBindingsCache) -#ifndef TARGET_OPENGLES +//#ifndef TARGET_OPENGLES , uniformBlocksCache(mom.uniformBlocksCache) -#endif +//#endif { if (mom.bLoaded) { retainProgram(program); @@ -713,9 +713,9 @@ bool ofShader::linkProgram() { } } -#ifndef TARGET_OPENGLES +//#ifndef TARGET_OPENGLES #ifdef GLEW_ARB_uniform_buffer_object - if (GLEW_ARB_uniform_buffer_object) { +// if (GLEW_ARB_uniform_buffer_object) { // Pre-cache all active uniforms blocks GLint numUniformBlocks = 0; glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &numUniformBlocks); @@ -726,11 +726,13 @@ bool ofShader::linkProgram() { for (GLint i = 0; i < numUniformBlocks; i++) { glGetActiveUniformBlockName(program, i, uniformMaxLength, &length, uniformBlockName.data()); string name(uniformBlockName.begin(), uniformBlockName.begin() + length); +// std::cout << "WOW name " << name << std::endl; + bufferObjectsCache[name] = std::make_unique(); uniformBlocksCache[name] = glGetUniformBlockIndex(program, name.c_str()); } - } +// } #endif -#endif +//#endif #ifdef TARGET_ANDROID ofAddListener(ofxAndroidEvents().unloadGL, this, &ofShader::unloadGL); @@ -766,11 +768,11 @@ void ofShader::reloadGL() { auto bindings = attributesBindingsCache; shaders.clear(); uniformsCache.clear(); - #ifndef TARGET_OPENGLES + //#ifndef TARGET_OPENGLES #ifdef GLEW_ARB_uniform_buffer_object // Core in OpenGL 3.1 uniformBlocksCache.clear(); #endif - #endif + //#endif attributesBindingsCache.clear(); for (auto & shader : source) { auto source = shader.second.source; @@ -821,11 +823,11 @@ void ofShader::unload() { shaders.clear(); uniformsCache.clear(); -#ifndef TARGET_OPENGLES +//#ifndef TARGET_OPENGLES #ifdef GLEW_ARB_uniform_buffer_object // Core in OpenGL 3.1 uniformBlocksCache.clear(); #endif -#endif +//#endif attributesBindingsCache.clear(); #ifdef TARGET_ANDROID ofRemoveListener(ofxAndroidEvents().reloadGL, this, &ofShader::reloadGL); @@ -1018,6 +1020,23 @@ void ofShader::setUniform4i(const string & name, int v1, int v2, int v3, int v4) } } +//-------------------------------------------------------------- +void ofShader::setUniformBufferObject(const std::string & name, const void * data, GLsizeiptr dataSize) const { + if (bufferObjectsCache.find(name) != bufferObjectsCache.end()) { + if (!bufferObjectsCache.at(name)->isAllocated()) { + bufferObjectsCache.at(name)->allocate(dataSize, GL_STATIC_DRAW); + } + bufferObjectsCache.at(name)->updateData(dataSize, data); + bufferObjectsCache.at(name)->bindBase(GL_UNIFORM_BUFFER, getUniformBlockIndex(name)); + } else { +// bufferObjectsCache.at(name) = std::make_unique(); +// for (const auto & b : bufferObjectsCache) { +// std::cout << b.first << std::endl; +// } +// std::cout << "setUniformBufferObject don't exist " << name << std::endl; + } +} + //-------------------------------------------------------------- void ofShader::setUniform1f(const string & name, float v1) const { if (bLoaded) { @@ -1311,45 +1330,52 @@ GLint ofShader::getUniformLocation(const string & name) const { } } -#ifndef TARGET_OPENGLES - #ifdef GLEW_ARB_uniform_buffer_object +//#ifndef TARGET_OPENGLES +// #ifdef GLEW_ARB_uniform_buffer_object //-------------------------------------------------------------- GLint ofShader::getUniformBlockIndex(const string & name) const { if (!bLoaded) return -1; - if (GLEW_ARB_uniform_buffer_object) { +// if (GLEW_ARB_uniform_buffer_object) { +#ifdef GLEW_ARB_uniform_buffer_object auto it = uniformBlocksCache.find(name); if (it == uniformBlocksCache.end()) { return -1; } else { return it->second; } - } else { +#else + // } else { ofLogError("ofShader::getUniformBlockIndex") << "Sorry, it looks like you can't run 'ARB_uniform_buffer_object'"; return -1; - } +// } +#endif } //-------------------------------------------------------------- GLint ofShader::getUniformBlockBinding(const string & name) const { if (!bLoaded) return -1; - if (GLEW_ARB_uniform_buffer_object) { +#ifdef GLEW_ARB_uniform_buffer_object +// if (GLEW_ARB_uniform_buffer_object) { GLint index = getUniformBlockIndex(name); if (index == -1) return -1; GLint blockBinding; glGetActiveUniformBlockiv(program, index, GL_UNIFORM_BLOCK_BINDING, &blockBinding); return blockBinding; - } else { +#else +//} else { ofLogError("ofShader::getUniformBlockBinding") << "Sorry, it looks like you can't run 'ARB_uniform_buffer_object'"; return -1; - } +// } +#endif } //-------------------------------------------------------------- void ofShader::printActiveUniformBlocks() const { - if (GLEW_ARB_uniform_buffer_object) { +#ifdef GLEW_ARB_uniform_buffer_object +// if (GLEW_ARB_uniform_buffer_object) { GLint numUniformBlocks = 0; glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &numUniformBlocks); ofLogNotice("ofShader") << numUniformBlocks << " uniform blocks"; @@ -1376,25 +1402,32 @@ void ofShader::printActiveUniformBlocks() const { line.str(""); } delete[] uniformBlockName; - } else { +#else +//} else { ofLogError("ofShader::printActiveUniformBlocks") << "Sorry, it looks like you can't run 'ARB_uniform_buffer_object'"; - } +#endif +//} } void ofShader::bindUniformBlock(GLuint binding, const string & name) const { - if (bLoaded) { - if (GLEW_ARB_uniform_buffer_object) { + if (!bLoaded) return; + + +#ifdef GLEW_ARB_uniform_buffer_object +// if (GLEW_ARB_uniform_buffer_object) { GLint index = getUniformBlockIndex(name); if (index != -1) { glUniformBlockBinding(program, index, binding); } - } else { +#else +// } else { ofLogError("ofShader::bindUniformBlock") << "Sorry, it looks like you can't run 'ARB_uniform_buffer_object'"; - } - } -} - #endif +// } #endif + +} +// #endif +//#endif //-------------------------------------------------------------- void ofShader::printActiveUniforms() const { diff --git a/libs/openFrameworks/gl/ofShader.h b/libs/openFrameworks/gl/ofShader.h index e52cdc18d26..3f0bed908e4 100644 --- a/libs/openFrameworks/gl/ofShader.h +++ b/libs/openFrameworks/gl/ofShader.h @@ -166,6 +166,10 @@ class ofShader { void setUniform3i(const std::string & name, int v1, int v2, int v3) const; void setUniform4i(const std::string & name, int v1, int v2, int v3, int v4) const; + + // Dmtr testing + void setUniformBufferObject(const std::string & name, const void * data, GLsizeiptr dataSize) const; + void setUniform1f(const std::string & name, float v1) const; void setUniform2f(const std::string & name, float v1, float v2) const; void setUniform3f(const std::string & name, float v1, float v2, float v3) const; @@ -198,14 +202,14 @@ class ofShader { // set attributes that vary per vertex (look up the location before glBegin) GLint getAttributeLocation(const std::string & name) const; -#ifndef TARGET_OPENGLES -#ifdef GLEW_ARB_uniform_buffer_object +//#ifndef TARGET_OPENGLES +//#ifdef GLEW_ARB_uniform_buffer_object GLint getUniformBlockIndex(const std::string & name) const; GLint getUniformBlockBinding(const std::string & name) const; void bindUniformBlock(GLuint bindind, const std::string & name) const; void printActiveUniformBlocks() const; -#endif -#endif +//#endif +//#endif #ifndef TARGET_OPENGLES void setAttribute1s(GLint location, short v1) const; @@ -285,12 +289,19 @@ class ofShader { }; std::unordered_map shaders; + +// std::unordered_map bufferObjectsCache; +// const std::unordered_map & getBufferObjectsCache() const { +// return bufferObjectsCache; +// } + std::unordered_map> bufferObjectsCache; + std::unordered_map uniformsCache; mutable std::unordered_map attributesBindingsCache; -#ifndef TARGET_OPENGLES +//#ifndef TARGET_OPENGLES std::unordered_map uniformBlocksCache; -#endif +//#endif bool setupShaderFromSource(Source && source); ofShader::Source sourceFromFile(GLenum type, const of::filesystem::path& filename); diff --git a/libs/openFrameworks/gl/ofTexture.cpp b/libs/openFrameworks/gl/ofTexture.cpp index 0c526bb7ab3..8f99048e282 100644 --- a/libs/openFrameworks/gl/ofTexture.cpp +++ b/libs/openFrameworks/gl/ofTexture.cpp @@ -7,6 +7,8 @@ #include "ofMesh.h" #include "ofRectangle.h" #include +// FIXME: unordered_set +#include #ifdef TARGET_ANDROID #include "ofAppAndroidWindow.h" @@ -19,7 +21,7 @@ static bool bUsingArbTex = true; static bool bUsingNormalizedTexCoords = false; static bool bUseCustomMinMagFilters = false; -using std::set; +//using std::set; //--------------------------------- void ofEnableTextureEdgeHack(){ @@ -164,8 +166,8 @@ static void release(GLuint id){ } #ifdef TARGET_ANDROID -static set & allTextures(){ - static set * allTextures = new set; +static std::set & allTextures(){ + static std::set * allTextures = new std::set; return *allTextures; } @@ -1140,8 +1142,8 @@ ofMesh ofTexture::getMeshForSubsection(float x, float y, float z, float w, float // to constantly add a 2 pixel border on all uploaded images // is insane.. - GLfloat offsetw = 0.0f; - GLfloat offseth = 0.0f; + GLfloat offsetw { 0.0f }; + GLfloat offseth { 0.0f }; if (!ofGLSupportsNPOTTextures() && bTexHackEnabled) { offsetw = 1.0f / (texData.tex_w); @@ -1149,13 +1151,13 @@ ofMesh ofTexture::getMeshForSubsection(float x, float y, float z, float w, float } // ------------------------------------------------- - auto topLeft = getCoordFromPoint(sx, sy); - auto bottomRight = getCoordFromPoint(sx + sw, sy + sh); + auto topLeft { getCoordFromPoint(sx, sy) }; + auto bottomRight { getCoordFromPoint(sx + sw, sy + sh) }; - GLfloat tx0 = topLeft.x + offsetw; - GLfloat ty0 = topLeft.y + offseth; - GLfloat tx1 = bottomRight.x - offsetw; - GLfloat ty1 = bottomRight.y - offseth; + GLfloat tx0 { topLeft.x + offsetw }; + GLfloat ty0 { topLeft.y + offseth }; + GLfloat tx1 { bottomRight.x - offsetw }; + GLfloat ty1 { bottomRight.y - offseth }; quad.setMode(OF_PRIMITIVE_TRIANGLE_FAN); quad.getVertices().resize(4); diff --git a/libs/openFrameworks/gl/shaders/pbr.vert b/libs/openFrameworks/gl/shaders/pbr.vert index aa570a137d3..fc464948d0a 100644 --- a/libs/openFrameworks/gl/shaders/pbr.vert +++ b/libs/openFrameworks/gl/shaders/pbr.vert @@ -17,13 +17,23 @@ IN vec4 color; IN vec4 normal; IN vec2 texcoord; +//layout(std140) uniform matrices { +// mat4 modelMatrix; +// mat4 viewMatrix; +// mat4 modelViewMatrix; +// mat4 modelViewProjectionMatrix; +// mat4 projectionMatrix; +// mat4 textureMatrix; +//}; + + // these are passed in from OF programmable renderer uniform mat4 modelViewMatrix; uniform mat4 modelMatrix; uniform mat4 viewMatrix; +uniform mat4 modelViewProjectionMatrix; uniform mat4 projectionMatrix; uniform mat4 textureMatrix; -uniform mat4 modelViewProjectionMatrix; uniform vec2 mat_texcoord_scale; diff --git a/libs/openFrameworks/gl/shaders/phong.frag b/libs/openFrameworks/gl/shaders/phong.frag index 4850c56f2ad..6cce911798e 100644 --- a/libs/openFrameworks/gl/shaders/phong.frag +++ b/libs/openFrameworks/gl/shaders/phong.frag @@ -9,7 +9,6 @@ static const string fragmentShader = R"( #if HAS_COLOR IN vec4 v_color; #endif - uniform mat4 viewMatrix; struct lightData @@ -49,10 +48,24 @@ static const string fragmentShader = R"( uniform vec4 global_ambient; // these are passed in from OF programmable renderer - uniform mat4 modelViewMatrix; + +//layout(std140) uniform matrices { +// mat4 modelMatrix; +// mat4 viewMatrix; +// mat4 modelViewMatrix; +// mat4 modelViewProjectionMatrix; +// mat4 projectionMatrix; +// mat4 textureMatrix; +//}; + + uniform mat4 viewMatrix; + uniform mat4 modelViewMatrix; + uniform mat4 modelViewProjectionMatrix; + + uniform mat4 textureMatrix; uniform mat4 projectionMatrix; - uniform mat4 textureMatrix; - uniform mat4 modelViewProjectionMatrix; +// + #if defined(MAX_LIGHTS) && MAX_LIGHTS uniform lightData lights[MAX_LIGHTS]; diff --git a/libs/openFrameworks/gl/shaders/phong.vert b/libs/openFrameworks/gl/shaders/phong.vert index ca053f3dceb..03af6223b47 100644 --- a/libs/openFrameworks/gl/shaders/phong.vert +++ b/libs/openFrameworks/gl/shaders/phong.vert @@ -1,4 +1,5 @@ static const string vertexShader = R"( + OUT vec2 v_texcoord; // phong pass the texCoord if needed OUT vec3 v_transformedNormal; OUT vec3 v_normal; @@ -14,13 +15,25 @@ IN vec4 color; IN vec4 normal; IN vec2 texcoord; + + +//layout(std140) uniform matrices { +// mat4 modelMatrix; +// mat4 viewMatrix; +// mat4 modelViewMatrix; +// mat4 modelViewProjectionMatrix; +// mat4 projectionMatrix; +// mat4 textureMatrix; +//}; + // these are passed in from OF programmable renderer -uniform mat4 modelViewMatrix; -uniform mat4 modelMatrix; -uniform mat4 viewMatrix; -uniform mat4 projectionMatrix; -uniform mat4 textureMatrix; -uniform mat4 modelViewProjectionMatrix; +//uniform mat4 modelMatrix; +//uniform mat4 viewMatrix; +//uniform mat4 modelViewMatrix; +//uniform mat4 modelViewProjectionMatrix; +//uniform mat4 projectionMatrix; +//uniform mat4 textureMatrix; + uniform mat4 normalMatrix; uniform vec2 mat_texcoord_scale; diff --git a/libs/openFrameworks/graphics/ofGraphics.cpp b/libs/openFrameworks/graphics/ofGraphics.cpp index b7e45922cd5..f14827d406a 100644 --- a/libs/openFrameworks/graphics/ofGraphics.cpp +++ b/libs/openFrameworks/graphics/ofGraphics.cpp @@ -13,7 +13,7 @@ using std::vector; static ofVboMesh gradientMesh; -void ofSetCurrentRenderer(shared_ptr renderer, bool setDefaults) { +void ofSetCurrentRenderer(const shared_ptr & renderer, bool setDefaults) { if (setDefaults) { ofStyle style = ofGetCurrentRenderer()->getStyle(); renderer->setupGraphicDefaults(); diff --git a/libs/openFrameworks/graphics/ofGraphicsCairo.cpp b/libs/openFrameworks/graphics/ofGraphicsCairo.cpp index 87cabde8571..ddef1e2e8b3 100644 --- a/libs/openFrameworks/graphics/ofGraphicsCairo.cpp +++ b/libs/openFrameworks/graphics/ofGraphicsCairo.cpp @@ -18,7 +18,7 @@ static void ofEndSaveScreen(){ cairoScreenshot.reset(); } if( storedRenderer ){ - ofSetCurrentRenderer(storedRenderer,true); + ofSetCurrentRenderer(storedRenderer, true); storedRenderer.reset(); } diff --git a/libs/openFrameworks/graphics/ofImage.h b/libs/openFrameworks/graphics/ofImage.h index a6ac46a0870..cbdbe329b6e 100644 --- a/libs/openFrameworks/graphics/ofImage.h +++ b/libs/openFrameworks/graphics/ofImage.h @@ -646,7 +646,7 @@ class ofImage_ : public ofBaseImage_{ void resizePixels(ofPixels_ &pix, int newWidth, int newHeight); void unloadTexture(); - ofPixels_ pixels; + ofPixels_ pixels; bool bUseTexture; ofTexture tex; diff --git a/libs/openFrameworks/math/ofVec2f.h b/libs/openFrameworks/math/ofVec2f.h index 4753c3c68dc..a47bd682f5b 100644 --- a/libs/openFrameworks/math/ofVec2f.h +++ b/libs/openFrameworks/math/ofVec2f.h @@ -4,7 +4,6 @@ #define GLM_FORCE_CTOR_INIT #define GLM_ENABLE_EXPERIMENTAL - #include #include #include diff --git a/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp b/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp index 63953bc1e47..218527bc72b 100644 --- a/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp +++ b/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp @@ -10,6 +10,8 @@ #include "ofEvents.h" #include "ofUtils.h" +#include + #if defined (TARGET_OF_IOS) || defined (TARGET_OSX) #include #include diff --git a/libs/openFrameworks/sound/ofRtAudioSoundStream.cpp b/libs/openFrameworks/sound/ofRtAudioSoundStream.cpp index 284760aa40a..a9a500d8cb4 100644 --- a/libs/openFrameworks/sound/ofRtAudioSoundStream.cpp +++ b/libs/openFrameworks/sound/ofRtAudioSoundStream.cpp @@ -4,6 +4,7 @@ #include "ofAppRunner.h" #include "ofLog.h" #include +#include "ofConstants.h" using std::vector; using std::shared_ptr; diff --git a/libs/openFrameworks/sound/ofSoundBuffer.cpp b/libs/openFrameworks/sound/ofSoundBuffer.cpp index c7e5cab9aad..b836a64cc9c 100644 --- a/libs/openFrameworks/sound/ofSoundBuffer.cpp +++ b/libs/openFrameworks/sound/ofSoundBuffer.cpp @@ -9,6 +9,7 @@ #include "ofSoundUtils.h" #include "ofLog.h" #include "ofMath.h" + #define GLM_FORCE_CTOR_INIT #define GLM_ENABLE_EXPERIMENTAL #include diff --git a/libs/openFrameworks/sound/ofSoundStream.cpp b/libs/openFrameworks/sound/ofSoundStream.cpp index 5c563add7a0..4fcb68148a8 100644 --- a/libs/openFrameworks/sound/ofSoundStream.cpp +++ b/libs/openFrameworks/sound/ofSoundStream.cpp @@ -2,6 +2,10 @@ #include "ofAppRunner.h" #include "ofLog.h" +// REMOVE +//#define OF_SOUND_PLAYER_FMOD +//#include "ofConstants.h" + //------------------------------------------------ soundstream // check if any soundstream api is defined from the compiler #if !defined(OF_SOUNDSTREAM_RTAUDIO) && !defined(OF_SOUNDSTREAM_ANDROID) && !defined(OF_SOUNDSTREAM_IOS) && !defined(OF_SOUNDSTREAM_EMSCRIPTEN) diff --git a/libs/openFrameworks/types/ofRectangle.cpp b/libs/openFrameworks/types/ofRectangle.cpp index 8b142d420f9..fdd250ad39e 100644 --- a/libs/openFrameworks/types/ofRectangle.cpp +++ b/libs/openFrameworks/types/ofRectangle.cpp @@ -18,6 +18,11 @@ ofRectangle::ofRectangle(float px, float py, float w, float h) : x(position.x), set(px,py,w,h); } +// //---------------------------------------------------------- +// ofRectangle::ofRectangle(int px, int py, int w, int h) : x(position.x), y(position.y) { +// set(px,py,w,h); +// } + //---------------------------------------------------------- ofRectangle::ofRectangle(const glm::vec3& p, float w, float h) : x(position.x), y(position.y) { set(p,w,h); diff --git a/libs/openFrameworks/types/ofRectangle.h b/libs/openFrameworks/types/ofRectangle.h index a2c30f0ef43..abbc11daed1 100644 --- a/libs/openFrameworks/types/ofRectangle.h +++ b/libs/openFrameworks/types/ofRectangle.h @@ -104,6 +104,8 @@ class ofRectangle { /// \param h The height of the rectangle. ofRectangle(float px, float py, float w, float h); + // ofRectangle(int px, int py, int w, int h); + /// \brief Construct a rectangle from a point and dimensions. /// /// To produce consistent results, users are encouraged to initialize diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index 2dcbf0c5034..3716fe67502 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -99,6 +99,7 @@ enum ofTargetPlatform{ #endif #elif defined( __APPLE_CC__) #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 + #include #if (TARGET_OS_IPHONE || TARGET_OS_IOS || TARGET_OS_SIMULATOR || TARGET_IPHONE_SIMULATOR) && !TARGET_OS_TV && !TARGET_OS_WATCH && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION #define TARGET_OF_IPHONE @@ -125,6 +126,7 @@ enum ofTargetPlatform{ #define TARGET_MAC #define TARGET_OF_MAC #endif + #include #elif defined (__ANDROID__) #define TARGET_ANDROID #define TARGET_OPENGLES @@ -357,6 +359,8 @@ typedef TESSindex ofIndexType; #endif + +// Move to ofPath //------------------------------------------------ thread local storage // clang has a bug where it won't support tls on some versions even // on c++11, this is a workaround that bug diff --git a/libs/openFrameworks/utils/ofMatrixStack.cpp b/libs/openFrameworks/utils/ofMatrixStack.cpp index a4f9c0826f4..be959c40afd 100644 --- a/libs/openFrameworks/utils/ofMatrixStack.cpp +++ b/libs/openFrameworks/utils/ofMatrixStack.cpp @@ -19,6 +19,10 @@ using std::swap; using std::make_pair; using std::pair; +// TEMPORARY +using std::cout; +using std::endl; + ofMatrixStack::ofMatrixStack(const ofAppBaseWindow * window) :vFlipped(true) ,orientation(OF_ORIENTATION_DEFAULT) @@ -118,7 +122,7 @@ int ofMatrixStack::getRenderSurfaceWidth() const{ if(currentRenderSurface){ return currentRenderSurface->getWidth(); }else if(currentWindow){ - return currentWindow->getWindowSize().x; + return currentWindow->getFramebufferSize().x; }else{ return 0; } @@ -128,12 +132,25 @@ int ofMatrixStack::getRenderSurfaceHeight() const{ if(currentRenderSurface){ return currentRenderSurface->getHeight(); }else if(currentWindow){ - return currentWindow->getWindowSize().y; + return currentWindow->getFramebufferSize().y; }else{ return 0; } } +glm::ivec2 ofMatrixStack::getRenderSurfaceSize() const { + if (currentRenderSurface) { + return currentRenderSurface->getSize(); + } else if (currentWindow) { + // FIXME: FramebufferSize + // return currentWindow->getWindowSize(); + return currentWindow->getFramebufferSize(); + + } else { + return {}; + } +} + ofMatrixMode ofMatrixStack::getCurrentMatrixMode() const{ return currentMatrixMode; } @@ -153,14 +170,19 @@ void ofMatrixStack::viewport(float x, float y, float width, float height, bool v swap(x,y); } + auto xy = getRenderSurfaceSize(); + if(width < 0 || height < 0){ - width = getRenderSurfaceWidth(); - height = getRenderSurfaceHeight(); + width = xy.x; + height = xy.y; +// width = getRenderSurfaceWidth(); +// height = getRenderSurfaceHeight(); vflip = isVFlipped(); } if (vflip){ - y = getRenderSurfaceHeight() - (y + height); +// y = getRenderSurfaceHeight() - (y + height); + y = xy.y - (y + height); } currentViewport.set(x,y,width,height); @@ -183,13 +205,14 @@ ofRectangle ofMatrixStack::getNativeViewport() const{ return currentViewport; } -ofRectangle ofMatrixStack::getFullSurfaceViewport() const{ - if(currentRenderSurface){ - return ofRectangle(0,0,currentRenderSurface->getWidth(),currentRenderSurface->getHeight()); - }else if(currentWindow){ - return ofRectangle(0,0,currentWindow->getWidth(),currentWindow->getHeight()); - }else{ - return ofRectangle(); +ofRectangle ofMatrixStack::getFullSurfaceViewport() const { + if (currentRenderSurface) { + return { 0.0f, 0.0f, currentRenderSurface->getWidth(),currentRenderSurface->getHeight() }; + } else if (currentWindow) { + // FIXME: ofRectangle accepting int as parameter. + return { 0, 0, (float)currentWindow->getWidth(), (float)currentWindow->getHeight() }; + } else { + return {}; //ofRectangle(); } } diff --git a/libs/openFrameworks/utils/ofMatrixStack.h b/libs/openFrameworks/utils/ofMatrixStack.h index 57839166197..e3a9221a5de 100644 --- a/libs/openFrameworks/utils/ofMatrixStack.h +++ b/libs/openFrameworks/utils/ofMatrixStack.h @@ -10,6 +10,7 @@ // ofRectangle currentViewport only #include "ofRectangle.h" #include "ofGraphicsConstants.h" + #define GLM_FORCE_CTOR_INIT #define GLM_ENABLE_EXPERIMENTAL #include @@ -108,6 +109,7 @@ class ofMatrixStack { int getRenderSurfaceWidth() const; int getRenderSurfaceHeight() const; + glm::ivec2 getRenderSurfaceSize() const; bool doesHWOrientation() const; inline void updatedRelatedMatrices(); diff --git a/libs/openFrameworks/utils/ofURLFileLoader.cpp b/libs/openFrameworks/utils/ofURLFileLoader.cpp index 32f9b62daba..f18decd007a 100644 --- a/libs/openFrameworks/utils/ofURLFileLoader.cpp +++ b/libs/openFrameworks/utils/ofURLFileLoader.cpp @@ -3,6 +3,8 @@ #include "ofUtils.h" #include "ofFileUtils.h" #include "ofLog.h" +// FIXME: unordered_set +#include using std::map; using std::set; @@ -64,6 +66,7 @@ class ofURLFileLoaderImpl : public ofThread, public ofBaseURLFileLoader { ofThreadChannel requests; ofThreadChannel responses; ofThreadChannel cancelRequestQueue; + // FIXME: unordered_set set cancelledRequests; }; diff --git a/libs/openFrameworks/utils/ofUtils.cpp b/libs/openFrameworks/utils/ofUtils.cpp index c362239b6c3..d763735e576 100644 --- a/libs/openFrameworks/utils/ofUtils.cpp +++ b/libs/openFrameworks/utils/ofUtils.cpp @@ -247,8 +247,8 @@ uint64_t ofGetFixedStepForFps(double fps) { } ofTimeMode ofGetTimeMode() { - if (auto mainLoop = ofGetMainLoop()) { - if (auto window = mainLoop->getCurrentWindow()) { + if (ofCore.mainLoop) { + if (auto window { ofCore.getCurrentWindow() }) { return window->events().getTimeMode(); } } @@ -257,12 +257,11 @@ ofTimeMode ofGetTimeMode() { //-------------------------------------- void ofSetTimeModeSystem() { - auto mainLoop = ofGetMainLoop(); - if (!mainLoop) { + if (!ofCore.mainLoop) { ofLogError("ofSetSystemTimeMode") << "ofMainLoop is not initialized yet, can't set time mode"; return; } - auto window = mainLoop->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (!window) { ofLogError("ofSetSystemTimeMode") << "No window setup yet can't set time mode"; return; @@ -273,28 +272,26 @@ void ofSetTimeModeSystem() { //-------------------------------------- void ofSetTimeModeFixedRate(uint64_t stepNanos) { - auto mainLoop = ofGetMainLoop(); - if (!mainLoop) { + if (!ofCore.mainLoop) { ofLogError("ofSetSystemTimeMode") << "ofMainLoop is not initialized yet, can't set time mode"; return; } - auto window = mainLoop->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (!window) { ofLogError("ofSetSystemTimeMode") << "No window setup yet can't set time mode"; return; } window->events().setTimeModeFixedRate(stepNanos); - of::priv::getClock().setTimeModeFixedRate(stepNanos, *mainLoop); + of::priv::getClock().setTimeModeFixedRate(stepNanos, *ofCore.mainLoop); } //-------------------------------------- void ofSetTimeModeFiltered(float alpha) { - auto mainLoop = ofGetMainLoop(); - if (!mainLoop) { + if (!ofCore.mainLoop) { ofLogError("ofSetSystemTimeMode") << "ofMainLoop is not initialized yet, can't set time mode"; return; } - auto window = mainLoop->getCurrentWindow(); + auto window { ofCore.getCurrentWindow() }; if (!window) { ofLogError("ofSetSystemTimeMode") << "No window setup yet can't set time mode"; return; diff --git a/libs/openFrameworks/video/ofVideoPlayer.cpp b/libs/openFrameworks/video/ofVideoPlayer.cpp index bc84360afe6..1f01fca6a21 100644 --- a/libs/openFrameworks/video/ofVideoPlayer.cpp +++ b/libs/openFrameworks/video/ofVideoPlayer.cpp @@ -36,6 +36,38 @@ #endif +//------------------------------------------------ video player +// check if any video player system is already defined from the compiler +#if !defined(OF_VIDEO_PLAYER_GSTREAMER) && !defined(OF_VIDEO_PLAYER_IOS) && !defined(OF_VIDEO_PLAYER_DIRECTSHOW) && !defined(OF_VIDEO_PLAYER_MEDIA_FOUNDATION) && !defined(OF_VIDEO_PLAYER_QUICKTIME) && !defined(OF_VIDEO_PLAYER_AVFOUNDATION) && !defined(OF_VIDEO_PLAYER_EMSCRIPTEN) + #ifdef TARGET_LINUX + #define OF_VIDEO_PLAYER_GSTREAMER + #elif defined(TARGET_ANDROID) + #define OF_VIDEO_PLAYER_ANDROID + #elif defined(TARGET_OF_IOS) + #define OF_VIDEO_PLAYER_IOS + #elif defined(TARGET_WIN32) + #ifdef _MSC_VER //use MF Foundation player for VS as mingw doesn't have needed symbols + #define OF_VIDEO_PLAYER_MEDIA_FOUNDATION + #else + #define OF_VIDEO_PLAYER_DIRECTSHOW + #endif + #elif defined(TARGET_OSX) + //for 10.8 and 10.9 users we use AVFoundation, for 10.7 we use QTKit, for 10.6 users we use QuickTime + #ifndef MAC_OS_X_VERSION_10_7 + #define OF_VIDEO_PLAYER_QUICKTIME + #elif !defined(MAC_OS_X_VERSION_10_8) + #define OF_VIDEO_PLAYER_QTKIT + #else + #define OF_VIDEO_PLAYER_AVFOUNDATION + #endif + #elif defined(TARGET_EMSCRIPTEN) + #define OF_VIDEO_PLAYER_EMSCRIPTEN + #else + #define OF_VIDEO_PLAYER_QUICKTIME + #endif +#endif + + #ifdef OF_VIDEO_PLAYER_GSTREAMER #include "ofGstVideoPlayer.h" #define OF_VID_PLAYER_TYPE ofGstVideoPlayer diff --git a/libs/openFrameworksCompiled/project/macos/openFrameworksLib.xcodeproj/project.pbxproj b/libs/openFrameworksCompiled/project/macos/openFrameworksLib.xcodeproj/project.pbxproj index 1f5553bdc44..69a7ef9a2a9 100644 --- a/libs/openFrameworksCompiled/project/macos/openFrameworksLib.xcodeproj/project.pbxproj +++ b/libs/openFrameworksCompiled/project/macos/openFrameworksLib.xcodeproj/project.pbxproj @@ -2189,6 +2189,7 @@ E4B27C1610CBEB8E00536013 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS)"; CONFIGURATION_BUILD_DIR = "$(SRCROOT)/../../lib/macos/"; EXECUTABLE_PREFIX = ""; INSTALL_PATH = /usr/local/lib; @@ -2213,6 +2214,7 @@ E4B27C1710CBEB8E00536013 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS)"; CONFIGURATION_BUILD_DIR = "$(SRCROOT)/../../lib/macos/"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; EXECUTABLE_PREFIX = ""; @@ -2266,7 +2268,7 @@ MERGEABLE_LIBRARY = YES; MERGED_BINARY_TYPE = automatic; OBJROOT = "$(SRCROOT)/../../lib/macos/build/release"; - ONLY_ACTIVE_ARCH = NO; + ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; }; diff --git a/scripts/templates/macos/emptyExample.xcodeproj/project.pbxproj b/scripts/templates/macos/emptyExample.xcodeproj/project.pbxproj index e966b681bdb..810d5b26ba0 100644 --- a/scripts/templates/macos/emptyExample.xcodeproj/project.pbxproj +++ b/scripts/templates/macos/emptyExample.xcodeproj/project.pbxproj @@ -828,6 +828,7 @@ BF6278052BADE871008864C1 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ONLY_ACTIVE_ARCH = YES; ALWAYS_SEARCH_USER_PATHS = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;