Hello,<div>I have been fiddling some time with implementing a prototype for a research project in Cairo in combination with Python and OpenGL. </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 continuously.</div><div><br> </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> </div><div>def redraw():</div><div> global Tree</div><div> global surface</div><div> global surfacedata</div><div> global writing_texture
</div><div> </div><div> while 1:</div><div> surface1 = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(Tree.getroot().get("width")), int(Tree.getroot().get("height")))</div><div> ctx =
cairo.Context(surface1)</div><div> ctx.set_source_rgba(0, 0, 0, 1)</div><div> ctx.set_tolerance(0.1)</div><div> ctx.set_line_join(cairo.LINE_JOIN_ROUND)</div><div> </div><div> ViewManager.draw
(Tree.getroot(), ctx)</div><div> </div><div> surface = ctx.get_target()</div><div> surfacedata = str(surface.get_data())</div><div> </div><div> time.sleep(0.01) </div><div><br>
</div><div><br> </div><div>I then in my OpenGL draw function have the texture generation:</div><div><br> </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> </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> </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>