Skip to content

Commit

Permalink
Merge pull request #457 from isage/master
Browse files Browse the repository at this point in the history
Fix 3.2 context creation on mesa
  • Loading branch information
alexeevdv committed Mar 18, 2016
2 parents f4ec4b4 + c859951 commit 889558c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion data/shaders/21/animation.fp
Expand Up @@ -111,7 +111,7 @@ void main(void)

if (almosteq(origColor.a,0.2) && almosteq(origColor.r, 0.6))
{
int index = int(round(origColor.b * 255.0)) / 51;
int index = int(origColor.b * 255.0) / 51;

if (index<0) index = 0;

Expand Down
2 changes: 1 addition & 1 deletion data/shaders/21/sprite.fp
Expand Up @@ -117,7 +117,7 @@ void main(void)

if (almosteq(origColor.a, 0.2) && almosteq(origColor.r, 0.6))
{
int index = int(round(origColor.b * 255.0)) / 51;
int index = int(origColor.b * 255.0) / 51;

if (index<0) index = 0;

Expand Down
37 changes: 13 additions & 24 deletions src/Graphics/Renderer.cpp
Expand Up @@ -104,14 +104,26 @@ void Renderer::init()
Logger::info("RENDERER") << message + "[OK]" << std::endl;

message = "Init OpenGL - ";
// specifically request 3.2, because fucking Mesa ignores core flag with version < 3
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
_glcontext = SDL_GL_CreateContext(_sdlWindow);

if (!_glcontext)
{
throw Exception(message + "[FAIL]");
// ok, try and create 2.1 context then
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
_glcontext = SDL_GL_CreateContext(_sdlWindow);

if (!_glcontext)
{
throw Exception(message + "[FAIL]");
}
}

Logger::info("RENDERER") << message + "[OK]" << std::endl;
Expand Down Expand Up @@ -329,29 +341,6 @@ const Size& Renderer::size() const
return _size;
}

/*
void Renderer::drawTexture(Texture* texture, int x, int y, int sourceX, int sourceY, unsigned int sourceWidth, unsigned int sourceHeight)
{
if (!texture) return;
if (!sourceX && !sourceY && !sourceWidth && !sourceHeight)
{
SDL_Rect dest = {(short)x, (short)y, (unsigned short)texture->width(), (unsigned short)texture->height()};
SDL_RenderCopy(_sdlRenderer, texture->sdlTexture(), NULL, &dest);
}
else
{
SDL_Rect dest = {(short)x, (short)y, (unsigned short)sourceWidth, (unsigned short)sourceHeight};
SDL_Rect src = {(short)sourceX, (short)sourceY, (unsigned short)sourceWidth, (unsigned short)sourceHeight};
SDL_RenderCopy(_sdlRenderer, texture->sdlTexture(), &src, &dest);
}
}
void Renderer::drawTexture(Texture* texture, const Point& pos, const Point& src, const Size& srcSize)
{
drawTexture(texture, pos.x(), pos.y(), src.x(), src.y(), (unsigned int)srcSize.width(), (unsigned int)srcSize.height());
}
*/

void Renderer::screenshot()
{
std::string filename;
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Tilemap.cpp
Expand Up @@ -119,7 +119,7 @@ void Tilemap::render(const Point &pos, std::vector<GLuint> indexes, uint32_t atl

GLint curvao;
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &curvao);
if (curvao != _vao)
if ((GLuint)curvao != _vao)
{
GL_CHECK(glBindVertexArray(_vao));
}
Expand Down

0 comments on commit 889558c

Please sign in to comment.