9
/* COGL Material handle */
12
pycogl_material_new (PyTypeObject *type, PyObject *args, PyObject *kwargs)
14
return pycogl_handle_from_handle (cogl_material_new ());
18
pycogl_material_set_color (PyCoglMaterial *self, PyObject *args)
23
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_color",
27
if (!pycogl_color_from_pyobject (py_color, &color))
30
cogl_material_set_color (self->handle, &color);
37
pycogl_material_get_color (PyCoglMaterial *self)
42
cogl_material_get_color (self->handle, &color);
43
py_ret = pyobject_from_cogl_color (&color);
49
pycogl_material_set_color4ub (PyCoglMaterial *self,
53
static char *kwlist[] = { "red", "green", "blue", "alpha", NULL };
54
guint8 red, green, blue, alpha;
55
red = green = blue = 0x0;
58
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
59
"|HHHH:cogl.Material.set_color4ub",
61
&red, &green, &blue, &alpha))
64
cogl_material_set_color4ub (self->handle, red, green, blue, alpha);
71
pycogl_material_set_color4f (PyCoglMaterial *self,
75
static char *kwlist[] = { "red", "green", "blue", "alpha", NULL };
76
float red, green, blue, alpha;
77
red = green = blue = 0.0;
80
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
81
"|ffff:cogl.Material.set_color4ub",
83
&red, &green, &blue, &alpha))
86
cogl_material_set_color4f (self->handle, red, green, blue, alpha);
93
pycogl_material_set_ambient (PyCoglMaterial *self, PyObject *args)
98
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_ambient",
102
if (!pycogl_color_from_pyobject (py_color, &color))
105
cogl_material_set_ambient (self->handle, &color);
112
pycogl_material_get_ambient (PyCoglMaterial *self)
117
cogl_material_get_ambient (self->handle, &color);
118
py_ret = pyobject_from_cogl_color (&color);
124
pycogl_material_set_diffuse (PyCoglMaterial *self, PyObject *args)
129
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_diffuse",
133
if (!pycogl_color_from_pyobject (py_color, &color))
136
cogl_material_set_diffuse (self->handle, &color);
143
pycogl_material_get_diffuse (PyCoglMaterial *self)
148
cogl_material_get_diffuse (self->handle, &color);
149
py_ret = pyobject_from_cogl_color (&color);
155
pycogl_material_set_ambient_and_diffuse (PyCoglMaterial *self, PyObject *args)
160
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_ambient",
164
if (!pycogl_color_from_pyobject (py_color, &color))
167
cogl_material_set_ambient_and_diffuse (self->handle, &color);
174
pycogl_material_set_emission (PyCoglMaterial *self, PyObject *args)
179
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_emission",
183
if (!pycogl_color_from_pyobject (py_color, &color))
186
cogl_material_set_emission (self->handle, &color);
193
pycogl_material_get_emission (PyCoglMaterial *self)
198
cogl_material_get_emission (self->handle, &color);
199
py_ret = pyobject_from_cogl_color (&color);
205
pycogl_material_set_specular (PyCoglMaterial *self, PyObject *args)
210
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_specular",
214
if (!pycogl_color_from_pyobject (py_color, &color))
217
cogl_material_set_specular (self->handle, &color);
224
pycogl_material_get_specular (PyCoglMaterial *self)
229
cogl_material_get_specular (self->handle, &color);
230
py_ret = pyobject_from_cogl_color (&color);
236
pycogl_material_set_shininess (PyCoglMaterial *self, PyObject *args)
239
if (!PyArg_ParseTuple (args, "f:cogl.Material.set_shininess",
243
cogl_material_set_shininess (self->handle, shininess);
250
pycogl_material_get_shininess (PyCoglMaterial *self)
252
return Py_BuildValue ("f", cogl_material_get_shininess (self->handle));
256
pycogl_material_set_alpha_test_function (PyCoglMaterial *self,
259
PyObject *py_alpha_func;
260
CoglMaterialAlphaFunc alpha_func;
261
float alpha_reference;
263
if (!PyArg_ParseTuple (args, "Of:cogl.Material.set_alpha_test_function",
264
&py_alpha_func, &alpha_reference))
267
if (pyg_enum_get_value (COGL_TYPE_MATERIAL_ALPHA_FUNC, py_alpha_func,
268
(gpointer)&alpha_func))
271
cogl_material_set_alpha_test_function (self->handle, alpha_func,
279
pycogl_material_set_blend (PyCoglMaterial *self, PyObject *args)
281
const char *blend_string;
282
GError *error = NULL;
285
if (!PyArg_ParseTuple (args, "s:cogl.Material.set_blend",
289
ret = cogl_material_set_blend (self->handle, blend_string, &error);
291
if (!ret && error != NULL)
293
PyErr_Format (PyExc_RuntimeError, " %s", error->message);
294
g_error_free (error);
298
return PyBool_FromLong (ret);
302
pycogl_material_set_blend_constant (PyCoglMaterial *self, PyObject *args)
307
if (!PyArg_ParseTuple (args, "O:cogl.Material.set_blend_constant",
311
if (!pycogl_color_from_pyobject (py_color, &color))
314
cogl_material_set_blend_constant (self->handle, &color);
321
pycogl_material_set_layer (PyCoglMaterial *self, PyObject *args)
324
PyCoglTexture *texture;
326
if (!PyArg_ParseTuple (args, "iO!:cogl.Material.set_layer",
327
&index, &PyCoglTexture_Type, &texture))
330
cogl_material_set_layer (self->handle, index, texture->handle);
337
pycogl_material_remove_layer (PyCoglMaterial *self, PyObject *args)
341
if (!PyArg_ParseTuple (args, "i:cogl.Material.remove_layer",
345
cogl_material_remove_layer (self->handle, index);
352
pycogl_material_set_layer_combine (PyCoglMaterial *self, PyObject *args)
355
const char *blend_string;
356
GError *error = NULL;
359
if (!PyArg_ParseTuple (args, "is:cogl.Material.set_layer_combine",
360
&index, &blend_string))
363
ret = cogl_material_set_layer_combine (self->handle, index, blend_string,
366
if (!ret && error != NULL)
368
PyErr_Format (PyExc_RuntimeError, " %s", error->message);
369
g_error_free (error);
373
return PyBool_FromLong (ret);
377
pycogl_material_set_layer_matrix (PyCoglMaterial *self, PyObject *args)
380
PyCoglMatrix *py_matrix;
382
if (!PyArg_ParseTuple (args, "iO!:cogl.Material.set_layer_matrix",
383
&index, &PyCoglMatrix_Type, &py_matrix))
386
cogl_material_set_layer_matrix (self->handle, index, &py_matrix->matrix);
393
pycogl_material_get_layers (PyCoglMaterial *self)
399
layers = cogl_material_get_layers (self->handle);
401
py_list = PyList_New (0);
403
for (l = (GList *)layers; l != NULL; l = l->next)
406
CoglHandle handle = l->data;
408
py_layer = pycogl_handle_from_handle (handle);
416
PyList_Append (py_list, py_layer);
423
pycogl_material_get_n_layers (PyCoglMaterial *self)
425
return Py_BuildValue ("i", cogl_material_get_n_layers (self->handle));
429
pycogl_material_set_layer_filters (PyCoglMaterial *self, PyObject *args)
432
PyObject *py_min_filter, *py_mag_filter;
433
CoglMaterialFilter min_filter, mag_filter;
435
if (!PyArg_ParseTuple (args, "iOO:cogl.Material.set_layer_filters",
436
&layer_index, &py_min_filter, &py_mag_filter))
439
if (pyg_enum_get_value (COGL_TYPE_MATERIAL_FILTER, py_min_filter,
440
(gpointer)&min_filter))
443
if (pyg_enum_get_value (COGL_TYPE_MATERIAL_FILTER, py_mag_filter,
444
(gpointer)&mag_filter))
447
cogl_material_set_layer_filters (self->handle, layer_index,
448
min_filter, mag_filter);
455
static PyMethodDef pycogl_material_methods[] = {
456
{ "set_color", (PyCFunction)pycogl_material_set_color, METH_VARARGS },
457
{ "get_color", (PyCFunction)pycogl_material_get_color, METH_NOARGS },
458
{ "set_color4ub", (PyCFunction)pycogl_material_set_color4ub, METH_VARARGS|METH_KEYWORDS },
459
{ "set_color4f", (PyCFunction)pycogl_material_set_color4f, METH_VARARGS|METH_KEYWORDS },
460
{ "set_ambient", (PyCFunction)pycogl_material_set_ambient, METH_VARARGS },
461
{ "get_ambient", (PyCFunction)pycogl_material_get_ambient, METH_NOARGS },
462
{ "set_diffuse", (PyCFunction)pycogl_material_set_diffuse, METH_VARARGS },
463
{ "get_diffuse", (PyCFunction)pycogl_material_get_diffuse, METH_NOARGS },
464
{ "set_ambient_and_diffuse", (PyCFunction)pycogl_material_set_ambient_and_diffuse, METH_VARARGS },
465
{ "set_emission", (PyCFunction)pycogl_material_set_emission, METH_VARARGS },
466
{ "get_emission", (PyCFunction)pycogl_material_get_emission, METH_NOARGS },
467
{ "set_specular", (PyCFunction)pycogl_material_set_specular, METH_VARARGS },
468
{ "get_specular", (PyCFunction)pycogl_material_get_specular, METH_NOARGS },
469
{ "set_shininess", (PyCFunction)pycogl_material_set_shininess, METH_VARARGS },
470
{ "get_shininess", (PyCFunction)pycogl_material_get_shininess, METH_NOARGS },
471
{ "set_alpha_test_function", (PyCFunction)pycogl_material_set_alpha_test_function, METH_VARARGS },
472
{ "set_blend", (PyCFunction)pycogl_material_set_blend, METH_VARARGS },
473
{ "set_blend_constant", (PyCFunction)pycogl_material_set_blend_constant, METH_VARARGS },
474
{ "set_layer", (PyCFunction)pycogl_material_set_layer, METH_VARARGS },
475
{ "remove_layer", (PyCFunction)pycogl_material_remove_layer, METH_VARARGS },
476
{ "set_layer_combine", (PyCFunction)pycogl_material_set_layer_combine, METH_VARARGS },
477
{ "set_layer_matrix", (PyCFunction)pycogl_material_set_layer_matrix, METH_VARARGS },
478
{ "get_layers", (PyCFunction)pycogl_material_get_layers, METH_NOARGS },
479
{ "get_n_layers", (PyCFunction)pycogl_material_get_n_layers, METH_NOARGS },
480
{ "set_layer_filters", (PyCFunction)pycogl_material_set_layer_filters, METH_VARARGS },
481
{ NULL, NULL, 0, NULL },
484
PyTypeObject PyCoglMaterial_Type = {
485
PyObject_HEAD_INIT(NULL)
487
"cogl.Material", /* tp_name */
488
sizeof(PyCoglMaterial), /* tp_basicsize */
490
(destructor)pycogl_handle_dealloc, /* tp_dealloc */
496
0, /* tp_as_number */
497
0, /* tp_as_sequence */
498
0, /* tp_as_mapping */
504
0, /* tp_as_buffer */
505
Py_TPFLAGS_DEFAULT, /* tp_flags */
509
0, /* tp_richcompare */
510
0, /* tp_weaklistoffset */
513
pycogl_material_methods, /* tp_methods */
516
0, /* &PyCoglHandle_Type, */ /* tp_base */
518
0, /* tp_descr_get */
519
0, /* tp_descr_set */
520
0, /* tp_dictoffset */
523
(newfunc)pycogl_material_new, /* tp_new */