Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048
Sorry I missed the answers because of my email settings. However they are still useful. Thank you very much. John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=58768#58768 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Set Viewport background color as transparent
Hi Vishwa, today when I was updating my OSG I just realized that I was using a modified version of GraphicsWindowIOS... that's why transparency was working with that code. You can achieve the same result with the original GraphicsWindowIOS by calling this code before setting the traits: Code: osg::ref_ptrosgViewer::GraphicsWindowIOS::WindowData windowData = new osgViewer::GraphicsWindowIOS::WindowData(self.renderView, osgViewer::GraphicsWindowIOS::WindowData::ALL_ORIENTATIONS); windowData-setCreateTransparentView(true); // Init the Windata Variable that holds the handle for the Window to display OSG in. osg::ref_ptrosg::Referenced windata = windowData; I know it's 2 years... but I hope it helps someone to know how to do it... Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=58752#58752 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Multisample makes app crash for memory pressure after 5/6 consecutive changes of orientation in iOS devices
Hi, I am experiencing a strange problem in my iOS app using OpenSceneGraph. I use this code to create a graphics context Code: - (osg::ref_ptrosg::GraphicsContext)createGraphicContext { //create our graphics context directly so we can pass our own window osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits; // Init the Windata Variable that holds the handle for the Window to display OSG in. osg::ref_ptrosg::Referenced windata = new osgViewer::GraphicsWindowIOS::WindowData(self.renderView, osgViewer::GraphicsWindowIOS::WindowData::ALL_ORIENTATIONS); // Setup the traits parameters traits-x = 0; traits-y = 0; NSLog(@is retina display? content scale factor is: %f, self.renderView.contentScaleFactor); traits-width = self.renderView.bounds.size.width*self.renderView.contentScaleFactor; traits-height = self.renderView.bounds.size.height*self.renderView.contentScaleFactor; NSLog(@Traits width is %d, traits height is %d, traits-width, traits-height); traits-depth = 16; //keep memory down, default is currently 24 traits-sampleBuffers = true; traits-samples = 4; traits-alpha = 8; traits-windowDecoration = true; traits-doubleBuffer = true; traits-sharedContext = 0; traits-setInheritedWindowPixelFormat = true; traits-inheritedWindowData = windata; // Create the Graphics Context osg::ref_ptrosg::GraphicsContext graphicsContext = osg::GraphicsContext::createGraphicsContext(traits.get()); #ifdef DEBUG_OPENSCENEGRAPH osg::setNotifyLevel(osg::DEBUG_INFO); #else osg::setNotifyLevel(osg::FATAL); #endif return graphicsContext; } Now if I use the option Code: traits-sampleBuffers = false; there is no problem. But when I enable the antialiasing by setting it to true Code: traits-sampleBuffers = true; After around 6 - 7 changes of orientation in the app (i.e. when the user rotates the device), the app crashes due to memory pressure. The strange thing is that I am looking to the memory reported by XCode and the memory is below 30 MB when the crash happens. Do you have any idea why this crash is happening? Am I missing some setting during the Graphics context creation ? Thank you very much for your support, John[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=58729#58729 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Optimizing memory usage by Texture of size 4096x2048
Hi, In my app I am using 2 textures of size 4096x2048. I have a serious problem of memory usage. Code: osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(image.release()); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture:: LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(image2.release()); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get()); using this code my app jumps from 20 MB of memory to 250 MB of memory usage Since I am developing on mobile platform this is a huge waste of memory. I partially solved the problem by changing the MIN_FILTER from LINEAR_MIPMAP_LINEAR to LINEAR Now the memory usage is 150MB It's still a lot! Do you know a way to optimize the memory usage of these 2 textures? Thank you, Have a nice day (or night :) ), John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57295#57295 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048
Thank you Gwaldron, that line of code saved me 40MB. Better than nothing. Now the memory usage is around 110 MB. The format of the image is JPG. I tried to use PVR but I can't load the image. This is the complete function (updated with your suggestion) that I use to create a sphere with 2 textures. Then I use a shader to cross fade between the two textures that's why I need to have both of them in memory. Code: - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray { osg::ref_ptrosg::Geode sphere = new osg::Geode(); sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), ray))); sphere-setName(BubbleNode); // load image for texture osg::ref_ptrosg::Image todayImage = osgDB::readImageFile(todayTextName.UTF8String); osg::ref_ptrosg::Image pastImage = osgDB::readImageFile(pastTextName.UTF8String); if (!todayImage || !pastImage) { std::cout Couldn't load texture. std::endl; } else { osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(todayImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(pastImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get()); } return sphere; } and then I call this to add the sphere Code: osg::ref_ptrosg::Geode sphere = [self createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg andRay:1.0f]; _root-addChild(sphere.get()); _root-setDataVariance( osg::Object::DYNAMIC); gwaldron wrote: What's the data type of your image? Show the code where you allocate the image data. You can also call this, which will free the CPU memory once the texture gets to the GPU: texture-setUnRefImageDataAfterApply(true); Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 8:11 AM, John Moore () wrote: Hi, In my app I am using 2 textures of size 4096x2048. I have a serious problem of memory usage. Code: osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(image.release()); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture:: LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(image2.release()); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get()); using this code my app jumps from 20 MB of memory to 250 MB of memory usage Since I am developing on mobile platform this is a huge waste of memory. I partially solved the problem by changing the MIN_FILTER from LINEAR_MIPMAP_LINEAR to LINEAR Now the memory usage is 150MB It's still a lot! Do you know a way to optimize the memory usage of these 2 textures? Thank you, Have a nice day (or night :) ), John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57295#57295 (http://forum.openscenegraph.org/viewtopic.php?p=57295#57295) ___ osg-users mailing list () http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http
Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048
Memory usage is for the entire app. However memory usage of the same scene if I don’t load the texture is 20 MB. So I can safely assume the rest is consumed by the fact the textures are applied to the sphere. gwaldron wrote: 110MB -- CPU or GPU memory? For the entire app or just your textures? Quick math: 2 * 4096 * 2048 * 4 * 1.3 = 87MB. (4 = RGBA, 1.3 = mipmaps) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:18 AM, John Moore () wrote: Thank you Gwaldron, that line of code saved me 40MB. Better than nothing. Now the memory usage is around 110 MB. The format of the image is JPG. I tried to use PVR but I can't load the image. This is the complete function (updated with your suggestion) that I use to create a sphere with 2 textures. Then I use a shader to cross fade between the two textures that's why I need to have both of them in memory. Code: - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray { osg::ref_ptrosg::Geode sphere = new osg::Geode(); sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), ray))); sphere-setName(BubbleNode); // load image for texture osg::ref_ptrosg::Image todayImage = osgDB::readImageFile(todayTextName.UTF8String); osg::ref_ptrosg::Image pastImage = osgDB::readImageFile(pastTextName.UTF8String); if (!todayImage || !pastImage) { std::cout Couldn't load texture. std::endl; } else { osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(todayImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(pastImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get()); } return sphere; } and then I call this to add the sphere Code: osg::ref_ptrosg::Geode sphere = [self createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg andRay:1.0f]; _root-addChild(sphere.get()); _root-setDataVariance( osg::Object::DYNAMIC); gwaldron wrote: What's the data type of your image? Show the code where you allocate the image data. You can also call this, which will free the CPU memory once the texture gets to the GPU: texture-setUnRefImageDataAfterApply(true); Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 8:11 AM, John Moore () wrote: Hi, In my app I am using 2 textures of size 4096x2048. I have a serious problem of memory usage. Code: osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(image.release()); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture:: LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(image2.release()); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get()); using this code my app jumps from 20 MB of memory to 250 MB of memory
Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048
I am not very concerned about disk usage. I am more concerned about RAM. Will be there any advantages using this kind of compression? If yes how can I compress and then load the data in a osg::Image? I am asking because I tried to do the compression with PVR (using PVRTexToolGUI) but I was not able to load it in a osg::Image. Thank you. John gwaldron wrote: Your only further recourse would be to take Luc's advice and DXT-compress the data on disk (using NVTT e.g.); that will give you 4:1 savings. Ref: http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:51 AM, John Moore () wrote: Memory usage is for the entire app. However memory usage of the same scene if I don’t load the texture is 20 MB. So I can safely assume the rest is consumed by the fact the textures are applied to the sphere. gwaldron wrote: 110MB -- CPU or GPU memory? For the entire app or just your textures? Quick math: 2 * 4096 * 2048 * 4 * 1.3 = 87MB. (4 = RGBA, 1.3 = mipmaps) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:18 AM, John Moore () wrote: Thank you Gwaldron, that line of code saved me 40MB. Better than nothing. Now the memory usage is around 110 MB. The format of the image is JPG. I tried to use PVR but I can't load the image. This is the complete function (updated with your suggestion) that I use to create a sphere with 2 textures. Then I use a shader to cross fade between the two textures that's why I need to have both of them in memory. Code: - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray { osg::ref_ptrosg::Geode sphere = new osg::Geode(); sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), ray))); sphere-setName(BubbleNode); // load image for texture osg::ref_ptrosg::Image todayImage = osgDB::readImageFile(todayTextName.UTF8String); osg::ref_ptrosg::Image pastImage = osgDB::readImageFile(pastTextName.UTF8String); if (!todayImage || !pastImage) { std::cout Couldn't load texture. std::endl; } else { osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(todayImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(pastImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get()); } return sphere; } and then I call this to add the sphere Code: osg::ref_ptrosg::Geode sphere = [self createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg andRay:1.0f]; _root-addChild(sphere.get()); _root-setDataVariance( osg::Object::DYNAMIC); gwaldron wrote: What's the data type of your image? Show the code where you allocate the image data. You can also call this, which will free the CPU memory once the texture gets to the GPU: texture-setUnRefImageDataAfterApply(true); Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 8:11 AM, John Moore () wrote: Hi, In my app I am using 2 textures of size 4096x2048. I have a serious problem of memory usage. Code: osg::ref_ptrosg::Texture2D texture = new osg::Texture2D
Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048
Cool, how can use it? PVR is not Apple. It's by PowerVR GRaphics. It's optimized for the Power VR GPUs that are mounted on most of the mobile devices like iPhone or iPad. However I can't understand how to use it in OpenSceneGRaph. gwaldron wrote: It stays compressed in memory (CPU and GPU), so you get 4:1 compression in the app, not just on disk. No experience with PVR; is it Apple only? Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 10:25 AM, John Moore () wrote: I am not very concerned about disk usage. I am more concerned about RAM. Will be there any advantages using this kind of compression? If yes how can I compress and then load the data in a osg::Image? I am asking because I tried to do the compression with PVR (using PVRTexToolGUI) but I was not able to load it in a osg::Image. Thank you. John gwaldron wrote: Your only further recourse would be to take Luc's advice and DXT-compress the data on disk (using NVTT e.g.); that will give you 4:1 savings. Ref: http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison) (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison)) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:51 AM, John Moore () wrote: Memory usage is for the entire app. However memory usage of the same scene if I don’t load the texture is 20 MB. So I can safely assume the rest is consumed by the fact the textures are applied to the sphere. gwaldron wrote: 110MB -- CPU or GPU memory? For the entire app or just your textures? Quick math: 2 * 4096 * 2048 * 4 * 1.3 = 87MB. (4 = RGBA, 1.3 = mipmaps) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:18 AM, John Moore () wrote: Thank you Gwaldron, that line of code saved me 40MB. Better than nothing. Now the memory usage is around 110 MB. The format of the image is JPG. I tried to use PVR but I can't load the image. This is the complete function (updated with your suggestion) that I use to create a sphere with 2 textures. Then I use a shader to cross fade between the two textures that's why I need to have both of them in memory. Code: - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray { osg::ref_ptrosg::Geode sphere = new osg::Geode(); sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), ray))); sphere-setName(BubbleNode); // load image for texture osg::ref_ptrosg::Image todayImage = osgDB::readImageFile(todayTextName.UTF8String); osg::ref_ptrosg::Image pastImage = osgDB::readImageFile(pastTextName.UTF8String); if (!todayImage || !pastImage) { std::cout Couldn't load texture. std::endl; } else { osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(todayImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC); texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture2-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture2-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture2-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture2-setImage(pastImage.release()); texture
Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048
I think I found the osg plugin to decompress PVR but I don't know how to use it. Do you have any idea? Alistair Baxter wrote: PVRTC is exclusive to Imagination technology’s PowerVR chipsets. All iDevices use those chipsets, so it’s in common use on iOS, but only certain Android devices with the right type of GPU support it. I don’t believe there are any desktop or laptop graphics cards that support it directly, but there’s a library available to decompress them. Alistair Baxter Software Engineer Have you downloaded your FREE copy of FieldMove Clino? Find out more about our app for iPhone and Android smartphones: http://news.mve.com/fieldmoveclino (http://news.mve.com/fieldmoveclino) Midland Valley Exploration Ltd. 144 West George Street Glasgow G2 2HG United Kingdom Tel: +44 (0) 141 332 2681 Fax: +44 (0) 141 332 6792 The structural geology experts From: [mailto:] On Behalf Of Glenn Waldron Sent: 19 November 2013 15:32 To: OpenSceneGraph Users Subject: Re: Optimizing memory usage by Texture of size 4096x2048 It stays compressed in memory (CPU and GPU), so you get 4:1 compression in the app, not just on disk. No experience with PVR; is it Apple only? Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 10:25 AM, John Moore () wrote: I am not very concerned about disk usage. I am more concerned about RAM. Will be there any advantages using this kind of compression? If yes how can I compress and then load the data in a osg::Image? I am asking because I tried to do the compression with PVR (using PVRTexToolGUI) but I was not able to load it in a osg::Image. Thank you. John gwaldron wrote: Your only further recourse would be to take Luc's advice and DXT-compress the data on disk (using NVTT e.g.); that will give you 4:1 savings. Ref: http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison) (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison)) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:51 AM, John Moore () wrote: Memory usage is for the entire app. However memory usage of the same scene if I don’t load the texture is 20 MB. So I can safely assume the rest is consumed by the fact the textures are applied to the sphere. gwaldron wrote: 110MB -- CPU or GPU memory? For the entire app or just your textures? Quick math: 2 * 4096 * 2048 * 4 * 1.3 = 87MB. (4 = RGBA, 1.3 = mipmaps) Glenn Waldron / @glennwaldron On Tue, Nov 19, 2013 at 9:18 AM, John Moore () wrote: Thank you Gwaldron, that line of code saved me 40MB. Better than nothing. Now the memory usage is around 110 MB. The format of the image is JPG. I tried to use PVR but I can't load the image. This is the complete function (updated with your suggestion) that I use to create a sphere with 2 textures. Then I use a shader to cross fade between the two textures that's why I need to have both of them in memory. Code: - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray { osg::ref_ptrosg::Geode sphere = new osg::Geode(); sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), ray))); sphere-setName(BubbleNode); // load image for texture osg::ref_ptrosg::Image todayImage = osgDB::readImageFile(todayTextName.UTF8String); osg::ref_ptrosg::Image pastImage = osgDB::readImageFile(pastTextName.UTF8String); if (!todayImage || !pastImage) { std::cout Couldn't load texture. std::endl; } else { osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setDataVariance(osg::Object::STATIC); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture-setImage(todayImage.release()); texture-setUnRefImageDataAfterApply(true); sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get()); osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D; texture2-setDataVariance(osg::Object::STATIC
Re: [osg-users] Drawing lines using OpenGL ES 2.0
Actually I solved it... one of the problems was that the number I was using for the attribute was too big (or reserved). I am forced to use OpenGL ES 2.0 because I develop on iOS platform! Thank you anyway for your advice. Cheers, John This is the working code Code: #define BARYCENTRIC_ATTR_UNIT 11 void OSGGraphicsUtils::setBarycentricCoordinates(osg::Node * object, osg::Program *shaderProgram) { GeodeFinder myGeodeFinder; std::vector osg::Geode * listOfGeodes; object-accept(myGeodeFinder); listOfGeodes = myGeodeFinder.getNodeList(); std::cout there are listOfGeodes.size() geodes std::endl; for (int j = 0; j listOfGeodes.size() ; j++) { //play with the Geode here std::cout Geode number j std::endl; //get the current geode osg::Geode* currentGeode = listOfGeodes.at(j); if (currentGeode != NULL) { std::cout number of drawables in geode is currentGeode-getNumDrawables() std::endl; for (int i = 0; i currentGeode-getNumDrawables(); i++) { std::cout current geode class is currentGeode-getDrawable(i)-className() std::endl; std::cout inside cycle i std::endl; osg::Geometry *cubeGeometry = currentGeode-getDrawable(i)-asGeometry(); if (!cubeGeometry) continue; int numAttribs = cubeGeometry-getVertexArray()-getNumElements(); std::cout number of vertices is numAttribsstd::endl; osg::ref_ptr osg::Vec3Array cubeVertexVector; if (! strcmp (cubeGeometry-getVertexArray()-className(), Vec3Array)) { cubeVertexVector = (osg::Vec3Array *) cubeGeometry-getVertexArray(); } else { //handle the error however you want -- here all I do is print a warning and bail out. std::cerr Unexpected VertexArray className.\n std::endl; return; } osg::ref_ptrosg::Vec3Array array = new osg::Vec3Array; //add this to declaration section: std::map int, int vertexMap; osg::ref_ptr osg::PrimitiveSet nextPrimitiveSet; // ... // int k = 0; for (i = 0; i cubeGeometry-getNumPrimitiveSets(); i++) { nextPrimitiveSet = cubeGeometry-getPrimitiveSet(i); //cout PrimitiveSet # i has Mode: nextPrimitiveSet-getMode() endl; //cout \tVertex Indices: endl; for (j = 0; j nextPrimitiveSet-getNumIndices(); j++) { if(vertexMap.find(nextPrimitiveSet-index(j)) == vertexMap.end()) { if (k==3) k = 0; //cout \t nextPrimitiveSet-index(j) endl; vertexMap[nextPrimitiveSet-index(j)] = k; k++; } else { k = vertexMap[nextPrimitiveSet-index(j)] + 1; } } } for (int i = 0; i numAttribs; i++) { int j = vertexMap[i]; if (j==0) { array-push_back(osg::Vec3f(1.0f,0.0f,0.0f)); } else if (j==1) { array-push_back(osg::Vec3f(0.0f,1.0f,0.0f)); } else if (j==2) { array-push_back(osg::Vec3f(0.0f,0.0f,1.0f)); } //std::cout Vertex # i : ( cubeVertexVector-getName()): ( nextVertex[0] , nextVertex[1] , nextVertex[2] )\n; } std::cout Array size is array-getNumElements() std::endl; if( !cubeGeometry-getVertexAttribArray( BARYCENTRIC_ATTR_UNIT ) ) { //cubeGeometry-setVertexAttribData(31, osg::Geometry::ArrayData(array,osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) ); std::cout setting barycentric attr unit array of size array-getNumElements() std::endl; cubeGeometry-setVertexAttribArray(BARYCENTRIC_ATTR_UNIT, array.get());
Re: [osg-users] Drawing lines using OpenGL ES 2.0
I want to add that this is the fragment shader I used for drawing the wireframe model Code: precision highp float; varying vec3 vBC; #extension GL_OES_standard_derivatives : enable float edgeFactor(){ vec3 d = fwidth(vBC); vec3 a3 = smoothstep(vec3(0.0), d*1.0, vBC); return min(min(a3.x, a3.y), a3.z); } void main (void) { gl_FragColor = vec4(0.0, 0.0, 0.0, (1.0-edgeFactor())*1.0); } Special thanks to this blog for the fragment shader and the idea of using barycentric coordinates! http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/ -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57117#57117 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Drawing lines using OpenGL ES 2.0
I found a solution which involves computing the barycentric coordinates. However it seems that is not working properly. To compute the barycentric coordinates I need to associate to the vertices of the triangles a coordinate among (1,0,0) (0,1,0) (0,0,1) for doing that I use the following function, which is based on the assumption I load the 3d model using the option noTriStripPolygons so that each polygon is a triangle (and not a strip of triangles). Code: void OSGGraphicsUtils::setBarycentricCoordinates(osg::Node * object, osg::Program *shaderProgram) { GeodeFinder myGeodeFinder; std::vector osg::Geode * listOfGeodes; object-accept(myGeodeFinder); listOfGeodes = myGeodeFinder.getNodeList(); std::cout there are listOfGeodes.size() geodes std::endl; for (int j = 0; j listOfGeodes.size() ; j++) { //get the current geode osg::Geode* currentGeode = listOfGeodes.at(j); if (currentGeode != NULL) { for (int i = 0; i currentGeode-getNumDrawables(); i++) { osg::Geometry *cubeGeometry = currentGeode-getDrawable(i)-asGeometry(); if (!cubeGeometry) continue; int numAttribs = cubeGeometry-getVertexArray()-getNumElements(); std::cout number of vertices is numAttribsstd::endl; osg::ref_ptr osg::Vec3Array cubeVertexVector; if (! strcmp (cubeGeometry-getVertexArray()-className(), Vec3Array)) { cubeVertexVector = (osg::Vec3Array *) cubeGeometry-getVertexArray(); } else { //handle the error however you want -- here all I do is print a warning and bail out. std::cerr Unexpected VertexArray className.\n std::endl; return; } osg::Vec3Array *array = new osg::Vec3Array(cubeVertexVector-size()); std::map osg::Vec3, int vertexMap; osg::Vec3 nextVertex; int j = 0; for (int i = 0; i cubeVertexVector-size(); i++) { nextVertex = cubeVertexVector-at(i); if (j == 3) j = 0; if(vertexMap.find(nextVertex) == vertexMap.end()) {//check if it is the first, the second o the third vertex of the triangle and associate appropriate attribute if (j==0) { array-at(i) = (osg::Vec3(1.0,0.0,0.0)); vertexMap[nextVertex] = i; } else if (j==1) { array-at(i) = (osg::Vec3(0.0,1.0,0.0)); vertexMap[nextVertex] = i; } else if (j==2) { array-at(i) = (osg::Vec3(0.0,0.0,1.0)); vertexMap[nextVertex] = i; } } else { //std::cout Vertex already present in the map at index vertexMap[nextVertex] std::endl; array-at(i) = osg::Vec3(array-at(vertexMap[nextVertex])); } j++; } if( !cubeGeometry-getVertexAttribArray( 31 ) ) { //cubeGeometry-setVertexAttribData(31, osg::Geometry::ArrayData(array,osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) ); std::cout setting barycentric attr unit array of size array-getNumElements() std::endl; cubeGeometry-setVertexAttribArray(31, array); cubeGeometry-setVertexAttribBinding(BARYCENTRIC_ATTR_UNIT, osg::Geometry::BIND_PER_VERTEX); } } } } } The attribute is binded to the program with the line of code Code: void OSGGraphicsUtils::loadShaders(osg::ref_ptrosg::StateSet objectStateSet, const char *vsSource, const char *fsSource, osg::ref_ptrosg::Node object, const char *shaderName) { // set shader for mammoth osg::ref_ptrosg::Program shaderProgram = new osg::Program; shaderProgram-setName(shaderName); shaderProgram-addShader( new osg::Shader( osg::Shader::VERTEX, vsSource ) ); shaderProgram-addShader( new osg::Shader( osg::Shader::FRAGMENT, fsSource ) ); objectStateSet = object-getOrCreateStateSet(); objectStateSet-setAttributeAndModes(shaderProgram, osg::StateAttribute::ON ); if (strcmp(shaderName,ShaderWireframe)==0) { std::cout adding
[osg-users] Drawing lines using OpenGL ES 2.0
Hi, I am using OpenSceneGraph on iOS, using OpenGL ES 2.0. I am having hard time to figure out how to draw polygon lines using shaders. I'd like to draw a simple box with lines. However I can't find a way because osg::PolygonMode::LINE does not work. In fact boundingBoxNode-getOrCreateStateSet()-setAttributeAndModes(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE) ); with a simple phong shader attached gives me a box. is there any way to find the edges inside the fragment shader? maybe some mathematical computation that I can do to figure out if the fragment belongs to an edge or not. Thank you John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57054#57054 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android osgAndroidExampleGLES2 compiler errors
Thank you Raphael, it's working! :) I didn't think about pressing the menu button. LOL Thank you again. Have a nice day :) John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55204#55204 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android osgAndroidExampleGLES2 compiler errors
Dear Jordi Torres, thank you for your suggestion. I downloaded the SVN version of OpenSceneGraph and built it for Android. Now I am able to run the Example without crash. However I get some errors and I can't see any rendered 3d model. This is the log of the app. Code: 07-10 23:02:52.770: W/EGLview(14138): creating OpenGL ES 2.0 context 07-10 23:02:52.790: E/OSGANDROID(14138): Initializing geometry 07-10 23:02:52.790: E/Osg Viewer(14138): Testing 07-10 23:02:52.800: W/Osg Viewer(14138): Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile 07-10 23:02:52.830: E/OSGANDROID(14138): Initializing geometry 07-10 23:02:52.830: E/Osg Viewer(14138): Testing 07-10 23:02:52.840: W/Osg Viewer(14138): Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile 07-10 23:08:08.958: W/SurfaceView(14138): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false 07-10 23:08:09.278: W/IInputConnectionWrapper(14138): showStatusIcon on inactive InputConnection 07-10 23:08:53.751: D/libEGL(15910): loaded /system/lib/egl/libEGL_mali.so 07-10 23:08:53.761: D/libEGL(15910): loaded /system/lib/egl/libGLESv1_CM_mali.so 07-10 23:08:53.761: D/libEGL(15910): loaded /system/lib/egl/libGLESv2_mali.so 07-10 23:08:53.771: W/EGLview(15910): creating OpenGL ES 2.0 context 07-10 23:08:53.781: D/dalvikvm(15910): Trying to load lib /data/data/osg.AndroidExample/lib/libosgNativeLib.so 0x41a44740 07-10 23:08:53.901: D/dalvikvm(15910): Added shared lib /data/data/osg.AndroidExample/lib/libosgNativeLib.so 0x41a44740 07-10 23:08:53.901: D/dalvikvm(15910): No JNI_OnLoad found in /data/data/osg.AndroidExample/lib/libosgNativeLib.so 0x41a44740, skipping init 07-10 23:08:53.911: E/OSGANDROID(15910): Initializing geometry 07-10 23:08:53.911: E/Osg Viewer(15910): Testing 07-10 23:08:53.921: W/Osg Viewer(15910): Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile In attachment you can see a screenshot of the app running on my Galaxy S III mini. As you can see from the screenshot there's nothing rendered on the screen. The buttons seem to work correctly because when I press them a label on the screen appears indicating the status of the button. What is the problem in your opinion? Thank you again, John Jorge Izquierdo Ciges wrote: Osg in Android is not emulator-friendly... and the EGL libraries seem from emulator instead of a proper device. 2013/7/8 John Moore () Hi Adun (), I have done as you said. There was no libgnustl_static.a in the $(OSG_ANDROID_DIR)/obj/local/armeabi-v7a folder, so I copied it from ANDROID_NDK folder. Specifically I copied it from $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a folder The build-ndk now seems ok, except some warnings that were treated as errors because of the -Werror flag in the LOCAL_CFLAGS. These are the warnings: Code: jni/osgNativeLib.cpp: In function 'void Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv*, jobject, jstring)': jni/osgNativeLib.cpp:78:70: error: converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] jni/osgNativeLib.cpp: In function 'void Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv*, jobject, jstring, jstring)': jni/osgNativeLib.cpp:87:70: error: converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] jni/osgNativeLib.cpp:88:64: error: converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] cc1plus: all warnings being treated as errors I removed the -Werror flag and I was able to successfully complete ndk-build. However when I run the app on ADT, it crashes with this output: Code: 07-08 17:32:14.799: D/(633): HostConnection::get() New Host Connection established 0x2a117488, tid 633 07-08 17:32:14.809: D/libEGL(633): loaded /system/lib/egl/libEGL_emulation.so 07-08 17:32:14.809: D/(633): HostConnection::get() New Host Connection established 0x2a117530, tid 647 07-08 17:32:14.829: D/libEGL(633): loaded /system/lib/egl/libGLESv1_CM_emulation.so 07-08 17:32:14.861: D/libEGL(633): loaded /system/lib/egl/libGLESv2_emulation.so 07-08 17:32:14.899: W/EGLview(633): creating OpenGL ES 2.0 context 07-08 17:32:14.899: W/dalvikvm(633): threadid=11: thread exiting with uncaught exception (group=0x40a13300) 07-08 17:32:14.909: E/AndroidRuntime(633): FATAL EXCEPTION: GLThread 75 07-08 17:32:14.909: E/AndroidRuntime(633): java.lang.IllegalArgumentException 07-08 17:32:14.909: E/AndroidRuntime(633): at com.google.android.gles_jni.EGLImpl
Re: [osg-users] Android osgAndroidExampleGLES2 compiler errors
Jordi Torres wrote: Hi, This bug is fixed in recent versions. So try the svn trunk. Cheers El 09/07/2013 18:16, John Moore () escribió: Jorge Izquierdo Ciges wrote: The message its pretty clear: couldn't load osgNativeLib: findLibrary returned null Probably the library has not been copied. This usually happens when compiling armeabi-v7 and the device doesn't support it.It is also possible that the apk was generated without the .so open the apk first to check it. -- Post generated by Mail2Forum Ok, so the problem could be the warnings that I ignored by removing -Werror flag. In fact these are the pieces of code in the osgNativeLib.cpp that gives me warnings: Code: 78 const char *nativeAddress = env-GetStringUTFChars(address, false); 87 const char *nativeAddress = env-GetStringUTFChars(address, false); 88 const char *nativeName = env-GetStringUTFChars(name, false); the warning (which is considered as error if I don't remove -Werror flag) is about#058; converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] osgNativeLib.cpp /osgViewer/jni line 78 C/C++ Problem I didn't write this code. It was in the osgAndroidExampleGLES2. What do you think about it? Thanks again for your time. John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55170#55170 (http://forum.openscenegraph.org/viewtopic.php?p=55170#55170) ___ osg-users mailing list () http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org) Dear Jordi Torres, thank you for your suggestion. I downloaded the SVN version of OpenSceneGraph and built it for Android. Now I am able to run the Example without crash. However I get some errors and I can't see any rendered 3d model. This is the log of the app. Code: 07-10 23:02:52.770: W/EGLview(14138): creating OpenGL ES 2.0 context 07-10 23:02:52.790: E/OSGANDROID(14138): Initializing geometry 07-10 23:02:52.790: E/Osg Viewer(14138): Testing 07-10 23:02:52.800: W/Osg Viewer(14138): Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile 07-10 23:02:52.830: E/OSGANDROID(14138): Initializing geometry 07-10 23:02:52.830: E/Osg Viewer(14138): Testing 07-10 23:02:52.840: W/Osg Viewer(14138): Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile 07-10 23:08:08.958: W/SurfaceView(14138): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false 07-10 23:08:09.278: W/IInputConnectionWrapper(14138): showStatusIcon on inactive InputConnection 07-10 23:08:53.751: D/libEGL(15910): loaded /system/lib/egl/libEGL_mali.so 07-10 23:08:53.761: D/libEGL(15910): loaded /system/lib/egl/libGLESv1_CM_mali.so 07-10 23:08:53.761: D/libEGL(15910): loaded /system/lib/egl/libGLESv2_mali.so 07-10 23:08:53.771: W/EGLview(15910): creating OpenGL ES 2.0 context 07-10 23:08:53.781: D/dalvikvm(15910): Trying to load lib /data/data/osg.AndroidExample/lib/libosgNativeLib.so 0x41a44740 07-10 23:08:53.901: D/dalvikvm(15910): Added shared lib /data/data/osg.AndroidExample/lib/libosgNativeLib.so 0x41a44740 07-10 23:08:53.901: D/dalvikvm(15910): No JNI_OnLoad found in /data/data/osg.AndroidExample/lib/libosgNativeLib.so 0x41a44740, skipping init 07-10 23:08:53.911: E/OSGANDROID(15910): Initializing geometry 07-10 23:08:53.911: E/Osg Viewer(15910): Testing 07-10 23:08:53.921: W/Osg Viewer(15910): Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile In attachment you can see a screenshot of the app running on my Galaxy S III mini. As you can see from the screenshot there's nothing rendered on the screen. The buttons seem to work correctly because when I press them a label on the screen appears indicating the status of the button. Thank you, John -- Post generated by Mail2Forum -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55192#55192 attachment: schermata osgAndroidExample.png___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android osgAndroidExampleGLES2 compiler errors
Osg in Android is not emulator-friendly... and the EGL libraries seem from emulator instead of a proper device. Ok, I tried with a Samsung Galaxy S3 Mini (which has the same gpu of Samsung Galaxy S3) but the app is still crashing. :( This is the log: Code: 07-08 18:12:30.278: D/libEGL(11086): loaded /system/lib/egl/libEGL_mali.so 07-08 18:12:30.288: D/libEGL(11086): loaded /system/lib/egl/libGLESv1_CM_mali.so 07-08 18:12:30.288: D/libEGL(11086): loaded /system/lib/egl/libGLESv2_mali.so 07-08 18:12:30.298: W/EGLview(11086): creating OpenGL ES 2.0 context 07-08 18:12:30.308: W/dalvikvm(11086): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Losg/AndroidExample/osgNativeLib; 07-08 18:12:30.308: W/dalvikvm(11086): threadid=11: thread exiting with uncaught exception (group=0x41c722a0) 07-08 18:12:30.308: E/AndroidRuntime(11086): FATAL EXCEPTION: GLThread 908 07-08 18:12:30.308: E/AndroidRuntime(11086): java.lang.ExceptionInInitializerError 07-08 18:12:30.308: E/AndroidRuntime(11086):at osg.AndroidExample.EGLview$Renderer.onSurfaceChanged(EGLview.java:319) 07-08 18:12:30.308: E/AndroidRuntime(11086):at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511) 07-08 18:12:30.308: E/AndroidRuntime(11086):at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 07-08 18:12:30.308: E/AndroidRuntime(11086): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load osgNativeLib: findLibrary returned null 07-08 18:12:30.308: E/AndroidRuntime(11086):at java.lang.Runtime.loadLibrary(Runtime.java:365) 07-08 18:12:30.308: E/AndroidRuntime(11086):at java.lang.System.loadLibrary(System.java:535) 07-08 18:12:30.308: E/AndroidRuntime(11086):at osg.AndroidExample.osgNativeLib.clinit(osgNativeLib.java:6) 07-08 18:12:30.308: E/AndroidRuntime(11086):... 3 more 07-08 18:12:37.495: I/Choreographer(11086): Skipped 426 frames! The application may be doing too much work on its main thread. 07-08 18:12:37.515: W/SurfaceView(11086): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false [/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55166#55166 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android osgAndroidExampleGLES2 compiler errors
Jorge Izquierdo Ciges wrote: The message its pretty clear: couldn't load osgNativeLib: findLibrary returned null Probably the library has not been copied. This usually happens when compiling armeabi-v7 and the device doesn't support it.It is also possible that the apk was generated without the .so open the apk first to check it. -- Post generated by Mail2Forum Ok, so the problem could be the warnings that I ignored by removing -Werror flag. In fact these are the pieces of code in the osgNativeLib.cpp that gives me warnings: Code: 78const char *nativeAddress = env-GetStringUTFChars(address, false); 87const char *nativeAddress = env-GetStringUTFChars(address, false); 88const char *nativeName = env-GetStringUTFChars(name, false); the warning (which is considered as error if I don't remove -Werror flag) is about#058; converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] osgNativeLib.cpp/osgViewer/jni line 78 C/C++ Problem I didn't write this code. It was in the osgAndroidExampleGLES2. What do you think about it? Thanks again for your time. John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55170#55170 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android osgAndroidExampleGLES2 compiler errors
Hi Adun (), I have done as you said. There was no libgnustl_static.a in the $(OSG_ANDROID_DIR)/obj/local/armeabi-v7a folder, so I copied it from ANDROID_NDK folder. Specifically I copied it from $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a folder The build-ndk now seems ok, except some warnings that were treated as errors because of the -Werror flag in the LOCAL_CFLAGS. These are the warnings: Code: jni/osgNativeLib.cpp: In function 'void Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv*, jobject, jstring)': jni/osgNativeLib.cpp:78:70: error: converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] jni/osgNativeLib.cpp: In function 'void Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv*, jobject, jstring, jstring)': jni/osgNativeLib.cpp:87:70: error: converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] jni/osgNativeLib.cpp:88:64: error: converting 'false' to pointer type for argument 2 of 'char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)' [-Werror=conversion-null] cc1plus: all warnings being treated as errors I removed the -Werror flag and I was able to successfully complete ndk-build. However when I run the app on ADT, it crashes with this output: Code: 07-08 17:32:14.799: D/(633): HostConnection::get() New Host Connection established 0x2a117488, tid 633 07-08 17:32:14.809: D/libEGL(633): loaded /system/lib/egl/libEGL_emulation.so 07-08 17:32:14.809: D/(633): HostConnection::get() New Host Connection established 0x2a117530, tid 647 07-08 17:32:14.829: D/libEGL(633): loaded /system/lib/egl/libGLESv1_CM_emulation.so 07-08 17:32:14.861: D/libEGL(633): loaded /system/lib/egl/libGLESv2_emulation.so 07-08 17:32:14.899: W/EGLview(633): creating OpenGL ES 2.0 context 07-08 17:32:14.899: W/dalvikvm(633): threadid=11: thread exiting with uncaught exception (group=0x40a13300) 07-08 17:32:14.909: E/AndroidRuntime(633): FATAL EXCEPTION: GLThread 75 07-08 17:32:14.909: E/AndroidRuntime(633): java.lang.IllegalArgumentException 07-08 17:32:14.909: E/AndroidRuntime(633): at com.google.android.gles_jni.EGLImpl._eglCreateContext(Native Method) 07-08 17:32:14.909: E/AndroidRuntime(633): at com.google.android.gles_jni.EGLImpl.eglCreateContext(EGLImpl.java:54) 07-08 17:32:14.909: E/AndroidRuntime(633): at osg.AndroidExample.EGLview$ContextFactory.createContext(EGLview.java:103) 07-08 17:32:14.909: E/AndroidRuntime(633): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1030) 07-08 17:32:14.909: E/AndroidRuntime(633): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401) 07-08 17:32:14.909: E/AndroidRuntime(633): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) Do you think the crash is related to the warning? Thank you for your time, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55163#55163 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Android osgAndroidExampleGLES2 compiler errors
Hello, I am trying to compile the OSG sample application for Android, the one that works with OpenGL ES 2.0. I followed this guide doing some minor modification for OpenGL ES 2.0: http://forum.openscenegraph.org/viewtopic.php?t=10076 I built openscenegraph with no errors with 3rd party components. Now I am stuck at the ndk-build part. When I try to compile the osgAndroidExampleGLES2 example I get these errors: Code: Build of configuration Default for project osgViewer /Users/John/Developer/Android/android-ndk-r8e/ndk-build all SharedLibrary : libosgNativeLib.so /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lgnustl_static /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(ReaderWriterFLT.o): in function std::basic_stringbufchar, std::char_traitschar, std::allocatorchar ::~basic_stringbuf():/Users/John/Developer/Android/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/sstream:60: error: undefined reference to 'vtable for std::basic_stringbufchar, std::char_traitschar, std::allocatorchar ' /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(ReaderWriterFLT.o): in function FLTReaderWriter::readNode(std::basic_istreamchar, std::char_traitschar , osgDB::Options const*) const:/Users/John/Developer/Android/OpenSceneGraph-3.0.1/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:451: error: undefined reference to 'std::basic_stringbufchar, std::char_traitschar, std::allocatorchar ::basic_stringbuf(std::basic_stringchar, std::char_traitschar, std::allocatorchar const, std::_Ios_Openmode)' /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(ReaderWriterFLT.o): in function FLTReaderWriter::readNode(std::basic_istreamchar, std::char_traitschar , osgDB::Options const*) const:/Users/John/Developer/Android/OpenSceneGraph-3.0.1/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:503: error: undefined reference to 'std::basic_stringbufchar, std::char_traitschar, std::allocatorchar ::basic_stringbuf(std::basic_stringchar, std::char_traitschar, std::allocatorchar const, std::_Ios_Openmode)' /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(PaletteRecords.o): in function .LTHUNK76:/Users/John/Developer/Android/OpenSceneGraph-3.0.1/src/osgPlugins/OpenFlight/Pools.h:45: error: undefined reference to 'std::basic_istringstreamchar, std::char_traitschar, std::allocatorchar ::~basic_istringstream()' /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(PaletteRecords.o): in function flt::VertexPool::VertexPool(std::basic_stringchar, std::char_traitschar, std::allocatorchar const):/Users/John/Developer/Android/OpenSceneGraph-3.0.1/src/osgPlugins/OpenFlight/Pools.h:41: error: undefined reference to 'std::basic_istringstreamchar, std::char_traitschar, std::allocatorchar ::basic_istringstream(std::basic_stringchar, std::char_traitschar, std::allocatorchar const, std::_Ios_Openmode)' /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(PaletteRecords.o): in function typeinfo for flt::VertexPool:PaletteRecords.cpp(.data.rel.ro._ZTIN3flt10VertexPoolE+0x18): error: undefined reference to 'typeinfo for std::basic_istringstreamchar, std::char_traitschar, std::allocatorchar ' /Users/John/Developer/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/John/Developer/Android/workspace/osgViewer/obj/local/armeabi/libosgdb_openflight.a(PaletteRecords.o): in
Re: [osg-users] how to get number of vertices and faces
Dear Robert, Actually I can't use the S key because my application is running on iOS. Is there any way to compute these value using a node visitor? actually for knowing the vertices I tried using this line of code inside my nodevisitor totalNumOfVertices += geo-getVertexArray()-getNumElements(); however the result is a higher than expected, so I am not sure it's the true value. Am I doing it right? Thank you. Bye, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50474#50474 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] how to get number of vertices and faces
Hi guys, I have a scene graph with only a node containing an OBJ file. Do you know hot can I get the number of vertices and faces of the OBJ model? Actually I am using osg::Stats osg::Stats* stats = _viewer-getCamera()-getStats(); I get the attribute map... const osg::Stats::AttributeMap attributes = stats-getAttributeMap(i); I iterate and then I am able to get the -Visible number of GL_TRIANGLE_STRIP -Visible vertex count that seems to be the values I need... However the real number of faces of the OBJ is different from GL_TRIANGLE_STRIP, and the real number of vertices of the OBJ is different from Vertex count. I know because I checked using 3DS max. How can I get the correct values? Thank you! Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50457#50457 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] bumpmapping and tangentspacegenerator, generating tangents
Ok, Let's say that I want to read an OBJ file and assign the BUMP texture to 0 and the DIFFUSE texture to 1 Am I doing right with these lines of code for the options? osg::ref_ptrosgDB::ReaderWriter::Options options = new osgDB::ReaderWriter::Options; options-setOptionString(DIFFUSE=1 BUMP=0); Thank you! Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50409#50409 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] bumpmapping and tangentspacegenerator, generating tangents
Dear OSG users, I am trying to develop bump mapping using opengl es 2.0 and openscenegraph. I can't use osgFX because of opengl es 2.0. I have to apply a bump map to an obj that has the map embedded in the MTL. The mtl is like this: newmtl Nuovo Kd 0.80 0.80 0.80 illum 2 Ns 50.781250 map_bump PINKGRA2_NRM.JPG map_Kd PINKGRA2.JPG I read the obj using the options string: osg::ref_ptrosgDB::ReaderWriter::Options options = new osgDB::ReaderWriter::Options; options-setOptionString(DIFFUSE=0 BUMP=1); To generate the tagents I use tangentspacegenerator. osg::ref_ptr osgUtil::TangentSpaceGenerator tsg = new osgUtil::TangentSpaceGenerator; tsg-generate( geo , 1); However this is not working!!! The application crashes with a bad access! Instead, if I use tsg-generate( geo, 0) then it is working! However in this case I think it is using the diffuse map to generate the tangents, which I think is bad! The tangent space generator is created and applied inside a nodevisitor. I am almost sure everything is bound correctly. #define NORMAL_ATTR_UNIT 2 #define TANGENT_ATTR_UNIT 9 #define NORMAL_TEX_UNIT 1 #define TEX_UNIT 0 _programBumpMapping-addBindAttribLocation( a_tangent, TANGENT_ATTR_UNIT ); _programBumpMapping-addBindAttribLocation( a_normal, NORMAL_ATTR_UNIT ); ssRoot-setAttributeAndModes( _programBumpMapping, osg::StateAttribute::ON ); ssRoot-addUniform(new osg::Uniform(osg::Uniform::SAMPLER_2D, u_TextureMap, TEX_UNIT)); ssRoot-addUniform(new osg::Uniform(osg::Uniform::SAMPLER_2D, u_NormalMap, NORMAL_TEX_UNIT)); Can you please help me to understand why with 0 works and with 1 I have a bad access? Kind Regards, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50387#50387 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Update camera and context after resize view in iOS
Hi, I am developing an application in iOS using openscenegraph. I'd like to resize a viewer. Simply resizing the container view (which contains my osgViewController) resizes the viewer, but the model appears centered incorrectly and it is blurred and scaled up. Furthermore camera manipulator is not working perfectly. In practice, I start with a view of size 150x150. Then in a toolbar there's a button to make this view go fullscreen, and hide the other ones. When I press the button the view is correctly resized to fullscreen. The graphics context appears to be update automatically because I checked the traits for width and height and they are updated correctly. However when it goes full-screen the 3D model appears blurry and taller. I am using a Camera Manipulator, specifically a osgGA::MultiTouchTrackballManipulator() My update function execute only the following command: _viewer-getCamera()-setViewport(0, 0, frame.size.width, frame.size.height); should I do something else? Thank you very much! Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50350#50350 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Bump mapping with embedded maps in OBJs and OpenGL ES 2.0 programmable pipeline
Hi, I am trying to write a shader to do bump mapping using OSG and OpenGL ES 2.0 in a mobile platform (iOS). My 3d models are saved as OBJs. The bump map is embedded in the .MTL and declared in lines of the type: Code: newmtl brick2 Kd 0.80 0.80 0.80 illum 2 Ns 50.781250 map_Kd BRICKTAN.jpg bump BRICKBMP.jpg the fragment shader is: Code: precision mediump float; uniform sampler2D BumpTex; //The bump-map uniform sampler2D DecalTex; //The texture varying vec4 passcolor; //Receiving the vertex color from the vertex shader varying vec3 LightDir; //Receiving the transformed light direction varying vec2 tex_coord0; varying vec2 bump_coord0; void main() { //Get the color of the bump-map vec3 BumpNorm = vec3(texture2D(BumpTex, bump_coord0)); //Get the color of the texture vec3 DecalCol = vec3(texture2D(DecalTex, tex_coord0)); //Expand the bump-map into a normalized signed vector BumpNorm = (BumpNorm -0.5) * 2.0; //Find the dot product between the light direction and the normal float NdotL = max(dot(BumpNorm, LightDir), 0.0); //Calculate the final color gl_FragColor vec3 diffuse = NdotL * passcolor.xyz * DecalCol; //Set the color of the fragment gl_FragColor = vec4(diffuse, passcolor.w); } the vertex shader is Code: precision mediump float; varying vec2 tex_coord0; varying vec2 bump_coord0; varying vec4 passcolor; //The vertex color passed varying vec3 LightDir; //The transformed light direction, to pass to the fragment shader attribute vec3 tangent; //The inverse tangent to the geometry attribute vec3 binormal; //The inverse binormal to the geometry uniform vec4 u_LightPos; //The position of the light void main() { tex_coord0 = gl_MultiTexCoord0.xy; bump_coord0 = gl_MultiTexCoord1.xy; // the vertex position vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); // light dir vec3 lightDirection = vec3(u_LightPos.xyz - vVertex); //Put the color in a varying variable passcolor = gl_Color; //Construct a 3x3 matrix from the geometry’s inverse tangent, binormal, and normal mat3 rotmat = mat3(tangent,binormal,gl_Normal); //Rotate the light into tangent space LightDir = rotmat * normalize(lightDirection); //Normalize the light normalize(LightDir); //Use the first set of texture coordinates in the fragment shader //Put the vertex in the position passed gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } I thought I should link three uniforms. One for the bump texture and one for the normal texture. I assigned the value 0 to DecalTex and 1 to BumpTex. Code: osg::Uniform* textureUniform = new osg::Uniform(osg::Uniform::SAMPLER_2D, DecalTex); textureUniform-set(0); _oggettoObj-getOrCreateStateSet()-addUniform(textureUniform); osg::Uniform* bumpUniform = new osg::Uniform(osg::Uniform::SAMPLER_2D, BumpTex); bumpUniform-set(1); _oggettoObj-getOrCreateStateSet()-addUniform(bumpUniform); _root-addChild(_oggettoObj.get()); Then there is light position which is placed at (0,0,0) and can be moved with some controls in my application. The output of the application seems normal. The shader does not fail to compile and the images are loaded in memory. The problem is that this is not working. I am sure that I am accessing the wrong texture for the bump mapping. The problem is I don't know how to select the correct one from the shader. Can you help me to understand, please? Thank you! Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49187#49187 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Bump mapping with embedded maps in OBJs and OpenGL ES 2.0 programmable pipeline
I just realized that I didn't linked the attributes tangent and binormals. How can I compute them. I have stored in my OBJ only the information about normals. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49189#49189 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Bump mapping with embedded maps in OBJs and OpenGL ES 2.0 programmable pipeline
Hi Sergey, I am looking to TangentSpaceGenerator and I need to pass a Geometry to the generate method. However I have a osg::Node data structure because I load data using obj reader. Code: _oggettoObj = osgDB::readNodeFile(provaBump/objconbump.obj); then I create a tangent space with these lines: Code: osg::ref_ptrosgUtil::TangentSpaceGenerator tangentSpace = new osgUtil::TangentSpaceGenerator; tangentSpace-generate(objectNode-asGeode()-getDrawable(0)-asGeometry()); but the application is crashing with a BAD_ACCESS exception at the moment when getDrawable is called. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49191#49191 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Bump mapping with embedded maps in OBJs and OpenGL ES 2.0 programmable pipeline
In this way it's using another shader that I did not write by myself and this shader is giving errors. Code: State::convertShaderSourceToOsgBuiltIns() ++Before Converted source void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; gl_FrontColor = gl_Color; } Converted source uniform mat4 osg_ModelViewProjectionMatrix; attribute vec4 osg_MultiTexCoord0; attribute vec4 osg_Color; attribute vec4 osg_Vertex; void main() { gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; gl_TexCoord[0] = osg_MultiTexCoord0; gl_FrontColor = osg_Color; } Compiling VERTEX source: 1: uniform mat4 osg_ModelViewProjectionMatrix; 2: attribute vec4 osg_MultiTexCoord0; 3: attribute vec4 osg_Color; 4: attribute vec4 osg_Vertex; 5: 6: void main() 7: { 8: gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; 9: gl_TexCoord[0] = osg_MultiTexCoord0; 10: gl_FrontColor = osg_Color; 11: } VERTEX glCompileShader FAILED VERTEX Shader infolog: ERROR: 0:9: Use of undeclared identifier 'gl_TexCoord' ERROR: 0:10: Use of undeclared identifier 'gl_FrontColor' Compiling FRAGMENT source: 1: uniform sampler2D diffuseMap; 2: 3: void main() 4: { 5: vec4 base = texture2D(diffuseMap, gl_TexCoord[0].st); 6: vec4 color = base; 7: color *= gl_Color; 8: gl_FragColor = color; 9: } FRAGMENT glCompileShader FAILED FRAGMENT Shader infolog: ERROR: 0:5: Use of undeclared identifier 'gl_TexCoord' ERROR: 0:6: Use of undeclared identifier 'base' ERROR: 0:7: Use of undeclared identifier 'color' ERROR: 0:7: Use of undeclared identifier 'gl_Color' ERROR: 0:8: Use of undeclared identifier 'color' Linking osg::Program id=9 contextID=1 State's vertex attrib binding 2, osg_Color State's vertex attrib binding 7, osg_FogCoord State's vertex attrib binding 3, osg_MultiTexCoord0 State's vertex attrib binding 4, osg_MultiTexCoord1 State's vertex attrib binding 5, osg_MultiTexCoord2 State's vertex attrib binding 6, osg_MultiTexCoord3 State's vertex attrib binding 7, osg_MultiTexCoord4 State's vertex attrib binding 1, osg_Normal State's vertex attrib binding 6, osg_SecondaryColor State's vertex attrib binding 0, osg_Vertex glLinkProgram FAILED Program infolog: ERROR: One or more attached shaders not successfully compiled I think this is something built in in open scene graph. Ho can I use only my shader? Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49193#49193 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Bump mapping with embedded maps in OBJs and OpenGL ES 2.0 programmable pipeline
ok, I understand... but is there anyway to have a Geometry object from a osg::Node? I am trying with this lines of code but I have no success because no geode is found is printed. Code: osg::Geode *geode = dynamic_castosg::Geode*(_oggettoObj.get()); if (geode) { std::cout number of drawables in geode is geode-getNumDrawables() std::endl; for (unsigned int i = 0; i geode-getNumDrawables(); i++) { std::cout inside cycle i std::endl; osg::Geometry *geo = dynamic_castosg::Geometry *(geode-getDrawable(i)); if (!geo) continue; else std::cout geode has geometry i std::endl; osg::StateSet *stateset = geo-getStateSet(); if (!stateset) continue; else std::cout geometry has stateset i std::endl; osg::StateAttribute *state = stateset-getAttribute(osg::StateAttribute::MATERIAL); if (state) { osg::Material *mat = dynamic_castosg::Material *(state); std::cout material name is: mat-getName() std::endl; } else std::cout no material state i std::endl; osg::ref_ptrosgUtil::TangentSpaceGenerator tsg = new osgUtil::TangentSpaceGenerator; tsg-generate(geo, 1);//tex unit for bump map geo-setVertexAttribArray(8, tsg-getTangentArray()); geo-setVertexAttribArray(7, tsg-getBinormalArray()); std::cout binormals are: tsg-getBinormalArray()-getTotalDataSize() std::endl; std::cout tangents are: tsg-getTangentArray()-getTotalDataSize() std::endl; } } else std::cout no geode found std::endl; -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49196#49196 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Bump mapping with embedded maps in OBJs and OpenGL ES 2.0 programmable pipeline
hybr wrote: In gles 2.0 shaders dont have builtins like gl_MultiTexCoord gl_Color gl_FrontColor\gl_BackColor gl_TexCoord gl_FragColor etc, and ftransform too. Check gles 2.0 spec. Use your own varyings and attributes, use your own output from fragment shader(and dont forget to bind stuff in osg::Program). Cheers. 07.08.2012, 19:20, John Moore : In this way it's using another shader that I did not write by myself and this shader is giving errors. Code: State::convertShaderSourceToOsgBuiltIns() ++Before Converted source void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; gl_FrontColor = gl_Color; } Converted source uniform mat4 osg_ModelViewProjectionMatrix; attribute vec4 osg_MultiTexCoord0; attribute vec4 osg_Color; attribute vec4 osg_Vertex; void main() { gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; gl_TexCoord[0] = osg_MultiTexCoord0; gl_FrontColor = osg_Color; } Compiling VERTEX source: 1: uniform mat4 osg_ModelViewProjectionMatrix; 2: attribute vec4 osg_MultiTexCoord0; 3: attribute vec4 osg_Color; 4: attribute vec4 osg_Vertex; 5: 6: void main() 7: { 8: gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; 9: gl_TexCoord[0] = osg_MultiTexCoord0; 10: gl_FrontColor = osg_Color; 11: } VERTEX glCompileShader FAILED VERTEX Shader infolog: ERROR: 0:9: Use of undeclared identifier 'gl_TexCoord' ERROR: 0:10: Use of undeclared identifier 'gl_FrontColor' Compiling FRAGMENT source: 1: uniform sampler2D diffuseMap; 2: 3: void main() 4: { 5: vec4 base = texture2D(diffuseMap, gl_TexCoord[0].st); 6: vec4 color = base; 7: color *= gl_Color; 8: gl_FragColor = color; 9: } FRAGMENT glCompileShader FAILED FRAGMENT Shader infolog: ERROR: 0:5: Use of undeclared identifier 'gl_TexCoord' ERROR: 0:6: Use of undeclared identifier 'base' ERROR: 0:7: Use of undeclared identifier 'color' ERROR: 0:7: Use of undeclared identifier 'gl_Color' ERROR: 0:8: Use of undeclared identifier 'color' Linking osg::Program id=9 contextID=1 State's vertex attrib binding 2, osg_Color State's vertex attrib binding 7, osg_FogCoord State's vertex attrib binding 3, osg_MultiTexCoord0 State's vertex attrib binding 4, osg_MultiTexCoord1 State's vertex attrib binding 5, osg_MultiTexCoord2 State's vertex attrib binding 6, osg_MultiTexCoord3 State's vertex attrib binding 7, osg_MultiTexCoord4 State's vertex attrib binding 1, osg_Normal State's vertex attrib binding 6, osg_SecondaryColor State's vertex attrib binding 0, osg_Vertex glLinkProgram FAILED Program infolog: ERROR: One or more attached shaders not successfully compiled I think this is something built in in open scene graph. Ho can I use only my shader? Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49193#49193 ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Post generated by Mail2Forum This is not completely true because I wrote some simple shaders for texture mapping (without bump mapping) and they are working. I don't know precisely how it works but it seems openscenegraph is able to map these variables such as gl_ModelViewProjectionMatrix, gl_Vertex, gl_Normal, gl_MultiTexCoord0 to openscenegraph built in variables like osg_ModelViewProjectionMatrix, osg_Vertex, osg_Normal, osg_MultiTexCoord0. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49197#49197 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] OpenGL ES 2.0 and LIGHTING
Hi, I am developing an application for iPhone and iPod touch using OpenSceneGraph. In origin I written my own shaders and I used to control light using a uniform. It was working. Now I wanted to switch to use osg::Light and osg::LightSource because I think it is more object-oriented, but when I run my code I obtain this warning: Code: Warning: Light::apply(State) - not supported. Does this mean that I can't use this approach with OpenGL ES 2.0 ? I post the code I use for managing light: Code: #define LIGHT_0 0 - (osg::ref_ptrosg::Light)createLight:(osg::Vec4)color atPosition:(osg::Vec4)position { osg::ref_ptrosg::Light light = new osg::Light; // each light must have a unique number light-setLightNum(LIGHT_0); // we set the light's position via a PositionAttitudeTransform object light-setPosition(position); light-setDiffuse(color); light-setSpecular(osg::Vec4(1.0, 1.0, 1.0, 1.0)); light-setAmbient( osg::Vec4(0.0, 0.0, 0.0, 1.0)); return light; } - (void)setupLights { osg::StateSet* state = _root-getOrCreateStateSet(); state-setMode( GL_LIGHTING, osg::StateAttribute::ON ); state-setMode( GL_LIGHT0, osg::StateAttribute::ON ); // Create a MatrixTransform to position the Light. osg::ref_ptrosg::MatrixTransform mt = new osg::MatrixTransform; osg::Matrix m; m.makeTranslate( osg::Vec3( -3.f, 2.f, 5.f ) ); mt-setMatrix( m ); osg::ref_ptrosg::Light light = [self createLight:osg::Vec4(1.0,0.0,0.0,1.0) atPosition:osg::Vec4(3.0,2.0,1.0,1.0)]; // Add the Light to a LightSource. Add the LightSource and // MatrixTransform to the scene graph. osg::ref_ptrosg::LightSource ls = new osg::LightSource; _root-addChild( mt.get() ); mt-addChild( ls.get() ); ls-setLight( light.get() ); } - (void) viewDidLoad { //some other code //initialize the model and attach it to _root [self initModel]; //setup the lights [self setupLights]; //initialize the shaders and attach them to _root [self initShaders]; //create scene and attach it to _viewer _viewer-setSceneData(_root.get()); //some other code } Thank you! Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47877#47877 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Improving performance of OBJ rendering by back face culling
Hello, I am developing an application for iphone and ipod touch using openscenegraph. It is an augmented reality application and I have to load a very complex model. The original 3d model has 5 million vertices. Since I am using a mobile platform which is limited in computational power I simplified the model using 3d studio max. I reduced the size of the model from 500Mb to 4.2 Mb using proOptimizer. The model now has in total about 36,000 vertices and about 53,000 faces. I am able to render it but frame rate is slow. I'd like to improve performance using back face culling. The point is I don't know how to activate it (if it is possible): I tried with these lines of code but frame rate is still low: Code: osg::StateSet* ss = _root-getOrCreateStateSet(); osg::CullFace* cf = new osg::CullFace(osg::CullFace::BACK ); ss-setAttribute( cf ); I am using OpenGL ES 2.0 and shaders. I setup the camera in this way: Code: //set the clear color of the camera to be transparent _viewer-getCamera()-setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f)); //set the clear mask for the camera _viewer-getCamera()-setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); _viewer-getCamera()-setRenderOrder(osg::CameraNode::PRE_RENDER); _viewer-getCamera()-setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); I use DO_NOT_COMPUTE_NEAR_FAR because I need to set manually projection and viewMatrix at every drawing cycle. I also initially set viewport like this: Code: _viewer-getCamera()-setViewport(new osg::Viewport(0, 0, graphicsContext-getTraits()-width, graphicsContext-getTraits()-height)); The hierarchy of my object is structured as: _root is a osg::MatrixTransform my 3d model is divided in subparts. all the subparts of my 3d model are direct child of _root and are of type osg::Node I hope you can give me some tips to improve performance. If you need some other information about my setup I will be glad to give it. Thank you. Greetings, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47880#47880 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org