diff --git a/CMakeLists.txt b/CMakeLists.txt index 472596f6..0b23e987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,14 @@ endmacro() # determine whether to create a debug or release build sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)") +# Suppress Cygwin legacy warning +set(CMAKE_LEGACY_CYGWIN_WIN32 0) + +# Suppress Mac OS X RPATH warnings and adopt new related behaviors +if(NOT CMAKE_VERSION VERSION_LESS 3.0) + cmake_policy(SET CMP0042 NEW) +endif() + # set Android specific options # define the minimum API level to be used @@ -31,6 +39,8 @@ if(NOT ANDROID_ABI) set(ANDROID_ABI armeabi-v7a) endif() +#end of Android specific options + # project name project(SFML) @@ -39,7 +49,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake) # setup version numbers set(VERSION_MAJOR 2) -set(VERSION_MINOR 3) +set(VERSION_MINOR 4) set(VERSION_PATCH 2) # add the SFML header path @@ -63,11 +73,21 @@ else() set(SFML_BUILD_EXAMPLES FALSE) endif() +# add options to select which modules to build +sfml_set_option(SFML_BUILD_WINDOW TRUE BOOL "TRUE to build SFML's Window module. This setting is ignored, if the graphics module is built.") +sfml_set_option(SFML_BUILD_GRAPHICS TRUE BOOL "TRUE to build SFML's Graphics module.") +if(NOT SFML_OS_IOS) + sfml_set_option(SFML_BUILD_AUDIO TRUE BOOL "TRUE to build SFML's Audio module.") +endif() +sfml_set_option(SFML_BUILD_NETWORK TRUE BOOL "TRUE to build SFML's Network module.") + # add an option for building the API documentation sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it") # add an option for choosing the OpenGL implementation -sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation") +if(SFML_BUILD_WINDOW) + sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation") +endif() # Mac OS X specific options if(SFML_OS_MACOSX) @@ -125,6 +145,45 @@ if(NOT BUILD_SHARED_LIBS) add_definitions(-DSFML_STATIC) endif() +# force building sfml-window, if sfml-graphics module is built +if(SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW) + message(WARNING "You're trying to build SFML's Graphics module without the Window module. Forcing building of the Window module as a dependency.") + set(SFML_BUILD_WINDOW TRUE) +endif() + +# allow not using bundled dependencies with a switch +# (except for stb_image) +# yes this is horrible, but GLOB_RECURSE sucks +sfml_set_option(SFML_USE_SYSTEM_DEPS FALSE BOOL "TRUE to use system dependencies, FALSE to use the bundled ones.") +if(SFML_USE_SYSTEM_DEPS) + if(SFML_INSTALL_XCODE_TEMPLATES) + message(FATAL_ERROR "XCode templates installation cannot be used with the SFML_USE_SYSTEM_DEPS option (the bundled frameworks are required.)") + endif() + + file(GLOB_RECURSE DEP_LIBS "${CMAKE_SOURCE_DIR}/extlibs/libs*/*") + file(GLOB_RECURSE DEP_BINS "${CMAKE_SOURCE_DIR}/extlibs/bin*/*") + file(GLOB_RECURSE DEP_HEADERS "${CMAKE_SOURCE_DIR}/extlibs/headers/*") + + foreach(DEP_FILE ${DEP_LIBS} ${DEP_BINS} ${DEP_HEADERS}) + get_filename_component(DEP_DIR ${DEP_FILE} PATH) + + if(NOT DEP_DIR MATCHES "/stb_image(/|$)") + set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH} ${DEP_DIR}) + endif() + + get_filename_component(DEP_PARENT_DIR ${DEP_DIR} PATH) + while(NOT DEP_PARENT_DIR STREQUAL "${CMAKE_SOURCE_DIR}/extlibs") + if(NOT DEP_DIR MATCHES "/stb_image(/|$)") + set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH} ${DEP_PARENT_DIR}) + endif() + + get_filename_component(DEP_PARENT_DIR ${DEP_PARENT_DIR} PATH) + endwhile() + endforeach() + + list(REMOVE_DUPLICATES CMAKE_IGNORE_PATH) +endif() + # Visual C++: remove warnings regarding SL security and algorithms on pointers if(SFML_COMPILER_MSVC) # add an option to choose whether PDB debug symbols should be generated (defaults to true when possible) @@ -200,11 +259,11 @@ if(SFML_OS_MACOSX) endif() # only the default architecture (i.e. 64-bit) is supported - if(CMAKE_OSX_ARCHITECTURES AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64") + if(CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") message(FATAL_ERROR "Only 64-bit architecture is supported") return() endif() - + # configure Xcode templates set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)") endif() @@ -246,6 +305,19 @@ if(SFML_BUILD_DOC) add_subdirectory(doc) endif() +sfml_set_option(SFML_INSTALL_PKGCONFIG_FILES FALSE BOOL "TRUE to automatically install pkg-config files so other projects can find SFML") + +if(SFML_OS_SUPPORTS_PKGCONFIG OR SFML_INSTALL_PKGCONFIG_FILES) + foreach(sfml_module IN ITEMS all system window graphics audio network) + CONFIGURE_FILE( + "tools/pkg-config/sfml-${sfml_module}.pc.in" + "tools/pkg-config/sfml-${sfml_module}.pc" + @ONLY) + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc" + DESTINATION "${CMAKE_INSTALL_PREFIX}/${SFML_OS_PKGCONFIG_DIR}") + endforeach() +endif() + # setup the install rules if(NOT SFML_BUILD_FRAMEWORKS) install(DIRECTORY include @@ -286,10 +358,46 @@ else() MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} PUBLIC_HEADER "${SFML_HEADERS}") - # add the remaining headers - add_custom_command(TARGET SFML - POST_BUILD - COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* $/Headers) + # add the non-optional SFML headers + add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r + ${PROJECT_SOURCE_DIR}/include/SFML/Config.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/OpenGL.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/System.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/Main.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/System + $/Headers) + + # add window module headers if enabled + if(SFML_BUILD_WINDOW) + add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r + ${PROJECT_SOURCE_DIR}/include/SFML/Window.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/Window + $/Headers) + endif() + + # add network module headers if enabled + if(SFML_BUILD_GRAPHICS) + add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r + ${PROJECT_SOURCE_DIR}/include/SFML/Network.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/Network + $/Headers) + endif() + + # add graphics module headers if enabled + if(SFML_BUILD_GRAPHICS) + add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r + ${PROJECT_SOURCE_DIR}/include/SFML/Graphics.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/Graphics + $/Headers) + endif() + + # add audio module headers if enabled + if(SFML_BUILD_AUDIO) + add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r + ${PROJECT_SOURCE_DIR}/include/SFML/Audio.hpp + ${PROJECT_SOURCE_DIR}/include/SFML/Audio + $/Headers) + endif() # adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle # NOTE: it's not required to link against SFML.framework @@ -303,8 +411,8 @@ else() COMPONENT devel) endif() -install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR}) -install(FILES readme.txt DESTINATION ${INSTALL_MISC_DIR}) +install(FILES license.md DESTINATION ${INSTALL_MISC_DIR}) +install(FILES readme.md DESTINATION ${INSTALL_MISC_DIR}) if(NOT SFML_OS_ANDROID) install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules) endif() @@ -336,32 +444,36 @@ if(SFML_OS_WINDOWS) elseif(SFML_OS_MACOSX) # install extlibs dependencies only when used - if("${FLAC_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework") - install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + if(SFML_BUILD_GRAPHICS) + if(FREETYPE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework") + install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() endif() - if("${FREETYPE_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework") - install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + if(SFML_BUILD_AUDIO) + if(FLAC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework") + install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() - if("${OGG_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework") - install(DIRECTORY extlibs/libs-osx/Frameworks/ogg.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + if(OGG_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework") + install(DIRECTORY extlibs/libs-osx/Frameworks/ogg.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() - if("${VORBIS_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework") - install(DIRECTORY extlibs/libs-osx/Frameworks/vorbis.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + if(VORBIS_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework") + install(DIRECTORY extlibs/libs-osx/Frameworks/vorbis.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() - if("${VORBISENC_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework") - install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + if(VORBISENC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework") + install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() - if("${VORBISFILE_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework") - install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + if(VORBISFILE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework") + install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() - if("${OPENAL_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework") - install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + if(OPENAL_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework") + install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() endif() # install the Xcode templates if requested @@ -388,7 +500,9 @@ elseif(SFML_OS_IOS) # since the iOS libraries are built as static, we must install the SFML dependencies # too so that the end user can easily link them to its final application - install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib) + if(SFML_BUILD_GRAPHICS) + install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib) + endif() elseif(SFML_OS_ANDROID) diff --git a/CONTRIBUTING b/CONTRIBUTING deleted file mode 100644 index fae5de03..00000000 --- a/CONTRIBUTING +++ /dev/null @@ -1,16 +0,0 @@ -Contribution Guidelines -======================= - -You would like to see a feature implemented or a bug fixed in SFML? Great! -Contributions to SFML are highly appreciated, be it in the form of general -ideas, concrete suggestions or code patches. - -A few guiding rules have been set up on the SFML website that you should be -aware of before opening an Issue or Pull Request. They will help you focus -on the important stuff and prevent you from losing (y)our time with requests -that are out of SFML's scope, known issues, and so on. - - http://www.sfml-dev.org/contribute.php - -Those rules cover the general scope defined for this project, a coding -style, and a precise procedure to report bugs or suggest new features. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..6f71bbb4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +# Contribution Guidelines + +You would like to see a feature implemented or a bug fixed in SFML? Great! Contributions to SFML are highly appreciated, be it in the form of general ideas, concrete suggestions or code patches. + +[A few guiding rules have been set up on the SFML website](http://www.sfml-dev.org/contribute.php) that you should be aware of before opening an Issue or Pull Request. They will help you focus on the important stuff and prevent you from losing (y)our time with requests that are out of SFML's scope, known issues, and so on. + +Those rules cover the general scope defined for this project, a coding style, and a precise procedure to report bugs or suggest new features. diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..d8103292 --- /dev/null +++ b/changelog.md @@ -0,0 +1,536 @@ +# Changelog + +## SFML 2.4.2 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.4.2 + +### System + +**Bugfixes** + + * [Windows] Removed thread affinity changes in sf::Clock (#1107) + +### Window + +**Bugfixes** + + * Fixed bug where TransientContextLock would hang (#1165, #1172) + * [Linux] Fixed GLX extensions being loaded too late (#1183) + * [Linux] Fix wrong types passed to XChangeProperty (#1168 #1171) + * [Windows] Make context disabling via wglMakeCurrent more tolerant of broken drivers (#1186) + +### Graphics + +**Bugfixes** + + * Optimized sf::Image::create and made it more exception safe (#1166) + +## SFML 2.4.1 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.4.1 + +### General + + * [kFreeBSD] Define SFML_OS_FREEBSD when compiling for kFreeBSD (#1129) + * [Windows] Added some simple messaging when trying to build under Cygwin (#1153) + +### Window + +**Bugfixes** + + * Fixed stack overflow on GlContext creation with multiple threads (#989, #1002) + * Adjusted mouse cursor grab documentation (#1133) + * [iOS] Fixed orientation change not rescaling window size properly (#1049, #1050) + * [Linux] Fixed fullscreen issue (#921, #1138) + * [Linux] Switched from XCB back to Xlib for windowing (#1138) + * [Linux] Fixed window icon not showing up on some distros (#1087, #1088) + * [Linux] Fixed an issue where GNOME flags window unresponsive (#1089, #1138) + * [Linux] Fixed leak of XVisualInfo objects during GlxContext creation (#1135) + * [Linux] Fixed possible hang when setting visibility if external window sources (#1136) + * [OS X] Fixed inconsistency between doc and impl on OS X for the grab feature (#1133, #1148, #1150) + * [Windows] Fixed context memory leaks (#1143, #1002) + +### Graphics + +**Bugfixes** + + * Adjusted uniform error message (#1131) + * Clarify documentation on Rect::contains function bounds (#1151) + +### Network + +**Bugfixes** + + * Fixed a typo in comment for void unbind() (#1121) + +## SFML 2.4.0 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.4.0 + +### General + + * Added deprecation macro (#969) + * Fixed issues reported by Coverity Scan static analysis (#1064) + * Fixed some initialization issues reported by Cppcheck (#1008) + * Changed comment chars in FindSFML.cmake to # (#1090) + * Fixed some typos (#1098, #993, #1099, #956, #963, #979) + * Updated/fixed string comparisons in Config.cmake (#1102) + * Added the missing -s postfix for the RelWithDebInfo config (#1014) + * [Android] Fixed current Android compilation issues (#1116, #1111, #1079) + * [OS X] Update Xcode template material (#976, #968) + * [Windows] Added support for VS 2015 (#972) + * [Windows] Create and install PDB debug symbols alongside binaries (#1037) + +### Deprecated API + + * sf::RenderWindow::capture(): Use a sf::Texture and its sf::Texture::update(const Window&) function and copy its contents into an sf::Image instead. + * sf::Shader::setParameter(): Use setUniform() instead. + * sf::Text::getColor(): There is now fill and outline colors instead of a single global color. Use getFillColor() or getOutlineColor() instead. + * sf::Text::setColor(): There is now fill and outline colors instead of a single global color. Use setFillColor() or setOutlineColor() instead. + * sf::LinesStrip: Use LineStrip instead. + * sf::TrianglesFan: Use TriangleFan instead. + * sf::TrianglesStrip: Use TriangleStrip instead. + +### System + +**Features** + + * [Android] Added sf::getNativeActivity() (#1005, #680) + +**Bugfixes** + + * Added missing include in String.hpp (#1069, #1068) + * Fixed encoding of UTF-16 (#997) + * [Android] Fixed crash when trying to load a non-existing font file (#1058) + +### Window + +**Features** + + * Added ability to grab cursor (#614, #394, #1107) + * Added Multi-GPU preference (#869, #867) + * Added support for sRGB capable framebuffers (#981, #175) + * [Linux, Windows] Improved OpenGL context creation (#884) + * [Linux, Windows] Added support for pbuffers on Windows and Unix (#885, #434) + +**Bugfixes** + + * Updated platform-specific handle documentation (#961) + * [Android] Accept touch events from "multiple" devices (#954, #953) + * [Android] Copy the selected EGL context's settings to SFML (#1039) + * [Linux] Fixed modifiers causing sf::Keyboard::Unknown being returned (#1022, #1012) + * [OS X] Improved memory management on OS X (#962, #790) + * [OS X] Fixed crash when resizing a window to a zero-height/width size (#986, #984) + * [OS X] Use the mouse button constant instead of 0 to avoid a compiler error on OSX (#1035) + * [OS X] OS X improvement: warnings + bugfix + refactoring, the lot! (#1042) + +### Graphics + +**Features** + + * Added support for outlined text (#840) + * Add support for geometry shaders (#886, #428) + * Feature/blend mode reverse subtract (#945, #944) + * Implemented support for mipmap generation (#973, #498, #123) + * Added new API to set shader uniforms (#983, #538) + * Rewrite RenderWindow::capture (#1001) + +**Bugfixes** + + * Exporting some Glsl utility functions due to linking issues (#1044, #1046) + * Fixed missing initialisation of Font::m_stroker (#1059) + * Changed primitive types to be grammatically correct (#1095, #939) + +### Audio + +**Features** + + * Implemented stereo audio recording (#1010) + +**Bugfixes** + + * Added an assignment operator to SoundSource (#864) + * [OS X] Updates OpenAL-soft for OS X to version 1.17.2 (#1057, #900, #1000) + * Fixed a bug where vorbis can't handle large buffers (#1067) + * Added support for 24-bit .wav files (#958, #955) + * Fixed threading issue in sf::SoundRecorder (#1011) + * Made WAV file reader no longer assume that data chunk goes till end of file to prevent reading trailing metadata as samples (#1018) + * Fixed seeking in multi channel FLAC files (#1041, #1040) + +### Network + +**Features** + + * Added optional argument on which address to bind (socket). (#850, #678) + +**Bugfixes** + + * Fixed FTP directory listing blocking forever (#1086, #1025) + +## SFML 2.3.2 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.3.2 + +### General + + * Fixed an issue where FindSFML.cmake couldn't find older versions of SFML (#903) + * Robust alCheck and glCheck macros (#917) + * Fixed FindSFML.cmake to use the uppercase FLAC name (#923) + * Added a CONTRIBUTING file so GitHub shows a message when creating a new issue (#932) + +### Window + +**Bugfixes** + + * [Linux] Fixed an issue where the keypad's key weren't being detected (#910) + * [Linux] Revert to Xlib event handling (#934) + * [Linux] Fixed `XK_*` inconsistency in InpuImpl.cpp (#947) + * [Linux] Fix `_NET_WM_PING` messages not being replied to properly (#947) + +### Graphics + +**Bugfixes** + + * Fixed clear bug on RenderTextures (#915) + * Fixed image file extension detection (#929, #930, #931) + * Secure function against random data return (#935, #942) + +## SFML 2.3.1 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.3.1 + +### Window + +**Bugfixes** + + * [Android] Make sure a window still exists before trying to access its dimensions (#854) + * [Android] Added Android API level checks (#856) + * [Android] Updated the JNI/event handling code (#906) + * [Linux] Resized events are only spawned when the window size actually changes (#878, #893) + * [Linux] Whitelisted X SHAPE events (#879, #883) + * [Linux] Remap Unix keyboard when user changes layout (#895, #897) + * [Linux] Fix undefined behavior in ewmhSupported() (#892, #901) + +### Graphics + +**Bugfixes** + + * Added support for GL_EXT_texture_edge_clamp for systems that don't expose GL_SGIS_texture_edge_clamp (#880, #882) + +### Audio + +**Bugfixes** + + * [Android] Fixed audio files not loading (and possibly crashing) (#855, #887) + +## SFML 2.3 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.3 + +### General + + * Examples only link against sfml-main in release mode (#610, #766) + * Replaced unsigned int with std::size_t for array indices and sizes (#739) + * Fixed some issues with the Doxygen documentation (#750) + * Added support for EditorConfig (#751) + * Hide success message for CMake in quiet mode (#753) + * Improved documentation for statuses with sf::Ftp (#763) + * Moved stb_image into the extlibs directory (#795) + * Changed the SOVERSION to major.minor (#812) + * Fixed warnings about switch-statements (#863) + * Added missing includes in the general headers (#851) + * [Android] Updated toolchain file and dependencies (#791) + * [Linux] Fixed missing pthread dependency (#794) + * [OS X] Relaxed CMake installation rules regarding framework dependencies (#767) + +### Deprecated API + + * sf::Event::MouseWheelEvent: This event is deprecated and potentially inaccurate. Use MouseWheelScrollEvent instead. + +### Window + +**Features** + + * Added new events for handling high-precision scrolling (#95, #810, #837) + * Switched from Xlib to XCB (#200, #319, #694, #780, #813, #825) + * Added support for OpenGL 3 core context creation (#654, #779) + +**Bugfixes** + + * Fixed glXSwapIntervalSGI being broken for some driver implementations (#727, #779) + * Fixed simultaneous context operations causing crashes on some AMD hardware (#778, #779) + * Fixed joystick identification (#809, #811) + * [iOS] Fixed various issues including stencil bits, device orientation and retina support (#748) + * [iOS] Fixed inconsistency between sf::Touch::getPosition and touch events (#875) + * [Linux] Fixed Alt+F4 not getting triggered in window mode (#274) + * [Linux] Fixed Unix joystick stuff (#838) + * [OS X] Fixed typo in JoystickImpl.cpp to prevent a crash (#762, #765) + * [OS X] Fixed an issue in InputImpl::getSFOpenGLViewFromSFMLWindow (#782, #792) + +### Graphics + +**Features** + + * Replaced GLEW with loader generated by glLoadGen (#779) + * Added a new constructor to sf::Color that takes an sf::Uint32 (#722) + * Updated stb_image to v2.02 (#777) + * Updated FreeType to v2.5.5 (#799, #804) + * Added checks for software OpenGL (#870) + +**Bugfixes** + + * Fixed GL_ARB_compatibility not being detected (#859) + * Fixed pixel format selection (#862) + * Bumped back the OpenGL version requirement to 1.1 (#858) + +### Audio + +**Features** + + * Dropped libsndfile and started using Vorbis, FLAC and OGG directly (#604, #757) + * Added a FLAC file to the sound example (#815) + +**Bugfixes** + + * Fixed access violation error in the destructor of sf::AudioDevice (#30, #602) + * [OS X] Fixed threading issue with sf::SoundStream and OpenAL (#541, #831) + +### Network + +**Bugfixes** + + * Fixed sf::TcpSocket not handling partial sends properly (#749, #796) + +## SFML 2.2 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.2 + +### General + + * Support for iOS and Android platform (#410, #440) + * Various documentation corrections (#438, #496, #497, #714) + * Fixed support for compilers on Debian FreeBSD (#380, #578) + * Added support for Visual Studio 2013 and proper support for the TDM builds (#482) + * Fixed CMake problems related to FindSFML and cached variables (#637, #684) + * Switched and enforced LF line endings (#708, #712) + * Updated OpenAL to version 1.15.1 (d077210) + * Made compiler and OS variable names much clearer in CMake files (9b0ed30) + * Re-enabled RPATH feature (e157e7a) + * Slight adjustments to the examples (#737) + * [FreeBSD] Various configuration fixes (#577, #578) + * [Linux] Updated FindSFML.cmake to add UDev to SFML's dependencies (#728, #729, #734, #736) + * [OS X] Fixed incorrect symlink in freetype.framework (#519) + * [OS X] CMake module for correct dependencies (#548) + * [OS X] Fixed SFML target for Xcode (#595, #596) + * [OS X] Updated implementation, mainly reverting to non-ARC (#601) + * [OS X] Fixed memory leaks and dead store (#615) + * [OS X] Improved event handling and performance (#617) + * [OS X] Reduced memory usage (#672, #698) + * [OS X] OS X 10.10 support (#691, #699) + * [OS X] Improve flexibility of dependencies' locations (#713) + * [Windows] Removed the hack that copied external libraries into SFML static libraries (dbf01a7) + +### System + +**Features** + + * Added substring and replace functions to sf::String (#21, #355) + * Added toUtfX to sf::String (#501) + * Added fromUtfX functions to set the internal data to a string by converting from another string in a fixed encoding (#196) + * Added modulo operator for sf::Time (#429, #430) + * Added division operator for sf::Time (#453) + +**Bugfixes** + + * Ensured a high resolution for sf::sleep (#439, #475) + * [Windows] Fixed stack unalignment by two internal functions (#412) + +### Window + +**Features** + + * Added window methods to request and to check focus (#518, #525, #613, #723, #735) + * Provide name, manufacturer ID and product ID via sf::Joystick (#152, #528) + * [FreeBSD] Joystick support (#477) + * [OS X] Improved integration with menus and dock actions (#11) + * [OS X] Support for OpenGL 3.2 (#84) + * [OS X] Improved fullscreen support (#343) + * [OS X] Added support for retina displays (#353, #388) + * [Windows] Removed support for Windows 9x (#469) + * [Windows] Fixed typo in Windows keyboard implementation (#516) + +**Bugfixes** + + * sf::Window::create() now also resets framerate limit (#371) + * Fixed OpenGL context leak (#635, #705) + * Fixed various joystick problems (memory leak, accelerometer detected, code refactoring) (#660, #686, #742, #743) + * Optimized sf::Window::waitEvent a bit, no sleep if events are available at first try (ff555d6) + * [Linux] Output error message when XOpenDisplay() fails (#508, #616) + * [Linux] Resize window with setSize when sf::Style::Resize is set (#466) + * [Linux] Fixed broken key repeat on window recreation (#564, #567) + * [OS X] Fixed KeyReleased not being fired in fullscreen mode (#465) + * [OS X] Fixed an issue where disconnecting the keyboard would cause a crash (#467) + * [OS X] Fixed unexpected resizing behavior (#468) + * [OS X] Improved resizing windows (#474) + * [OS X] Fixed memory leak with sf::Window::create() (#484) + * [OS X] Fixed menu shortcuts in fullscreen on OS X (#527) + * [OS X] Improved cursor hiding (#703) + * [OS X] Fixed right click not detected with trackpads (#716, #730) + * [Windows] Fixed joystick POV values (ef1d29b) + * [Windows] Fixed Unicode inconsistency (#635) + * [Windows] Fixed Alt+F4 and mouse clicks issues (#437, #457) + * [Windows] Send MouseButtonReleased event when the mouse is outside of the window (#455, #457) + * [Windows] Fixed sf::Joystick wrong registry usage (#701, #702, #706) + +### Graphics + +**Features** + + * Provide more information about the loaded font in sf::Font (#164) + * Implemented a more flexible blending system (#298) + * Added strikethrough text style (#243, #362, #682) + * Slight optimization for sf::Text::setString (#413) + * Added subtraction operator for sf::Color (#114, #145) + * Optimized sf::Image::flipVertically/flipHorizontally (#555) + * Changed sf::Font measurements from int to float to allow better underline drawing (#693) + +**Bugfixes** + + * Improved text quality for small and pixelated fonts (#228) + * Yet another fix for Intel GPUs with sf::RenderTexture (#418) + * Removed VTab since it causes issues and doesn't have a use nowadays (#442, #445, #460, #588) + * Fixed broken BDF and PCF font formats (#448) + * Fixed compilation issue with newer versions of GCC for sf::Rect (#458) + * Fixed resetGLStates() not explicitly setting the default polygon mode (#480) + * Fixed division-by-zero in sf::RectangleShape (#499) + * Fixed potential memory leak in sf::Font (#509) + * Updated glext and removed glxext (#511, #583) + * Make sure texture unit 0 is active when resetting sf::RenderTarget states (#523, #591) + * Fixed texture rect computation in fonts (#669) + * Improved rendering of underlined text (#593) + * Avoided repeated output of error messages (#566) + * Fixed text rendered with vertical offset on ascent and font size mismatch (#576) + * Fixed rounding problem for viewports (#598) + * Fixed sf::Shader::isAvailable() possibly breaking context management (#211, #603, #608, #603) + * Fixed sf::Texture::getMaximumSize() possibly breaking context management (#666) + * Fixed various sf::Text rendering issues (#692, #699) + * The texture matrix is now reset in sf::Texture::bind(NULL) (7c4b058) + * [Windows] Fixed DPI scaling causing strange window behavior (#679, #681, #688) + +### Audio + +**Features** + + * Added support for selecting the audio capture device (#220, #470) + * Make sf::SoundRecorder processing frequency configurable (#333) + * Added up vector to sf::Listener (#545) + +**Bugfixes** + + * Prevented sf::SoundStream::setPlayingOffset() from restarting playing even when paused (#203, #592) + * Fixed sf::SoundBuffer contents not being able to be updated when still attached to sounds (#354, 367, #390, #589) + * Catch audio format error and prevent division by zero (#529) + * Fixed sf::SoundBuffer returning wrong duration for sounds containing more than ~4.3 million samples (2ff58ed) + * Optimized sf::Listener with a cache (d97e524) + +### Network + +**Features** + + * Added support for PUT and DELETE in sf::Http (#257, #312, #607) + * Added support for chunked HTTP transfers (#296, #337) + * Added support for 64-bit integers in sf::Packet (#710) + * Made sf::Ftp::sendCommand() public (2c5cab5) + +**Bugfixes** + + * Checked socket descriptor limit (#153, #628, #683) + * Fixed sf::TcpSocket::connect()'s switching from blocking to non-blocking mode on immediate connection success (#221) + * Fixed FTP download and upload file sizes being limited by available RAM (#565, #590) + * Fixed C++11 compiler warnings for sf::Uint8 (#731, #732) + +## SFML 2.1 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.1 + +### General + + * Updated the Window and OpenGL examples (got rid of GLU and immediate mode) + +### Window + +**Features** + + * Now using inotify on Linux to avoid constantly polling joystick connections (#96) + * Add keypad return, equal and period keys support for OS X + * Improved mouse events on OS X regarding fullscreen mode + * Improved mouse events on OS X (#213, #277) + * Improved reactivity of setMousePosition on OS X (#290) + * Added support for right control key on OS X + * Improved TextEntered for OS X (#377) + * Improved the performances of Window::getSize() (the size is now cached) + * Added the WM_CLASS property to SFML windows on Linux + * Fake resize events are no longer sent when the window is moved, on Linux + * Pressing ALT or F10 on Windows no longer steals the focus + +**Bugfixes** + + * Fixed MouseMove event sometimes not generated when holding left button on Windows (#225) + * Fixed ContextSettings ignored when creating a 3.x/4.x OpenGL context on Linux (#258) + * Fixed ContextSettings ignored on Linux when creating a window (#35) + * Fixed windows bigger than the desktop not appearing on Windows (#215) + * Fixed KeyRelease events sometimes not reported on Linux (#404) + * Fixed mouse moved event on OS X when dragging the cursor (#277) + * Fixed KeyRelease event with CMD key pressed (#381) + * Fixed taskbar bugs on Windows (#328, #69) + * Fixed Window::getPosition() on Linux (#346) + * Unicode characters outside the BMP (> 0xFFFF) are now correctly handled on Windows (#366) + +### Graphics + +**Features** + + * Checking errors in RenderTarget::pushGLStates() to avoid generating false error messages when user leaves unchecked OpenGL errors (#340) + * Optimized Shader::setParameter functions, by using a cache internally (#316, #358) + +**Bugfixes** + + * Fixed bounding rect of sf::Text ignoring whitespaces (#216) + * Solved graphics resources not updated or corrupted when loaded in a thread (#411) + * Fixed white pixel showing on first character of sf::Text (#414) + * sf::Rect::contains and sf::Rect::intersects now handle rectangles with negative dimensions correctly (#219) + * Fixed Shape::setTextureRect not working when called before setTexture + +### Audio + +**Features** + + * loadFromStream functions now explicitly reset the stream (seek(0)) before starting to read (#349) + +**Bugfixes** + + * Added a workaround for a bug in the OS X implementation of OpenAL (unsupported channel count no properly detected) (#201) + * Fixed SoundBuffer::loadFromStream reading past the end of the stream (#214) + +### Network + +**Features** + + * Replaced the deprecated gethostbyname with getaddrinfo (#47) + * Minor improvements to sf::Packet operators (now using strlen and wcslen instead of explicit loops) (#118) + +**Bugfixes** + + * Fixed non-blocking connection with a sf::TcpSocket on Windows + * Fixed TCP packet data corruption in non-blocking mode (#402, #119) + * On Unix systems, a socket disconnection no longer stops the program with signal SIGPIPE (#72) + +## SFML 2.0 + +Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.0 + +No changelog available. *Everything changed.* + +## Older Releases + +See the website for changelogs of older releases: http://www.sfml-dev.org/changelog.php diff --git a/changelog.txt b/changelog.txt deleted file mode 100644 index 80ded9cd..00000000 --- a/changelog.txt +++ /dev/null @@ -1,411 +0,0 @@ -SFML 2.3.2 -========== - -Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.3.2 - -General -======= - -* Fixed an issue where FindSFML.cmake couldn't find older versions of SFML (#903) -* Robust alCheck and glCheck macros (#917) -* Fixed FindSFML.cmake to use the uppercase FLAC name (#923) -* Added a CONTRIBUTING file so GitHub shows a message when creating a new issue (#932) - - -Window -====== - -Bugfixes --------- -* [Linux] Fixed an issue where the keypad's key weren't being detected (#910) -* [Linux] Revert to Xlib event handling (#934) -* [Linux] Fixed XK_* inconsistency in InpuImpl.cpp (#947) -* [Linux] Fix _NET_WM_PING messages not being replied to properly (#947) - - -Graphics -======== - -Bugfixes --------- -* Fixed clear bug on RenderTextures (#915) -* Fixed image file extension detection (#929, #930, #931) -* Secure function against random data return (#935, #942) - - -SFML 2.3.1 -========== - -Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.3.1 - -Window -====== - -Bugfixes --------- -* [Android] Make sure a window still exists before trying to access its dimensions (#854) -* [Android] Added Android API level checks (#856) -* [Android] Updated the JNI/event handling code (#906) -* [Linux] Resized events are only spawned when the window size actually changes (#878, #893) -* [Linux] Whitelisted X SHAPE events (#879, #883) -* [Linux] Remap Unix keyboard when user changes layout (#895, #897) -* [Linux] Fix undefined behavior in ewmhSupported() (#892, #901) - - -Graphics -======== - -Bugfixes --------- -* Added support for GL_EXT_texture_edge_clamp for systems that don't expose GL_SGIS_texture_edge_clamp (#880, #882) - - -Audio -===== - -Bugfixes --------- -* [Android] Fixed audio files not loading (and possibly crashing) (#855, #887) - - - -SFML 2.3 -======== - -Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.3 - -General -======= - -* Examples only link against sfml-main in release mode (#610, #766) -* Replaced unsigned int with std::size_t for array indices and sizes (#739) -* Fixed some issues with the Doxygen documentation (#750) -* Added support for EditorConfig (#751) -* Hide success message for CMake in quiet mode (#753) -* Improved documentation for statuses with sf::Ftp (#763) -* Moved stb_image into the extlibs directory (#795) -* Changed the SOVERSION to major.minor (#812) -* Fixed warnings about switch-statements (#863) -* Added missing includes in the general headers (#851) -* [Android] Updated toolchain file and dependencies (#791) -* [Linux] Fixed missing pthread dependency (#794) -* [OS X] Relaxed CMake installation rules regarding framework dependencies (#767) - -Window -====== - -Features --------- -* Added new events for handling high-precision scrolling (#95, #810, #837) -* Switched from Xlib to XCB (#200, #319, #694, #780, #813, #825) -* Added support for OpenGL 3 core context creation (#654, #779) - -Bugfixes --------- -* Fixed glXSwapIntervalSGI being broken for some driver implementations (#727, #779) -* Fixed simultaneous context operations causing crashes on some AMD hardware (#778, #779) -* Fixed joystick identification (#809, #811) -* [iOS] Fixed various issues including stencil bits, device orientation and retina support (#748) -* [iOS] Fixed inconsistency between sf::Touch::getPosition and touch events (#875) -* [Linux] Fixed Alt+F4 not getting triggered in window mode (#274) -* [Linux] Fixed Unix joystick stuff (#838) -* [OS X] Fixed typo in JoystickImpl.cpp to prevent a crash (#762, #765) -* [OS X] Fixed an issue in InputImpl::getSFOpenGLViewFromSFMLWindow (#782, #792) - -Graphics -======== - -Features --------- -* Replaced GLEW with loader generated by glLoadGen (#779) -* Added a new constructor to sf::Color that takes an sf::Uint32 (#722) -* Updated stb_image to v2.02 (#777) -* Updated FreeType to v2.5.5 (#799, #804) -* Added checks for software OpenGL (#870) - -Bugfixes --------- -* Fixed GL_ARB_compatibility not being detected (#859) -* Fixed pixel format selection (#862) -* Bumped back the OpenGL version requirement to 1.1 (#858) - -Audio -===== - -Features --------- -* Dropped libsndfile and started using Vorbis, FLAC and OGG directly (#604, #757) -* Added a FLAC file to the sound example (#815) - -Bugfixes --------- -* Fixed access violation error in the destructor of sf::AudioDevice (#30, #602) -* [OS X] Fixed threading issue with sf::SoundStream and OpenAL (#541, #831) - -Network -======= - -Bugfixes --------- -* Fixed sf::TcpSocket not handling partial sends properly (#749, #796) - - - -SFML 2.2 -======== - -Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.2 - -General -======= - -* Support for iOS and Android platform (#410, #440) -* Various documentation corrections (#438, #496, #497, #714) -* Fixed support for compilers on Debian FreeBSD (#380, #578) -* Added support for Visual Studio 2013 and proper support for the TDM builds (#482) -* Fixed CMake problems related to FindSFML and cached variables (#637, #684) -* Switched and enforced LF line endings (#708, #712) -* Updated OpenAL to version 1.15.1 (d077210) -* Made compiler and OS variable names much clearer in CMake files (9b0ed30) -* Re-enabled RPATH feature (e157e7a) -* Slight adjustments to the examples (#737) -* [FreeBSD] Various configuration fixes (#577, #578) -* [Linux] Updated FindSFML.cmake to add UDev to SFML's dependencies (#728, #729, #734, #736) -* [OS X] Fixed incorrect symlink in freetype.framework (#519) -* [OS X] CMake module for correct dependencies (#548) -* [OS X] Fixed SFML target for Xcode (#595, #596) -* [OS X] Updated implementation, mainly reverting to non-ARC (#601) -* [OS X] Fixed memory leaks and dead store (#615) -* [OS X] Improved event handling and performance (#617) -* [OS X] Reduced memory usage (#672, #698) -* [OS X] OS X 10.10 support (#691, #699) -* [OS X] Improve flexibility of dependencies' locations (#713) -* [Windows] Removed the hack that copied external libraries into SFML static libraries (dbf01a7) - - -System -====== - -Features --------- -* Added substring and replace functions to sf::String (#21, #355) -* Added toUtfX to sf::String (#501) -* Added fromUtfX functions to set the internal data to a string by converting from another string in a fixed encoding (#196) -* Added modulo operator for sf::Time (#429, #430) -* Added division operator for sf::Time (#453) - -Bugfixes --------- -* Ensured a high resolution for sf::sleep (#439, #475) -* [Windows] Fixed stack unalignment by two internal functions (#412) - - -Window -====== - -Features --------- -* Added window methods to request and to check focus (#518, #525, #613, #723, #735) -* Provide name, manufacturer ID and product ID via sf::Joystick (#152, #528) -* [FreeBSD] Joystick support (#477) -* [OS X] Improved integration with menus and dock actions (#11) -* [OS X] Support for OpenGL 3.2 (#84) -* [OS X] Improved fullscreen support (#343) -* [OS X] Added support for retina displays (#353, #388) -* [Windows] Removed support for Windows 9x (#469) -* [Windows] Fixed typo in Windows keyboard implementation (#516) - -Bugfixes --------- -* sf::Window::create() now also resets framerate limit (#371) -* Fixed OpenGL context leak (#635, #705) -* Fixed various joystick problems (memory leak, accelerometer detected, code refactoring) (#660, #686, #742, #743) -* Optimized sf::Window::waitEvent a bit, no sleep if events are available at first try (ff555d6) -* [Linux] Output error message when XOpenDisplay() fails (#508, #616) -* [Linux] Resize window with setSize when sf::Style::Resize is set (#466) -* [Linux] Fixed broken key repeat on window recreation (#564, #567) -* [OS X] Fixed KeyReleased not being fired in fullscreen mode (#465) -* [OS X] Fixed an issue where disconnecting the keyboard would cause a crash (#467) -* [OS X] Fixed unexpected resizing behavior (#468) -* [OS X] Improved resizing windows (#474) -* [OS X] Fixed memory leak with sf::Window::create() (#484) -* [OS X] Fixed menu shortcuts in fullscreen on OS X (#527) -* [OS X] Improved cursor hiding (#703) -* [OS X] Fixed right click not detected with trackpads (#716, #730) -* [Windows] Fixed joystick POV values (ef1d29b) -* [Windows] Fixed Unicode inconsistency (#635) -* [Windows] Fixed Alt+F4 and mouse clicks issues (#437, #457) -* [Windows] Send MouseButtonReleased event when the mouse is outside of the window (#455, #457) -* [Windows] Fixed sf::Joystick wrong registry usage (#701, #702, #706) - - -Graphics -======== - -Features --------- -* Provide more information about the loaded font in sf::Font (#164) -* Implemented a more flexible blending system (#298) -* Added strikethrough text style (#243, #362, #682) -* Slight optimization for sf::Text::setString (#413) -* Added subtraction operator for sf::Color (#114, #145) -* Optimized sf::Image::flipVertically/flipHorizontally (#555) -* Changed sf::Font measurements from int to float to allow better underline drawing (#693) - -Bugfixes --------- -* Improved text quality for small and pixelated fonts (#228) -* Yet another fix for Intel GPUs with sf::RenderTexture (#418) -* Removed VTab since it causes issues and doesn't have a use nowadays (#442, #445, #460, #588) -* Fixed broken BDF and PCF font formats (#448) -* Fixed compilation issue with newer versions of GCC for sf::Rect (#458) -* Fixed resetGLStates() not explicitly setting the default polygon mode (#480) -* Fixed division-by-zero in sf::RectangleShape (#499) -* Fixed potential memory leak in sf::Font (#509) -* Updated glext and removed glxext (#511, #583) -* Make sure texture unit 0 is active when resetting sf::RenderTarget states (#523, #591) -* Fixed texture rect computation in fonts (#669) -* Improved rendering of underlined text (#593) -* Avoided repeated output of error messages (#566) -* Fixed text rendered with vertical offset on ascent and font size mismatch (#576) -* Fixed rounding problem for viewports (#598) -* Fixed sf::Shader::isAvailable() possibly breaking context management (#211, #603, #608, #603) -* Fixed sf::Texture::getMaximumSize() possibly breaking context management (#666) -* Fixed various sf::Text rendering issues (#692, #699) -* The texture matrix is now reset in sf::Texture::bind(NULL) (7c4b058) -* [Windows] Fixed DPI scaling causing strange window behavior (#679, #681, #688) - - -Audio -===== - -Features --------- -* Added support for selecting the audio capture device (#220, #470) -* Make sf::SoundRecorder processing frequency configurable (#333) -* Added up vector to sf::Listener (#545) - -Bugfixes --------- -* Prevented sf::SoundStream::setPlayingOffset() from restarting playing even when paused (#203, #592) -* Fixed sf::SoundBuffer contents not being able to be updated when still attached to sounds (#354, 367, #390, #589) -* Catch audio format error and prevent division by zero (#529) -* Fixed sf::SoundBuffer returning wrong duration for sounds containing more than ~4.3 million samples (2ff58ed) -* Optimized sf::Listener with a cache (d97e524) - -Network -======= - -Features --------- -* Added support for PUT and DELETE in sf::Http (#257, #312, #607) -* Added support for chunked HTTP transfers (#296, #337) -* Added support for 64-bit integers in sf::Packet (#710) -* Made sf::Ftp::sendCommand() public (2c5cab5) - -Bugfixes --------- -* Checked socket descriptor limit (#153, #628, #683) -* Fixed sf::TcpSocket::connect()'s switching from blocking to non-blocking mode on immediate connection success (#221) -* Fixed FTP download and upload file sizes being limited by available RAM (#565, #590) -* Fixed C++11 compiler warnings for sf::Uint8 (#731, #732) - - - -SFML 2.1 -======== - -Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.1 - -General -======= - -* Updated the Window and OpenGL examples (got rid of GLU and immediate mode) - -Window -====== - -Features --------- -* Now using inotify on Linux to avoid constantly polling joystick connections (#96) -* Add keypad return, equal and period keys support for OS X -* Improved mouse events on OS X regarding fullscreen mode -* Improved mouse events on OS X (#213, #277) -* Improved reactivity of setMousePosition on OS X (#290) -* Added support for right control key on OS X -* Improved TextEntered for OS X (#377) -* Improved the performances of Window::getSize() (the size is now cached) -* Added the WM_CLASS property to SFML windows on Linux -* Fake resize events are no longer sent when the window is moved, on Linux -* Pressing ALT or F10 on Windows no longer steals the focus - -Bugfixes --------- -* Fixed MouseMove event sometimes not generated when holding left button on Windows (#225) -* Fixed ContextSettings ignored when creating a 3.x/4.x OpenGL context on Linux (#258) -* Fixed ContextSettings ignored on Linux when creating a window (#35) -* Fixed windows bigger than the desktop not appearing on Windows (#215) -* Fixed KeyRelease events sometimes not reported on Linux (#404) -* Fixed mouse moved event on OS X when dragging the cursor (#277) -* Fixed KeyRelease event with CMD key pressed (#381) -* Fixed taskbar bugs on Windows (#328, #69) -* Fixed Window::getPosition() on Linux (#346) -* Unicode characters outside the BMP (> 0xFFFF) are now correctly handled on Windows (#366) - -Graphics -======== - -Features --------- -* Checking errors in RenderTarget::pushGLStates() to avoid generating false error messages when user leaves unchecked OpenGL errors (#340) -* Optimized Shader::setParameter functions, by using a cache internally (#316, #358) - -Bugfixes --------- -* Fixed bounding rect of sf::Text ignoring whitespaces (#216) -* Solved graphics resources not updated or corrupted when loaded in a thread (#411) -* Fixed white pixel showing on first character of sf::Text (#414) -* sf::Rect::contains and sf::Rect::intersects now handle rectangles with negative dimensions correctly (#219) -* Fixed Shape::setTextureRect not working when called before setTexture - -Audio -===== - -Features --------- -* loadFromStream functions now explicitly reset the stream (seek(0)) before starting to read (#349) - -Bugfixes --------- -* Added a workaround for a bug in the OS X implementation of OpenAL (unsupported channel count no properly detected) (#201) -* Fixed SoundBuffer::loadFromStream reading past the end of the stream (#214) - -Network -======= - -Features --------- -* Replaced the deprecated gethostbyname with getaddrinfo (#47) -* Minor improvements to sf::Packet operators (now using strlen and wcslen instead of explicit loops) (#118) - -Bugfixes --------- -* Fixed non-blocking connection with a sf::TcpSocket on Windows -* Fixed TCP packet data corruption in non-blocking mode (#402, #119) -* On Unix systems, a socket disconnection no longer stops the program with signal SIGPIPE (#72) - - - -SFML 2.0 -======== - -Also available on the website: http://www.sfml-dev.org/changelog.php#sfml-2.0 - -No changelog available. Everything changed. - - - -Older Releases -============== - -See the website for changelogs of older releases: http://www.sfml-dev.org/changelog.php diff --git a/cmake/Config.cmake b/cmake/Config.cmake index 85fb8fea..c447113a 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -1,5 +1,5 @@ # detect the OS -if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") set(SFML_OS_WINDOWS 1) # don't use the OpenGL ES implementation on Windows @@ -8,15 +8,15 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") # detect the architecture (note: this test won't work for cross-compilation) include(CheckTypeSize) check_type_size(void* SIZEOF_VOID_PTR) - if("${SIZEOF_VOID_PTR}" STREQUAL "4") + if(${SIZEOF_VOID_PTR} STREQUAL "4") set(ARCH_32BITS 1) - elseif("${SIZEOF_VOID_PTR}" STREQUAL "8") + elseif(${SIZEOF_VOID_PTR} STREQUAL "8") set(ARCH_64BITS 1) else() message(FATAL_ERROR "Unsupported architecture") return() endif() -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(SFML_OS_UNIX 1) if(ANDROID) set(SFML_OS_ANDROID 1) @@ -27,11 +27,11 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") # don't use the OpenGL ES implementation on Linux set(OPENGL_ES 0) endif() -elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") +elseif(CMAKE_SYSTEM_NAME MATCHES "^k?FreeBSD$") set(SFML_OS_FREEBSD 1) # don't use the OpenGL ES implementation on FreeBSD set(OPENGL_ES 0) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") if(IOS) set(SFML_OS_IOS 1) @@ -59,16 +59,33 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") return() endif() endif() -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android") set(SFML_OS_ANDROID 1) # use the OpenGL ES implementation on Android set(OPENGL_ES 1) +# comparing CMAKE_SYSTEM_NAME with "CYGWIN" generates a false warning depending on the CMake version +# let's avoid it so the actual error is more visible +elseif(${CYGWIN}) + message(FATAL_ERROR "Unfortunately SFML doesn't support Cygwin's 'hybrid' status between both Windows and Linux derivatives.\nIf you insist on using the GCC, please use a standalone build of MinGW without the Cygwin environment instead.") else() - message(FATAL_ERROR "Unsupported operating system") + message(FATAL_ERROR "Unsupported operating system or environment") return() endif() +# check if OS or package system supports pkg-config +# this could be e.g. macports on mac or msys2 on windows etc. +find_package(PkgConfig QUIET) +if(PKG_CONFIG_EXECUTABLE) + if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig") + set(SFML_OS_SUPPORTS_PKGCONFIG ON) + set(SFML_OS_PKGCONFIG_DIR "/lib${LIB_SUFFIX}/pkgconfig") + elseif(EXISTS "${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig") + set(SFML_OS_SUPPORTS_PKGCONFIG ON) + set(SFML_OS_PKGCONFIG_DIR "/libdata/pkgconfig") + endif() +endif() + # detect the compiler and its version # Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true # even when CLANG is used, therefore the Clang test is done first @@ -86,7 +103,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}") execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE) string(STRIP "${GCC_MACHINE}" GCC_MACHINE) - if(${GCC_MACHINE} MATCHES ".*w64.*") + if(GCC_MACHINE MATCHES ".*w64.*") set(SFML_COMPILER_GCC_W64 1) endif() elseif(MSVC) diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index cd2ca8fc..0f316034 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -105,9 +105,17 @@ macro(sfml_add_library target) endif() # adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle - set_target_properties(${target} PROPERTIES - BUILD_WITH_INSTALL_RPATH 1 - INSTALL_NAME_DIR "@rpath") + # but only if cmake rpath options aren't set + if(NOT CMAKE_SKIP_RPATH AND NOT CMAKE_SKIP_INSTALL_RPATH AND NOT CMAKE_INSTALL_RPATH AND NOT CMAKE_INSTALL_RPATH_USE_LINK_PATH AND NOT CMAKE_INSTALL_NAME_DIR) + if(CMAKE_SKIP_BUILD_RPATH) + set_target_properties(${target} PROPERTIES + INSTALL_NAME_DIR "@rpath") + else() + set_target_properties(${target} PROPERTIES + BUILD_WITH_INSTALL_RPATH 1 + INSTALL_NAME_DIR "@rpath") + endif() + endif() endif() # enable automatic reference counting on iOS diff --git a/cmake/Modules/FindSFML.cmake b/cmake/Modules/FindSFML.cmake index 871f8662..fe84c961 100644 --- a/cmake/Modules/FindSFML.cmake +++ b/cmake/Modules/FindSFML.cmake @@ -7,14 +7,14 @@ # When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main). # If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing. # example: -# find_package(SFML COMPONENTS graphics window system) // find the graphics, window and system modules +# find_package(SFML COMPONENTS graphics window system) # find the graphics, window and system modules # # You can enforce a specific version, either MAJOR.MINOR or only MAJOR. # If nothing is specified, the version won't be checked (i.e. any version will be accepted). # example: -# find_package(SFML COMPONENTS ...) // no specific version required -# find_package(SFML 2 COMPONENTS ...) // any 2.x version -# find_package(SFML 2.4 COMPONENTS ...) // version 2.4 or greater +# find_package(SFML COMPONENTS ...) # no specific version required +# find_package(SFML 2 COMPONENTS ...) # any 2.x version +# find_package(SFML 2.4 COMPONENTS ...) # version 2.4 or greater # # By default, the dynamic libraries of SFML will be found. To find the static ones instead, # you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...). @@ -285,10 +285,7 @@ if(SFML_STATIC_LIBRARIES) # find libraries if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD) find_sfml_dependency(X11_LIBRARY "X11" X11) - find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb) - find_sfml_dependency(X11_XCB_LIBRARY "X11-xcb" X11-xcb libX11-xcb) - find_sfml_dependency(XCB_RANDR_LIBRARY "xcb-randr" xcb-randr libxcb-randr) - find_sfml_dependency(XCB_IMAGE_LIBRARY "xcb-image" xcb-image libxcb-image) + find_sfml_dependency(XRANDR_LIBRARY "Xrandr" Xrandr) endif() if(FIND_SFML_OS_LINUX) @@ -299,9 +296,9 @@ if(SFML_STATIC_LIBRARIES) if(FIND_SFML_OS_WINDOWS) set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32") elseif(FIND_SFML_OS_LINUX) - set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} ${UDEV_LIBRARIES}) + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY} ${UDEV_LIBRARIES}) elseif(FIND_SFML_OS_FREEBSD) - set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} "usbhid") + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY} "usbhid") elseif(FIND_SFML_OS_MACOSX) set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon") endif() diff --git a/cmake/Modules/FindXCB.cmake b/cmake/Modules/FindXCB.cmake deleted file mode 100644 index d6914610..00000000 --- a/cmake/Modules/FindXCB.cmake +++ /dev/null @@ -1,97 +0,0 @@ -# Try to find libxcb -# -# -# Once done this will define: -# LIBXCB_FOUND - True if xcb was found -# LIBXCB_INCLUDE_DIRS - Directories containing the headers -# LIBXCB_LIBRARIES - List of libraries to link to -# -# Also for each requested component: -# LIBXCB_${UPPER_COMPONENT_NAME}_FOUND -# LIBXCB_${UPPER_COMPONENT_NAME}_INCLUDE_DIRS -# LIBXCB_${UPPER_COMPONENT_NAME}_LIBRARIES - -include(FindPackageHandleStandardArgs) - -IF(NOT WIN32) - IF(LIBXCB_LIBRARIES AND LIBXCB_INCLUDE_DIR) - set(XCB_FIND_QUIETLY TRUE) - ENDIF() - - # Find xcb - FIND_PATH(LIBXCB_INCLUDE_DIR xcb/xcb.h) - FIND_LIBRARY(LIBXCB_LIBRARY NAMES xcb libxcb) - - # Add xcb info to LIBXCB_LIBRARIES and LIBXCB_INCLUDE_DIRS - SET(LIBXCB_LIBRARIES ${LIBXCB_LIBRARY}) - SET(LIBXCB_INCLUDE_DIRS ${LIBXCB_INCLUDE_DIR}) - - find_package_handle_standard_args(LIBXCB DEFAULT_MSG - LIBXCB_LIBRARY LIBXCB_INCLUDE_DIR) - - mark_as_advanced(LIBXCB_LIBRARY LIBXCB_INCLUDE_DIR) - - # Check whether we should search for XLIB_XCB - set(FIND_XLIB_XCB FALSE) - FOREACH(XCB_COMPONENT ${XCB_FIND_COMPONENTS}) - # Generate upper string of the component name - string(TOUPPER ${XCB_COMPONENT} XCB_COMPONENT_UPPER) - - IF(${XCB_COMPONENT_UPPER} MATCHES "XLIB_XCB") - set(FIND_XLIB_XCB TRUE) - ELSE() - # XCB_COMPONENTS is generated to be a copy of XCB_FIND_COMPONENTS - # without XLIB_XCB (for later component search) - set(XCB_COMPONENTS ${XCB_COMPONENTS} ${XCB_COMPONENT}) - ENDIF() - ENDFOREACH() - - # Find XLIB_XCB if requested - IF(FIND_XLIB_XCB) - FIND_PATH(XLIB_XCB_INCLUDE_DIR X11/Xlib-xcb.h) - FIND_LIBRARY(XLIB_XCB_LIBRARY NAMES X11-xcb libX11-xcb) - - SET(XLIB_XCB_LIBRARIES ${XLIB_XCB_LIBRARY}) - SET(XLIB_XCB_INCLUDE_DIRS ${XLIB_XCB_INCLUDE_DIR}) - - find_package_handle_standard_args(XLIB_XCB DEFAULT_MSG - XLIB_XCB_LIBRARY LIBXCB_INCLUDE_DIR) - - mark_as_advanced(XLIB_XCB_LIBRARY XLIB_XCB_INCLUDE_DIR) - - # Add xlib_xcb info to LIBXCB_LIBRARIES and LIBXCB_INCLUDE_DIRS - set(LIBXCB_LIBRARIES ${LIBXCB_LIBRARIES} ${XLIB_XCB_LIBRARIES}) - set(LIBXCB_INCLUDE_DIRS ${LIBXCB_INCLUDE_DIRS} ${XLIB_XCB_INCLUDE_DIR}) - - if(NOT XLIB_XCB_FOUND) - message(FATAL_ERROR "XlibXcb library not found") - endif() - ELSE() - # Add component name to the component list - set(${XCB_COMPONENTS} ${XCB_FIND_COMPONENTS}) - ENDIF() - - # Loop through requested xcb components (does not contain xlib_xcb) - FOREACH(XCB_COMPONENT ${XCB_COMPONENTS}) - # Generate lower and upper string of the component name - string(TOLOWER ${XCB_COMPONENT} XCB_COMPONENT_LOWER) - string(TOUPPER ${XCB_COMPONENT} XCB_COMPONENT_UPPER) - - # Find the specific component - FIND_LIBRARY(LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY - NAMES libxcb-${XCB_COMPONENT_LOWER} xcb-${XCB_COMPONENT_LOWER}) - - find_package_handle_standard_args(LIBXCB_${XCB_COMPONENT_UPPER} DEFAULT_MSG - LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY LIBXCB_INCLUDE_DIR) - - mark_as_advanced(LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY) - - # Append the component's library path to LIBXCB_LIBRARIES - set(LIBXCB_LIBRARIES ${LIBXCB_LIBRARIES} ${LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY}) - - if(NOT LIBXCB_${XCB_COMPONENT_UPPER}_FOUND) - message(FATAL_ERROR "xcb-${XCB_COMPONENT_LOWER} not found") - endif() - ENDFOREACH() - -endif() diff --git a/cmake/toolchains/android.toolchain.cmake b/cmake/toolchains/android.toolchain.cmake index 1eeebe57..d0fdf005 100644 --- a/cmake/toolchains/android.toolchain.cmake +++ b/cmake/toolchains/android.toolchain.cmake @@ -600,7 +600,7 @@ if( BUILD_WITH_ANDROID_NDK ) endif() if( NOT __availableToolchains ) file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" ) - if( __availableToolchains ) + if( __availableToolchainsLst ) list(SORT __availableToolchainsLst) # we need clang to go after gcc endif() __LIST_FILTER( __availableToolchainsLst "^[.]" ) @@ -847,8 +847,8 @@ The possible values are: stlport_shared -> Use the STLport runtime as a shared library. gnustl_static -> (default) Use the GNU STL as a static library. gnustl_shared -> Use the GNU STL as a shared library. - c++_static -> Use libc++ as a static library. - c++_shared -> Use libc++ as a shared library. + c++_static -> Use libc++ as a static library. + c++_shared -> Use libc++ as a shared library. " ) endif() elseif( BUILD_WITH_STANDALONE_TOOLCHAIN ) @@ -973,6 +973,7 @@ if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFF set( _clang_name "clang" ) endif() + # setup paths and STL for NDK if( BUILD_WITH_ANDROID_NDK ) set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) @@ -990,7 +991,7 @@ if( BUILD_WITH_ANDROID_NDK ) set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) elseif( ANDROID_STL MATCHES "gabi" ) if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - message( FATAL_ERROR "gabi++ is not awailable in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") + message( FATAL_ERROR "gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") endif() set( ANDROID_RTTI ON ) set( ANDROID_EXCEPTIONS OFF ) @@ -1122,7 +1123,12 @@ if( NOT CMAKE_C_COMPILER ) endif() set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) - set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) + if( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" ) + # Use gcc-ar if we have it for better LTO support. + set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) + else() + set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) + endif() set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a55137d6..872c77d9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,18 +1,30 @@ # add the examples subdirectories -add_subdirectory(ftp) -add_subdirectory(opengl) -add_subdirectory(pong) -add_subdirectory(shader) -add_subdirectory(sockets) -add_subdirectory(sound) -add_subdirectory(sound_capture) -add_subdirectory(voip) -add_subdirectory(window) -if(SFML_OS_WINDOWS) - add_subdirectory(win32) -elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) - add_subdirectory(X11) -elseif(SFML_OS_MACOSX) - add_subdirectory(cocoa) +if(SFML_BUILD_NETWORK) + add_subdirectory(ftp) + add_subdirectory(sockets) +endif() +if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO) + add_subdirectory(voip) +endif() +if(SFML_BUILD_AUDIO) + add_subdirectory(sound) + add_subdirectory(sound_capture) +endif() +if(SFML_BUILD_WINDOW) + add_subdirectory(window) +endif() +if(SFML_BUILD_GRAPHICS) + add_subdirectory(opengl) + add_subdirectory(shader) + if(SFML_OS_WINDOWS) + add_subdirectory(win32) + elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) + add_subdirectory(X11) + elseif(SFML_OS_MACOSX) + add_subdirectory(cocoa) + endif() +endif() +if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO) + add_subdirectory(pong) endif() diff --git a/examples/X11/X11.cpp b/examples/X11/X11.cpp index 2c2419b7..746bf075 100644 --- a/examples/X11/X11.cpp +++ b/examples/X11/X11.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -133,77 +133,46 @@ int main() if (!display) return EXIT_FAILURE; - // Get the XCB connection for the opened display. - xcb_connection_t* xcbConnection = XGetXCBConnection(display); - - if (!xcbConnection) - { - sf::err() << "Failed to get the XCB connection for opened display." << std::endl; - return EXIT_FAILURE; - } - - // Get XCB screen. - const xcb_setup_t* xcbSetup = xcb_get_setup(xcbConnection); - xcb_screen_iterator_t xcbScreenIter = xcb_setup_roots_iterator(xcbSetup); - xcb_screen_t* screen = xcbScreenIter.data; - - if (!screen) - { - sf::err() << "Failed to get the XCB screen." << std::endl; + // Get the default screen + int screen = DefaultScreen(display); + + // Let's create the main window + XSetWindowAttributes attributes; + attributes.background_pixel = BlackPixel(display, screen); + attributes.event_mask = KeyPressMask; + Window window = XCreateWindow(display, RootWindow(display, screen), + 0, 0, 650, 330, 0, + DefaultDepth(display, screen), + InputOutput, + DefaultVisual(display, screen), + CWBackPixel | CWEventMask, &attributes); + if (!window) return EXIT_FAILURE; - } - // Generate the XCB window IDs. - xcb_window_t rootWindowId = xcb_generate_id(xcbConnection); - xcb_window_t view1WindowId = xcb_generate_id(xcbConnection); - xcb_window_t view2WindowId = xcb_generate_id(xcbConnection); - - // Create the root window with a black background. - uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; - uint32_t attributes[2] = {screen->black_pixel, XCB_EVENT_MASK_KEY_PRESS}; - - xcb_create_window(xcbConnection, - XCB_COPY_FROM_PARENT, - rootWindowId, - screen->root, - 0, 0, 650, 330, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - screen->root_visual, - mask, attributes); - - // Create windows for the SFML views. - xcb_create_window(xcbConnection, - XCB_COPY_FROM_PARENT, - view1WindowId, - rootWindowId, - 10, 10, 310, 310, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - screen->root_visual, - mask, attributes); - - xcb_create_window(xcbConnection, - XCB_COPY_FROM_PARENT, - view2WindowId, - rootWindowId, - 330, 10, 310, 310, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - screen->root_visual, - mask, attributes); - - // Map windows to screen. - xcb_map_window(xcbConnection, rootWindowId); - xcb_map_window(xcbConnection, view1WindowId); - xcb_map_window(xcbConnection, view2WindowId); - - // Flush commands. - xcb_flush(xcbConnection); + // Set the window's name + XStoreName(display, window , "SFML Window"); + + // Let's create the windows which will serve as containers for our SFML views + Window view1 = XCreateWindow(display, window, + 10, 10, 310, 310, 0, + DefaultDepth(display, screen), + InputOutput, + DefaultVisual(display, screen), + 0, NULL); + Window view2 = XCreateWindow(display, window, + 330, 10, 310, 310, 0, + DefaultDepth(display, screen), + InputOutput, + DefaultVisual(display, screen), + 0, NULL); + + // Show our windows + XMapWindow(display, window); + XFlush(display); // Create our SFML views - sf::Window sfmlView1(view1WindowId); - sf::Window sfmlView2(view2WindowId); + sf::Window sfmlView1(view1); + sf::Window sfmlView2(view2); // Create a clock for measuring elapsed time sf::Clock clock; @@ -214,13 +183,22 @@ int main() // Start the event loop bool running = true; - xcb_generic_event_t* event = NULL; - while (running) { - while ((event = xcb_poll_for_event(xcbConnection))) + while (XPending(display)) { - running = false; + // Get the next pending event + XEvent event; + XNextEvent(display, &event); + + // Process it + switch (event.type) + { + // Any key is pressed: quit + case KeyPress: + running = false; + break; + } } // Draw something into our views @@ -232,5 +210,8 @@ int main() sfmlView2.display(); } + // Close the display + XCloseDisplay(display); + return EXIT_SUCCESS; } diff --git a/examples/android/jni/Application.mk b/examples/android/jni/Application.mk index a18107ba..71828c8d 100644 --- a/examples/android/jni/Application.mk +++ b/examples/android/jni/Application.mk @@ -1,4 +1,4 @@ -NDK_TOOLCHAIN_VERSION := 4.8 +NDK_TOOLCHAIN_VERSION := 4.9 APP_PLATFORM := android-9 APP_STL := c++_shared APP_ABI := armeabi-v7a diff --git a/examples/cocoa/CocoaAppDelegate.h b/examples/cocoa/CocoaAppDelegate.h index b3fe9ca0..fed5b528 100644 --- a/examples/cocoa/CocoaAppDelegate.h +++ b/examples/cocoa/CocoaAppDelegate.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/examples/cocoa/CocoaAppDelegate.mm b/examples/cocoa/CocoaAppDelegate.mm index 87bc3b12..3996b3a3 100644 --- a/examples/cocoa/CocoaAppDelegate.mm +++ b/examples/cocoa/CocoaAppDelegate.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/examples/cocoa/NSString+stdstring.h b/examples/cocoa/NSString+stdstring.h index 0e4195ae..0021ef95 100644 --- a/examples/cocoa/NSString+stdstring.h +++ b/examples/cocoa/NSString+stdstring.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/examples/cocoa/NSString+stdstring.mm b/examples/cocoa/NSString+stdstring.mm index 5581f5ec..d2ce03bc 100644 --- a/examples/cocoa/NSString+stdstring.mm +++ b/examples/cocoa/NSString+stdstring.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/examples/cocoa/main.m b/examples/cocoa/main.m index 2609d648..a66e33a4 100644 --- a/examples/cocoa/main.m +++ b/examples/cocoa/main.m @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/examples/cocoa/resources/Cocoa-Info.plist b/examples/cocoa/resources/Cocoa-Info.plist index 0e730f24..3bbc6081 100644 --- a/examples/cocoa/resources/Cocoa-Info.plist +++ b/examples/cocoa/resources/Cocoa-Info.plist @@ -25,7 +25,7 @@ LSMinimumSystemVersion 10.6 NSHumanReadableCopyright - Copyright © 2007-2015 Marco Antognini and Laurent Gomila. Shared under zlib/libpng License. + Copyright © 2007-2017 Marco Antognini and Laurent Gomila. Shared under zlib/libpng License. NSMainNibFile MainMenu NSPrincipalClass diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index f8079f9f..fb3f77c6 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -21,7 +21,7 @@ int main() bool exit = false; bool sRgb = false; - while(!exit) + while (!exit) { // Request a 24-bits depth buffer when creating the window sf::ContextSettings contextSettings; @@ -44,26 +44,27 @@ int main() if (!font.loadFromFile("resources/sansation.ttf")) return EXIT_FAILURE; sf::Text text("SFML / OpenGL demo", font); - sf::Text instructions("Press space to toggle sRGB conversion", font); + sf::Text sRgbInstructions("Press space to toggle sRGB conversion", font); + sf::Text mipmapInstructions("Press return to toggle mipmapping", font); text.setFillColor(sf::Color(255, 255, 255, 170)); - instructions.setFillColor(sf::Color(255, 255, 255, 170)); + sRgbInstructions.setFillColor(sf::Color(255, 255, 255, 170)); + mipmapInstructions.setFillColor(sf::Color(255, 255, 255, 170)); text.setPosition(250.f, 450.f); - instructions.setPosition(150.f, 500.f); + sRgbInstructions.setPosition(150.f, 500.f); + mipmapInstructions.setPosition(180.f, 550.f); - // Load an OpenGL texture. - // We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function), - // but here we want more control on it (generate mipmaps, ...) so we create a new one from an image - GLuint texture = 0; - { - sf::Image image; - if (!image.loadFromFile("resources/texture.jpg")) - return EXIT_FAILURE; - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, sRgb ? GL_SRGB8_ALPHA8 : GL_RGBA, image.getSize().x, image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } + // Load a texture to apply to our 3D cube + sf::Texture texture; + if (!texture.loadFromFile("resources/texture.jpg")) + return EXIT_FAILURE; + + // Attempt to generate a mipmap for our cube texture + // We don't check the return value here since + // mipmapping is purely optional in this example + texture.generateMipmap(); + + // Make the window the active window for OpenGL calls + window.setActive(true); // Enable Z-buffer read and write glEnable(GL_DEPTH_TEST); @@ -84,7 +85,7 @@ int main() // Bind the texture glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture); + sf::Texture::bind(&texture); // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices) static const GLfloat cube[] = @@ -143,9 +144,15 @@ int main() glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); + // Make the window no longer the active window for OpenGL calls + window.setActive(false); + // Create a clock for measuring the time elapsed sf::Clock clock; + // Flag to track whether mipmapping is currently enabled + bool mipmapEnabled = true; + // Start game loop while (window.isOpen()) { @@ -167,6 +174,25 @@ int main() window.close(); } + // Return key: toggle mipmapping + if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Return)) + { + if (mipmapEnabled) + { + // We simply reload the texture to disable mipmapping + if (!texture.loadFromFile("resources/texture.jpg")) + return EXIT_FAILURE; + + mipmapEnabled = false; + } + else + { + texture.generateMipmap(); + + mipmapEnabled = true; + } + } + // Space key: toggle sRGB conversion if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) { @@ -176,7 +202,15 @@ int main() // Adjust the viewport when the window is resized if (event.type == sf::Event::Resized) + { + // Make the window the active window for OpenGL calls + window.setActive(true); + glViewport(0, 0, event.size.width, event.size.height); + + // Make the window no longer the active window for OpenGL calls + window.setActive(false); + } } // Draw the background @@ -184,6 +218,9 @@ int main() window.draw(background); window.popGLStates(); + // Make the window the active window for OpenGL calls + window.setActive(true); + // Clear the depth buffer glClear(GL_DEPTH_BUFFER_BIT); @@ -202,18 +239,19 @@ int main() // Draw the cube glDrawArrays(GL_TRIANGLES, 0, 36); + // Make the window no longer the active window for OpenGL calls + window.setActive(false); + // Draw some text on top of our OpenGL object window.pushGLStates(); window.draw(text); - window.draw(instructions); + window.draw(sRgbInstructions); + window.draw(mipmapInstructions); window.popGLStates(); // Finally, display the rendered frame on screen window.display(); } - - // Don't forget to destroy our texture - glDeleteTextures(1, &texture); } return EXIT_SUCCESS; diff --git a/extlibs/libs-ios/libflac.a b/extlibs/libs-ios/libflac.a index 9bf53b3a..5b74895d 100644 Binary files a/extlibs/libs-ios/libflac.a and b/extlibs/libs-ios/libflac.a differ diff --git a/extlibs/libs-ios/libfreetype.a b/extlibs/libs-ios/libfreetype.a index 6b20a682..70fb708d 100644 Binary files a/extlibs/libs-ios/libfreetype.a and b/extlibs/libs-ios/libfreetype.a differ diff --git a/extlibs/libs-ios/libjpeg.a b/extlibs/libs-ios/libjpeg.a index 8c39846f..d92b0c1a 100644 Binary files a/extlibs/libs-ios/libjpeg.a and b/extlibs/libs-ios/libjpeg.a differ diff --git a/extlibs/libs-ios/libogg.a b/extlibs/libs-ios/libogg.a index be00db08..62cbc103 100644 Binary files a/extlibs/libs-ios/libogg.a and b/extlibs/libs-ios/libogg.a differ diff --git a/extlibs/libs-ios/libvorbis.a b/extlibs/libs-ios/libvorbis.a index 804301a7..fe87e924 100644 Binary files a/extlibs/libs-ios/libvorbis.a and b/extlibs/libs-ios/libvorbis.a differ diff --git a/extlibs/libs-ios/libvorbisenc.a b/extlibs/libs-ios/libvorbisenc.a deleted file mode 100644 index 2826e622..00000000 Binary files a/extlibs/libs-ios/libvorbisenc.a and /dev/null differ diff --git a/extlibs/libs-ios/libvorbisfile.a b/extlibs/libs-ios/libvorbisfile.a deleted file mode 100644 index e39be76e..00000000 Binary files a/extlibs/libs-ios/libvorbisfile.a and /dev/null differ diff --git a/extlibs/libs-osx/Frameworks/FLAC.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/FLAC.framework/Versions/A/Resources/Info.plist index 36f80bd9..17506ffe 100644 --- a/extlibs/libs-osx/Frameworks/FLAC.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/FLAC.framework/Versions/A/Resources/Info.plist @@ -16,5 +16,7 @@ ???? CFBundleVersion 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/extlibs/libs-osx/Frameworks/OpenAL.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/OpenAL.framework/Versions/A/Resources/Info.plist index 9d630276..abcc123b 100644 --- a/extlibs/libs-osx/Frameworks/OpenAL.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/OpenAL.framework/Versions/A/Resources/Info.plist @@ -16,5 +16,7 @@ ???? CFBundleVersion 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/extlibs/libs-osx/Frameworks/freetype.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/freetype.framework/Versions/A/Resources/Info.plist index f7f42180..3fae0b28 100644 --- a/extlibs/libs-osx/Frameworks/freetype.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/freetype.framework/Versions/A/Resources/Info.plist @@ -2,19 +2,21 @@ - CFBundleDevelopmentRegion - English - CFBundleExecutable - freetype - CFBundleIdentifier - org.sfml-dev.freetype - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - FMWK - CFBundleSignature - ???? - CFBundleVersion - 1.0 + CFBundleDevelopmentRegion + English + CFBundleExecutable + freetype + CFBundleIdentifier + org.sfml-dev.freetype + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleSignature + ???? + CFBundleVersion + 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/extlibs/libs-osx/Frameworks/ogg.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/ogg.framework/Versions/A/Resources/Info.plist index ed6050c2..3b7fe8cd 100644 --- a/extlibs/libs-osx/Frameworks/ogg.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/ogg.framework/Versions/A/Resources/Info.plist @@ -16,5 +16,7 @@ ???? CFBundleVersion 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/extlibs/libs-osx/Frameworks/vorbis.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/vorbis.framework/Versions/A/Resources/Info.plist index 7f0d0712..49288dcc 100644 --- a/extlibs/libs-osx/Frameworks/vorbis.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/vorbis.framework/Versions/A/Resources/Info.plist @@ -16,5 +16,7 @@ ???? CFBundleVersion 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/extlibs/libs-osx/Frameworks/vorbisenc.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/vorbisenc.framework/Versions/A/Resources/Info.plist index 71765e18..7239ec07 100644 --- a/extlibs/libs-osx/Frameworks/vorbisenc.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/vorbisenc.framework/Versions/A/Resources/Info.plist @@ -16,5 +16,7 @@ ???? CFBundleVersion 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/extlibs/libs-osx/Frameworks/vorbisfile.framework/Versions/A/Resources/Info.plist b/extlibs/libs-osx/Frameworks/vorbisfile.framework/Versions/A/Resources/Info.plist index 50b71edc..02c18c59 100644 --- a/extlibs/libs-osx/Frameworks/vorbisfile.framework/Versions/A/Resources/Info.plist +++ b/extlibs/libs-osx/Frameworks/vorbisfile.framework/Versions/A/Resources/Info.plist @@ -16,5 +16,7 @@ ???? CFBundleVersion 1.0 + CFBundleSupportedPlatforms + MacOSX diff --git a/include/SFML/Audio.hpp b/include/SFML/Audio.hpp index 41737cf8..2d3e5d75 100644 --- a/include/SFML/Audio.hpp +++ b/include/SFML/Audio.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/AlResource.hpp b/include/SFML/Audio/AlResource.hpp index ca5d2c01..2cb48d0e 100644 --- a/include/SFML/Audio/AlResource.hpp +++ b/include/SFML/Audio/AlResource.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/Export.hpp b/include/SFML/Audio/Export.hpp index 1ea6f425..31e463ea 100644 --- a/include/SFML/Audio/Export.hpp +++ b/include/SFML/Audio/Export.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/InputSoundFile.hpp b/include/SFML/Audio/InputSoundFile.hpp index 250a9b16..031c85f4 100644 --- a/include/SFML/Audio/InputSoundFile.hpp +++ b/include/SFML/Audio/InputSoundFile.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -32,6 +32,7 @@ #include #include #include +#include namespace sf @@ -146,6 +147,22 @@ class SFML_AUDIO_API InputSoundFile : NonCopyable //////////////////////////////////////////////////////////// Time getDuration() const; + //////////////////////////////////////////////////////////// + /// \brief Get the read offset of the file in time + /// + /// \return Time position + /// + //////////////////////////////////////////////////////////// + Time getTimeOffset() const; + + //////////////////////////////////////////////////////////// + /// \brief Get the read offset of the file in samples + /// + /// \return Sample position + /// + //////////////////////////////////////////////////////////// + Uint64 getSampleOffset() const; + //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset /// @@ -203,6 +220,7 @@ class SFML_AUDIO_API InputSoundFile : NonCopyable SoundFileReader* m_reader; ///< Reader that handles I/O on the file's format InputStream* m_stream; ///< Input stream used to access the file's data bool m_streamOwned; ///< Is the stream internal or external? + Uint64 m_sampleOffset; ///< Sample Read Position Uint64 m_sampleCount; ///< Total number of samples in the file unsigned int m_channelCount; ///< Number of channels of the sound unsigned int m_sampleRate; ///< Number of samples per second diff --git a/include/SFML/Audio/Listener.hpp b/include/SFML/Audio/Listener.hpp index 04e4af3d..af83e252 100644 --- a/include/SFML/Audio/Listener.hpp +++ b/include/SFML/Audio/Listener.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/Music.hpp b/include/SFML/Audio/Music.hpp index 76b4254e..5e272655 100644 --- a/include/SFML/Audio/Music.hpp +++ b/include/SFML/Audio/Music.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -168,10 +168,9 @@ class SFML_AUDIO_API Music : public SoundStream //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - InputSoundFile m_file; ///< The streamed music file - Time m_duration; ///< Music duration - std::vector m_samples; ///< Temporary buffer of samples - Mutex m_mutex; ///< Mutex protecting the data + InputSoundFile m_file; ///< The streamed music file + std::vector m_samples; ///< Temporary buffer of samples + Mutex m_mutex; ///< Mutex protecting the data }; } // namespace sf diff --git a/include/SFML/Audio/OutputSoundFile.hpp b/include/SFML/Audio/OutputSoundFile.hpp index 8f60498c..325b38f0 100644 --- a/include/SFML/Audio/OutputSoundFile.hpp +++ b/include/SFML/Audio/OutputSoundFile.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/Sound.hpp b/include/SFML/Audio/Sound.hpp index 8b0771d6..3b200240 100644 --- a/include/SFML/Audio/Sound.hpp +++ b/include/SFML/Audio/Sound.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundBuffer.hpp b/include/SFML/Audio/SoundBuffer.hpp index 42eda6fa..6303cfb3 100644 --- a/include/SFML/Audio/SoundBuffer.hpp +++ b/include/SFML/Audio/SoundBuffer.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundBufferRecorder.hpp b/include/SFML/Audio/SoundBufferRecorder.hpp index 28b7596e..b5b6436c 100644 --- a/include/SFML/Audio/SoundBufferRecorder.hpp +++ b/include/SFML/Audio/SoundBufferRecorder.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundFileFactory.hpp b/include/SFML/Audio/SoundFileFactory.hpp index bd346cc1..b4eadf0f 100644 --- a/include/SFML/Audio/SoundFileFactory.hpp +++ b/include/SFML/Audio/SoundFileFactory.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundFileFactory.inl b/include/SFML/Audio/SoundFileFactory.inl index 19d334b6..a552ba87 100644 --- a/include/SFML/Audio/SoundFileFactory.inl +++ b/include/SFML/Audio/SoundFileFactory.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundFileReader.hpp b/include/SFML/Audio/SoundFileReader.hpp index 0bf83550..006ce654 100644 --- a/include/SFML/Audio/SoundFileReader.hpp +++ b/include/SFML/Audio/SoundFileReader.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundFileWriter.hpp b/include/SFML/Audio/SoundFileWriter.hpp index 36a26784..8a35a0da 100644 --- a/include/SFML/Audio/SoundFileWriter.hpp +++ b/include/SFML/Audio/SoundFileWriter.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundRecorder.hpp b/include/SFML/Audio/SoundRecorder.hpp index f05b4a59..33c80b1f 100644 --- a/include/SFML/Audio/SoundRecorder.hpp +++ b/include/SFML/Audio/SoundRecorder.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -144,6 +144,34 @@ class SFML_AUDIO_API SoundRecorder : AlResource //////////////////////////////////////////////////////////// const std::string& getDevice() const; + //////////////////////////////////////////////////////////// + /// \brief Set the channel count of the audio capture device + /// + /// This method allows you to specify the number of channels + /// used for recording. Currently only 16-bit mono and + /// 16-bit stereo are supported. + /// + /// \param channelCount Number of channels. Currently only + /// mono (1) and stereo (2) are supported. + /// + /// \see getChannelCount + /// + //////////////////////////////////////////////////////////// + void setChannelCount(unsigned int channelCount); + + //////////////////////////////////////////////////////////// + /// \brief Get the number of channels used by this recorder + /// + /// Currently only mono and stereo are supported, so the + /// value is either 1 (for mono) or 2 (for stereo). + /// + /// \return Number of channels + /// + /// \see setChannelCount + /// + //////////////////////////////////////////////////////////// + unsigned int getChannelCount() const; + //////////////////////////////////////////////////////////// /// \brief Check if the system supports audio capture /// @@ -263,6 +291,7 @@ class SFML_AUDIO_API SoundRecorder : AlResource Time m_processingInterval; ///< Time period between calls to onProcessSamples bool m_isCapturing; ///< Capturing state std::string m_deviceName; ///< Name of the audio capture device + unsigned int m_channelCount; ///< Number of recording channels }; } // namespace sf @@ -309,6 +338,12 @@ class SFML_AUDIO_API SoundRecorder : AlResource /// by calling setDevice() with the appropriate device. Otherwise /// the default capturing device will be used. /// +/// By default the recording is in 16-bit mono. Using the +/// setChannelCount method you can change the number of channels +/// used by the audio capture device to record. Note that you +/// have to decide whether you want to record in mono or stereo +/// before starting the recording. +/// /// It is important to note that the audio capture happens in a /// separate thread, so that it doesn't block the rest of the /// program. In particular, the onProcessSamples virtual function diff --git a/include/SFML/Audio/SoundSource.hpp b/include/SFML/Audio/SoundSource.hpp index 02445775..edcaaa29 100644 --- a/include/SFML/Audio/SoundSource.hpp +++ b/include/SFML/Audio/SoundSource.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Audio/SoundStream.hpp b/include/SFML/Audio/SoundStream.hpp index 22ae8cd5..bd621727 100644 --- a/include/SFML/Audio/SoundStream.hpp +++ b/include/SFML/Audio/SoundStream.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -254,11 +254,12 @@ class SFML_AUDIO_API SoundStream : public SoundSource /// playing queue. /// /// \param bufferNum Number of the buffer to fill (in [0, BufferCount]) + /// \param immediateLoop Treat empty buffers as spent, and act on loops immediately /// /// \return True if the stream source has requested to stop, false otherwise /// //////////////////////////////////////////////////////////// - bool fillAndPushBuffer(unsigned int bufferNum); + bool fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop = false); //////////////////////////////////////////////////////////// /// \brief Fill the audio buffers and put them all into the playing queue @@ -281,7 +282,8 @@ class SFML_AUDIO_API SoundStream : public SoundSource enum { - BufferCount = 3 ///< Number of audio buffers used by the streaming loop + BufferCount = 3, ///< Number of audio buffers used by the streaming loop + BufferRetries = 2 ///< Number of retries (excluding initial try) for onGetData() }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Config.hpp b/include/SFML/Config.hpp index f5788dc0..5a8a87cf 100644 --- a/include/SFML/Config.hpp +++ b/include/SFML/Config.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -30,7 +30,7 @@ // Define the SFML version //////////////////////////////////////////////////////////// #define SFML_VERSION_MAJOR 2 -#define SFML_VERSION_MINOR 3 +#define SFML_VERSION_MINOR 4 #define SFML_VERSION_PATCH 2 diff --git a/include/SFML/Graphics.hpp b/include/SFML/Graphics.hpp index 7a7f4da8..5bb622aa 100644 --- a/include/SFML/Graphics.hpp +++ b/include/SFML/Graphics.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index 08f049dd..3ba0a40f 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -202,7 +202,7 @@ SFML_GRAPHICS_API extern const BlendMode BlendNone; ///< Overwrite dest with /// \code /// sf::BlendMode alphaBlending = sf::BlendAlpha; /// sf::BlendMode additiveBlending = sf::BlendAdd; -/// sf::BlendMode multiplicativeBlending = sf::BlendMultipy; +/// sf::BlendMode multiplicativeBlending = sf::BlendMultiply; /// sf::BlendMode noBlending = sf::BlendNone; /// \endcode /// diff --git a/include/SFML/Graphics/CircleShape.hpp b/include/SFML/Graphics/CircleShape.hpp index 2d5ac00c..9f689691 100644 --- a/include/SFML/Graphics/CircleShape.hpp +++ b/include/SFML/Graphics/CircleShape.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Color.hpp b/include/SFML/Graphics/Color.hpp index 87a15982..1f81feb1 100644 --- a/include/SFML/Graphics/Color.hpp +++ b/include/SFML/Graphics/Color.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/ConvexShape.hpp b/include/SFML/Graphics/ConvexShape.hpp index 82991a72..117f843a 100644 --- a/include/SFML/Graphics/ConvexShape.hpp +++ b/include/SFML/Graphics/ConvexShape.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Drawable.hpp b/include/SFML/Graphics/Drawable.hpp index 5ddf2da0..a409cf7c 100644 --- a/include/SFML/Graphics/Drawable.hpp +++ b/include/SFML/Graphics/Drawable.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Export.hpp b/include/SFML/Graphics/Export.hpp index 624f1eb5..de164a1a 100644 --- a/include/SFML/Graphics/Export.hpp +++ b/include/SFML/Graphics/Export.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index 409802bf..9451f08c 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -91,7 +91,7 @@ class SFML_GRAPHICS_API Font /// /// The supported font formats are: TrueType, Type 1, CFF, /// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. - /// Note that this function know nothing about the standard + /// Note that this function knows nothing about the standard /// fonts installed on the user's system, thus you can't /// load them directly. /// diff --git a/include/SFML/Graphics/Glsl.hpp b/include/SFML/Graphics/Glsl.hpp index ecc7a923..7bf16046 100644 --- a/include/SFML/Graphics/Glsl.hpp +++ b/include/SFML/Graphics/Glsl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Glsl.inl b/include/SFML/Graphics/Glsl.inl index b729b297..8e728716 100644 --- a/include/SFML/Graphics/Glsl.inl +++ b/include/SFML/Graphics/Glsl.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Glyph.hpp b/include/SFML/Graphics/Glyph.hpp index 00688723..8c632af2 100644 --- a/include/SFML/Graphics/Glyph.hpp +++ b/include/SFML/Graphics/Glyph.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 11dc8f70..a9010c0d 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/PrimitiveType.hpp b/include/SFML/Graphics/PrimitiveType.hpp index 9dae947d..33f9e466 100644 --- a/include/SFML/Graphics/PrimitiveType.hpp +++ b/include/SFML/Graphics/PrimitiveType.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -38,13 +38,18 @@ namespace sf //////////////////////////////////////////////////////////// enum PrimitiveType { - Points, ///< List of individual points - Lines, ///< List of individual lines - LinesStrip, ///< List of connected lines, a point uses the previous point to form a line - Triangles, ///< List of individual triangles - TrianglesStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle - TrianglesFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle - Quads ///< List of individual quads (deprecated, don't work with OpenGL ES) + Points, ///< List of individual points + Lines, ///< List of individual lines + LineStrip, ///< List of connected lines, a point uses the previous point to form a line + Triangles, ///< List of individual triangles + TriangleStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle + TriangleFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle + Quads, ///< List of individual quads (deprecated, don't work with OpenGL ES) + + // Deprecated names + LinesStrip = LineStrip, ///< \deprecated Use LineStrip instead + TrianglesStrip = TriangleStrip, ///< \deprecated Use TriangleStrip instead + TrianglesFan = TriangleFan ///< \deprecated Use TriangleFan instead }; } // namespace sf diff --git a/include/SFML/Graphics/Rect.hpp b/include/SFML/Graphics/Rect.hpp index f11a9204..b88e9b2b 100644 --- a/include/SFML/Graphics/Rect.hpp +++ b/include/SFML/Graphics/Rect.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -95,6 +95,9 @@ class Rect //////////////////////////////////////////////////////////// /// \brief Check if a point is inside the rectangle's area /// + /// This check is non-inclusive. If the point lies on the + /// edge of the rectangle, this function will return false. + /// /// \param x X coordinate of the point to test /// \param y Y coordinate of the point to test /// @@ -108,6 +111,9 @@ class Rect //////////////////////////////////////////////////////////// /// \brief Check if a point is inside the rectangle's area /// + /// This check is non-inclusive. If the point lies on the + /// edge of the rectangle, this function will return false. + /// /// \param point Point to test /// /// \return True if the point is inside, false otherwise diff --git a/include/SFML/Graphics/Rect.inl b/include/SFML/Graphics/Rect.inl index 9ac4870b..c1bb9bbf 100644 --- a/include/SFML/Graphics/Rect.inl +++ b/include/SFML/Graphics/Rect.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/RectangleShape.hpp b/include/SFML/Graphics/RectangleShape.hpp index 3195dc39..f9754f69 100644 --- a/include/SFML/Graphics/RectangleShape.hpp +++ b/include/SFML/Graphics/RectangleShape.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/RenderStates.hpp b/include/SFML/Graphics/RenderStates.hpp index 3ab3271f..870b275a 100644 --- a/include/SFML/Graphics/RenderStates.hpp +++ b/include/SFML/Graphics/RenderStates.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/RenderTarget.hpp b/include/SFML/Graphics/RenderTarget.hpp index eb023552..50bf7a6f 100644 --- a/include/SFML/Graphics/RenderTarget.hpp +++ b/include/SFML/Graphics/RenderTarget.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -255,6 +255,28 @@ class SFML_GRAPHICS_API RenderTarget : NonCopyable //////////////////////////////////////////////////////////// virtual Vector2u getSize() const = 0; + //////////////////////////////////////////////////////////// + /// \brief Activate or deactivate the render target for rendering + /// + /// This function makes the render target's context current for + /// future OpenGL rendering operations (so you shouldn't care + /// about it if you're not doing direct OpenGL stuff). + /// A render target's context is active only on the current thread, + /// if you want to make it active on another thread you have + /// to deactivate it on the previous thread first if it was active. + /// Only one context can be current in a thread, so if you + /// want to draw OpenGL geometry to another render target + /// don't forget to activate it again. Activating a render + /// target will automatically deactivate the previously active + /// context (if any). + /// + /// \param active True to activate, false to deactivate + /// + /// \return True if operation was successful, false otherwise + /// + //////////////////////////////////////////////////////////// + virtual bool setActive(bool active = true) = 0; + //////////////////////////////////////////////////////////// /// \brief Save the current OpenGL render states and matrices /// @@ -380,20 +402,6 @@ class SFML_GRAPHICS_API RenderTarget : NonCopyable //////////////////////////////////////////////////////////// void applyShader(const Shader* shader); - //////////////////////////////////////////////////////////// - /// \brief Activate the target for rendering - /// - /// This function must be implemented by derived classes to make - /// their OpenGL context current; it is called by the base class - /// everytime it's going to use OpenGL calls. - /// - /// \param active True to make the target active, false to deactivate it - /// - /// \return True if the function succeeded - /// - //////////////////////////////////////////////////////////// - virtual bool activate(bool active) = 0; - //////////////////////////////////////////////////////////// /// \brief Render states cache /// @@ -406,6 +414,7 @@ class SFML_GRAPHICS_API RenderTarget : NonCopyable bool viewChanged; ///< Has the current view changed since last draw? BlendMode lastBlendMode; ///< Cached blending mode Uint64 lastTextureId; ///< Cached texture + bool texCoordsArrayEnabled; ///< Is GL_TEXTURE_COORD_ARRAY client state enabled? bool useVertexCache; ///< Did we previously use the vertex cache? Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache }; diff --git a/include/SFML/Graphics/RenderTexture.hpp b/include/SFML/Graphics/RenderTexture.hpp index e06740cd..52d53bd1 100644 --- a/include/SFML/Graphics/RenderTexture.hpp +++ b/include/SFML/Graphics/RenderTexture.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -131,6 +131,22 @@ class SFML_GRAPHICS_API RenderTexture : public RenderTarget //////////////////////////////////////////////////////////// bool isRepeated() const; + //////////////////////////////////////////////////////////// + /// \brief Generate a mipmap using the current texture data + /// + /// This function is similar to Texture::generateMipmap and operates + /// on the texture used as the target for drawing. + /// Be aware that any draw operation may modify the base level image data. + /// For this reason, calling this function only makes sense after all + /// drawing is completed and display has been called. Not calling display + /// after subsequent drawing will lead to undefined behavior if a mipmap + /// had been previously generated. + /// + /// \return True if mipmap generation was successful, false if unsuccessful + /// + //////////////////////////////////////////////////////////// + bool generateMipmap(); + //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the render-texture for rendering /// @@ -188,19 +204,6 @@ class SFML_GRAPHICS_API RenderTexture : public RenderTarget private: - //////////////////////////////////////////////////////////// - /// \brief Activate the target for rendering - /// - /// This function is called by the base class - /// everytime it's going to use OpenGL calls. - /// - /// \param active True to make the target active, false to deactivate it - /// - /// \return True if the function succeeded - /// - //////////////////////////////////////////////////////////// - virtual bool activate(bool active); - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index e415b003..609f912a 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -112,6 +112,24 @@ class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget //////////////////////////////////////////////////////////// virtual Vector2u getSize() const; + //////////////////////////////////////////////////////////// + /// \brief Activate or deactivate the window as the current target + /// for OpenGL rendering + /// + /// A window is active only on the current thread, if you want to + /// make it active on another thread you have to deactivate it + /// on the previous thread first if it was active. + /// Only one window can be active on a thread at a time, thus + /// the window previously active (if any) automatically gets deactivated. + /// This is not to be confused with requestFocus(). + /// + /// \param active True to activate, false to deactivate + /// + /// \return True if operation was successful, false otherwise + /// + //////////////////////////////////////////////////////////// + bool setActive(bool active = true); + //////////////////////////////////////////////////////////// /// \brief Copy the current contents of the window to an image /// @@ -159,18 +177,6 @@ class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget /// //////////////////////////////////////////////////////////// virtual void onResize(); - -private: - - //////////////////////////////////////////////////////////// - /// \brief Activate the target for rendering - /// - /// \param active True to make the target active, false to deactivate it - /// - /// \return True if the function succeeded - /// - //////////////////////////////////////////////////////////// - virtual bool activate(bool active); }; } // namespace sf diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 9f7e5f99..9fe9c607 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Shape.hpp b/include/SFML/Graphics/Shape.hpp index 5983a9de..b257ddc8 100644 --- a/include/SFML/Graphics/Shape.hpp +++ b/include/SFML/Graphics/Shape.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index c7447dff..51bba30c 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index ad2c9180..7b7cf611 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -445,7 +445,7 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable /// sf::Text text("hello", font); /// text.setCharacterSize(30); /// text.setStyle(sf::Text::Bold); -/// text.setColor(sf::Color::Red); +/// text.setFillColor(sf::Color::Red); /// /// // Draw it /// window.draw(text); diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index e9e97afe..20a8ede8 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -276,6 +276,43 @@ class SFML_GRAPHICS_API Texture : GlResource //////////////////////////////////////////////////////////// void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y); + //////////////////////////////////////////////////////////// + /// \brief Update a part of this texture from another texture + /// + /// Although the source texture can be smaller than this texture, + /// this function is usually used for updating the whole texture. + /// The other overload, which has (x, y) additional arguments, + /// is more convenient for updating a sub-area of this texture. + /// + /// No additional check is performed on the size of the passed + /// texture, passing a texture bigger than this texture + /// will lead to an undefined behavior. + /// + /// This function does nothing if either texture was not + /// previously created. + /// + /// \param texture Source texture to copy to this texture + /// + //////////////////////////////////////////////////////////// + void update(const Texture& texture); + + //////////////////////////////////////////////////////////// + /// \brief Update a part of this texture from another texture + /// + /// No additional check is performed on the size of the texture, + /// passing an invalid combination of texture size and offset + /// will lead to an undefined behavior. + /// + /// This function does nothing if either texture was not + /// previously created. + /// + /// \param texture Source texture to copy to this texture + /// \param x X offset in this texture where to copy the source texture + /// \param y Y offset in this texture where to copy the source texture + /// + //////////////////////////////////////////////////////////// + void update(const Texture& texture, unsigned int x, unsigned int y); + //////////////////////////////////////////////////////////// /// \brief Update the texture from an image /// @@ -445,6 +482,31 @@ class SFML_GRAPHICS_API Texture : GlResource //////////////////////////////////////////////////////////// bool isRepeated() const; + //////////////////////////////////////////////////////////// + /// \brief Generate a mipmap using the current texture data + /// + /// Mipmaps are pre-computed chains of optimized textures. Each + /// level of texture in a mipmap is generated by halving each of + /// the previous level's dimensions. This is done until the final + /// level has the size of 1x1. The textures generated in this process may + /// make use of more advanced filters which might improve the visual quality + /// of textures when they are applied to objects much smaller than they are. + /// This is known as minification. Because fewer texels (texture elements) + /// have to be sampled from when heavily minified, usage of mipmaps + /// can also improve rendering performance in certain scenarios. + /// + /// Mipmap generation relies on the necessary OpenGL extension being + /// available. If it is unavailable or generation fails due to another + /// reason, this function will return false. Mipmap data is only valid from + /// the time it is generated until the next time the base level image is + /// modified, at which point this function will have to be called again to + /// regenerate it. + /// + /// \return True if mipmap generation was successful, false if unsuccessful + /// + //////////////////////////////////////////////////////////// + bool generateMipmap(); + //////////////////////////////////////////////////////////// /// \brief Overload of assignment operator /// @@ -455,6 +517,14 @@ class SFML_GRAPHICS_API Texture : GlResource //////////////////////////////////////////////////////////// Texture& operator =(const Texture& right); + //////////////////////////////////////////////////////////// + /// \brief Swap the contents of this texture with those of another + /// + /// \param right Instance to swap with + /// + //////////////////////////////////////////////////////////// + void swap(Texture& right); + //////////////////////////////////////////////////////////// /// \brief Get the underlying OpenGL handle of the texture. /// @@ -532,6 +602,15 @@ class SFML_GRAPHICS_API Texture : GlResource //////////////////////////////////////////////////////////// static unsigned int getValidSize(unsigned int size); + //////////////////////////////////////////////////////////// + /// \brief Invalidate the mipmap if one exists + /// + /// This also resets the texture's minifying function. + /// This function is mainly for internal use by RenderTexture. + /// + //////////////////////////////////////////////////////////// + void invalidateMipmap(); + //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// @@ -543,6 +622,7 @@ class SFML_GRAPHICS_API Texture : GlResource bool m_isRepeated; ///< Is the texture in repeat mode? mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation bool m_fboAttachment; ///< Is this texture owned by a framebuffer object? + bool m_hasMipmap; ///< Has the mipmap been generated? Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache }; diff --git a/include/SFML/Graphics/Transform.hpp b/include/SFML/Graphics/Transform.hpp index a555a33d..ab0307cc 100644 --- a/include/SFML/Graphics/Transform.hpp +++ b/include/SFML/Graphics/Transform.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Transformable.hpp b/include/SFML/Graphics/Transformable.hpp index e4b86cf3..4e46cc6f 100644 --- a/include/SFML/Graphics/Transformable.hpp +++ b/include/SFML/Graphics/Transformable.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/Vertex.hpp b/include/SFML/Graphics/Vertex.hpp index 25099764..a9a88200 100644 --- a/include/SFML/Graphics/Vertex.hpp +++ b/include/SFML/Graphics/Vertex.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Graphics/VertexArray.hpp b/include/SFML/Graphics/VertexArray.hpp index f0820a53..109a7e82 100644 --- a/include/SFML/Graphics/VertexArray.hpp +++ b/include/SFML/Graphics/VertexArray.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -209,7 +209,7 @@ class SFML_GRAPHICS_API VertexArray : public Drawable /// /// Example: /// \code -/// sf::VertexArray lines(sf::LinesStrip, 4); +/// sf::VertexArray lines(sf::LineStrip, 4); /// lines[0].position = sf::Vector2f(10, 0); /// lines[1].position = sf::Vector2f(20, 0); /// lines[2].position = sf::Vector2f(30, 5); diff --git a/include/SFML/Graphics/View.hpp b/include/SFML/Graphics/View.hpp index 4bd62d83..d49cb491 100644 --- a/include/SFML/Graphics/View.hpp +++ b/include/SFML/Graphics/View.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -302,11 +302,11 @@ class SFML_GRAPHICS_API View /// The viewport allows to map the scene to a custom part /// of the render target, and can be used for split-screen /// or for displaying a minimap, for example. If the source -/// rectangle has not the same size as the viewport, its +/// rectangle doesn't have the same size as the viewport, its /// contents will be stretched to fit in. /// /// To apply a view, you have to assign it to the render target. -/// Then, every objects drawn in this render target will be +/// Then, objects drawn in this render target will be /// affected by the view until you use another view. /// /// Usage example: diff --git a/include/SFML/Main.hpp b/include/SFML/Main.hpp index 23973d0f..f8ac048d 100644 --- a/include/SFML/Main.hpp +++ b/include/SFML/Main.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network.hpp b/include/SFML/Network.hpp index 68507aff..3216c5cc 100644 --- a/include/SFML/Network.hpp +++ b/include/SFML/Network.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/Export.hpp b/include/SFML/Network/Export.hpp index 6c880f65..4a8d800a 100644 --- a/include/SFML/Network/Export.hpp +++ b/include/SFML/Network/Export.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/Ftp.hpp b/include/SFML/Network/Ftp.hpp index c62db7ba..3600a9d8 100644 --- a/include/SFML/Network/Ftp.hpp +++ b/include/SFML/Network/Ftp.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -529,7 +529,8 @@ class SFML_NETWORK_API Ftp : NonCopyable //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - TcpSocket m_commandSocket; ///< Socket holding the control connection with the server + TcpSocket m_commandSocket; ///< Socket holding the control connection with the server + std::string m_receiveBuffer; ///< Received command data that is yet to be processed }; } // namespace sf diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index 057b86ba..d165a7c1 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/IpAddress.hpp b/include/SFML/Network/IpAddress.hpp index 5d9c8e8d..4940f2b7 100644 --- a/include/SFML/Network/IpAddress.hpp +++ b/include/SFML/Network/IpAddress.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index 0b7da9f5..ac97692a 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/Socket.hpp b/include/SFML/Network/Socket.hpp index d63f55e5..0b111716 100644 --- a/include/SFML/Network/Socket.hpp +++ b/include/SFML/Network/Socket.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/SocketHandle.hpp b/include/SFML/Network/SocketHandle.hpp index 7808ab52..d5b395de 100644 --- a/include/SFML/Network/SocketHandle.hpp +++ b/include/SFML/Network/SocketHandle.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/SocketSelector.hpp b/include/SFML/Network/SocketSelector.hpp index 4d334c62..92dcbad9 100644 --- a/include/SFML/Network/SocketSelector.hpp +++ b/include/SFML/Network/SocketSelector.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/TcpListener.hpp b/include/SFML/Network/TcpListener.hpp index b9d14acf..720ebf1d 100644 --- a/include/SFML/Network/TcpListener.hpp +++ b/include/SFML/Network/TcpListener.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/TcpSocket.hpp b/include/SFML/Network/TcpSocket.hpp index a402506b..da6b5493 100644 --- a/include/SFML/Network/TcpSocket.hpp +++ b/include/SFML/Network/TcpSocket.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Network/UdpSocket.hpp b/include/SFML/Network/UdpSocket.hpp index f4b69dcb..6ee191c6 100644 --- a/include/SFML/Network/UdpSocket.hpp +++ b/include/SFML/Network/UdpSocket.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -95,9 +95,11 @@ class SFML_NETWORK_API UdpSocket : public Socket //////////////////////////////////////////////////////////// /// \brief Unbind the socket from the local port to which it is bound /// - /// The port that the socket was previously using is immediately - /// available after this function is called. If the - /// socket is not bound to a port, this function has no effect. + /// The port that the socket was previously bound to is immediately + /// made available to the operating system after this function is called. + /// This means that a subsequent call to bind() will be able to re-bind + /// the port if no other process has done so in the mean time. + /// If the socket is not bound to a port, this function has no effect. /// /// \see bind /// diff --git a/include/SFML/OpenGL.hpp b/include/SFML/OpenGL.hpp index a5d964f1..39e97b6d 100644 --- a/include/SFML/OpenGL.hpp +++ b/include/SFML/OpenGL.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -67,6 +67,9 @@ #include #include + + // We're not using OpenGL ES 2+ yet, but we can use the sRGB extension + #include #endif diff --git a/include/SFML/System.hpp b/include/SFML/System.hpp index 6af06527..5f18f766 100644 --- a/include/SFML/System.hpp +++ b/include/SFML/System.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Clock.hpp b/include/SFML/System/Clock.hpp index 684c6165..0e57d600 100644 --- a/include/SFML/System/Clock.hpp +++ b/include/SFML/System/Clock.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Err.hpp b/include/SFML/System/Err.hpp index 1c5b4684..56505a9d 100644 --- a/include/SFML/System/Err.hpp +++ b/include/SFML/System/Err.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Export.hpp b/include/SFML/System/Export.hpp index f4adc10b..0387c2eb 100644 --- a/include/SFML/System/Export.hpp +++ b/include/SFML/System/Export.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/FileInputStream.hpp b/include/SFML/System/FileInputStream.hpp index 86f572c3..b1a8c62c 100644 --- a/include/SFML/System/FileInputStream.hpp +++ b/include/SFML/System/FileInputStream.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/InputStream.hpp b/include/SFML/System/InputStream.hpp index e5694fae..4419a0b2 100644 --- a/include/SFML/System/InputStream.hpp +++ b/include/SFML/System/InputStream.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Lock.hpp b/include/SFML/System/Lock.hpp index 05dac108..eb420a8e 100644 --- a/include/SFML/System/Lock.hpp +++ b/include/SFML/System/Lock.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/MemoryInputStream.hpp b/include/SFML/System/MemoryInputStream.hpp index 4b7414b7..c26f823d 100644 --- a/include/SFML/System/MemoryInputStream.hpp +++ b/include/SFML/System/MemoryInputStream.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Mutex.hpp b/include/SFML/System/Mutex.hpp index 67a8473c..18349e42 100644 --- a/include/SFML/System/Mutex.hpp +++ b/include/SFML/System/Mutex.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/NativeActivity.hpp b/include/SFML/System/NativeActivity.hpp index 06d0a082..79276205 100644 --- a/include/SFML/System/NativeActivity.hpp +++ b/include/SFML/System/NativeActivity.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/NonCopyable.hpp b/include/SFML/System/NonCopyable.hpp index 9eb291c4..71476388 100644 --- a/include/SFML/System/NonCopyable.hpp +++ b/include/SFML/System/NonCopyable.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -51,6 +51,16 @@ class SFML_SYSTEM_API NonCopyable /// //////////////////////////////////////////////////////////// NonCopyable() {} + + //////////////////////////////////////////////////////////// + /// \brief Default destructor + /// + /// By declaring a protected destructor it's impossible to + /// call delete on a pointer of sf::NonCopyable, thus + /// preventing possible resource leaks. + /// + //////////////////////////////////////////////////////////// + ~NonCopyable() {} private: diff --git a/include/SFML/System/Sleep.hpp b/include/SFML/System/Sleep.hpp index 3c0d04a7..e943aa1a 100644 --- a/include/SFML/System/Sleep.hpp +++ b/include/SFML/System/Sleep.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index 0a54628d..8b0da3f0 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/String.inl b/include/SFML/System/String.inl index 2b22efac..1be1266a 100644 --- a/include/SFML/System/String.inl +++ b/include/SFML/System/String.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Thread.hpp b/include/SFML/System/Thread.hpp index 33216158..65c91271 100644 --- a/include/SFML/System/Thread.hpp +++ b/include/SFML/System/Thread.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Thread.inl b/include/SFML/System/Thread.inl index 8e0236fb..b707aa30 100644 --- a/include/SFML/System/Thread.inl +++ b/include/SFML/System/Thread.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/ThreadLocal.hpp b/include/SFML/System/ThreadLocal.hpp index d1f9e4f8..6975e524 100644 --- a/include/SFML/System/ThreadLocal.hpp +++ b/include/SFML/System/ThreadLocal.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/ThreadLocalPtr.hpp b/include/SFML/System/ThreadLocalPtr.hpp index 3ee7abf0..751a9b53 100644 --- a/include/SFML/System/ThreadLocalPtr.hpp +++ b/include/SFML/System/ThreadLocalPtr.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/ThreadLocalPtr.inl b/include/SFML/System/ThreadLocalPtr.inl index 1d735bf3..5652f56e 100644 --- a/include/SFML/System/ThreadLocalPtr.inl +++ b/include/SFML/System/ThreadLocalPtr.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index 95a0a353..4dff9283 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Utf.hpp b/include/SFML/System/Utf.hpp index 9e9d1530..819d8ff5 100644 --- a/include/SFML/System/Utf.hpp +++ b/include/SFML/System/Utf.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index 801ebf57..6ffceda6 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Vector2.hpp b/include/SFML/System/Vector2.hpp index 62840268..d5e17446 100644 --- a/include/SFML/System/Vector2.hpp +++ b/include/SFML/System/Vector2.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Vector2.inl b/include/SFML/System/Vector2.inl index 5cc67ca7..081b211c 100644 --- a/include/SFML/System/Vector2.inl +++ b/include/SFML/System/Vector2.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Vector3.hpp b/include/SFML/System/Vector3.hpp index 51704b8c..61d0dc78 100644 --- a/include/SFML/System/Vector3.hpp +++ b/include/SFML/System/Vector3.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/System/Vector3.inl b/include/SFML/System/Vector3.inl index 3c69f2c7..2f5eea8e 100644 --- a/include/SFML/System/Vector3.inl +++ b/include/SFML/System/Vector3.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window.hpp b/include/SFML/Window.hpp index 103f8882..eefe2678 100644 --- a/include/SFML/Window.hpp +++ b/include/SFML/Window.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Context.hpp b/include/SFML/Window/Context.hpp index e8920c1d..9e1eedd4 100644 --- a/include/SFML/Window/Context.hpp +++ b/include/SFML/Window/Context.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/ContextSettings.hpp b/include/SFML/Window/ContextSettings.hpp index 66375a4f..27743029 100644 --- a/include/SFML/Window/ContextSettings.hpp +++ b/include/SFML/Window/ContextSettings.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index 5fc9a101..7bfd610f 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Export.hpp b/include/SFML/Window/Export.hpp index 4a708ecd..a890beec 100644 --- a/include/SFML/Window/Export.hpp +++ b/include/SFML/Window/Export.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/GlResource.hpp b/include/SFML/Window/GlResource.hpp index a341f64e..3b3e225c 100644 --- a/include/SFML/Window/GlResource.hpp +++ b/include/SFML/Window/GlResource.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -29,10 +29,14 @@ // Headers //////////////////////////////////////////////////////////// #include +#include namespace sf { + +class Context; + //////////////////////////////////////////////////////////// /// \brief Base class for classes that require an OpenGL context /// @@ -54,10 +58,24 @@ class SFML_WINDOW_API GlResource ~GlResource(); //////////////////////////////////////////////////////////// - /// \brief Make sure that a valid OpenGL context exists in the current thread + /// \brief RAII helper class to temporarily lock an available context for use /// //////////////////////////////////////////////////////////// - static void ensureGlContext(); + class SFML_WINDOW_API TransientContextLock : NonCopyable + { + public: + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + //////////////////////////////////////////////////////////// + TransientContextLock(); + + //////////////////////////////////////////////////////////// + /// \brief Destructor + /// + //////////////////////////////////////////////////////////// + ~TransientContextLock(); + }; }; } // namespace sf diff --git a/include/SFML/Window/Joystick.hpp b/include/SFML/Window/Joystick.hpp index 27f6291e..dda73699 100644 --- a/include/SFML/Window/Joystick.hpp +++ b/include/SFML/Window/Joystick.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Keyboard.hpp b/include/SFML/Window/Keyboard.hpp index b3186e93..b35c7a02 100644 --- a/include/SFML/Window/Keyboard.hpp +++ b/include/SFML/Window/Keyboard.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Mouse.hpp b/include/SFML/Window/Mouse.hpp index 0056f8ca..53d5281f 100644 --- a/include/SFML/Window/Mouse.hpp +++ b/include/SFML/Window/Mouse.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Sensor.hpp b/include/SFML/Window/Sensor.hpp index 6078881f..9bef9703 100644 --- a/include/SFML/Window/Sensor.hpp +++ b/include/SFML/Window/Sensor.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Touch.hpp b/include/SFML/Window/Touch.hpp index ae61c7ca..92c42df7 100644 --- a/include/SFML/Window/Touch.hpp +++ b/include/SFML/Window/Touch.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/VideoMode.hpp b/include/SFML/Window/VideoMode.hpp index 5eb268cd..fee45ae0 100644 --- a/include/SFML/Window/VideoMode.hpp +++ b/include/SFML/Window/VideoMode.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index 41fc0a9a..7135fdfe 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -348,6 +348,19 @@ class SFML_WINDOW_API Window : GlResource, NonCopyable //////////////////////////////////////////////////////////// void setMouseCursorVisible(bool visible); + //////////////////////////////////////////////////////////// + /// \brief Grab or release the mouse cursor + /// + /// If set, grabs the mouse cursor inside this window's client + /// area so it may no longer be moved outside its bounds. + /// Note that grabbing is only active while the window has + /// focus. + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + void setMouseCursorGrabbed(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// diff --git a/include/SFML/Window/WindowHandle.hpp b/include/SFML/Window/WindowHandle.hpp index 0f0f9ef7..bfb4dc50 100644 --- a/include/SFML/Window/WindowHandle.hpp +++ b/include/SFML/Window/WindowHandle.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/include/SFML/Window/WindowStyle.hpp b/include/SFML/Window/WindowStyle.hpp index b9253db1..8623d1f0 100644 --- a/include/SFML/Window/WindowStyle.hpp +++ b/include/SFML/Window/WindowStyle.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/license.md b/license.md new file mode 100644 index 00000000..ff07ad46 --- /dev/null +++ b/license.md @@ -0,0 +1,21 @@ +# SFML + +SFML - Copyright (C) 2007-2017 Laurent Gomila - laurent@sfml-dev.org + +This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + +## External libraries used by SFML + + * _OpenAL-Soft_ is under the LGPL license + * _libjpeg_ is public domain + * _stb_image_ and _stb_image_write_ are public domain + * _freetype_ is under the FreeType license or the GPL license + * _libogg_ is under the BSD license + * _libvorbis_ is under the BSD license + * _libflac_ is under the BSD license diff --git a/license.txt b/license.txt deleted file mode 100644 index 0d6e05fe..00000000 --- a/license.txt +++ /dev/null @@ -1,37 +0,0 @@ -SFML ----- - -SFML - Copyright (C) 2007-2015 Laurent Gomila - laurent@sfml-dev.org - -This software is provided 'as-is', without any express or -implied warranty. In no event will the authors be held -liable for any damages arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute -it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; - you must not claim that you wrote the original software. - If you use this software in a product, an acknowledgment - in the product documentation would be appreciated but - is not required. - -2. Altered source versions must be plainly marked as such, - and must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any - source distribution. - - - -External libraries used by SFML -------------------------------- - -* OpenAL-Soft is under the LGPL license -* libjpeg is public domain -* stb_image and stb_image_write are public domain -* freetype is under the FreeType license or the GPL license -* libogg is under the BSD license -* libvorbis is under the BSD license -* libflac is under the BSD license diff --git a/readme.md b/readme.md index 7d2ac24e..1cba5ca5 100644 --- a/readme.md +++ b/readme.md @@ -35,3 +35,42 @@ graphics and no need to be running X. More Info --------- Please consult the SFML readme for more info: [readme.txt][] +======= +![SFML logo](http://www.sfml-dev.org/images/logo.png) + +# SFML — Simple and Fast Multimedia Library + +SFML is a simple, fast, cross-platform and object-oriented multimedia API. It provides access to windowing, graphics, audio and network. It is written in C++, and has bindings for various languages such as C, .Net, Ruby, Python. + +## Authors + + - Laurent Gomila — main developer (laurent@sfml-dev.org) + - Marco Antognini — OS X developer (hiura@sfml-dev.org) + - Jonathan De Wachter — Android developer (dewachter.jonathan@gmail.com) + - Jan Haller (bromeon@sfml-dev.org) + - Stefan Schindler (tank@sfml-dev.org) + - Lukas Dürrenberger (eXpl0it3r@sfml-dev.org) + - binary1248 (binary1248@hotmail.com) + - Artur Moreira (artturmoreira@gmail.com) + - Mario Liebisch (mario@sfml-dev.org) + +## Download + +You can get the latest official release on [SFML's website](http://www.sfml-dev.org/download.php). You can also get the current development version from the [Git repository](https://github.com/SFML/SFML). + +## Install + +Follow the instructions of the [tutorials](http://www.sfml-dev.org/tutorials/), there is one for each platform/compiler that SFML supports. + +## Learn + +There are several places to learn SFML: + + * The [official tutorials](http://www.sfml-dev.org/tutorials/) + * The [online API documentation](http://www.sfml-dev.org/documentation/) + * The [community wiki](https://github.com/SFML/SFML/wiki/) + * The [community forum](http://en.sfml-dev.org/forums/) ([French](http://fr.sfml-dev.org/forums/)) + +## Contribute + +SFML is an open-source project, and it needs your help to go on growing and improving. If you want to get involved and suggest some additional features, file a bug report or submit a patch, please have a look at the [contribution guidelines](http://www.sfml-dev.org/contribute.php). diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 28beb60d..00000000 --- a/readme.txt +++ /dev/null @@ -1,44 +0,0 @@ -SFML - Simple and Fast Multimedia Library -========================================= - -SFML is a simple, fast, cross-platform and object-oriented multimedia API. It provides access to windowing, graphics, audio and network. -It is written in C++, and has bindings for various languages such as C, .Net, Ruby, Python. - -Authors -------- - -Laurent Gomila - main developer (laurent@sfml-dev.org) -Marco Antognini - OS X developer (hiura@sfml-dev.org) -Jonathan De Wachter - Android developer (dewachter.jonathan@gmail.com) -Jan Haller (bromeon@sfml-dev.org) -Stefan Schindler (tank@sfml-dev.org) -Lukas Dürrenberger (eXpl0it3r@sfml-dev.org) -binary1248 (binary1248@hotmail.com) -Artur Moreira (artturmoreira@gmail.com) -Mario Liebisch (mario@sfml-dev.org) - -Download --------- - -You can get the latest official release on SFML website (http://www.sfml-dev.org/download.php). -You can also get the current development version from the git repository (https://github.com/SFML/SFML). - -Install -------- - -Follow the instructions of the tutorials (http://www.sfml-dev.org/tutorials/), there is one for each platform/compiler that SFML supports. - -Learn ------ - -There are several places to learn SFML: -* The official tutorials (http://www.sfml-dev.org/tutorials/) -* The online API documentation (http://www.sfml-dev.org/documentation/) -* The community wiki (https://github.com/SFML/SFML/wiki/) -* The community forum (http://en.sfml-dev.org/forums/) (or http://fr.sfml-dev.org/forums/ for French people) - -Contribute ----------- - -SFML is an open-source project, and it needs your help to go on growing and improving. -If you want to get involved and suggest some additional features, file a bug report or submit a patch, please have a look at the contribution guidelines (http://www.sfml-dev.org/contribute.php). diff --git a/src/SFML/Audio/ALCheck.cpp b/src/SFML/Audio/ALCheck.cpp index 3bb8e288..e3b7bb6b 100644 --- a/src/SFML/Audio/ALCheck.cpp +++ b/src/SFML/Audio/ALCheck.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/ALCheck.hpp b/src/SFML/Audio/ALCheck.hpp index 750af9ec..85f4e72d 100644 --- a/src/SFML/Audio/ALCheck.hpp +++ b/src/SFML/Audio/ALCheck.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/AlResource.cpp b/src/SFML/Audio/AlResource.cpp index 8ea92477..df50be0a 100644 --- a/src/SFML/Audio/AlResource.cpp +++ b/src/SFML/Audio/AlResource.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/AudioDevice.cpp b/src/SFML/Audio/AudioDevice.cpp index e2005e8f..4a2c55f0 100644 --- a/src/SFML/Audio/AudioDevice.cpp +++ b/src/SFML/Audio/AudioDevice.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/AudioDevice.hpp b/src/SFML/Audio/AudioDevice.hpp index 74edb180..9d3f6e8d 100644 --- a/src/SFML/Audio/AudioDevice.hpp +++ b/src/SFML/Audio/AudioDevice.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/InputSoundFile.cpp b/src/SFML/Audio/InputSoundFile.cpp index ede0f478..43a3388f 100644 --- a/src/SFML/Audio/InputSoundFile.cpp +++ b/src/SFML/Audio/InputSoundFile.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -41,6 +41,7 @@ InputSoundFile::InputSoundFile() : m_reader (NULL), m_stream (NULL), m_streamOwned (false), +m_sampleOffset (0), m_sampleCount (0), m_channelCount(0), m_sampleRate (0) @@ -195,15 +196,42 @@ unsigned int InputSoundFile::getSampleRate() const //////////////////////////////////////////////////////////// Time InputSoundFile::getDuration() const { + // Make sure we don't divide by 0 + if (m_channelCount == 0 || m_sampleRate == 0) + return Time::Zero; + return seconds(static_cast(m_sampleCount) / m_channelCount / m_sampleRate); } +//////////////////////////////////////////////////////////// +Time InputSoundFile::getTimeOffset() const +{ + // Make sure we don't divide by 0 + if (m_channelCount == 0 || m_sampleRate == 0) + return Time::Zero; + + return seconds(static_cast(m_sampleOffset) / m_channelCount / m_sampleRate); +} + + +//////////////////////////////////////////////////////////// +Uint64 InputSoundFile::getSampleOffset() const +{ + return m_sampleOffset; +} + + //////////////////////////////////////////////////////////// void InputSoundFile::seek(Uint64 sampleOffset) { if (m_reader) - m_reader->seek(sampleOffset); + { + // The reader handles an overrun gracefully, but we + // pre-check to keep our known position consistent + m_sampleOffset = std::min(sampleOffset, m_sampleCount); + m_reader->seek(m_sampleOffset); + } } @@ -217,10 +245,11 @@ void InputSoundFile::seek(Time timeOffset) //////////////////////////////////////////////////////////// Uint64 InputSoundFile::read(Int16* samples, Uint64 maxCount) { + Uint64 readSamples = 0; if (m_reader && samples && maxCount) - return m_reader->read(samples, maxCount); - else - return 0; + readSamples = m_reader->read(samples, maxCount); + m_sampleOffset += readSamples; + return readSamples; } @@ -238,6 +267,7 @@ void InputSoundFile::close() m_streamOwned = false; } m_stream = NULL; + m_sampleOffset = 0; // Reset the sound file attributes m_sampleCount = 0; diff --git a/src/SFML/Audio/Listener.cpp b/src/SFML/Audio/Listener.cpp index b173d5ed..23e0aafd 100644 --- a/src/SFML/Audio/Listener.cpp +++ b/src/SFML/Audio/Listener.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 7bf91d94..e959cea8 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -36,8 +36,7 @@ namespace sf { //////////////////////////////////////////////////////////// Music::Music() : -m_file (), -m_duration() +m_file () { } @@ -105,7 +104,7 @@ bool Music::openFromStream(InputStream& stream) //////////////////////////////////////////////////////////// Time Music::getDuration() const { - return m_duration; + return m_file.getDuration(); } @@ -118,8 +117,8 @@ bool Music::onGetData(SoundStream::Chunk& data) data.samples = &m_samples[0]; data.sampleCount = static_cast(m_file.read(&m_samples[0], m_samples.size())); - // Check if we have reached the end of the audio file - return data.sampleCount == m_samples.size(); + // Check if we have stopped obtaining samples or reached the end of the audio file + return (data.sampleCount != 0) && (m_file.getSampleOffset() < m_file.getSampleCount()); } @@ -135,9 +134,6 @@ void Music::onSeek(Time timeOffset) //////////////////////////////////////////////////////////// void Music::initialize() { - // Compute the music duration - m_duration = m_file.getDuration(); - // Resize the internal buffer so that it can contain 1 second of audio samples m_samples.resize(m_file.getSampleRate() * m_file.getChannelCount()); diff --git a/src/SFML/Audio/OutputSoundFile.cpp b/src/SFML/Audio/OutputSoundFile.cpp index 8f43ca76..870e622e 100644 --- a/src/SFML/Audio/OutputSoundFile.cpp +++ b/src/SFML/Audio/OutputSoundFile.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/Sound.cpp b/src/SFML/Audio/Sound.cpp index 52a1c63a..8ebaa038 100644 --- a/src/SFML/Audio/Sound.cpp +++ b/src/SFML/Audio/Sound.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index a6ff7ea5..c9842048 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundBufferRecorder.cpp b/src/SFML/Audio/SoundBufferRecorder.cpp index e09c4ffc..105b45b6 100644 --- a/src/SFML/Audio/SoundBufferRecorder.cpp +++ b/src/SFML/Audio/SoundBufferRecorder.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -63,7 +63,7 @@ bool SoundBufferRecorder::onProcessSamples(const Int16* samples, std::size_t sam void SoundBufferRecorder::onStop() { if (!m_samples.empty()) - m_buffer.loadFromSamples(&m_samples[0], m_samples.size(), 1, getSampleRate()); + m_buffer.loadFromSamples(&m_samples[0], m_samples.size(), getChannelCount(), getSampleRate()); } diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index fa2811c8..10b1c1e1 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileReaderFlac.cpp b/src/SFML/Audio/SoundFileReaderFlac.cpp index bba45360..00794b66 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.cpp +++ b/src/SFML/Audio/SoundFileReaderFlac.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -107,10 +107,6 @@ namespace { sf::priv::SoundFileReaderFlac::ClientData* data = static_cast(clientData); - // If there's no output buffer, it means that we are seeking - if (!data->buffer) - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - // Reserve memory if we're going to use the leftovers buffer unsigned int frameSamples = frame->header.blocksize * frame->header.channels; if (data->remaining < frameSamples) @@ -142,15 +138,16 @@ namespace break; } - if (data->remaining > 0) + if (data->buffer && data->remaining > 0) { - // There's room in the output buffer, copy the sample there + // If there's room in the output buffer, copy the sample there *data->buffer++ = sample; data->remaining--; } else { - // We have decoded all the requested samples, put the sample in a temporary buffer until next call + // We are either seeking (null buffer) or have decoded all the requested samples during a + // normal read (0 remaining), so we put the sample in a temporary buffer until next call data->leftovers.push_back(sample); } } @@ -210,8 +207,7 @@ bool SoundFileReaderFlac::check(InputStream& stream) //////////////////////////////////////////////////////////// SoundFileReaderFlac::SoundFileReaderFlac() : m_decoder(NULL), -m_clientData(), -m_channelCount(0) +m_clientData() { } @@ -249,9 +245,6 @@ bool SoundFileReaderFlac::open(InputStream& stream, Info& info) // Retrieve the sound properties info = m_clientData.info; // was filled in the "metadata" callback - // We must keep the channel count for the seek function - m_channelCount = info.channelCount; - return true; } @@ -267,7 +260,21 @@ void SoundFileReaderFlac::seek(Uint64 sampleOffset) m_clientData.leftovers.clear(); // FLAC decoder expects absolute sample offset, so we take the channel count out - FLAC__stream_decoder_seek_absolute(m_decoder, sampleOffset / m_channelCount); + if (sampleOffset < m_clientData.info.sampleCount) + { + // The "write" callback will populate the leftovers buffer with the first batch of samples from the + // seek destination, and since we want that data in this typical case, we don't re-clear it afterward + FLAC__stream_decoder_seek_absolute(m_decoder, sampleOffset / m_clientData.info.channelCount); + } + else + { + // FLAC decoder can't skip straight to EOF, so we short-seek by one sample and skip the rest + FLAC__stream_decoder_seek_absolute(m_decoder, (m_clientData.info.sampleCount / m_clientData.info.channelCount) - 1); + FLAC__stream_decoder_skip_single_frame(m_decoder); + + // This was re-populated during the seek, but we're skipping everything in this, so we need it emptied + m_clientData.leftovers.clear(); + } } @@ -283,7 +290,7 @@ Uint64 SoundFileReaderFlac::read(Int16* samples, Uint64 maxCount) if (left > maxCount) { // There are more leftovers than needed - std::copy(m_clientData.leftovers.begin(), m_clientData.leftovers.end(), samples); + std::copy(m_clientData.leftovers.begin(), m_clientData.leftovers.begin() + maxCount, samples); std::vector leftovers(m_clientData.leftovers.begin() + maxCount, m_clientData.leftovers.end()); m_clientData.leftovers.swap(leftovers); return maxCount; diff --git a/src/SFML/Audio/SoundFileReaderFlac.hpp b/src/SFML/Audio/SoundFileReaderFlac.hpp index f1dec1fb..bde8a197 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.hpp +++ b/src/SFML/Audio/SoundFileReaderFlac.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -131,9 +131,8 @@ class SoundFileReaderFlac : public SoundFileReader //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - FLAC__StreamDecoder* m_decoder; ///< FLAC decoder - ClientData m_clientData; ///< Structure passed to the decoder callbacks - unsigned int m_channelCount; ///< number of channels of the sound file + FLAC__StreamDecoder* m_decoder; ///< FLAC decoder + ClientData m_clientData; ///< Structure passed to the decoder callbacks }; } // namespace priv diff --git a/src/SFML/Audio/SoundFileReaderOgg.cpp b/src/SFML/Audio/SoundFileReaderOgg.cpp index d9f86281..df46193e 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.cpp +++ b/src/SFML/Audio/SoundFileReaderOgg.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileReaderOgg.hpp b/src/SFML/Audio/SoundFileReaderOgg.hpp index 087f9811..b1bf2529 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.hpp +++ b/src/SFML/Audio/SoundFileReaderOgg.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileReaderWav.cpp b/src/SFML/Audio/SoundFileReaderWav.cpp index 6706bc45..6f4a7779 100644 --- a/src/SFML/Audio/SoundFileReaderWav.cpp +++ b/src/SFML/Audio/SoundFileReaderWav.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileReaderWav.hpp b/src/SFML/Audio/SoundFileReaderWav.hpp index 16c7611c..904408b2 100644 --- a/src/SFML/Audio/SoundFileReaderWav.hpp +++ b/src/SFML/Audio/SoundFileReaderWav.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileWriterFlac.cpp b/src/SFML/Audio/SoundFileWriterFlac.cpp index 52368969..b12088b0 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.cpp +++ b/src/SFML/Audio/SoundFileWriterFlac.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileWriterFlac.hpp b/src/SFML/Audio/SoundFileWriterFlac.hpp index 49465641..39f50dbb 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.hpp +++ b/src/SFML/Audio/SoundFileWriterFlac.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index 44094be1..c661b746 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileWriterOgg.hpp b/src/SFML/Audio/SoundFileWriterOgg.hpp index bac570d7..868464a4 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.hpp +++ b/src/SFML/Audio/SoundFileWriterOgg.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileWriterWav.cpp b/src/SFML/Audio/SoundFileWriterWav.cpp index e7f977d5..1b48fe5d 100644 --- a/src/SFML/Audio/SoundFileWriterWav.cpp +++ b/src/SFML/Audio/SoundFileWriterWav.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundFileWriterWav.hpp b/src/SFML/Audio/SoundFileWriterWav.hpp index d96b4d39..b37a970c 100644 --- a/src/SFML/Audio/SoundFileWriterWav.hpp +++ b/src/SFML/Audio/SoundFileWriterWav.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 510495b0..7105fbdf 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -51,7 +51,8 @@ m_thread (&SoundRecorder::record, this), m_sampleRate (0), m_processingInterval(milliseconds(100)), m_isCapturing (false), -m_deviceName (getDefaultDevice()) +m_deviceName (getDefaultDevice()), +m_channelCount (1) { } @@ -86,8 +87,11 @@ bool SoundRecorder::start(unsigned int sampleRate) return false; } - // Open the capture device for capturing 16 bits mono samples - captureDevice = alcCaptureOpenDevice(m_deviceName.c_str(), sampleRate, AL_FORMAT_MONO16, sampleRate); + // Determine the recording format + ALCenum format = (m_channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; + + // Open the capture device for capturing 16 bits samples + captureDevice = alcCaptureOpenDevice(m_deviceName.c_str(), sampleRate, format, sampleRate); if (!captureDevice) { err() << "Failed to open the audio capture device with the name: " << m_deviceName << std::endl; @@ -180,8 +184,11 @@ bool SoundRecorder::setDevice(const std::string& name) m_isCapturing = false; m_thread.wait(); - // Open the requested capture device for capturing 16 bits mono samples - captureDevice = alcCaptureOpenDevice(name.c_str(), m_sampleRate, AL_FORMAT_MONO16, m_sampleRate); + // Determine the recording format + ALCenum format = (m_channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; + + // Open the requested capture device for capturing 16 bits samples + captureDevice = alcCaptureOpenDevice(name.c_str(), m_sampleRate, format, m_sampleRate); if (!captureDevice) { // Notify derived class @@ -210,6 +217,32 @@ const std::string& SoundRecorder::getDevice() const } +//////////////////////////////////////////////////////////// +void SoundRecorder::setChannelCount(unsigned int channelCount) +{ + if (m_isCapturing) + { + err() << "It's not possible to change the channels while recording." << std::endl; + return; + } + + if (channelCount < 1 || channelCount > 2) + { + err() << "Unsupported channel count: " << channelCount << " Currently only mono (1) and stereo (2) recording is supported." << std::endl; + return; + } + + m_channelCount = channelCount; +} + + +//////////////////////////////////////////////////////////// +unsigned int SoundRecorder::getChannelCount() const +{ + return m_channelCount; +} + + //////////////////////////////////////////////////////////// bool SoundRecorder::isAvailable() { @@ -267,7 +300,7 @@ void SoundRecorder::processCapturedSamples() if (samplesAvailable > 0) { // Get the recorded samples - m_samples.resize(samplesAvailable); + m_samples.resize(samplesAvailable * getChannelCount()); alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable); // Forward them to the derived class diff --git a/src/SFML/Audio/SoundSource.cpp b/src/SFML/Audio/SoundSource.cpp index 45498ec1..b2b4059d 100644 --- a/src/SFML/Audio/SoundSource.cpp +++ b/src/SFML/Audio/SoundSource.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 00258ccf..baefc097 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -77,7 +77,9 @@ SoundStream::~SoundStream() void SoundStream::initialize(unsigned int channelCount, unsigned int sampleRate) { m_channelCount = channelCount; - m_sampleRate = sampleRate; + m_sampleRate = sampleRate; + m_samplesProcessed = 0; + m_isStreaming = false; // Deduce the format from the number of channels m_format = priv::AudioDevice::getFormatFromChannelCount(channelCount); @@ -127,11 +129,7 @@ void SoundStream::play() stop(); } - // Move to the beginning - onSeek(Time::Zero); - // Start updating the stream in a separate thread to avoid blocking the application - m_samplesProcessed = 0; m_isStreaming = true; m_threadStartState = Playing; m_thread.launch(); @@ -397,34 +395,41 @@ void SoundStream::streamData() //////////////////////////////////////////////////////////// -bool SoundStream::fillAndPushBuffer(unsigned int bufferNum) +bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop) { bool requestStop = false; - // Acquire audio data + // Acquire audio data, also address EOF and error cases if they occur Chunk data = {NULL, 0}; - if (!onGetData(data)) + for (Uint32 retryCount = 0; !onGetData(data) && (retryCount < BufferRetries); ++retryCount) { // Mark the buffer as the last one (so that we know when to reset the playing position) m_endBuffers[bufferNum] = true; // Check if the stream must loop or stop - if (m_loop) - { - // Return to the beginning of the stream source - onSeek(Time::Zero); - - // If we previously had no data, try to fill the buffer once again - if (!data.samples || (data.sampleCount == 0)) - { - return fillAndPushBuffer(bufferNum); - } - } - else + if (!m_loop) { // Not looping: request stop requestStop = true; + break; } + + // Return to the beginning of the stream source + onSeek(Time::Zero); + + // If we got data, break and process it, else try to fill the buffer once again + if (data.samples && data.sampleCount) + break; + + // If immediateLoop is specified, we have to immediately adjust the sample count + if (immediateLoop) + { + // We just tried to begin preloading at EOF: reset the sample count + m_samplesProcessed = 0; + m_endBuffers[bufferNum] = false; + } + + // We're a looping sound that got no data, so we retry onGetData() } // Fill the buffer if some data was returned @@ -439,6 +444,11 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum) // Push it into the sound queue alCheck(alSourceQueueBuffers(m_source, 1, &buffer)); } + else + { + // If we get here, we most likely ran out of retries + requestStop = true; + } return requestStop; } @@ -451,7 +461,9 @@ bool SoundStream::fillQueue() bool requestStop = false; for (int i = 0; (i < BufferCount) && !requestStop; ++i) { - if (fillAndPushBuffer(i)) + // Since no sound has been loaded yet, we can't schedule loop seeks preemptively, + // So if we start on EOF or Loop End, we let fillAndPushBuffer() adjust the sample count + if (fillAndPushBuffer(i, (i == 0))) requestStop = true; } diff --git a/src/SFML/CMakeLists.txt b/src/SFML/CMakeLists.txt index 8eb334d9..61be9ae6 100644 --- a/src/SFML/CMakeLists.txt +++ b/src/SFML/CMakeLists.txt @@ -49,11 +49,31 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib") # add the modules subdirectories + +# sfml-system add_subdirectory(System) + +# sfml-main and sfml-activity if(SFML_OS_WINDOWS OR SFML_OS_ANDROID OR SFML_OS_IOS) add_subdirectory(Main) endif() -add_subdirectory(Window) -add_subdirectory(Network) -add_subdirectory(Graphics) -add_subdirectory(Audio) + +# sfml-window +if(SFML_BUILD_WINDOW OR SFML_BUILD_GRAPHICS) + add_subdirectory(Window) +endif() + +# sfml-network +if(SFML_BUILD_NETWORK) + add_subdirectory(Network) +endif() + +# sfml-graphics +if(SFML_BUILD_GRAPHICS) + add_subdirectory(Graphics) +endif() + +# sfml-audio +if(SFML_BUILD_AUDIO) + add_subdirectory(Audio) +endif() diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp index a9fb0856..ab69dcd3 100644 --- a/src/SFML/Graphics/BlendMode.cpp +++ b/src/SFML/Graphics/BlendMode.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index 24bd9d37..8e555105 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Color.cpp b/src/SFML/Graphics/Color.cpp index 0bcd5024..fdadb41a 100644 --- a/src/SFML/Graphics/Color.cpp +++ b/src/SFML/Graphics/Color.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/ConvexShape.cpp b/src/SFML/Graphics/ConvexShape.cpp index f605647f..35ff1352 100644 --- a/src/SFML/Graphics/ConvexShape.cpp +++ b/src/SFML/Graphics/ConvexShape.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index f6ab15d4..0ab41b9b 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -151,19 +151,21 @@ bool Font::loadFromFile(const std::string& filename) if (FT_Stroker_New(static_cast(m_library), &stroker) != 0) { err() << "Failed to load font \"" << filename << "\" (failed to create the stroker)" << std::endl; + FT_Done_Face(face); return false; } - m_stroker = stroker; // Select the unicode character map if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl; + FT_Stroker_Done(stroker); FT_Done_Face(face); return false; } // Store the loaded font in our ugly void* :) + m_stroker = stroker; m_face = face; // Store the font information @@ -214,19 +216,21 @@ bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes) if (FT_Stroker_New(static_cast(m_library), &stroker) != 0) { err() << "Failed to load font from memory (failed to create the stroker)" << std::endl; + FT_Done_Face(face); return false; } - m_stroker = stroker; // Select the Unicode character map if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { err() << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl; + FT_Stroker_Done(stroker); FT_Done_Face(face); return false; } // Store the loaded font in our ugly void* :) + m_stroker = stroker; m_face = face; // Store the font information @@ -287,20 +291,23 @@ bool Font::loadFromStream(InputStream& stream) if (FT_Stroker_New(static_cast(m_library), &stroker) != 0) { err() << "Failed to load font from stream (failed to create the stroker)" << std::endl; + FT_Done_Face(face); + delete rec; return false; } - m_stroker = stroker; // Select the Unicode character map if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { err() << "Failed to load font from stream (failed to set the Unicode character set)" << std::endl; FT_Done_Face(face); + FT_Stroker_Done(stroker); delete rec; return false; } // Store the loaded font in our ugly void* :) + m_stroker = stroker; m_face = face; m_streamRec = rec; @@ -504,7 +511,7 @@ void Font::cleanup() m_streamRec = NULL; m_refCount = NULL; m_pages.clear(); - m_pixelBuffer.clear(); + std::vector().swap(m_pixelBuffer); } @@ -583,11 +590,14 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f // pollute them with pixels from neighbors const unsigned int padding = 1; + width += 2 * padding; + height += 2 * padding; + // Get the glyphs page corresponding to the character size Page& page = m_pages[characterSize]; // Find a good position for the new glyph into the texture - glyph.textureRect = findGlyphRect(page, width + 2 * padding, height + 2 * padding); + glyph.textureRect = findGlyphRect(page, width, height); // Make sure the texture data is positioned in the center // of the allocated texture rectangle @@ -602,19 +612,32 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f glyph.bounds.width = static_cast(face->glyph->metrics.width) / static_cast(1 << 6) + outlineThickness * 2; glyph.bounds.height = static_cast(face->glyph->metrics.height) / static_cast(1 << 6) + outlineThickness * 2; + // Resize the pixel buffer to the new size and fill it with transparent white pixels + m_pixelBuffer.resize(width * height * 4); + + Uint8* current = &m_pixelBuffer[0]; + Uint8* end = current + width * height * 4; + + while (current != end) + { + (*current++) = 255; + (*current++) = 255; + (*current++) = 255; + (*current++) = 0; + } + // Extract the glyph's pixels from the bitmap - m_pixelBuffer.resize(width * height * 4, 255); const Uint8* pixels = bitmap.buffer; if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { // Pixels are 1 bit monochrome values - for (int y = 0; y < height; ++y) + for (int y = padding; y < height - padding; ++y) { - for (int x = 0; x < width; ++x) + for (int x = padding; x < width - padding; ++x) { // The color channels remain white, just fill the alpha channel - std::size_t index = (x + y * width) * 4 + 3; - m_pixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0; + std::size_t index = x + y * width; + m_pixelBuffer[index * 4 + 3] = ((pixels[(x - padding) / 8]) & (1 << (7 - ((x - padding) % 8)))) ? 255 : 0; } pixels += bitmap.pitch; } @@ -622,33 +645,29 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f else { // Pixels are 8 bits gray levels - for (int y = 0; y < height; ++y) + for (int y = padding; y < height - padding; ++y) { - for (int x = 0; x < width; ++x) + for (int x = padding; x < width - padding; ++x) { // The color channels remain white, just fill the alpha channel - std::size_t index = (x + y * width) * 4 + 3; - m_pixelBuffer[index] = pixels[x]; + std::size_t index = x + y * width; + m_pixelBuffer[index * 4 + 3] = pixels[x - padding]; } pixels += bitmap.pitch; } } // Write the pixels to the texture - unsigned int x = glyph.textureRect.left; - unsigned int y = glyph.textureRect.top; - unsigned int w = glyph.textureRect.width; - unsigned int h = glyph.textureRect.height; + unsigned int x = glyph.textureRect.left - padding; + unsigned int y = glyph.textureRect.top - padding; + unsigned int w = glyph.textureRect.width + 2 * padding; + unsigned int h = glyph.textureRect.height + 2 * padding; page.texture.update(&m_pixelBuffer[0], w, h, x, y); } // Delete the FT glyph FT_Done_Glyph(glyphDesc); - // Force an OpenGL flush, so that the font's texture will appear updated - // in all contexts immediately (solves problems in multi-threaded apps) - glCheck(glFlush()); - // Done :) return glyph; } @@ -693,10 +712,10 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) if ((textureWidth * 2 <= Texture::getMaximumSize()) && (textureHeight * 2 <= Texture::getMaximumSize())) { // Make the texture 2 times bigger - Image newImage; - newImage.create(textureWidth * 2, textureHeight * 2, Color(255, 255, 255, 0)); - newImage.copy(page.texture.copyToImage(), 0, 0); - page.texture.loadFromImage(newImage); + Texture newTexture; + newTexture.create(textureWidth * 2, textureHeight * 2); + newTexture.update(page.texture); + page.texture.swap(newTexture); } else { diff --git a/src/SFML/Graphics/GLCheck.cpp b/src/SFML/Graphics/GLCheck.cpp index 2a706cd8..85d9854a 100644 --- a/src/SFML/Graphics/GLCheck.cpp +++ b/src/SFML/Graphics/GLCheck.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/GLCheck.hpp b/src/SFML/Graphics/GLCheck.hpp index 9b7db8b7..2b5fa7d0 100644 --- a/src/SFML/Graphics/GLCheck.hpp +++ b/src/SFML/Graphics/GLCheck.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/GLExtensions.cpp b/src/SFML/Graphics/GLExtensions.cpp index 3949ee3b..57f5bcc7 100644 --- a/src/SFML/Graphics/GLExtensions.cpp +++ b/src/SFML/Graphics/GLExtensions.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -29,6 +29,14 @@ #include #include +#if !defined(GL_MAJOR_VERSION) + #define GL_MAJOR_VERSION 0x821B +#endif + +#if !defined(GL_MINOR_VERSION) + #define GL_MINOR_VERSION 0x821C +#endif + namespace sf { @@ -41,22 +49,41 @@ void ensureExtensionsInit() static bool initialized = false; if (!initialized) { - const Context* context = Context::getActiveContext(); - - if (!context) - return; + initialized = true; sfogl_LoadFunctions(); - ContextSettings settings = context->getSettings(); + // Retrieve the context version number + int majorVersion = 0; + int minorVersion = 0; - if ((settings.majorVersion < 1) || ((settings.majorVersion == 1) && (settings.minorVersion < 1))) + // Try the new way first + glGetIntegerv(GL_MAJOR_VERSION, &majorVersion); + glGetIntegerv(GL_MINOR_VERSION, &minorVersion); + + if (glGetError() == GL_INVALID_ENUM) + { + // Try the old way + const GLubyte* version = glGetString(GL_VERSION); + if (version) + { + // The beginning of the returned string is "major.minor" (this is standard) + majorVersion = version[0] - '0'; + minorVersion = version[2] - '0'; + } + else + { + // Can't get the version number, assume 1.1 + majorVersion = 1; + minorVersion = 1; + } + } + + if ((majorVersion < 1) || ((majorVersion == 1) && (minorVersion < 1))) { err() << "sfml-graphics requires support for OpenGL 1.1 or greater" << std::endl; err() << "Ensure that hardware acceleration is enabled if available" << std::endl; } - - initialized = true; } #endif } diff --git a/src/SFML/Graphics/GLExtensions.hpp b/src/SFML/Graphics/GLExtensions.hpp index fdb6b20e..a8010245 100644 --- a/src/SFML/Graphics/GLExtensions.hpp +++ b/src/SFML/Graphics/GLExtensions.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -121,6 +121,7 @@ #define GLEXT_glCheckFramebufferStatus glCheckFramebufferStatusOES #define GLEXT_glFramebufferTexture2D glFramebufferTexture2DOES #define GLEXT_glFramebufferRenderbuffer glFramebufferRenderbufferOES + #define GLEXT_glGenerateMipmap glGenerateMipmapOES #define GLEXT_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES #define GLEXT_GL_RENDERBUFFER GL_RENDERBUFFER_OES #define GLEXT_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT16_OES @@ -130,9 +131,17 @@ #define GLEXT_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES #define GLEXT_GL_INVALID_FRAMEBUFFER_OPERATION GL_INVALID_FRAMEBUFFER_OPERATION_OES + // Core since 3.0 + #define GLEXT_framebuffer_blit false + // Core since 3.0 - EXT_sRGB - #define GLEXT_texture_sRGB GL_EXT_sRGB - #define GLEXT_GL_SRGB8_ALPHA8 GL_SRGB8_ALPHA8_EXT + #ifdef GL_EXT_sRGB + #define GLEXT_texture_sRGB GL_EXT_sRGB + #define GLEXT_GL_SRGB8_ALPHA8 GL_SRGB8_ALPHA8_EXT + #else + #define GLEXT_texture_sRGB false + #define GLEXT_GL_SRGB8_ALPHA8 0 + #endif #else @@ -248,6 +257,7 @@ #define GLEXT_glCheckFramebufferStatus glCheckFramebufferStatusEXT #define GLEXT_glFramebufferTexture2D glFramebufferTexture2DEXT #define GLEXT_glFramebufferRenderbuffer glFramebufferRenderbufferEXT + #define GLEXT_glGenerateMipmap glGenerateMipmapEXT #define GLEXT_GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT #define GLEXT_GL_RENDERBUFFER GL_RENDERBUFFER_EXT #define GLEXT_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT @@ -256,6 +266,14 @@ #define GLEXT_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_EXT #define GLEXT_GL_INVALID_FRAMEBUFFER_OPERATION GL_INVALID_FRAMEBUFFER_OPERATION_EXT + // Core since 3.0 - EXT_framebuffer_blit + #define GLEXT_framebuffer_blit sfogl_ext_EXT_framebuffer_blit + #define GLEXT_glBlitFramebuffer glBlitFramebufferEXT + #define GLEXT_GL_READ_FRAMEBUFFER GL_READ_FRAMEBUFFER_EXT + #define GLEXT_GL_DRAW_FRAMEBUFFER GL_DRAW_FRAMEBUFFER_EXT + #define GLEXT_GL_DRAW_FRAMEBUFFER_BINDING GL_DRAW_FRAMEBUFFER_BINDING_EXT + #define GLEXT_GL_READ_FRAMEBUFFER_BINDING GL_READ_FRAMEBUFFER_BINDING_EXT + // Core since 3.2 - ARB_geometry_shader4 #define GLEXT_geometry_shader4 sfogl_ext_ARB_geometry_shader4 #define GLEXT_GL_GEOMETRY_SHADER GL_GEOMETRY_SHADER_ARB diff --git a/src/SFML/Graphics/GLExtensions.txt b/src/SFML/Graphics/GLExtensions.txt index 5b620278..4b3ac662 100644 --- a/src/SFML/Graphics/GLExtensions.txt +++ b/src/SFML/Graphics/GLExtensions.txt @@ -15,4 +15,5 @@ ARB_texture_non_power_of_two EXT_blend_equation_separate EXT_texture_sRGB EXT_framebuffer_object +EXT_framebuffer_blit ARB_geometry_shader4 diff --git a/src/SFML/Graphics/GLLoader.cpp b/src/SFML/Graphics/GLLoader.cpp index 209520db..ec1531fb 100644 --- a/src/SFML/Graphics/GLLoader.cpp +++ b/src/SFML/Graphics/GLLoader.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -47,6 +47,7 @@ int sfogl_ext_ARB_texture_non_power_of_two = sfogl_LOAD_FAILED; int sfogl_ext_EXT_blend_equation_separate = sfogl_LOAD_FAILED; int sfogl_ext_EXT_texture_sRGB = sfogl_LOAD_FAILED; int sfogl_ext_EXT_framebuffer_object = sfogl_LOAD_FAILED; +int sfogl_ext_EXT_framebuffer_blit = sfogl_LOAD_FAILED; int sfogl_ext_ARB_geometry_shader4 = sfogl_LOAD_FAILED; void (GL_FUNCPTR *sf_ptrc_glBlendEquationEXT)(GLenum) = NULL; @@ -800,6 +801,19 @@ static int Load_EXT_framebuffer_object() return numFailed; } +void (GL_FUNCPTR *sf_ptrc_glBlitFramebufferEXT)(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum) = NULL; + +static int Load_EXT_framebuffer_blit() +{ + int numFailed = 0; + + sf_ptrc_glBlitFramebufferEXT = reinterpret_cast(glLoaderGetProcAddress("glBlitFramebufferEXT")); + if (!sf_ptrc_glBlitFramebufferEXT) + numFailed++; + + return numFailed; +} + void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureARB)(GLenum, GLenum, GLuint, GLint) = NULL; void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureFaceARB)(GLenum, GLenum, GLuint, GLint, GLenum) = NULL; void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureLayerARB)(GLenum, GLenum, GLuint, GLint, GLint) = NULL; @@ -836,7 +850,7 @@ typedef struct sfogl_StrToExtMap_s PFN_LOADFUNCPOINTERS LoadExtension; } sfogl_StrToExtMap; -static sfogl_StrToExtMap ExtensionMap[15] = { +static sfogl_StrToExtMap ExtensionMap[16] = { {"GL_SGIS_texture_edge_clamp", &sfogl_ext_SGIS_texture_edge_clamp, NULL}, {"GL_EXT_texture_edge_clamp", &sfogl_ext_EXT_texture_edge_clamp, NULL}, {"GL_EXT_blend_minmax", &sfogl_ext_EXT_blend_minmax, Load_EXT_blend_minmax}, @@ -851,10 +865,11 @@ static sfogl_StrToExtMap ExtensionMap[15] = { {"GL_EXT_blend_equation_separate", &sfogl_ext_EXT_blend_equation_separate, Load_EXT_blend_equation_separate}, {"GL_EXT_texture_sRGB", &sfogl_ext_EXT_texture_sRGB, NULL}, {"GL_EXT_framebuffer_object", &sfogl_ext_EXT_framebuffer_object, Load_EXT_framebuffer_object}, + {"GL_EXT_framebuffer_blit", &sfogl_ext_EXT_framebuffer_blit, Load_EXT_framebuffer_blit}, {"GL_ARB_geometry_shader4", &sfogl_ext_ARB_geometry_shader4, Load_ARB_geometry_shader4} }; -static int g_extensionMapSize = 15; +static int g_extensionMapSize = 16; static void ClearExtensionVars() @@ -873,6 +888,7 @@ static void ClearExtensionVars() sfogl_ext_EXT_blend_equation_separate = sfogl_LOAD_FAILED; sfogl_ext_EXT_texture_sRGB = sfogl_LOAD_FAILED; sfogl_ext_EXT_framebuffer_object = sfogl_LOAD_FAILED; + sfogl_ext_EXT_framebuffer_blit = sfogl_LOAD_FAILED; sfogl_ext_ARB_geometry_shader4 = sfogl_LOAD_FAILED; } diff --git a/src/SFML/Graphics/GLLoader.hpp b/src/SFML/Graphics/GLLoader.hpp index ac1bfdfc..a802808c 100644 --- a/src/SFML/Graphics/GLLoader.hpp +++ b/src/SFML/Graphics/GLLoader.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -184,6 +184,7 @@ extern int sfogl_ext_ARB_texture_non_power_of_two; extern int sfogl_ext_EXT_blend_equation_separate; extern int sfogl_ext_EXT_texture_sRGB; extern int sfogl_ext_EXT_framebuffer_object; +extern int sfogl_ext_EXT_framebuffer_blit; extern int sfogl_ext_ARB_geometry_shader4; #define GL_CLAMP_TO_EDGE_SGIS 0x812F @@ -379,6 +380,11 @@ extern int sfogl_ext_ARB_geometry_shader4; #define GL_STENCIL_INDEX4_EXT 0x8D47 #define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 + #define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 #define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9 @@ -1242,6 +1248,12 @@ extern void (GL_FUNCPTR *sf_ptrc_glRenderbufferStorageEXT)(GLenum, GLenum, GLsiz #define glRenderbufferStorageEXT sf_ptrc_glRenderbufferStorageEXT #endif // GL_EXT_framebuffer_object +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit 1 +extern void (GL_FUNCPTR *sf_ptrc_glBlitFramebufferEXT)(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); +#define glBlitFramebufferEXT sf_ptrc_glBlitFramebufferEXT +#endif // GL_EXT_framebuffer_blit + #ifndef GL_ARB_geometry_shader4 #define GL_ARB_geometry_shader4 1 extern void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureARB)(GLenum, GLenum, GLuint, GLint); diff --git a/src/SFML/Graphics/Glsl.cpp b/src/SFML/Graphics/Glsl.cpp index d9813316..c5d2b78a 100644 --- a/src/SFML/Graphics/Glsl.cpp +++ b/src/SFML/Graphics/Glsl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 08fc495e..8dae99b0 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -66,16 +66,12 @@ void Image::create(unsigned int width, unsigned int height, const Color& color) { if (width && height) { - // Assign the new size - m_size.x = width; - m_size.y = height; - - // Resize the pixel buffer - m_pixels.resize(width * height * 4); - + // Create a new pixel buffer first for exception safety's sake + std::vector newPixels(width * height * 4); + // Fill it with the specified color - Uint8* ptr = &m_pixels[0]; - Uint8* end = ptr + m_pixels.size(); + Uint8* ptr = &newPixels[0]; + Uint8* end = ptr + newPixels.size(); while (ptr < end) { *ptr++ = color.r; @@ -83,13 +79,22 @@ void Image::create(unsigned int width, unsigned int height, const Color& color) *ptr++ = color.b; *ptr++ = color.a; } + + // Commit the new pixel buffer + m_pixels.swap(newPixels); + + // Assign the new size + m_size.x = width; + m_size.y = height; } else { - // Create an empty image + // Dump the pixel buffer + std::vector().swap(m_pixels); + + // Assign the new size m_size.x = 0; m_size.y = 0; - m_pixels.clear(); } } @@ -99,21 +104,24 @@ void Image::create(unsigned int width, unsigned int height, const Uint8* pixels) { if (pixels && width && height) { + // Create a new pixel buffer first for exception safety's sake + std::vector newPixels(pixels, pixels + width * height * 4); + + // Commit the new pixel buffer + m_pixels.swap(newPixels); + // Assign the new size m_size.x = width; m_size.y = height; - - // Copy the pixels - std::size_t size = width * height * 4; - m_pixels.resize(size); - std::memcpy(&m_pixels[0], pixels, size); // faster than vector::assign } else { - // Create an empty image + // Dump the pixel buffer + std::vector().swap(m_pixels); + + // Assign the new size m_size.x = 0; m_size.y = 0; - m_pixels.clear(); } } diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 439ed0a4..15d50d98 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/ImageLoader.hpp b/src/SFML/Graphics/ImageLoader.hpp index 12e06991..adcd3d8b 100644 --- a/src/SFML/Graphics/ImageLoader.hpp +++ b/src/SFML/Graphics/ImageLoader.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RectangleShape.cpp b/src/SFML/Graphics/RectangleShape.cpp index 6fa4119f..abe11874 100644 --- a/src/SFML/Graphics/RectangleShape.cpp +++ b/src/SFML/Graphics/RectangleShape.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderStates.cpp b/src/SFML/Graphics/RenderStates.cpp index 3da5fb14..bc451031 100644 --- a/src/SFML/Graphics/RenderStates.cpp +++ b/src/SFML/Graphics/RenderStates.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index ded377c1..244ee302 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -98,7 +98,7 @@ RenderTarget::~RenderTarget() //////////////////////////////////////////////////////////// void RenderTarget::clear(const Color& color) { - if (activate(true)) + if (setActive(true)) { // Unbind texture to fix RenderTexture preventing clear applyTexture(NULL); @@ -214,7 +214,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, #define GL_QUADS 0 #endif - if (activate(true)) + if (setActive(true)) { // First set the persistent OpenGL states if it's the very first call if (!m_cache.glStatesSet) @@ -269,13 +269,25 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, vertices = NULL; } + // Check if texture coordinates array is needed, and update client state accordingly + bool enableTexCoordsArray = (states.texture || states.shader); + if (enableTexCoordsArray != m_cache.texCoordsArrayEnabled) + { + if (enableTexCoordsArray) + glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); + else + glCheck(glDisableClientState(GL_TEXTURE_COORD_ARRAY)); + m_cache.texCoordsArrayEnabled = enableTexCoordsArray; + } + // Setup the pointers to the vertices' components if (vertices) { const char* data = reinterpret_cast(vertices); glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)); glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)); - glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); + if (enableTexCoordsArray) + glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); } // Find the OpenGL primitive type @@ -304,7 +316,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, //////////////////////////////////////////////////////////// void RenderTarget::pushGLStates() { - if (activate(true)) + if (setActive(true)) { #ifdef SFML_DEBUG // make sure that the user didn't leave an unchecked OpenGL error @@ -336,7 +348,7 @@ void RenderTarget::pushGLStates() //////////////////////////////////////////////////////////// void RenderTarget::popGLStates() { - if (activate(true)) + if (setActive(true)) { glCheck(glMatrixMode(GL_PROJECTION)); glCheck(glPopMatrix()); @@ -358,7 +370,7 @@ void RenderTarget::resetGLStates() // Check here to make sure a context change does not happen after activate(true) bool shaderAvailable = Shader::isAvailable(); - if (activate(true)) + if (setActive(true)) { // Make sure that extensions are initialized priv::ensureExtensionsInit(); @@ -390,6 +402,8 @@ void RenderTarget::resetGLStates() if (shaderAvailable) applyShader(NULL); + m_cache.texCoordsArrayEnabled = true; + m_cache.useVertexCache = false; // Set the default view diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index 4602beb3..12e8edf6 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -116,6 +116,13 @@ bool RenderTexture::isRepeated() const } +//////////////////////////////////////////////////////////// +bool RenderTexture::generateMipmap() +{ + return m_texture.generateMipmap(); +} + + //////////////////////////////////////////////////////////// bool RenderTexture::setActive(bool active) { @@ -131,6 +138,7 @@ void RenderTexture::display() { m_impl->updateTexture(m_texture.m_texture); m_texture.m_pixelsFlipped = true; + m_texture.invalidateMipmap(); } } @@ -148,11 +156,4 @@ const Texture& RenderTexture::getTexture() const return m_texture; } - -//////////////////////////////////////////////////////////// -bool RenderTexture::activate(bool active) -{ - return setActive(active); -} - } // namespace sf diff --git a/src/SFML/Graphics/RenderTextureImpl.cpp b/src/SFML/Graphics/RenderTextureImpl.cpp index f69305bc..19023b37 100644 --- a/src/SFML/Graphics/RenderTextureImpl.cpp +++ b/src/SFML/Graphics/RenderTextureImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderTextureImpl.hpp b/src/SFML/Graphics/RenderTextureImpl.hpp index 87562e79..e2fece0e 100644 --- a/src/SFML/Graphics/RenderTextureImpl.hpp +++ b/src/SFML/Graphics/RenderTextureImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderTextureImplDefault.cpp b/src/SFML/Graphics/RenderTextureImplDefault.cpp index 3d1a9dd0..c52679dc 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.cpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderTextureImplDefault.hpp b/src/SFML/Graphics/RenderTextureImplDefault.hpp index 5c05a880..803b18f9 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.hpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index 94771690..58dcb464 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -48,7 +48,7 @@ m_depthBuffer(0) //////////////////////////////////////////////////////////// RenderTextureImplFBO::~RenderTextureImplFBO() { - ensureGlContext(); + m_context->setActive(true); // Destroy the depth buffer if (m_depthBuffer) @@ -72,7 +72,7 @@ RenderTextureImplFBO::~RenderTextureImplFBO() //////////////////////////////////////////////////////////// bool RenderTextureImplFBO::isAvailable() { - ensureGlContext(); + TransientContextLock lock; // Make sure that extensions are initialized priv::ensureExtensionsInit(); diff --git a/src/SFML/Graphics/RenderTextureImplFBO.hpp b/src/SFML/Graphics/RenderTextureImplFBO.hpp index cfbb53aa..c987281f 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.hpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index d5df65b8..672c8b55 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -62,16 +62,16 @@ RenderWindow::~RenderWindow() //////////////////////////////////////////////////////////// -bool RenderWindow::activate(bool active) +Vector2u RenderWindow::getSize() const { - return setActive(active); + return Window::getSize(); } //////////////////////////////////////////////////////////// -Vector2u RenderWindow::getSize() const +bool RenderWindow::setActive(bool active) { - return Window::getSize(); + return Window::setActive(active); } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index d8c9e68e..92b92dbf 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -56,7 +56,8 @@ namespace { - sf::Mutex mutex; + sf::Mutex maxTextureUnitsMutex; + sf::Mutex isAvailableMutex; GLint checkMaxTextureUnits() { @@ -70,7 +71,7 @@ namespace GLint getMaxTextureUnits() { // TODO: Remove this lock when it becomes unnecessary in C++11 - sf::Lock lock(mutex); + sf::Lock lock(maxTextureUnitsMutex); static GLint maxUnits = checkMaxTextureUnits(); @@ -116,53 +117,6 @@ namespace return success; } - bool checkShadersAvailable() - { - // Create a temporary context in case the user checks - // before a GlResource is created, thus initializing - // the shared context - if (!sf::Context::getActiveContext()) - { - sf::Context context; - - // Make sure that extensions are initialized - sf::priv::ensureExtensionsInit(); - - bool available = GLEXT_multitexture && - GLEXT_shading_language_100 && - GLEXT_shader_objects && - GLEXT_vertex_shader && - GLEXT_fragment_shader; - - return available; - } - - // Make sure that extensions are initialized - sf::priv::ensureExtensionsInit(); - - bool available = GLEXT_multitexture && - GLEXT_shading_language_100 && - GLEXT_shader_objects && - GLEXT_vertex_shader && - GLEXT_fragment_shader; - - return available; - } - bool checkGeometryShadersAvailable() - { - // Create a temporary context in case the user checks - // before a GlResource is created, thus initializing - // the shared context - sf::Context context; - - // Make sure that extensions are initialized - sf::priv::ensureExtensionsInit(); - - bool available = checkShadersAvailable() && GLEXT_geometry_shader4; - - return available; - } - // Transforms an array of 2D vectors into a contiguous array of scalars template std::vector flatten(const sf::Vector2* vectorArray, std::size_t length) @@ -236,8 +190,6 @@ struct Shader::UniformBinder : private NonCopyable { if (currentProgram) { - ensureGlContext(); - // Enable program object glCheck(savedProgram = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT)); if (currentProgram != savedProgram) @@ -259,9 +211,10 @@ struct Shader::UniformBinder : private NonCopyable glCheck(GLEXT_glUseProgramObject(savedProgram)); } - GLEXT_GLhandle savedProgram; ///< Handle to the previously active program object - GLEXT_GLhandle currentProgram; ///< Handle to the program object of the modified sf::Shader instance - GLint location; ///< Uniform location, used by the surrounding sf::Shader code + TransientContextLock lock; ///< Lock to keep context active while uniform is bound + GLEXT_GLhandle savedProgram; ///< Handle to the previously active program object + GLEXT_GLhandle currentProgram; ///< Handle to the program object of the modified sf::Shader instance + GLint location; ///< Uniform location, used by the surrounding sf::Shader code }; @@ -278,7 +231,7 @@ m_uniforms () //////////////////////////////////////////////////////////// Shader::~Shader() { - ensureGlContext(); + TransientContextLock lock; // Destroy effect program if (m_shaderProgram) @@ -592,7 +545,7 @@ void Shader::setUniform(const std::string& name, const Texture& texture) { if (m_shaderProgram) { - ensureGlContext(); + TransientContextLock lock; // Find the location of the variable in the shader int location = getUniformLocation(name); @@ -627,7 +580,7 @@ void Shader::setUniform(const std::string& name, CurrentTextureType) { if (m_shaderProgram) { - ensureGlContext(); + TransientContextLock lock; // Find the location of the variable in the shader m_currentTexture = getUniformLocation(name); @@ -787,7 +740,7 @@ unsigned int Shader::getNativeHandle() const //////////////////////////////////////////////////////////// void Shader::bind(const Shader* shader) { - ensureGlContext(); + TransientContextLock lock; // Make sure that we can use shaders if (!isAvailable()) @@ -820,10 +773,26 @@ void Shader::bind(const Shader* shader) //////////////////////////////////////////////////////////// bool Shader::isAvailable() { - // TODO: Remove this lock when it becomes unnecessary in C++11 - Lock lock(mutex); + Lock lock(isAvailableMutex); + + static bool checked = false; + static bool available = false; + + if (!checked) + { + checked = true; + + TransientContextLock contextLock; + + // Make sure that extensions are initialized + sf::priv::ensureExtensionsInit(); - static bool available = checkShadersAvailable(); + available = GLEXT_multitexture && + GLEXT_shading_language_100 && + GLEXT_shader_objects && + GLEXT_vertex_shader && + GLEXT_fragment_shader; + } return available; } @@ -832,10 +801,22 @@ bool Shader::isAvailable() //////////////////////////////////////////////////////////// bool Shader::isGeometryAvailable() { - // TODO: Remove this lock when it becomes unnecessary in C++11 - Lock lock(mutex); + Lock lock(isAvailableMutex); + + static bool checked = false; + static bool available = false; + + if (!checked) + { + checked = true; + + TransientContextLock contextLock; - static bool available = checkGeometryShadersAvailable(); + // Make sure that extensions are initialized + sf::priv::ensureExtensionsInit(); + + available = isAvailable() && GLEXT_geometry_shader4; + } return available; } @@ -844,7 +825,7 @@ bool Shader::isGeometryAvailable() //////////////////////////////////////////////////////////// bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCode, const char* fragmentShaderCode) { - ensureGlContext(); + TransientContextLock lock; // First make sure that we can use shaders if (!isAvailable()) @@ -1022,7 +1003,7 @@ int Shader::getUniformLocation(const std::string& name) m_uniforms.insert(std::make_pair(name, location)); if (location == -1) - err() << "Parameter \"" << name << "\" not found in shader" << std::endl; + err() << "Uniform \"" << name << "\" not found in shader" << std::endl; return location; } diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 5403b404..c0d4f821 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -163,8 +163,8 @@ m_textureRect (), m_fillColor (255, 255, 255), m_outlineColor (255, 255, 255), m_outlineThickness(0), -m_vertices (TrianglesFan), -m_outlineVertices (TrianglesStrip), +m_vertices (TriangleFan), +m_outlineVertices (TriangleStrip), m_insideBounds (), m_bounds () { diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index e24c8f27..71d5c70a 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -140,7 +140,7 @@ void Sprite::draw(RenderTarget& target, RenderStates states) const { states.transform *= getTransform(); states.texture = m_texture; - target.draw(m_vertices, 4, TrianglesStrip, states); + target.draw(m_vertices, 4, TriangleStrip, states); } } diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index ec76c6fe..5ad50c1f 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index ac610db1..a3eb1234 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -40,39 +40,19 @@ namespace { - sf::Mutex mutex; + sf::Mutex idMutex; + sf::Mutex maximumSizeMutex; // Thread-safe unique identifier generator, // is used for states cache (see RenderTarget) sf::Uint64 getUniqueId() { - sf::Lock lock(mutex); + sf::Lock lock(idMutex); static sf::Uint64 id = 1; // start at 1, zero is "no texture" return id++; } - - unsigned int checkMaximumTextureSize() - { - // Create a temporary context in case the user queries - // the size before a GlResource is created, thus - // initializing the shared context - if (!sf::Context::getActiveContext()) - { - sf::Context context; - - GLint size; - glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size)); - - return static_cast(size); - } - - GLint size; - glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size)); - - return static_cast(size); - } } @@ -88,6 +68,7 @@ m_sRgb (false), m_isRepeated (false), m_pixelsFlipped(false), m_fboAttachment(false), +m_hasMipmap (false), m_cacheId (getUniqueId()) { } @@ -103,10 +84,24 @@ m_sRgb (copy.m_sRgb), m_isRepeated (copy.m_isRepeated), m_pixelsFlipped(false), m_fboAttachment(false), +m_hasMipmap (false), m_cacheId (getUniqueId()) { if (copy.m_texture) - loadFromImage(copy.copyToImage()); + { + if (create(copy.getSize().x, copy.getSize().y)) + { + update(copy); + + // Force an OpenGL flush, so that the texture will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); + } + else + { + err() << "Failed to copy texture, failed to create new texture" << std::endl; + } + } } @@ -116,7 +111,7 @@ Texture::~Texture() // Destroy the OpenGL texture if (m_texture) { - ensureGlContext(); + TransientContextLock lock; GLuint texture = static_cast(m_texture); glCheck(glDeleteTextures(1, &texture)); @@ -155,7 +150,7 @@ bool Texture::create(unsigned int width, unsigned int height) m_pixelsFlipped = false; m_fboAttachment = false; - ensureGlContext(); + TransientContextLock lock; // Create the OpenGL texture if it doesn't exist yet if (!m_texture) @@ -217,6 +212,8 @@ bool Texture::create(unsigned int width, unsigned int height) glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); m_cacheId = getUniqueId(); + m_hasMipmap = false; + return true; } @@ -261,10 +258,6 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) { update(image); - // Force an OpenGL flush, so that the texture will appear updated - // in all contexts immediately (solves problems in multi-threaded apps) - glCheck(glFlush()); - return true; } else @@ -286,6 +279,8 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) // Create the texture and upload the pixels if (create(rectangle.width, rectangle.height)) { + TransientContextLock lock; + // Make sure that the current texture binding will be preserved priv::TextureSaver save; @@ -298,6 +293,9 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) pixels += 4 * width; } + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); + m_hasMipmap = false; + // Force an OpenGL flush, so that the texture will appear updated // in all contexts immediately (solves problems in multi-threaded apps) glCheck(glFlush()); @@ -326,7 +324,7 @@ Image Texture::copyToImage() const if (!m_texture) return Image(); - ensureGlContext(); + TransientContextLock lock; // Make sure that the current texture binding will be preserved priv::TextureSaver save; @@ -417,7 +415,7 @@ void Texture::update(const Uint8* pixels, unsigned int width, unsigned int heigh if (pixels && m_texture) { - ensureGlContext(); + TransientContextLock lock; // Make sure that the current texture binding will be preserved priv::TextureSaver save; @@ -425,12 +423,109 @@ void Texture::update(const Uint8* pixels, unsigned int width, unsigned int heigh // Copy pixels from the given array to the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); + m_hasMipmap = false; m_pixelsFlipped = false; m_cacheId = getUniqueId(); + + // Force an OpenGL flush, so that the texture data will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); } } +//////////////////////////////////////////////////////////// +void Texture::update(const Texture& texture) +{ + // Update the whole texture + update(texture, 0, 0); +} + + +//////////////////////////////////////////////////////////// +void Texture::update(const Texture& texture, unsigned int x, unsigned int y) +{ + assert(x + texture.m_size.x <= m_size.x); + assert(y + texture.m_size.y <= m_size.y); + + if (!m_texture || !texture.m_texture) + return; + +#ifndef SFML_OPENGL_ES + + { + TransientContextLock lock; + + // Make sure that extensions are initialized + priv::ensureExtensionsInit(); + } + + if (GLEXT_framebuffer_object && GLEXT_framebuffer_blit) + { + TransientContextLock lock; + + // Save the current bindings so we can restore them after we are done + GLint readFramebuffer = 0; + GLint drawFramebuffer = 0; + + glCheck(glGetIntegerv(GLEXT_GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer)); + glCheck(glGetIntegerv(GLEXT_GL_DRAW_FRAMEBUFFER_BINDING, &drawFramebuffer)); + + // Create the framebuffers + GLuint sourceFrameBuffer = 0; + GLuint destFrameBuffer = 0; + glCheck(GLEXT_glGenFramebuffers(1, &sourceFrameBuffer)); + glCheck(GLEXT_glGenFramebuffers(1, &destFrameBuffer)); + + if (!sourceFrameBuffer || !destFrameBuffer) + { + err() << "Cannot copy texture, failed to create a frame buffer object" << std::endl; + return; + } + + // Link the source texture to the source frame buffer + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_READ_FRAMEBUFFER, sourceFrameBuffer)); + glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_READ_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.m_texture, 0)); + + // Link the destination texture to the destination frame buffer + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, destFrameBuffer)); + glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_DRAW_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0)); + + // A final check, just to be sure... + GLenum sourceStatus; + glCheck(sourceStatus = GLEXT_glCheckFramebufferStatus(GLEXT_GL_READ_FRAMEBUFFER)); + + GLenum destStatus; + glCheck(destStatus = GLEXT_glCheckFramebufferStatus(GLEXT_GL_DRAW_FRAMEBUFFER)); + + if ((sourceStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE) && (destStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE)) + { + // Blit the texture contents from the source to the destination texture + glCheck(GLEXT_glBlitFramebuffer(0, 0, texture.m_size.x, texture.m_size.y, x, y, x + texture.m_size.x, y + texture.m_size.y, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + } + else + { + err() << "Cannot copy texture, failed to link texture to frame buffer" << std::endl; + } + + // Restore previously bound framebuffers + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_READ_FRAMEBUFFER, readFramebuffer)); + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, drawFramebuffer)); + + // Delete the framebuffers + glCheck(GLEXT_glDeleteFramebuffers(1, &sourceFrameBuffer)); + glCheck(GLEXT_glDeleteFramebuffers(1, &destFrameBuffer)); + + return; + } + +#endif // SFML_OPENGL_ES + + update(texture.copyToImage(), x, y); +} + + //////////////////////////////////////////////////////////// void Texture::update(const Image& image) { @@ -461,14 +556,22 @@ void Texture::update(const Window& window, unsigned int x, unsigned int y) if (m_texture && window.setActive(true)) { + TransientContextLock lock; + // Make sure that the current texture binding will be preserved priv::TextureSaver save; // Copy pixels from the back-buffer to the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.getSize().x, window.getSize().y)); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); + m_hasMipmap = false; m_pixelsFlipped = true; m_cacheId = getUniqueId(); + + // Force an OpenGL flush, so that the texture will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); } } @@ -482,14 +585,22 @@ void Texture::setSmooth(bool smooth) if (m_texture) { - ensureGlContext(); + TransientContextLock lock; // Make sure that the current texture binding will be preserved priv::TextureSaver save; glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); - glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); + + if (m_hasMipmap) + { + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_LINEAR)); + } + else + { + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); + } } } } @@ -525,7 +636,7 @@ void Texture::setRepeated(bool repeated) if (m_texture) { - ensureGlContext(); + TransientContextLock lock; // Make sure that the current texture binding will be preserved priv::TextureSaver save; @@ -561,10 +672,55 @@ bool Texture::isRepeated() const } +//////////////////////////////////////////////////////////// +bool Texture::generateMipmap() +{ + if (!m_texture) + return false; + + TransientContextLock lock; + + // Make sure that extensions are initialized + priv::ensureExtensionsInit(); + + if (!GLEXT_framebuffer_object) + return false; + + // Make sure that the current texture binding will be preserved + priv::TextureSaver save; + + glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); + glCheck(GLEXT_glGenerateMipmap(GL_TEXTURE_2D)); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_LINEAR)); + + m_hasMipmap = true; + + return true; +} + + +//////////////////////////////////////////////////////////// +void Texture::invalidateMipmap() +{ + if (!m_hasMipmap) + return; + + TransientContextLock lock; + + // Make sure that the current texture binding will be preserved + priv::TextureSaver save; + + glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); + + m_hasMipmap = false; +} + + //////////////////////////////////////////////////////////// void Texture::bind(const Texture* texture, CoordinateType coordinateType) { - ensureGlContext(); + TransientContextLock lock; if (texture && texture->m_texture) { @@ -620,12 +776,21 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType) //////////////////////////////////////////////////////////// unsigned int Texture::getMaximumSize() { - // TODO: Remove this lock when it becomes unnecessary in C++11 - Lock lock(mutex); + Lock lock(maximumSizeMutex); + + static bool checked = false; + static GLint size = 0; + + if (!checked) + { + checked = true; + + TransientContextLock lock; - static unsigned int size = checkMaximumTextureSize(); + glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size)); + } - return size; + return static_cast(size); } @@ -634,19 +799,30 @@ Texture& Texture::operator =(const Texture& right) { Texture temp(right); - std::swap(m_size, temp.m_size); - std::swap(m_actualSize, temp.m_actualSize); - std::swap(m_texture, temp.m_texture); - std::swap(m_isSmooth, temp.m_isSmooth); - std::swap(m_isRepeated, temp.m_isRepeated); - std::swap(m_pixelsFlipped, temp.m_pixelsFlipped); - std::swap(m_fboAttachment, temp.m_fboAttachment); - m_cacheId = getUniqueId(); + swap(temp); return *this; } +//////////////////////////////////////////////////////////// +void Texture::swap(Texture& right) +{ + std::swap(m_size, right.m_size); + std::swap(m_actualSize, right.m_actualSize); + std::swap(m_texture, right.m_texture); + std::swap(m_isSmooth, right.m_isSmooth); + std::swap(m_sRgb, right.m_sRgb); + std::swap(m_isRepeated, right.m_isRepeated); + std::swap(m_pixelsFlipped, right.m_pixelsFlipped); + std::swap(m_fboAttachment, right.m_fboAttachment); + std::swap(m_hasMipmap, right.m_hasMipmap); + + m_cacheId = getUniqueId(); + right.m_cacheId = getUniqueId(); +} + + //////////////////////////////////////////////////////////// unsigned int Texture::getNativeHandle() const { @@ -657,7 +833,7 @@ unsigned int Texture::getNativeHandle() const //////////////////////////////////////////////////////////// unsigned int Texture::getValidSize(unsigned int size) { - ensureGlContext(); + TransientContextLock lock; // Make sure that extensions are initialized priv::ensureExtensionsInit(); diff --git a/src/SFML/Graphics/TextureSaver.cpp b/src/SFML/Graphics/TextureSaver.cpp index 47ad6e95..1a119b57 100644 --- a/src/SFML/Graphics/TextureSaver.cpp +++ b/src/SFML/Graphics/TextureSaver.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/TextureSaver.hpp b/src/SFML/Graphics/TextureSaver.hpp index 4c87e4eb..467f6119 100644 --- a/src/SFML/Graphics/TextureSaver.hpp +++ b/src/SFML/Graphics/TextureSaver.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Transform.cpp b/src/SFML/Graphics/Transform.cpp index e027031b..3b831ba5 100644 --- a/src/SFML/Graphics/Transform.cpp +++ b/src/SFML/Graphics/Transform.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Transformable.cpp b/src/SFML/Graphics/Transformable.cpp index c45452d8..851ab3e7 100644 --- a/src/SFML/Graphics/Transformable.cpp +++ b/src/SFML/Graphics/Transformable.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/Vertex.cpp b/src/SFML/Graphics/Vertex.cpp index b95eb713..3d344c1e 100644 --- a/src/SFML/Graphics/Vertex.cpp +++ b/src/SFML/Graphics/Vertex.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp index e2d02183..0f9c8136 100644 --- a/src/SFML/Graphics/VertexArray.cpp +++ b/src/SFML/Graphics/VertexArray.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index 4fc61782..09a45bd6 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 52e3816a..595a3a26 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Main/MainWin32.cpp b/src/SFML/Main/MainWin32.cpp index 29e7133f..4658d9f3 100644 --- a/src/SFML/Main/MainWin32.cpp +++ b/src/SFML/Main/MainWin32.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Main/MainiOS.mm b/src/SFML/Main/MainiOS.mm index 48040e65..c6bddccd 100644 --- a/src/SFML/Main/MainiOS.mm +++ b/src/SFML/Main/MainiOS.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.prg) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.prg) // Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 44a03b8b..1882da86 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -395,8 +395,18 @@ Ftp::Response Ftp::getResponse() // Receive the response from the server char buffer[1024]; std::size_t length; - if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Done) - return Response(Response::ConnectionClosed); + + if (m_receiveBuffer.empty()) + { + if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Done) + return Response(Response::ConnectionClosed); + } + else + { + std::copy(m_receiveBuffer.begin(), m_receiveBuffer.end(), buffer); + length = m_receiveBuffer.size(); + m_receiveBuffer.clear(); + } // There can be several lines inside the received buffer, extract them all std::istringstream in(std::string(buffer, length), std::ios_base::binary); @@ -452,6 +462,9 @@ Ftp::Response Ftp::getResponse() message = separator + line; } + // Save the remaining data for the next time getResponse() is called + m_receiveBuffer.assign(buffer + in.tellg(), length - in.tellg()); + // Return the response code and message return Response(static_cast(code), message); } diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index 3654fc35..ef6987fb 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index e2beead2..91eec78e 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 2c5d0e06..fc33355c 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/Socket.cpp b/src/SFML/Network/Socket.cpp index 29e57e32..ad6d9930 100644 --- a/src/SFML/Network/Socket.cpp +++ b/src/SFML/Network/Socket.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/SocketImpl.hpp b/src/SFML/Network/SocketImpl.hpp index 423787e8..6f0c7e11 100644 --- a/src/SFML/Network/SocketImpl.hpp +++ b/src/SFML/Network/SocketImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index 31e82d8f..d7c9c564 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index 451b85e1..713301e1 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 6476c534..be218cf3 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 5bb1ff47..81e2e49c 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/Unix/SocketImpl.cpp b/src/SFML/Network/Unix/SocketImpl.cpp index 8cbb99b1..0c1457f8 100644 --- a/src/SFML/Network/Unix/SocketImpl.cpp +++ b/src/SFML/Network/Unix/SocketImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/Unix/SocketImpl.hpp b/src/SFML/Network/Unix/SocketImpl.hpp index c54c55fb..df99d3bd 100644 --- a/src/SFML/Network/Unix/SocketImpl.hpp +++ b/src/SFML/Network/Unix/SocketImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/Win32/SocketImpl.cpp b/src/SFML/Network/Win32/SocketImpl.cpp index 0f19842e..0e9f6ae2 100644 --- a/src/SFML/Network/Win32/SocketImpl.cpp +++ b/src/SFML/Network/Win32/SocketImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Network/Win32/SocketImpl.hpp b/src/SFML/Network/Win32/SocketImpl.hpp index f6cabafa..254fad2a 100644 --- a/src/SFML/Network/Win32/SocketImpl.hpp +++ b/src/SFML/Network/Win32/SocketImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Android/Activity.cpp b/src/SFML/System/Android/Activity.cpp index fe3d0151..4f657ee0 100644 --- a/src/SFML/System/Android/Activity.cpp +++ b/src/SFML/System/Android/Activity.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/System/Android/NativeActivity.cpp b/src/SFML/System/Android/NativeActivity.cpp index cf4f8085..ff97501e 100644 --- a/src/SFML/System/Android/NativeActivity.cpp +++ b/src/SFML/System/Android/NativeActivity.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index fbc1ec4f..93280aa6 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -49,35 +49,66 @@ m_file (NULL) //////////////////////////////////////////////////////////// ResourceStream::~ResourceStream() { - AAsset_close(m_file); + if (m_file) + { + AAsset_close(m_file); + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::read(void *data, Int64 size) { - return AAsset_read(m_file, data, size); + if (m_file) + { + return AAsset_read(m_file, data, size); + } + else + { + return -1; + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::seek(Int64 position) { - return AAsset_seek(m_file, position, SEEK_SET); + if (m_file) + { + return AAsset_seek(m_file, position, SEEK_SET); + } + else + { + return -1; + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::tell() { - return getSize() - AAsset_getRemainingLength(m_file); + if (m_file) + { + return getSize() - AAsset_getRemainingLength(m_file); + } + else + { + return -1; + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::getSize() { - return AAsset_getLength(m_file); + if (m_file) + { + return AAsset_getLength(m_file); + } + else + { + return -1; + } } diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index ba0bddb9..e4f347e3 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Err.cpp b/src/SFML/System/Err.cpp index a7a408e0..5d2084ec 100644 --- a/src/SFML/System/Err.cpp +++ b/src/SFML/System/Err.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/FileInputStream.cpp b/src/SFML/System/FileInputStream.cpp index 05510d11..e6f1c838 100644 --- a/src/SFML/System/FileInputStream.cpp +++ b/src/SFML/System/FileInputStream.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Lock.cpp b/src/SFML/System/Lock.cpp index 90da155a..4a371271 100644 --- a/src/SFML/System/Lock.cpp +++ b/src/SFML/System/Lock.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/MemoryInputStream.cpp b/src/SFML/System/MemoryInputStream.cpp index 6c2d5478..e3129279 100644 --- a/src/SFML/System/MemoryInputStream.cpp +++ b/src/SFML/System/MemoryInputStream.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Mutex.cpp b/src/SFML/System/Mutex.cpp index 4d515fc7..36d48ee6 100644 --- a/src/SFML/System/Mutex.cpp +++ b/src/SFML/System/Mutex.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 47650506..4f2a50e4 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index df5c1691..94b8b822 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Thread.cpp b/src/SFML/System/Thread.cpp index 5c4b08cc..3a2c0f90 100644 --- a/src/SFML/System/Thread.cpp +++ b/src/SFML/System/Thread.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/ThreadLocal.cpp b/src/SFML/System/ThreadLocal.cpp index 8e9cda11..01e3a352 100644 --- a/src/SFML/System/ThreadLocal.cpp +++ b/src/SFML/System/ThreadLocal.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp index 2be34c96..63de359a 100644 --- a/src/SFML/System/Time.cpp +++ b/src/SFML/System/Time.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp index 72330091..2cd89cfc 100644 --- a/src/SFML/System/Unix/ClockImpl.cpp +++ b/src/SFML/System/Unix/ClockImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ClockImpl.hpp b/src/SFML/System/Unix/ClockImpl.hpp index 24db7d98..26c6433a 100644 --- a/src/SFML/System/Unix/ClockImpl.hpp +++ b/src/SFML/System/Unix/ClockImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/MutexImpl.cpp b/src/SFML/System/Unix/MutexImpl.cpp index 56d28542..2ab46c0e 100644 --- a/src/SFML/System/Unix/MutexImpl.cpp +++ b/src/SFML/System/Unix/MutexImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/MutexImpl.hpp b/src/SFML/System/Unix/MutexImpl.hpp index d89365d2..ea4c838f 100644 --- a/src/SFML/System/Unix/MutexImpl.hpp +++ b/src/SFML/System/Unix/MutexImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp index 611a5544..22b6f358 100644 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ b/src/SFML/System/Unix/SleepImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/SleepImpl.hpp b/src/SFML/System/Unix/SleepImpl.hpp index 49125818..a4039b6b 100644 --- a/src/SFML/System/Unix/SleepImpl.hpp +++ b/src/SFML/System/Unix/SleepImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ThreadImpl.cpp b/src/SFML/System/Unix/ThreadImpl.cpp index 39cdeab8..b6dd383c 100644 --- a/src/SFML/System/Unix/ThreadImpl.cpp +++ b/src/SFML/System/Unix/ThreadImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ThreadImpl.hpp b/src/SFML/System/Unix/ThreadImpl.hpp index 37daae41..0191d5e2 100644 --- a/src/SFML/System/Unix/ThreadImpl.hpp +++ b/src/SFML/System/Unix/ThreadImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ThreadLocalImpl.cpp b/src/SFML/System/Unix/ThreadLocalImpl.cpp index 0664d82e..a0a157e2 100644 --- a/src/SFML/System/Unix/ThreadLocalImpl.cpp +++ b/src/SFML/System/Unix/ThreadLocalImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ThreadLocalImpl.hpp b/src/SFML/System/Unix/ThreadLocalImpl.hpp index b591cb25..b72ce65f 100644 --- a/src/SFML/System/Unix/ThreadLocalImpl.hpp +++ b/src/SFML/System/Unix/ThreadLocalImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/ClockImpl.cpp b/src/SFML/System/Win32/ClockImpl.cpp index 7ba7b9af..8098a7d4 100644 --- a/src/SFML/System/Win32/ClockImpl.cpp +++ b/src/SFML/System/Win32/ClockImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,17 +26,27 @@ // Headers //////////////////////////////////////////////////////////// #include +#include +#include #include namespace { + sf::Mutex oldWindowsMutex; + LARGE_INTEGER getFrequency() { LARGE_INTEGER frequency; QueryPerformanceFrequency(&frequency); return frequency; } + + bool isWindowsXpOrOlder() + { + // Windows XP was the last 5.x version of Windows + return static_cast(LOBYTE(LOWORD(GetVersion()))) < 6; + } } namespace sf @@ -46,21 +56,28 @@ namespace priv //////////////////////////////////////////////////////////// Time ClockImpl::getCurrentTime() { - // Force the following code to run on first core - // (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx) - HANDLE currentThread = GetCurrentThread(); - DWORD_PTR previousMask = SetThreadAffinityMask(currentThread, 1); - // Get the frequency of the performance counter // (it is constant across the program lifetime) static LARGE_INTEGER frequency = getFrequency(); - // Get the current time + // Detect if we are on Windows XP or older + static bool oldWindows = isWindowsXpOrOlder(); + LARGE_INTEGER time; - QueryPerformanceCounter(&time); - // Restore the thread affinity - SetThreadAffinityMask(currentThread, previousMask); + if (oldWindows) + { + // Acquire a lock (CRITICAL_SECTION) to prevent travelling back in time + Lock lock(oldWindowsMutex); + + // Get the current time + QueryPerformanceCounter(&time); + } + else + { + // Get the current time + QueryPerformanceCounter(&time); + } // Return the current time as microseconds return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart); diff --git a/src/SFML/System/Win32/ClockImpl.hpp b/src/SFML/System/Win32/ClockImpl.hpp index 37904919..45e08e87 100644 --- a/src/SFML/System/Win32/ClockImpl.hpp +++ b/src/SFML/System/Win32/ClockImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/MutexImpl.cpp b/src/SFML/System/Win32/MutexImpl.cpp index 047ea525..7b47cd51 100644 --- a/src/SFML/System/Win32/MutexImpl.cpp +++ b/src/SFML/System/Win32/MutexImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/MutexImpl.hpp b/src/SFML/System/Win32/MutexImpl.hpp index 75a5fb6f..c7174e8b 100644 --- a/src/SFML/System/Win32/MutexImpl.hpp +++ b/src/SFML/System/Win32/MutexImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/SleepImpl.cpp b/src/SFML/System/Win32/SleepImpl.cpp index 090c2195..8a8eee1c 100644 --- a/src/SFML/System/Win32/SleepImpl.cpp +++ b/src/SFML/System/Win32/SleepImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/SleepImpl.hpp b/src/SFML/System/Win32/SleepImpl.hpp index 682ec7f6..2cde5b3d 100644 --- a/src/SFML/System/Win32/SleepImpl.hpp +++ b/src/SFML/System/Win32/SleepImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/ThreadImpl.cpp b/src/SFML/System/Win32/ThreadImpl.cpp index dfe3c64e..d34950ab 100644 --- a/src/SFML/System/Win32/ThreadImpl.cpp +++ b/src/SFML/System/Win32/ThreadImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/ThreadImpl.hpp b/src/SFML/System/Win32/ThreadImpl.hpp index 94b45f86..cfd10399 100644 --- a/src/SFML/System/Win32/ThreadImpl.hpp +++ b/src/SFML/System/Win32/ThreadImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/ThreadLocalImpl.cpp b/src/SFML/System/Win32/ThreadLocalImpl.cpp index 0f0fb4ad..221fffe9 100644 --- a/src/SFML/System/Win32/ThreadLocalImpl.cpp +++ b/src/SFML/System/Win32/ThreadLocalImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/ThreadLocalImpl.hpp b/src/SFML/System/Win32/ThreadLocalImpl.hpp index 38bef43c..458b28a5 100644 --- a/src/SFML/System/Win32/ThreadLocalImpl.hpp +++ b/src/SFML/System/Win32/ThreadLocalImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Android/SensorImpl.cpp b/src/SFML/Window/Android/SensorImpl.cpp index 2b691a10..201c3ebf 100644 --- a/src/SFML/Window/Android/SensorImpl.cpp +++ b/src/SFML/Window/Android/SensorImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Android/SensorImpl.hpp b/src/SFML/Window/Android/SensorImpl.hpp index 0b349971..5cae66b4 100644 --- a/src/SFML/Window/Android/SensorImpl.hpp +++ b/src/SFML/Window/Android/SensorImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 78e20093..27d2f10e 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -178,6 +178,13 @@ void WindowImplAndroid::setMouseCursorVisible(bool visible) } +//////////////////////////////////////////////////////////// +void WindowImplAndroid::setMouseCursorGrabbed(bool grabbed) +{ + // Not applicable +} + + //////////////////////////////////////////////////////////// void WindowImplAndroid::setKeyRepeatEnabled(bool enabled) { diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index fb05b35b..88250d41 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -146,6 +146,14 @@ class WindowImplAndroid : public WindowImpl //////////////////////////////////////////////////////////// virtual void setMouseCursorVisible(bool visible); + //////////////////////////////////////////////////////////// + /// \brief Clips or releases the mouse cursor + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + virtual void setMouseCursorGrabbed(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 7119ade9..46f04729 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -76,8 +76,6 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) ${SRCROOT}/Unix/Display.hpp ${SRCROOT}/Unix/InputImpl.cpp ${SRCROOT}/Unix/InputImpl.hpp - ${SRCROOT}/Unix/ScopedXcbPtr.hpp - ${SRCROOT}/Unix/ScopedXcbPtr.inl ${SRCROOT}/Unix/SensorImpl.cpp ${SRCROOT}/Unix/SensorImpl.hpp ${SRCROOT}/Unix/VideoModeImpl.cpp @@ -96,7 +94,6 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) ${SRCROOT}/RPi/WindowImplRPi.hpp ) endif() - if(NOT SFML_OPENGL_ES) set(PLATFORM_SRC ${PLATFORM_SRC} @@ -214,18 +211,14 @@ if((SFML_OS_LINUX OR SFML_OS_FREEBSD) AND NOT SFML_RPI) if(NOT X11_FOUND) message(FATAL_ERROR "X11 library not found") endif() + if(NOT X11_Xrandr_FOUND) + message(FATAL_ERROR "Xrandr library not found") + endif() include_directories(${X11_INCLUDE_DIR}) endif() if(NOT SFML_OPENGL_ES) find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) - if(SFML_OS_LINUX OR SFML_OS_FREEBSD) - find_package(XCB COMPONENTS xlib_xcb image randr REQUIRED) - if(NOT LIBXCB_FOUND) - message(FATAL_ERROR "Xcb library not found") - endif() - include_directories(${LIBXCB_INCLUDE_DIRS}) - endif() endif() if(SFML_OPENGL_ES AND SFML_OS_LINUX) find_package(EGL REQUIRED) @@ -246,11 +239,11 @@ if(SFML_OS_WINDOWS) list(APPEND WINDOW_EXT_LIBS winmm gdi32) elseif(SFML_OS_LINUX) if(NOT SFML_RPI) - list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${LIBXCB_LIBRARIES}) + list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES}) endif() list(APPEND WINDOW_EXT_LIBS ${UDEV_LIBRARIES}) elseif(SFML_OS_FREEBSD) - list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${LIBXCB_LIBRARIES} usbhid) + list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} usbhid) elseif(SFML_OS_MACOSX) list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon") elseif(SFML_OS_IOS) diff --git a/src/SFML/Window/Context.cpp b/src/SFML/Window/Context.cpp index 3b3b9dc2..321dc2cc 100644 --- a/src/SFML/Window/Context.cpp +++ b/src/SFML/Window/Context.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -28,24 +28,6 @@ #include #include #include -#include -#include -#include -#include - -#if defined(SFML_SYSTEM_WINDOWS) - - typedef const GLubyte* (APIENTRY *glGetStringiFuncType)(GLenum, GLuint); - -#else - - typedef const GLubyte* (*glGetStringiFuncType)(GLenum, GLuint); - -#endif - -#if !defined(GL_NUM_EXTENSIONS) - #define GL_NUM_EXTENSIONS 0x821D -#endif namespace @@ -99,70 +81,16 @@ const Context* Context::getActiveContext() //////////////////////////////////////////////////////////// -GlFunctionPointer Context::getFunction(const char* name) +bool Context::isExtensionAvailable(const char* name) { - return priv::GlContext::getFunction(name); + return priv::GlContext::isExtensionAvailable(name); } //////////////////////////////////////////////////////////// -bool Context::isExtensionAvailable(const char* name) +GlFunctionPointer Context::getFunction(const char* name) { - static std::vector extensions; - static bool loaded = false; - - if (!loaded) - { - const Context* context = getActiveContext(); - - if (!context) - return false; - - const char* extensionString = NULL; - - if(context->getSettings().majorVersion < 3) - { - // Try to load the < 3.0 way - extensionString = reinterpret_cast(glGetString(GL_EXTENSIONS)); - - do - { - const char* extension = extensionString; - - while(*extensionString && (*extensionString != ' ')) - extensionString++; - - extensions.push_back(std::string(extension, extensionString)); - } - while (*extensionString++); - } - else - { - // Try to load the >= 3.0 way - glGetStringiFuncType glGetStringiFunc = NULL; - glGetStringiFunc = reinterpret_cast(getFunction("glGetStringi")); - - if (glGetStringiFunc) - { - int numExtensions = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - - if (numExtensions) - { - for (unsigned int i = 0; i < static_cast(numExtensions); ++i) - { - extensionString = reinterpret_cast(glGetStringiFunc(GL_EXTENSIONS, i)); - - extensions.push_back(extensionString); - } - } - } - } - - loaded = true; - } - - return std::find(extensions.begin(), extensions.end(), name) != extensions.end(); + return priv::GlContext::getFunction(name); } diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index ce21022f..9c4bfccf 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -173,9 +173,12 @@ EglContext::~EglContext() //////////////////////////////////////////////////////////// -bool EglContext::makeCurrent() +bool EglContext::makeCurrent(bool current) { - return m_surface != EGL_NO_SURFACE && eglCheck(eglMakeCurrent(m_display, m_surface, m_surface, m_context)); + if (current) + return m_surface != EGL_NO_SURFACE && eglCheck(eglMakeCurrent(m_display, m_surface, m_surface, m_context)); + + return m_surface != EGL_NO_SURFACE && eglCheck(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); } @@ -209,6 +212,9 @@ void EglContext::createContext(EglContext* shared) else toShared = EGL_NO_CONTEXT; + if (toShared != EGL_NO_CONTEXT) + eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + // Create EGL context m_context = eglCheck(eglCreateContext(m_display, m_config, toShared, contextVersion)); } diff --git a/src/SFML/Window/EglContext.hpp b/src/SFML/Window/EglContext.hpp index acd6eafa..1df273f5 100644 --- a/src/SFML/Window/EglContext.hpp +++ b/src/SFML/Window/EglContext.hpp @@ -83,10 +83,12 @@ class EglContext : public GlContext /// \brief Activate the context as the current target /// for rendering /// + /// \param current Whether to make the context current or no longer current + /// /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(); + virtual bool makeCurrent(bool current); //////////////////////////////////////////////////////////// /// \brief Display what has been rendered to the context so far diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.cpp b/src/SFML/Window/FreeBSD/JoystickImpl.cpp index ff21293e..7636e472 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.cpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // 2013-2013 David Demelier (demelier.david@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.hpp b/src/SFML/Window/FreeBSD/JoystickImpl.hpp index b52307c3..7f57f2f8 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.hpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 525d16a0..396d366b 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,14 +26,19 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include #include #include +#include +#include +#include #include #include #include +#include #if !defined(SFML_OPENGL_ES) @@ -126,43 +131,74 @@ namespace // AMD drivers have issues with internal synchronization // We need to make sure that no operating system context // or pixel format operations are performed simultaneously + // This mutex is also used to protect the shared context + // from being locked on multiple threads and for managing + // the resource count sf::Mutex mutex; + // OpenGL resources counter + unsigned int resourceCount = 0; + // This per-thread variable holds the current context for each thread sf::ThreadLocalPtr currentContext(NULL); // The hidden, inactive context that will be shared with all other contexts ContextType* sharedContext = NULL; - // Internal contexts - sf::ThreadLocalPtr internalContext(NULL); - std::set internalContexts; - sf::Mutex internalContextsMutex; - - // Check if the internal context of the current thread is valid - bool hasInternalContext() + // This structure contains all the state necessary to + // track TransientContext usage + struct TransientContext : private sf::NonCopyable { - // The internal context can be null... - if (!internalContext) - return false; - - // ... or non-null but deleted from the list of internal contexts - sf::Lock lock(internalContextsMutex); - return internalContexts.find(internalContext) != internalContexts.end(); - } + //////////////////////////////////////////////////////////// + /// \brief Constructor + /// + //////////////////////////////////////////////////////////// + TransientContext() : + referenceCount (0), + context (0), + sharedContextLock(0), + useSharedContext (false) + { + if (resourceCount == 0) + { + context = new sf::Context; + } + else if (!currentContext) + { + sharedContextLock = new sf::Lock(mutex); + useSharedContext = true; + sharedContext->setActive(true); + } + } - // Retrieve the internal context for the current thread - sf::Context* getInternalContext() - { - if (!hasInternalContext()) + //////////////////////////////////////////////////////////// + /// \brief Destructor + /// + //////////////////////////////////////////////////////////// + ~TransientContext() { - internalContext = new sf::Context; - sf::Lock lock(internalContextsMutex); - internalContexts.insert(internalContext); + if (useSharedContext) + sharedContext->setActive(false); + + delete sharedContextLock; + delete context; } - return internalContext; - } + /////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int referenceCount; + sf::Context* context; + sf::Lock* sharedContextLock; + bool useSharedContext; + }; + + // This per-thread variable tracks if and how a transient + // context is currently being used on the current thread + sf::ThreadLocalPtr transientContext(NULL); + + // Supported OpenGL extensions + std::vector extensions; } @@ -171,60 +207,163 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -void GlContext::globalInit() +void GlContext::initResource() { + // Protect from concurrent access Lock lock(mutex); - if (sharedContext) - return; + // If this is the very first resource, trigger the global context initialization + if (resourceCount == 0) + { + if (sharedContext) + { + // Increment the resources counter + resourceCount++; + + return; + } + + // Create the shared context + sharedContext = new ContextType(NULL); + sharedContext->initialize(ContextSettings()); + + // Load our extensions vector + extensions.clear(); + + // Check whether a >= 3.0 context is available + int majorVersion = 0; + glGetIntegerv(GL_MAJOR_VERSION, &majorVersion); + + if (glGetError() == GL_INVALID_ENUM) + { + // Try to load the < 3.0 way + const char* extensionString = reinterpret_cast(glGetString(GL_EXTENSIONS)); + + do + { + const char* extension = extensionString; - // Create the shared context - sharedContext = new ContextType(NULL); - sharedContext->initialize(ContextSettings()); + while(*extensionString && (*extensionString != ' ')) + extensionString++; - // This call makes sure that: - // - the shared context is inactive (it must never be) - // - another valid context is activated in the current thread - sharedContext->setActive(false); + extensions.push_back(std::string(extension, extensionString)); + } + while (*extensionString++); + } + else + { + // Try to load the >= 3.0 way + glGetStringiFuncType glGetStringiFunc = NULL; + glGetStringiFunc = reinterpret_cast(getFunction("glGetStringi")); + + if (glGetStringiFunc) + { + int numExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + + if (numExtensions) + { + for (unsigned int i = 0; i < static_cast(numExtensions); ++i) + { + const char* extensionString = reinterpret_cast(glGetStringiFunc(GL_EXTENSIONS, i)); + + extensions.push_back(extensionString); + } + } + } + } + + // Deactivate the shared context so that others can activate it when necessary + sharedContext->setActive(false); + } + + // Increment the resources counter + resourceCount++; } //////////////////////////////////////////////////////////// -void GlContext::globalCleanup() +void GlContext::cleanupResource() { + // Protect from concurrent access Lock lock(mutex); - if (!sharedContext) - return; + // Decrement the resources counter + resourceCount--; + + // If there's no more resource alive, we can trigger the global context cleanup + if (resourceCount == 0) + { + if (!sharedContext) + return; + + // Destroy the shared context + delete sharedContext; + sharedContext = NULL; + } +} + - // Destroy the shared context - delete sharedContext; - sharedContext = NULL; +//////////////////////////////////////////////////////////// +void GlContext::acquireTransientContext() +{ + // Protect from concurrent access + Lock lock(mutex); + + // If this is the first TransientContextLock on this thread + // construct the state object + if (!transientContext) + transientContext = new TransientContext; - // Destroy the internal contexts - Lock internalContextsLock(internalContextsMutex); - for (std::set::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it) - delete *it; - internalContexts.clear(); + // Increase the reference count + transientContext->referenceCount++; } //////////////////////////////////////////////////////////// -void GlContext::ensureContext() +void GlContext::releaseTransientContext() { - // If there's no active context on the current thread, activate an internal one - if (!currentContext) - getInternalContext()->setActive(true); + // Protect from concurrent access + Lock lock(mutex); + + // Make sure a matching acquireTransientContext() was called + assert(transientContext); + + // Decrease the reference count + transientContext->referenceCount--; + + // If this is the last TransientContextLock that is released + // destroy the state object + if (transientContext->referenceCount == 0) + { + delete transientContext; + transientContext = NULL; + } } //////////////////////////////////////////////////////////// GlContext* GlContext::create() { + // Make sure that there's an active context (context creation may need extensions, and thus a valid context) + assert(sharedContext != NULL); + Lock lock(mutex); - // Create the context - GlContext* context = new ContextType(sharedContext); + GlContext* context = NULL; + + // We don't use acquireTransientContext here since we have + // to ensure we have exclusive access to the shared context + // in order to make sure it is not active during context creation + { + sharedContext->setActive(true); + + // Create the context + context = new ContextType(sharedContext); + + sharedContext->setActive(false); + } + context->initialize(ContextSettings()); return context; @@ -235,12 +374,24 @@ GlContext* GlContext::create() GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) - ensureContext(); + assert(sharedContext != NULL); Lock lock(mutex); - // Create the context - GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel); + GlContext* context = NULL; + + // We don't use acquireTransientContext here since we have + // to ensure we have exclusive access to the shared context + // in order to make sure it is not active during context creation + { + sharedContext->setActive(true); + + // Create the context + context = new ContextType(sharedContext, settings, owner, bitsPerPixel); + + sharedContext->setActive(false); + } + context->initialize(settings); context->checkSettings(settings); @@ -252,12 +403,24 @@ GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* GlContext* GlContext::create(const ContextSettings& settings, unsigned int width, unsigned int height) { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) - ensureContext(); + assert(sharedContext != NULL); Lock lock(mutex); - // Create the context - GlContext* context = new ContextType(sharedContext, settings, width, height); + GlContext* context = NULL; + + // We don't use acquireTransientContext here since we have + // to ensure we have exclusive access to the shared context + // in order to make sure it is not active during context creation + { + sharedContext->setActive(true); + + // Create the context + context = new ContextType(sharedContext, settings, width, height); + + sharedContext->setActive(false); + } + context->initialize(settings); context->checkSettings(settings); @@ -265,6 +428,13 @@ GlContext* GlContext::create(const ContextSettings& settings, unsigned int width } +//////////////////////////////////////////////////////////// +bool GlContext::isExtensionAvailable(const char* name) +{ + return std::find(extensions.begin(), extensions.end(), name) != extensions.end(); +} + + //////////////////////////////////////////////////////////// GlFunctionPointer GlContext::getFunction(const char* name) { @@ -287,7 +457,10 @@ GlContext::~GlContext() { // Deactivate the context before killing it, unless we're inside Cleanup() if (sharedContext) - setActive(false); + { + if (this == currentContext) + currentContext = NULL; + } } @@ -308,7 +481,7 @@ bool GlContext::setActive(bool active) Lock lock(mutex); // Activate the context - if (makeCurrent()) + if (makeCurrent(true)) { // Set it as the new current context for this thread currentContext = this; @@ -329,9 +502,18 @@ bool GlContext::setActive(bool active) { if (this == currentContext) { - // To deactivate the context, we actually activate another one so that we make - // sure that there is always an active context for subsequent graphics operations - return getInternalContext()->setActive(true); + Lock lock(mutex); + + // Deactivate the context + if (makeCurrent(false)) + { + currentContext = NULL; + return true; + } + else + { + return false; + } } else { diff --git a/src/SFML/Window/GlContext.hpp b/src/SFML/Window/GlContext.hpp index b5a8b968..22efa626 100644 --- a/src/SFML/Window/GlContext.hpp +++ b/src/SFML/Window/GlContext.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -49,34 +49,37 @@ class GlContext : NonCopyable public: //////////////////////////////////////////////////////////// - /// \brief Perform the global initialization + /// \brief Perform resource initialization /// - /// This function is called once, before the very first OpenGL - /// resource is created. It makes sure that everything is ready - /// for contexts to work properly. - /// Note: this function doesn't need to be thread-safe, as it - /// can be called only once. + /// This function is called every time an OpenGL resource is + /// created. When the first resource is initialized, it makes + /// sure that everything is ready for contexts to work properly. /// //////////////////////////////////////////////////////////// - static void globalInit(); + static void initResource(); //////////////////////////////////////////////////////////// - /// \brief Perform the global cleanup + /// \brief Perform resource cleanup /// - /// This function is called after the very last OpenGL resource - /// is destroyed. It makes sure that everything that was - /// created by initialize() is properly released. - /// Note: this function doesn't need to be thread-safe, as it - /// can be called only once. + /// This function is called every time an OpenGL resource is + /// destroyed. When the last resource is destroyed, it makes + /// sure that everything that was created by initResource() + /// is properly released. /// //////////////////////////////////////////////////////////// - static void globalCleanup(); + static void cleanupResource(); //////////////////////////////////////////////////////////// - /// \brief Ensures that an OpenGL context is active in the current thread + /// \brief Acquires a context for short-term use on the current thread /// //////////////////////////////////////////////////////////// - static void ensureContext(); + static void acquireTransientContext(); + + //////////////////////////////////////////////////////////// + /// \brief Releases a context after short-term use on the current thread + /// + //////////////////////////////////////////////////////////// + static void releaseTransientContext(); //////////////////////////////////////////////////////////// /// \brief Create a new context, not associated to a window @@ -120,6 +123,16 @@ class GlContext : NonCopyable static GlContext* create(const ContextSettings& settings, unsigned int width, unsigned int height); public: + //////////////////////////////////////////////////////////// + /// \brief Check whether a given OpenGL extension is available + /// + /// \param name Name of the extension to check for + /// + /// \return True if available, false if unavailable + /// + //////////////////////////////////////////////////////////// + static bool isExtensionAvailable(const char* name); + //////////////////////////////////////////////////////////// /// \brief Get the address of an OpenGL function /// @@ -197,10 +210,12 @@ class GlContext : NonCopyable /// \brief Activate the context as the current target /// for rendering /// + /// \param current Whether to make the context current or no longer current + /// /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent() = 0; + virtual bool makeCurrent(bool current) = 0; //////////////////////////////////////////////////////////// /// \brief Evaluate a pixel format configuration diff --git a/src/SFML/Window/GlResource.cpp b/src/SFML/Window/GlResource.cpp index 921874d8..6924aa3a 100644 --- a/src/SFML/Window/GlResource.cpp +++ b/src/SFML/Window/GlResource.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -27,16 +27,6 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include - - -namespace -{ - // OpenGL resources counter and its mutex - unsigned int count = 0; - sf::Mutex mutex; -} namespace sf @@ -44,42 +34,28 @@ namespace sf //////////////////////////////////////////////////////////// GlResource::GlResource() { - { - // Protect from concurrent access - Lock lock(mutex); - - // If this is the very first resource, trigger the global context initialization - if (count == 0) - priv::GlContext::globalInit(); - - // Increment the resources counter - count++; - } - - // Now make sure that there is an active OpenGL context in the current thread - priv::GlContext::ensureContext(); + priv::GlContext::initResource(); } //////////////////////////////////////////////////////////// GlResource::~GlResource() { - // Protect from concurrent access - Lock lock(mutex); + priv::GlContext::cleanupResource(); +} - // Decrement the resources counter - count--; - // If there's no more resource alive, we can trigger the global context cleanup - if (count == 0) - priv::GlContext::globalCleanup(); +//////////////////////////////////////////////////////////// +GlResource::TransientContextLock::TransientContextLock() +{ + priv::GlContext::acquireTransientContext(); } //////////////////////////////////////////////////////////// -void GlResource::ensureGlContext() +GlResource::TransientContextLock::~TransientContextLock() { - priv::GlContext::ensureContext(); + priv::GlContext::releaseTransientContext(); } } // namespace sf diff --git a/src/SFML/Window/InputImpl.hpp b/src/SFML/Window/InputImpl.hpp index 1df5f2d4..14682c73 100644 --- a/src/SFML/Window/InputImpl.hpp +++ b/src/SFML/Window/InputImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Joystick.cpp b/src/SFML/Window/Joystick.cpp index 11cf289d..9d5c69fe 100644 --- a/src/SFML/Window/Joystick.cpp +++ b/src/SFML/Window/Joystick.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/JoystickImpl.hpp b/src/SFML/Window/JoystickImpl.hpp index 6648b599..18063967 100644 --- a/src/SFML/Window/JoystickImpl.hpp +++ b/src/SFML/Window/JoystickImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/JoystickManager.cpp b/src/SFML/Window/JoystickManager.cpp index 99c100d6..b89a7473 100644 --- a/src/SFML/Window/JoystickManager.cpp +++ b/src/SFML/Window/JoystickManager.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/JoystickManager.hpp b/src/SFML/Window/JoystickManager.hpp index 229160bd..2ccfa612 100644 --- a/src/SFML/Window/JoystickManager.hpp +++ b/src/SFML/Window/JoystickManager.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Keyboard.cpp b/src/SFML/Window/Keyboard.cpp index 6076122d..264d33f6 100644 --- a/src/SFML/Window/Keyboard.cpp +++ b/src/SFML/Window/Keyboard.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Mouse.cpp b/src/SFML/Window/Mouse.cpp index 0f966bcd..bbc5b79c 100644 --- a/src/SFML/Window/Mouse.cpp +++ b/src/SFML/Window/Mouse.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/OSX/AutoreleasePoolWrapper.h b/src/SFML/Window/OSX/AutoreleasePoolWrapper.h index eb5bb57d..6fedaaf4 100644 --- a/src/SFML/Window/OSX/AutoreleasePoolWrapper.h +++ b/src/SFML/Window/OSX/AutoreleasePoolWrapper.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm b/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm index f88982a2..9f832c7d 100644 --- a/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm +++ b/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/HIDInputManager.hpp b/src/SFML/Window/OSX/HIDInputManager.hpp index 01c5ccd5..819039a7 100644 --- a/src/SFML/Window/OSX/HIDInputManager.hpp +++ b/src/SFML/Window/OSX/HIDInputManager.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index f0c44a7f..c74200ce 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/HIDJoystickManager.cpp b/src/SFML/Window/OSX/HIDJoystickManager.cpp index 0223eca5..64416809 100644 --- a/src/SFML/Window/OSX/HIDJoystickManager.cpp +++ b/src/SFML/Window/OSX/HIDJoystickManager.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/HIDJoystickManager.hpp b/src/SFML/Window/OSX/HIDJoystickManager.hpp index a128df57..6052d38d 100644 --- a/src/SFML/Window/OSX/HIDJoystickManager.hpp +++ b/src/SFML/Window/OSX/HIDJoystickManager.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/InputImpl.hpp b/src/SFML/Window/OSX/InputImpl.hpp index ef897b18..8055d42d 100644 --- a/src/SFML/Window/OSX/InputImpl.hpp +++ b/src/SFML/Window/OSX/InputImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/InputImpl.mm b/src/SFML/Window/OSX/InputImpl.mm index a4087c6b..cf41b032 100644 --- a/src/SFML/Window/OSX/InputImpl.mm +++ b/src/SFML/Window/OSX/InputImpl.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/JoystickImpl.cpp b/src/SFML/Window/OSX/JoystickImpl.cpp index 09d76141..215a6a92 100644 --- a/src/SFML/Window/OSX/JoystickImpl.cpp +++ b/src/SFML/Window/OSX/JoystickImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/JoystickImpl.hpp b/src/SFML/Window/OSX/JoystickImpl.hpp index 5b08ba67..9d185cbe 100644 --- a/src/SFML/Window/OSX/JoystickImpl.hpp +++ b/src/SFML/Window/OSX/JoystickImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/NSImage+raw.h b/src/SFML/Window/OSX/NSImage+raw.h index 910c4cba..6672ea87 100644 --- a/src/SFML/Window/OSX/NSImage+raw.h +++ b/src/SFML/Window/OSX/NSImage+raw.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/NSImage+raw.mm b/src/SFML/Window/OSX/NSImage+raw.mm index cbe03c0d..ea33a16b 100644 --- a/src/SFML/Window/OSX/NSImage+raw.mm +++ b/src/SFML/Window/OSX/NSImage+raw.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFApplication.h b/src/SFML/Window/OSX/SFApplication.h index b388d806..8b280166 100644 --- a/src/SFML/Window/OSX/SFApplication.h +++ b/src/SFML/Window/OSX/SFApplication.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFApplication.m b/src/SFML/Window/OSX/SFApplication.m index 6ba1f900..90928cbd 100644 --- a/src/SFML/Window/OSX/SFApplication.m +++ b/src/SFML/Window/OSX/SFApplication.m @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFApplicationDelegate.h b/src/SFML/Window/OSX/SFApplicationDelegate.h index 4a995508..9b87b2b4 100644 --- a/src/SFML/Window/OSX/SFApplicationDelegate.h +++ b/src/SFML/Window/OSX/SFApplicationDelegate.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFApplicationDelegate.m b/src/SFML/Window/OSX/SFApplicationDelegate.m index c15037cd..75834113 100644 --- a/src/SFML/Window/OSX/SFApplicationDelegate.m +++ b/src/SFML/Window/OSX/SFApplicationDelegate.m @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFContext.hpp b/src/SFML/Window/OSX/SFContext.hpp index 761c12e7..8f020b33 100644 --- a/src/SFML/Window/OSX/SFContext.hpp +++ b/src/SFML/Window/OSX/SFContext.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -137,10 +137,12 @@ class SFContext : public GlContext /// \brief Activate the context as the current target /// for rendering /// + /// \param current Whether to make the context current or no longer current + /// /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(); + virtual bool makeCurrent(bool current); private: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index 09c57721..8c7e5a11 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -104,6 +104,10 @@ SFContext::~SFContext() { [m_context clearDrawable]; + + if (m_context == [NSOpenGLContext currentContext]) + [NSOpenGLContext clearCurrentContext]; + [m_context release]; [m_view release]; // Might be nil but we don't care. @@ -124,10 +128,18 @@ //////////////////////////////////////////////////////////// -bool SFContext::makeCurrent() +bool SFContext::makeCurrent(bool current) { - [m_context makeCurrentContext]; - return m_context == [NSOpenGLContext currentContext]; // Should be true. + if (current) + { + [m_context makeCurrentContext]; + return m_context == [NSOpenGLContext currentContext]; // Should be true. + } + else + { + [NSOpenGLContext clearCurrentContext]; + return m_context != [NSOpenGLContext currentContext]; // Should be true. + } } @@ -257,6 +269,17 @@ // Use the shared context if one is given. NSOpenGLContext* sharedContext = shared != NULL ? shared->m_context : nil; + if (sharedContext != nil) + { + [NSOpenGLContext clearCurrentContext]; + + if (sharedContext == [NSOpenGLContext currentContext]) + { + sf::err() << "Failed to deactivate shared context before sharing" << std::endl; + return; + } + } + // Create the context. m_context = [[NSOpenGLContext alloc] initWithFormat:pixFmt shareContext:sharedContext]; diff --git a/src/SFML/Window/OSX/SFKeyboardModifiersHelper.h b/src/SFML/Window/OSX/SFKeyboardModifiersHelper.h index 60bdb3fa..daaa72d9 100644 --- a/src/SFML/Window/OSX/SFKeyboardModifiersHelper.h +++ b/src/SFML/Window/OSX/SFKeyboardModifiersHelper.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm b/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm index 89c23b50..eec7e203 100644 --- a/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm +++ b/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm b/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm index 4f2d2a6d..aab4d9b8 100644 --- a/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm +++ b/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFOpenGLView+keyboard_priv.h b/src/SFML/Window/OSX/SFOpenGLView+keyboard_priv.h index b8846d98..0ed9aaf8 100644 --- a/src/SFML/Window/OSX/SFOpenGLView+keyboard_priv.h +++ b/src/SFML/Window/OSX/SFOpenGLView+keyboard_priv.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFOpenGLView+mouse.mm b/src/SFML/Window/OSX/SFOpenGLView+mouse.mm index d12df1c2..fa65aa6e 100644 --- a/src/SFML/Window/OSX/SFOpenGLView+mouse.mm +++ b/src/SFML/Window/OSX/SFOpenGLView+mouse.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -27,6 +27,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #import #import @@ -52,20 +53,29 @@ -(BOOL)isMouseInside //////////////////////////////////////////////////////// -(void)updateMouseState { + // Update in/out state BOOL mouseWasIn = m_mouseIsIn; m_mouseIsIn = [self isMouseInside]; - if (m_requester == 0) - return; - // Send event if needed. - if (mouseWasIn && !m_mouseIsIn) - m_requester->mouseMovedOut(); - else if (!mouseWasIn && m_mouseIsIn) - m_requester->mouseMovedIn(); + if (m_requester != 0) + { + if (mouseWasIn && !m_mouseIsIn) + m_requester->mouseMovedOut(); + else if (!mouseWasIn && m_mouseIsIn) + m_requester->mouseMovedIn(); + } } +//////////////////////////////////////////////////////// +-(void)setCursorGrabbed:(BOOL)grabbed +{ + m_cursorGrabbed = grabbed; + + [self updateCursorGrabbed]; +} + //////////////////////////////////////////////////////// -(void)mouseDown:(NSEvent*)theEvent @@ -200,20 +210,71 @@ -(void)otherMouseDragged:(NSEvent*)theEvent //////////////////////////////////////////////////////// -(void)handleMouseMove:(NSEvent*)theEvent { - if (m_requester != 0) + NSPoint loc = [self cursorPositionFromEvent:theEvent]; + + // If the cursor is grabbed, cursorPositionFromEvent: will + // return its correct position but not move actually it + // so we do it now. + if ([self isCursorCurrentlyGrabbed]) + [self moveCursorTo:loc]; + + // Make sure the point is inside the view. + // (mouseEntered: and mouseExited: are not immediately called + // when the mouse is dragged. That would be too easy!) + [self updateMouseState]; + if ((m_requester != 0) && m_mouseIsIn) + m_requester->mouseMovedAt(loc.x, loc.y); +} + + +//////////////////////////////////////////////////////// +-(BOOL)isCursorCurrentlyGrabbed +{ + return [[self window] isKeyWindow] && m_cursorGrabbed; +} + + +//////////////////////////////////////////////////////// +-(void)updateCursorGrabbed +{ + // Disable/enable normal movements of the cursor + // and project the cursor if needed. + if ([self isCursorCurrentlyGrabbed]) { - NSPoint loc = [self cursorPositionFromEvent:theEvent]; + CGAssociateMouseAndMouseCursorPosition(NO); - // Make sure the point is inside the view. - // (mouseEntered: and mouseExited: are not immediately called - // when the mouse is dragged. That would be too easy!) - [self updateMouseState]; - if (m_mouseIsIn) - m_requester->mouseMovedAt(loc.x, loc.y); + // Similarly to handleMouseMove: but without event. + NSPoint loc = [self cursorPositionFromEvent:nil]; + [self moveCursorTo:loc]; + } + else + { + CGAssociateMouseAndMouseCursorPosition(YES); } } +//////////////////////////////////////////////////////// +-(void)moveCursorTo:(NSPoint)loc +{ + // Convert the point from SFML coord system to screen coord system. + NSPoint screenLocation = [self computeGlobalPositionOfRelativePoint:loc]; + + // This won't produce a move event, which is perfect if the cursor was grabbed + // as we move it manually based on delta values of the cursor. + CGDisplayMoveCursorToPoint([self displayId], NSPointToCGPoint(screenLocation)); +} + + +//////////////////////////////////////////////////////// +-(CGDirectDisplayID)displayId +{ + NSScreen* screen = [[self window] screen]; + NSNumber* displayId = [[screen deviceDescription] objectForKey:@"NSScreenNumber"]; + return [displayId intValue]; +} + + //////////////////////////////////////////////////////// -(void)scrollWheel:(NSEvent*)theEvent { @@ -247,18 +308,74 @@ -(void)mouseExited:(NSEvent*)theEvent //////////////////////////////////////////////////////// -(NSPoint)cursorPositionFromEvent:(NSEvent*)eventOrNil { - NSPoint loc; + NSPoint rawPos; + // If no event given then get current mouse pos. if (eventOrNil == nil) - { - NSPoint rawPos = [[self window] mouseLocationOutsideOfEventStream]; - loc = [self convertPoint:rawPos fromView:nil]; - } + rawPos = [[self window] mouseLocationOutsideOfEventStream]; else + rawPos = [eventOrNil locationInWindow]; + + if ([self isCursorCurrentlyGrabbed]) { - loc = [self convertPoint:[eventOrNil locationInWindow] fromView:nil]; + if (eventOrNil != nil) + { + // Special case when the mouse is grabbed: + // we need to take into account the delta since the cursor + // is dissociated from its position. + + // Ignore any non-move related event + if (([eventOrNil type] == NSMouseMoved) || + ([eventOrNil type] == NSLeftMouseDragged) || + ([eventOrNil type] == NSRightMouseDragged) || + ([eventOrNil type] == NSOtherMouseDragged)) + { + // Without this factor, the cursor flies around waaay too fast! + // But I don't know if it because of retina display or because + // some event are sent twice (and that in itself is another mystery). + CGFloat factor = 2; + + // Also, this factor is not the same when keeping track of how much + // we move the cursor (buffers) when projecting the cursor into the + // view when grabbing the cursor for the first time. + CGFloat factorBuffer = m_fullscreen ? 1 : 2; + + CGFloat deltaX = [eventOrNil deltaX]; + CGFloat deltaY = [eventOrNil deltaY]; + + // If the buffer for X is empty, move the cursor; + // otherwise decrement this buffer a bit. + if (m_deltaXBuffer <= 0) + rawPos.x += deltaX / factor; + else + m_deltaXBuffer -= std::abs(deltaX / factorBuffer); + + // Rinse and repeat for Y. + if (m_deltaYBuffer <= 0) + rawPos.y -= deltaY / factor; + else + m_deltaYBuffer -= std::abs(deltaY / factorBuffer); + } + } + + // We also make sure the new point is inside the view + NSSize size = [self frame].size; + NSPoint origin = [self frame].origin; + NSPoint oldPos = rawPos; + rawPos.x = std::min(std::max(origin.x, rawPos.x), origin.x + size.width - 1); + rawPos.y = std::min(std::max(origin.y + 1, rawPos.y), origin.y + size.height); + // Note: the `-1` and `+1` on the two lines above prevent the user to click + // on the left or below the window, repectively, and therefore prevent the + // application to lose focus by accident. The sign of this offset is determinded + // by the direction of the x and y axis. + + // Increase X and Y buffer with the distance of the projection + m_deltaXBuffer += std::abs(rawPos.x - oldPos.x); + m_deltaYBuffer += std::abs(rawPos.y - oldPos.y); } + NSPoint loc = [self convertPoint:rawPos fromView:nil]; + // Don't forget to change to SFML coord system. float h = [self frame].size.height; loc.y = h - loc.y; diff --git a/src/SFML/Window/OSX/SFOpenGLView+mouse_priv.h b/src/SFML/Window/OSX/SFOpenGLView+mouse_priv.h index d020b796..a896e45d 100644 --- a/src/SFML/Window/OSX/SFOpenGLView+mouse_priv.h +++ b/src/SFML/Window/OSX/SFOpenGLView+mouse_priv.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -66,6 +66,36 @@ //////////////////////////////////////////////////////////// -(void)handleMouseMove:(NSEvent*)theEvent; +//////////////////////////////////////////////////////////// +/// \brief Check whether the cursor is grabbed or not +/// +/// The cursor is grabbed if the window is active (key) and +/// the user wants to grab it. +/// +//////////////////////////////////////////////////////////// +-(BOOL)isCursorCurrentlyGrabbed; + +//////////////////////////////////////////////////////////// +/// \brief (Dis)connect the cursor's movements from/to the system +/// and project the cursor into the view +/// +//////////////////////////////////////////////////////////// +-(void)updateCursorGrabbed; + +//////////////////////////////////////////////////////////// +/// \brief Move the cursor to the given location +/// +/// \param loc location expressed in SFML coordinate system +/// +//////////////////////////////////////////////////////////// +-(void)moveCursorTo:(NSPoint)loc; + +//////////////////////////////////////////////////////////// +/// \brief Get the display identifier on which the view is +/// +//////////////////////////////////////////////////////////// +-(CGDirectDisplayID)displayId; + //////////////////////////////////////////////////////////// /// \brief Convert the NSEvent mouse button type to SFML type /// diff --git a/src/SFML/Window/OSX/SFOpenGLView.h b/src/SFML/Window/OSX/SFOpenGLView.h index ec4078c6..d25b1b24 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.h +++ b/src/SFML/Window/OSX/SFOpenGLView.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -52,6 +52,19 @@ namespace sf { /// implementation. However, all attributes are defined in the main /// interface declaration right below. /// +/// Note about deltaXBuffer and deltaYBuffer: when grabbing the cursor +/// for the first time, either by entering fullscreen or through +/// setCursorGrabbed:, the cursor might be projected into the view. +/// Doing this will result in a big delta (relative movement) in the +/// next move event (cursorPositionFromEvent:), because no move event +/// is generated, which in turn will give the impression that the user +/// want to move the cursor by the same distance it was projected. To +/// prevent the cursor to fly twice the distance we keep track of how +/// much the cursor was projected in deltaXBuffer and deltaYBuffer. In +/// cursorPositionFromEvent: we can then reduce/augment those buffers +/// to determine when a move event should result in an actual move of +/// the cursor (that was disconnected from the system). +/// //////////////////////////////////////////////////////////// @interface SFOpenGLView : NSOpenGLView { @@ -61,6 +74,9 @@ namespace sf { NSTrackingArea* m_trackingArea; ///< Mouse tracking area BOOL m_fullscreen; ///< Indicate whether the window is fullscreen or not CGFloat m_scaleFactor; ///< Display scale factor (e.g. 1x for classic display, 2x for retina) + BOOL m_cursorGrabbed; ///< Is the mouse cursor trapped? + CGFloat m_deltaXBuffer; ///< See note about cursor grabbing above + CGFloat m_deltaYBuffer; ///< See note about cursor grabbing above // Hidden text view used to convert key event to actual chars. // We use a silent responder to prevent sound alerts. @@ -143,6 +159,8 @@ namespace sf { /// /// \param eventOrNil if nil the cursor position is the current one /// +/// \return the mouse position in SFML coord system +/// //////////////////////////////////////////////////////////// -(NSPoint)cursorPositionFromEvent:(NSEvent*)eventOrNil; @@ -154,4 +172,22 @@ namespace sf { //////////////////////////////////////////////////////////// -(BOOL)isMouseInside; +//////////////////////////////////////////////////////////// +/// Clips or releases the mouse cursor +/// +/// Generate a MouseEntered event when it makes sense. +/// +/// \param grabbed YES to grab, NO to release +/// +//////////////////////////////////////////////////////////// +-(void)setCursorGrabbed:(BOOL)grabbed; + +//////////////////////////////////////////////////////////// +/// Update the cursor position according to the grabbing behaviour +/// +/// This function has to be called when the window's state change +/// +//////////////////////////////////////////////////////////// +-(void)updateCursorGrabbed; + @end diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 2e7ba1e7..aa51de16 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -108,6 +108,9 @@ -(id)initWithFrame:(NSRect)frameRect fullscreen:(BOOL)isFullscreen m_fullscreen = isFullscreen; m_scaleFactor = 1.0; // Default value; it will be updated in finishInit + m_cursorGrabbed = NO; + m_deltaXBuffer = 0; + m_deltaYBuffer = 0; // Create a hidden text view for parsing key down event properly m_silentResponder = [[SFSilentResponder alloc] init]; @@ -163,8 +166,9 @@ -(void)finishInit name:NSWindowDidChangeScreenProfileNotification object:[self window]]; - // Now that we have a window, set up correctly the scale factor + // Now that we have a window, set up correctly the scale factor and cursor grabbing [self updateScaleFactor]; + [self updateCursorGrabbed]; // update for fullscreen } @@ -245,6 +249,7 @@ -(void)viewDidEndLiveResize // Update mouse internal state. [self updateMouseState]; + [self updateCursorGrabbed]; // Update the OGL view to fit the new size. [self update]; @@ -263,6 +268,8 @@ -(void)windowDidBecomeKey:(NSNotification*)notification { (void)notification; + [self updateCursorGrabbed]; + if (m_requester) m_requester->windowGainedFocus(); @@ -276,6 +283,8 @@ -(void)windowDidResignKey:(NSNotification*)notification { (void)notification; + [self updateCursorGrabbed]; + if (m_requester) m_requester->windowLostFocus(); diff --git a/src/SFML/Window/OSX/SFSilentResponder.h b/src/SFML/Window/OSX/SFSilentResponder.h index 0f00dd38..6c6da5d4 100644 --- a/src/SFML/Window/OSX/SFSilentResponder.h +++ b/src/SFML/Window/OSX/SFSilentResponder.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFSilentResponder.m b/src/SFML/Window/OSX/SFSilentResponder.m index f256a2fa..00569bfd 100644 --- a/src/SFML/Window/OSX/SFSilentResponder.m +++ b/src/SFML/Window/OSX/SFSilentResponder.m @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFViewController.h b/src/SFML/Window/OSX/SFViewController.h index b6d0a0ac..721d0134 100644 --- a/src/SFML/Window/OSX/SFViewController.h +++ b/src/SFML/Window/OSX/SFViewController.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index 8e35f792..03b161fc 100644 --- a/src/SFML/Window/OSX/SFViewController.mm +++ b/src/SFML/Window/OSX/SFViewController.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -121,6 +121,13 @@ -(BOOL)isMouseInside } +//////////////////////////////////////////////////////// +-(void)setCursorGrabbed:(BOOL)grabbed +{ + [m_oglView setCursorGrabbed:grabbed]; +} + + //////////////////////////////////////////////////////////// -(NSPoint)position { diff --git a/src/SFML/Window/OSX/SFWindow.h b/src/SFML/Window/OSX/SFWindow.h index 36ebc926..c24f3736 100644 --- a/src/SFML/Window/OSX/SFWindow.h +++ b/src/SFML/Window/OSX/SFWindow.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SFWindow.m b/src/SFML/Window/OSX/SFWindow.m index 7a4ee75f..0c32a427 100644 --- a/src/SFML/Window/OSX/SFWindow.m +++ b/src/SFML/Window/OSX/SFWindow.m @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -93,7 +93,7 @@ -(void)performClose:(id)sender //////////////////////////////////////////////////////// -(BOOL)validateMenuItem:(NSMenuItem*)menuItem { - return [menuItem action] == @selector(performClose:); + return [menuItem action] == @selector(performClose:) || [super validateMenuItem:menuItem]; } diff --git a/src/SFML/Window/OSX/SFWindowController.h b/src/SFML/Window/OSX/SFWindowController.h index 3736b92a..7c7635f8 100644 --- a/src/SFML/Window/OSX/SFWindowController.h +++ b/src/SFML/Window/OSX/SFWindowController.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -49,6 +49,11 @@ namespace sf { /// Used when SFML handle everything and when a NSWindow* is given /// as handle to WindowImpl. /// +/// When grabbing the cursor, if the window is resizeable, m_restoreResize is +/// set to YES and the window is marked as not resizeable. This is to prevent +/// accidental resize by the user. When the cursor is released, the window +/// style is restored. +/// //////////////////////////////////////////////////////////// @interface SFWindowController : NSResponder { @@ -56,6 +61,7 @@ namespace sf { SFOpenGLView* m_oglView; ///< OpenGL view for rendering sf::priv::WindowImplCocoa* m_requester; ///< Requester BOOL m_fullscreen; ///< Indicate whether the window is fullscreen or not + BOOL m_restoreResize; ///< See note above } //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index 72bd29d4..b12db9b6 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -97,6 +97,8 @@ -(id)initWithWindow:(NSWindow*)window m_window = nil; m_oglView = nil; m_requester = 0; + m_fullscreen = NO; // assuming this is the case... too hard to handle anyway. + m_restoreResize = NO; // Retain the window for our own use. m_window = [window retain]; @@ -148,6 +150,7 @@ -(id)initWithMode:(const sf::VideoMode&)mode andStyle:(unsigned long)style m_oglView = nil; m_requester = 0; m_fullscreen = (style & sf::Style::Fullscreen); + m_restoreResize = NO; if (m_fullscreen) [self setupFullscreenViewWithMode:mode]; @@ -345,6 +348,29 @@ -(BOOL)isMouseInside } +//////////////////////////////////////////////////////// +-(void)setCursorGrabbed:(BOOL)grabbed +{ + // Remove or restore resizeable style if needed + BOOL resizeable = [m_window styleMask] & NSResizableWindowMask; + if (grabbed && resizeable) + { + m_restoreResize = YES; + NSUInteger newStyle = [m_window styleMask] & ~NSResizableWindowMask; + [m_window setStyleMask:newStyle]; + } + else if (!grabbed && m_restoreResize) + { + m_restoreResize = NO; + NSUInteger newStyle = [m_window styleMask] | NSResizableWindowMask; + [m_window setStyleMask:newStyle]; + } + + // Forward to our view + [m_oglView setCursorGrabbed:grabbed]; +} + + //////////////////////////////////////////////////////////// -(NSPoint)position { @@ -379,6 +405,9 @@ -(void)setWindowPositionToX:(int)x Y:(int)y // Place the window. [m_window setFrameTopLeftPoint:point]; + + // In case the cursor was grabbed we need to update its position + [m_oglView updateCursorGrabbed]; } diff --git a/src/SFML/Window/OSX/Scaling.h b/src/SFML/Window/OSX/Scaling.h index 5a2af08f..733812d9 100644 --- a/src/SFML/Window/OSX/Scaling.h +++ b/src/SFML/Window/OSX/Scaling.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/SensorImpl.cpp b/src/SFML/Window/OSX/SensorImpl.cpp index 144c6d7e..4c00668e 100644 --- a/src/SFML/Window/OSX/SensorImpl.cpp +++ b/src/SFML/Window/OSX/SensorImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/OSX/SensorImpl.hpp b/src/SFML/Window/OSX/SensorImpl.hpp index 68b810e0..09bfd234 100644 --- a/src/SFML/Window/OSX/SensorImpl.hpp +++ b/src/SFML/Window/OSX/SensorImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/OSX/VideoModeImpl.cpp b/src/SFML/Window/OSX/VideoModeImpl.cpp index b6137553..ae5fdfb9 100644 --- a/src/SFML/Window/OSX/VideoModeImpl.cpp +++ b/src/SFML/Window/OSX/VideoModeImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/WindowImplCocoa.hpp b/src/SFML/Window/OSX/WindowImplCocoa.hpp index 486bf783..8daa8f83 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.hpp +++ b/src/SFML/Window/OSX/WindowImplCocoa.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -313,6 +313,14 @@ class WindowImplCocoa : public WindowImpl //////////////////////////////////////////////////////////// virtual void setMouseCursorVisible(bool visible); + //////////////////////////////////////////////////////////// + /// \brief Grab or release the mouse cursor + /// + /// \param grabbed True to grab, false to release + /// + //////////////////////////////////////////////////////////// + virtual void setMouseCursorGrabbed(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index b7dc45db..b294881a 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -486,6 +486,13 @@ void showMouseCursor() } +//////////////////////////////////////////////////////////// +void WindowImplCocoa::setMouseCursorGrabbed(bool grabbed) +{ + [m_delegate setCursorGrabbed:grabbed]; +} + + //////////////////////////////////////////////////////////// void WindowImplCocoa::setKeyRepeatEnabled(bool enabled) { diff --git a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h index 0c4595c7..0ca85625 100644 --- a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h +++ b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. @@ -96,6 +96,14 @@ namespace sf { //////////////////////////////////////////////////////////// -(BOOL)isMouseInside; +//////////////////////////////////////////////////////////// +/// \brief Grab or release the mouse cursor +/// +/// \param grabbed YES to grab, NO to release +/// +//////////////////////////////////////////////////////////// +-(void)setCursorGrabbed:(BOOL)grabbed; + //////////////////////////////////////////////////////////// /// \brief Get window position /// diff --git a/src/SFML/Window/OSX/cg_sf_conversion.hpp b/src/SFML/Window/OSX/cg_sf_conversion.hpp index c0083f84..3d18d6fd 100644 --- a/src/SFML/Window/OSX/cg_sf_conversion.hpp +++ b/src/SFML/Window/OSX/cg_sf_conversion.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/cg_sf_conversion.mm b/src/SFML/Window/OSX/cg_sf_conversion.mm index 30a4ea67..df0cfc4e 100644 --- a/src/SFML/Window/OSX/cg_sf_conversion.mm +++ b/src/SFML/Window/OSX/cg_sf_conversion.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/cpp_objc_conversion.h b/src/SFML/Window/OSX/cpp_objc_conversion.h index 42f15577..dce1779c 100644 --- a/src/SFML/Window/OSX/cpp_objc_conversion.h +++ b/src/SFML/Window/OSX/cpp_objc_conversion.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/OSX/cpp_objc_conversion.mm b/src/SFML/Window/OSX/cpp_objc_conversion.mm index ea7c84b6..af7894d8 100644 --- a/src/SFML/Window/OSX/cpp_objc_conversion.mm +++ b/src/SFML/Window/OSX/cpp_objc_conversion.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/src/SFML/Window/Sensor.cpp b/src/SFML/Window/Sensor.cpp index 64b9fff3..5331bbbc 100644 --- a/src/SFML/Window/Sensor.cpp +++ b/src/SFML/Window/Sensor.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/SensorImpl.hpp b/src/SFML/Window/SensorImpl.hpp index 39ca794f..aabf2774 100644 --- a/src/SFML/Window/SensorImpl.hpp +++ b/src/SFML/Window/SensorImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/SensorManager.cpp b/src/SFML/Window/SensorManager.cpp index dd3e7a0a..409eace6 100644 --- a/src/SFML/Window/SensorManager.cpp +++ b/src/SFML/Window/SensorManager.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/SensorManager.hpp b/src/SFML/Window/SensorManager.hpp index 2d9f9c1e..08bcea4d 100644 --- a/src/SFML/Window/SensorManager.hpp +++ b/src/SFML/Window/SensorManager.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Touch.cpp b/src/SFML/Window/Touch.cpp index 4ff400e2..ecc66000 100644 --- a/src/SFML/Window/Touch.cpp +++ b/src/SFML/Window/Touch.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/Display.cpp b/src/SFML/Window/Unix/Display.cpp index c57ae0fd..60f4c55a 100644 --- a/src/SFML/Window/Unix/Display.cpp +++ b/src/SFML/Window/Unix/Display.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,10 +26,12 @@ // Headers //////////////////////////////////////////////////////////// #include +#include +#include #include -#include #include #include +#include #include @@ -38,8 +40,9 @@ namespace // The shared display and its reference counter Display* sharedDisplay = NULL; unsigned int referenceCount = 0; + sf::Mutex mutex; - typedef std::map AtomMap; + typedef std::map AtomMap; AtomMap atoms; } @@ -50,6 +53,8 @@ namespace priv //////////////////////////////////////////////////////////// Display* OpenDisplay() { + Lock lock(mutex); + if (referenceCount == 0) { sharedDisplay = XOpenDisplay(NULL); @@ -68,16 +73,11 @@ Display* OpenDisplay() } -//////////////////////////////////////////////////////////// -xcb_connection_t* OpenConnection() -{ - return XGetXCBConnection(OpenDisplay()); -} - - //////////////////////////////////////////////////////////// void CloseDisplay(Display* display) { + Lock lock(mutex); + assert(display == sharedDisplay); referenceCount--; @@ -87,81 +87,22 @@ void CloseDisplay(Display* display) //////////////////////////////////////////////////////////// -void CloseConnection(xcb_connection_t* connection) -{ - assert(connection == XGetXCBConnection(sharedDisplay)); - return CloseDisplay(sharedDisplay); -} - - -//////////////////////////////////////////////////////////// -xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr) -{ - xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); - - for (; iter.rem; --screen_nbr, xcb_screen_next (&iter)) - { - if (screen_nbr == 0) - return iter.data; - } - - return NULL; -} - - -//////////////////////////////////////////////////////////// -xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection) -{ - assert(connection == XGetXCBConnection(sharedDisplay)); - return XCBScreenOfDisplay(connection, XDefaultScreen(sharedDisplay)); -} - - -//////////////////////////////////////////////////////////// -xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection) -{ - assert(connection == XGetXCBConnection(sharedDisplay)); - xcb_screen_t* screen = XCBScreenOfDisplay(connection, XDefaultScreen(sharedDisplay)); - if (screen) - return screen->root; - return 0; -} - - -//////////////////////////////////////////////////////////// -xcb_atom_t getAtom(const std::string& name, bool onlyIfExists) +Atom getAtom(const std::string& name, bool onlyIfExists) { AtomMap::const_iterator iter = atoms.find(name); if (iter != atoms.end()) return iter->second; - ScopedXcbPtr error(NULL); + Display* display = OpenDisplay(); - xcb_connection_t* connection = OpenConnection(); + Atom atom = XInternAtom(display, name.c_str(), onlyIfExists ? True : False); - ScopedXcbPtr reply(xcb_intern_atom_reply( - connection, - xcb_intern_atom( - connection, - onlyIfExists, - name.size(), - name.c_str() - ), - &error - )); - - CloseConnection(connection); - - if (error || !reply) - { - err() << "Failed to get " << name << " atom." << std::endl; - return XCB_ATOM_NONE; - } + CloseDisplay(display); - atoms[name] = reply->atom; + atoms[name] = atom; - return reply->atom; + return atom; } } // namespace priv diff --git a/src/SFML/Window/Unix/Display.hpp b/src/SFML/Window/Unix/Display.hpp index 2b33c964..0679369d 100644 --- a/src/SFML/Window/Unix/Display.hpp +++ b/src/SFML/Window/Unix/Display.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include +#include #include @@ -47,17 +47,6 @@ namespace priv //////////////////////////////////////////////////////////// Display* OpenDisplay(); -//////////////////////////////////////////////////////////// -/// \brief Get the xcb connection of the shared Display -/// -/// This function increments the reference count of the display, -/// it must be matched with a call to CloseConnection. -/// -/// \return Pointer to the shared connection -/// -//////////////////////////////////////////////////////////// -xcb_connection_t* OpenConnection(); - //////////////////////////////////////////////////////////// /// \brief Release a reference to the shared display /// @@ -66,55 +55,16 @@ xcb_connection_t* OpenConnection(); //////////////////////////////////////////////////////////// void CloseDisplay(Display* display); -//////////////////////////////////////////////////////////// -/// \brief Release a reference to the shared display -/// -/// \param connection Connection of display to release -/// -//////////////////////////////////////////////////////////// -void CloseConnection(xcb_connection_t* connection); - -//////////////////////////////////////////////////////////// -/// \brief Get screen of a display by index (equivalent to XScreenOfDisplay) -/// -/// \param connection Connection of display -/// \param screen_nbr The index of the screen -/// -/// \return Pointer to the screen -/// -//////////////////////////////////////////////////////////// -xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr); - -//////////////////////////////////////////////////////////// -/// \brief Get default screen of a display (equivalent to XDefaultScreen) -/// -/// \param connection Connection of display -/// -/// \return Pointer to the default screen of the display -/// -//////////////////////////////////////////////////////////// -xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection); - -//////////////////////////////////////////////////////////// -/// \brief Get default root window of a display (equivalent to XDefaultRootWindow) -/// -/// \param connection Connection of display -/// -/// \return Root window of the display -/// -//////////////////////////////////////////////////////////// -xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection); - //////////////////////////////////////////////////////////// /// \brief Get the atom with the specified name /// /// \param name Name of the atom /// \param onlyIfExists Don't try to create the atom if it doesn't already exist /// -/// \return Atom if it exists or XCB_ATOM_NONE (0) if it doesn't +/// \return Atom if it exists or None (0) if it doesn't /// //////////////////////////////////////////////////////////// -xcb_atom_t getAtom(const std::string& name, bool onlyIfExists = false); +Atom getAtom(const std::string& name, bool onlyIfExists = false); } // namespace priv diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index 4dc207f2..b16c0e28 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -105,10 +105,11 @@ m_ownsWindow(false) // Save the creation settings m_settings = ContextSettings(); - // Make sure that extensions are initialized if this is not the shared context - // The shared context is the context used to initialize the extensions - if (shared && shared->m_display) - ensureExtensionsInit(shared->m_display, DefaultScreen(shared->m_display)); + // Open the connection with the X server + m_display = OpenDisplay(); + + // Make sure that extensions are initialized + ensureExtensionsInit(m_display, DefaultScreen(m_display)); // Create the rendering surface (window or pbuffer if supported) createSurface(shared, 1, 1, VideoMode::getDesktopMode().bitsPerPixel); @@ -129,10 +130,11 @@ m_ownsWindow(false) // Save the creation settings m_settings = settings; - // Make sure that extensions are initialized if this is not the shared context - // The shared context is the context used to initialize the extensions - if (shared && shared->m_display) - ensureExtensionsInit(shared->m_display, DefaultScreen(shared->m_display)); + // Open the connection with the X server + m_display = OpenDisplay(); + + // Make sure that extensions are initialized + ensureExtensionsInit(m_display, DefaultScreen(m_display)); // Create the rendering surface from the owner window createSurface(static_cast< ::Window>(owner->getSystemHandle())); @@ -153,10 +155,11 @@ m_ownsWindow(false) // Save the creation settings m_settings = settings; - // Make sure that extensions are initialized if this is not the shared context - // The shared context is the context used to initialize the extensions - if (shared && shared->m_display) - ensureExtensionsInit(shared->m_display, DefaultScreen(shared->m_display)); + // Open the connection with the X server + m_display = OpenDisplay(); + + // Make sure that extensions are initialized + ensureExtensionsInit(m_display, DefaultScreen(m_display)); // Create the rendering surface (window or pbuffer if supported) createSurface(shared, width, height, VideoMode::getDesktopMode().bitsPerPixel); @@ -194,8 +197,8 @@ GlxContext::~GlxContext() // Destroy the window if we own it if (m_window && m_ownsWindow) { - xcb_destroy_window(m_connection, m_window); - xcb_flush(m_connection); + XDestroyWindow(m_display, m_window); + XFlush(m_display); } // Close the connection with the X server @@ -211,7 +214,7 @@ GlFunctionPointer GlxContext::getFunction(const char* name) //////////////////////////////////////////////////////////// -bool GlxContext::makeCurrent() +bool GlxContext::makeCurrent(bool current) { if (!m_context) return false; @@ -222,13 +225,20 @@ bool GlxContext::makeCurrent() bool result = false; - if (m_pbuffer) + if (current) { - result = glXMakeContextCurrent(m_display, m_pbuffer, m_pbuffer, m_context); + if (m_pbuffer) + { + result = glXMakeContextCurrent(m_display, m_pbuffer, m_pbuffer, m_context); + } + else if (m_window) + { + result = glXMakeCurrent(m_display, m_window, m_context); + } } - else if (m_window) + else { - result = glXMakeCurrent(m_display, m_window, m_context); + result = glXMakeCurrent(m_display, None, NULL); } #if defined(GLX_DEBUGGING) @@ -262,9 +272,6 @@ void GlxContext::display() //////////////////////////////////////////////////////////// void GlxContext::setVerticalSyncEnabled(bool enabled) { - // Make sure that extensions are initialized - ensureExtensionsInit(m_display, DefaultScreen(m_display)); - int result = 0; // Prioritize the EXT variant and fall back to MESA or SGI if needed @@ -303,6 +310,9 @@ void GlxContext::setVerticalSyncEnabled(bool enabled) //////////////////////////////////////////////////////////// XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPerPixel, const ContextSettings& settings) { + // Make sure that extensions are initialized + ensureExtensionsInit(display, DefaultScreen(display)); + // Retrieve all the visuals int count; XVisualInfo* visuals = XGetVisualInfo(display, 0, NULL, &count); @@ -443,9 +453,6 @@ void GlxContext::updateSettingsFromWindow() //////////////////////////////////////////////////////////// void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel) { - m_display = OpenDisplay(); - m_connection = XGetXCBConnection(m_display); - // Choose the visual according to the context settings XVisualInfo visualInfo = selectBestVisual(m_display, bitsPerPixel, m_settings); @@ -482,8 +489,11 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned if (visual->visualid == visualInfo.visualid) { config = &configs[i]; + XFree(visual); break; } + + XFree(visual); } if (config) @@ -510,28 +520,22 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned } // If pbuffers are not available we use a hidden window as the off-screen surface to draw to - xcb_screen_t* screen = XCBScreenOfDisplay(m_connection, DefaultScreen(m_display)); + int screen = DefaultScreen(m_display); // Define the window attributes - xcb_colormap_t colormap = xcb_generate_id(m_connection); - xcb_create_colormap(m_connection, XCB_COLORMAP_ALLOC_NONE, colormap, screen->root, visualInfo.visualid); - const uint32_t value_list[] = {colormap}; - - // Create a dummy window (disabled and hidden) - m_window = xcb_generate_id(m_connection); - xcb_create_window( - m_connection, - static_cast(visualInfo.depth), - m_window, - screen->root, - 0, 0, - width, height, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - visualInfo.visualid, - XCB_CW_COLORMAP, - value_list - ); + XSetWindowAttributes attributes; + attributes.colormap = XCreateColormap(m_display, RootWindow(m_display, screen), visualInfo.visual, AllocNone); + + m_window = XCreateWindow(m_display, + RootWindow(m_display, screen), + 0, 0, + width, height, + 0, + DefaultDepth(m_display, screen), + InputOutput, + visualInfo.visual, + CWColormap, + &attributes); m_ownsWindow = true; @@ -542,9 +546,6 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned //////////////////////////////////////////////////////////// void GlxContext::createSurface(::Window window) { - m_display = OpenDisplay(); - m_connection = XGetXCBConnection(m_display); - // A window already exists, so just use it m_window = window; @@ -640,8 +641,11 @@ void GlxContext::createContext(GlxContext* shared) if (visual->visualid == visualInfo->visualid) { config = &configs[i]; + XFree(visual); break; } + + XFree(visual); } if (!config) @@ -688,6 +692,15 @@ void GlxContext::createContext(GlxContext* shared) // On an error, glXCreateContextAttribsARB will return 0 anyway GlxErrorHandler handler(m_display); + if (toShare) + { + if (!glXMakeCurrent(m_display, None, NULL)) + { + err() << "Failed to deactivate shared context before sharing" << std::endl; + return; + } + } + // Create the context m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, &attributes[0]); @@ -734,6 +747,15 @@ void GlxContext::createContext(GlxContext* shared) GlxErrorHandler handler(m_display); #endif + if (toShare) + { + if (!glXMakeCurrent(m_display, None, NULL)) + { + err() << "Failed to deactivate shared context before sharing" << std::endl; + return; + } + } + // Create the context, using the target window's visual m_context = glXCreateContext(m_display, visualInfo, toShare, true); diff --git a/src/SFML/Window/Unix/GlxContext.hpp b/src/SFML/Window/Unix/GlxContext.hpp index 36ba98a6..3991abad 100644 --- a/src/SFML/Window/Unix/GlxContext.hpp +++ b/src/SFML/Window/Unix/GlxContext.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include namespace sf @@ -94,10 +94,12 @@ class GlxContext : public GlContext //////////////////////////////////////////////////////////// /// \brief Activate the context as the current target for rendering /// + /// \param current Whether to make the context current or no longer current + /// /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(); + virtual bool makeCurrent(bool current); //////////////////////////////////////////////////////////// /// \brief Display what has been rendered to the context so far @@ -178,7 +180,6 @@ class GlxContext : public GlContext //////////////////////////////////////////////////////////// ::Display* m_display; ///< Connection to the X server ::Window m_window; ///< Window to which the context is attached - xcb_connection_t* m_connection; ///< Pointer to the xcb connection GLXContext m_context; ///< OpenGL context GLXPbuffer m_pbuffer; ///< GLX pbuffer ID if one was created bool m_ownsWindow; ///< Do we own the window associated to the context? diff --git a/src/SFML/Window/Unix/GlxExtensions.cpp b/src/SFML/Window/Unix/GlxExtensions.cpp index e20e4bf0..4d9d9781 100644 --- a/src/SFML/Window/Unix/GlxExtensions.cpp +++ b/src/SFML/Window/Unix/GlxExtensions.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/GlxExtensions.hpp b/src/SFML/Window/Unix/GlxExtensions.hpp index 28e159e7..929e38a7 100644 --- a/src/SFML/Window/Unix/GlxExtensions.hpp +++ b/src/SFML/Window/Unix/GlxExtensions.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/InputImpl.cpp b/src/SFML/Window/Unix/InputImpl.cpp index 53d92be3..23c114b2 100644 --- a/src/SFML/Window/Unix/InputImpl.cpp +++ b/src/SFML/Window/Unix/InputImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -28,9 +28,8 @@ #include // important to be included first (conflict with None) #include #include -#include #include -#include +#include #include @@ -157,36 +156,26 @@ bool InputImpl::isKeyPressed(Keyboard::Key key) Display* display = OpenDisplay(); // Convert to keycode - xcb_keycode_t keycode = XKeysymToKeycode(display, keysym); - - CloseDisplay(display); - - ScopedXcbPtr error(NULL); - - // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); - - // Get the whole keyboard state - ScopedXcbPtr keymap( - xcb_query_keymap_reply( - connection, - xcb_query_keymap(connection), - &error - ) - ); + KeyCode keycode = XKeysymToKeycode(display, keysym); + if (keycode != 0) + { + // Get the whole keyboard state + char keys[32]; + XQueryKeymap(display, keys); - // Close the connection with the X server - CloseConnection(connection); + // Close the connection with the X server + CloseDisplay(display); - if (error) + // Check our keycode + return (keys[keycode / 8] & (1 << (keycode % 8))) != 0; + } + else { - err() << "Failed to query keymap" << std::endl; + // Close the connection with the X server + CloseDisplay(display); return false; } - - // Check our keycode - return (keymap->keys[keycode / 8] & (1 << (keycode % 8))) != 0; } @@ -201,43 +190,30 @@ void InputImpl::setVirtualKeyboardVisible(bool /*visible*/) bool InputImpl::isMouseButtonPressed(Mouse::Button button) { // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); - - ScopedXcbPtr error(NULL); - - // Get pointer mask - ScopedXcbPtr pointer( - xcb_query_pointer_reply( - connection, - xcb_query_pointer( - connection, - XCBDefaultRootWindow(connection) - ), - &error - ) - ); - - // Close the connection with the X server - CloseConnection(connection); + Display* display = OpenDisplay(); - if (error) - { - err() << "Failed to query pointer" << std::endl; + // we don't care about these but they are required + ::Window root, child; + int wx, wy; + int gx, gy; - return false; - } + unsigned int buttons = 0; + XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &wx, &wy, &buttons); - uint16_t buttons = pointer->mask; + // Close the connection with the X server + CloseDisplay(display); switch (button) { - case Mouse::Left: return buttons & XCB_BUTTON_MASK_1; - case Mouse::Right: return buttons & XCB_BUTTON_MASK_3; - case Mouse::Middle: return buttons & XCB_BUTTON_MASK_2; + case Mouse::Left: return buttons & Button1Mask; + case Mouse::Right: return buttons & Button3Mask; + case Mouse::Middle: return buttons & Button2Mask; case Mouse::XButton1: return false; // not supported by X case Mouse::XButton2: return false; // not supported by X default: return false; } + + return false; } @@ -245,32 +221,21 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) Vector2i InputImpl::getMousePosition() { // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); + Display* display = OpenDisplay(); - ScopedXcbPtr error(NULL); + // we don't care about these but they are required + ::Window root, child; + int x, y; + unsigned int buttons; - ScopedXcbPtr pointer( - xcb_query_pointer_reply( - connection, - xcb_query_pointer( - connection, - XCBDefaultRootWindow(connection) - ), - &error - ) - ); + int gx = 0; + int gy = 0; + XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &x, &y, &buttons); // Close the connection with the X server - CloseConnection(connection); - - if (error) - { - err() << "Failed to query pointer" << std::endl; - - return Vector2i(0, 0); - } + CloseDisplay(display); - return Vector2i(pointer->root_x, pointer->root_y); + return Vector2i(gx, gy); } @@ -281,32 +246,21 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo) if (handle) { // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); + Display* display = OpenDisplay(); - ScopedXcbPtr error(NULL); + // we don't care about these but they are required + ::Window root, child; + int gx, gy; + unsigned int buttons; - ScopedXcbPtr pointer( - xcb_query_pointer_reply( - connection, - xcb_query_pointer( - connection, - handle - ), - &error - ) - ); + int x = 0; + int y = 0; + XQueryPointer(display, handle, &root, &child, &gx, &gy, &x, &y, &buttons); // Close the connection with the X server - CloseConnection(connection); - - if (error) - { - err() << "Failed to query pointer" << std::endl; - - return Vector2i(0, 0); - } + CloseDisplay(display); - return Vector2i(pointer->win_x, pointer->win_y); + return Vector2i(x, y); } else { @@ -319,27 +273,13 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo) void InputImpl::setMousePosition(const Vector2i& position) { // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); - - ScopedXcbPtr error(xcb_request_check( - connection, - xcb_warp_pointer( - connection, - None, // Source window - XCBDefaultRootWindow(connection), // Destination window - 0, 0, // Source position - 0, 0, // Source size - position.x, position.y // Destination position - ) - )); - - if (error) - err() << "Failed to set mouse position" << std::endl; + Display* display = OpenDisplay(); - xcb_flush(connection); + XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, position.x, position.y); + XFlush(display); // Close the connection with the X server - CloseConnection(connection); + CloseDisplay(display); } @@ -347,31 +287,17 @@ void InputImpl::setMousePosition(const Vector2i& position) void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo) { // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); + Display* display = OpenDisplay(); WindowHandle handle = relativeTo.getSystemHandle(); if (handle) { - ScopedXcbPtr error(xcb_request_check( - connection, - xcb_warp_pointer( - connection, - None, // Source window - handle, // Destination window - 0, 0, // Source position - 0, 0, // Source size - position.x, position.y // Destination position - ) - )); - - if (error) - err() << "Failed to set mouse position" << std::endl; - - xcb_flush(connection); + XWarpPointer(display, None, handle, 0, 0, 0, 0, position.x, position.y); + XFlush(display); } // Close the connection with the X server - CloseConnection(connection); + CloseDisplay(display); } diff --git a/src/SFML/Window/Unix/InputImpl.hpp b/src/SFML/Window/Unix/InputImpl.hpp index 9425c3df..32ff1133 100644 --- a/src/SFML/Window/Unix/InputImpl.hpp +++ b/src/SFML/Window/Unix/InputImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/JoystickImpl.cpp b/src/SFML/Window/Unix/JoystickImpl.cpp index f9ddb426..2898c6ca 100644 --- a/src/SFML/Window/Unix/JoystickImpl.cpp +++ b/src/SFML/Window/Unix/JoystickImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/JoystickImpl.hpp b/src/SFML/Window/Unix/JoystickImpl.hpp index d68e2997..c62b0df0 100644 --- a/src/SFML/Window/Unix/JoystickImpl.hpp +++ b/src/SFML/Window/Unix/JoystickImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/ScopedXcbPtr.hpp b/src/SFML/Window/Unix/ScopedXcbPtr.hpp deleted file mode 100644 index 6c98065d..00000000 --- a/src/SFML/Window/Unix/ScopedXcbPtr.hpp +++ /dev/null @@ -1,102 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_SCOPEDXCBPTR_HPP -#define SFML_SCOPEDXCBPTR_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Scoped pointer that frees memory returned in XCB replies -/// -//////////////////////////////////////////////////////////// -template -class ScopedXcbPtr -{ -public: - //////////////////////////////////////////////////////////// - /// \brief Constructor - /// - /// \param pointer Pointer value to store - /// - //////////////////////////////////////////////////////////// - ScopedXcbPtr(T* pointer); - - //////////////////////////////////////////////////////////// - /// \brief Destructor, calls std::free() on the stored pointer - /// - //////////////////////////////////////////////////////////// - ~ScopedXcbPtr(); - - //////////////////////////////////////////////////////////// - /// \brief Structure dereference operator - /// - /// \return Stored pointer - /// - //////////////////////////////////////////////////////////// - T* operator ->() const; - - //////////////////////////////////////////////////////////// - /// \brief Address operator. - /// - /// \return Address of the stored pointer - /// - //////////////////////////////////////////////////////////// - T** operator &(); - - //////////////////////////////////////////////////////////// - /// \brief Check if stored pointer is valid - /// - /// \return true if stored pointer is valid - /// - //////////////////////////////////////////////////////////// - operator bool() const; - - //////////////////////////////////////////////////////////// - /// \brief Retrieve the stored pointer. - /// - /// \return The stored pointer - /// - //////////////////////////////////////////////////////////// - T* get() const; - -private: - T* m_pointer; ///< Stored pointer -}; - -#include - -} // namespace priv - -} // namespace sf - -#endif // SFML_SCOPEDXCBPTR_HPP diff --git a/src/SFML/Window/Unix/ScopedXcbPtr.inl b/src/SFML/Window/Unix/ScopedXcbPtr.inl deleted file mode 100644 index 6683a1e6..00000000 --- a/src/SFML/Window/Unix/ScopedXcbPtr.inl +++ /dev/null @@ -1,72 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////// -template -inline ScopedXcbPtr::ScopedXcbPtr(T* pointer) : -m_pointer(pointer) -{ - -} - - -//////////////////////////////////////////////////////////// -template -inline ScopedXcbPtr::~ScopedXcbPtr() -{ - std::free(m_pointer); -} - - -//////////////////////////////////////////////////////////// -template -inline T* ScopedXcbPtr::operator ->() const -{ - return m_pointer; -} - - -//////////////////////////////////////////////////////////// -template -inline T** ScopedXcbPtr::operator &() -{ - return &m_pointer; -} - - -//////////////////////////////////////////////////////////// -template -inline ScopedXcbPtr::operator bool() const -{ - return m_pointer != NULL; -} - - -//////////////////////////////////////////////////////////// -template -inline T* ScopedXcbPtr::get() const -{ - return m_pointer; -} diff --git a/src/SFML/Window/Unix/SensorImpl.cpp b/src/SFML/Window/Unix/SensorImpl.cpp index 144c6d7e..4c00668e 100644 --- a/src/SFML/Window/Unix/SensorImpl.cpp +++ b/src/SFML/Window/Unix/SensorImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/SensorImpl.hpp b/src/SFML/Window/Unix/SensorImpl.hpp index 49ced872..a4eedde2 100644 --- a/src/SFML/Window/Unix/SensorImpl.hpp +++ b/src/SFML/Window/Unix/SensorImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Unix/VideoModeImpl.cpp b/src/SFML/Window/Unix/VideoModeImpl.cpp index 9ee812f2..f58d8597 100644 --- a/src/SFML/Window/Unix/VideoModeImpl.cpp +++ b/src/SFML/Window/Unix/VideoModeImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -27,9 +27,9 @@ //////////////////////////////////////////////////////////// #include #include -#include #include -#include +#include +#include #include @@ -43,95 +43,78 @@ std::vector VideoModeImpl::getFullscreenModes() std::vector modes; // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); - - // Retrieve the default screen - xcb_screen_t* screen = XCBDefaultScreen(connection); - - ScopedXcbPtr error(NULL); - - const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id); - - if (!randrExt || !randrExt->present) - { - // Randr extension is not supported: we cannot get the video modes - err() << "Failed to use the RandR extension while trying to get the supported video modes" << std::endl; - - // Close the connection with the X server - CloseConnection(connection); - - return modes; - } - - // Load RandR and check its version - ScopedXcbPtr randrVersion(xcb_randr_query_version_reply( - connection, - xcb_randr_query_version( - connection, - 1, - 1 - ), - &error - )); - - if (error) - { - err() << "Failed to load the RandR extension while trying to get the supported video modes" << std::endl; - - // Close the connection with the X server - CloseConnection(connection); - - return modes; - } - - // Get the current configuration - ScopedXcbPtr config(xcb_randr_get_screen_info_reply( - connection, - xcb_randr_get_screen_info( - connection, - screen->root - ), - &error - )); - - if (error) + Display* display = OpenDisplay(); + if (display) { - // Failed to get the screen configuration - err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl; + // Retrieve the default screen number + int screen = DefaultScreen(display); - // Close the connection with the X server - CloseConnection(connection); - - return modes; - } - - // Get the available screen sizes - xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); - if (sizes && (config->nSizes > 0)) - { - // Get the list of supported depths - xcb_depth_iterator_t iter = xcb_screen_allowed_depths_iterator(screen); - // Combine depths and sizes to fill the array of supported modes - for (; iter.rem; xcb_depth_next(&iter)) + // Check if the XRandR extension is present + int version; + if (XQueryExtension(display, "RANDR", &version, &version, &version)) { - for (int j = 0; j < config->nSizes; ++j) + // Get the current configuration + XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen)); + if (config) { - // Convert to VideoMode - VideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth); - - if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || - config->rotation == XCB_RANDR_ROTATION_ROTATE_270) - std::swap(mode.width, mode.height); - - // Add it only if it is not already in the array - if (std::find(modes.begin(), modes.end(), mode) == modes.end()) - modes.push_back(mode); + // Get the available screen sizes + int nbSizes; + XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); + if (sizes && (nbSizes > 0)) + { + // Get the list of supported depths + int nbDepths = 0; + int* depths = XListDepths(display, screen, &nbDepths); + if (depths && (nbDepths > 0)) + { + // Combine depths and sizes to fill the array of supported modes + for (int i = 0; i < nbDepths; ++i) + { + for (int j = 0; j < nbSizes; ++j) + { + // Convert to VideoMode + VideoMode mode(sizes[j].width, sizes[j].height, depths[i]); + + Rotation currentRotation; + XRRConfigRotations(config, ¤tRotation); + + if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270) + std::swap(mode.width, mode.height); + + // Add it only if it is not already in the array + if (std::find(modes.begin(), modes.end(), mode) == modes.end()) + modes.push_back(mode); + } + } + + // Free the array of depths + XFree(depths); + } + } + + // Free the configuration instance + XRRFreeScreenConfigInfo(config); + } + else + { + // Failed to get the screen configuration + err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl; } } - } + else + { + // XRandr extension is not supported: we cannot get the video modes + err() << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl; + } - // Close the connection with the X server - CloseConnection(connection); + // Close the connection with the X server + CloseDisplay(display); + } + else + { + // We couldn't connect to the X server + err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl; + } return modes; } @@ -143,91 +126,62 @@ VideoMode VideoModeImpl::getDesktopMode() VideoMode desktopMode; // Open a connection with the X server - xcb_connection_t* connection = OpenConnection(); - - // Retrieve the default screen - xcb_screen_t* screen = XCBDefaultScreen(connection); - - ScopedXcbPtr error(NULL); - - // Check if the RandR extension is present - const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id); - - if (!randrExt || !randrExt->present) - { - // Randr extension is not supported: we cannot get the video modes - err() << "Failed to use the RandR extension while trying to get the desktop video mode" << std::endl; - - // Close the connection with the X server - CloseConnection(connection); - - return desktopMode; - } - - // Load RandR and check its version - ScopedXcbPtr randrVersion(xcb_randr_query_version_reply( - connection, - xcb_randr_query_version( - connection, - 1, - 1 - ), - &error - )); - - if (error) + Display* display = OpenDisplay(); + if (display) { - err() << "Failed to load the RandR extension while trying to get the desktop video mode" << std::endl; - - // Close the connection with the X server - CloseConnection(connection); - - return desktopMode; - } + // Retrieve the default screen number + int screen = DefaultScreen(display); - // Get the current configuration - ScopedXcbPtr config(xcb_randr_get_screen_info_reply( - connection, - xcb_randr_get_screen_info( - connection, - screen->root - ), - &error - )); - - if (error) - { - // Failed to get the screen configuration - err() << "Failed to retrieve the screen configuration while trying to get the desktop video mode" << std::endl; + // Check if the XRandR extension is present + int version; + if (XQueryExtension(display, "RANDR", &version, &version, &version)) + { + // Get the current configuration + XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen)); + if (config) + { + // Get the current video mode + Rotation currentRotation; + int currentMode = XRRConfigCurrentConfiguration(config, ¤tRotation); + + // Get the available screen sizes + int nbSizes; + XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); + if (sizes && (nbSizes > 0)) + { + desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen)); + + Rotation currentRotation; + XRRConfigRotations(config, ¤tRotation); + + if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270) + std::swap(desktopMode.width, desktopMode.height); + } + + // Free the configuration instance + XRRFreeScreenConfigInfo(config); + } + else + { + // Failed to get the screen configuration + err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl; + } + } + else + { + // XRandr extension is not supported: we cannot get the video modes + err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl; + } // Close the connection with the X server - CloseConnection(connection); - - return desktopMode; - } - - // Get the current video mode - xcb_randr_mode_t currentMode = config->sizeID; - - // Get the available screen sizes - int nbSizes = xcb_randr_get_screen_info_sizes_length(config.get()); - xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); - if (sizes && (nbSizes > 0)) - { - desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, screen->root_depth); - - if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || - config->rotation == XCB_RANDR_ROTATION_ROTATE_270) - std::swap(desktopMode.width, desktopMode.height); + CloseDisplay(display); } else { - err() << "Failed to retrieve any screen sizes while trying to get the desktop video mode" << std::endl; + // We couldn't connect to the X server + err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl; } - // Close the connection with the X server - CloseConnection(connection); - return desktopMode; } diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 09156fa0..91086e14 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -29,14 +29,16 @@ #include #include #include -#include #include #include #include #include -#include -#include +#include #include +#include +#include +#include +#include #include #include #include @@ -65,11 +67,14 @@ namespace sf::Mutex allWindowsMutex; sf::String windowManagerName; - static const unsigned long eventMask = XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_PRESS | - XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_MOTION | - XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_KEY_PRESS | - XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | - XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW; + static const unsigned long eventMask = FocusChangeMask | ButtonPressMask | + ButtonReleaseMask | ButtonMotionMask | + PointerMotionMask | KeyPressMask | + KeyReleaseMask | StructureNotifyMask | + EnterWindowMask | LeaveWindowMask | + VisibilityChangeMask | PropertyChangeMask; + + static const unsigned int maxTrialsCount = 5; // Filter the events received by windows (only allow those matching a specific window) Bool checkEvent(::Display*, XEvent* event, XPointer userData) @@ -123,76 +128,88 @@ namespace checked = true; - xcb_connection_t* connection = sf::priv::OpenConnection(); - - xcb_atom_t netSupportingWmCheck = sf::priv::getAtom("_NET_SUPPORTING_WM_CHECK", true); - xcb_atom_t netSupported = sf::priv::getAtom("_NET_SUPPORTED", true); + Atom netSupportingWmCheck = sf::priv::getAtom("_NET_SUPPORTING_WM_CHECK", true); + Atom netSupported = sf::priv::getAtom("_NET_SUPPORTED", true); if (!netSupportingWmCheck || !netSupported) return false; - sf::priv::ScopedXcbPtr error(NULL); - - sf::priv::ScopedXcbPtr rootSupportingWindow(xcb_get_property_reply( - connection, - xcb_get_property( - connection, - 0, - sf::priv::XCBDefaultRootWindow(connection), - netSupportingWmCheck, - XCB_ATOM_WINDOW, - 0, - 1 - ), - &error - )); - - if (!rootSupportingWindow || rootSupportingWindow->length != 1) + ::Display* display = sf::priv::OpenDisplay(); + + Atom actualType; + int actualFormat; + unsigned long numItems; + unsigned long numBytes; + unsigned char* data; + + int result = XGetWindowProperty(display, + DefaultRootWindow(display), + netSupportingWmCheck, + 0, + 1, + False, + XA_WINDOW, + &actualType, + &actualFormat, + &numItems, + &numBytes, + &data); + + if (result != Success || actualType != XA_WINDOW || numItems != 1) { - sf::priv::CloseConnection(connection); + if(result == Success) + XFree(data); + + sf::priv::CloseDisplay(display); return false; } - xcb_window_t* rootWindow = reinterpret_cast(xcb_get_property_value(rootSupportingWindow.get())); + ::Window rootWindow = *reinterpret_cast< ::Window* >(data); + + XFree(data); if (!rootWindow) { - sf::priv::CloseConnection(connection); + sf::priv::CloseDisplay(display); return false; } - sf::priv::ScopedXcbPtr childSupportingWindow(xcb_get_property_reply( - connection, - xcb_get_property( - connection, - 0, - *rootWindow, - netSupportingWmCheck, - XCB_ATOM_WINDOW, - 0, - 1 - ), - &error - )); - - if (!childSupportingWindow || childSupportingWindow->length != 1) + result = XGetWindowProperty(display, + rootWindow, + netSupportingWmCheck, + 0, + 1, + False, + XA_WINDOW, + &actualType, + &actualFormat, + &numItems, + &numBytes, + &data); + + if (result != Success || actualType != XA_WINDOW || numItems != 1) { - sf::priv::CloseConnection(connection); + if(result == Success) + XFree(data); + + sf::priv::CloseDisplay(display); return false; } - xcb_window_t* childWindow = reinterpret_cast(xcb_get_property_value(childSupportingWindow.get())); + ::Window childWindow = *reinterpret_cast< ::Window* >(data); + + XFree(data); if (!childWindow) { - sf::priv::CloseConnection(connection); + sf::priv::CloseDisplay(display); return false; } // Conforming window managers should return the same window for both queries - if (*rootWindow != *childWindow) + if (rootWindow != childWindow) { - sf::priv::CloseConnection(connection); + sf::priv::CloseDisplay(display); return false; } @@ -200,45 +217,51 @@ namespace // We try to get the name of the window manager // for window manager specific workarounds - xcb_atom_t netWmName = sf::priv::getAtom("_NET_WM_NAME", true); - xcb_atom_t utf8StringType = sf::priv::getAtom("UTF8_STRING"); - - if (!utf8StringType) - utf8StringType = XCB_ATOM_STRING; + Atom netWmName = sf::priv::getAtom("_NET_WM_NAME", true); if (!netWmName) { - sf::priv::CloseConnection(connection); + sf::priv::CloseDisplay(display); return true; } - sf::priv::ScopedXcbPtr wmName(xcb_get_property_reply( - connection, - xcb_get_property( - connection, - 0, - *childWindow, - netWmName, - utf8StringType, - 0, - 0x7fffffff - ), - &error - )); - - sf::priv::CloseConnection(connection); - - // It seems the wm name string reply is not necessarily - // null-terminated. The work around is to get its actual - // length to build a proper string - const char* begin = reinterpret_cast(xcb_get_property_value(wmName.get())); - const char* end = begin + xcb_get_property_value_length(wmName.get()); - windowManagerName = sf::String::fromUtf8(begin, end); + Atom utf8StringType = sf::priv::getAtom("UTF8_STRING"); + + if (!utf8StringType) + utf8StringType = XA_STRING; + + result = XGetWindowProperty(display, + rootWindow, + netWmName, + 0, + 0x7fffffff, + False, + utf8StringType, + &actualType, + &actualFormat, + &numItems, + &numBytes, + &data); + + if (actualType && numItems) + { + // It seems the wm name string reply is not necessarily + // null-terminated. The work around is to get its actual + // length to build a proper string + const char* begin = reinterpret_cast(data); + const char* end = begin + numItems; + windowManagerName = sf::String::fromUtf8(begin, end); + } + + if(result == Success) + XFree(data); + + sf::priv::CloseDisplay(display); return true; } - sf::Keyboard::Key keysymToSF(xcb_keysym_t symbol) + sf::Keyboard::Key keysymToSF(KeySym symbol) { switch (symbol) { @@ -358,32 +381,29 @@ namespace priv //////////////////////////////////////////////////////////// WindowImplX11::WindowImplX11(WindowHandle handle) : m_window (0), -m_screen (NULL), +m_screen (0), m_inputMethod (NULL), m_inputContext (NULL), m_isExternal (true), +m_oldVideoMode (0), m_hiddenCursor (0), m_keyRepeat (true), m_previousSize (-1, -1), m_useSizeHints (false), -m_fullscreen (false) +m_fullscreen (false), +m_cursorGrabbed (false), +m_windowMapped (false), +m_iconPixmap (0), +m_iconMaskPixmap (0), +m_lastInputTime (0) { // Open a connection with the X server m_display = OpenDisplay(); - m_connection = XGetXCBConnection(m_display); - - std::memset(&m_oldVideoMode, 0, sizeof(m_oldVideoMode)); - - if (!m_connection) - { - err() << "Failed cast Display object to an XCB connection object" << std::endl; - return; - } // Make sure to check for EWMH support before we do anything ewmhSupported(); - m_screen = XCBDefaultScreen(m_connection); + m_screen = DefaultScreen(m_display); // Save the window handle m_window = handle; @@ -391,14 +411,10 @@ m_fullscreen (false) if (m_window) { // Make sure the window is listening to all the required events - const uint32_t value_list[] = {static_cast(eventMask)}; + XSetWindowAttributes attributes; + attributes.event_mask = eventMask; - xcb_change_window_attributes( - m_connection, - m_window, - XCB_CW_EVENT_MASK, - value_list - ); + XChangeWindowAttributes(m_display, m_window, CWEventMask, &attributes); // Set the WM protocols setProtocols(); @@ -412,36 +428,33 @@ m_fullscreen (false) //////////////////////////////////////////////////////////// WindowImplX11::WindowImplX11(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings) : m_window (0), -m_screen (NULL), +m_screen (0), m_inputMethod (NULL), m_inputContext (NULL), m_isExternal (false), +m_oldVideoMode (0), m_hiddenCursor (0), m_keyRepeat (true), m_previousSize (-1, -1), m_useSizeHints (false), -m_fullscreen ((style & Style::Fullscreen) != 0) +m_fullscreen ((style & Style::Fullscreen) != 0), +m_cursorGrabbed (m_fullscreen), +m_windowMapped (false), +m_iconPixmap (0), +m_iconMaskPixmap (0), +m_lastInputTime (0) { // Open a connection with the X server m_display = OpenDisplay(); - m_connection = XGetXCBConnection(m_display); - - std::memset(&m_oldVideoMode, 0, sizeof(m_oldVideoMode)); - - if (!m_connection) - { - err() << "Failed cast Display object to an XCB connection object" << std::endl; - return; - } // Make sure to check for EWMH support before we do anything ewmhSupported(); - m_screen = XCBDefaultScreen(m_connection); + m_screen = DefaultScreen(m_display); // Compute position and size - int left = m_fullscreen ? 0 : (m_screen->width_in_pixels - mode.width) / 2; - int top = m_fullscreen ? 0 : (m_screen->height_in_pixels - mode.height) / 2; + int left = m_fullscreen ? 0 : (DisplayWidth(m_display, m_screen) - mode.width) / 2; + int top = m_fullscreen ? 0 : (DisplayHeight(m_display, m_screen) - mode.height) / 2; int width = mode.width; int height = mode.height; @@ -449,31 +462,23 @@ m_fullscreen ((style & Style::Fullscreen) != 0) XVisualInfo visualInfo = ContextType::selectBestVisual(m_display, mode.bitsPerPixel, settings); // Define the window attributes - xcb_colormap_t colormap = xcb_generate_id(m_connection); - xcb_create_colormap(m_connection, XCB_COLORMAP_ALLOC_NONE, colormap, m_screen->root, visualInfo.visualid); - const uint32_t value_list[] = {m_fullscreen && !ewmhSupported(), static_cast(eventMask), colormap}; - - // Create the window - m_window = xcb_generate_id(m_connection); - - ScopedXcbPtr errptr(xcb_request_check( - m_connection, - xcb_create_window_checked( - m_connection, - static_cast(visualInfo.depth), - m_window, - m_screen->root, - left, top, - width, height, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - visualInfo.visualid, - XCB_CW_EVENT_MASK | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_COLORMAP, - value_list - ) - )); - - if (errptr) + XSetWindowAttributes attributes; + attributes.colormap = XCreateColormap(m_display, DefaultRootWindow(m_display), visualInfo.visual, AllocNone); + attributes.event_mask = eventMask; + attributes.override_redirect = (m_fullscreen && !ewmhSupported()) ? True : False; + + m_window = XCreateWindow(m_display, + DefaultRootWindow(m_display), + left, top, + width, height, + 0, + visualInfo.depth, + InputOutput, + visualInfo.visual, + CWEventMask | CWOverrideRedirect | CWColormap, + &attributes); + + if (!m_window) { err() << "Failed to create window" << std::endl; return; @@ -483,54 +488,113 @@ m_fullscreen ((style & Style::Fullscreen) != 0) setProtocols(); // Set the WM initial state to the normal state - WMHints hints; - std::memset(&hints, 0, sizeof(hints)); - hints.initial_state = 1; - hints.flags |= 1 << 1; - setWMHints(hints); + XWMHints* hints = XAllocWMHints(); + hints->flags = StateHint; + hints->initial_state = NormalState; + XSetWMHints(m_display, m_window, hints); + XFree(hints); // If not in fullscreen, set the window's style (tell the window manager to // change our window's decorations and functions according to the requested style) if (!m_fullscreen) - setMotifHints(style); + { + Atom WMHintsAtom = getAtom("_MOTIF_WM_HINTS", false); + if (WMHintsAtom) + { + static const unsigned long MWM_HINTS_FUNCTIONS = 1 << 0; + static const unsigned long MWM_HINTS_DECORATIONS = 1 << 1; + + //static const unsigned long MWM_DECOR_ALL = 1 << 0; + static const unsigned long MWM_DECOR_BORDER = 1 << 1; + static const unsigned long MWM_DECOR_RESIZEH = 1 << 2; + static const unsigned long MWM_DECOR_TITLE = 1 << 3; + static const unsigned long MWM_DECOR_MENU = 1 << 4; + static const unsigned long MWM_DECOR_MINIMIZE = 1 << 5; + static const unsigned long MWM_DECOR_MAXIMIZE = 1 << 6; + + //static const unsigned long MWM_FUNC_ALL = 1 << 0; + static const unsigned long MWM_FUNC_RESIZE = 1 << 1; + static const unsigned long MWM_FUNC_MOVE = 1 << 2; + static const unsigned long MWM_FUNC_MINIMIZE = 1 << 3; + static const unsigned long MWM_FUNC_MAXIMIZE = 1 << 4; + static const unsigned long MWM_FUNC_CLOSE = 1 << 5; + + struct WMHints + { + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long state; + }; + + WMHints hints; + std::memset(&hints, 0, sizeof(hints)); + hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + hints.decorations = 0; + hints.functions = 0; + + if (style & Style::Titlebar) + { + hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE | MWM_DECOR_MENU; + hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE; + } + if (style & Style::Resize) + { + hints.decorations |= MWM_DECOR_MAXIMIZE | MWM_DECOR_RESIZEH; + hints.functions |= MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; + } + if (style & Style::Close) + { + hints.decorations |= 0; + hints.functions |= MWM_FUNC_CLOSE; + } - WMSizeHints sizeHints; - std::memset(&sizeHints, 0, sizeof(sizeHints)); + XChangeProperty(m_display, + m_window, + WMHintsAtom, + WMHintsAtom, + 32, + PropModeReplace, + reinterpret_cast(&hints), + 5); + } + } // This is a hack to force some windows managers to disable resizing - // Fullscreen is bugged on Openbox. Unless size hints are set, there - // will be a region of the window that is off-screen. We try to workaround - // this by setting size hints even in fullscreen just for Openbox. - if ((!m_fullscreen || (windowManagerName == "Openbox")) && !(style & Style::Resize)) + if (!(style & Style::Resize)) { m_useSizeHints = true; - sizeHints.flags |= ((1 << 4) | (1 << 5)); - sizeHints.min_width = width; - sizeHints.max_width = width; - sizeHints.min_height = height; - sizeHints.max_height = height; + XSizeHints* sizeHints = XAllocSizeHints(); + sizeHints->flags = PMinSize | PMaxSize; + sizeHints->min_width = sizeHints->max_width = width; + sizeHints->min_height = sizeHints->max_height = height; + XSetWMNormalHints(m_display, m_window, sizeHints); + XFree(sizeHints); } - // Set the WM hints of the normal state - setWMSizeHints(sizeHints); - // Set the window's WM class (this can be used by window managers) - // The WM_CLASS property actually consists of 2 parts, - // the instance name and the class name both of which should be - // null terminated strings. - // The instance name should be something unique to this invokation + XClassHint* hint = XAllocClassHint(); + + // The instance name should be something unique to this invocation // of the application but is rarely if ever used these days. // For simplicity, we retrieve it via the base executable name. + std::string executableName = findExecutableName(); + std::vector windowInstance(executableName.size() + 1, 0); + std::copy(executableName.begin(), executableName.end(), windowInstance.begin()); + hint->res_name = &windowInstance[0]; + // The class name identifies a class of windows that // "are of the same type". We simply use the initial window name as // the class name. - std::string windowClass = findExecutableName(); - windowClass += '\0'; // Important to separate instance from class - windowClass += title.toAnsiString(); + std::string ansiTitle = title.toAnsiString(); + std::vector windowClass(ansiTitle.size() + 1, 0); + std::copy(ansiTitle.begin(), ansiTitle.end(), windowClass.begin()); + hint->res_class = &windowClass[0]; - // We add 1 to the size of the string to include the null at the end - if (!changeWindowProperty(XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, 8, windowClass.size() + 1, windowClass.c_str())) - sf::err() << "Failed to set WM_CLASS property" << std::endl; + XSetClassHint(m_display, m_window, hint); + + XFree(hint); // Set the window's name setTitle(title); @@ -554,18 +618,27 @@ WindowImplX11::~WindowImplX11() // Cleanup graphical resources cleanup(); + // Destroy icon pixmap + if(m_iconPixmap) + XFreePixmap(m_display, m_iconPixmap); + + // Destroy icon mask pixmap + if(m_iconMaskPixmap) + XFreePixmap(m_display, m_iconMaskPixmap); + // Destroy the cursor if (m_hiddenCursor) - xcb_free_cursor(m_connection, m_hiddenCursor); + XFreeCursor(m_display, m_hiddenCursor); // Destroy the input context if (m_inputContext) XDestroyIC(m_inputContext); + // Destroy the window if (m_window && !m_isExternal) { - xcb_destroy_window(m_connection, m_window); - xcb_flush(m_connection); + XDestroyWindow(m_display, m_window); + XFlush(m_display); } // Close the input method @@ -602,70 +675,31 @@ void WindowImplX11::processEvents() //////////////////////////////////////////////////////////// Vector2i WindowImplX11::getPosition() const { - ::Window topLevelWindow = m_window; - ::Window nextWindow = topLevelWindow; - - ScopedXcbPtr error(NULL); - - // Get "top level" window, i.e. the window with the root window as its parent. - while (nextWindow != m_screen->root) - { - topLevelWindow = nextWindow; - - ScopedXcbPtr treeReply(xcb_query_tree_reply( - m_connection, - xcb_query_tree( - m_connection, - topLevelWindow - ), - &error - )); - - if (error) - { - err() << "Failed to get window position (query_tree)" << std::endl; - return Vector2i(0, 0); - } - - nextWindow = treeReply->parent; - } - - ScopedXcbPtr geometryReply(xcb_get_geometry_reply( - m_connection, - xcb_get_geometry( - m_connection, - topLevelWindow - ), - &error - )); + ::Window root, child; + int localX, localY, x, y; + unsigned int width, height, border, depth; - if (error) - { - err() << "Failed to get window position (get_geometry)" << std::endl; - return Vector2i(0, 0); - } + XGetGeometry(m_display, m_window, &root, &localX, &localY, &width, &height, &border, &depth); + XTranslateCoordinates(m_display, m_window, root, localX, localY, &x, &y, &child); - return Vector2i(geometryReply->x, geometryReply->y); + return Vector2i(x, y); } //////////////////////////////////////////////////////////// void WindowImplX11::setPosition(const Vector2i& position) { - uint32_t values[] = {static_cast(position.x), static_cast(position.y)}; - xcb_configure_window(m_connection, m_window, - XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, - values); - xcb_flush(m_connection); + XMoveWindow(m_display, m_window, position.x, position.y); + XFlush(m_display); } //////////////////////////////////////////////////////////// Vector2u WindowImplX11::getSize() const { - ScopedXcbPtr reply(xcb_get_geometry_reply(m_connection, xcb_get_geometry(m_connection, m_window), NULL)); - - return Vector2u(reply->width, reply->height); + XWindowAttributes attributes; + XGetWindowAttributes(m_display, m_window, &attributes); + return Vector2u(attributes.width, attributes.height); } @@ -673,75 +707,65 @@ Vector2u WindowImplX11::getSize() const void WindowImplX11::setSize(const Vector2u& size) { // If resizing is disable for the window we have to update the size hints (required by some window managers). - if( m_useSizeHints ) { - WMSizeHints sizeHints; - std::memset(&sizeHints, 0, sizeof(sizeHints)); - - sizeHints.flags |= (1 << 4 | 1 << 5); - sizeHints.min_width = size.x; - sizeHints.max_width = size.x; - sizeHints.min_height = size.y; - sizeHints.max_height = size.y; - - setWMSizeHints(sizeHints); + if (m_useSizeHints) + { + XSizeHints* sizeHints = XAllocSizeHints(); + sizeHints->flags = PMinSize | PMaxSize; + sizeHints->min_width = sizeHints->max_width = size.x; + sizeHints->min_height = sizeHints->max_height = size.y; + XSetWMNormalHints(m_display, m_window, sizeHints); + XFree(sizeHints); } - uint32_t values[] = {size.x, size.y}; - - ScopedXcbPtr configureWindowError(xcb_request_check( - m_connection, - xcb_configure_window( - m_connection, - m_window, - XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, - values - ) - )); - - if (configureWindowError) - err() << "Failed to set window size" << std::endl; - - xcb_flush(m_connection); + XResizeWindow(m_display, m_window, size.x, size.y); + XFlush(m_display); } //////////////////////////////////////////////////////////// void WindowImplX11::setTitle(const String& title) { - // XCB takes UTF-8-encoded strings. - xcb_atom_t utf8StringType = getAtom("UTF8_STRING"); - - if (!utf8StringType) - utf8StringType = XCB_ATOM_STRING; - - std::string utf8String; - Utf<32>::toUtf8(title.begin(), title.end(), std::back_inserter(utf8String)); - - if (!changeWindowProperty(XCB_ATOM_WM_NAME, utf8StringType, 8, utf8String.length(), utf8String.c_str())) - err() << "Failed to set window title" << std::endl; - - if (!changeWindowProperty(XCB_ATOM_WM_ICON_NAME, utf8StringType, 8, utf8String.length(), utf8String.c_str())) - err() << "Failed to set WM_ICON_NAME property" << std::endl; - - if (ewmhSupported()) - { - xcb_atom_t netWmName = getAtom("_NET_WM_NAME", true); - xcb_atom_t netWmIconName = getAtom("_NET_WM_ICON_NAME", true); - - if (utf8StringType && netWmName) - { - if (!changeWindowProperty(netWmName, utf8StringType, 8, utf8String.length(), utf8String.c_str())) - err() << "Failed to set _NET_WM_NAME property" << std::endl; - } - - if (utf8StringType && netWmIconName) - { - if (!changeWindowProperty(netWmIconName, utf8StringType, 8, utf8String.length(), utf8String.c_str())) - err() << "Failed to set _NET_WM_ICON_NAME property" << std::endl; - } - } - - xcb_flush(m_connection); + // Bare X11 has no Unicode window title support. + // There is however an option to tell the window manager your Unicode title via hints. + + // Convert to UTF-8 encoding. + std::basic_string utf8Title; + Utf32::toUtf8(title.begin(), title.end(), std::back_inserter(utf8Title)); + + Atom useUtf8 = getAtom("UTF8_STRING", false); + + // Set the _NET_WM_NAME atom, which specifies a UTF-8 encoded window title. + Atom wmName = getAtom("_NET_WM_NAME", false); + XChangeProperty(m_display, m_window, wmName, useUtf8, 8, + PropModeReplace, utf8Title.c_str(), utf8Title.size()); + + // Set the _NET_WM_ICON_NAME atom, which specifies a UTF-8 encoded window title. + Atom wmIconName = getAtom("_NET_WM_ICON_NAME", false); + XChangeProperty(m_display, m_window, wmIconName, useUtf8, 8, + PropModeReplace, utf8Title.c_str(), utf8Title.size()); + + // Set the non-Unicode title as a fallback for window managers who don't support _NET_WM_NAME. + #ifdef X_HAVE_UTF8_STRING + Xutf8SetWMProperties(m_display, + m_window, + title.toAnsiString().c_str(), + title.toAnsiString().c_str(), + NULL, + 0, + NULL, + NULL, + NULL); + #else + XmbSetWMProperties(m_display, + m_window, + title.toAnsiString().c_str(), + title.toAnsiString().c_str(), + NULL, + 0, + NULL, + NULL, + NULL); + #endif } @@ -749,7 +773,8 @@ void WindowImplX11::setTitle(const String& title) void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8* pixels) { // X11 wants BGRA pixels: swap red and blue channels - Uint8 iconPixels[width * height * 4]; + // Note: this memory will be freed by XDestroyImage + Uint8* iconPixels = static_cast(std::malloc(width * height * 4)); for (std::size_t i = 0; i < width * height; ++i) { iconPixels[i * 4 + 0] = pixels[i * 4 + 2]; @@ -759,89 +784,31 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 } // Create the icon pixmap - xcb_pixmap_t iconPixmap = xcb_generate_id(m_connection); - - ScopedXcbPtr createPixmapError(xcb_request_check( - m_connection, - xcb_create_pixmap_checked( - m_connection, - m_screen->root_depth, - iconPixmap, - m_screen->root, - width, - height - ) - )); - - if (createPixmapError) + Visual* defVisual = DefaultVisual(m_display, m_screen); + unsigned int defDepth = DefaultDepth(m_display, m_screen); + XImage* iconImage = XCreateImage(m_display, defVisual, defDepth, ZPixmap, 0, (char*)iconPixels, width, height, 32, 0); + if (!iconImage) { - err() << "Failed to set the window's icon (create_pixmap): "; - err() << "Error code " << static_cast(createPixmapError->error_code) << std::endl; + err() << "Failed to set the window's icon" << std::endl; return; } - xcb_gcontext_t iconGC = xcb_generate_id(m_connection); - - ScopedXcbPtr createGcError(xcb_request_check( - m_connection, - xcb_create_gc( - m_connection, - iconGC, - iconPixmap, - 0, - NULL - ) - )); - - if (createGcError) - { - err() << "Failed to set the window's icon (create_gc): "; - err() << "Error code " << static_cast(createGcError->error_code) << std::endl; - return; - } + if(m_iconPixmap) + XFreePixmap(m_display, m_iconPixmap); - ScopedXcbPtr putImageError(xcb_request_check( - m_connection, - xcb_put_image_checked( - m_connection, - XCB_IMAGE_FORMAT_Z_PIXMAP, - iconPixmap, - iconGC, - width, - height, - 0, - 0, - 0, - m_screen->root_depth, - sizeof(iconPixels), - iconPixels - ) - )); - - ScopedXcbPtr freeGcError(xcb_request_check( - m_connection, - xcb_free_gc( - m_connection, - iconGC - ) - )); - - if (freeGcError) - { - err() << "Failed to free icon GC: "; - err() << "Error code " << static_cast(freeGcError->error_code) << std::endl; - } + if(m_iconMaskPixmap) + XFreePixmap(m_display, m_iconMaskPixmap); - if (putImageError) - { - err() << "Failed to set the window's icon (put_image): "; - err() << "Error code " << static_cast(putImageError->error_code) << std::endl; - return; - } + m_iconPixmap = XCreatePixmap(m_display, RootWindow(m_display, m_screen), width, height, defDepth); + XGCValues values; + GC iconGC = XCreateGC(m_display, m_iconPixmap, 0, &values); + XPutImage(m_display, m_iconPixmap, iconGC, iconImage, 0, 0, 0, 0, width, height); + XFreeGC(m_display, iconGC); + XDestroyImage(iconImage); // Create the mask pixmap (must have 1 bit depth) std::size_t pitch = (width + 7) / 8; - static std::vector maskPixels(pitch * height, 0); + std::vector maskPixels(pitch * height, 0); for (std::size_t j = 0; j < height; ++j) { for (std::size_t i = 0; i < pitch; ++i) @@ -856,43 +823,44 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 } } } - - xcb_pixmap_t maskPixmap = xcb_create_pixmap_from_bitmap_data( - m_connection, - m_window, - reinterpret_cast(&maskPixels[0]), - width, - height, - 1, - 0, - 1, - NULL - ); + m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, (char*)&maskPixels[0], width, height, 1, 0, 1); // Send our new icon to the window through the WMHints - WMHints hints; - std::memset(&hints, 0, sizeof(hints)); - hints.flags |= ((1 << 2) | (1 << 5)); - hints.icon_pixmap = iconPixmap; - hints.icon_mask = maskPixmap; - - setWMHints(hints); + XWMHints* hints = XAllocWMHints(); + hints->flags = IconPixmapHint | IconMaskHint; + hints->icon_pixmap = m_iconPixmap; + hints->icon_mask = m_iconMaskPixmap; + XSetWMHints(m_display, m_window, hints); + XFree(hints); - xcb_flush(m_connection); + // ICCCM wants BGRA pixels: swap red and blue channels + // ICCCM also wants the first 2 unsigned 32-bit values to be width and height + std::vector icccmIconPixels(2 + width * height, 0); + unsigned long* ptr = &icccmIconPixels[0]; - ScopedXcbPtr freePixmapError(xcb_request_check( - m_connection, - xcb_free_pixmap_checked( - m_connection, - iconPixmap - ) - )); + *ptr++ = width; + *ptr++ = height; - if (freePixmapError) + for (std::size_t i = 0; i < width * height; ++i) { - err() << "Failed to free icon pixmap: "; - err() << "Error code " << static_cast(freePixmapError->error_code) << std::endl; + *ptr++ = (pixels[i * 4 + 2] << 0 ) | + (pixels[i * 4 + 1] << 8 ) | + (pixels[i * 4 + 0] << 16) | + (pixels[i * 4 + 3] << 24); } + + Atom netWmIcon = getAtom("_NET_WM_ICON"); + + XChangeProperty(m_display, + m_window, + netWmIcon, + XA_CARDINAL, + 32, + PropModeReplace, + reinterpret_cast(&icccmIconPixels[0]), + 2 + width * height); + + XFlush(m_display); } @@ -901,54 +869,68 @@ void WindowImplX11::setVisible(bool visible) { if (visible) { - ScopedXcbPtr error(xcb_request_check( - m_connection, - xcb_map_window( - m_connection, - m_window - ) - )); - - if (error) - err() << "Failed to change window visibility" << std::endl; + XMapWindow(m_display, m_window); + + XFlush(m_display); + + // Before continuing, make sure the WM has + // internally marked the window as viewable + while (!m_windowMapped && !m_isExternal) + processEvents(); } else { - ScopedXcbPtr error(xcb_request_check( - m_connection, - xcb_unmap_window( - m_connection, - m_window - ) - )); - - if (error) - err() << "Failed to change window visibility" << std::endl; - } + XUnmapWindow(m_display, m_window); + + XFlush(m_display); - xcb_flush(m_connection); + // Before continuing, make sure the WM has + // internally marked the window as unviewable + while (m_windowMapped && !m_isExternal) + processEvents(); + } } //////////////////////////////////////////////////////////// void WindowImplX11::setMouseCursorVisible(bool visible) { - const uint32_t values = visible ? XCB_NONE : m_hiddenCursor; - - ScopedXcbPtr error(xcb_request_check( - m_connection, - xcb_change_window_attributes( - m_connection, - m_window, - XCB_CW_CURSOR, - &values - ) - )); - - if (error) - err() << "Failed to change mouse cursor visibility" << std::endl; - - xcb_flush(m_connection); + XDefineCursor(m_display, m_window, visible ? None : m_hiddenCursor); + XFlush(m_display); +} + + +//////////////////////////////////////////////////////////// +void WindowImplX11::setMouseCursorGrabbed(bool grabbed) +{ + // This has no effect in fullscreen mode + if (m_fullscreen || (m_cursorGrabbed == grabbed)) + return; + + if (grabbed) + { + // Try multiple times to grab the cursor + for (unsigned int trial = 0; trial < maxTrialsCount; ++trial) + { + int result = XGrabPointer(m_display, m_window, True, None, GrabModeAsync, GrabModeAsync, m_window, None, CurrentTime); + + if (result == GrabSuccess) + { + m_cursorGrabbed = true; + break; + } + + // The cursor grab failed, trying again after a small sleep + sf::sleep(sf::milliseconds(50)); + } + + if (!m_cursorGrabbed) + err() << "Failed to grab mouse cursor" << std::endl; + } + else + { + XUngrabPointer(m_display, CurrentTime); + } } @@ -979,26 +961,16 @@ void WindowImplX11::requestFocus() } } - ScopedXcbPtr error(NULL); - // Check if window is viewable (not on other desktop, ...) // TODO: Check also if minimized - ScopedXcbPtr attributes(xcb_get_window_attributes_reply( - m_connection, - xcb_get_window_attributes( - m_connection, - m_window - ), - &error - )); - - if (error || !attributes) + XWindowAttributes attributes; + if (XGetWindowAttributes(m_display, m_window, &attributes) == 0) { - err() << "Failed to check if window is viewable while requesting focus" << std::endl; + sf::err() << "Failed to check if window is viewable while requesting focus" << std::endl; return; // error getting attribute } - bool windowViewable = (attributes->map_state == XCB_MAP_STATE_VIEWABLE); + bool windowViewable = (attributes.map_state == IsViewable); if (sfmlWindowFocused && windowViewable) { @@ -1008,31 +980,16 @@ void WindowImplX11::requestFocus() } else { - // Get current WM hints. - ScopedXcbPtr hintsReply(xcb_get_property_reply( - m_connection, - xcb_get_property(m_connection, 0, m_window, XCB_ATOM_WM_HINTS, XCB_ATOM_WM_HINTS, 0, 9), - &error - )); - - if (error || !hintsReply) - { - err() << "Failed to get WM hints while requesting focus" << std::endl; - return; - } - - WMHints* hints = reinterpret_cast(xcb_get_property_value(hintsReply.get())); - - if (!hints) - { - err() << "Failed to get WM hints while requesting focus" << std::endl; - return; - } - - // Even if no hints were returned, we can simply set the proper flags we need and go on. This is - // different from Xlib where XAllocWMHints() has to be called. - hints->flags |= (1 << 8); - setWMHints(*hints); + // Otherwise: display urgency hint (flashing application logo) + // Ensure WM hints exist, allocate if necessary + XWMHints* hints = XGetWMHints(m_display, m_window); + if (hints == NULL) + hints = XAllocWMHints(); + + // Add urgency (notification) flag to hints + hints->flags |= XUrgencyHint; + XSetWMHints(m_display, m_window, hints); + XFree(hints); } } @@ -1040,91 +997,59 @@ void WindowImplX11::requestFocus() //////////////////////////////////////////////////////////// bool WindowImplX11::hasFocus() const { - ScopedXcbPtr error(NULL); - - ScopedXcbPtr reply(xcb_get_input_focus_reply( - m_connection, - xcb_get_input_focus_unchecked( - m_connection - ), - &error - )); - - if (error) - err() << "Failed to check if window has focus" << std::endl; + ::Window focusedWindow = 0; + int revertToReturn = 0; + XGetInputFocus(m_display, &focusedWindow, &revertToReturn); - return (reply->focus == m_window); + return (m_window == focusedWindow); } //////////////////////////////////////////////////////////// void WindowImplX11::grabFocus() { - xcb_atom_t netActiveWindow = XCB_ATOM_NONE; + Atom netActiveWindow = None; if (ewmhSupported()) netActiveWindow = getAtom("_NET_ACTIVE_WINDOW"); + // Only try to grab focus if the window is mapped + XWindowAttributes attr; + + XGetWindowAttributes(m_display, m_window, &attr); + + if (attr.map_state == IsUnmapped) + return; + if (netActiveWindow) { - xcb_client_message_event_t event; + XEvent event; std::memset(&event, 0, sizeof(event)); - event.response_type = XCB_CLIENT_MESSAGE; - event.window = m_window; - event.format = 32; - event.sequence = 0; - event.type = netActiveWindow; - event.data.data32[0] = 1; // Normal application - event.data.data32[1] = XCB_CURRENT_TIME; - event.data.data32[2] = 0; // We don't know the currently active window - - ScopedXcbPtr activeWindowError(xcb_request_check( - m_connection, - xcb_send_event_checked( - m_connection, - 0, - XCBDefaultRootWindow(m_connection), - XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, - reinterpret_cast(&event) - ) - )); - - if (activeWindowError) + event.type = ClientMessage; + event.xclient.window = m_window; + event.xclient.format = 32; + event.xclient.message_type = netActiveWindow; + event.xclient.data.l[0] = 1; // Normal application + event.xclient.data.l[1] = m_lastInputTime; + event.xclient.data.l[2] = 0; // We don't know the currently active window + + int result = XSendEvent(m_display, + DefaultRootWindow(m_display), + False, + SubstructureNotifyMask | SubstructureRedirectMask, + &event); + + XFlush(m_display); + + if (!result) err() << "Setting fullscreen failed, could not send \"_NET_ACTIVE_WINDOW\" event" << std::endl; } else { - ScopedXcbPtr setInputFocusError(xcb_request_check( - m_connection, - xcb_set_input_focus( - m_connection, - XCB_INPUT_FOCUS_POINTER_ROOT, - m_window, - XCB_CURRENT_TIME - ) - )); - - if (setInputFocusError) - { - err() << "Failed to change active window (set_input_focus)" << std::endl; - return; - } - - const uint32_t values[] = {XCB_STACK_MODE_ABOVE}; - - ScopedXcbPtr configureWindowError(xcb_request_check( - m_connection, - xcb_configure_window( - m_connection, - m_window, - XCB_CONFIG_WINDOW_STACK_MODE, - values - ) - )); - - if (configureWindowError) - err() << "Failed to change active window (configure_window)" << std::endl; + XRaiseWindow(m_display, m_window); + XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime); + XFlush(m_display); } } @@ -1136,46 +1061,19 @@ void WindowImplX11::setVideoMode(const VideoMode& mode) if (mode == VideoMode::getDesktopMode()) return; - ScopedXcbPtr error(NULL); - - // Check if the RandR extension is present - const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(m_connection, &xcb_randr_id); - - if (!randrExt || !randrExt->present) + // Check if the XRandR extension is present + int version; + if (!XQueryExtension(m_display, "RANDR", &version, &version, &version)) { - // RandR extension is not supported: we cannot use fullscreen mode + // XRandR extension is not supported: we cannot use fullscreen mode err() << "Fullscreen is not supported, switching to window mode" << std::endl; return; } - // Load RandR and check its version - ScopedXcbPtr randrVersion(xcb_randr_query_version_reply( - m_connection, - xcb_randr_query_version( - m_connection, - 1, - 1 - ), - &error - )); - - if (error) - { - err() << "Failed to load RandR, switching to window mode" << std::endl; - return; - } - // Get the current configuration - ScopedXcbPtr config(xcb_randr_get_screen_info_reply( - m_connection, - xcb_randr_get_screen_info( - m_connection, - m_screen->root - ), - &error - )); - - if (error || !config) + XRRScreenConfiguration* config = XRRGetScreenInfo(m_display, RootWindow(m_display, m_screen)); + + if (!config) { // Failed to get the screen configuration err() << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl; @@ -1183,52 +1081,34 @@ void WindowImplX11::setVideoMode(const VideoMode& mode) } // Save the current video mode before we switch to fullscreen - m_oldVideoMode = *config.get(); + Rotation currentRotation; + m_oldVideoMode = XRRConfigCurrentConfiguration(config, ¤tRotation); // Get the available screen sizes - xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); - - if (!sizes || !config->nSizes) - { - err() << "Failed to get the fullscreen sizes, switching to window mode" << std::endl; - return; - } + int nbSizes; + XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); // Search for a matching size - for (int i = 0; i < config->nSizes; ++i) + for (int i = 0; (sizes && i < nbSizes); ++i) { - if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || - config->rotation == XCB_RANDR_ROTATION_ROTATE_270) + XRRConfigRotations(config, ¤tRotation); + + if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270) std::swap(sizes[i].height, sizes[i].width); - if ((sizes[i].width == static_cast(mode.width)) && - (sizes[i].height == static_cast(mode.height))) + if ((sizes[i].width == static_cast(mode.width)) && (sizes[i].height == static_cast(mode.height))) { // Switch to fullscreen mode - ScopedXcbPtr setScreenConfig(xcb_randr_set_screen_config_reply( - m_connection, - xcb_randr_set_screen_config( - m_connection, - config->root, - XCB_CURRENT_TIME, - config->config_timestamp, - i, - config->rotation, - config->rate - ), - &error - )); - - if (error) - err() << "Failed to set new screen configuration" << std::endl; + XRRSetScreenConfig(m_display, config, RootWindow(m_display, m_screen), i, currentRotation, CurrentTime); // Set "this" as the current fullscreen window fullscreenWindow = this; - return; + break; } } - err() << "Failed to find matching fullscreen size, switching to window mode" << std::endl; + // Free the configuration instance + XRRFreeScreenConfigInfo(config); } @@ -1238,25 +1118,19 @@ void WindowImplX11::resetVideoMode() if (fullscreenWindow == this) { // Get current screen info - ScopedXcbPtr error(NULL); - - // Reset the video mode - ScopedXcbPtr setScreenConfig(xcb_randr_set_screen_config_reply( - m_connection, - xcb_randr_set_screen_config( - m_connection, - m_oldVideoMode.root, - XCB_CURRENT_TIME, - m_oldVideoMode.config_timestamp, - m_oldVideoMode.sizeID, - m_oldVideoMode.rotation, - m_oldVideoMode.rate - ), - &error - )); - - if (error) - err() << "Failed to reset old screen configuration" << std::endl; + XRRScreenConfiguration* config = XRRGetScreenInfo(m_display, RootWindow(m_display, m_screen)); + if (config) + { + // Get the current rotation + Rotation currentRotation; + XRRConfigCurrentConfiguration(config, ¤tRotation); + + // Reset the video mode + XRRSetScreenConfig(m_display, config, RootWindow(m_display, m_screen), m_oldVideoMode, currentRotation, CurrentTime); + + // Free the configuration instance + XRRFreeScreenConfigInfo(config); + } // Reset the fullscreen window fullscreenWindow = NULL; @@ -1271,19 +1145,24 @@ void WindowImplX11::switchToFullscreen() if (ewmhSupported()) { - xcb_atom_t netWmBypassCompositor = getAtom("_NET_WM_BYPASS_COMPOSITOR"); + Atom netWmBypassCompositor = getAtom("_NET_WM_BYPASS_COMPOSITOR"); if (netWmBypassCompositor) { - static const Uint32 bypassCompositor = 1; - - // Not being able to bypass the compositor is not a fatal error - if (!changeWindowProperty(netWmBypassCompositor, XCB_ATOM_CARDINAL, 32, 1, &bypassCompositor)) - err() << "xcb_change_property failed, unable to set _NET_WM_BYPASS_COMPOSITOR" << std::endl; + static const unsigned long bypassCompositor = 1; + + XChangeProperty(m_display, + m_window, + netWmBypassCompositor, + XA_CARDINAL, + 32, + PropModeReplace, + reinterpret_cast(&bypassCompositor), + 1); } - xcb_atom_t netWmState = getAtom("_NET_WM_STATE", true); - xcb_atom_t netWmStateFullscreen = getAtom("_NET_WM_STATE_FULLSCREEN", true); + Atom netWmState = getAtom("_NET_WM_STATE", true); + Atom netWmStateFullscreen = getAtom("_NET_WM_STATE_FULLSCREEN", true); if (!netWmState || !netWmStateFullscreen) { @@ -1291,32 +1170,26 @@ void WindowImplX11::switchToFullscreen() return; } - xcb_client_message_event_t event; + XEvent event; std::memset(&event, 0, sizeof(event)); - event.response_type = XCB_CLIENT_MESSAGE; - event.window = m_window; - event.format = 32; - event.sequence = 0; - event.type = netWmState; - event.data.data32[0] = 1; // _NET_WM_STATE_ADD - event.data.data32[1] = netWmStateFullscreen; - event.data.data32[2] = 0; // No second property - event.data.data32[3] = 1; // Normal window - - ScopedXcbPtr wmStateError(xcb_request_check( - m_connection, - xcb_send_event_checked( - m_connection, - 0, - XCBDefaultRootWindow(m_connection), - XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, - reinterpret_cast(&event) - ) - )); - - if (wmStateError) - err() << "Setting fullscreen failed. Could not send \"_NET_WM_STATE\" event" << std::endl; + event.type = ClientMessage; + event.xclient.window = m_window; + event.xclient.format = 32; + event.xclient.message_type = netWmState; + event.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD + event.xclient.data.l[1] = netWmStateFullscreen; + event.xclient.data.l[2] = 0; // No second property + event.xclient.data.l[3] = 1; // Normal window + + int result = XSendEvent(m_display, + DefaultRootWindow(m_display), + False, + SubstructureNotifyMask | SubstructureRedirectMask, + &event); + + if (!result) + err() << "Setting fullscreen failed, could not send \"_NET_WM_STATE\" event" << std::endl; } } @@ -1324,8 +1197,8 @@ void WindowImplX11::switchToFullscreen() //////////////////////////////////////////////////////////// void WindowImplX11::setProtocols() { - xcb_atom_t wmProtocols = getAtom("WM_PROTOCOLS"); - xcb_atom_t wmDeleteWindow = getAtom("WM_DELETE_WINDOW"); + Atom wmProtocols = getAtom("WM_PROTOCOLS"); + Atom wmDeleteWindow = getAtom("WM_DELETE_WINDOW"); if (!wmProtocols) { @@ -1333,7 +1206,7 @@ void WindowImplX11::setProtocols() return; } - std::vector atoms; + std::vector atoms; if (wmDeleteWindow) { @@ -1344,8 +1217,8 @@ void WindowImplX11::setProtocols() err() << "Failed to request WM_DELETE_WINDOW atom." << std::endl; } - xcb_atom_t netWmPing = XCB_ATOM_NONE; - xcb_atom_t netWmPid = XCB_ATOM_NONE; + Atom netWmPing = None; + Atom netWmPid = None; if (ewmhSupported()) { @@ -1353,20 +1226,32 @@ void WindowImplX11::setProtocols() netWmPid = getAtom("_NET_WM_PID", true); } - ScopedXcbPtr error(NULL); - if (netWmPing && netWmPid) { - uint32_t pid = getpid(); - - if (changeWindowProperty(netWmPid, XCB_ATOM_CARDINAL, 32, 1, &pid)) - atoms.push_back(netWmPing); + const long pid = getpid(); + + XChangeProperty(m_display, + m_window, + netWmPid, + XA_CARDINAL, + 32, + PropModeReplace, + reinterpret_cast(&pid), + 1); + + atoms.push_back(netWmPing); } if (!atoms.empty()) { - if (!changeWindowProperty(wmProtocols, XCB_ATOM_ATOM, 32, atoms.size(), &atoms[0])) - err() << "Failed to set window protocols" << std::endl; + XChangeProperty(m_display, + m_window, + wmProtocols, + XA_ATOM, + 32, + PropModeReplace, + reinterpret_cast(&atoms[0]), + atoms.size()); } else { @@ -1375,122 +1260,6 @@ void WindowImplX11::setProtocols() } -//////////////////////////////////////////////////////////// -void WindowImplX11::setMotifHints(unsigned long style) -{ - ScopedXcbPtr error(NULL); - - static const std::string MOTIF_WM_HINTS = "_MOTIF_WM_HINTS"; - ScopedXcbPtr hintsAtomReply(xcb_intern_atom_reply( - m_connection, - xcb_intern_atom( - m_connection, - 0, - MOTIF_WM_HINTS.size(), - MOTIF_WM_HINTS.c_str() - ), - &error - )); - - if (!error && hintsAtomReply) - { - static const unsigned long MWM_HINTS_FUNCTIONS = 1 << 0; - static const unsigned long MWM_HINTS_DECORATIONS = 1 << 1; - - //static const unsigned long MWM_DECOR_ALL = 1 << 0; - static const unsigned long MWM_DECOR_BORDER = 1 << 1; - static const unsigned long MWM_DECOR_RESIZEH = 1 << 2; - static const unsigned long MWM_DECOR_TITLE = 1 << 3; - static const unsigned long MWM_DECOR_MENU = 1 << 4; - static const unsigned long MWM_DECOR_MINIMIZE = 1 << 5; - static const unsigned long MWM_DECOR_MAXIMIZE = 1 << 6; - - //static const unsigned long MWM_FUNC_ALL = 1 << 0; - static const unsigned long MWM_FUNC_RESIZE = 1 << 1; - static const unsigned long MWM_FUNC_MOVE = 1 << 2; - static const unsigned long MWM_FUNC_MINIMIZE = 1 << 3; - static const unsigned long MWM_FUNC_MAXIMIZE = 1 << 4; - static const unsigned long MWM_FUNC_CLOSE = 1 << 5; - - struct MotifWMHints - { - uint32_t flags; - uint32_t functions; - uint32_t decorations; - int32_t inputMode; - uint32_t state; - }; - - MotifWMHints hints; - hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; - hints.decorations = 0; - hints.functions = 0; - hints.inputMode = 0; - hints.state = 0; - - if (style & Style::Titlebar) - { - hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE | MWM_DECOR_MENU; - hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE; - } - if (style & Style::Resize) - { - hints.decorations |= MWM_DECOR_MAXIMIZE | MWM_DECOR_RESIZEH; - hints.functions |= MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; - } - if (style & Style::Close) - { - hints.decorations |= 0; - hints.functions |= MWM_FUNC_CLOSE; - } - - if (!changeWindowProperty(hintsAtomReply->atom, hintsAtomReply->atom, 32, 5, &hints)) - err() << "xcb_change_property failed, could not set window hints" << std::endl; - } - else - { - err() << "Failed to request _MOTIF_WM_HINTS atom." << std::endl; - } -} - - -//////////////////////////////////////////////////////////// -void WindowImplX11::setWMHints(const WMHints& hints) -{ - if (!changeWindowProperty(XCB_ATOM_WM_HINTS, XCB_ATOM_WM_HINTS, 32, sizeof(hints) / 4, &hints)) - sf::err() << "Failed to set WM_HINTS property" << std::endl; -} - - -//////////////////////////////////////////////////////////// -void WindowImplX11::setWMSizeHints(const WMSizeHints& hints) -{ - if (!changeWindowProperty(XCB_ATOM_WM_NORMAL_HINTS, XCB_ATOM_WM_SIZE_HINTS, 32, sizeof(hints) / 4, &hints)) - sf::err() << "Failed to set XCB_ATOM_WM_NORMAL_HINTS property" << std::endl; -} - - -//////////////////////////////////////////////////////////// -bool WindowImplX11::changeWindowProperty(xcb_atom_t property, xcb_atom_t type, uint8_t format, uint32_t length, const void* data) -{ - ScopedXcbPtr error(xcb_request_check( - m_connection, - xcb_change_property_checked( - m_connection, - XCB_PROP_MODE_REPLACE, - m_window, - property, - type, - format, - length, - data - ) - )); - - return !error; -} - - //////////////////////////////////////////////////////////// void WindowImplX11::initialize() { @@ -1499,16 +1268,14 @@ void WindowImplX11::initialize() if (m_inputMethod) { - m_inputContext = XCreateIC( - m_inputMethod, - XNClientWindow, - m_window, - XNFocusWindow, - m_window, - XNInputStyle, - XIMPreeditNothing | XIMStatusNothing, - reinterpret_cast(NULL) - ); + m_inputContext = XCreateIC(m_inputMethod, + XNClientWindow, + m_window, + XNFocusWindow, + m_window, + XNInputStyle, + XIMPreeditNothing | XIMStatusNothing, + reinterpret_cast(NULL)); } else { @@ -1518,6 +1285,21 @@ void WindowImplX11::initialize() if (!m_inputContext) err() << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl; + Atom wmWindowType = getAtom("_NET_WM_WINDOW_TYPE", false); + Atom wmWindowTypeNormal = getAtom("_NET_WM_WINDOW_TYPE_NORMAL", false); + + if (wmWindowType && wmWindowTypeNormal) + { + XChangeProperty(m_display, + m_window, + wmWindowType, + XA_ATOM, + 32, + PropModeReplace, + reinterpret_cast(&wmWindowTypeNormal), + 1); + } + // Show the window setVisible(true); @@ -1528,7 +1310,7 @@ void WindowImplX11::initialize() createHiddenCursor(); // Flush the commands queue - xcb_flush(m_connection); + XFlush(m_display); // Add this window to the global list of windows (required for focus request) Lock lock(allWindowsMutex); @@ -1537,60 +1319,46 @@ void WindowImplX11::initialize() //////////////////////////////////////////////////////////// -void WindowImplX11::createHiddenCursor() +void WindowImplX11::updateLastInputTime(::Time time) { - xcb_pixmap_t cursorPixmap = xcb_generate_id(m_connection); - - // Create the cursor's pixmap (1x1 pixels) - ScopedXcbPtr createPixmapError(xcb_request_check( - m_connection, - xcb_create_pixmap( - m_connection, - 1, - cursorPixmap, - m_window, - 1, - 1 - ) - )); - - if (createPixmapError) + if (time && (time != m_lastInputTime)) { - err() << "Failed to create pixmap for hidden cursor" << std::endl; - return; + Atom netWmUserTime = getAtom("_NET_WM_USER_TIME", true); + + if(netWmUserTime) + { + XChangeProperty(m_display, + m_window, + netWmUserTime, + XA_CARDINAL, + 32, + PropModeReplace, + reinterpret_cast(&time), + 1); + } + + m_lastInputTime = time; } +} - m_hiddenCursor = xcb_generate_id(m_connection); + +//////////////////////////////////////////////////////////// +void WindowImplX11::createHiddenCursor() +{ + // Create the cursor's pixmap (1x1 pixels) + Pixmap cursorPixmap = XCreatePixmap(m_display, m_window, 1, 1, 1); + GC graphicsContext = XCreateGC(m_display, cursorPixmap, 0, NULL); + XDrawPoint(m_display, cursorPixmap, graphicsContext, 0, 0); + XFreeGC(m_display, graphicsContext); // Create the cursor, using the pixmap as both the shape and the mask of the cursor - ScopedXcbPtr createCursorError(xcb_request_check( - m_connection, - xcb_create_cursor( - m_connection, - m_hiddenCursor, - cursorPixmap, - cursorPixmap, - 0, 0, 0, // Foreground RGB color - 0, 0, 0, // Background RGB color - 0, // X - 0 // Y - ) - )); - - if (createCursorError) - err() << "Failed to create hidden cursor" << std::endl; + XColor color; + color.flags = DoRed | DoGreen | DoBlue; + color.red = color.blue = color.green = 0; + m_hiddenCursor = XCreatePixmapCursor(m_display, cursorPixmap, cursorPixmap, &color, &color, 0, 0); // We don't need the pixmap any longer, free it - ScopedXcbPtr freePixmapError(xcb_request_check( - m_connection, - xcb_free_pixmap( - m_connection, - cursorPixmap - ) - )); - - if (freePixmapError) - err() << "Failed to free pixmap for hidden cursor" << std::endl; + XFreePixmap(m_display, cursorPixmap); } @@ -1661,38 +1429,42 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if (m_inputContext) XSetICFocus(m_inputContext); - Event event; - event.type = Event::GainedFocus; - pushEvent(event); + // Grab cursor + if (m_cursorGrabbed) + { + // Try multiple times to grab the cursor + for (unsigned int trial = 0; trial < maxTrialsCount; ++trial) + { + int result = XGrabPointer(m_display, m_window, True, None, GrabModeAsync, GrabModeAsync, m_window, None, CurrentTime); - // If the window has been previously marked urgent (notification) as a result of a focus request, undo that - ScopedXcbPtr error(NULL); + if (result == GrabSuccess) + { + m_cursorGrabbed = true; + break; + } - ScopedXcbPtr hintsReply(xcb_get_property_reply( - m_connection, - xcb_get_property(m_connection, 0, m_window, XCB_ATOM_WM_HINTS, XCB_ATOM_WM_HINTS, 0, 9), - &error - )); + // The cursor grab failed, trying again after a small sleep + sf::sleep(sf::milliseconds(50)); + } - if (error || !hintsReply) - { - err() << "Failed to get WM hints in XCB_FOCUS_IN" << std::endl; - break; + if (!m_cursorGrabbed) + err() << "Failed to grab mouse cursor" << std::endl; } - WMHints* hints = reinterpret_cast(xcb_get_property_value(hintsReply.get())); + Event event; + event.type = Event::GainedFocus; + pushEvent(event); - if (!hints) + // If the window has been previously marked urgent (notification) as a result of a focus request, undo that + XWMHints* hints = XGetWMHints(m_display, m_window); + if (hints != NULL) { - err() << "Failed to get WM hints in XCB_FOCUS_IN" << std::endl; - break; + // Remove urgency (notification) flag from hints + hints->flags &= ~XUrgencyHint; + XSetWMHints(m_display, m_window, hints); + XFree(hints); } - // Remove urgency (notification) flag from hints - hints->flags &= ~(1 << 8); - - setWMHints(*hints); - break; } @@ -1703,6 +1475,10 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if (m_inputContext) XUnsetICFocus(m_inputContext); + // Release cursor + if (m_cursorGrabbed) + XUngrabPointer(m_display, CurrentTime); + Event event; event.type = Event::LostFocus; pushEvent(event); @@ -1730,13 +1506,13 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Close event case ClientMessage: { - static xcb_atom_t wmProtocols = getAtom("WM_PROTOCOLS"); + static Atom wmProtocols = getAtom("WM_PROTOCOLS"); // Handle window manager protocol messages we support if (windowEvent.xclient.message_type == wmProtocols) { - static xcb_atom_t wmDeleteWindow = getAtom("WM_DELETE_WINDOW"); - static xcb_atom_t netWmPing = ewmhSupported() ? getAtom("_NET_WM_PING", true) : XCB_ATOM_NONE; + static Atom wmDeleteWindow = getAtom("WM_DELETE_WINDOW"); + static Atom netWmPing = ewmhSupported() ? getAtom("_NET_WM_PING", true) : None; if ((windowEvent.xclient.format == 32) && (windowEvent.xclient.data.l[0]) == static_cast(wmDeleteWindow)) { @@ -1748,9 +1524,9 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) else if (netWmPing && (windowEvent.xclient.format == 32) && (windowEvent.xclient.data.l[0]) == static_cast(netWmPing)) { // Handle the _NET_WM_PING message, send pong back to WM to show that we are responsive - windowEvent.xclient.window = XCBDefaultRootWindow(m_connection); + windowEvent.xclient.window = DefaultRootWindow(m_display); - XSendEvent(m_display, windowEvent.xclient.window, False, SubstructureNotifyMask | SubstructureRedirectMask, &windowEvent); + XSendEvent(m_display, DefaultRootWindow(m_display), False, SubstructureNotifyMask | SubstructureRedirectMask, &windowEvent); } } break; @@ -1759,17 +1535,23 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Key down event case KeyPress: { - // Get the keysym of the key that has been pressed - static XComposeStatus keyboard; - char buffer[32]; - KeySym symbol; - XLookupString(&windowEvent.xkey, buffer, sizeof(buffer), &symbol, &keyboard); + Keyboard::Key key = Keyboard::Unknown; + + // Try each KeySym index (modifier group) until we get a match + for (int i = 0; i < 4; ++i) + { + // Get the SFML keyboard code from the keysym of the key that has been pressed + key = keysymToSF(XLookupKeysym(&windowEvent.xkey, i)); + + if (key != Keyboard::Unknown) + break; + } // Fill the event parameters // TODO: if modifiers are wrong, use XGetModifierMapping to retrieve the actual modifiers mapping Event event; event.type = Event::KeyPressed; - event.key.code = keysymToSF(symbol); + event.key.code = key; event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.control = windowEvent.xkey.state & ControlMask; event.key.shift = windowEvent.xkey.state & ShiftMask; @@ -1822,21 +1604,30 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) } } + updateLastInputTime(windowEvent.xkey.time); + break; } // Key up event case KeyRelease: { - // Get the keysym of the key that has been pressed - char buffer[32]; - KeySym symbol; - XLookupString(&windowEvent.xkey, buffer, 32, &symbol, NULL); + Keyboard::Key key = Keyboard::Unknown; + + // Try each KeySym index (modifier group) until we get a match + for (int i = 0; i < 4; ++i) + { + // Get the SFML keyboard code from the keysym of the key that has been released + key = keysymToSF(XLookupKeysym(&windowEvent.xkey, i)); + + if (key != Keyboard::Unknown) + break; + } // Fill the event parameters Event event; event.type = Event::KeyReleased; - event.key.code = keysymToSF(symbol); + event.key.code = key; event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.control = windowEvent.xkey.state & ControlMask; event.key.shift = windowEvent.xkey.state & ShiftMask; @@ -1872,6 +1663,9 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) } pushEvent(event); } + + updateLastInputTime(windowEvent.xbutton.time); + break; } @@ -1964,16 +1758,42 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) break; } - // Parent window changed - case ReparentNotify: + // Window unmapped + case UnmapNotify: + { + if (windowEvent.xunmap.window == m_window) + m_windowMapped = false; + + break; + } + + // Window visibility change + case VisibilityNotify: + { + // We prefer using VisibilityNotify over MapNotify because + // some window managers like awesome don't internally flag a + // window as viewable even after it is mapped but before it + // is visible leading to certain function calls failing with + // an unviewable error if called before VisibilityNotify arrives + + // Empirical testing on most widely used window managers shows + // that mapping a window will always lead to a VisibilityNotify + // event that is not VisibilityFullyObscured + if (windowEvent.xvisibility.window == m_window) + { + if (windowEvent.xvisibility.state != VisibilityFullyObscured) + m_windowMapped = true; + } + + break; + } + + // Window property change + case PropertyNotify: { - // Catch reparent events to properly apply fullscreen on - // some "strange" window managers (like Awesome) which - // seem to make use of temporary parents during mapping - if (m_fullscreen) - switchToFullscreen(); + if (!m_lastInputTime) + m_lastInputTime = windowEvent.xproperty.time; - XSync(m_display, True); // Discard remaining events break; } } diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index f84c86c1..973a57d3 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -31,8 +31,7 @@ #include #include #include -#include -#include +#include #include @@ -147,6 +146,14 @@ class WindowImplX11 : public WindowImpl //////////////////////////////////////////////////////////// virtual void setMouseCursorVisible(bool visible); + //////////////////////////////////////////////////////////// + /// \brief Grab or release the mouse cursor + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + virtual void setMouseCursorGrabbed(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// @@ -180,33 +187,6 @@ class WindowImplX11 : public WindowImpl private: - struct WMHints - { - int32_t flags; - uint32_t input; - int32_t initial_state; - xcb_pixmap_t icon_pixmap; - xcb_window_t icon_window; - int32_t icon_x; - int32_t icon_y; - xcb_pixmap_t icon_mask; - xcb_window_t window_group; - }; - - struct WMSizeHints - { - uint32_t flags; - int32_t x, y; - int32_t width, height; - int32_t min_width, min_height; - int32_t max_width, max_height; - int32_t width_inc, height_inc; - int32_t min_aspect_num, min_aspect_den; - int32_t max_aspect_num, max_aspect_den; - int32_t base_width, base_height; - uint32_t win_gravity; - }; - //////////////////////////////////////////////////////////// /// \brief Request the WM to make the current window active /// @@ -240,40 +220,12 @@ class WindowImplX11 : public WindowImpl void setProtocols(); //////////////////////////////////////////////////////////// - /// \brief Set Motif WM hints - /// - //////////////////////////////////////////////////////////// - void setMotifHints(unsigned long style); - - //////////////////////////////////////////////////////////// - /// \brief Set WM hints - /// - /// \param hints Hints - /// - //////////////////////////////////////////////////////////// - void setWMHints(const WMHints& hints); - - //////////////////////////////////////////////////////////// - /// \brief Set WM size hints - /// - /// \param hints Size hints - /// - //////////////////////////////////////////////////////////// - void setWMSizeHints(const WMSizeHints& hints); - - //////////////////////////////////////////////////////////// - /// \brief Change a XCB window property - /// - /// \param property Property to change - /// \param type Type of the property - /// \param format Format of the property - /// \param length Length of the new value - /// \param data The new value of the property + /// \brief Update the last time we received user input /// - /// \return True if successful, false if unsuccessful + /// \param time Last time we received user input /// //////////////////////////////////////////////////////////// - bool changeWindowProperty(xcb_atom_t property, xcb_atom_t type, uint8_t format, uint32_t length, const void* data); + void updateLastInputTime(::Time time); //////////////////////////////////////////////////////////// /// \brief Do some common initializations after the window has been created @@ -306,19 +258,23 @@ class WindowImplX11 : public WindowImpl //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - xcb_window_t m_window; ///< xcb identifier defining our window - ::Display* m_display; ///< Pointer to the display - xcb_connection_t* m_connection; ///< Pointer to the xcb connection - xcb_screen_t* m_screen; ///< Screen identifier - XIM m_inputMethod; ///< Input method linked to the X display - XIC m_inputContext; ///< Input context used to get unicode input in our window - bool m_isExternal; ///< Tell whether the window has been created externally or by SFML - xcb_randr_get_screen_info_reply_t m_oldVideoMode; ///< Video mode in use before we switch to fullscreen - Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one - bool m_keyRepeat; ///< Is the KeyRepeat feature enabled? - Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only) - bool m_useSizeHints; ///< Is the size of the window fixed with size hints? - bool m_fullscreen; ///< Is window in fullscreen? + ::Window m_window; ///< X identifier defining our window + ::Display* m_display; ///< Pointer to the display + int m_screen; ///< Screen identifier + XIM m_inputMethod; ///< Input method linked to the X display + XIC m_inputContext; ///< Input context used to get unicode input in our window + bool m_isExternal; ///< Tell whether the window has been created externally or by SFML + int m_oldVideoMode; ///< Video mode in use before we switch to fullscreen + Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one + bool m_keyRepeat; ///< Is the KeyRepeat feature enabled? + Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only) + bool m_useSizeHints; ///< Is the size of the window fixed with size hints? + bool m_fullscreen; ///< Is the window in fullscreen? + bool m_cursorGrabbed; ///< Is the mouse cursor trapped? + bool m_windowMapped; ///< Has the window been mapped by the window manager? + Pixmap m_iconPixmap; ///< The current icon pixmap if in use + Pixmap m_iconMaskPixmap; ///< The current icon mask pixmap if in use + ::Time m_lastInputTime; ///< Last time we received user input }; } // namespace priv diff --git a/src/SFML/Window/VideoMode.cpp b/src/SFML/Window/VideoMode.cpp index 8f3861d4..01103892 100644 --- a/src/SFML/Window/VideoMode.cpp +++ b/src/SFML/Window/VideoMode.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/VideoModeImpl.hpp b/src/SFML/Window/VideoModeImpl.hpp index cc992f96..525e9983 100644 --- a/src/SFML/Window/VideoModeImpl.hpp +++ b/src/SFML/Window/VideoModeImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/InputImpl.cpp b/src/SFML/Window/Win32/InputImpl.cpp index 6b1a4727..d5d3e566 100644 --- a/src/SFML/Window/Win32/InputImpl.cpp +++ b/src/SFML/Window/Win32/InputImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/InputImpl.hpp b/src/SFML/Window/Win32/InputImpl.hpp index 9f455f48..708472cb 100644 --- a/src/SFML/Window/Win32/InputImpl.hpp +++ b/src/SFML/Window/Win32/InputImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/JoystickImpl.cpp b/src/SFML/Window/Win32/JoystickImpl.cpp index ab40d5fb..c6defc6f 100644 --- a/src/SFML/Window/Win32/JoystickImpl.cpp +++ b/src/SFML/Window/Win32/JoystickImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -44,10 +44,13 @@ namespace bool connected; sf::Clock timer; }; - const sf::Time connectionRefreshDelay = sf::milliseconds(500); + ConnectionCache connectionCache[sf::Joystick::Count]; + // If true, will only update when WM_DEVICECHANGE message is received + bool lazyUpdates = false; + // Get a system error string from an error code std::string getErrorString(DWORD error) { @@ -150,19 +153,7 @@ namespace priv void JoystickImpl::initialize() { // Perform the initial scan and populate the connection cache - for (unsigned int i = 0; i < Joystick::Count; ++i) - { - ConnectionCache& cache = connectionCache[i]; - - // Check if the joystick is connected - JOYINFOEX joyInfo; - joyInfo.dwSize = sizeof(joyInfo); - joyInfo.dwFlags = 0; - cache.connected = joyGetPosEx(JOYSTICKID1 + i, &joyInfo) == JOYERR_NOERROR; - - // start the timeout - cache.timer.restart(); - } + updateConnections(); } @@ -176,28 +167,40 @@ void JoystickImpl::cleanup() //////////////////////////////////////////////////////////// bool JoystickImpl::isConnected(unsigned int index) { - // We check the connection state of joysticks only every N milliseconds, - // because of a strange (buggy?) behavior of joyGetPosEx when joysticks - // are just plugged/unplugged -- it takes really long and kills the app performances ConnectionCache& cache = connectionCache[index]; - if (cache.timer.getElapsedTime() > connectionRefreshDelay) + if (!lazyUpdates && cache.timer.getElapsedTime() > connectionRefreshDelay) { - cache.timer.restart(); - JOYINFOEX joyInfo; joyInfo.dwSize = sizeof(joyInfo); joyInfo.dwFlags = 0; - cache.connected = joyGetPosEx(JOYSTICKID1 + index, &joyInfo) == JOYERR_NOERROR; - return cache.connected; + + cache.timer.restart(); } - else + return cache.connected; +} + +//////////////////////////////////////////////////////////// +void JoystickImpl::setLazyUpdates(bool status) +{ + lazyUpdates = status; +} + +//////////////////////////////////////////////////////////// +void JoystickImpl::updateConnections() +{ + for (unsigned int i = 0; i < Joystick::Count; ++i) { - return cache.connected; + JOYINFOEX joyInfo; + joyInfo.dwSize = sizeof(joyInfo); + joyInfo.dwFlags = 0; + ConnectionCache& cache = connectionCache[i]; + cache.connected = joyGetPosEx(JOYSTICKID1 + i, &joyInfo) == JOYERR_NOERROR; + + cache.timer.restart(); } } - //////////////////////////////////////////////////////////// bool JoystickImpl::open(unsigned int index) { diff --git a/src/SFML/Window/Win32/JoystickImpl.hpp b/src/SFML/Window/Win32/JoystickImpl.hpp index ab0a7241..aa93fd1d 100644 --- a/src/SFML/Window/Win32/JoystickImpl.hpp +++ b/src/SFML/Window/Win32/JoystickImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -77,6 +77,20 @@ class JoystickImpl //////////////////////////////////////////////////////////// static bool isConnected(unsigned int index); + //////////////////////////////////////////////////////////// + /// \brief Enable or disable lazy enumeration updates + /// + /// \param status Whether to rely on windows triggering enumeration updates + /// + //////////////////////////////////////////////////////////// + static void setLazyUpdates(bool status); + + //////////////////////////////////////////////////////////// + /// \brief Update the connection status of all joysticks + /// + //////////////////////////////////////////////////////////// + static void updateConnections(); + //////////////////////////////////////////////////////////// /// \brief Open the joystick /// diff --git a/src/SFML/Window/Win32/SensorImpl.cpp b/src/SFML/Window/Win32/SensorImpl.cpp index 144c6d7e..4c00668e 100644 --- a/src/SFML/Window/Win32/SensorImpl.cpp +++ b/src/SFML/Window/Win32/SensorImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/SensorImpl.hpp b/src/SFML/Window/Win32/SensorImpl.hpp index 666e5d27..747220a6 100644 --- a/src/SFML/Window/Win32/SensorImpl.hpp +++ b/src/SFML/Window/Win32/SensorImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/VideoModeImpl.cpp b/src/SFML/Window/Win32/VideoModeImpl.cpp index 4b34a0fc..87839316 100644 --- a/src/SFML/Window/Win32/VideoModeImpl.cpp +++ b/src/SFML/Window/Win32/VideoModeImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index a1ddad2e..3e07c48a 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -28,6 +28,7 @@ #include // included first to avoid a warning about macro redefinition #include // included second to avoid an error in WglExtensions.hpp #include +#include #include #include #include @@ -35,6 +36,14 @@ #include +namespace +{ + // Some drivers are bugged and don't track the current HDC/HGLRC properly + // In order to deactivate successfully, we need to track it ourselves as well + sf::ThreadLocalPtr currentContext(NULL); +} + + namespace sf { namespace priv @@ -148,8 +157,12 @@ WglContext::~WglContext() // Destroy the OpenGL context if (m_context) { - if (wglGetCurrentContext() == m_context) - wglMakeCurrent(NULL, NULL); + if (currentContext == this) + { + if (wglMakeCurrent(m_deviceContext, NULL) == TRUE) + currentContext = NULL; + } + wglDeleteContext(m_context); } @@ -200,9 +213,20 @@ GlFunctionPointer WglContext::getFunction(const char* name) //////////////////////////////////////////////////////////// -bool WglContext::makeCurrent() +bool WglContext::makeCurrent(bool current) { - return m_deviceContext && m_context && wglMakeCurrent(m_deviceContext, m_context); + if (!m_deviceContext || !m_context) + return false; + + if (wglMakeCurrent(m_deviceContext, current ? m_context : NULL) == FALSE) + { + err() << "Failed to " << (current ? "activate" : "deactivate") << " OpenGL context: " << getErrorString(GetLastError()).toAnsiString() << std::endl; + return false; + } + + currentContext = (current ? this : NULL); + + return true; } @@ -223,7 +247,7 @@ void WglContext::setVerticalSyncEnabled(bool enabled) if (sfwgl_ext_EXT_swap_control == sfwgl_LOAD_SUCCEEDED) { if (wglSwapIntervalEXT(enabled ? 1 : 0) == FALSE) - err() << "Setting vertical sync failed" << std::endl; + err() << "Setting vertical sync failed: " << getErrorString(GetLastError()).toAnsiString() << std::endl; } else { @@ -258,9 +282,12 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix }; // Let's check how many formats are supporting our requirements - int formats[512]; - UINT nbFormats; - bool isValid = wglChoosePixelFormatARB(deviceContext, intAttributes, NULL, 512, formats, &nbFormats) != 0; + int formats[512]; + UINT nbFormats; + bool isValid = wglChoosePixelFormatARB(deviceContext, intAttributes, NULL, 512, formats, &nbFormats) != FALSE; + + if (!isValid) + err() << "Failed to enumerate pixel formats: " << getErrorString(GetLastError()).toAnsiString() << std::endl; // Get the best format among the returned ones if (isValid && (nbFormats > 0)) @@ -281,7 +308,7 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix WGL_ACCELERATION_ARB }; - if (!wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 7, attributes, values)) + if (wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 7, attributes, values) == FALSE) { err() << "Failed to retrieve pixel format information: " << getErrorString(GetLastError()).toAnsiString() << std::endl; break; @@ -296,7 +323,7 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix WGL_SAMPLES_ARB }; - if (!wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 2, sampleAttributes, sampleValues)) + if (wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 2, sampleAttributes, sampleValues) == FALSE) { err() << "Failed to retrieve pixel format multisampling information: " << getErrorString(GetLastError()).toAnsiString() << std::endl; break; @@ -308,7 +335,7 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix { const int sRgbCapableAttribute = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB; - if (!wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 1, &sRgbCapableAttribute, &sRgbCapableValue)) + if (wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 1, &sRgbCapableAttribute, &sRgbCapableValue) == FALSE) { err() << "Failed to retrieve pixel format sRGB capability information: " << getErrorString(GetLastError()).toAnsiString() << std::endl; break; @@ -324,7 +351,7 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix int pbufferValue = 0; - if (!wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 1, pbufferAttributes, &pbufferValue)) + if (wglGetPixelFormatAttribivARB(deviceContext, formats[i], PFD_MAIN_PLANE, 1, pbufferAttributes, &pbufferValue) == FALSE) { err() << "Failed to retrieve pixel format pbuffer information: " << getErrorString(GetLastError()).toAnsiString() << std::endl; break; @@ -395,7 +422,7 @@ void WglContext::setDevicePixelFormat(unsigned int bitsPerPixel) DescribePixelFormat(m_deviceContext, bestFormat, sizeof(actualFormat), &actualFormat); // Set the chosen pixel format - if (!SetPixelFormat(m_deviceContext, bestFormat, &actualFormat)) + if (SetPixelFormat(m_deviceContext, bestFormat, &actualFormat) == FALSE) { err() << "Failed to set pixel format for device context: " << getErrorString(GetLastError()).toAnsiString() << std::endl << "Cannot create OpenGL context" << std::endl; @@ -409,14 +436,19 @@ void WglContext::updateSettingsFromPixelFormat() { int format = GetPixelFormat(m_deviceContext); + if (format == 0) + { + err() << "Failed to get selected pixel format: " << getErrorString(GetLastError()).toAnsiString() << std::endl; + return; + } + PIXELFORMATDESCRIPTOR actualFormat; actualFormat.nSize = sizeof(actualFormat); actualFormat.nVersion = 1; - DescribePixelFormat(m_deviceContext, format, sizeof(actualFormat), &actualFormat); - if (format == 0) + if (DescribePixelFormat(m_deviceContext, format, sizeof(actualFormat), &actualFormat) == 0) { - err() << "Failed to get selected pixel format" << std::endl; + err() << "Failed to retrieve pixel format information: " << getErrorString(GetLastError()).toAnsiString() << std::endl; return; } @@ -425,7 +457,7 @@ void WglContext::updateSettingsFromPixelFormat() const int attributes[] = {WGL_DEPTH_BITS_ARB, WGL_STENCIL_BITS_ARB}; int values[2]; - if (wglGetPixelFormatAttribivARB(m_deviceContext, format, PFD_MAIN_PLANE, 2, attributes, values)) + if (wglGetPixelFormatAttribivARB(m_deviceContext, format, PFD_MAIN_PLANE, 2, attributes, values) == TRUE) { m_settings.depthBits = values[0]; m_settings.stencilBits = values[1]; @@ -442,7 +474,7 @@ void WglContext::updateSettingsFromPixelFormat() const int sampleAttributes[] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB}; int sampleValues[2]; - if (wglGetPixelFormatAttribivARB(m_deviceContext, format, PFD_MAIN_PLANE, 2, sampleAttributes, sampleValues)) + if (wglGetPixelFormatAttribivARB(m_deviceContext, format, PFD_MAIN_PLANE, 2, sampleAttributes, sampleValues) == TRUE) { m_settings.antialiasingLevel = sampleValues[0] ? sampleValues[1] : 0; } @@ -462,7 +494,7 @@ void WglContext::updateSettingsFromPixelFormat() const int sRgbCapableAttribute = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB; int sRgbCapableValue = 0; - if (wglGetPixelFormatAttribivARB(m_deviceContext, format, PFD_MAIN_PLANE, 1, &sRgbCapableAttribute, &sRgbCapableValue)) + if (wglGetPixelFormatAttribivARB(m_deviceContext, format, PFD_MAIN_PLANE, 1, &sRgbCapableAttribute, &sRgbCapableValue) == TRUE) { m_settings.sRgbCapable = (sRgbCapableValue == TRUE); } @@ -507,10 +539,16 @@ void WglContext::createSurface(WglContext* shared, unsigned int width, unsigned if (!m_deviceContext) { + err() << "Failed to retrieve pixel buffer device context: " << getErrorString(GetLastError()).toAnsiString() << std::endl; + wglDestroyPbufferARB(m_pbuffer); m_pbuffer = NULL; } } + else + { + err() << "Failed to create pixel buffer: " << getErrorString(GetLastError()).toAnsiString() << std::endl; + } } } @@ -599,6 +637,23 @@ void WglContext::createContext(WglContext* shared) attributes.push_back(0); attributes.push_back(0); + if (sharedContext) + { + static Mutex mutex; + Lock lock(mutex); + + if (currentContext == shared) + { + if (wglMakeCurrent(shared->m_deviceContext, NULL) == FALSE) + { + err() << "Failed to deactivate shared context before sharing: " << getErrorString(GetLastError()).toAnsiString() << std::endl; + return; + } + + currentContext = NULL; + } + } + // Create the context m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, &attributes[0]); } @@ -657,7 +712,18 @@ void WglContext::createContext(WglContext* shared) static Mutex mutex; Lock lock(mutex); - if (!wglShareLists(sharedContext, m_context)) + if (currentContext == shared) + { + if (wglMakeCurrent(shared->m_deviceContext, NULL) == FALSE) + { + err() << "Failed to deactivate shared context before sharing: " << getErrorString(GetLastError()).toAnsiString() << std::endl; + return; + } + + currentContext = NULL; + } + + if (wglShareLists(sharedContext, m_context) == FALSE) err() << "Failed to share the OpenGL context: " << getErrorString(GetLastError()).toAnsiString() << std::endl; } } diff --git a/src/SFML/Window/Win32/WglContext.hpp b/src/SFML/Window/Win32/WglContext.hpp index acc52913..d45de78b 100644 --- a/src/SFML/Window/Win32/WglContext.hpp +++ b/src/SFML/Window/Win32/WglContext.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -93,10 +93,12 @@ class WglContext : public GlContext //////////////////////////////////////////////////////////// /// \brief Activate the context as the current target for rendering /// + /// \param current Whether to make the context current or no longer current + /// /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(); + virtual bool makeCurrent(bool current); //////////////////////////////////////////////////////////// /// \brief Display what has been rendered to the context so far diff --git a/src/SFML/Window/Win32/WglExtensions.cpp b/src/SFML/Window/Win32/WglExtensions.cpp index 9ba446d9..3c037ab7 100644 --- a/src/SFML/Window/Win32/WglExtensions.cpp +++ b/src/SFML/Window/Win32/WglExtensions.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/Win32/WglExtensions.hpp b/src/SFML/Window/Win32/WglExtensions.hpp index f3ebfe55..a5400cf7 100644 --- a/src/SFML/Window/Win32/WglExtensions.hpp +++ b/src/SFML/Window/Win32/WglExtensions.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -136,7 +136,7 @@ extern int sfwgl_ext_ARB_create_context_profile; #define WGL_NUMBER_UNDERLAYS_ARB 0x2009 #define WGL_PIXEL_TYPE_ARB 0x2013 #define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 +#define WGL_RED_SHIFT_ARB 0x2017 #define WGL_SHARE_ACCUM_ARB 0x200E #define WGL_SHARE_DEPTH_ARB 0x200C #define WGL_SHARE_STENCIL_ARB 0x200D diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 8bf86ab8..f8669b21 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -55,10 +55,15 @@ #define MAPVK_VK_TO_VSC (0) #endif +// Avoid including just for one define +#ifndef DBT_DEVNODES_CHANGED + #define DBT_DEVNODES_CHANGED 0x0007 +#endif namespace { - unsigned int windowCount = 0; + unsigned int windowCount = 0; // Windows owned by SFML + unsigned int handleCount = 0; // All window handles const wchar_t* className = L"SFML_Window"; sf::priv::WindowImplWin32* fullscreenWindow = NULL; @@ -132,13 +137,21 @@ m_keyRepeatEnabled(true), m_lastSize (0, 0), m_resizing (false), m_surrogate (0), -m_mouseInside (false) +m_mouseInside (false), +m_fullscreen (false), +m_cursorGrabbed (false) { // Set that this process is DPI aware and can handle DPI scaling setProcessDpiAware(); if (m_handle) { + // If we're the first window handle, we only need to poll for joysticks when WM_DEVICECHANGE message is received + if (handleCount == 0) + JoystickImpl::setLazyUpdates(true); + + ++handleCount; + // We change the event procedure of the control (it is important to save the old one) SetWindowLongPtrW(m_handle, GWLP_USERDATA, reinterpret_cast(this)); m_callback = SetWindowLongPtrW(m_handle, GWLP_WNDPROC, reinterpret_cast(&WindowImplWin32::globalOnEvent)); @@ -156,7 +169,9 @@ m_keyRepeatEnabled(true), m_lastSize (mode.width, mode.height), m_resizing (false), m_surrogate (0), -m_mouseInside (false) +m_mouseInside (false), +m_fullscreen (style & Style::Fullscreen), +m_cursorGrabbed (m_fullscreen) { // Set that this process is DPI aware and can handle DPI scaling setProcessDpiAware(); @@ -187,8 +202,7 @@ m_mouseInside (false) } // In windowed mode, adjust width and height so that window will have the requested client area - bool fullscreen = (style & Style::Fullscreen) != 0; - if (!fullscreen) + if (!m_fullscreen) { RECT rectangle = {0, 0, width, height}; AdjustWindowRect(&rectangle, win32Style, false); @@ -199,12 +213,21 @@ m_mouseInside (false) // Create the window m_handle = CreateWindowW(className, title.toWideString().c_str(), win32Style, left, top, width, height, NULL, NULL, GetModuleHandle(NULL), this); + // If we're the first window handle, we only need to poll for joysticks when WM_DEVICECHANGE message is received + if (m_handle) + { + if (handleCount == 0) + JoystickImpl::setLazyUpdates(true); + + ++handleCount; + } + // By default, the OS limits the size of the window the the desktop size, // we have to resize it after creation to apply the real size setSize(Vector2u(mode.width, mode.height)); // Switch to fullscreen if requested - if (fullscreen) + if (m_fullscreen) switchToFullscreen(mode); // Increment window count @@ -219,6 +242,15 @@ WindowImplWin32::~WindowImplWin32() if (m_icon) DestroyIcon(m_icon); + // If it's the last window handle we have to poll for joysticks again + if (m_handle) + { + --handleCount; + + if (handleCount == 0) + JoystickImpl::setLazyUpdates(false); + } + if (!m_callback) { // Destroy the window @@ -277,6 +309,9 @@ Vector2i WindowImplWin32::getPosition() const void WindowImplWin32::setPosition(const Vector2i& position) { SetWindowPos(m_handle, NULL, position.x, position.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + + if(m_cursorGrabbed) + grabCursor(true); } @@ -363,6 +398,14 @@ void WindowImplWin32::setMouseCursorVisible(bool visible) } +//////////////////////////////////////////////////////////// +void WindowImplWin32::setMouseCursorGrabbed(bool grabbed) +{ + m_cursorGrabbed = grabbed; + grabCursor(m_cursorGrabbed); +} + + //////////////////////////////////////////////////////////// void WindowImplWin32::setKeyRepeatEnabled(bool enabled) { @@ -485,6 +528,23 @@ void WindowImplWin32::setTracking(bool track) } +//////////////////////////////////////////////////////////// +void WindowImplWin32::grabCursor(bool grabbed) +{ + if (grabbed) + { + RECT rect; + GetClientRect(m_handle, &rect); + MapWindowPoints(m_handle, NULL, reinterpret_cast(&rect), 2); + ClipCursor(&rect); + } + else + { + ClipCursor(NULL); + } +} + + //////////////////////////////////////////////////////////// void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) { @@ -536,6 +596,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) event.size.width = m_lastSize.x; event.size.height = m_lastSize.y; pushEvent(event); + + // Restore/update cursor grabbing + grabCursor(m_cursorGrabbed); } break; } @@ -544,6 +607,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_ENTERSIZEMOVE: { m_resizing = true; + grabCursor(false); break; } @@ -565,6 +629,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) event.size.height = m_lastSize.y; pushEvent(event); } + + // Restore/update cursor grabbing + grabCursor(m_cursorGrabbed); break; } @@ -582,6 +649,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Gain focus event case WM_SETFOCUS: { + // Restore cursor grabbing + grabCursor(m_cursorGrabbed); + Event event; event.type = Event::GainedFocus; pushEvent(event); @@ -591,6 +661,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Lost focus event case WM_KILLFOCUS: { + // Ungrab the cursor + grabCursor(false); + Event event; event.type = Event::LostFocus; pushEvent(event); @@ -892,6 +965,13 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) pushEvent(event); break; } + case WM_DEVICECHANGE: + { + // Some sort of device change has happened, update joystick connections + if (wParam == DBT_DEVNODES_CHANGED) + JoystickImpl::updateConnections(); + break; + } } } diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index fb5fe0f3..6c29e0b4 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -145,6 +145,14 @@ class WindowImplWin32 : public WindowImpl //////////////////////////////////////////////////////////// virtual void setMouseCursorVisible(bool visible); + //////////////////////////////////////////////////////////// + /// \brief Grab or release the mouse cursor + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + virtual void setMouseCursorGrabbed(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// @@ -216,6 +224,19 @@ class WindowImplWin32 : public WindowImpl //////////////////////////////////////////////////////////// void setTracking(bool track); + //////////////////////////////////////////////////////////// + /// \brief Grab or release the mouse cursor + /// + /// This is not to be confused with setMouseCursorGrabbed. + /// Here m_cursorGrabbed is not modified; it is used, + /// for example, to release the cursor when switching to + /// another application. + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + void grabCursor(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Convert a Win32 virtual key code to a SFML key code /// @@ -252,6 +273,8 @@ class WindowImplWin32 : public WindowImpl bool m_resizing; ///< Is the window being resized? Uint16 m_surrogate; ///< First half of the surrogate pair, in case we're receiving a Unicode character in two events bool m_mouseInside; ///< Mouse is inside the window? + bool m_fullscreen; ///< Is the window fullscreen? + bool m_cursorGrabbed; ///< Is the mouse cursor trapped? }; } // namespace priv diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index a091325f..6618e5bb 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -288,6 +288,14 @@ void Window::setMouseCursorVisible(bool visible) } +//////////////////////////////////////////////////////////// +void Window::setMouseCursorGrabbed(bool grabbed) +{ + if (m_impl) + m_impl->setMouseCursorGrabbed(grabbed); +} + + //////////////////////////////////////////////////////////// void Window::setKeyRepeatEnabled(bool enabled) { diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 8be51c82..fb5ba6b3 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 1e07a0f5..96f4436e 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -186,6 +186,14 @@ class WindowImpl : NonCopyable //////////////////////////////////////////////////////////// virtual void setMouseCursorVisible(bool visible) = 0; + //////////////////////////////////////////////////////////// + /// \brief Grab or release the mouse cursor and keeps it from leaving + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + virtual void setMouseCursorGrabbed(bool grabbed) = 0; + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// diff --git a/src/SFML/Window/iOS/EaglContext.hpp b/src/SFML/Window/iOS/EaglContext.hpp index 1ad457f9..a6853ee1 100644 --- a/src/SFML/Window/iOS/EaglContext.hpp +++ b/src/SFML/Window/iOS/EaglContext.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -126,10 +126,12 @@ class EaglContext : public GlContext /// \brief Activate the context as the current target /// for rendering /// + /// \param current Whether to make the context current or no longer current + /// /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(); + virtual bool makeCurrent(bool current); private: diff --git a/src/SFML/Window/iOS/EaglContext.mm b/src/SFML/Window/iOS/EaglContext.mm index 380c1397..72cec776 100644 --- a/src/SFML/Window/iOS/EaglContext.mm +++ b/src/SFML/Window/iOS/EaglContext.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -107,6 +107,9 @@ // Restore the previous context [EAGLContext setCurrentContext:previousContext]; + + if (m_context == [EAGLContext currentContext]) + [EAGLContext setCurrentContext:nil]; } } @@ -167,9 +170,12 @@ //////////////////////////////////////////////////////////// -bool EaglContext::makeCurrent() +bool EaglContext::makeCurrent(bool current) { - return [EAGLContext setCurrentContext:m_context]; + if (current) + return [EAGLContext setCurrentContext:m_context]; + + return [EAGLContext setCurrentContext:nil]; } @@ -215,12 +221,18 @@ // Create the context if (shared) + { + [EAGLContext setCurrentContext:nil]; + m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[shared->m_context sharegroup]]; + } else + { m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; + } // Activate it - makeCurrent(); + makeCurrent(true); // Create the framebuffer (this is the only allowed drawable on iOS) glGenFramebuffersOES(1, &m_framebuffer); @@ -230,6 +242,9 @@ // Attach the context to the GL view for future updates window->getGlView().context = this; + + // Deactivate it + makeCurrent(false); } } // namespace priv diff --git a/src/SFML/Window/iOS/InputImpl.hpp b/src/SFML/Window/iOS/InputImpl.hpp index 43733cb7..f41e072b 100644 --- a/src/SFML/Window/iOS/InputImpl.hpp +++ b/src/SFML/Window/iOS/InputImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/InputImpl.mm b/src/SFML/Window/iOS/InputImpl.mm index b8dd103f..6ac604f0 100644 --- a/src/SFML/Window/iOS/InputImpl.mm +++ b/src/SFML/Window/iOS/InputImpl.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/JoystickImpl.hpp b/src/SFML/Window/iOS/JoystickImpl.hpp index 59f31f25..9e4f52f3 100644 --- a/src/SFML/Window/iOS/JoystickImpl.hpp +++ b/src/SFML/Window/iOS/JoystickImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/JoystickImpl.mm b/src/SFML/Window/iOS/JoystickImpl.mm index 6821e032..4f4de868 100644 --- a/src/SFML/Window/iOS/JoystickImpl.mm +++ b/src/SFML/Window/iOS/JoystickImpl.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/ObjCType.hpp b/src/SFML/Window/iOS/ObjCType.hpp index 5b111d59..cf93a19f 100644 --- a/src/SFML/Window/iOS/ObjCType.hpp +++ b/src/SFML/Window/iOS/ObjCType.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFAppDelegate.hpp b/src/SFML/Window/iOS/SFAppDelegate.hpp index cd20bfc6..984e1e13 100644 --- a/src/SFML/Window/iOS/SFAppDelegate.hpp +++ b/src/SFML/Window/iOS/SFAppDelegate.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFAppDelegate.mm b/src/SFML/Window/iOS/SFAppDelegate.mm index 5908b4e3..5e202d38 100644 --- a/src/SFML/Window/iOS/SFAppDelegate.mm +++ b/src/SFML/Window/iOS/SFAppDelegate.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -214,8 +214,8 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification // Send a Resized event to the current window sf::Event event; event.type = sf::Event::Resized; - event.size.width = size.x * backingScaleFactor; - event.size.height = size.y * backingScaleFactor; + event.size.width = size.x; + event.size.height = size.y; sfWindow->forwardEvent(event); } } diff --git a/src/SFML/Window/iOS/SFMain.hpp b/src/SFML/Window/iOS/SFMain.hpp index f52857b5..dffd107b 100644 --- a/src/SFML/Window/iOS/SFMain.hpp +++ b/src/SFML/Window/iOS/SFMain.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFMain.mm b/src/SFML/Window/iOS/SFMain.mm index 0e9d481f..7a48cdb1 100644 --- a/src/SFML/Window/iOS/SFMain.mm +++ b/src/SFML/Window/iOS/SFMain.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFView.hpp b/src/SFML/Window/iOS/SFView.hpp index 48047973..d858a2bd 100644 --- a/src/SFML/Window/iOS/SFView.hpp +++ b/src/SFML/Window/iOS/SFView.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFView.mm b/src/SFML/Window/iOS/SFView.mm index b818749f..b4ae496d 100644 --- a/src/SFML/Window/iOS/SFView.mm +++ b/src/SFML/Window/iOS/SFView.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFViewController.hpp b/src/SFML/Window/iOS/SFViewController.hpp index ecc8476f..65b6eda0 100644 --- a/src/SFML/Window/iOS/SFViewController.hpp +++ b/src/SFML/Window/iOS/SFViewController.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SFViewController.mm b/src/SFML/Window/iOS/SFViewController.mm index 01422974..582b3ff1 100644 --- a/src/SFML/Window/iOS/SFViewController.mm +++ b/src/SFML/Window/iOS/SFViewController.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SensorImpl.hpp b/src/SFML/Window/iOS/SensorImpl.hpp index 0e3f211e..88d995e3 100644 --- a/src/SFML/Window/iOS/SensorImpl.hpp +++ b/src/SFML/Window/iOS/SensorImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/SensorImpl.mm b/src/SFML/Window/iOS/SensorImpl.mm index 96e4c7ac..02f8e1ff 100644 --- a/src/SFML/Window/iOS/SensorImpl.mm +++ b/src/SFML/Window/iOS/SensorImpl.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/VideoModeImpl.mm b/src/SFML/Window/iOS/VideoModeImpl.mm index dd3d1348..6798afe8 100644 --- a/src/SFML/Window/iOS/VideoModeImpl.mm +++ b/src/SFML/Window/iOS/VideoModeImpl.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/Window/iOS/WindowImplUIKit.hpp b/src/SFML/Window/iOS/WindowImplUIKit.hpp index 53c066e6..51e890a7 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.hpp +++ b/src/SFML/Window/iOS/WindowImplUIKit.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -149,6 +149,14 @@ class WindowImplUIKit : public WindowImpl //////////////////////////////////////////////////////////// virtual void setMouseCursorVisible(bool visible); + //////////////////////////////////////////////////////////// + /// \brief Clips or releases the mouse cursor + /// + /// \param grabbed True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + virtual void setMouseCursorGrabbed(bool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// diff --git a/src/SFML/Window/iOS/WindowImplUIKit.mm b/src/SFML/Window/iOS/WindowImplUIKit.mm index 3e7c833f..49791ce3 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.mm +++ b/src/SFML/Window/iOS/WindowImplUIKit.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -183,6 +183,13 @@ } +//////////////////////////////////////////////////////////// +void WindowImplUIKit::setMouseCursorGrabbed(bool grabbed) +{ + // Not applicable +} + + //////////////////////////////////////////////////////////// void WindowImplUIKit::setKeyRepeatEnabled(bool enabled) { diff --git a/tools/pkg-config/sfml-audio.pc.in b/tools/pkg-config/sfml-audio.pc.in index 7456daaa..0d7a3ce1 100644 --- a/tools/pkg-config/sfml-audio.pc.in +++ b/tools/pkg-config/sfml-audio.pc.in @@ -8,5 +8,8 @@ Description: The Simple and Fast Multimedia Library, audio module. URL: http://www.sfml-dev.org Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ Requires: sfml-system +Requires.private: openal, vorbisenc, vorbisfile, vorbis, ogg, flac Libs: -L${libdir} -lsfml-audio +# openal may be a system framework +Libs.private: @OPENAL_LIBRARY@ Cflags: -I${includedir} diff --git a/tools/pkg-config/sfml-graphics.pc.in b/tools/pkg-config/sfml-graphics.pc.in index d0a88a13..a96b72c9 100644 --- a/tools/pkg-config/sfml-graphics.pc.in +++ b/tools/pkg-config/sfml-graphics.pc.in @@ -8,5 +8,8 @@ Description: The Simple and Fast Multimedia Library, graphics module. URL: http://www.sfml-dev.org Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ Requires: sfml-window +Requires.private: sfml-system, freetype2 Libs: -L${libdir} -lsfml-graphics +# gl and jpeg may not be in pkg-config +Libs.private: @OPENGL_gl_LIBRARY@ @OPENGL_glu_LIBRARY@ @JPEG_LIBRARY@ Cflags: -I${includedir} diff --git a/tools/pkg-config/sfml-window.pc.in b/tools/pkg-config/sfml-window.pc.in index b0266e67..93bf344c 100644 --- a/tools/pkg-config/sfml-window.pc.in +++ b/tools/pkg-config/sfml-window.pc.in @@ -9,4 +9,6 @@ URL: http://www.sfml-dev.org Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ Requires: sfml-system Libs: -L${libdir} -lsfml-window +# gl may not be in pkg-config +Libs.private: @OPENGL_gl_LIBRARY@ @OPENGL_glu_LIBRARY@ Cflags: -I${includedir} diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp index 412ff394..4006fb16 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm index f3960032..079e1e45 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/ResourcePath.mm @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Marco Antognini (antognini.marco@gmail.com), +// Copyright (C) 2007-2017 Marco Antognini (antognini.marco@gmail.com), // Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in b/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in index e44dee90..d4533878 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in @@ -3,7 +3,7 @@