From 068bb1493736b76bc8e060aa29515899d651c34b Mon Sep 17 00:00:00 2001 From: Zachariah Brown Date: Sat, 26 Sep 2015 10:09:28 -0400 Subject: [PATCH 01/16] Added support for outlined text --- include/SFML/Graphics/Font.h | 11 ++--- include/SFML/Graphics/Text.h | 87 +++++++++++++++++++++++++++++++++--- src/SFML/Graphics/Font.cpp | 4 +- src/SFML/Graphics/Text.cpp | 55 ++++++++++++++++++++++- 4 files changed, 143 insertions(+), 14 deletions(-) diff --git a/include/SFML/Graphics/Font.h b/include/SFML/Graphics/Font.h index 1c028b9..9b1aa09 100644 --- a/include/SFML/Graphics/Font.h +++ b/include/SFML/Graphics/Font.h @@ -88,15 +88,16 @@ CSFML_GRAPHICS_API void sfFont_destroy(sfFont* font); //////////////////////////////////////////////////////////// /// \brief Get a glyph in a font /// -/// \param font Source font -/// \param codePoint Unicode code point of the character to get -/// \param characterSize Character size, in pixels -/// \param bold Retrieve the bold version or the regular one? +/// \param font Source font +/// \param codePoint Unicode code point of the character to get +/// \param characterSize Character size, in pixels +/// \param bold Retrieve the bold version or the regular one? +/// \param outlineThickness Thickness of outline (when != 0 the glyph will not be filled) /// /// \return The corresponding glyph /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfGlyph sfFont_getGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize, sfBool bold); +CSFML_GRAPHICS_API sfGlyph sfFont_getGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize, sfBool bold, float outlineThickness); //////////////////////////////////////////////////////////// /// \brief Get the kerning value corresponding to a given pair of characters in a font diff --git a/include/SFML/Graphics/Text.h b/include/SFML/Graphics/Text.h index ff9383f..0eaa6d3 100644 --- a/include/SFML/Graphics/Text.h +++ b/include/SFML/Graphics/Text.h @@ -290,16 +290,60 @@ CSFML_GRAPHICS_API void sfText_setCharacterSize(sfText* text, unsigned int size) CSFML_GRAPHICS_API void sfText_setStyle(sfText* text, sfUint32 style); //////////////////////////////////////////////////////////// -/// \brief Set the global color of a text +/// \brief Set the fill color of a text /// -/// By default, the text's color is opaque white. +/// By default, the text's fill color is opaque white. +/// Setting the fill color to a transparent color with an outline +/// will cause the outline to be displayed in the fill area of the text. /// /// \param text Text object -/// \param color New color of the text +/// \param color New fill color of the text +/// +/// \deprecated This function is deprecated and may be removed in future releases. +/// Use sfText_setFillColor instead. /// //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfText_setColor(sfText* text, sfColor color); +//////////////////////////////////////////////////////////// +/// \brief Set the fill color of a text +/// +/// By default, the text's fill color is opaque white. +/// Setting the fill color to a transparent color with an outline +/// will cause the outline to be displayed in the fill area of the text. +/// +/// \param text Text object +/// \param color New fill color of the text +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfText_setFillColor(sfText* text, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the outline color of the text +/// +/// By default, the text's outline color is opaque black. +/// +/// \param text Text object +/// \param color New outline color of the text +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfText_setOutlineColor(sfText* text, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the thickness of the text's outline +/// +/// By default, the outline thickness is 0. +/// +/// Be aware that using a negative value for the outline +/// thickness will cause distorted rendering. +/// +/// \param thickness New outline thickness, in pixels +/// +/// \see getOutlineThickness +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfText_setOutlineThickness(sfText* text, float thickness); + //////////////////////////////////////////////////////////// /// \brief Get the string of a text (returns an ANSI string) /// @@ -355,15 +399,48 @@ CSFML_GRAPHICS_API unsigned int sfText_getCharacterSize(const sfText* text); CSFML_GRAPHICS_API sfUint32 sfText_getStyle(const sfText* text); //////////////////////////////////////////////////////////// -/// \brief Get the global color of a text +/// \brief Get the fill color of a text /// /// \param text Text object /// -/// \return Global color of the text +/// \return Fill color of the text +/// +/// \deprecated This function is deprecated and may be removed in future releases. +/// Use sfText_getFillColor instead. /// //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfColor sfText_getColor(const sfText* text); +//////////////////////////////////////////////////////////// +/// \brief Get the fill color of a text +/// +/// \param text Text object +/// +/// \return Fill color of the text +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfColor sfText_getFillColor(const sfText* text); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline color of a text +/// +/// \param text Text object +/// +/// \return Outline color of the text +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfColor sfText_getOutlineColor(const sfText* text); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline thickness of a text +/// +/// \param text Text object +/// +/// \return Outline thickness of a text, in pixels +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API float sfText_getOutlineThickness(const sfText* text); + //////////////////////////////////////////////////////////// /// \brief Return the position of the \a index-th character in a text /// diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index b2b82a7..1f54e4a 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -93,12 +93,12 @@ void sfFont_destroy(sfFont* font) //////////////////////////////////////////////////////////// -sfGlyph sfFont_getGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize, sfBool bold) +sfGlyph sfFont_getGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize, sfBool bold, float outlineThickness) { sfGlyph glyph = {0, {0, 0, 0, 0}, {0, 0, 0, 0}}; CSFML_CHECK_RETURN(font, glyph); - sf::Glyph SFMLGlyph = font->This.getGlyph(codePoint, characterSize, bold == sfTrue); + sf::Glyph SFMLGlyph = font->This.getGlyph(codePoint, characterSize, bold == sfTrue, outlineThickness); glyph.advance = SFMLGlyph.advance; glyph.bounds.left = SFMLGlyph.bounds.left; diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index cd6e51c..27578ed 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -219,7 +219,28 @@ void sfText_setStyle(sfText* text, sfUint32 style) //////////////////////////////////////////////////////////// void sfText_setColor(sfText* text, sfColor color) { - CSFML_CALL(text, setColor(sf::Color(color.r, color.g, color.b, color.a))); + sfText_setFillColor(text, color); +} + + +//////////////////////////////////////////////////////////// +void sfText_setFillColor(sfText* text, sfColor color) +{ + CSFML_CALL(text, setFillColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfText_setOutlineColor(sfText* text, sfColor color) +{ + CSFML_CALL(text, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfText_setOutlineThickness(sfText* text, float thickness) +{ + CSFML_CALL(text, setOutlineThickness(thickness)); } @@ -268,11 +289,18 @@ sfUint32 sfText_getStyle(const sfText* text) //////////////////////////////////////////////////////////// sfColor sfText_getColor(const sfText* text) +{ + return sfText_getFillColor(text); +} + + +//////////////////////////////////////////////////////////// +sfColor sfText_getFillColor(const sfText* text) { sfColor color = {0, 0, 0, 0}; CSFML_CHECK_RETURN(text, color); - sf::Color sfmlColor = text->This.getColor(); + sf::Color sfmlColor = text->This.getFillColor(); color.r = sfmlColor.r; color.g = sfmlColor.g; color.b = sfmlColor.b; @@ -282,6 +310,29 @@ sfColor sfText_getColor(const sfText* text) } +//////////////////////////////////////////////////////////// +sfColor sfText_getOutlineColor(const sfText* text) +{ + sfColor color = { 0, 0, 0, 0 }; + CSFML_CHECK_RETURN(text, color); + + sf::Color sfmlColor = text->This.getOutlineColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +float sfText_getOutlineThickness(const sfText* text) +{ + CSFML_CALL_RETURN(text, getOutlineThickness(), 0.f); +} + + //////////////////////////////////////////////////////////// sfVector2f sfText_findCharacterPos(const sfText* text, size_t index) { From da9cce83500521adadc7bfad3064faf3ef60421e Mon Sep 17 00:00:00 2001 From: DJMaster Date: Mon, 8 Aug 2016 19:57:17 +0200 Subject: [PATCH 02/16] Added missing sfShader_isGeometryAvailable(void) function --- include/SFML/Graphics/Shader.h | 18 ++++++++++++++++++ src/SFML/Graphics/Shader.cpp | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/include/SFML/Graphics/Shader.h b/include/SFML/Graphics/Shader.h index 7172c51..89fc2ed 100644 --- a/include/SFML/Graphics/Shader.h +++ b/include/SFML/Graphics/Shader.h @@ -398,5 +398,23 @@ CSFML_GRAPHICS_API void sfShader_bind(const sfShader* shader); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfShader_isAvailable(void); +//////////////////////////////////////////////////////////// +/// \brief Tell whether or not the system supports geometry shaders +/// +/// This function should always be called before using +/// the geometry shader features. If it returns false, then +/// any attempt to use sfShader geometry shader features will fail. +/// +/// This function can only return true if isAvailable() would also +/// return true, since shaders in general have to be supported in +/// order for geometry shaders to be supported as well. +/// +/// Note: The first call to this function, whether by your +/// code or SFML will result in a context switch. +/// +/// \return True if geometry shaders are supported, false otherwise +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfBool sfShader_isGeometryAvailable(void); #endif // SFML_SHADER_H diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index e90da6d..e604afa 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -236,3 +236,10 @@ sfBool sfShader_isAvailable(void) { return sf::Shader::isAvailable() ? sfTrue : sfFalse; } + + +//////////////////////////////////////////////////////////// +sfBool sfShader_isGeometryAvailable(void) +{ + return sf::Shader::isGeometryAvailable() ? sfTrue : sfFalse; +} From bf46c5386a0ee985554c4e694ceffcd1cf24a854 Mon Sep 17 00:00:00 2001 From: DJMaster Date: Mon, 8 Aug 2016 20:23:22 +0200 Subject: [PATCH 03/16] Modified sfShader_createFromFile, sfShader_createFromMemory and sfShader_createFromStream functions to allow loading of all three vertex + geometry + fragment shaders --- include/SFML/Graphics/Shader.h | 27 +++++---- src/SFML/Graphics/Shader.cpp | 103 +++++++++++++++++++++------------ 2 files changed, 80 insertions(+), 50 deletions(-) diff --git a/include/SFML/Graphics/Shader.h b/include/SFML/Graphics/Shader.h index 89fc2ed..dd2aaef 100644 --- a/include/SFML/Graphics/Shader.h +++ b/include/SFML/Graphics/Shader.h @@ -40,59 +40,62 @@ //////////////////////////////////////////////////////////// /// \brief Load both the vertex and fragment shaders from files /// -/// This function can load both the vertex and the fragment -/// shaders, or only one of them: pass NULL if you don't want to load -/// either the vertex shader or the fragment shader. +/// This function can load the vertex, the geometry and the fragment +/// shaders, or only one or two of them: pass NULL if you don't want to load +/// the vertex shader, the geometry shader or the fragment shader. /// The sources must be text files containing valid shaders /// in GLSL language. GLSL is a C-like language dedicated to /// OpenGL shaders; you'll probably need to read a good documentation /// for it before writing your own shaders. /// /// \param vertexShaderFilename Path of the vertex shader file to load, or NULL to skip this shader +/// \param geometryShaderFilename Path of the geometry shader file to load, or NULL to skip this shader /// \param fragmentShaderFilename Path of the fragment shader file to load, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* fragmentShaderFilename); +CSFML_GRAPHICS_API sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename); //////////////////////////////////////////////////////////// /// \brief Load both the vertex and fragment shaders from source codes in memory /// -/// This function can load both the vertex and the fragment -/// shaders, or only one of them: pass NULL if you don't want to load -/// either the vertex shader or the fragment shader. +/// This function can load the vertex, the geometry and the fragment +/// shaders, or only one or two of them: pass NULL if you don't want to load +/// the vertex shader, the geometry shader or the fragment shader. /// The sources must be valid shaders in GLSL language. GLSL is /// a C-like language dedicated to OpenGL shaders; you'll /// probably need to read a good documentation for it before /// writing your own shaders. /// /// \param vertexShader String containing the source code of the vertex shader, or NULL to skip this shader +/// \param geometryShader String containing the source code of the geometry shader, or NULL to skip this shader /// \param fragmentShader String containing the source code of the fragment shader, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfShader* sfShader_createFromMemory(const char* vertexShader, const char* fragmentShader); +CSFML_GRAPHICS_API sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geometryShader, const char* fragmentShader); //////////////////////////////////////////////////////////// /// \brief Load both the vertex and fragment shaders from custom streams /// -/// This function can load both the vertex and the fragment -/// shaders, or only one of them: pass NULL if you don't want to load -/// either the vertex shader or the fragment shader. +/// This function can load the vertex, the geometry and the fragment +/// shaders, or only one or two of them: pass NULL if you don't want to load +/// the vertex shader, the geometry shader or the fragment shader. /// The source codes must be valid shaders in GLSL language. /// GLSL is a C-like language dedicated to OpenGL shaders; /// you'll probably need to read a good documentation for /// it before writing your own shaders. /// /// \param vertexShaderStream Source stream to read the vertex shader from, or NULL to skip this shader +/// \param geometryShaderStream Source stream to read the geometry shader from, or NULL to skip this shader /// \param fragmentShaderStream Source stream to read the fragment shader from, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* fragmentShaderStream); +CSFML_GRAPHICS_API sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream); //////////////////////////////////////////////////////////// /// \brief Destroy an existing shader diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index e604afa..f277271 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -34,26 +34,34 @@ //////////////////////////////////////////////////////////// -sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* fragmentShaderFilename) +sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename) { bool success = false; sfShader* shader = new sfShader; - if (vertexShaderFilename || fragmentShaderFilename) + if (vertexShaderFilename || geometryShaderFilename || fragmentShaderFilename) { - if (!vertexShaderFilename) + if (!geometryShaderFilename) { - // fragment shader only - success = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); - } - else if (!fragmentShaderFilename) - { - // vertex shader only - success = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); + if (!vertexShaderFilename) + { + // fragment shader only + success = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); + } + else if (!fragmentShaderFilename) + { + // vertex shader only + success = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); + } + else + { + // vertex + fragment shaders + success = shader->This.loadFromFile(vertexShaderFilename, fragmentShaderFilename); + } } else { - // vertex + fragment shaders - success = shader->This.loadFromFile(vertexShaderFilename, fragmentShaderFilename); + // vertex + geometry + fragment shaders + success = shader->This.loadFromFile(vertexShaderFilename, geometryShaderFilename, fragmentShaderFilename); } } @@ -68,26 +76,34 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* //////////////////////////////////////////////////////////// -sfShader* sfShader_createFromMemory(const char* vertexShader, const char* fragmentShader) +sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geometryShader, const char* fragmentShader) { bool success = false; sfShader* shader = new sfShader; - if (vertexShader || fragmentShader) + if (vertexShader || geometryShader || fragmentShader) { - if (!vertexShader) + if (!geometryShader) { - // fragment shader only - success = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); - } - else if (!fragmentShader) - { - // vertex shader only - success = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); + if (!vertexShader) + { + // fragment shader only + success = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); + } + else if (!fragmentShader) + { + // vertex shader only + success = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); + } + else + { + // vertex + fragment shaders + success = shader->This.loadFromMemory(vertexShader, fragmentShader); + } } else { - // vertex + fragment shaders - success = shader->This.loadFromMemory(vertexShader, fragmentShader); + // vertex + geometry + fragment shaders + success = shader->This.loadFromMemory(vertexShader, geometryShader, fragmentShader); } } @@ -102,30 +118,41 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* fragme //////////////////////////////////////////////////////////// -sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* fragmentShaderStream) +sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream) { bool success = false; sfShader* shader = new sfShader; - if (vertexShaderStream || fragmentShaderStream) + if (vertexShaderStream || geometryShaderStream || fragmentShaderStream) { - if (!vertexShaderStream) + if (!geometryShaderStream) { - // fragment shader only - CallbackStream stream(fragmentShaderStream); - success = shader->This.loadFromStream(stream, sf::Shader::Fragment); - } - else if (!fragmentShaderStream) - { - // vertex shader only - CallbackStream stream(vertexShaderStream); - success = shader->This.loadFromStream(stream, sf::Shader::Vertex); + if (!vertexShaderStream) + { + // fragment shader only + CallbackStream stream(fragmentShaderStream); + success = shader->This.loadFromStream(stream, sf::Shader::Fragment); + } + else if (!fragmentShaderStream) + { + // vertex shader only + CallbackStream stream(vertexShaderStream); + success = shader->This.loadFromStream(stream, sf::Shader::Vertex); + } + else + { + // vertex + fragment shaders + CallbackStream vertexStream(vertexShaderStream); + CallbackStream fragmentStream(fragmentShaderStream); + success = shader->This.loadFromStream(vertexStream, fragmentStream); + } } else { - // vertex + fragment shaders + // vertex + geometry + fragment shaders CallbackStream vertexStream(vertexShaderStream); + CallbackStream geometryStream(geometryShaderStream); CallbackStream fragmentStream(fragmentShaderStream); - success = shader->This.loadFromStream(vertexStream, fragmentStream); + success = shader->This.loadFromStream(vertexStream, geometryStream, fragmentStream); } } From 21e8e0523f42f95d919e7f08c4f4dd7c50877262 Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Wed, 10 Aug 2016 11:33:44 -0700 Subject: [PATCH 04/16] Copied/Converted SFML_DEPRECATED to CSFML. --- include/SFML/Config.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/SFML/Config.h b/include/SFML/Config.h index 01d706f..b3b0000 100644 --- a/include/SFML/Config.h +++ b/include/SFML/Config.h @@ -110,6 +110,42 @@ #endif +//////////////////////////////////////////////////////////// +// Cross-platform warning for deprecated functions and classes +// +// Usage: +// struct CSFML_DEPRECATED MyStruct +// { +// ... +// }; +// +// CSFML_DEPRECATED void globalFunc(); +//////////////////////////////////////////////////////////// +#if defined(CSFML_NO_DEPRECATED_WARNINGS) + + // User explicitly requests to disable deprecation warnings + #define CSFML_DEPRECATED + +#elif defined(_MSC_VER) + + // Microsoft C++ compiler + // Note: On newer MSVC versions, using deprecated functions causes a compiler error. In order to + // trigger a warning instead of an error, the compiler flag /sdl- (instead of /sdl) must be specified. + #define CSFML_DEPRECATED __declspec(deprecated) + +#elif defined(__GNUC__) + + // g++ and Clang + #define CSFML_DEPRECATED __attribute__ ((deprecated)) + +#else + + // Other compilers are not supported, leave class or function as-is. + // With a bit of luck, the #pragma directive works, otherwise users get a warning (no error!) for unrecognized #pragma. + #pragma message("CSFML_DEPRECATED is not supported for your compiler, please contact the CSFML team") + #define CSFML_DEPRECATED + +#endif //////////////////////////////////////////////////////////// // Define a portable boolean type From ce5e3a38911164ea846f4d2a739e3c15e2d4f8d2 Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Wed, 10 Aug 2016 11:34:51 -0700 Subject: [PATCH 05/16] Deprecated capture(), added mouse grabbing API. Deprecated: sfImage* sfRenderWindow_capture(const sfRenderWindow*); Added: sfRenderWindow_setMouseCursorGrabbed(sfRenderWindow*, sfBool); Added: sfWindow_setMouseCursorGrabbed(sfWindow*, sfBool); Also reordered some functions according to order in SFML. --- include/SFML/Graphics/RenderWindow.h | 84 ++++++++++++++++++---------- include/SFML/Window/Window.h | 83 ++++++++++++++++----------- src/SFML/Graphics/RenderWindow.cpp | 11 +++- src/SFML/Window/Window.cpp | 7 +++ 4 files changed, 119 insertions(+), 66 deletions(-) diff --git a/include/SFML/Graphics/RenderWindow.h b/include/SFML/Graphics/RenderWindow.h index 41c13f5..e55a549 100644 --- a/include/SFML/Graphics/RenderWindow.h +++ b/include/SFML/Graphics/RenderWindow.h @@ -208,6 +208,15 @@ CSFML_GRAPHICS_API void sfRenderWindow_setIcon(sfRenderWindow* renderWindow, uns //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRenderWindow_setVisible(sfRenderWindow* renderWindow, sfBool visible); +//////////////////////////////////////////////////////////// +/// \brief Enable / disable vertical synchronization on a render window +/// +/// \param renderWindow Render window object +/// \param enabled sfTrue to enable v-sync, sfFalse to deactivate +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderWindow_setVerticalSyncEnabled(sfRenderWindow* renderWindow, sfBool enabled); + //////////////////////////////////////////////////////////// /// \brief Show or hide the mouse cursor on a render window /// @@ -218,13 +227,19 @@ CSFML_GRAPHICS_API void sfRenderWindow_setVisible(sfRenderWindow* renderWindow, CSFML_GRAPHICS_API void sfRenderWindow_setMouseCursorVisible(sfRenderWindow* renderWindow, sfBool show); //////////////////////////////////////////////////////////// -/// \brief Enable / disable vertical synchronization on a render window +/// \brief Grab or release the mouse cursor /// -/// \param renderWindow Render window object -/// \param enabled sfTrue to enable v-sync, sfFalse to deactivate +/// 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 and calling this function for fullscreen windows +/// won't have any effect (fullscreen windows always grab the +/// cursor). +/// +/// \param grabbed sfTrue to enable, sfFalse to disable /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfRenderWindow_setVerticalSyncEnabled(sfRenderWindow* renderWindow, sfBool enabled); +CSFML_GRAPHICS_API void sfRenderWindow_setMouseCursorGrabbed(sfRenderWindow* renderWindow, sfBool grabbed); //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat for keydown events @@ -237,6 +252,24 @@ CSFML_GRAPHICS_API void sfRenderWindow_setVerticalSyncEnabled(sfRenderWindow* re //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRenderWindow_setKeyRepeatEnabled(sfRenderWindow* renderWindow, sfBool enabled); +//////////////////////////////////////////////////////////// +/// \brief Limit the framerate to a maximum fixed frequency for a render window +/// +/// \param renderWindow Render window object +/// \param limit Framerate limit, in frames per seconds (use 0 to disable limit) +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderWindow_setFramerateLimit(sfRenderWindow* renderWindow, unsigned int limit); + +//////////////////////////////////////////////////////////// +/// \brief Change the joystick threshold, ie. the value below which no move event will be generated +/// +/// \param renderWindow Render window object +/// \param threshold New threshold, in range [0, 100] +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderWindow_setJoystickThreshold(sfRenderWindow* renderWindow, float threshold); + //////////////////////////////////////////////////////////// /// \brief Activate or deactivate a render window as the current target for rendering /// @@ -282,24 +315,6 @@ CSFML_GRAPHICS_API sfBool sfRenderWindow_hasFocus(const sfRenderWindow* renderWi //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRenderWindow_display(sfRenderWindow* renderWindow); -//////////////////////////////////////////////////////////// -/// \brief Limit the framerate to a maximum fixed frequency for a render window -/// -/// \param renderWindow Render window object -/// \param limit Framerate limit, in frames per seconds (use 0 to disable limit) -/// -//////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfRenderWindow_setFramerateLimit(sfRenderWindow* renderWindow, unsigned int limit); - -//////////////////////////////////////////////////////////// -/// \brief Change the joystick threshold, ie. the value below which no move event will be generated -/// -/// \param renderWindow Render window object -/// \param threshold New threshold, in range [0, 100] -/// -//////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfRenderWindow_setJoystickThreshold(sfRenderWindow* renderWindow, float threshold); - //////////////////////////////////////////////////////////// /// \brief Retrieve the OS-specific handle of a render window /// @@ -494,22 +509,31 @@ CSFML_GRAPHICS_API void sfRenderWindow_popGLStates(sfRenderWindow* renderWindow) CSFML_GRAPHICS_API void sfRenderWindow_resetGLStates(sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// \brief Copy the current contents of a render window to an image +/// \brief Copy the current contents of the window to an image +/// +/// \deprecated +/// Use a sfTexture and its +/// sfTexture_updateFromRenderWindow(sfTexture*, const sfRenderWindow*, unsigned int, unsigned int) +/// function and copy its contents into an sfImage instead. +/// \code +/// sfVector2u windowSize = sfRenderWindow_getSize(window); +/// sfTexture* texture = sfTexture_create(windowSize.x, windowSize.y); +/// sfTexture_updateFromRenderWindow(texture, window, windowSize.x, windowSize.y); +/// sfImage* screenshot = sfTexture_copyToImage(texture); +/// \endcode /// /// This is a slow operation, whose main purpose is to make /// screenshots of the application. If you want to update an /// image with the contents of the window and then use it for -/// drawing, you should rather use a sfTexture and its -/// update(sfWindow*) function. +/// drawing, you should rather use a sfTexture and the +/// sfTexture_updateFromWindow(sfTexture*, const sfWindow*, unsigned int, unsigned int) function. /// You can also draw things directly to a texture with the -/// sfRenderWindow class. +/// sfRenderTexture class. /// -/// \param renderWindow Render window object -/// -/// \return New image containing the captured contents +/// \return sfImage containing the captured contents. /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfImage* sfRenderWindow_capture(const sfRenderWindow* renderWindow); +CSFML_GRAPHICS_API CSFML_DEPRECATED sfImage* sfRenderWindow_capture(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// /// \brief Get the current position of the mouse relative to a render-window diff --git a/include/SFML/Window/Window.h b/include/SFML/Window/Window.h index 8ccdb0c..0c60a05 100644 --- a/include/SFML/Window/Window.h +++ b/include/SFML/Window/Window.h @@ -315,15 +315,6 @@ CSFML_WINDOW_API void sfWindow_setIcon(sfWindow* window, unsigned int width, uns //////////////////////////////////////////////////////////// CSFML_WINDOW_API void sfWindow_setVisible(sfWindow* window, sfBool visible); -//////////////////////////////////////////////////////////// -/// \brief Show or hide the mouse cursor -/// -/// \param window Window object -/// \param visible sfTrue to show, sfFalse to hide -/// -//////////////////////////////////////////////////////////// -CSFML_WINDOW_API void sfWindow_setMouseCursorVisible(sfWindow* window, sfBool visible); - //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization /// @@ -338,6 +329,30 @@ CSFML_WINDOW_API void sfWindow_setMouseCursorVisible(sfWindow* window, sfBool vi //////////////////////////////////////////////////////////// CSFML_WINDOW_API void sfWindow_setVerticalSyncEnabled(sfWindow* window, sfBool enabled); +//////////////////////////////////////////////////////////// +/// \brief Show or hide the mouse cursor +/// +/// \param window Window object +/// \param visible sfTrue to show, sfFalse to hide +/// +//////////////////////////////////////////////////////////// +CSFML_WINDOW_API void sfWindow_setMouseCursorVisible(sfWindow* window, sfBool 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 and calling this function for fullscreen windows +/// won't have any effect (fullscreen windows always grab the +/// cursor). +/// +/// \param grabbed sfTrue to enable, sfFalse to disable +/// +//////////////////////////////////////////////////////////// +CSFML_WINDOW_API void sfWindow_setMouseCursorGrabbed(sfWindow* window, sfBool grabbed); + //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat /// @@ -353,6 +368,31 @@ CSFML_WINDOW_API void sfWindow_setVerticalSyncEnabled(sfWindow* window, sfBool e //////////////////////////////////////////////////////////// CSFML_WINDOW_API void sfWindow_setKeyRepeatEnabled(sfWindow* window, sfBool enabled); +//////////////////////////////////////////////////////////// +/// \brief Limit the framerate to a maximum fixed frequency +/// +/// If a limit is set, the window will use a small delay after +/// each call to sfWindow_display to ensure that the current frame +/// lasted long enough to match the framerate limit. +/// +/// \param window Window object +/// \param limit Framerate limit, in frames per seconds (use 0 to disable limit) +/// +//////////////////////////////////////////////////////////// +CSFML_WINDOW_API void sfWindow_setFramerateLimit(sfWindow* window, unsigned int limit); + +//////////////////////////////////////////////////////////// +/// \brief Change the joystick threshold +/// +/// The joystick threshold is the value below which +/// no JoyMoved event will be generated. +/// +/// \param window Window object +/// \param threshold New threshold, in the range [0, 100] +/// +//////////////////////////////////////////////////////////// +CSFML_WINDOW_API void sfWindow_setJoystickThreshold(sfWindow* window, float threshold); + //////////////////////////////////////////////////////////// /// \brief Activate or deactivate a window as the current target /// for OpenGL rendering @@ -411,31 +451,6 @@ CSFML_WINDOW_API sfBool sfWindow_hasFocus(const sfWindow* window); //////////////////////////////////////////////////////////// CSFML_WINDOW_API void sfWindow_display(sfWindow* window); -//////////////////////////////////////////////////////////// -/// \brief Limit the framerate to a maximum fixed frequency -/// -/// If a limit is set, the window will use a small delay after -/// each call to sfWindow_display to ensure that the current frame -/// lasted long enough to match the framerate limit. -/// -/// \param window Window object -/// \param limit Framerate limit, in frames per seconds (use 0 to disable limit) -/// -//////////////////////////////////////////////////////////// -CSFML_WINDOW_API void sfWindow_setFramerateLimit(sfWindow* window, unsigned int limit); - -//////////////////////////////////////////////////////////// -/// \brief Change the joystick threshold -/// -/// The joystick threshold is the value below which -/// no JoyMoved event will be generated. -/// -/// \param window Window object -/// \param threshold New threshold, in the range [0, 100] -/// -//////////////////////////////////////////////////////////// -CSFML_WINDOW_API void sfWindow_setJoystickThreshold(sfWindow* window, float threshold); - //////////////////////////////////////////////////////////// /// \brief Get the OS-specific handle of the window /// diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index 8ead1ae..d586ab4 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -272,6 +272,13 @@ void sfRenderWindow_setVisible(sfRenderWindow* renderWindow, sfBool visible) } +//////////////////////////////////////////////////////////// +void sfRenderWindow_setVerticalSyncEnabled(sfRenderWindow* renderWindow, sfBool enabled) +{ + CSFML_CALL(renderWindow, setVerticalSyncEnabled(enabled == sfTrue)); +} + + //////////////////////////////////////////////////////////// void sfRenderWindow_setMouseCursorVisible(sfRenderWindow* renderWindow, sfBool visible) { @@ -280,9 +287,9 @@ void sfRenderWindow_setMouseCursorVisible(sfRenderWindow* renderWindow, sfBool v //////////////////////////////////////////////////////////// -void sfRenderWindow_setVerticalSyncEnabled(sfRenderWindow* renderWindow, sfBool enabled) +void sfRenderWindow_setMouseCursorGrabbed(sfRenderWindow* renderWindow, sfBool grabbed) { - CSFML_CALL(renderWindow, setVerticalSyncEnabled(enabled == sfTrue)); + CSFML_CALL(renderWindow, setMouseCursorGrabbed(grabbed == sfTrue)); } diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 6507a3d..996871b 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -262,6 +262,13 @@ void sfWindow_setMouseCursorVisible(sfWindow* window, sfBool visible) } +//////////////////////////////////////////////////////////// +void sfWindow_setMouseCursorGrabbed(sfWindow* window, sfBool grabbed) +{ + CSFML_CALL(window, setMouseCursorGrabbed(grabbed == sfTrue)); +} + + //////////////////////////////////////////////////////////// void sfWindow_setVerticalSyncEnabled(sfWindow* window, sfBool enabled) { From 826ebac51a8d6387ec18056f44a089956238181b Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Wed, 10 Aug 2016 13:04:54 -0700 Subject: [PATCH 06/16] Add Glsl typedefs for sf::Shader::setUniform API. --- include/SFML/Graphics/Glsl.h | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 include/SFML/Graphics/Glsl.h diff --git a/include/SFML/Graphics/Glsl.h b/include/SFML/Graphics/Glsl.h new file mode 100644 index 0000000..a62b34c --- /dev/null +++ b/include/SFML/Graphics/Glsl.h @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////// +// +// 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_GLSL_H +#define SFML_GLSL_H + +#include +#include +#include +#include + +// 2D vectors +typedef sfVector2f sfGlslVec2; +typedef sfVector2i sfGlslIvec2; + +typedef struct +{ + bool x; + bool y; +} sfGlslBvec2; + +// 3D vectors +typedef sfVector3f sfGlslVec3; + +typedef struct +{ + int x; + int y; + int z; +} sfGlslIvec3; + +typedef struct +{ + bool x; + bool y; + bool z; +} sfGlslBvec3; + +// 4D vectors +typedef struct +{ + float x; + float y; + float z; + float w; +} sfGlslVec4; + +typedef struct +{ + int x; + int y; + int z; + int w; +} sfGlslIvec4; + +typedef struct +{ + bool x; + bool y; + bool z; + bool w; +} sfGlslBvec4; + +// matrices +typedef struct +{ + float array[3 * 3]; +} sfGlslMat3; + +typedef struct +{ + float array[4 * 4]; +} sfGlslMat4; + +#endif // SFML_GLSL_H From 36430b11c70bf8b1f9e6188d55cccf55be578c88 Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 14:02:18 -0700 Subject: [PATCH 07/16] Added geometry shader support. --- include/SFML/Graphics/Shader.h | 35 +++++----- src/SFML/Graphics/Shader.cpp | 121 ++++++++++++++++----------------- 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/include/SFML/Graphics/Shader.h b/include/SFML/Graphics/Shader.h index 7172c51..6976fc1 100644 --- a/include/SFML/Graphics/Shader.h +++ b/include/SFML/Graphics/Shader.h @@ -38,61 +38,64 @@ //////////////////////////////////////////////////////////// -/// \brief Load both the vertex and fragment shaders from files +/// \brief Load the vertex, geometry and fragment shaders from files /// -/// This function can load both the vertex and the fragment -/// shaders, or only one of them: pass NULL if you don't want to load -/// either the vertex shader or the fragment shader. +/// This function loads the vertex, geometry and fragment +/// shaders. Pass NULL if you don't want to load +/// a specific shader. /// The sources must be text files containing valid shaders /// in GLSL language. GLSL is a C-like language dedicated to /// OpenGL shaders; you'll probably need to read a good documentation /// for it before writing your own shaders. /// /// \param vertexShaderFilename Path of the vertex shader file to load, or NULL to skip this shader +/// \param geometryShaderFilename Path of the geometry shader file to load, or NULL to skip this shader /// \param fragmentShaderFilename Path of the fragment shader file to load, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* fragmentShaderFilename); +CSFML_GRAPHICS_API sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename); //////////////////////////////////////////////////////////// -/// \brief Load both the vertex and fragment shaders from source codes in memory +/// \brief Load the vertex, geometry and fragment shaders from source code in memory /// -/// This function can load both the vertex and the fragment -/// shaders, or only one of them: pass NULL if you don't want to load -/// either the vertex shader or the fragment shader. +/// This function loads the vertex, geometry and fragment +/// shaders. Pass NULL if you don't want to load +/// a specific shader. /// The sources must be valid shaders in GLSL language. GLSL is /// a C-like language dedicated to OpenGL shaders; you'll /// probably need to read a good documentation for it before /// writing your own shaders. /// /// \param vertexShader String containing the source code of the vertex shader, or NULL to skip this shader +/// \param geometryShader String containing the source code of the geometry shader, or NULL to skip this shader /// \param fragmentShader String containing the source code of the fragment shader, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfShader* sfShader_createFromMemory(const char* vertexShader, const char* fragmentShader); +CSFML_GRAPHICS_API sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geometryShader, const char* fragmentShader); //////////////////////////////////////////////////////////// -/// \brief Load both the vertex and fragment shaders from custom streams +/// \brief Load the vertex, geometry and fragment shaders from custom streams /// -/// This function can load both the vertex and the fragment -/// shaders, or only one of them: pass NULL if you don't want to load -/// either the vertex shader or the fragment shader. +/// This function loads the vertex, geometry and fragment +/// shaders. Pass NULL if you don't want to load +/// a specific shader. /// The source codes must be valid shaders in GLSL language. /// GLSL is a C-like language dedicated to OpenGL shaders; /// you'll probably need to read a good documentation for /// it before writing your own shaders. /// /// \param vertexShaderStream Source stream to read the vertex shader from, or NULL to skip this shader +/// \param geometryShaderStream Source stream to read the geometry shader from, or NULL to skip this shader /// \param fragmentShaderStream Source stream to read the fragment shader from, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* fragmentShaderStream); +CSFML_GRAPHICS_API sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream); //////////////////////////////////////////////////////////// /// \brief Destroy an existing shader @@ -122,7 +125,7 @@ CSFML_GRAPHICS_API void sfShader_destroy(sfShader* shader); /// \param x Value to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setFloatParameter(sfShader* shader, const char* name, float x); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setFloatParameter(sfShader* shader, const char* name, float x); //////////////////////////////////////////////////////////// /// \brief Change a 2-components vector parameter of a shader diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index e90da6d..661b44f 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -34,30 +34,30 @@ //////////////////////////////////////////////////////////// -sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* fragmentShaderFilename) +sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename) { - bool success = false; + bool vertexSuccess = false; + bool geometrySuccess = false; + bool fragmentSuccess = false; + sfShader* shader = new sfShader; - if (vertexShaderFilename || fragmentShaderFilename) + + if (vertexShaderFilename) { - if (!vertexShaderFilename) - { - // fragment shader only - success = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); - } - else if (!fragmentShaderFilename) - { - // vertex shader only - success = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); - } - else - { - // vertex + fragment shaders - success = shader->This.loadFromFile(vertexShaderFilename, fragmentShaderFilename); - } + vertexSuccess = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); } - if (!success) + if (geometryShaderFilename) + { + geometrySuccess = shader->This.loadFromFile(geometryShaderFilename, sf::Shader::Geometry); + } + + if (fragmentShaderFilename) + { + fragmentSuccess = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); + } + + if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) { delete shader; shader = NULL; @@ -68,30 +68,30 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* //////////////////////////////////////////////////////////// -sfShader* sfShader_createFromMemory(const char* vertexShader, const char* fragmentShader) +sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geometryShader, const char* fragmentShader) { - bool success = false; + bool vertexSuccess = false; + bool geometrySuccess = false; + bool fragmentSuccess = false; + sfShader* shader = new sfShader; - if (vertexShader || fragmentShader) + + if (vertexShader) { - if (!vertexShader) - { - // fragment shader only - success = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); - } - else if (!fragmentShader) - { - // vertex shader only - success = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); - } - else - { - // vertex + fragment shaders - success = shader->This.loadFromMemory(vertexShader, fragmentShader); - } + vertexSuccess = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); } - if (!success) + if (geometryShader) + { + geometrySuccess = shader->This.loadFromMemory(geometryShader, sf::Shader::Geometry); + } + + if (fragmentShader) + { + fragmentSuccess = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); + } + + if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) { delete shader; shader = NULL; @@ -102,34 +102,33 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* fragme //////////////////////////////////////////////////////////// -sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* fragmentShaderStream) +sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream) { - bool success = false; + bool vertexSuccess = false; + bool geometrySuccess = false; + bool fragmentSuccess = false; + sfShader* shader = new sfShader; - if (vertexShaderStream || fragmentShaderStream) + + if (vertexShaderStream) { - if (!vertexShaderStream) - { - // fragment shader only - CallbackStream stream(fragmentShaderStream); - success = shader->This.loadFromStream(stream, sf::Shader::Fragment); - } - else if (!fragmentShaderStream) - { - // vertex shader only - CallbackStream stream(vertexShaderStream); - success = shader->This.loadFromStream(stream, sf::Shader::Vertex); - } - else - { - // vertex + fragment shaders - CallbackStream vertexStream(vertexShaderStream); - CallbackStream fragmentStream(fragmentShaderStream); - success = shader->This.loadFromStream(vertexStream, fragmentStream); - } + CallbackStream stream(vertexShaderStream); + vertexSuccess = shader->This.loadFromStream(stream, sf::Shader::Vertex); } - if (!success) + if (geometryShaderStream) + { + CallbackStream stream(geometryShaderStream); + geometrySuccess = shader->This.loadFromStream(stream, sf::Shader::Geometry); + } + + if (fragmentShaderStream) + { + CallbackStream stream(fragmentShaderStream); + fragmentSuccess = shader->This.loadFromStream(stream, sf::Shader::Fragment); + } + + if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) { delete shader; shader = NULL; From 16ea259e04a1a946f0a7655ce5c2acc3d04c430f Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 15:11:28 -0700 Subject: [PATCH 08/16] Implemented new setUniform API for shaders. Deprecated old setParameter API. --- include/SFML/Graphics/Glsl.h | 44 ++--- include/SFML/Graphics/Shader.h | 310 ++++++++++++++++++++++++++++- src/SFML/Graphics/Shader.cpp | 348 +++++++++++++++++++++++++-------- 3 files changed, 586 insertions(+), 116 deletions(-) diff --git a/include/SFML/Graphics/Glsl.h b/include/SFML/Graphics/Glsl.h index a62b34c..aa3f562 100644 --- a/include/SFML/Graphics/Glsl.h +++ b/include/SFML/Graphics/Glsl.h @@ -36,8 +36,8 @@ typedef sfVector2i sfGlslIvec2; typedef struct { - bool x; - bool y; + bool x; + bool y; } sfGlslBvec2; // 3D vectors @@ -45,52 +45,52 @@ typedef sfVector3f sfGlslVec3; typedef struct { - int x; - int y; - int z; + int x; + int y; + int z; } sfGlslIvec3; typedef struct { - bool x; - bool y; - bool z; + bool x; + bool y; + bool z; } sfGlslBvec3; // 4D vectors typedef struct { - float x; - float y; - float z; - float w; + float x; + float y; + float z; + float w; } sfGlslVec4; typedef struct { - int x; - int y; - int z; - int w; + int x; + int y; + int z; + int w; } sfGlslIvec4; typedef struct { - bool x; - bool y; - bool z; - bool w; + bool x; + bool y; + bool z; + bool w; } sfGlslBvec4; // matrices typedef struct { - float array[3 * 3]; + float array[3 * 3]; } sfGlslMat3; typedef struct { - float array[4 * 4]; + float array[4 * 4]; } sfGlslMat4; #endif // SFML_GLSL_H diff --git a/include/SFML/Graphics/Shader.h b/include/SFML/Graphics/Shader.h index 6976fc1..3e0c350 100644 --- a/include/SFML/Graphics/Shader.h +++ b/include/SFML/Graphics/Shader.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include #include @@ -105,6 +106,297 @@ CSFML_GRAPHICS_API sfShader* sfShader_createFromStream(sfInputStream* vertexShad //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfShader_destroy(sfShader* shader); +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p float uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param x Value of the float scalar +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setFloatUniform(sfShader* shader, const char* name, float x); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p vec2 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the vec2 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setVec2Uniform(sfShader* shader, const char* name, sfGlslVec2 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p vec3 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the vec3 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setVec3Uniform(sfShader* shader, const char* name, sfGlslVec3 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p vec4 uniform +/// +/// sfColor objects can be passed to this function via +/// the use of sfGlslVec4_fromsfColor(sfColor); +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the vec4 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setVec4Uniform(sfShader* shader, const char* name, sfGlslVec4 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p vec4 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param color Value of the vec4 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setColorUniform(sfShader* shader, const char* name, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p int uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param x Value of the integer scalar +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setIntUniform(sfShader* shader, const char* name, int x); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p ivec2 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the ivec2 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setIvec2Uniform(sfShader* shader, const char* name, sfGlslIvec2 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p ivec3 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the ivec3 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setIvec3Uniform(sfShader* shader, const char* name, sfGlslIvec3 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p ivec4 uniform +/// +/// sfColor objects can be passed to this function via +/// the use of sfGlslIvec4_fromsfColor(sfColor); +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the ivec4 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setIvec4Uniform(sfShader* shader, const char* name, sfGlslIvec4 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p ivec4 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param color Value of the ivec4 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setIntColorUniform(sfShader* shader, const char* name, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p bool uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param x Value of the bool scalar +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setBoolUniform(sfShader* shader, const char* name, sfBool x); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p bvec2 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the bvec2 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setBvec2Uniform(sfShader* shader, const char* name, sfGlslBvec2 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p Bvec3 uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the Bvec3 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setBvec3Uniform(sfShader* shader, const char* name, sfGlslBvec3 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p bvec4 uniform +/// +/// sfColor objects can be passed to this function via +/// the use of sfGlslIvec4_fromsfColor(sfColor); +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vector Value of the bvec4 vector +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setBvec4Uniform(sfShader* shader, const char* name, sfGlslBvec4 vector); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p mat3 matrix +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param matrix Value of the mat3 matrix +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setMat3Uniform(sfShader* shader, const char* name, const sfGlslMat3* matrix); + +//////////////////////////////////////////////////////////// +/// \brief Specify value for \p mat4 matrix +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param matrix Value of the mat4 matrix +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setMat4Uniform(sfShader* shader, const char* name, const sfGlslMat4* matrix); + +//////////////////////////////////////////////////////////// +/// \brief Specify a texture as \p sampler2D uniform +/// +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 2D texture +/// (\p sampler2D GLSL type). +/// +/// Example: +/// \code +/// uniform sampler2D the_texture; // this is the variable in the shader +/// \endcode +/// \code +/// sfTexture texture; +/// ... +/// sfShader_setTextureUniform(shader, "the_texture", &texture); +/// \endcode +/// It is important to note that \a texture must remain alive as long +/// as the shader uses it, no copy is made internally. +/// +/// To use the texture of the object being drawn, which cannot be +/// known in advance, you can pass the special value +/// sf::Shader::CurrentTexture: +/// \code +/// shader.setUniform("the_texture", sf::Shader::CurrentTexture). +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the texture in the shader +/// \param texture Texture to assign +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setTextureUniform(sfShader* shader, const char* name, const sfTexture* texture); + +//////////////////////////////////////////////////////////// +/// \brief Specify current texture as \p sampler2D uniform +/// +/// This overload maps a shader texture variable to the +/// texture of the object being drawn, which cannot be +/// known in advance. +/// The corresponding parameter in the shader must be a 2D texture +/// (\p sampler2D GLSL type). +/// +/// Example: +/// \code +/// uniform sampler2D current; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_setCurrentTextureUniform(shader, "current"); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the texture in the shader +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setCurrentTextureUniform(sfShader* shader, const char* name); + +//////////////////////////////////////////////////////////// +/// \brief Specify values for \p float[] array uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param scalarArray pointer to array of \p float values +/// \param length Number of elements in the array +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setFloatUniformArray(sfShader* shader, const char* name, const float* scalarArray, size_t length); + +//////////////////////////////////////////////////////////// +/// \brief Specify values for \p vec2[] array uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vectorArray pointer to array of \p vec2 values +/// \param length Number of elements in the array +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setVec2UniformArray(sfShader* shader, const char* name, const sfGlslVec2* vectorArray, size_t length); + +//////////////////////////////////////////////////////////// +/// \brief Specify values for \p vec3[] array uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vectorArray pointer to array of \p vec3 values +/// \param length Number of elements in the array +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setVec3UniformArray(sfShader* shader, const char* name, const sfGlslVec3* vectorArray, size_t length); + +//////////////////////////////////////////////////////////// +/// \brief Specify values for \p vec4[] array uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param vectorArray pointer to array of \p vec4 values +/// \param length Number of elements in the array +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setVec4UniformArray(sfShader* shader, const char* name, const sfGlslVec4* vectorArray, size_t length); + +//////////////////////////////////////////////////////////// +/// \brief Specify values for \p mat3[] array uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param matrixArray pointer to array of \p mat3 values +/// \param length Number of elements in the array +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setMat3UniformArray(sfShader* shader, const char* name, const sfGlslMat3* matrixArray, size_t length); + +//////////////////////////////////////////////////////////// +/// \brief Specify values for \p mat4[] array uniform +/// +/// \param shader Shader object +/// \param name Name of the uniform variable in GLSL +/// \param matrixArray pointer to array of \p mat4 values +/// \param length Number of elements in the array +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShader_setMat4UniformArray(sfShader* shader, const char* name, const sfGlslMat4* matrixArray, size_t length); + //////////////////////////////////////////////////////////// /// \brief Change a float parameter of a shader /// @@ -148,7 +440,7 @@ CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setFloatParameter(sfShader* sh /// \param y Second component of the value to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setFloat2Parameter(sfShader* shader, const char* name, float x, float y); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setFloat2Parameter(sfShader* shader, const char* name, float x, float y); //////////////////////////////////////////////////////////// /// \brief Change a 3-components vector parameter of a shader @@ -172,7 +464,7 @@ CSFML_GRAPHICS_API void sfShader_setFloat2Parameter(sfShader* shader, const char /// \param z Third component of the value to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z); //////////////////////////////////////////////////////////// /// \brief Change a 4-components vector parameter of a shader @@ -197,7 +489,7 @@ CSFML_GRAPHICS_API void sfShader_setFloat3Parameter(sfShader* shader, const char /// \param w Fourth component of the value to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w); //////////////////////////////////////////////////////////// /// \brief Change a 2-components vector parameter of a shader @@ -220,7 +512,7 @@ CSFML_GRAPHICS_API void sfShader_setFloat4Parameter(sfShader* shader, const char /// \param vector Vector to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setVector2Parameter(sfShader* shader, const char* name, sfVector2f vector); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setVector2Parameter(sfShader* shader, const char* name, sfVector2f vector); //////////////////////////////////////////////////////////// /// \brief Change a 3-components vector parameter of a shader @@ -243,7 +535,7 @@ CSFML_GRAPHICS_API void sfShader_setVector2Parameter(sfShader* shader, const cha /// \param vector Vector to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setVector3Parameter(sfShader* shader, const char* name, sfVector3f vector); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setVector3Parameter(sfShader* shader, const char* name, sfVector3f vector); //////////////////////////////////////////////////////////// /// \brief Change a color parameter of a shader @@ -271,7 +563,7 @@ CSFML_GRAPHICS_API void sfShader_setVector3Parameter(sfShader* shader, const cha /// \param color Color to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setColorParameter(sfShader* shader, const char* name, sfColor color); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setColorParameter(sfShader* shader, const char* name, sfColor color); //////////////////////////////////////////////////////////// /// \brief Change a matrix parameter of a shader @@ -294,7 +586,7 @@ CSFML_GRAPHICS_API void sfShader_setColorParameter(sfShader* shader, const char* /// \param transform Transform to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setTransformParameter(sfShader* shader, const char* name, sfTransform transform); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setTransformParameter(sfShader* shader, const char* name, sfTransform transform); //////////////////////////////////////////////////////////// /// \brief Change a texture parameter of a shader @@ -327,7 +619,7 @@ CSFML_GRAPHICS_API void sfShader_setTransformParameter(sfShader* shader, const c /// \param texture Texture to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setTextureParameter(sfShader* shader, const char* name, const sfTexture* texture); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setTextureParameter(sfShader* shader, const char* name, const sfTexture* texture); //////////////////////////////////////////////////////////// /// \brief Change a texture parameter of a shader @@ -350,7 +642,7 @@ CSFML_GRAPHICS_API void sfShader_setTextureParameter(sfShader* shader, const cha /// \param name Name of the texture in the shader /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setCurrentTextureParameter(sfShader* shader, const char* name); +CSFML_GRAPHICS_API CSFML_DEPRECATED void sfShader_setCurrentTextureParameter(sfShader* shader, const char* name); //////////////////////////////////////////////////////////// /// \brief Get the underlying OpenGL handle of the shader. diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 661b44f..d1a6c7e 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -36,202 +36,380 @@ //////////////////////////////////////////////////////////// sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename) { - bool vertexSuccess = false; - bool geometrySuccess = false; - bool fragmentSuccess = false; + bool vertexSuccess = false; + bool geometrySuccess = false; + bool fragmentSuccess = false; - sfShader* shader = new sfShader; - - if (vertexShaderFilename) - { - vertexSuccess = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); - } + sfShader* shader = new sfShader; + + if (vertexShaderFilename) + { + vertexSuccess = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); + } - if (geometryShaderFilename) - { - geometrySuccess = shader->This.loadFromFile(geometryShaderFilename, sf::Shader::Geometry); - } + if (geometryShaderFilename) + { + geometrySuccess = shader->This.loadFromFile(geometryShaderFilename, sf::Shader::Geometry); + } - if (fragmentShaderFilename) - { - fragmentSuccess = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); - } + if (fragmentShaderFilename) + { + fragmentSuccess = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); + } - if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) - { - delete shader; - shader = NULL; - } + if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) + { + delete shader; + shader = NULL; + } - return shader; + return shader; } //////////////////////////////////////////////////////////// sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geometryShader, const char* fragmentShader) { - bool vertexSuccess = false; - bool geometrySuccess = false; - bool fragmentSuccess = false; + bool vertexSuccess = false; + bool geometrySuccess = false; + bool fragmentSuccess = false; - sfShader* shader = new sfShader; + sfShader* shader = new sfShader; - if (vertexShader) - { - vertexSuccess = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); - } + if (vertexShader) + { + vertexSuccess = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); + } - if (geometryShader) - { - geometrySuccess = shader->This.loadFromMemory(geometryShader, sf::Shader::Geometry); - } + if (geometryShader) + { + geometrySuccess = shader->This.loadFromMemory(geometryShader, sf::Shader::Geometry); + } - if (fragmentShader) - { - fragmentSuccess = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); - } + if (fragmentShader) + { + fragmentSuccess = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); + } - if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) - { - delete shader; - shader = NULL; - } + if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) + { + delete shader; + shader = NULL; + } - return shader; + return shader; } //////////////////////////////////////////////////////////// sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream) { - bool vertexSuccess = false; - bool geometrySuccess = false; - bool fragmentSuccess = false; + bool vertexSuccess = false; + bool geometrySuccess = false; + bool fragmentSuccess = false; - sfShader* shader = new sfShader; + sfShader* shader = new sfShader; - if (vertexShaderStream) - { - CallbackStream stream(vertexShaderStream); - vertexSuccess = shader->This.loadFromStream(stream, sf::Shader::Vertex); - } + if (vertexShaderStream) + { + CallbackStream stream(vertexShaderStream); + vertexSuccess = shader->This.loadFromStream(stream, sf::Shader::Vertex); + } - if (geometryShaderStream) - { - CallbackStream stream(geometryShaderStream); - geometrySuccess = shader->This.loadFromStream(stream, sf::Shader::Geometry); - } + if (geometryShaderStream) + { + CallbackStream stream(geometryShaderStream); + geometrySuccess = shader->This.loadFromStream(stream, sf::Shader::Geometry); + } - if (fragmentShaderStream) - { - CallbackStream stream(fragmentShaderStream); - fragmentSuccess = shader->This.loadFromStream(stream, sf::Shader::Fragment); - } + if (fragmentShaderStream) + { + CallbackStream stream(fragmentShaderStream); + fragmentSuccess = shader->This.loadFromStream(stream, sf::Shader::Fragment); + } - if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) - { - delete shader; - shader = NULL; - } + if (!(vertexSuccess || geometrySuccess || fragmentSuccess)) + { + delete shader; + shader = NULL; + } - return shader; + return shader; } //////////////////////////////////////////////////////////// void sfShader_destroy(sfShader* shader) { - delete shader; + delete shader; +} + + +//////////////////////////////////////////////////////////// +void sfShader_setFloatUniform(sfShader* shader, const char* name, float x) +{ + CSFML_CALL(shader, setUniform(name, x)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setVec2Uniform(sfShader* shader, const char* name, sfGlslVec2 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Vec2(vector.x, vector.y))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setVec3Uniform(sfShader* shader, const char* name, sfGlslVec3 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Vec3(vector.x, vector.y, vector.z))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setVec4Uniform(sfShader* shader, const char* name, sfGlslVec4 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Vec4(vector.x, vector.y, vector.z, vector.w))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setColorUniform(sfShader* shader, const char* name, sfColor color) +{ + sfGlslVec4 vec4; + vec4.x = color.r / 255.f; + vec4.y = color.g / 255.f; + vec4.z = color.b / 255.f; + vec4.w = color.a / 255.f; + + sfShader_setVec4Uniform(shader, name, vec4); +} + +//////////////////////////////////////////////////////////// +void sfShader_setIntUniform(sfShader* shader, const char* name, int x) +{ + CSFML_CALL(shader, setUniform(name, x)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setIvec2Uniform(sfShader* shader, const char* name, sfGlslIvec2 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Ivec2(vector.x, vector.y))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setIvec3Uniform(sfShader* shader, const char* name, sfGlslIvec3 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Ivec3(vector.x, vector.y, vector.z))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setIvec4Uniform(sfShader* shader, const char* name, sfGlslIvec4 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Ivec4(vector.x, vector.y, vector.z, vector.w))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setIntColorUniform(sfShader* shader, const char* name, sfColor color) +{ + sfGlslIvec4 ivec4; + ivec4.x = (int)color.r; + ivec4.y = (int)color.g; + ivec4.z = (int)color.b; + ivec4.w = (int)color.a; + + sfShader_setIvec4Uniform(shader, name, ivec4); +} + +//////////////////////////////////////////////////////////// +void sfShader_setBoolUniform(sfShader* shader, const char* name, sfBool x) +{ + CSFML_CALL(shader, setUniform(name, x)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setBvec2Uniform(sfShader* shader, const char* name, sfGlslBvec2 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Bvec2(vector.x, vector.y))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setBvec3Uniform(sfShader* shader, const char* name, sfGlslBvec3 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Bvec3(vector.x, vector.y, vector.z))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setBvec4Uniform(sfShader* shader, const char* name, sfGlslBvec4 vector) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Bvec4(vector.x, vector.y, vector.z, vector.w))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setMat3Uniform(sfShader* shader, const char* name, const sfGlslMat3* matrix) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Mat3(matrix->array))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setMat4Uniform(sfShader* shader, const char* name, const sfGlslMat4* matrix) +{ + CSFML_CALL(shader, setUniform(name, sf::Glsl::Mat4(matrix->array))); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setTextureUniform(sfShader* shader, const char* name, const sfTexture* texture) +{ + CSFML_CALL(shader, setUniform(name, *texture->This)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setCurrentTextureUniform(sfShader* shader, const char* name) +{ + CSFML_CALL(shader, setUniform(name, sf::Shader::CurrentTexture)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setFloatUniformArray(sfShader* shader, const char* name, const float* scalarArray, size_t length) +{ + CSFML_CALL(shader, setUniformArray(name, scalarArray, length)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setVec2UniformArray(sfShader* shader, const char* name, const sfGlslVec2* vectorArray, size_t length) +{ + CSFML_CALL(shader, setUniformArray(name, reinterpret_cast(vectorArray), length)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setVec3UniformArray(sfShader* shader, const char* name, const sfGlslVec3* vectorArray, size_t length) +{ + CSFML_CALL(shader, setUniformArray(name, reinterpret_cast(vectorArray), length)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setVec4UniformArray(sfShader* shader, const char* name, const sfGlslVec4* vectorArray, size_t length) +{ + CSFML_CALL(shader, setUniformArray(name, reinterpret_cast(vectorArray), length)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setMat3UniformArray(sfShader* shader, const char* name, const sfGlslMat3* matrixArray, size_t length) +{ + CSFML_CALL(shader, setUniformArray(name, reinterpret_cast(matrixArray), length)); +} + + +//////////////////////////////////////////////////////////// +void sfShader_setMat4UniformArray(sfShader* shader, const char* name, const sfGlslMat4* matrixArray, size_t length) +{ + CSFML_CALL(shader, setUniformArray(name, reinterpret_cast(matrixArray), length)); } //////////////////////////////////////////////////////////// void sfShader_setFloatParameter(sfShader* shader, const char* name, float x) { - CSFML_CALL(shader, setParameter(name, x)); + CSFML_CALL(shader, setParameter(name, x)); } //////////////////////////////////////////////////////////// void sfShader_setFloat2Parameter(sfShader* shader, const char* name, float x, float y) { - CSFML_CALL(shader, setParameter(name, x, y)); + CSFML_CALL(shader, setParameter(name, x, y)); } //////////////////////////////////////////////////////////// void sfShader_setFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z) { - CSFML_CALL(shader, setParameter(name, x, y, z)); + CSFML_CALL(shader, setParameter(name, x, y, z)); } //////////////////////////////////////////////////////////// void sfShader_setFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w) { - CSFML_CALL(shader, setParameter(name, x, y, z, w)); + CSFML_CALL(shader, setParameter(name, x, y, z, w)); } //////////////////////////////////////////////////////////// void sfShader_setVector2Parameter(sfShader* shader, const char* name, sfVector2f vector) { - CSFML_CALL(shader, setParameter(name, sf::Vector2f(vector.x, vector.y))); + CSFML_CALL(shader, setParameter(name, sf::Vector2f(vector.x, vector.y))); } //////////////////////////////////////////////////////////// void sfShader_setVector3Parameter(sfShader* shader, const char* name, sfVector3f vector) { - CSFML_CALL(shader, setParameter(name, sf::Vector3f(vector.x, vector.y, vector.z))); + CSFML_CALL(shader, setParameter(name, sf::Vector3f(vector.x, vector.y, vector.z))); } //////////////////////////////////////////////////////////// void sfShader_setColorParameter(sfShader* shader, const char* name, sfColor color) { - CSFML_CALL(shader, setParameter(name, sf::Color(color.r, color.g, color.b, color.a))); + CSFML_CALL(shader, setParameter(name, sf::Color(color.r, color.g, color.b, color.a))); } //////////////////////////////////////////////////////////// void sfShader_setTransformParameter(sfShader* shader, const char* name, sfTransform transform) { - CSFML_CALL(shader, setParameter(name, convertTransform(transform))); + CSFML_CALL(shader, setParameter(name, convertTransform(transform))); } //////////////////////////////////////////////////////////// void sfShader_setTextureParameter(sfShader* shader, const char* name, const sfTexture* texture) { - CSFML_CHECK(texture); - CSFML_CALL(shader, setParameter(name, *texture->This)); + CSFML_CHECK(texture); + CSFML_CALL(shader, setParameter(name,*texture->This)); } //////////////////////////////////////////////////////////// void sfShader_setCurrentTextureParameter(sfShader* shader, const char* name) { - CSFML_CALL(shader, setParameter(name, sf::Shader::CurrentTexture)); + CSFML_CALL(shader, setParameter(name, sf::Shader::CurrentTexture)); } //////////////////////////////////////////////////////////// unsigned int sfShader_getNativeHandle(const sfShader* shader) { - CSFML_CALL_RETURN(shader, getNativeHandle(), 0); + CSFML_CALL_RETURN(shader, getNativeHandle(), 0); } //////////////////////////////////////////////////////////// void sfShader_bind(const sfShader* shader) { - sf::Shader::bind(shader ? &shader->This : NULL); + sf::Shader::bind(shader ? &shader->This : NULL); } //////////////////////////////////////////////////////////// sfBool sfShader_isAvailable(void) { - return sf::Shader::isAvailable() ? sfTrue : sfFalse; + return sf::Shader::isAvailable() ? sfTrue : sfFalse; } From 490a21fdff267a584324941c117e96205bf8d31d Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 15:28:03 -0700 Subject: [PATCH 09/16] Renamed/deprecated sfPrimitiveType values. sfLinesStrip -> sfLineStrip sfTrianglesStrip -> sfTriangleStrip sfTrianglesFan -> sfTriangleFan --- include/SFML/Graphics/PrimitiveType.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/SFML/Graphics/PrimitiveType.h b/include/SFML/Graphics/PrimitiveType.h index aa41baa..8bcd782 100644 --- a/include/SFML/Graphics/PrimitiveType.h +++ b/include/SFML/Graphics/PrimitiveType.h @@ -41,13 +41,17 @@ //////////////////////////////////////////////////////////// typedef enum { - sfPoints, ///< List of individual points - sfLines, ///< List of individual lines - sfLinesStrip, ///< List of connected lines, a point uses the previous point to form a line - sfTriangles, ///< List of individual triangles - sfTrianglesStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle - sfTrianglesFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle - sfQuads ///< List of individual quads + sfPoints, ///< List of individual points + sfLines, ///< List of individual lines + sfLineStrip, ///< List of connected lines, a point uses the previous point to form a line + sfTriangles, ///< List of individual triangles + sfTriangleStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle + sfTriangleFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle + sfQuads, ///< List of individual quads + + sfLinesStrip = sfLineStrip, ///< \deprecated Use sfLineStrip instead + sfTrianglesStrp = sfTriangleStrip, ///< \deprecated Use sfTriangleStrip instead + sfTrianglesFan = sfTriangleFan ///< \deprecated Use sfTriangleFan instead } sfPrimitiveType; From 784b20038f49e474d7e85c471d623b3c5fdb519b Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 15:43:15 -0700 Subject: [PATCH 10/16] Added sRGB support to sfTexture. --- include/SFML/Graphics/Texture.h | 35 +++++++++++++++++++++++++++++++++ src/SFML/Graphics/Texture.cpp | 14 +++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/SFML/Graphics/Texture.h b/include/SFML/Graphics/Texture.h index 4f4f094..052bf1a 100644 --- a/include/SFML/Graphics/Texture.h +++ b/include/SFML/Graphics/Texture.h @@ -196,6 +196,41 @@ CSFML_GRAPHICS_API void sfTexture_setSmooth(sfTexture* texture, sfBool smooth); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfTexture_isSmooth(const sfTexture* texture); +//////////////////////////////////////////////////////////// +/// \brief Enable or disable conversion from sRGB +/// +/// When providing texture data from an image file or memory, it can +/// either be stored in a linear color space or an sRGB color space. +/// Most digital images account for gamma correction already, so they +/// would need to be "uncorrected" back to linear color space before +/// being processed by the hardware. The hardware can automatically +/// convert it from the sRGB color space to a linear color space when +/// it gets sampled. When the rendered image gets output to the final +/// framebuffer, it gets converted back to sRGB. +/// +/// After enabling or disabling sRGB conversion, make sure to reload +/// the texture data in order for the setting to take effect. +/// +/// This option is only useful in conjunction with an sRGB capable +/// framebuffer. This can be requested during window creation. +/// +/// \param sRgb True to enable sRGB conversion, false to disable it +/// +/// \see sfTexture_isSrgb +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfTexture_setSrgb(sfTexture* texture, sfBool sRgb); + +//////////////////////////////////////////////////////////// +/// \brief Tell whether the texture source is converted from sRGB or not +/// +/// \return True if the texture source is converted from sRGB, false if not +/// +/// \see sfTexture_setSrgb +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfBool sfTexture_isSrgb(const sfTexture* texture); + //////////////////////////////////////////////////////////// /// \brief Enable or disable repeating for a texture /// diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index efe328f..ef440bb 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -225,6 +225,20 @@ sfBool sfTexture_isSmooth(const sfTexture* texture) } +//////////////////////////////////////////////////////////// +void sfTexture_setSrgb(sfTexture* texture, sfBool sRgb) +{ + CSFML_CALL_PTR(texture, setSrgb(sRgb == sfTrue)); +} + + +//////////////////////////////////////////////////////////// +sfBool sfTexture_isSrgb(const sfTexture* texture) +{ + CSFML_CALL_PTR_RETURN(texture, isSrgb(), sfFalse); +} + + //////////////////////////////////////////////////////////// void sfTexture_setRepeated(sfTexture* texture, sfBool repeated) { From ae727f0a04638b3b70fee9f90c022840d77521c4 Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 15:48:03 -0700 Subject: [PATCH 11/16] Added ReverseSubtract sfBlendMode --- include/SFML/Graphics/BlendMode.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.h b/include/SFML/Graphics/BlendMode.h index 93ea84b..00782a6 100644 --- a/include/SFML/Graphics/BlendMode.h +++ b/include/SFML/Graphics/BlendMode.h @@ -56,8 +56,9 @@ typedef enum //////////////////////////////////////////////////////////// typedef enum { - sfBlendEquationAdd, ///< Pixel = Src * SrcFactor + Dst * DstFactor - sfBlendEquationSubtract ///< Pixel = Src * SrcFactor - Dst * DstFactor + sfBlendEquationAdd, ///< Pixel = Src * SrcFactor + Dst * DstFactor + sfBlendEquationSubtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor + sfBlendEquationReverseSubtract ///< Pixel = Dst * DstFactor - Src * SrcFactor } sfBlendEquation; From 962a6855707bf9aefe12368c8e4b1e14b40afa48 Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 15:56:21 -0700 Subject: [PATCH 12/16] Added mipmaps to sfRenderTexture and sfTexture. --- include/SFML/Graphics/RenderTexture.h | 16 ++++++++++++++++ include/SFML/Graphics/Texture.h | 25 +++++++++++++++++++++++++ src/SFML/Graphics/RenderTexture.cpp | 7 +++++++ src/SFML/Graphics/Texture.cpp | 7 +++++++ 4 files changed, 55 insertions(+) diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index 754aacf..71a873e 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -316,4 +316,20 @@ CSFML_GRAPHICS_API void sfRenderTexture_setRepeated(sfRenderTexture* renderTextu //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfRenderTexture_isRepeated(const sfRenderTexture* renderTexture); +//////////////////////////////////////////////////////////// +/// \brief Generate a mipmap using the current texture data +/// +/// This function is similar to sfTexture_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 sfTrue if mipmap generation was successful, sfFalse if unsuccessful +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfBool sfRenderTexture_generateMipmap(sfRenderTexture* renderTexture); + #endif // SFML_RENDERTEXTURE_H diff --git a/include/SFML/Graphics/Texture.h b/include/SFML/Graphics/Texture.h index 052bf1a..3c83527 100644 --- a/include/SFML/Graphics/Texture.h +++ b/include/SFML/Graphics/Texture.h @@ -264,6 +264,31 @@ CSFML_GRAPHICS_API void sfTexture_setRepeated(sfTexture* texture, sfBool repeate //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfTexture_isRepeated(const sfTexture* texture); +//////////////////////////////////////////////////////////// +/// \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 sfTrue if mipmap generation was successful, sfFalse if unsuccessful +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfBool sfTexture_generateMipmap(sfTexture* texture); + //////////////////////////////////////////////////////////// /// \brief Get the underlying OpenGL handle of the texture. /// diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index d80b13f..57b5554 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -281,3 +281,10 @@ sfBool sfRenderTexture_isRepeated(const sfRenderTexture* renderTexture) { CSFML_CALL_RETURN(renderTexture, isRepeated(), sfFalse); } + + +//////////////////////////////////////////////////////////// +sfBool sfRenderTexture_generateMipmap(sfRenderTexture* renderTexture) +{ + CSFML_CALL_RETURN(renderTexture, generateMipmap(), sfFalse); +} diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index ef440bb..a224351 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -256,6 +256,13 @@ sfBool sfTexture_isRepeated(const sfTexture* texture) } +//////////////////////////////////////////////////////////// +sfBool sfTexture_generateMipmap(sfTexture* texture) +{ + CSFML_CALL_PTR_RETURN(texture, generateMipmap(), sfFalse); +} + + //////////////////////////////////////////////////////////// unsigned int sfTexture_getNativeHandle(const sfTexture* texture) { From 15995fa19cd4c0e24510b62331a51b81f000ae4e Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 16:04:14 -0700 Subject: [PATCH 13/16] Fixed spacing... --- include/SFML/Graphics/Glsl.h | 1 + include/SFML/Graphics/RenderTexture.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/SFML/Graphics/Glsl.h b/include/SFML/Graphics/Glsl.h index aa3f562..62c23ff 100644 --- a/include/SFML/Graphics/Glsl.h +++ b/include/SFML/Graphics/Glsl.h @@ -93,4 +93,5 @@ typedef struct float array[4 * 4]; } sfGlslMat4; + #endif // SFML_GLSL_H diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index 71a873e..5bc3fed 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -332,4 +332,5 @@ CSFML_GRAPHICS_API sfBool sfRenderTexture_isRepeated(const sfRenderTexture* rend //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfRenderTexture_generateMipmap(sfRenderTexture* renderTexture); + #endif // SFML_RENDERTEXTURE_H From 3c70f99028a0341a92fae10b593f0e6b0c6df98b Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 16:04:24 -0700 Subject: [PATCH 14/16] Added stereo recording support to sfSoundRecorder. --- include/SFML/Audio/SoundRecorder.h | 28 ++++++++++++++++++++++++++++ src/SFML/Audio/SoundRecorder.cpp | 17 +++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/SFML/Audio/SoundRecorder.h b/include/SFML/Audio/SoundRecorder.h index 92e8d45..610d8de 100644 --- a/include/SFML/Audio/SoundRecorder.h +++ b/include/SFML/Audio/SoundRecorder.h @@ -185,5 +185,33 @@ CSFML_AUDIO_API sfBool sfSoundRecorder_setDevice(sfSoundRecorder* soundRecorder, //////////////////////////////////////////////////////////// CSFML_AUDIO_API const char* sfSoundRecorder_getDevice(sfSoundRecorder* soundRecorder); +//////////////////////////////////////////////////////////// +/// \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 sfSoundRecorder_getChannelCount +/// +//////////////////////////////////////////////////////////// +CSFML_AUDIO_API void sfSoundRecorder_setChannelCount(sfSoundRecorder* soundRecorder, 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 sfSoundRecorder_setChannelCount +/// +//////////////////////////////////////////////////////////// +CSFML_AUDIO_API unsigned int sfSoundRecorder_getChannelCount(const sfSoundRecorder* soundRecorder); + #endif // SFML_SOUNDRECORDER_H diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index c27e922..69a59fd 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -102,6 +102,7 @@ const char** sfSoundRecorder_getAvailableDevices(size_t* count) return !cstringDevices.empty() ? &cstringDevices[0] : NULL; } + //////////////////////////////////////////////////////////// const char* sfSoundRecorder_getDefaultDevice() { @@ -110,12 +111,14 @@ const char* sfSoundRecorder_getDefaultDevice() return !defaultDevice.empty() ? defaultDevice.c_str() : NULL; } + //////////////////////////////////////////////////////////// sfBool sfSoundRecorder_setDevice(sfSoundRecorder* soundRecorder, const char* name) { CSFML_CALL_RETURN(soundRecorder, setDevice(name), sfFalse); } + //////////////////////////////////////////////////////////// const char* sfSoundRecorder_getDevice(sfSoundRecorder* soundRecorder) { @@ -125,3 +128,17 @@ const char* sfSoundRecorder_getDevice(sfSoundRecorder* soundRecorder) return soundRecorder->DeviceName.c_str(); } + + +//////////////////////////////////////////////////////////// +void sfSoundRecorder_setChannelCount(sfSoundRecorder* soundRecorder, unsigned int channelCount) +{ + CSFML_CALL(soundRecorder, setChannelCount(channelCount)); +} + + +//////////////////////////////////////////////////////////// +unsigned int sfSoundRecorder_getChannelCount(const sfSoundRecorder* soundRecorder) +{ + CSFML_CALL_RETURN(soundRecorder, getChannelCount(), 0); +} From 41fa94478a9030d4dcf1c2653e50d3535763ab31 Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 16:29:42 -0700 Subject: [PATCH 15/16] Added address arg to listen/bind on (sockets) --- include/SFML/Network/IpAddress.h | 6 ++++++ include/SFML/Network/TcpListener.h | 6 +++++- include/SFML/Network/UdpSocket.h | 9 ++++++--- src/SFML/Network/IpAddress.cpp | 4 ++++ src/SFML/Network/TcpListener.cpp | 5 +++-- src/SFML/Network/UdpSocket.cpp | 5 +++-- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/SFML/Network/IpAddress.h b/include/SFML/Network/IpAddress.h index 92d9dc5..7ca444c 100644 --- a/include/SFML/Network/IpAddress.h +++ b/include/SFML/Network/IpAddress.h @@ -48,6 +48,12 @@ typedef struct //////////////////////////////////////////////////////////// CSFML_NETWORK_API const sfIpAddress sfIpAddress_None; +//////////////////////////////////////////////////////////// +/// \brief Value representing any address (0.0.0.0) +/// +//////////////////////////////////////////////////////////// +CSFML_NETWORK_API const sfIpAddress sfIpAddress_Any; + //////////////////////////////////////////////////////////// /// \brief Local host IP address (127.0.0.1, or "localhost") /// diff --git a/include/SFML/Network/TcpListener.h b/include/SFML/Network/TcpListener.h index 3ac3507..9e65c58 100644 --- a/include/SFML/Network/TcpListener.h +++ b/include/SFML/Network/TcpListener.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -98,13 +99,16 @@ CSFML_NETWORK_API unsigned short sfTcpListener_getLocalPort(const sfTcpListener* /// If the socket was previously listening to another port, /// it will be stopped first and bound to the new port. /// +/// If there is no specific address to listen to, pass sfIpAddress_Any +/// /// \param listener TCP listener object /// \param port Port to listen for new connections +/// \param address Address of the interface to listen on /// /// \return Status code /// //////////////////////////////////////////////////////////// -CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port); +CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port, sfIpAddress address); //////////////////////////////////////////////////////////// /// \brief Accept a new connection diff --git a/include/SFML/Network/UdpSocket.h b/include/SFML/Network/UdpSocket.h index 21dc2b5..e0d9fba 100644 --- a/include/SFML/Network/UdpSocket.h +++ b/include/SFML/Network/UdpSocket.h @@ -101,13 +101,16 @@ CSFML_NETWORK_API unsigned short sfUdpSocket_getLocalPort(const sfUdpSocket* soc /// system to automatically pick an available port, and then /// call sfUdpSocket_getLocalPort to retrieve the chosen port. /// -/// \param socket UDP socket object -/// \param port Port to bind the socket to +/// If there is no specific address to listen to, pass sfIpAddress_Any +/// +/// \param socket UDP socket object +/// \param port Port to bind the socket to +/// \param address Address of the interface to bind to /// /// \return Status code /// //////////////////////////////////////////////////////////// -CSFML_NETWORK_API sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port); +CSFML_NETWORK_API sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port, sfIpAddress address); //////////////////////////////////////////////////////////// /// \brief Unbind a UDP socket from the local port to which it is bound diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 9f0e6de..07bfe71 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -53,6 +53,10 @@ namespace const sfIpAddress sfIpAddress_None = sfIpAddress_fromBytes(0, 0, 0, 0); +//////////////////////////////////////////////////////////// +const sfIpAddress sfIpAddress_Any = sfIpAddress_fromBytes(0, 0, 0, 0); + + //////////////////////////////////////////////////////////// const sfIpAddress sfIpAddress_LocalHost = sfIpAddress_fromBytes(127, 0, 0, 1); diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index dded940..f64a0d2 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -67,11 +67,12 @@ unsigned short sfTcpListener_getLocalPort(const sfTcpListener* listener) //////////////////////////////////////////////////////////// -sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port) +sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port, sfIpAddress address) { CSFML_CHECK_RETURN(listener, sfSocketError); - return static_cast(listener->This.listen(port)); + sf::IpAddress sfmlAddress(address.address); + return static_cast(listener->This.listen(port, sfmlAddress)); } diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 9e181aa..60dd518 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -68,11 +68,12 @@ unsigned short sfUdpSocket_getLocalPort(const sfUdpSocket* socket) //////////////////////////////////////////////////////////// -sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port) +sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port, sfIpAddress address) { CSFML_CHECK_RETURN(socket, sfSocketError); - return static_cast(socket->This.bind(port)); + sf::IpAddress sfmlAddress(address.address); + return static_cast(socket->This.bind(port, sfmlAddress)); } From 470bf3d19060f1b9b5e68533d97c3de8833450be Mon Sep 17 00:00:00 2001 From: Alec Iverson Date: Fri, 12 Aug 2016 16:38:42 -0700 Subject: [PATCH 16/16] Correctly deprecated sfMouseWheelEvent. Corrected some spacing/alignment. --- include/SFML/Graphics/BlendMode.h | 2 +- include/SFML/Window/Event.h | 33 +++++++++++++++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.h b/include/SFML/Graphics/BlendMode.h index 00782a6..8d3c144 100644 --- a/include/SFML/Graphics/BlendMode.h +++ b/include/SFML/Graphics/BlendMode.h @@ -58,7 +58,7 @@ typedef enum { sfBlendEquationAdd, ///< Pixel = Src * SrcFactor + Dst * DstFactor sfBlendEquationSubtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor - sfBlendEquationReverseSubtract ///< Pixel = Dst * DstFactor - Src * SrcFactor + sfBlendEquationReverseSubtract ///< Pixel = Dst * DstFactor - Src * SrcFactor } sfBlendEquation; diff --git a/include/SFML/Window/Event.h b/include/SFML/Window/Event.h index 12354aa..c4f13d9 100644 --- a/include/SFML/Window/Event.h +++ b/include/SFML/Window/Event.h @@ -117,10 +117,13 @@ typedef struct } sfMouseButtonEvent; //////////////////////////////////////////////////////////// -/// \brief Mouse wheel events parameters (deprecated) +/// \brief Mouse wheel events parameters /// +/// \deprecated +/// Use sfMouseWheelScrollEvent instead. +/// //////////////////////////////////////////////////////////// -typedef struct +typedef struct CSFML_DEPRECATED { sfEventType type; int delta; @@ -216,19 +219,19 @@ typedef struct //////////////////////////////////////////////////////////// typedef union { - sfEventType type; ///< Type of the event - sfSizeEvent size; ///< Size event parameters - sfKeyEvent key; ///< Key event parameters - sfTextEvent text; ///< Text event parameters - sfMouseMoveEvent mouseMove; ///< Mouse move event parameters - sfMouseButtonEvent mouseButton; ///< Mouse button event parameters - sfMouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (deprecated) - sfMouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters - sfJoystickMoveEvent joystickMove; ///< Joystick move event parameters - sfJoystickButtonEvent joystickButton; ///< Joystick button event parameters - sfJoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters - sfTouchEvent touch; ///< Touch events parameters - sfSensorEvent sensor; ///< Sensor event parameters + sfEventType type; ///< Type of the event + sfSizeEvent size; ///< Size event parameters + sfKeyEvent key; ///< Key event parameters + sfTextEvent text; ///< Text event parameters + sfMouseMoveEvent mouseMove; ///< Mouse move event parameters + sfMouseButtonEvent mouseButton; ///< Mouse button event parameters + sfMouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (deprecated) + sfMouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters + sfJoystickMoveEvent joystickMove; ///< Joystick move event parameters + sfJoystickButtonEvent joystickButton; ///< Joystick button event parameters + sfJoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters + sfTouchEvent touch; ///< Touch events parameters + sfSensorEvent sensor; ///< Sensor event parameters } sfEvent;