[Request] Dont Call glBindTexture Unless Necessary ... and glIsEnabled/glEnable
2 posters
[Request] Dont Call glBindTexture Unless Necessary ... and glIsEnabled/glEnable
I was doing a bit of testing with one of the tutorials and found that glBindTexture is a VERY expensive call on the iPhone. Would it be possible to modify sio2Image to check to see if the texture it is binding is not the currently bound texture?
sio2ImageRender could just be modified with something simple like:
This strategy could also apply to all the glEnable calls with the current state being maintained in the sio2 struct to avoid unnecessary calls to glIsEnabled and glEnable.
I would like to make these changes in the version of SIO2 that I am using but I don't want to modify any of the SIO2 source so that I don't make my upgrade path difficult. These are some pretty easy changes that get a surprisingly large benefit on the iPhone from my testing.
sio2ImageRender could just be modified with something simple like:
- Code:
if( sio2->currentTid != _SIO2image->tid )
{
glBindTexture( GL_TEXTURE_2D, _SIO2image->tid );
sio2->currentTid = _SIO2image->tid;
}
This strategy could also apply to all the glEnable calls with the current state being maintained in the sio2 struct to avoid unnecessary calls to glIsEnabled and glEnable.
I would like to make these changes in the version of SIO2 that I am using but I don't want to modify any of the SIO2 source so that I don't make my upgrade path difficult. These are some pretty easy changes that get a surprisingly large benefit on the iPhone from my testing.
uprise78- Posts : 228
Join date : 2008-10-31
Re: [Request] Dont Call glBindTexture Unless Necessary ... and glIsEnabled/glEnable
I would suggest you to use a texture atlas, and create 1 material that is applied to all the necessary object...
So basically:
1. Material containing the atlas.
2. The material is applied on ALL objects that have a texture within the atlas.
3. When SIO2 is going to render is going to check for the last material.
The idea is to create ONE material per texture and apply it on as much object as you can... there's ALOT more state changes by rendering the material than the texture... You should really go with this approach.
Also, by default all objects are sorted alphabetically within the SIO2 file... you can tweak the name of your object to fit with the material that you are using. This will help SIO2 to perform better.
ex:
Material -> Wood -> Wood.jpg
w_Bench
w_Chair
w_Table
In this example its pretty much sure that when you see the table you'll see the Bench and the Chair by regrouping them alphabetically based on their material you avoid SIO2 to bind the material multiple times and since the material is the most heavy thing to bind in SIO2 well... I think you start getting it by now
So basically:
1. Material containing the atlas.
2. The material is applied on ALL objects that have a texture within the atlas.
3. When SIO2 is going to render is going to check for the last material.
The idea is to create ONE material per texture and apply it on as much object as you can... there's ALOT more state changes by rendering the material than the texture... You should really go with this approach.
Also, by default all objects are sorted alphabetically within the SIO2 file... you can tweak the name of your object to fit with the material that you are using. This will help SIO2 to perform better.
ex:
Material -> Wood -> Wood.jpg
w_Bench
w_Chair
w_Table
In this example its pretty much sure that when you see the table you'll see the Bench and the Chair by regrouping them alphabetically based on their material you avoid SIO2 to bind the material multiple times and since the material is the most heavy thing to bind in SIO2 well... I think you start getting it by now
Re: [Request] Dont Call glBindTexture Unless Necessary ... and glIsEnabled/glEnable
Ahhhh...that will work just fine SIO2. Thanks for the alphabetical tip.
How about the glIsEnabled/glEnabled calls? They could all easily be wrapped up in an sio2GlEnbable() function that keeps it's own state to avoid state changes and gl queries when not necessary.
How about the glIsEnabled/glEnabled calls? They could all easily be wrapped up in an sio2GlEnbable() function that keeps it's own state to avoid state changes and gl queries when not necessary.
uprise78- Posts : 228
Join date : 2008-10-31
Re: [Request] Dont Call glBindTexture Unless Necessary ... and glIsEnabled/glEnable
Yes... but Im not sure that the performance gain will be tremendous... I had this in mind for a while but I never implement it...
Similar topics
» OpenGL glIsEnabled Calls
» REQUEST: Lua to Python
» tutorial request
» Code Response(s) on features & Request(s)
» Request: code comments
» REQUEST: Lua to Python
» tutorial request
» Code Response(s) on features & Request(s)
» Request: code comments
Permissions in this forum:
You cannot reply to topics in this forum