Skip to content

Commit

Permalink
move inspect out of Context
Browse files Browse the repository at this point in the history
  • Loading branch information
szabolcsdombi committed Apr 12, 2022
1 parent 0c841b6 commit 105ab8e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
78 changes: 39 additions & 39 deletions zengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,44 +1226,6 @@ PyObject * Context_meth_release(Context * self, PyObject * arg) {
Py_RETURN_NONE;
}

PyObject * Context_meth_inspect(Context * self, PyObject * arg) {
const GLMethods & gl = self->gl;
if (Py_TYPE(arg) == self->module_state->Buffer_type) {
Buffer * buffer = (Buffer *)arg;
return Py_BuildValue("{sssi}", "type", "buffer", "buffer", buffer->buffer);
} else if (Py_TYPE(arg) == self->module_state->Image_type) {
Image * image = (Image *)arg;
const char * gltype = image->renderbuffer ? "renderbuffer" : "texture";
int framebuffer = image->framebuffer ? image->framebuffer->obj : -1;
return Py_BuildValue("{sssisi}", "type", gltype, gltype, image->image, "framebuffer", framebuffer);
} else if (Py_TYPE(arg) == self->module_state->Pipeline_type) {
Pipeline * pipeline = (Pipeline *)arg;
PyObject * buffers = PyList_New(pipeline->descriptor_set_buffers->buffers);
for (int i = 0; i < pipeline->descriptor_set_buffers->buffers; ++i) {
int buffer = pipeline->descriptor_set_buffers->binding[i].buffer;
PyObject * obj = Py_BuildValue("{sssi}", "type", "buffer", "buffer", buffer);
PyList_SetItem(buffers, i, obj);
}
PyObject * samplers = PyList_New(pipeline->descriptor_set_images->samplers);
for (int i = 0; i < pipeline->descriptor_set_images->samplers; ++i) {
int sampler = pipeline->descriptor_set_images->binding[i].sampler;
int image = pipeline->descriptor_set_images->binding[i].image;
PyObject * obj = Py_BuildValue("{sssisi}", "type", "sampler", "sampler", sampler, "texture", image);
PyList_SetItem(samplers, i, obj);
}
return Py_BuildValue(
"{sssNsNsisisi}",
"type", "pipeline",
"buffers", buffers,
"samplers", samplers,
"framebuffer", pipeline->framebuffer->obj,
"vertex_array", pipeline->vertex_array->obj,
"program", pipeline->program->obj
);
}
Py_RETURN_NONE;
}

PyObject * Buffer_meth_write(Buffer * self, PyObject * vargs, PyObject * kwargs) {
static char * keywords[] = {"data", "offset", NULL};

Expand Down Expand Up @@ -1840,6 +1802,44 @@ int Pipeline_set_framebuffer(Pipeline * self, PyObject * framebuffer) {
return 0;
}

PyObject * meth_inspect(PyObject * self, PyObject * arg) {
ModuleState * module_state = (ModuleState *)PyModule_GetState(self);
if (Py_TYPE(arg) == module_state->Buffer_type) {
Buffer * buffer = (Buffer *)arg;
return Py_BuildValue("{sssi}", "type", "buffer", "buffer", buffer->buffer);
} else if (Py_TYPE(arg) == module_state->Image_type) {
Image * image = (Image *)arg;
const char * gltype = image->renderbuffer ? "renderbuffer" : "texture";
int framebuffer = image->framebuffer ? image->framebuffer->obj : -1;
return Py_BuildValue("{sssisi}", "type", gltype, gltype, image->image, "framebuffer", framebuffer);
} else if (Py_TYPE(arg) == module_state->Pipeline_type) {
Pipeline * pipeline = (Pipeline *)arg;
PyObject * buffers = PyList_New(pipeline->descriptor_set_buffers->buffers);
for (int i = 0; i < pipeline->descriptor_set_buffers->buffers; ++i) {
int buffer = pipeline->descriptor_set_buffers->binding[i].buffer;
PyObject * obj = Py_BuildValue("{sssi}", "type", "buffer", "buffer", buffer);
PyList_SetItem(buffers, i, obj);
}
PyObject * samplers = PyList_New(pipeline->descriptor_set_images->samplers);
for (int i = 0; i < pipeline->descriptor_set_images->samplers; ++i) {
int sampler = pipeline->descriptor_set_images->binding[i].sampler;
int image = pipeline->descriptor_set_images->binding[i].image;
PyObject * obj = Py_BuildValue("{sssisi}", "type", "sampler", "sampler", sampler, "texture", image);
PyList_SetItem(samplers, i, obj);
}
return Py_BuildValue(
"{sssNsNsisisi}",
"type", "pipeline",
"buffers", buffers,
"samplers", samplers,
"framebuffer", pipeline->framebuffer->obj,
"vertex_array", pipeline->vertex_array->obj,
"program", pipeline->program->obj
);
}
Py_RETURN_NONE;
}

struct vec3 {
double x, y, z;
};
Expand Down Expand Up @@ -2123,7 +2123,6 @@ PyMethodDef Context_methods[] = {
{"pipeline", (PyCFunction)Context_meth_pipeline, METH_VARARGS | METH_KEYWORDS, NULL},
{"clear_shader_cache", (PyCFunction)Context_meth_clear_shader_cache, METH_NOARGS, NULL},
{"release", (PyCFunction)Context_meth_release, METH_O, NULL},
{"inspect", (PyCFunction)Context_meth_inspect, METH_O, NULL},
{},
};

Expand Down Expand Up @@ -2286,6 +2285,7 @@ PyModuleDef_Slot module_slots[] = {

PyMethodDef module_methods[] = {
{"context", (PyCFunction)meth_context, METH_VARARGS | METH_KEYWORDS, NULL},
{"inspect", (PyCFunction)meth_inspect, METH_O, NULL},
{"camera", (PyCFunction)meth_camera, METH_VARARGS | METH_KEYWORDS, NULL},
{"rgba", (PyCFunction)meth_rgba, METH_VARARGS | METH_KEYWORDS, NULL},
{"pack", (PyCFunction)meth_pack, METH_FASTCALL, NULL},
Expand Down
2 changes: 1 addition & 1 deletion zengl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ class Context:
viewport: Viewport | None = None) -> Pipeline: ...
def clear_shader_cache(self) -> None: ...
def release(self, obj: Buffer | Image | Pipeline) -> None: ...
def inspect(self, obj: Buffer | Image | Pipeline): ...


def context(loader: ContextLoader | Any | None = None) -> Context: ...
def inspect(self, obj: Buffer | Image | Pipeline): ...
def camera(
eye: Vec3, target: Vec3, up: Vec3 = (0.0, 0.0, 1.0), *,
fov: float = 45.0, aspect: float = 1.0, near: float = 0.1, far: float = 1000.0,
Expand Down

0 comments on commit 105ab8e

Please sign in to comment.