Skip to content

Commit

Permalink
implement polygon offset
Browse files Browse the repository at this point in the history
  • Loading branch information
szabolcsdombi committed Nov 8, 2021
1 parent 172b5db commit 323e9e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions moderngl/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,24 @@ int MGLContext_set_provoking_vertex(MGLContext * self, PyObject * value) {
return -1;
}

PyObject * MGLContext_get_polygon_offset(MGLContext * self) {
return Py_BuildValue("ff", self->polygon_offset_factor, self->polygon_offset_units);
}

int MGLContext_set_polygon_offset(MGLContext * self, PyObject * value) {
if (!PyTuple_CheckExact(value) || PyTuple_Size(value) != 2) {
return -1;
}
float polygon_offset_factor = (float)PyFloat_AsDouble(PyTuple_GetItem(value, 0));
float polygon_offset_units = (float)PyFloat_AsDouble(PyTuple_GetItem(value, 1));

const GLMethods & gl = self->gl;
gl.PolygonOffset(polygon_offset_factor, polygon_offset_units);
self->polygon_offset_factor = polygon_offset_factor;
self->polygon_offset_units = polygon_offset_units;
return 0;
}

PyObject * MGLContext_get_default_texture_unit(MGLContext * self) {
return PyLong_FromLong(self->default_texture_unit);
}
Expand Down Expand Up @@ -1419,6 +1437,7 @@ PyGetSetDef MGLContext_tp_getseters[] = {
{(char *)"multisample", (getter)MGLContext_get_multisample, (setter)MGLContext_set_multisample, 0, 0},

{(char *)"provoking_vertex", (getter)MGLContext_get_provoking_vertex, (setter)MGLContext_set_provoking_vertex, 0, 0},
{(char *)"polygon_offset", (getter)MGLContext_get_polygon_offset, (setter)MGLContext_set_polygon_offset, 0, 0},

{(char *)"default_texture_unit", (getter)MGLContext_get_default_texture_unit, (setter)MGLContext_set_default_texture_unit, 0, 0},
{(char *)"max_samples", (getter)MGLContext_get_max_samples, 0, 0, 0},
Expand Down
4 changes: 4 additions & 0 deletions moderngl/src/ModernGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ PyObject * create_context(PyObject * self, PyObject * args, PyObject * kwargs) {
ctx->multisample = true;

ctx->provoking_vertex = GL_LAST_VERTEX_CONVENTION;

ctx->polygon_offset_factor = 0.0f;
ctx->polygon_offset_units = 0.0f;

gl.GetError(); // clear errors

if (PyErr_Occurred()) {
Expand Down
3 changes: 3 additions & 0 deletions moderngl/src/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ struct MGLContext {

int provoking_vertex;

float polygon_offset_factor;
float polygon_offset_units;

GLMethods gl;
};

Expand Down

0 comments on commit 323e9e4

Please sign in to comment.