-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Reducing the number of methods in TextureManager #600
Comments
I would say As for the data members, I am not sure where they get used in the process. If they need to be reuploaded for a new context, how does |
I guess I didn't explain it very well. It has been a long day ... 😴
But I really think it shouldn't be in the TextureConfig class. This is definitely something that the TextureManager class should manage. |
Ah, yes. I would agree. |
@MasDennis Thanks for saving me the hassle of figuring out the texture stuff btw...I wasn't looking forward to it 😉 |
Well thank you for your hard work on the scene graph! |
I think the ability to add custom texture names and override default names like "uDiffuseTexture", "uDiffuseTexture1", etc. would be a nice. |
This turns out to be one of those things that ends up affecting the framework significantly. It also turns out to be a lot more work than I thought. But it is all for the Greater Good 🍻 Here's what I think should change. Please feed back on this.
Texture texture = new Texture(TextureType.DIFFUSE);
texture.setBitmap(R.drawable.my_texture);
DiffuseMaterial material = new DiffuseMaterial();
material.addTexture(texture); In this case
|
I don't think there is anything wrong with Singletons. It is the misuse of of them that upsets people. In this case I disagree though. The problem I see is having multiple GLES contexts such as having a wallpaper set and having a preview. This leads to a higher chance of unknowingly eating up all the application memory loading the textures in multiple times as the user switches back and forth. Next I will throw it out there that no caffeine has been applied this morning so I could very well be way off base here. For setting a texture atlas, I believe the simple solution is something like this. Essentially TextureInfo would store the bounding box of each texture inside the atlas and users would only need to know the ID of the texture in the atlas to apply it to an object. TextureInfo textureAtlasInfo = mTextureManage.addTexture(R.drawable.my_texuture_atlas);
int atlasPositionID = textureAtlasInfo.defineAtlasPosition(x, y, w, h);
SimpleMaterial material = new SimpleMaterial();
material.addTexture(textureAtlasInfo);
Plane plane = new Plane(1, 1, 1, 1);
plane.setAtlas(textureAtlasInfo, atlasPositionID); I think a setup like that should allow for manipulation of the geometry. It should also be forward thinking by still giving objects a chance to manipulate data based on the TextureInfo. And finally, it does not require massive changes, or so I think. |
I'm all for singleton methods for the texture manager. I see nearly double memory usage and LogCat reports preview instance separately loading bitmaps into memory when the wallpaper is set and the preview is running at the same time. Using a singleton pattern should greatly help reduce resource usage. I support the name change from |
@ToxicBakery Yes, that @AndrewJo Thanks for your input. Inheritance makes perfect sense here. As @AndrewJo said, the singleton could solve some memory issues. @ToxicBakery could you inject a double espresso and have another think about it? Cheers for your input guys. Much appreciated. |
Alright, if TextureManager is a singleton, how do we handle the loading the of textures in a way that prevents the same texture being loaded twice. It seems textures would need to be given names or something similar so that the texture manager would be able to identify when a texture already exists otherwise it will just keep accepting duplicate textures each time a preview is shown. |
For bitmap resources we could use |
I think we should also allow custom texture names if the user decides to create a custom material that uses the textures instead of canned |
Now that you all have had a party while I was sleeping, I'll give my two cents....
-Perhaps it has to do with the mutual lack of caffeine, but I am not sure I fully understand Ian's suggestion for handling the atlas. I think it is basically add the atlas to Texture atlas = mTextureManager.packTexturesFromAssets("AwesomeAtlas", 1024, 1024, 0, false, "atlas");
SimpleMaterial material = new SimpleMaterial();
material.addTexture(atlas);
Plane plane = new Plane(1, 1, 1, 1);
plane.setAtlas(atlas, tile); Some details here are a matter of opinion but basically
@AndrewJo I'm guessing this stems from actual experience? I am not certain what the use case would be here. |
I do this this will work, and as @jwoolston points out the terminology needs some tweaking. This is how I have named thins so far.
It seems like the overall theory is sound. Passing an atlas and tile name into However, |
actually better yet, |
As long as you dont have two tiles of the same name in different atlases this would work fine. |
The tile name is set from the resourceID, so I believe you can't have duplicate names anyhow |
Never thought of that. There ya go, problem solved. Yes, thats nice and simple |
Thanks for your input guys. Very helpful. |
@MasDennis I will put a hold on the remaining tasks for the atlas until you are prepared to collaborate. I think we will need a little strategy to bring our two worlds together. I start a new job at the end of the month, so I will have significantly more time in the next two weeks to accomplish this than I will later on. |
Oh, by the way @jwoolston
These convenience methods are only used to store bitmaps and decode bitmaps. The OpenGL specific uploads will be thread safe and handled by @Davhed Congratulations! That's great news. 🍻 |
Sounds good. |
So. A lot of work. But it is getting there.
I will be working on compressed textures next. But the can is open. Worms are crawling up my trousers. |
Wow, Very awesome @MasDennis.
So is @jwoolston-izing going to be code for thread safe now? Have I broken the library that much 😉 I suppose @ToxicBakery pointed out the crusade/blitzkrieg I have brought upon threads. Yes, they should be thread safe, especially with the deferred lighting prospect....I see things going all kinds of crazy on us there. |
🤘 @jwoolston -ization is indeed code for the thread safety crusade. |
Well now I can die happy, my imprint on the world has been made 🚶 @AndrewJo we have a cat who does that. |
Not yet, finish the SceneGraph first please.
ANIMATED GIF PLEASE!!!! |
@MasDennis I am madly in love with the simplicity of this:
|
Also, since you've relegated Bump Maps to their own class do you plan to do the same for Alpha and Specular? To be nitpicky... shouldn't they be called Normal Maps (for RGB) and Height Maps (for B&W)? |
I'll have to see if I can get him to cooperate. |
It is a lot cleaner isn't it?
I just did 😄
Mmmm good call. Now is our chance to rename stuff so I'll rename BumpMap to NormalMap. Makes sense. |
👍 |
Ok, so the overhaul seems to be done. There's no documentation yet but I'm going to work on something else for a moment. Need a break! |
🍻 are in order. |
Loads of them. Kegs. |
If i had a resaonably way of getting my meade across the ocean to you, id send you some. |
@MasDennis I don't seem to be able to get those branches to compile |
What errors do you get? |
They're working fine for me 💃 |
I lied, I'm getting "The method Texture(String, Bitmap) is undefined for the type WallpaperRenderer", but when I review the Texture class I indeed see: public Texture(String textureName, Bitmap bitmap)
{
super(TextureType.DIFFUSE, textureName, bitmap);
} And the imports appear correct...
|
Strange. Did you do a clean before a rebuild all? |
This actually reminded me to update the wallpaper template as well: https://github.com/MasDennis/RajawaliWallpaperTemplate/tree/texture-manager-rewrite Please let me know if you still have problems. |
It's still not working... I'm going to try and diagnose and treat this evening. |
Thanks @Davhed There are still some issues with the live wallpaper template (run time, not compile time). I'll investigate either this evening or tomorrow. |
I just pushed another update. If nobody objects then I'll push it to master tomorrow. |
I took a look through it, I see no issues to prevent it from being in master. |
I've just pushed it to master. Please go ahead and test it. |
👍 You sir are a gentleman and a scholar. 🍻 |
Problem
The
TextureManager
class currently has no less than 56 methods that do basically the same thing: add textures.This is a proposal to simplify the API and to make the TextureManager more compact. Your feedback (especially @AndrewJo) is appreciated.
Solution
Leverage the existing
TextureInfo
class. Most of the parameters that are passed to theaddTexture()
methods are already part of theTextureInfo
class.A significant change is that
TextureInfo
will be used as input instead of output.This way the number of
addTexture()
methods can be reduced from 56 to 10.Implementation
TextureInfo class properties:
New
TextureManager
methods:Usage
Still in Question
Should
Bitmap
,Bitmap[]
andByteBuffer
still be part of theTextureInfo
class? Semantically it is incorrect I think.These properties are only used when the textures shouldn't be recycled. This way the texture can be uploaded again when the OpenGL context needs to be re-created. This can be flagged by the user by setting
info.shouldRecycle()
tofalse
.An alternative solution would be to store these in the
TextureManager
class.Should the class be called
TextureInfo
or should it be renamed toTextureConfig
?The text was updated successfully, but these errors were encountered: