Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Slow texture creation in RDP

8 views
Skip to first unread message

asper...@gmail.com

unread,
Dec 21, 2009, 12:02:00 PM12/21/09
to
Hi all,

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

asper...@gmail.com

unread,
Dec 22, 2009, 5:13:31 AM12/22/09
to
Additional info:
I share one rendering context among different windows. I implemented
it that way long ago, when I was hunting an elusive crash with
multiple OpenGL windows. Since my application is single-threaded, I
saw no harm always switching contexts (wglMakeCurrent) before drawing
to a specific window.

asper...@gmail.com

unread,
Dec 22, 2009, 8:35:54 AM12/22/09
to
I changed several things which seems to fix the problem:
1) Instead of multiple windows sharing one rendering context, I now
use one rendering context per window
2) Textures are shared across rendering contexts using wglShareLists
3) Textures I use for text display are re-used if the same text with
the same font, size, etc. is to be displayed. That way, I can
significantly cut down on the number of textures used.

I don't know if I will experience any side effects, especially with
different graphic cards and multi-monitor applications.

fungus

unread,
Dec 22, 2009, 8:57:05 AM12/22/09
to
On Dec 22, 2:35 pm, "asperama...@gmail.com" <asperama...@gmail.com>
wrote:

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

asper...@gmail.com

unread,
Jan 7, 2010, 9:11:22 AM1/7/10
to
On Dec 22 2009, 2:57 pm, fungus <openglMYSO...@artlum.com> wrote:
>
> OTOH I don't see why any of them would affect texture
> creation speed...
>

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.

0 new messages