SFML community forums

Help => Graphics => Topic started by: Clairvoire on January 25, 2014, 08:38:12 pm

Title: Texture::GetMaximumSize() returns crazy values on subsequent calls
Post by: Clairvoire on January 25, 2014, 08:38:12 pm
Hello!  I wrote a program to print out the maximum size of a texture I can create, so I can get a rough idea of what a good lower limit is when programming.  (so far, I've yet to see a value below 8192). 

It prints a reasonable number at first.  But if I run the function a second time, it'll return a different, and insanely large, number.  This occurred on my laptop as well.  I'm using the latest version, fresh from the git repo.

For me, the first time, it gave me 16384.  Every time after that though, it was "11457127" which isn't even a power of 2 (or even for that matter)

Here's the code I used, it's relatively small.  The check occurs on the first line of "queryOpenGL()." I left in the other tests in case they may have had something to do with it.  This should compile I think. 

#include <cstdio>
#include <SFML/Graphics.hpp>


void queryOpenGL(){
        printf("\nMaximum texture size is %u\n", sf::Texture::getMaximumSize());
        bool modeTest = sf::VideoMode(640, 480).isValid();
        printf("A fullscreen mode of 640 by 480 is %s\n", modeTest ? "VALID" : "NOT VALID what???");
        sf::RenderWindow window(sf::VideoMode(50, 50), "Test Window", 7U, sf::ContextSettings(24, 8, 0));
        printf("Framebuffer depth/stencil format: %u:%u\n", window.getSettings().depthBits, window.getSettings().stencilBits);
        printf("Shaders are... %s\n", sf::Shader::isAvailable() ? "VALID" : "NOT VALID aawwww");
        sf::RenderTexture texture;
        bool success = texture.create(1024, 1024, true);
        printf("Attempting to create a Framebuffer Object ... %s\n", success ? "SUCCESSFUL!" : "FAILURE OH NO");
        printf("Concluding test\n");
        printf( " (\\_/)\n"
                        "(@' <'@)  Thanks bebe~\n\n");
}

int main(int argc, char * argv[]){
        char * initialMessage =
                "What tool to use?  (enter the digit)\n"
                "  0: Quit\n"
                "  1: Query SFML to see some things\n"
                ">>";
        int choice;
        do{
                printf(initialMessage);
                scanf("%i", &choice);
                switch(choice){
                case 1:
                        queryOpenGL();
                        break;
                }
                printf("\n-----\n");
        }while(choice);
        return 0;
}
Title: Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
Post by: thomas9459 on January 25, 2014, 10:56:09 pm
This occurs because no valid OpenGL context exists on the subsequent calls. Here is what are the relevant events that occur when the posted code is run:
If the line testing the texture size is moved to after window is created, it should always return the correct value.

(As a bonus, I found out by toying with this problem that on my old Linux Mint machine, my maximum texture size is 2048.)

TL;DR The posted code contains an "error": it calls sf::Texture::getMaximumSize when there is no OpenGL context.
Title: Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
Post by: Clairvoire on January 26, 2014, 12:07:50 am
Aw, that was it!  I'll keep that in mind from now on!  Just moved the window creation to the very start.  Thank you! 

(and thanks for the texture size!  It's so hard to get a fair idea of what to expect in that regard.  I guess I should aim for 1024 and just make a runtime workaround thing if it ever returns lower than that.)
Title: Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
Post by: zsbzsb on January 26, 2014, 12:15:24 am
Well you need to choose yourself the minimum texture size you will support. But as for loading larger textures than the GPU supports you can take a look at Thor (http://www.bromeon.ch/libraries/thor). Thor has a BigTexture and BigSprite classes to automatically split large textures into smaller textures for drawing  ;)
Title: Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
Post by: thomas9459 on January 26, 2014, 03:20:52 am
The guaranteed minimum texture size in OpenGL 3.x - 4.x is 1024, so you should be safe with that. Unfortunately, the guaranteed minimum in 2.x is only 64.
Title: AW: Texture::GetMaximumSize() returns crazy values on subsequent calls
Post by: eXpl0it3r on January 26, 2014, 11:46:14 am
As for the original issue, it seems to be a bug. Given that we have a global context, it should get activated when call the function, so we can make sure, that it will always return a valid number.
If it shouldn't get changed, that a notice in the documentation is required.

Not sure if Laurent will see this thread, otherwise a ticket/ pull request could be opened on GitHub.