Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Texture::GetMaximumSize() returns crazy values on subsequent calls  (Read 2955 times)

0 Members and 1 Guest are viewing this topic.

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
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;
}

thomas9459

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
« Reply #1 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:
  • The program begins and SFML automatically creates an OpenGL context.
  • sf::Texture::getMaximumSize is called. Because it has a valid OpenGL context, it returns a sane value.
  • The sf::RenderWindow gets created, as well as a new OpenGL context for it.
  • The sf::RenderWindow goes out of scope, and its OpenGL context is destroyed. At this point, no OpenGL context is active.
  • sf::Texture::getMaximumSize is called a second time, but because there is not OpenGL context, it returns a "crazy" value.
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.

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
« Reply #2 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.)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
« Reply #3 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. Thor has a BigTexture and BigSprite classes to automatically split large textures into smaller textures for drawing  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

thomas9459

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Texture::GetMaximumSize() returns crazy values on subsequent calls
« Reply #4 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11053
    • View Profile
    • development blog
    • Email
AW: Texture::GetMaximumSize() returns crazy values on subsequent calls
« Reply #5 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/