I followed this tutorial to create a basic game using OpenGL and after profiling it, discovered that even after a sprite is removed, the textures are not being released creating a memory leak. I easily fixed the problem by creating a cache in the Sprite class, but I would like to know how I can delete the texture itself for future reference. It is loaded with GLKTextureLoader.
GLuint index = self.textureInfo.name;
glDeleteTextures(1, &index);
Related
Platform: Android OpenGL ES 2.0
I am using FBO, there is a texture attached to this FBO, after use, I use glDeleteFramebuffers to release FBO, the question is: Do I need to manually release the texture I created also? or glDeleteFramebuffers will also release the texture attached to it?
I would have thought you'd have to release each texture that you've created as well. There should be a delete call for every create call.
I try to use the great particle emitter which Michael Daley build for his Particle Designer to be working inside a GLKView. I see two ways to get there:
hack the code from his great (but too old) tutorial to work with iOS5.1 inside a GLKView
pay and use his Particle Designer to add the particle effect to a glkview
I tried 1. the whole day but ended alone and lost in the wide lands of openGL. I don't know how or what is important to initialize from the GL-stuff.
I ported the classes Image, Texture2D, Common and ParticleEmitter and instantiated them inside a GLKViewController, ending with an EXC_BAD_ACCESS in line 341 of ParticleEmitter.m:
// Now that all of the VBOs have been used to configure the vertices, pointer size and color
// use glDrawArrays to draw the points
glDrawArrays(GL_POINTS, 0, particleIndex);
and I don't know why or what....
Now I think about buying the Particle Designer and try to implement it inside the GLKViewController and its GLKView.
Is there any body who could help me with 1./2. to solve my problem, adding an openGL particle emitter to a view based application?
thanx!
edit: removed some stupid code
Looks like this one could help a lot...
;-)
I also created a new question here.
CCAnimate requires CCSpriteFrames, while they require a texture2d.
Is it not possible to simply use CCAnimate by providing my file names? Like anim1.png, anim2.png, anim3.png...
Not directly.
If you are on versions 0.99.*, you can load the files into UIImages, then create CCTexture2Ds using the initWithImage: function, then create CCSpriteFrames.
If you are on version 1.0.0 or later, you can load the textures from files using the CCTextureCache singleton, then create CCSpriteFrames.
However, the whole point behind this API is that you can place all the frames of your animation into one image file, load it as a texture, and then carve out the individual frames using the rect property/argument. This should also improve performance, since the graphics chip only has to load one texture and then perform cheap clipping operation instead of loading multiple textures.
EDIT: Cocos2D has a function for direct CCSpriteFrame loading since version 1.1.
I'm trying to build a weather application on the iPad but it seems that I need some help in animation. Say I'm animating a Radar, so the radar source files have 10 gif/jpeg pictures in 900x700 pixel size. I've tried the UIImage animation technique using the tutorial here:
http://www.icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/
but it seems that loading 10 images that big is too much for the iPad to handle and its crashing due to memory warnings. I'm researching other techniques to animate but I can't seem to find something that will do this efficiently.
I've looked at others like Core Animation using sprites, and Cocos2D with sprites. Can someone point in the right direction the best way to animate these big images? (keep in mind that these images are dynamic and changes often so the sprites will have to be recreated on a server and fetched from the iPad to do the animation). Thanks
OpenGL only creates textures with dimensions at powers of 2. In the case of your images, that's 1024x1024, which is a meg of memory per image. Still, that shouldn't be a problem with the iPad.
First, investigate using Xcode's profiling tools to ensure the images aren't being repeatedly loaded into memory at each loop of the animation (likely by way of new objects that aren't sharing cached textures). That could solve your problem from the start.
Second, I recommend using Cocos2D if only for the easy handling of textures and caching. Toss the images into a CCAnimation, pop that into a CCRepeatForever, run it with a CCSequence. When you're done hit CCTextureCache to release unused textures.
Third, lower your animation framerate to 30 or less (if only for this animation). It may be the iPad, but you making a weather app. Not a video game.
Finally, downgrade the size of your image. Justify all you want, but a large radar animation will not sell your app. And just because a website might already be playing that animation beautifully, remember that a desktop has vastly more memory and power than any smart phone.
Try breaking the animation image into into smaller parts and animate those instead by treating each components as sprites. It would be best if you use primarily code (CoreGraphics) and draw your radar "by hand" instead of just using images as if they were animated GIFs.
i'm work on a buffer for load very large pictures ( screen size) to single surface.
The idea is to animate a lot of pictures ( more than the video memory can store ) frame by frame.
I have create a code for make a buffer but i have a big problem with the loading time of bitmap.
My code work a this :
I load an array of local bitmap files path.
I (think ) i preload my bitmap datas in memory. I'm using a thread for store a CGImageRef in an NSArray for all my picture ( 40 for moment )
In a second thread, the code look another NSArray for determine if is empty of not, if is empty, i bind my cgimageRef to the video memory by creating textures. ( use sharedgroup for this)
This array store the adress of 20 textures names, and it's use directly by openGL for draw the surface. this array is my (buffer)
When i play my animation, i delete old textures from my "buffer" and my thread ( at point 3) load a new texture.
It's work great, but is really slow, and after few second, the animation lack.
Can you help me for optimise my code ?
Depending on device and iOS version glTexImage is just slow.
With iOS 4 performance was improved so that you can expect decent speed on 2nd gen devices too, and with decent I mean one or two texture uploads per frame...
Anyway:
Use glTexSubImage and reuse already created texture-IDs.
Also, when using glTex(Sub)Image, try to use a texture-ID that wasn't used for rendering in that frame. I mean: add some kind of texture-ID-doublebuffering.
I asume you do all your GL stuff in the same thread, if not change it.