Code archives/3D Graphics - Misc/OpenGL Accelerator
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Switching textures usually creates a bottleneck on graphics processing hardware. These two replacement functions will provide smarter handling of textures, and a speed increase that will vary depending on how efficient your rendering routine is. In order for this to work, you must use these two functions everywhere, instead of the original OpenGL functions. You might want to temporarily declare the OpenGL functions at the beginning of your code with no parameters, so that you can catch all references to the original functions in your source, and add an underscore at the end. | |||||
Private Const GL_TEXTURE_1D_SLOT=1 Const GL_TEXTURE_2D_SLOT=2 Const GL_TEXTURE_3D_SLOT=3 Const GL_TEXTURE_CUBE_MAP_SLOT=4 Const GL_TEXTURE_RECTANGLE_ARB_SLOT=5 Global BoundTexture[64,5] Global CurrentTextureUnit Global FastTextureBind=True' toggle this variable to see the difference Function glBindTexture_(target,index) Local slot Select target Case GL_TEXTURE_1D slot=GL_TEXTURE_1D_SLOT Case GL_TEXTURE_2D slot=GL_TEXTURE_2D_SLOT Case GL_TEXTURE_3D slot=GL_TEXTURE_3D_SLOT Case GL_TEXTURE_CUBE_MAP slot=GL_TEXTURE_CUBE_MAP_SLOT Case GL_TEXTURE_RECTANGLE_ARB slot=GL_TEXTURE_RECTANGLE_ARB_SLOT Default RunTimeError "Unknown texture target." EndSelect If FastTextureBind If BoundTexture[CurrentTextureUnit,slot]=index Return EndIf glBindTexture target,index BoundTexture[CurrentTextureUnit,slot]=index EndFunction Function glActiveTextureARB_(texunit) If FastTextureBind If CurrentTextureUnit=texunit-GL_TEXTURE0 Return EndIf glActiveTextureARB texunit CurrentTextureUnit=texunit-GL_TEXTURE0 EndFunction Public Rem 'Uncomment for testing: Function glbindtexture() EndFunction Function glActiveTextureARB() EndFunction EndRem |
Comments
None.
Code Archives Forum