Hello,<div>I have been fiddling some time with implementing a prototype for a research project in Cairo in combination with Python and OpenGL.&nbsp;</div><div>I have finally got it running, but the performance is very poor.</div>

<div>I have a (changing) XML structure (in elementtree) that I need re-rendered&nbsp;continuously.</div><div><br>&nbsp;</div><div>I have a thread creating a new cairo image all the time, looking something like below, where Tree is the structure I draw and 
ViewManger.draw() does the drawing.</div><div><br>&nbsp;</div><div>def redraw():</div><div>&nbsp;&nbsp; &nbsp;global Tree</div><div>&nbsp;&nbsp; &nbsp;global surface</div><div>&nbsp;&nbsp; &nbsp;global surfacedata</div><div>&nbsp;&nbsp; &nbsp;global writing_texture
</div><div>&nbsp;&nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp;while 1:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;surface1 = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(Tree.getroot().get(&quot;width&quot;)), int(Tree.getroot().get(&quot;height&quot;)))</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ctx = 
cairo.Context(surface1)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ctx.set_source_rgba(0, 0, 0, 1)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ctx.set_tolerance(0.1)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ctx.set_line_join(cairo.LINE_JOIN_ROUND)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ViewManager.draw

(Tree.getroot(), ctx)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;surface = ctx.get_target()</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;surfacedata = str(surface.get_data())</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;time.sleep(0.01)&nbsp;</div><div><br>
</div><div><br>&nbsp;</div><div>I then in my OpenGL draw function have the texture generation:</div><div><br>&nbsp;</div><div>glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, int(
surface.get_width()), int(surface.get_height()), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, surfacedata)</div><div><br>&nbsp;</div><div>The overall problem is that the operation str(surface.get.data
()) takes something around 300ms on my computer (Powerbook 1.67ghz), but it seems I have to do this conversion in order to get glTexImage2D to eat the data. If I just feed it with surface.get_data() (which would be the pointer to the data, and the most natural way to do it) I get a segmentation fault.
</div><div><br>&nbsp;</div><div>Are there anyone who have tried to do something similar, and have found a way to get around converting the data in memory to a string?</div><div><br class="webkit-block-placeholder"></div><div>
Thanks,</div><div>Clemens</div>