I am currently investigating a situation where texture creation, even
of small textures, is very slow. The circumstances are a bit special:
1) I am using the Microsoft software implementation of OpenGL on
Windows Server 2003 (this is the only implementation I can rely on
being available everywhere I deploy, and normally, the software
renderer is fast enough for my needs)
2) My code needs to run on OpenGL 1.1 (again, the only version I can
be certain will be available), so unfortunately, no nifty post-1.1-
features
3) The problem only occurs when the application is running via
RemoteDesktop
4) The problem only appears when you open a second window while the
first one is still open. The first window is as fast as you would
expect
The code I use for texture creation is at the end of the posting. It
basically gets a byte array with 32bpp color depth, and creates a
texture from it.
From my performance analysis, I found out the following calls to be
slow in my test case:
Call glGetIntegerv(glgUnPackAlignment, lngPrevUnpackAlignment)
(~11 ms per call)
Call glTexImage2D(glTexture2D, 0, 4, w, h, 0, tiRGBA,
GL_UNSIGNED_BYTE, bits(0))
(~11 ms per call)
Normally (non-Remote-Desktop or first window), those functions are
between 100 and 1000 times faster.
Please note that I create a lot of textures, but they are small (e.g.
64x16 pixels)
Right now, I am looking for ideas. Please throw any thoughts you have
my way (regardless how crazy they may sound). I have, so far, not been
able to fully reproduce this problem in a small sample. The code below
might run just fine in an isolated executable - or not.
*******************************************************************************************
Public Function TextureGenerate(ByVal w As Long, _
ByVal h As Long, _
ByRef bits() As Byte, _
ByVal blnInterpolate As Boolean, _
ByVal lngTransparentColor As Long, _
ByVal lngBaseAlphaValue As Long, _
ByRef blnTextureUsesAlpha As Boolean)
As Long
'*** Line(s) added by AutoErrHandler: Header
On Error GoTo Errhandler
'*** End AutoErrHandle: Header
Dim lngTex As Long
Dim lngFilterFlag As Long
Dim lngMagFilterFlag As Long
Dim i As Long
Dim lngColor As Long
Dim c As Long
Dim bytAlpha As Byte
Dim bytTemp As Byte
Dim strKey As String
Dim lngPrevUnpackAlignment As Long
Call glGenTextures(1, lngTex)
If (lngTex = 0) Then
' Not good...
Exit Function
End If
Call glBindTexture(GL_TEXTURE_2D, lngTex)
' Code to do some transparency calculations on bits()
' and flips red and blue byte
If (glngOGLMajorVersion > 1) Or (glngOGLMinorVersion >= 4) Then
' Much faster implementation available with OpenGL 1.4+
' Code omitted because it's irrelevant here
ElseIf (IsPowerOf2(w) And IsPowerOf2(h)) And _
(glngWindowsMajorVersion < 6) Then
' This code does not seem to work in Vista
Call glTexEnvi(tetTextureEnv, tenTextureEnvMode, tepModulate)
If (blnInterpolate) Then
lngFilterFlag = GL_LINEAR
lngMagFilterFlag = GL_LINEAR
Else
lngFilterFlag = GL_NEAREST
lngMagFilterFlag = GL_NEAREST
End If
Call glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
lngFilterFlag)
Call glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
lngMagFilterFlag)
Call glGetIntegerv(glgUnPackAlignment, lngPrevUnpackAlignment)
Call glPixelStorei(pxsUnpackAlignment, 1)
Call glTexImage2D(glTexture2D, 0, 4, w, h, 0, tiRGBA,
GL_UNSIGNED_BYTE, bits(0))
Call glPixelStorei(pxsUnpackAlignment, lngPrevUnpackAlignment)
Else
' Code omitted because it's irrelevant here
End If
TextureGenerate = lngTex
End Function
I don't know if I will experience any side effects, especially with
different graphic cards and multi-monitor applications.
There's nothing there which should cause problems
(in fact this is the way I do it).
OTOH I don't see why any of them would affect texture
creation speed...
--
<\___/>
/ O O \
\_____/ FTB.
http://www.topaz3d.com/ - New 3D editor for real time simulation
I don't either, but I just tested it, and with one RC = one DC and
shared textures, suddenly everything is back to normal speed.