Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/SFML/Graphics/Glsl.inl is written in an unsupported language. File is not indexed.

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 
0026 ////////////////////////////////////////////////////////////
0027 /// \brief Helper functions to copy sf::Transform to sf::Glsl::Mat3/4
0028 ///
0029 ////////////////////////////////////////////////////////////
0030 void SFML_GRAPHICS_API copyMatrix(const Transform& source, Matrix<3, 3>& dest);
0031 void SFML_GRAPHICS_API copyMatrix(const Transform& source, Matrix<4, 4>& dest);
0032 
0033 ////////////////////////////////////////////////////////////
0034 /// \brief Copy array-based matrix with given number of elements
0035 ///
0036 /// Indirection to std::copy() to avoid inclusion of
0037 /// <algorithm> and MSVC's annoying 4996 warning in header
0038 ///
0039 ////////////////////////////////////////////////////////////
0040 void SFML_GRAPHICS_API copyMatrix(const float* source, std::size_t elements, float* dest);
0041 
0042 ////////////////////////////////////////////////////////////
0043 /// \brief Helper functions to copy sf::Color to sf::Glsl::Vec4/Ivec4
0044 ///
0045 ////////////////////////////////////////////////////////////
0046 void SFML_GRAPHICS_API copyVector(const Color& source, Vector4<float>& dest);
0047 void SFML_GRAPHICS_API copyVector(const Color& source, Vector4<int>& dest);
0048 
0049 
0050 ////////////////////////////////////////////////////////////
0051 /// \brief Matrix type, used to set uniforms in GLSL
0052 ///
0053 ////////////////////////////////////////////////////////////
0054 template <std::size_t Columns, std::size_t Rows>
0055 struct Matrix
0056 {
0057     ////////////////////////////////////////////////////////////
0058     /// \brief Construct from raw data
0059     ///
0060     /// \param pointer Points to the beginning of an array that
0061     ///                has the size of the matrix. The elements
0062     ///                are copied to the instance.
0063     ///
0064     ////////////////////////////////////////////////////////////
0065     explicit Matrix(const float* pointer)
0066     {
0067         copyMatrix(pointer, Columns * Rows, array);
0068     }
0069 
0070     ////////////////////////////////////////////////////////////
0071     /// \brief Construct implicitly from SFML transform
0072     ///
0073     /// This constructor is only supported for 3x3 and 4x4
0074     /// matrices.
0075     ///
0076     /// \param transform Object containing a transform.
0077     ///
0078     ////////////////////////////////////////////////////////////
0079     Matrix(const Transform& transform)
0080     {
0081         copyMatrix(transform, *this);
0082     }
0083 
0084     float array[Columns * Rows]; //!< Array holding matrix data
0085 };
0086 
0087 ////////////////////////////////////////////////////////////
0088 /// \brief 4D vector type, used to set uniforms in GLSL
0089 ///
0090 ////////////////////////////////////////////////////////////
0091 template <typename T>
0092 struct Vector4
0093 {
0094     ////////////////////////////////////////////////////////////
0095     /// \brief Default constructor, creates a zero vector
0096     ///
0097     ////////////////////////////////////////////////////////////
0098     Vector4() :
0099     x(0),
0100     y(0),
0101     z(0),
0102     w(0)
0103     {
0104     }
0105 
0106     ////////////////////////////////////////////////////////////
0107     /// \brief Construct from 4 vector components
0108     ///
0109     /// \param X Component of the 4D vector
0110     /// \param Y Component of the 4D vector
0111     /// \param Z Component of the 4D vector
0112     /// \param W Component of the 4D vector
0113     ///
0114     ////////////////////////////////////////////////////////////
0115     Vector4(T X, T Y, T Z, T W) :
0116     x(X),
0117     y(Y),
0118     z(Z),
0119     w(W)
0120     {
0121     }
0122 
0123     ////////////////////////////////////////////////////////////
0124     /// \brief Conversion constructor
0125     ///
0126     /// \param other 4D vector of different type
0127     ///
0128     ////////////////////////////////////////////////////////////
0129     template <typename U>
0130     explicit Vector4(const Vector4<U>& other) :
0131     x(static_cast<T>(other.x)),
0132     y(static_cast<T>(other.y)),
0133     z(static_cast<T>(other.z)),
0134     w(static_cast<T>(other.w))
0135     {
0136     }
0137 
0138     ////////////////////////////////////////////////////////////
0139     /// \brief Construct float vector implicitly from color
0140     ///
0141     /// \param color Color instance. Is normalized to [0, 1]
0142     ///              for floats, and left as-is for ints.
0143     ///
0144     ////////////////////////////////////////////////////////////
0145     Vector4(const Color& color)
0146     // uninitialized
0147     {
0148         copyVector(color, *this);
0149     }
0150 
0151     T x; //!< 1st component (X) of the 4D vector
0152     T y; //!< 2nd component (Y) of the 4D vector
0153     T z; //!< 3rd component (Z) of the 4D vector
0154     T w; //!< 4th component (W) of the 4D vector
0155 };