Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/python/gpu/gpu_py_vertex_format.c
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/python/gpu/gpu_py_vertex_format.c')
-rw-r--r--source/blender/python/gpu/gpu_py_vertex_format.c316
1 files changed, 161 insertions, 155 deletions
diff --git a/source/blender/python/gpu/gpu_py_vertex_format.c b/source/blender/python/gpu/gpu_py_vertex_format.c
index 2cadbaf17ff..34df4cb1a4b 100644
--- a/source/blender/python/gpu/gpu_py_vertex_format.c
+++ b/source/blender/python/gpu/gpu_py_vertex_format.c
@@ -33,15 +33,15 @@
#include "gpu_py_vertex_format.h" /* own include */
#ifdef __BIG_ENDIAN__
- /* big endian */
-# define MAKE_ID2(c, d) ((c) << 8 | (d))
-# define MAKE_ID3(a, b, c) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 )
-# define MAKE_ID4(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) )
+/* big endian */
+# define MAKE_ID2(c, d) ((c) << 8 | (d))
+# define MAKE_ID3(a, b, c) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8)
+# define MAKE_ID4(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d))
#else
- /* little endian */
-# define MAKE_ID2(c, d) ((d) << 8 | (c))
-# define MAKE_ID3(a, b, c) ( (int)(c) << 16 | (b) << 8 | (a) )
-# define MAKE_ID4(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) )
+/* little endian */
+# define MAKE_ID2(c, d) ((d) << 8 | (c))
+# define MAKE_ID3(a, b, c) ((int)(c) << 16 | (b) << 8 | (a))
+# define MAKE_ID4(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
#endif
/* -------------------------------------------------------------------- */
@@ -52,205 +52,211 @@
static int bpygpu_parse_component_type(const char *str, int length)
{
- if (length == 2) {
- switch (*((ushort *)str)) {
- case MAKE_ID2('I', '8'): return GPU_COMP_I8;
- case MAKE_ID2('U', '8'): return GPU_COMP_U8;
- default: break;
- }
- }
- else if (length == 3) {
- switch (*((uint *)str)) {
- case MAKE_ID3('I', '1', '6'): return GPU_COMP_I16;
- case MAKE_ID3('U', '1', '6'): return GPU_COMP_U16;
- case MAKE_ID3('I', '3', '2'): return GPU_COMP_I32;
- case MAKE_ID3('U', '3', '2'): return GPU_COMP_U32;
- case MAKE_ID3('F', '3', '2'): return GPU_COMP_F32;
- case MAKE_ID3('I', '1', '0'): return GPU_COMP_I10;
- default: break;
- }
- }
- return -1;
+ if (length == 2) {
+ switch (*((ushort *)str)) {
+ case MAKE_ID2('I', '8'):
+ return GPU_COMP_I8;
+ case MAKE_ID2('U', '8'):
+ return GPU_COMP_U8;
+ default:
+ break;
+ }
+ }
+ else if (length == 3) {
+ switch (*((uint *)str)) {
+ case MAKE_ID3('I', '1', '6'):
+ return GPU_COMP_I16;
+ case MAKE_ID3('U', '1', '6'):
+ return GPU_COMP_U16;
+ case MAKE_ID3('I', '3', '2'):
+ return GPU_COMP_I32;
+ case MAKE_ID3('U', '3', '2'):
+ return GPU_COMP_U32;
+ case MAKE_ID3('F', '3', '2'):
+ return GPU_COMP_F32;
+ case MAKE_ID3('I', '1', '0'):
+ return GPU_COMP_I10;
+ default:
+ break;
+ }
+ }
+ return -1;
}
static int bpygpu_parse_fetch_mode(const char *str, int length)
{
#define MATCH_ID(id) \
- if (length == strlen(STRINGIFY(id))) { \
- if (STREQ(str, STRINGIFY(id))) { \
- return GPU_FETCH_##id; \
- } \
- } ((void)0)
-
- MATCH_ID(FLOAT);
- MATCH_ID(INT);
- MATCH_ID(INT_TO_FLOAT_UNIT);
- MATCH_ID(INT_TO_FLOAT);
+ if (length == strlen(STRINGIFY(id))) { \
+ if (STREQ(str, STRINGIFY(id))) { \
+ return GPU_FETCH_##id; \
+ } \
+ } \
+ ((void)0)
+
+ MATCH_ID(FLOAT);
+ MATCH_ID(INT);
+ MATCH_ID(INT_TO_FLOAT_UNIT);
+ MATCH_ID(INT_TO_FLOAT);
#undef MATCH_ID
- return -1;
+ return -1;
}
static int bpygpu_ParseVertCompType(PyObject *o, void *p)
{
- Py_ssize_t length;
- const char *str = _PyUnicode_AsStringAndSize(o, &length);
-
- if (str == NULL) {
- PyErr_Format(PyExc_ValueError,
- "expected a string, got %s",
- Py_TYPE(o)->tp_name);
- return 0;
- }
-
- int comp_type = bpygpu_parse_component_type(str, length);
- if (comp_type == -1) {
- PyErr_Format(PyExc_ValueError,
- "unkown component type: '%s",
- str);
- return 0;
- }
-
- *((GPUVertCompType *)p) = comp_type;
- return 1;
+ Py_ssize_t length;
+ const char *str = _PyUnicode_AsStringAndSize(o, &length);
+
+ if (str == NULL) {
+ PyErr_Format(PyExc_ValueError, "expected a string, got %s", Py_TYPE(o)->tp_name);
+ return 0;
+ }
+
+ int comp_type = bpygpu_parse_component_type(str, length);
+ if (comp_type == -1) {
+ PyErr_Format(PyExc_ValueError, "unkown component type: '%s", str);
+ return 0;
+ }
+
+ *((GPUVertCompType *)p) = comp_type;
+ return 1;
}
static int bpygpu_ParseVertFetchMode(PyObject *o, void *p)
{
- Py_ssize_t length;
- const char *str = _PyUnicode_AsStringAndSize(o, &length);
-
- if (str == NULL) {
- PyErr_Format(PyExc_ValueError,
- "expected a string, got %s",
- Py_TYPE(o)->tp_name);
- return 0;
- }
-
- int fetch_mode = bpygpu_parse_fetch_mode(str, length);
- if (fetch_mode == -1) {
- PyErr_Format(PyExc_ValueError,
- "unknown type literal: '%s'",
- str);
- return 0;
- }
-
- (*(GPUVertFetchMode *)p) = fetch_mode;
- return 1;
+ Py_ssize_t length;
+ const char *str = _PyUnicode_AsStringAndSize(o, &length);
+
+ if (str == NULL) {
+ PyErr_Format(PyExc_ValueError, "expected a string, got %s", Py_TYPE(o)->tp_name);
+ return 0;
+ }
+
+ int fetch_mode = bpygpu_parse_fetch_mode(str, length);
+ if (fetch_mode == -1) {
+ PyErr_Format(PyExc_ValueError, "unknown type literal: '%s'", str);
+ return 0;
+ }
+
+ (*(GPUVertFetchMode *)p) = fetch_mode;
+ return 1;
}
/** \} */
-
/* -------------------------------------------------------------------- */
/** \name VertFormat Type
* \{ */
static PyObject *bpygpu_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
{
- if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) {
- PyErr_SetString(PyExc_ValueError, "This function takes no arguments");
- return NULL;
- }
- return BPyGPUVertFormat_CreatePyObject(NULL);
+ if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) {
+ PyErr_SetString(PyExc_ValueError, "This function takes no arguments");
+ return NULL;
+ }
+ return BPyGPUVertFormat_CreatePyObject(NULL);
}
-PyDoc_STRVAR(bpygpu_VertFormat_attr_add_doc,
-".. method:: attr_add(id, comp_type, len, fetch_mode)\n"
-"\n"
-" Add a new attribute to the format.\n"
-"\n"
-" :param id: Name the attribute. Often `position`, `normal`, ...\n"
-" :type id: str\n"
-" :param comp_type: The data type that will be used store the value in memory.\n"
-" Possible values are `I8`, `U8`, `I16`, `U16`, `I32`, `U32`, `F32` and `I10`.\n"
-" :type comp_type: `str`\n"
-" :param len: How many individual values the attribute consists of (e.g. 2 for uv coordinates).\n"
-" :type len: int\n"
-" :param fetch_mode: How values from memory will be converted when used in the shader.\n"
-" This is mainly useful for memory optimizations when you want to store values with reduced precision.\n"
-" E.g. you can store a float in only 1 byte but it will be converted to a normal 4 byte float when used.\n"
-" Possible values are `FLOAT`, `INT`, `INT_TO_FLOAT_UNIT` and `INT_TO_FLOAT`.\n"
-" :type fetch_mode: `str`\n"
-);
+PyDoc_STRVAR(
+ bpygpu_VertFormat_attr_add_doc,
+ ".. method:: attr_add(id, comp_type, len, fetch_mode)\n"
+ "\n"
+ " Add a new attribute to the format.\n"
+ "\n"
+ " :param id: Name the attribute. Often `position`, `normal`, ...\n"
+ " :type id: str\n"
+ " :param comp_type: The data type that will be used store the value in memory.\n"
+ " Possible values are `I8`, `U8`, `I16`, `U16`, `I32`, `U32`, `F32` and `I10`.\n"
+ " :type comp_type: `str`\n"
+ " :param len: How many individual values the attribute consists of (e.g. 2 for uv "
+ "coordinates).\n"
+ " :type len: int\n"
+ " :param fetch_mode: How values from memory will be converted when used in the shader.\n"
+ " This is mainly useful for memory optimizations when you want to store values with "
+ "reduced precision.\n"
+ " E.g. you can store a float in only 1 byte but it will be converted to a normal 4 byte "
+ "float when used.\n"
+ " Possible values are `FLOAT`, `INT`, `INT_TO_FLOAT_UNIT` and `INT_TO_FLOAT`.\n"
+ " :type fetch_mode: `str`\n");
static PyObject *bpygpu_VertFormat_attr_add(BPyGPUVertFormat *self, PyObject *args, PyObject *kwds)
{
- struct {
- const char *id;
- GPUVertCompType comp_type;
- uint len;
- GPUVertFetchMode fetch_mode;
- } params;
-
- if (self->fmt.attr_len == GPU_VERT_ATTR_MAX_LEN) {
- PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GPU_VERT_ATTR_MAX_LEN));
- return NULL;
- }
-
- static const char *_keywords[] = {"id", "comp_type", "len", "fetch_mode", NULL};
- static _PyArg_Parser _parser = {"$sO&IO&:attr_add", _keywords, 0};
- if (!_PyArg_ParseTupleAndKeywordsFast(
- args, kwds, &_parser,
- &params.id,
- bpygpu_ParseVertCompType, &params.comp_type,
- &params.len,
- bpygpu_ParseVertFetchMode, &params.fetch_mode))
- {
- return NULL;
- }
-
- uint attr_id = GPU_vertformat_attr_add(&self->fmt, params.id, params.comp_type, params.len, params.fetch_mode);
- return PyLong_FromLong(attr_id);
+ struct {
+ const char *id;
+ GPUVertCompType comp_type;
+ uint len;
+ GPUVertFetchMode fetch_mode;
+ } params;
+
+ if (self->fmt.attr_len == GPU_VERT_ATTR_MAX_LEN) {
+ PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GPU_VERT_ATTR_MAX_LEN));
+ return NULL;
+ }
+
+ static const char *_keywords[] = {"id", "comp_type", "len", "fetch_mode", NULL};
+ static _PyArg_Parser _parser = {"$sO&IO&:attr_add", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(args,
+ kwds,
+ &_parser,
+ &params.id,
+ bpygpu_ParseVertCompType,
+ &params.comp_type,
+ &params.len,
+ bpygpu_ParseVertFetchMode,
+ &params.fetch_mode)) {
+ return NULL;
+ }
+
+ uint attr_id = GPU_vertformat_attr_add(
+ &self->fmt, params.id, params.comp_type, params.len, params.fetch_mode);
+ return PyLong_FromLong(attr_id);
}
static struct PyMethodDef bpygpu_VertFormat_methods[] = {
- {"attr_add", (PyCFunction)bpygpu_VertFormat_attr_add,
- METH_VARARGS | METH_KEYWORDS, bpygpu_VertFormat_attr_add_doc},
- {NULL, NULL, 0, NULL},
+ {"attr_add",
+ (PyCFunction)bpygpu_VertFormat_attr_add,
+ METH_VARARGS | METH_KEYWORDS,
+ bpygpu_VertFormat_attr_add_doc},
+ {NULL, NULL, 0, NULL},
};
-
static void bpygpu_VertFormat_dealloc(BPyGPUVertFormat *self)
{
- Py_TYPE(self)->tp_free(self);
+ Py_TYPE(self)->tp_free(self);
}
PyDoc_STRVAR(bpygpu_VertFormat_doc,
-".. class:: GPUVertFormat()\n"
-"\n"
-" This object contains information about the structure of a vertex buffer.\n"
-);
+ ".. class:: GPUVertFormat()\n"
+ "\n"
+ " This object contains information about the structure of a vertex buffer.\n");
PyTypeObject BPyGPUVertFormat_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "GPUVertFormat",
- .tp_basicsize = sizeof(BPyGPUVertFormat),
- .tp_dealloc = (destructor)bpygpu_VertFormat_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = bpygpu_VertFormat_doc,
- .tp_methods = bpygpu_VertFormat_methods,
- .tp_new = bpygpu_VertFormat_new,
+ PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUVertFormat",
+ .tp_basicsize = sizeof(BPyGPUVertFormat),
+ .tp_dealloc = (destructor)bpygpu_VertFormat_dealloc,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_doc = bpygpu_VertFormat_doc,
+ .tp_methods = bpygpu_VertFormat_methods,
+ .tp_new = bpygpu_VertFormat_new,
};
/** \} */
-
/* -------------------------------------------------------------------- */
/** \name Public API
* \{ */
PyObject *BPyGPUVertFormat_CreatePyObject(GPUVertFormat *fmt)
{
- BPyGPUVertFormat *self;
+ BPyGPUVertFormat *self;
- self = PyObject_New(BPyGPUVertFormat, &BPyGPUVertFormat_Type);
- if (fmt) {
- self->fmt = *fmt;
- }
- else {
- memset(&self->fmt, 0, sizeof(self->fmt));
- }
+ self = PyObject_New(BPyGPUVertFormat, &BPyGPUVertFormat_Type);
+ if (fmt) {
+ self->fmt = *fmt;
+ }
+ else {
+ memset(&self->fmt, 0, sizeof(self->fmt));
+ }
- return (PyObject *)self;
+ return (PyObject *)self;
}
/** \} */