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

Author Topic: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?  (Read 9979 times)

0 Members and 2 Guests are viewing this topic.

Haikarainen

  • Guest
OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« on: June 06, 2012, 01:31:05 am »
I don't know if the problem is related to SFML at all, but i'm posting it here either way!

A project of mine is using SFML to create a window as well as load imagefiles, and so far this has been going great! I'm currently working on drawing  planet earth using highresolution textures and shaders, currently I have 3 textures I want to use, all of wich are 8192x4096:
  • Normal/Daylight
  • Night-texture
  • Cloudmap

Regardless of the order I'm loading these in, the third one always fails with GL_OUT_OF_MEMORY after the methodcall gluBuild2DMipmaps. Remember I dont use sf::Texture or sf::Shader here, only sf::RenderWindow and sf::Image. The program still runs but the third texture seems to contain no pixeldata, making it transparent.

If I load the  night-texture last: https://legacy.sfmluploads.org/cache/pics/243_earthclouds.png
If I load the cloud-texture last: https://legacy.sfmluploads.org/cache/pics/244_earthnight.png

I suspect it being a missing glcontext or something, therefore I wanted to use ensureGlContext to ensure it but noticed that method is protected :/ Is there anyone who knows what it might be?

The max texture size on my system is 16K, so that passes.

Full code to create a  texture:

de::Texture::Texture(de::Base* r, std::string name,std::string path){
        std::cout << "Loading texture from " << path.c_str() << "..";
        this->Root = r;
        this->Name = "__not_ready";
        this->Handle = 0;
        this->IsReady = false;
        sf::Image c;
        if(c.loadFromFile(path)){
                glGenTextures(1, &this->Handle);
                glBindTexture(GL_TEXTURE_2D, this->Handle);
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, c.getSize().x, c.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, c.getPixelsPtr());
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

                if(this->Root->GetGLSystem()->GetHardware()->Anisotrophy){
                        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, this->Root->GetGLSystem()->GetHardware()->Anisotrophy);
                }
                this->IsReady = true;
                this->Name = name;
                std::cout << "Created texture!" << std::endl;
        }else{
                std::cout << "Couldn't load texture from file." << std::endl;
                throw(de::Exception("Couldn't create a texture, image not valid!"));
        }
}

de::Texture::Handle is a GLuint

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #1 on: June 06, 2012, 08:25:19 am »
How many MB of RAM does your graphics card have (512?)? GL_OUT_OF_MEMORY clearly states that it's full. A context error would trigger the GL_INVALID_OPERATION error.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #2 on: June 06, 2012, 03:22:02 pm »
How many MB of RAM does your graphics card have (512?)? GL_OUT_OF_MEMORY clearly states that it's full. A context error would trigger the GL_INVALID_OPERATION error.

I highly doubt this, I have 2 AMD HD6870 in Crossfire with 1GB each(Dont think the second gpu mem is used but still). I've also heard OUT_OF_MEMORY is triggered when a malloc() fails.

Anyway  I did some testing yesterday before I went to bed, If I loaded the first texture 10 times before loading the others, it seemed to work. Once. Then it failed again.

I have now also created my own glCheck function and wrapped all GL-calls in that, and I get no other errors than OUT_OF_MEMORY when generating mipmaps in loading textures.


EDIT: Something else I noted yesterday, apparently I dont have shader support unless I draw something to the window after creating it, and before loading resources.  That is (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) returns true. This made me suspect that sf::RenderWindow isn't that stable to use with pure OpenGL yet?
« Last Edit: June 06, 2012, 03:32:27 pm by Haikarainen »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #3 on: June 06, 2012, 03:31:18 pm »
Apparently GL_OUT_OF_MEMORY can indeed be triggered if there's no context (that's weird...). Is there a chance that no context is active when you get this error?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #4 on: June 06, 2012, 03:32:55 pm »
Apparently GL_OUT_OF_MEMORY can indeed be triggered if there's no context (that's weird...). Is there a chance that no context is active when you get this error?

Actually read my edit, I think it might have something to do with it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #5 on: June 06, 2012, 03:43:35 pm »
Quote
That is (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) returns true. This made me suspect that sf::RenderWindow isn't that stable to use with pure OpenGL yet?
This is not pure OpenGL, this is GLEW. Is GLEW properly initialized when you run this code?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #6 on: June 06, 2012, 03:54:32 pm »
Quote
That is (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) returns true. This made me suspect that sf::RenderWindow isn't that stable to use with pure OpenGL yet?
This is not pure OpenGL, this is GLEW. Is GLEW properly initialized when you run this code?

Didn't realize GLEW had to be initialized. It is initializing now and the shader-bug disappeared, anyhow still getting out of memory on texture loading :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #7 on: June 06, 2012, 04:14:47 pm »
Ok, so let's go back to the previous question:
Quote
Is there a chance that no context is active when you get this error?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #8 on: June 06, 2012, 04:28:42 pm »
Im not quite sure, I've tried to use setActive on my renderwindow after creation and before creating the textures. I guess SFML is  creating this context, but all of those functions are private/protected. How can I be sure?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #9 on: June 06, 2012, 04:37:50 pm »
The design of your engine must ensure that there is always an active OpenGL context in the current thread when you call an OpenGL function. This is the most important thing to consider when writing OpenGL code.

If you need an OpenGL context but have no window, you can instanciate a sf::Context.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #10 on: June 06, 2012, 04:39:53 pm »
Allright, well I create the sf::RenderWindow before loading my textures, is there any way for me to make sure that its glContext is active?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #11 on: June 06, 2012, 04:49:59 pm »
window.setActive(true);

By the way, do you use threads?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #12 on: June 06, 2012, 04:54:56 pm »
window.setActive(true);

By the way, do you use threads?

I do not use any threading.  the setActive(true) made no difference :/ I appreciate your help though, this problem probably has little to do with sfml

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #13 on: June 06, 2012, 05:01:18 pm »
If you can write a complete and minimal code that reproduces the problem, I can try to have a look at it.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: OpenGL Problems: GL_OUT_OF_MEMORY, ensureGlContext?
« Reply #14 on: June 06, 2012, 05:26:17 pm »
If you can write a complete and minimal code that reproduces the problem, I can try to have a look at it.

As complete and minimal as I possible could make it and still catch errors properly:
http://fredrik.haikarainen.se/test.rar