Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CONTRIBUTING guidelines #932

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Contribution Guidelines
=======================

You would like to see a feature implemented or a bug fixed in SFML? Great!
Contributions to SFML are highly appreciated, be it in the form of general
ideas, concrete suggestions or code patches.

A few guiding rules have been set up on the SFML website that you should be
aware of before opening an Issue or Pull Request. They will help you focus
on the important stuff and prevent you from losing (y)our time with requests
that are out of SFML's scope, known issues, and so on.

http://www.sfml-dev.org/contribute.php

Those rules cover the general scope defined for this project, a coding
style, and a precise procedure to report bugs or suggest new features.
2 changes: 1 addition & 1 deletion cmake/Modules/FindSFML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ if(SFML_STATIC_LIBRARIES)
find_sfml_dependency(VORBIS_LIBRARY "Vorbis" vorbis)
find_sfml_dependency(VORBISFILE_LIBRARY "VorbisFile" vorbisfile)
find_sfml_dependency(VORBISENC_LIBRARY "VorbisEnc" vorbisenc)
find_sfml_dependency(FLAC_LIBRARY "FLAC" flac)
find_sfml_dependency(FLAC_LIBRARY "FLAC" FLAC)

# update the list
set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${FLAC_LIBRARY} ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
Expand Down
1 change: 1 addition & 0 deletions include/SFML/Graphics/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ class SFML_GRAPHICS_API Texture : GlResource
bool m_isSmooth; ///< Status of the smooth filter
bool m_isRepeated; ///< Is the texture in repeat mode?
mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation
bool m_fboAttachment; ///< Is this texture owned by a framebuffer object?
Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache
};

Expand Down
55 changes: 27 additions & 28 deletions src/SFML/Graphics/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,35 +227,34 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector
if (!pixels.empty() && (size.x > 0) && (size.y > 0))
{
// Deduce the image type from its extension
if (filename.size() > 3)

// Extract the extension
const std::size_t dot = filename.find_last_of('.');
const std::string extension = dot != std::string::npos ? toLower(filename.substr(dot + 1)) : "";

if (extension == "bmp")
{
// BMP format
if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, &pixels[0]))
return true;
}
else if (extension == "tga")
{
// TGA format
if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, &pixels[0]))
return true;
}
else if (extension == "png")
{
// PNG format
if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0))
return true;
}
else if (extension == "jpg" || extension == "jpeg")
{
// Extract the extension
std::string extension = toLower(filename.substr(filename.size() - 3));

if (extension == "bmp")
{
// BMP format
if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, &pixels[0]))
return true;
}
else if (extension == "tga")
{
// TGA format
if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, &pixels[0]))
return true;
}
else if (extension == "png")
{
// PNG format
if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0))
return true;
}
else if (extension == "jpg")
{
// JPG format
if (writeJpg(filename, pixels, size.x, size.y))
return true;
}
// JPG format
if (writeJpg(filename, pixels, size.x, size.y))
return true;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/SFML/Graphics/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount,
if (states.shader)
applyShader(NULL);

// If the texture we used to draw belonged to a RenderTexture, then forcibly unbind that texture.
// This prevents a bug where some drivers do not clear RenderTextures properly.
if (states.texture && states.texture->m_fboAttachment)
applyTexture(NULL);

