diff --git a/docs/devinfo.html b/docs/devinfo.html index e068d87da13..f5113b0bd72 100644 --- a/docs/devinfo.html +++ b/docs/devinfo.html @@ -28,97 +28,118 @@
-Mesa's code style has changed over the years. Here's the latest. +Mesa is over 20 years old and the coding style has evolved over time. +Some old parts use a style that's a bit out of date. +If the guidelines below don't cover something, try following the format of +existing, neighboring code.
-Comment your code! It's extremely important that open-source code be -well documented. Also, strive to write clean, easily understandable code. +Basic formatting guidelines
--3-space indentation -
- --If you use tabs, set them to 8 columns -
- --Line width: the preferred width to fill comments and code in Mesa is 78 -columns. Exceptions are sometimes made for clarity (e.g. tabular data is -sometimes filled to a much larger width so that extraneous carriage returns -don't obscure the table). -
- --Brace example: -
+
- if (condition) {
- foo;
- }
- else {
- bar;
- }
-
- switch (condition) {
- case 0:
- foo();
- break;
-
- case 1: {
- ...
- break;
- }
-
- default:
- ...
- break;
- }
+ if (condition) {
+ foo;
+ } else {
+ bar;
+ }
--Here's the GNU indent command which will best approximate my preferred style: -(Note that it won't format switch statements in the preferred way) -
+- indent -br -i3 -npcs --no-tabs infile.c -o outfile.c + indent -br -i3 -npcs --no-tabs infile.c -o outfile.c- -
-Local variable name example: localVarName (no underscores) -
- --Constants and macros are ALL_UPPERCASE, with _ between words -
- --Global variables are not allowed. -
- --Function name examples: -
+- glFooBar() - a public GL entry point (in glapi_dispatch.c) - _mesa_FooBar() - the internal immediate mode function - save_FooBar() - retained mode (display list) function in dlist.c - foo_bar() - a static (private) function - _mesa_foo_bar() - an internal non-static Mesa function + /* null-out pointer to prevent dangling reference below */ + bufferObj = NULL; ++Or, +
+ bufferObj = NULL; /* prevent dangling reference below */ ++Multi-line comment: +
+ /* If this is a new buffer object id, or one which was generated but + * never used before, allocate a buffer object now. + */ ++We try to quote the OpenGL specification where prudent: +
+ /* Page 38 of the PDF of the OpenGL ES 3.0 spec says: + * + * "An INVALID_OPERATION error is generated for any of the following + * conditions: + * + * *+Function comment example: +is zero." + * + * Additionally, page 94 of the PDF of the OpenGL 4.5 core spec + * (30.10.2014) also says this, so it's no longer allowed for desktop GL, + * either. + */ +
+ /**
+ * Create and initialize a new buffer object. Called via the
+ * ctx->Driver.CreateObject() driver callback function.
+ * \param name integer name of the object
+ * \param type one of GL_FOO, GL_BAR, etc.
+ * \return pointer to new object or NULL if error
+ */
+ struct gl_object *
+ _mesa_create_object(GLuint name, GLenum type)
+ {
+ /* function body */
+ }
--Places that are not directly visible to the GL API should prefer the use -of bool, true, and +
grep ^function_name dir/* to find function definitions. Also,
+the opening brace goes on the next line by itself (see above.)
+
++ glFooBar() - a public GL entry point (in glapi_dispatch.c) + _mesa_FooBar() - the internal immediate mode function + save_FooBar() - retained mode (display list) function in dlist.c + foo_bar() - a static (private) function + _mesa_foo_bar() - an internal non-static Mesa function ++ +