MCPcopy Create free account
hub / github.com/SFML/SFML / bind

Method bind

src/SFML/Graphics/Texture.cpp:937–1010  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

935
936////////////////////////////////////////////////////////////
937void Texture::bind(const Texture* texture, CoordinateType coordinateType)
938{
939 const TransientContextLock lock;
940
941 if (texture && texture->m_texture)
942 {
943 // When debugging, ensure that the texture name is valid
944 assert((glIsTexture(texture->m_texture) == GL_TRUE) &&
945 "Texture to be bound is invalid, check if the texture is still being used after it has been destroyed");
946
947 // Bind the texture
948 glCheck(glBindTexture(GL_TEXTURE_2D, texture->m_texture));
949
950 // Check if we need to define a special texture matrix
951 if ((coordinateType == CoordinateType::Pixels) || texture->m_pixelsFlipped ||
952 ((coordinateType == CoordinateType::Normalized) && (texture->m_size != texture->m_actualSize)))
953 {
954 // clang-format off
955 std::array matrix = {1.f, 0.f, 0.f, 0.f,
956 0.f, 1.f, 0.f, 0.f,
957 0.f, 0.f, 1.f, 0.f,
958 0.f, 0.f, 0.f, 1.f};
959 // clang-format on
960
961 // If non-normalized coordinates (= pixels) are requested, we need to
962 // setup scale factors that convert the range [0 .. size] to [0 .. 1]
963 if (coordinateType == CoordinateType::Pixels)
964 {
965 matrix[0] = 1.f / static_cast<float>(texture->m_actualSize.x);
966 matrix[5] = 1.f / static_cast<float>(texture->m_actualSize.y);
967 }
968
969 // If normalized coordinates are used when NPOT textures aren't supported,
970 // then we need to setup scale factors to make the coordinates relative to the actual POT size
971 if ((coordinateType == CoordinateType::Normalized) && (texture->m_size != texture->m_actualSize))
972 {
973 matrix[0] = static_cast<float>(texture->m_size.x) / static_cast<float>(texture->m_actualSize.x);
974 matrix[5] = static_cast<float>(texture->m_size.y) / static_cast<float>(texture->m_actualSize.y);
975 }
976
977 // If pixels are flipped we must invert the Y axis
978 if (texture->m_pixelsFlipped)
979 {
980 matrix[5] = -matrix[5];
981 matrix[13] = static_cast<float>(texture->m_size.y) / static_cast<float>(texture->m_actualSize.y);
982 }
983
984 // Load the matrix
985 glCheck(glMatrixMode(GL_TEXTURE));
986 glCheck(glLoadMatrixf(matrix.data()));
987 }
988 else
989 {
990 // Reset the texture matrix
991 glCheck(glMatrixMode(GL_TEXTURE));
992 glCheck(glLoadIdentity());
993 }
994

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected