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>2011-02-09 18:26:12 -0200
commit8fa461559c80d4b5a8c6814b403930724303ed00 (patch)
treebbd5a7a9ddd7d327a188d90deb602257c72838fa
parent06755f06ba70288912893bbbd213f5458047cea8 (diff)
downloadpyside-8fa461559c80d4b5a8c6814b403930724303ed00.tar.gz
pyside-8fa461559c80d4b5a8c6814b403930724303ed00.tar.xz
pyside-8fa461559c80d4b5a8c6814b403930724303ed00.zip
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 cef742d..6ff9614 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 ae23fbd..2cf0602 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()