summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-02-08 14:35:38 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:53:56 -0300
commit280d68ca34debebfeb9172420598a15ba576eb7e (patch)
treefd64da47e26e1c10c760f6be5331ed16b1b19544
parent8cb71269c6273133710cfee3759cbbbf20ec6292 (diff)
Fix QGLBuffer::map code injection and test.
-rw-r--r--PySide/QtOpenGL/typesystem_opengl.xml18
-rw-r--r--tests/QtOpenGL/qglbuffer_test.py34
2 files changed, 26 insertions, 26 deletions
diff --git a/PySide/QtOpenGL/typesystem_opengl.xml b/PySide/QtOpenGL/typesystem_opengl.xml
index cef742dc..6ff9614d 100644
--- a/PySide/QtOpenGL/typesystem_opengl.xml
+++ b/PySide/QtOpenGL/typesystem_opengl.xml
@@ -123,12 +123,18 @@
</inject-code>
</modify-function>
<modify-function signature="map(QGLBuffer::Access)">
- <inject-code class="target" position="beginning">
- void *data = %CPPSELF.map(%1);
- QByteArray ret;
- if (data)
- ret.append((const char*)data, %CPPSELF.size());
- %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ret);
+ <inject-code>
+ Py_ssize_t dataSize = %CPPSELF.size();
+ void* data = %CPPSELF.map(%1);
+
+ if (!data) {
+ Py_INCREF(Py_None);
+ %PYARG_0 = Py_None;
+ } else if (%1 == QGLBuffer::ReadOnly) {
+ %PYARG_0 = PyBuffer_FromMemory(data, dataSize);
+ } else {
+ %PYARG_0 = PyBuffer_FromReadWriteMemory(data, dataSize);
+ }
</inject-code>
</modify-function>
<modify-function signature="read(int, void*, int)">
diff --git a/tests/QtOpenGL/qglbuffer_test.py b/tests/QtOpenGL/qglbuffer_test.py
index ae23fbdf..2cf06027 100644
--- a/tests/QtOpenGL/qglbuffer_test.py
+++ b/tests/QtOpenGL/qglbuffer_test.py
@@ -9,12 +9,11 @@ from PySide.QtOpenGL import QGLBuffer, QGLWidget
from helper import UsesQApplication
class QGLBufferTest(UsesQApplication):
- def usageCheck(self, t):
+ def testIt(self):
w = QGLWidget()
w.makeCurrent()
- b = QGLBuffer(t)
- self.assertEqual(b.usagePattern(), QGLBuffer.StaticDraw)
+ b = QGLBuffer()
b.setUsagePattern(QGLBuffer.DynamicDraw)
self.assert_(b.create())
@@ -26,24 +25,19 @@ class QGLBufferTest(UsesQApplication):
self.assertEqual(b.size(), data.size())
m = b.map(QGLBuffer.ReadOnly)
- self.assertEqual(m.data(), data.data())
- b.unmap()
-
- other_data = QByteArray("67")
- b.write(0, other_data)
- m = b.map(QGLBuffer.ReadOnly)
- self.assertEqual(m.mid(0, other_data.size()).data(), other_data.data())
- b.unmap()
-
- result, rdata = b.read(0, other_data.size())
- print result, rdata
- self.assert_(result)
- self.assertEqual(other_data.data(), rdata.data())
-
+ if m:
+ self.assertEqual(m, buffer(data.data()))
+ b.unmap()
+
+ m = b.map(QGLBuffer.ReadWrite)
+ m[3] = 'A'
+ b.unmap()
+ result, rdata = b.read(3, 1)
+ self.assertTrue(result)
+ self.assertEqual('A', rdata.data())
+ else:
+ print " memory mapping is not possible in this OpenGL implementation."
b.release()
- def testUsage(self):
- self.usageCheck(QGLBuffer.IndexBuffer)
-
if __name__ == '__main__':
unittest.main()