Browse Source

python: hide cryptic shit in less cryptic wrappers.

UGH.
pull/2/head
Vladimír Vondruš 7 years ago
parent
commit
e28e58b5b8
  1. 9
      src/python/corrade/PyBuffer.h
  2. 7
      src/python/magnum/gl.cpp

9
src/python/corrade/PyBuffer.h

@ -29,6 +29,8 @@
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StridedArrayView.h>
#include "Corrade/Python.h"
#include "bootstrap.h"
namespace corrade {
@ -45,17 +47,12 @@ template<class Class, bool(*getter)(Class&, Py_buffer&, int)> void enableBetterB
CORRADE_INTERNAL_ASSERT(typeObject.as_buffer.bf_releasebuffer == pybind11::detail::pybind11_releasebuffer);
typeObject.as_buffer.bf_getbuffer = [](PyObject *obj, Py_buffer *buffer, int flags) {
/* Stolen from pybind11::class_::def_buffer(). Not sure what exactly
it does, but I assume caster is implicitly convertible to Class& and
thus can magically access the actual Class from the PyObject. */
pybind11::detail::make_caster<Class> caster;
CORRADE_INTERNAL_ASSERT(!PyErr_Occurred() && buffer);
CORRADE_INTERNAL_ASSERT(caster.load(obj, /*convert=*/false));
/* Zero-initialize the output and ask the class to fill it. If that
fails for some reason, give up */
*buffer = Py_buffer{};
if(!getter(caster, *buffer, flags)) {
if(!getter(pyInstanceFromHandle<Class>(obj), *buffer, flags)) {
CORRADE_INTERNAL_ASSERT(!buffer->obj);
CORRADE_INTERNAL_ASSERT(PyErr_Occurred());
return -1;

7
src/python/magnum/gl.cpp

@ -39,6 +39,7 @@
#include <Magnum/GL/RenderbufferFormat.h>
#include <Magnum/Math/Color.h>
#include "Corrade/Python.h"
#include "Magnum/Python.h"
#include "corrade/PyArrayView.h"
@ -331,8 +332,7 @@ void gl(py::module& m) {
/* Keep a reference to the renderbuffer to avoid it being deleted
before the framebuffer */
/** @todo isn't there an API for this? */
self.attached.emplace_back(py::detail::get_object_handle(&renderbuffer, py::detail::get_type_info(typeid(GL::Renderbuffer))), true);
self.attached.emplace_back(pyObjectFromInstance(renderbuffer));
}, "Attach renderbuffer to given buffer")
.def_readonly("attached", &PyFramebuffer::attached, "Renderbuffer and texture objects referenced by the framebuffer");
@ -390,8 +390,7 @@ void gl(py::module& m) {
/* Keep a reference to the buffer to avoid it being deleted before
the mesh */
/** @todo isn't there an API for this? */
self.buffers.emplace_back(py::detail::get_object_handle(&buffer, py::detail::get_type_info(typeid(GL::Buffer))), true);
self.buffers.emplace_back(pyObjectFromInstance(buffer));
}, "Add vertex buffer", py::arg("buffer"), py::arg("offset"), py::arg("stride"), py::arg("attribute"))
.def("draw", [](PyMesh& self, GL::AbstractShaderProgram& shader) {
self.draw(shader);

Loading…
Cancel
Save