[SailfishDevel] Problem with OpenGL

Iosif Hamlatzis i.hamlatzis at gmail.com
Tue Mar 18 22:11:45 UTC 2014


In my game I have a class (ResourceManager) for loading .png images and
converting them to 2D textures. The code is fully debugged as it works on
various mobile platforms already but it seems something is happening with
SailfishOS

bool ResourceManager::DoCreateSurface( unsigned int iSurface )

{

    SurfaceNode* pSurfaceNode = mSurfaceCache.GetAt( iSurface );


	// Make sure there's a surface to create

	if( pSurfaceNode->strFilename[0] == 0 )

		return true;


	std::string strFile = std::string(pSurfaceNode->strFilename);


	int width, height;


	SDL_Surface *surface = IMG_Load( strFile.c_str() );

    if ( surface == 0 )

        Debug::DbgOutF( "failed to load file: %s\n", strFile.c_str() );

    	width = surface->w;

	height = surface->h;


	int nNewWidth = 2;

	int nNewHeight = 2;


	while( nNewWidth < width )

		nNewWidth = nNewWidth << 1;


	while( nNewHeight < height )

		nNewHeight = nNewHeight << 1;


	SDL_Surface *image = SDL_CreateRGBSurface(

			SDL_SWSURFACE,

			nNewWidth, nNewHeight,

			32,

#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */

			0x000000FF,

			0x0000FF00,

			0x00FF0000,

			0xFF000000

#else

			0xFF000000,

			0x00FF0000,

			0x0000FF00,

			0x000000FF

#endif

		       );


    if ( image == 0 )

    {

        Debug::DbgOutF( "Failed to create RGB surface: %s\n", SDL_GetError() );

        SDL_ClearError();

    }


    Uint8 saved_alpha;

    SDL_BlendMode saved_blend_mode;


    int error = 0;

    error = SDL_GetSurfaceAlphaMod(surface, &saved_alpha);

    if ( error != 0 )

    {

        Debug::DbgOutF( "1. failed SDL_GetSurfaceAlphaMod with error
%d: %s\n", error, SDL_GetError() );

        SDL_ClearError();

    }


    error = SDL_SetSurfaceAlphaMod(surface, 255);

    if ( error != 0 )

    {

        Debug::DbgOutF( "1. failed SDL_SetSurfaceAlphaMod with error
%d: %s\n", error, SDL_GetError() );

        SDL_ClearError();

    }


    error = SDL_GetSurfaceBlendMode(surface, &saved_blend_mode);

    if ( error != 0 )

    {

        Debug::DbgOutF( "2. failed SDL_GetSurfaceBlendMode with error
%d: %s\n", error, SDL_GetError() );

        SDL_ClearError();

    }


    error = SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);

    if ( error != 0 )

    {

        Debug::DbgOutF( "2. failed SDL_SetSurfaceBlendMode with error
%d: %s\n", error, SDL_GetError() );

        SDL_ClearError();

    }


	SDL_Rect area;

	area.x = 0;

	area.y = 0;

	area.w = (Uint16)width;

	area.h = (Uint16)height;

    error = SDL_BlitSurface(surface, &area, image, &area);

    if ( error != 0 )

    {

        Debug::DbgOutF( "failed SDL_BlitSurface with error %d: %s\n",
error, SDL_GetError() );

        SDL_ClearError();

    }



    error = SDL_SetSurfaceAlphaMod(surface, saved_alpha);

    if ( error != 0 )

    {

        Debug::DbgOutF( "3. failed SDL_SetSurfaceAlphaMod with error
%d: %s\n", error, SDL_GetError() );

        SDL_ClearError();

    }


    error = SDL_SetSurfaceBlendMode(surface, saved_blend_mode);

    if ( error != 0 )

    {

        Debug::DbgOutF( "3. failed SDL_SetSurfaceBlendMode with error
%d: %s\n", error, SDL_GetError() );

        SDL_ClearError();

    }


	glGenTextures( 1, &(pSurfaceNode->g_surfaceID) );

    GLenum err_ = glGetError();

    Debug::DbgOutF( "1. error code %d\n", err_);


	glBindTexture( GL_TEXTURE_2D, pSurfaceNode->g_surfaceID );

    err_ = glGetError();

    Debug::DbgOutF( "2. error code %d\n", err_);


	glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    err_ = glGetError();

    Debug::DbgOutF( "3. error code %d\n", err_);


    glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    err_ = glGetError();

    Debug::DbgOutF( "4. error code %d\n", err_);


	glTexImage2D(GL_TEXTURE_2D,

		     0,

		     GL_RGBA,

		     nNewWidth, nNewHeight,

		     0,

		     GL_RGBA,

		     GL_UNSIGNED_BYTE,

		     image->pixels);

    err_ = glGetError();

    Debug::DbgOutF( "5. error code %d\n", err_);


	SDL_FreeSurface(image);

	SDL_FreeSurface(surface);


	GLenum err = glGetError();


	Debug::DbgOutF( "DoCreateSurface : %s\n", strFile.c_str() );

	switch ( err )

	{

	case GL_NO_ERROR:

		Debug::DbgOutF("GL_NO_ERROR\n");

		break;

	case GL_INVALID_ENUM:

		Debug::DbgOutF("GL_INVALID_ENUM\n");

		break;

	case GL_INVALID_VALUE:

		Debug::DbgOutF("GL_INVALID_VALUE\n");

		break;

	case GL_INVALID_OPERATION:

		Debug::DbgOutF("GL_INVALID_OPERATION\n");

		break;

	default:

		Debug::DbgOutF("Other: %d\n", (int)err);

		break;

	}


	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

    err_ = glGetError();

    Debug::DbgOutF( "6. error code %d\n", err_);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    err_ = glGetError();

    Debug::DbgOutF( "7. error code %d\n", err_);


	// Store dimensions

	pSurfaceNode->dwWidth = width;

	pSurfaceNode->dwHeight = height;

	pSurfaceNode->bCreated = true;


	SetLastSurfaceRenderTime(iSurface, 0.0f);


	return true;

}



In SailfishOS the call to


                glGenTextures( 1, &(pSurfaceNode->g_surfaceID) );

                            GLenum err_ = glGetError();


fails and it returns error code 1280. But according to the OpenGL ES
API this should only fail if called with a negative value and I'm
calling it with 1.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140319/df18034e/attachment.html>


More information about the Devel mailing list