// Update the cache
m_cache.useVertexCache = useVertexCache;
}
Expand Down
3 changes: 3 additions & 0 deletions src/SFML/Graphics/RenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ bool RenderTexture::create(unsigned int width, unsigned int height, bool depthBu
{
// Use frame-buffer object (FBO)
m_impl = new priv::RenderTextureImplFBO;

// Mark the texture as being a framebuffer object attachment
m_texture.m_fboAttachment = true;
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/SFML/Graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ m_texture (0),
m_isSmooth (false),
m_isRepeated (false),
m_pixelsFlipped(false),
m_fboAttachment(false),
m_cacheId (getUniqueId())
{
}
Expand All @@ -91,6 +92,7 @@ m_texture (0),
m_isSmooth (copy.m_isSmooth),
m_isRepeated (copy.m_isRepeated),
m_pixelsFlipped(false),
m_fboAttachment(false),
m_cacheId (getUniqueId())
{
if (copy.m_texture)
Expand Down Expand Up @@ -141,6 +143,7 @@ bool Texture::create(unsigned int width, unsigned int height)
m_size.y = height;
m_actualSize = actualSize;
m_pixelsFlipped = false;
m_fboAttachment = false;

ensureGlContext();

Expand Down Expand Up @@ -592,6 +595,7 @@ Texture& Texture::operator =(const Texture& right)
std::swap(m_isSmooth, temp.m_isSmooth);
std::swap(m_isRepeated, temp.m_isRepeated);
std::swap(m_pixelsFlipped, temp.m_pixelsFlipped);
std::swap(m_fboAttachment, temp.m_fboAttachment);
m_cacheId = getUniqueId();

return *this;
Expand Down
187 changes: 0 additions & 187 deletions src/SFML/Window/Unix/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
#include <X11/keysym.h>
#include <cassert>
#include <cstdlib>
#include <algorithm>
#include <map>


Expand All @@ -43,108 +41,6 @@ namespace

typedef std::map<std::string, xcb_atom_t> AtomMap;
AtomMap atoms;

bool mapBuilt = false;
xcb_keycode_t firstKeycode = 255;
xcb_keycode_t lastKeycode = 0;

// We use a simple array instead of a map => constant time lookup
// xcb_keycode_t can only contain 256 distinct values
xcb_keysym_t keysymMap[256];

xcb_keysym_t keysymToLower(xcb_keysym_t keysym)
{
switch(keysym >> 8)
{
// Latin 1
case 0:
{
if ((keysym >= XK_A) && (keysym <= XK_Z))
return keysym + (XK_a - XK_A);
else if ((keysym >= XK_Agrave) && (keysym <= XK_Odiaeresis))
return keysym + (XK_agrave - XK_Agrave);
else if ((keysym >= XK_Ooblique) && (keysym <= XK_Thorn))
return keysym + (XK_oslash - XK_Ooblique);
break;
}

// Latin 2
case 1:
{
if (keysym == XK_Aogonek)
return XK_aogonek;
else if (keysym >= XK_Lstroke && keysym <= XK_Sacute)
return keysym + (XK_lstroke - XK_Lstroke);
else if (keysym >= XK_Scaron && keysym <= XK_Zacute)
return keysym + (XK_scaron - XK_Scaron);
else if (keysym >= XK_Zcaron && keysym <= XK_Zabovedot)
return keysym + (XK_zcaron - XK_Zcaron);
else if (keysym >= XK_Racute && keysym <= XK_Tcedilla)
return keysym + (XK_racute - XK_Racute);
break;
}

// Latin 3
case 2:
{
if (keysym >= XK_Hstroke && keysym <= XK_Hcircumflex)
return keysym + (XK_hstroke - XK_Hstroke);
else if (keysym >= XK_Gbreve && keysym <= XK_Jcircumflex)
return keysym + (XK_gbreve - XK_Gbreve);
else if (keysym >= XK_Cabovedot && keysym <= XK_Scircumflex)
return keysym + (XK_cabovedot - XK_Cabovedot);
break;
}

// Latin 4
case 3:
{
if (keysym >= XK_Rcedilla && keysym <= XK_Tslash)
return keysym + (XK_rcedilla - XK_Rcedilla);
else if (keysym == XK_ENG)
return XK_eng;
else if (keysym >= XK_Amacron && keysym <= XK_Umacron)
return keysym + (XK_amacron - XK_Amacron);
break;
}

// Cyrillic
case 6:
{
if (keysym >= XK_Serbian_DJE && keysym <= XK_Serbian_DZE)
return keysym - (XK_Serbian_DJE - XK_Serbian_dje);
else if (keysym >= XK_Cyrillic_YU && keysym <= XK_Cyrillic_HARDSIGN)
return keysym - (XK_Cyrillic_YU - XK_Cyrillic_yu);
break;
}

// Greek
case 7:
{
if (keysym >= XK_Greek_ALPHAaccent && keysym <= XK_Greek_OMEGAaccent)
return keysym + (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
else if (keysym >= XK_Greek_ALPHA && keysym <= XK_Greek_OMEGA)
return keysym + (XK_Greek_alpha - XK_Greek_ALPHA);
break;
}

// Armenian
case 0x14:
{
if (keysym >= XK_Armenian_AYB && keysym <= XK_Armenian_fe) {
return (keysym | 1);
}
break;
}

default:
{
break;
}
}

return keysym;
}
}

namespace sf
Expand Down Expand Up @@ -268,89 +164,6 @@ xcb_atom_t getAtom(const std::string& name, bool onlyIfExists)
return reply->atom;
}


////////////////////////////////////////////////////////////
const xcb_keysym_t* getKeysymMap()
{
if (!mapBuilt)
buildKeysymMap();

return keysymMap;
}


////////////////////////////////////////////////////////////
void buildKeysymMap()
{
// Open a connection with the X server
xcb_connection_t* connection = sf::priv::OpenConnection();

firstKeycode = xcb_get_setup(connection)->min_keycode;
lastKeycode = xcb_get_setup(connection)->max_keycode;

sf::priv::ScopedXcbPtr<xcb_generic_error_t> error(NULL);

sf::priv::ScopedXcbPtr<xcb_get_keyboard_mapping_reply_t> keyboardMapping(xcb_get_keyboard_mapping_reply(
connection,
xcb_get_keyboard_mapping(
connection,
firstKeycode,
lastKeycode - firstKeycode + 1
),
&error
));

sf::priv::CloseConnection(connection);

if (error || !keyboardMapping)
{
sf::err() << "Failed to get keyboard mapping" << std::endl;
return;
}

uint8_t keysymsPerKeycode = keyboardMapping->keysyms_per_keycode;

if (!keysymsPerKeycode)
{
sf::err() << "Error: No keysyms per keycode" << std::endl;
return;
}

const xcb_keysym_t* keysyms = xcb_get_keyboard_mapping_keysyms(keyboardMapping.get());

if (!keysyms)
{
sf::err() << "Failed to get keyboard mapping keysyms" << std::endl;
return;
}

xcb_keycode_t range = lastKeycode - firstKeycode + 1;

std::fill(keysymMap, keysymMap + 256, XK_VoidSymbol);

for (xcb_keycode_t i = firstKeycode; ; ++i)
{
const xcb_keysym_t* keysym = &keysyms[(i - firstKeycode) * keysymsPerKeycode];

if ((keysymsPerKeycode == 1) || (keysym[1] == XCB_NO_SYMBOL))
{
keysymMap[i] = keysymToLower(keysym[0]);

if (i == lastKeycode)
break;

continue;
}

keysymMap[i] = keysym[0];

if (i == lastKeycode)
break;
}

mapBuilt = true;
}

} // namespace priv

} // namespace sf
17 changes: 0 additions & 17 deletions src/SFML/Window/Unix/Display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,6 @@ xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection);
////////////////////////////////////////////////////////////
xcb_atom_t getAtom(const std::string& name, bool onlyIfExists = false);

////////////////////////////////////////////////////////////
/// \brief Get the keycode to keysym map
///
/// Contains 255 values. Use the keycode as the index
/// into the array to retrieve its keysym.
///
/// \return Keycode to keysym map
///
////////////////////////////////////////////////////////////
const xcb_keysym_t* getKeysymMap();

////////////////////////////////////////////////////////////
/// \brief Build the keysym map
///
////////////////////////////////////////////////////////////
void buildKeysymMap();

} // namespace priv

} // namespace sf
Expand Down
Loading