Compare commits

...

22 Commits

Author SHA1 Message Date
753dd8f09a First commit to this branch
This branch is supposed to serve as a template and tutorial to
newcomers of the Blender codebase.
2019-03-03 16:46:26 +11:00
ae977d13f8 Improve slightly the stability of wireframes in old GPUs from AMD.
Tested on `AMD Radeon HD 7570M`.
The reason for crash reduction is still unknown.
2019-03-02 21:01:13 -03:00
52f318b914 Refactor duplicate code for collections.
* Fix incorrect handling of children collections being linked more than
once in the hierarchy (previous code would make a new copy for each
link, instead of just re-linking the first copy for each extra link).

* Simplify some aspects of it (we do not need a GHash for new objects,
we can use ID->newid pointer instead, and some iterations can be done
directly on existing linked lists of old collection, instead of making
temp local copies of them).

* Move all copy logic into a single private recursive function (it was a
bit odd/disturbing to see calling function being indirectly called again
by the recursive helper one - not wrong, but that kind of code path can
quickly become problematic in recursive patterns).

* Added some comments about expected behavior of
`BKE_collection_duplicate()` depending on its booleans options.
2019-03-02 22:00:34 +01:00
dcbc09e429 Cleanup: comma warning 2019-03-03 02:29:43 +11:00
f67e81e295 Cleanup: SDNA/DNA naming
Use 'size' instead of 'len' to represent the size of data in bytes,
'len' is used for the result of 'strlen' or the length of an array
in some parts of 'makesdna.c' & 'dna_genfile.c'.

Also clarify comments and some variable names, no functional changes.
2019-03-03 01:29:08 +11:00
dc858a048b GPencil: Set alpha to 1 for all materials in SOLID mode
To be consistent, the alpha must be set to 1 when solid mode is enabled.
2019-03-02 14:28:44 +01:00
de78ffca84 GPencil: Initialize Fill alpha to 1.0 by default for new materials 2019-03-02 14:15:56 +01:00
ba7656ad25 GPencil: Set Viewport color to black by default
As the 2D viewport color is white, if the object default color is white, when wireframe is enabled the object is invisible.

Now, the grease pencil object default viewport color is black.
2019-03-02 14:13:04 +01:00
cd9c1c10e8 GPencil: Fix Display Textures in Solid mode
There was a bug when selected Solid mode with Material or Texture mode. The textures were not visible.

Now, the mode is passed to shaders to decide if use the solid color or the result texture color. The mode is passed using an array with shading type and mode.
2019-03-02 13:59:18 +01:00
10d41e48b8 Fix BLI_mempool incorrect slop-space calculation
Also ensure elements fit evenly into the chunk size
causing allocations to be slightly smaller in some cases.

In own tests reduces overall memory use by about ~4.5%
for high poly meshes in edit-mode.
2019-03-02 20:31:31 +11:00
cf75aea218 Cleanup: code style & comments 2019-03-02 18:36:42 +11:00
e5b6020ffc Cleanup: remove unused define
There is no reason to keep the option for separate allocations,
it makes code harder to follow.
2019-03-02 18:36:42 +11:00
e72bbd3805 Revert accidental change in submodules from last commit
This reverts part of commit d5c2be7031.
2019-03-02 03:05:58 +01:00
d5c2be7031 CMake: Use static libstdc++ for static builds
This enables static linking of libstdc++ by default when building using
`WITH_STATIC_LIBS`. This makes builds more portable for anyone making
static builds (in particular for older systems).

Reviewed By: brecht, campbellbarton, sergey

Differential Revision: https://developer.blender.org/D4393
2019-03-02 02:53:09 +01:00
490a385c81 Cleanup: comments, assert align is a power of two 2019-03-02 11:57:39 +11:00
b5d87f8028 BLI_memarena: use ASAN memory poison
Detects invalid memory use when WITH_COMPILER_ASAN is enabled.
2019-03-02 11:50:44 +11:00
4d9bf4fc6c Cleanup: use dummy valgrind macros instead of ifdef's 2019-03-02 11:49:03 +11:00
5d9b50054c Cleanup: unused variable 2019-03-02 11:49:03 +11:00
84820e7f58 Revert "Fix T62098: Outliner: Delete hierarchy crash"
This reverts commit d1baed5e3d.

Next time please let original author of the buggy code to take care of
fixing the issue!
2019-03-01 23:04:47 +01:00
ccecc409e4 Fix T62098: Outliner: Delete hierarchy crash.
Stupid mistake in own logic would prevent first deleted ID to be
properly unlinked from rest of .blend file before its deletion...
2019-03-01 23:04:04 +01:00
e0458a3ead Fix drawing order messed up by rB005626b8c6b4
When annotations enabled, image borders were drawn around whole area instead around preview image.

Reviewed by: Brecht

Differential revision: https://developer.blender.org/D4430
2019-03-01 12:23:15 -08:00
Dalai Felinto
d1baed5e3d Fix T62098: Outliner: Delete hierarchy crash
Revert "Outliner: Enable new faster 'Delete Hierarchy' code by default."
This reverts commit 491a98ca44.

It fails in the most basic of tests (see report). No point in leaving
this commit around until it passes the easy to test cases.
2019-03-01 17:21:00 -03:00
33 changed files with 565 additions and 365 deletions

View File

@@ -39,6 +39,10 @@ if(EXISTS ${LIBDIR})
set(WITH_OPENMP_STATIC ON)
endif()
if(WITH_STATIC_LIBS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
endif()
# Wrapper to prefer static libraries
macro(find_package_wrapper)
if(WITH_STATIC_LIBS)

View File

@@ -1396,6 +1396,7 @@ class VIEW3D_MT_mesh_add(Menu):
layout.operator("mesh.primitive_plane_add", text="Plane", icon='MESH_PLANE')
layout.operator("mesh.primitive_cube_add", text="Cube", icon='MESH_CUBE')
layout.operator("mesh.primitive_wedge_add", text="Wedge", icon='MESH_DATA') # XXX, no icon
layout.operator("mesh.primitive_circle_add", text="Circle", icon='MESH_CIRCLE')
layout.operator("mesh.primitive_uv_sphere_add", text="UV Sphere", icon='MESH_UVSPHERE')
layout.operator("mesh.primitive_ico_sphere_add", text="Ico Sphere", icon='MESH_ICOSPHERE')

View File

@@ -209,84 +209,31 @@ void BKE_collection_copy_data(
}
}
static void collection_duplicate_recursive(Main *bmain, GHash *visited, Collection *collection, const int dupflag)
static Collection *collection_duplicate_recursive(
Main *bmain, Collection *parent, Collection *collection_old, const bool do_hierarchy, const bool do_deep_copy)
{
const bool is_first_run = (visited == NULL);
if (is_first_run) {
visited = BLI_ghash_ptr_new(__func__);
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
}
if (collection->id.tag & LIB_TAG_DOIT) {
return;
}
collection->id.tag |= LIB_TAG_DOIT;
ListBase collection_object_list = {NULL, NULL};
BLI_duplicatelist(&collection_object_list, &collection->gobject);
for (CollectionObject *cob = collection_object_list.first; cob; cob = cob->next) {
Object *ob_old = cob->ob;
Object *ob_new = NULL;
void **ob_key_p, **ob_value_p;
if (!BLI_ghash_ensure_p_ex(visited, ob_old, &ob_key_p, &ob_value_p)) {
ob_new = BKE_object_duplicate(bmain, ob_old, dupflag);
*ob_key_p = ob_old;
*ob_value_p = ob_new;
}
else {
ob_new = *ob_value_p;
}
collection_object_add(bmain, collection, ob_new, 0, true);
collection_object_remove(bmain, collection, ob_old, false);
}
BLI_freelistN(&collection_object_list);
ListBase collection_child_list = {NULL, NULL};
BLI_duplicatelist(&collection_child_list, &collection->children);
for (CollectionChild *child = collection_child_list.first; child; child = child->next) {
Collection *child_collection_old = child->collection;
Collection *child_collection_new = BKE_collection_copy(bmain, collection, child_collection_old);
collection_duplicate_recursive(bmain, visited, child_collection_new, dupflag);
collection_child_remove(collection, child_collection_old);
}
BLI_freelistN(&collection_child_list);
if (is_first_run) {
BLI_ghash_free(visited, NULL, NULL);
}
}
/**
* Makes a shallow copy of a Collection
*
* Add a new collection in the same level as the old one, link any nested collections
* and finally link the objects to the new collection (as oppose to copy them).
*/
Collection *BKE_collection_copy(Main *bmain, Collection *parent, Collection *collection)
{
return BKE_collection_duplicate(bmain, parent, collection, false, false);
}
Collection *BKE_collection_duplicate(Main *bmain, Collection *parent, Collection *collection, const bool do_hierarchy, const bool do_deep_copy)
{
/* It's not allowed to copy the master collection. */
if (collection->flag & COLLECTION_IS_MASTER) {
BLI_assert("!Master collection can't be duplicated");
return NULL;
}
Collection *collection_new;
BKE_id_copy(bmain, &collection->id, (ID **)&collection_new);
id_us_min(&collection_new->id); /* Copying add one user by default, need to get rid of that one. */
bool do_full_process = false;
const int object_dupflag = (do_deep_copy) ? U.dupflag : 0;
/* Optionally add to parent. */
if (parent) {
if (!do_hierarchy || collection_old->id.newid == NULL) {
BKE_id_copy(bmain, &collection_old->id, (ID **)&collection_new);
id_us_min(&collection_new->id); /* Copying add one user by default, need to get rid of that one. */
if (do_hierarchy) {
ID_NEW_SET(collection_old, collection_new);
}
do_full_process = true;
}
else {
collection_new = (Collection *)collection_old->id.newid;
}
/* Optionally add to parent (we always want to do that, even if collection_old had already been duplicated). */
if (parent != NULL) {
if (collection_child_add(parent, collection_new, 0, true)) {
/* Put collection right after existing one. */
CollectionChild *child = collection_find_child(parent, collection);
CollectionChild *child = collection_find_child(parent, collection_old);
CollectionChild *child_new = collection_find_child(parent, collection_new);
if (child && child_new) {
@@ -296,8 +243,80 @@ Collection *BKE_collection_duplicate(Main *bmain, Collection *parent, Collection
}
}
/* If we are not doing any kind of deep-copy, we can return immediately.
* False do_full_process means collection_old had already been duplicated, no need to redo some deep-copy on it. */
if (!do_hierarchy || !do_full_process) {
return collection_new;
}
/* We can loop on collection_old's objects, that list is currently identical the collection_new' objects,
* and won't be changed here. */
for (CollectionObject *cob = collection_old->gobject.first; cob; cob = cob->next) {
Object *ob_old = cob->ob;
Object *ob_new = (Object *)ob_old->id.newid;
if (ob_new == NULL) {
ob_new = BKE_object_duplicate(bmain, ob_old, object_dupflag);
ID_NEW_SET(ob_old, ob_new);
}
collection_object_add(bmain, collection_new, ob_new, 0, true);
collection_object_remove(bmain, collection_new, ob_old, false);
}
/* We can loop on collection_old's children, that list is currently identical the collection_new' children,
* and won't be changed here. */
for (CollectionChild *child = collection_old->children.first; child; child = child->next) {
Collection *child_collection_old = child->collection;
collection_duplicate_recursive(bmain, collection_new, child_collection_old, do_hierarchy, do_deep_copy);
collection_child_remove(collection_new, child_collection_old);
}
return collection_new;
}
/**
* Makes a standard (aka shallow) ID copy of a Collection.
*
* Add a new collection in the same level as the old one, link any nested collections
* and finally link the objects to the new collection (as opposed to copying them).
*/
Collection *BKE_collection_copy(Main *bmain, Collection *parent, Collection *collection)
{
return BKE_collection_duplicate(bmain, parent, collection, false, false);
}
/**
* Make either a shallow copy, or deeper duplicate of given collection.
*
* If \a do_hierarchy and \a do_deep_copy are false, this is a regular (shallow) ID copy.
*
* \warning If any 'deep copy' behavior is enabled, this functions will clear all \a bmain id.idnew pointers.
*
* \param do_hierarchy If true, it will recursively make shallow copies of children collections and objects.
* \param do_deep_copy If true, it will also make deep duplicates of objects, using behavior defined in user settings
* (U.dupflag). This one does nothing if \a do_hierarchy is not set.
*/
Collection *BKE_collection_duplicate(
Main *bmain, Collection *parent, Collection *collection, const bool do_hierarchy, const bool do_deep_copy)
{
/* It's not allowed to copy the master collection. */
if (collection->flag & COLLECTION_IS_MASTER) {
BLI_assert("!Master collection can't be duplicated");
return NULL;
}
if (do_hierarchy) {
collection_duplicate_recursive(bmain, NULL, collection_new, (do_deep_copy) ? U.dupflag : 0);
BKE_main_id_clear_newpoins(bmain);
}
Collection *collection_new = collection_duplicate_recursive(
bmain, parent, collection, do_hierarchy, do_deep_copy);
if (do_hierarchy) {
/* Cleanup. */
BKE_main_id_clear_newpoins(bmain);
}
BKE_main_collection_sync(bmain);

View File

@@ -956,6 +956,7 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion)
{
const int tag = LIB_TAG_DOIT;
ListBase *lbarray[MAX_LIBARRAY];
Link dummy_link = {0};
int base_count, i;
/* Used by batch tagged deletion, when we call BKE_id_free then, id is no more in Main database,
@@ -1000,11 +1001,8 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion)
}
}
if (last_remapped_id == NULL) {
last_remapped_id = tagged_deleted_ids.first;
if (last_remapped_id == NULL) {
BLI_assert(!keep_looping);
break;
}
dummy_link.next = tagged_deleted_ids.first;
last_remapped_id = (ID *)(&dummy_link);
}
for (id = last_remapped_id->next; id; id = id->next) {
/* Will tag 'never NULL' users of this ID too.

View File

@@ -112,6 +112,7 @@ void BKE_material_init_gpencil_settings(Material *ma)
MaterialGPencilStyle *gp_style = ma->gp_style;
/* set basic settings */
gp_style->stroke_rgba[3] = 1.0f;
gp_style->fill_rgba[3] = 1.0f;
gp_style->pattern_gridsize = 0.1f;
gp_style->gradient_radius = 0.5f;
ARRAY_SET_ITEMS(gp_style->mix_rgba, 1.0f, 1.0f, 1.0f, 0.2f);

View File

@@ -15,12 +15,11 @@
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
* Efficient memory allocation for lots of similar small chunks.
*/
/** \file
* \ingroup bli
* \brief Memory arena ADT.
* \brief Efficient memory allocation for many small chunks.
* \section aboutmemarena Memory Arena
*
* Memory arena's are commonly used when the program
@@ -41,6 +40,21 @@
#ifdef WITH_MEM_VALGRIND
# include "valgrind/memcheck.h"
#else
# define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) UNUSED_VARS(pool, rzB, is_zeroed)
# define VALGRIND_DESTROY_MEMPOOL(pool) UNUSED_VARS(pool)
# define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) UNUSED_VARS(pool, addr, size)
#endif
/* Clang defines this. */
#ifndef __has_feature
# define __has_feature(x) 0
#endif
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
# include "sanitizer/asan_interface.h"
#else
# define ASAN_POISON_MEMORY_REGION(addr, size) UNUSED_VARS(addr, size)
# define ASAN_UNPOISON_MEMORY_REGION(addr, size) UNUSED_VARS(addr, size)
#endif
struct MemBuf {
@@ -75,9 +89,7 @@ MemArena *BLI_memarena_new(const size_t bufsize, const char *name)
ma->align = 8;
ma->name = name;
#ifdef WITH_MEM_VALGRIND
VALGRIND_CREATE_MEMPOOL(ma, 0, false);
#endif
return ma;
}
@@ -94,24 +106,25 @@ void BLI_memarena_use_malloc(MemArena *ma)
void BLI_memarena_use_align(struct MemArena *ma, const size_t align)
{
/* align should be a power of two */
/* Align must be a power of two. */
BLI_assert((align & (align - 1)) == 0);
ma->align = align;
}
void BLI_memarena_free(MemArena *ma)
{
memarena_buf_free_all(ma->bufs);
#ifdef WITH_MEM_VALGRIND
VALGRIND_DESTROY_MEMPOOL(ma);
#endif
MEM_freeN(ma);
}
/* amt must be power of two */
/** Pad num up by \a amt (must be power of two). */
#define PADUP(num, amt) (((num) + ((amt) - 1)) & ~((amt) - 1))
/* align alloc'ed memory (needed if align > 8) */
/** Align alloc'ed memory (needed if `align > 8`). */
static void memarena_curbuf_align(MemArena *ma)
{
unsigned char *tmp;
@@ -125,8 +138,7 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
{
void *ptr;
/* ensure proper alignment by rounding
* size up to multiple of 8 */
/* Ensure proper alignment by rounding size up to multiple of 8. */
size = PADUP(size, ma->align);
if (UNLIKELY(size > ma->cursize)) {
@@ -142,6 +154,8 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
mb->next = ma->bufs;
ma->bufs = mb;
ASAN_POISON_MEMORY_REGION(ma->curbuf, ma->cursize);
memarena_curbuf_align(ma);
}
@@ -149,9 +163,9 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
ma->curbuf += size;
ma->cursize -= size;
#ifdef WITH_MEM_VALGRIND
VALGRIND_MEMPOOL_ALLOC(ma, ptr, size);
#endif
ASAN_UNPOISON_MEMORY_REGION(ptr, size);
return ptr;
}
@@ -160,7 +174,7 @@ void *BLI_memarena_calloc(MemArena *ma, size_t size)
{
void *ptr;
/* no need to use this function call if we're calloc'ing by default */
/* No need to use this function call if we're calloc'ing by default. */
BLI_assert(ma->use_calloc == false);
ptr = BLI_memarena_alloc(ma, size);
@@ -195,11 +209,9 @@ void BLI_memarena_clear(MemArena *ma)
if (ma->use_calloc) {
memset(ma->curbuf, 0, curbuf_used);
}
ASAN_POISON_MEMORY_REGION(ma->curbuf, ma->cursize);
}
#ifdef WITH_MEM_VALGRIND
VALGRIND_DESTROY_MEMPOOL(ma);
VALGRIND_CREATE_MEMPOOL(ma, 0, false);
#endif
}

View File

@@ -78,9 +78,6 @@
/* currently totalloc isnt used */
// #define USE_TOTALLOC
/* when undefined, merge the allocs for BLI_mempool_chunk and its data */
// #define USE_DATA_PTR
/* optimize pool size */
#define USE_CHUNK_POW2
@@ -97,7 +94,8 @@ static bool mempool_debug_memset = false;
*/
typedef struct BLI_freenode {
struct BLI_freenode *next;
intptr_t freeword; /* used to identify this as a freed node */
/** Used to identify this as a freed node. */
intptr_t freeword;
} BLI_freenode;
/**
@@ -106,51 +104,48 @@ typedef struct BLI_freenode {
*/
typedef struct BLI_mempool_chunk {
struct BLI_mempool_chunk *next;
#ifdef USE_DATA_PTR
void *_data;
#endif
} BLI_mempool_chunk;
/**
* The mempool, stores and tracks memory \a chunks and elements within those chunks \a free.
*/
struct BLI_mempool {
BLI_mempool_chunk *chunks; /* single linked list of allocated chunks */
/* keep a pointer to the last, so we can append new chunks there
* this is needed for iteration so we can loop over chunks in the order added */
/** Single linked list of allocated chunks. */
BLI_mempool_chunk *chunks;
/** Keep a pointer to the last, so we can append new chunks there
* this is needed for iteration so we can loop over chunks in the order added. */
BLI_mempool_chunk *chunk_tail;
uint esize; /* element size in bytes */
uint csize; /* chunk size in bytes */
uint pchunk; /* number of elements per chunk */
/** Element size in bytes. */
uint esize;
/** Chunk size in bytes. */
uint csize;
/** Number of elements per chunk. */
uint pchunk;
uint flag;
/* keeps aligned to 16 bits */
BLI_freenode *free; /* free element list. Interleaved into chunk datas. */
uint maxchunks; /* use to know how many chunks to keep for BLI_mempool_clear */
uint totused; /* number of elements currently in use */
/** Free element list. Interleaved into chunk datas. */
BLI_freenode *free;
/** Use to know how many chunks to keep for #BLI_mempool_clear. */
uint maxchunks;
/** Number of elements currently in use. */
uint totused;
#ifdef USE_TOTALLOC
uint totalloc; /* number of elements allocated in total */
/** Number of elements allocated in total. */
uint totalloc;
#endif
};
#define MEMPOOL_ELEM_SIZE_MIN (sizeof(void *) * 2)
#ifdef USE_DATA_PTR
# define CHUNK_DATA(chunk) (chunk)->_data
#else
# define CHUNK_DATA(chunk) (CHECK_TYPE_INLINE(chunk, BLI_mempool_chunk *), (void *)((chunk) + 1))
#endif
#define CHUNK_DATA(chunk) (CHECK_TYPE_INLINE(chunk, BLI_mempool_chunk *), (void *)((chunk) + 1))
#define NODE_STEP_NEXT(node) ((void *)((char *)(node) + esize))
#define NODE_STEP_PREV(node) ((void *)((char *)(node) - esize))
/* extra bytes implicitly used for every chunk alloc */
#ifdef USE_DATA_PTR
# define CHUNK_OVERHEAD (uint)(MEM_SIZE_OVERHEAD + sizeof(BLI_mempool_chunk))
#else
# define CHUNK_OVERHEAD (uint)(MEM_SIZE_OVERHEAD)
#endif
/** Extra bytes implicitly used for every chunk alloc. */
#define CHUNK_OVERHEAD (uint)(MEM_SIZE_OVERHEAD + sizeof(BLI_mempool_chunk))
#ifdef USE_CHUNK_POW2
static uint power_of_2_max_u(uint x)
@@ -186,15 +181,7 @@ BLI_INLINE uint mempool_maxchunks(const uint totelem, const uint pchunk)
static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool)
{
BLI_mempool_chunk *mpchunk;
#ifdef USE_DATA_PTR
mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
CHUNK_DATA(mpchunk) = MEM_mallocN((size_t)pool->csize, "BLI Mempool Chunk Data");
#else
mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk) + (size_t)pool->csize, "BLI_Mempool Chunk");
#endif
return mpchunk;
return MEM_mallocN(sizeof(BLI_mempool_chunk) + (size_t)pool->csize, "BLI_Mempool Chunk");
}
/**
@@ -202,12 +189,13 @@ static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool)
*
* \param pool: The pool to add the chunk into.
* \param mpchunk: The new uninitialized chunk (can be malloc'd)
* \param lasttail: The last element of the previous chunk
* \param last_tail: The last element of the previous chunk
* (used when building free chunks initially)
* \return The last chunk,
*/
static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpchunk,
BLI_freenode *lasttail)
static BLI_freenode *mempool_chunk_add(
BLI_mempool *pool, BLI_mempool_chunk *mpchunk,
BLI_freenode *last_tail)
{
const uint esize = pool->esize;
BLI_freenode *curnode = CHUNK_DATA(mpchunk);
@@ -246,7 +234,7 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
}
/* terminate the list (rewind one)
* will be overwritten if 'curnode' gets passed in again as 'lasttail' */
* will be overwritten if 'curnode' gets passed in again as 'last_tail' */
curnode = NODE_STEP_PREV(curnode);
curnode->next = NULL;
@@ -255,8 +243,8 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
#endif
/* final pointer in the previously allocated chunk is wrong */
if (lasttail) {
lasttail->next = CHUNK_DATA(mpchunk);
if (last_tail) {
last_tail->next = CHUNK_DATA(mpchunk);
}
return curnode;
@@ -264,10 +252,6 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
static void mempool_chunk_free(BLI_mempool_chunk *mpchunk)
{
#ifdef USE_DATA_PTR
MEM_freeN(CHUNK_DATA(mpchunk));
#endif
MEM_freeN(mpchunk);
}
@@ -281,11 +265,12 @@ static void mempool_chunk_free_all(BLI_mempool_chunk *mpchunk)
}
}
BLI_mempool *BLI_mempool_create(uint esize, uint totelem,
uint pchunk, uint flag)
BLI_mempool *BLI_mempool_create(
uint esize, uint totelem,
uint pchunk, uint flag)
{
BLI_mempool *pool;
BLI_freenode *lasttail = NULL;
BLI_freenode *last_tail = NULL;
uint i, maxchunks;
/* allocate the pool structure */
@@ -305,18 +290,24 @@ BLI_mempool *BLI_mempool_create(uint esize, uint totelem,
pool->chunks = NULL;
pool->chunk_tail = NULL;
pool->esize = esize;
pool->csize = esize * pchunk;
/* Optimize chunk size to powers of 2, accounting for slop-space */
/* Optimize chunk size to powers of 2, accounting for slop-space. */
#ifdef USE_CHUNK_POW2
{
BLI_assert(pool->csize > CHUNK_OVERHEAD);
pool->csize = power_of_2_max_u(pool->csize) - CHUNK_OVERHEAD;
pchunk = pool->csize / esize;
BLI_assert(power_of_2_max_u(pchunk * esize) > CHUNK_OVERHEAD);
pchunk = (power_of_2_max_u(pchunk * esize) - CHUNK_OVERHEAD) / esize;
}
#endif
pool->csize = esize * pchunk;
/* Ensure this is a power of 2, minus the rounding by element size. */
#ifdef USE_CHUNK_POW2
{
uint final_size = (uint)MEM_SIZE_OVERHEAD + (uint)sizeof(BLI_mempool_chunk) + pool->csize;
BLI_assert(((uint)power_of_2_max_u(final_size) - final_size) < pool->esize);
}
#endif
pool->pchunk = pchunk;
pool->flag = flag;
@@ -328,10 +319,10 @@ BLI_mempool *BLI_mempool_create(uint esize, uint totelem,
pool->totused = 0;
if (totelem) {
/* allocate the actual chunks */
/* Allocate the actual chunks. */
for (i = 0; i < maxchunks; i++) {
BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool);
lasttail = mempool_chunk_add(pool, mpchunk, lasttail);
last_tail = mempool_chunk_add(pool, mpchunk, last_tail);
}
}
@@ -347,7 +338,7 @@ void *BLI_mempool_alloc(BLI_mempool *pool)
BLI_freenode *free_pop;
if (UNLIKELY(pool->free == NULL)) {
/* need to allocate a new chunk */
/* Need to allocate a new chunk. */
BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool);
mempool_chunk_add(pool, mpchunk, NULL);
}
@@ -401,7 +392,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
}
}
/* enable for debugging */
/* Enable for debugging. */
if (UNLIKELY(mempool_debug_memset)) {
memset(addr, 255, pool->esize);
}
@@ -409,7 +400,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
#ifndef NDEBUG
/* this will detect double free's */
/* This will detect double free's. */
BLI_assert(newhead->freeword != FREEWORD);
#endif
newhead->freeword = FREEWORD;
@@ -424,7 +415,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
VALGRIND_MEMPOOL_FREE(pool, addr);
#endif
/* nothing is in use; free all the chunks except the first */
/* Nothing is in use; free all the chunks except the first. */
if (UNLIKELY(pool->totused == 0) &&
(pool->chunks->next))
{
@@ -442,7 +433,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
pool->totalloc = pool->pchunk;
#endif
/* temp alloc so valgrind doesn't complain when setting free'd blocks 'next' */
/* Temp alloc so valgrind doesn't complain when setting free'd blocks 'next'. */
#ifdef WITH_MEM_VALGRIND
VALGRIND_MEMPOOL_ALLOC(pool, CHUNK_DATA(first), pool->csize);
#endif
@@ -474,12 +465,12 @@ void *BLI_mempool_findelem(BLI_mempool *pool, uint index)
BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
if (index < pool->totused) {
/* we could have some faster mem chunk stepping code inline */
/* We could have some faster mem chunk stepping code inline. */
BLI_mempool_iter iter;
void *elem;
BLI_mempool_iternew(pool, &iter);
for (elem = BLI_mempool_iterstep(&iter); index-- != 0; elem = BLI_mempool_iterstep(&iter)) {
/* do nothing */
/* pass */
}
return elem;
}
@@ -545,7 +536,7 @@ void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr)
}
/**
* Initialize a new mempool iterator, \a BLI_MEMPOOL_ALLOW_ITER flag must be set.
* Initialize a new mempool iterator, #BLI_MEMPOOL_ALLOW_ITER flag must be set.
*/
void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
{
@@ -559,7 +550,7 @@ void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
}
/**
* Initialize an array of mempool iterators, \a BLI_MEMPOOL_ALLOW_ITER flag must be set.
* Initialize an array of mempool iterators, #BLI_MEMPOOL_ALLOW_ITER flag must be set.
*
* This is used in threaded code, to generate as much iterators as needed (each task should have its own),
* such that each iterator goes over its own single chunk, and only getting the next chunk to iterate over has to be
@@ -583,7 +574,8 @@ BLI_mempool_iter *BLI_mempool_iter_threadsafe_create(BLI_mempool *pool, const si
for (size_t i = 1; i < num_iter; i++) {
iter_arr[i] = iter_arr[0];
*curchunk_threaded_shared = iter_arr[i].curchunk = (*curchunk_threaded_shared) ? (*curchunk_threaded_shared)->next : NULL;
*curchunk_threaded_shared = iter_arr[i].curchunk = (
(*curchunk_threaded_shared) ? (*curchunk_threaded_shared)->next : NULL);
}
return iter_arr;
@@ -620,7 +612,11 @@ static void *bli_mempool_iternext(BLI_mempool_iter *iter)
if (iter->curchunk == NULL) {
return ret;
}
if (atomic_cas_ptr((void **)iter->curchunk_threaded_shared, iter->curchunk, iter->curchunk->next) == iter->curchunk) {
if (atomic_cas_ptr(
(void **)iter->curchunk_threaded_shared,
iter->curchunk,
iter->curchunk->next) == iter->curchunk)
{
break;
}
}
@@ -669,8 +665,14 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
if (iter->curchunk_threaded_shared) {
for (iter->curchunk = *iter->curchunk_threaded_shared;
(iter->curchunk != NULL) &&
(atomic_cas_ptr((void **)iter->curchunk_threaded_shared, iter->curchunk, iter->curchunk->next) != iter->curchunk);
iter->curchunk = *iter->curchunk_threaded_shared);
(atomic_cas_ptr(
(void **)iter->curchunk_threaded_shared,
iter->curchunk,
iter->curchunk->next) != iter->curchunk);
iter->curchunk = *iter->curchunk_threaded_shared)
{
/* pass. */
}
if (UNLIKELY(iter->curchunk == NULL)) {
return (ret->freeword == FREEWORD) ? NULL : ret;
@@ -702,7 +704,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
uint maxchunks;
BLI_mempool_chunk *chunks_temp;
BLI_freenode *lasttail = NULL;
BLI_freenode *last_tail = NULL;
#ifdef WITH_MEM_VALGRIND
VALGRIND_DESTROY_MEMPOOL(pool);
@@ -716,7 +718,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
maxchunks = mempool_maxchunks((uint)totelem_reserve, pool->pchunk);
}
/* free all after pool->maxchunks */
/* Free all after 'pool->maxchunks'. */
mpchunk = mempool_chunk_find(pool->chunks, maxchunks - 1);
if (mpchunk && mpchunk->next) {
/* terminate */
@@ -743,7 +745,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
while ((mpchunk = chunks_temp)) {
chunks_temp = mpchunk->next;
lasttail = mempool_chunk_add(pool, mpchunk, lasttail);
last_tail = mempool_chunk_add(pool, mpchunk, last_tail);
}
}

View File

@@ -2118,7 +2118,7 @@ static void switch_endian_structs(const struct SDNA *filesdna, BHead *bhead)
char *data;
data = (char *)(bhead + 1);
blocksize = filesdna->typelens[filesdna->structs[bhead->SDNAnr][0]];
blocksize = filesdna->types_size[filesdna->structs[bhead->SDNAnr][0]];
nblocks = bhead->nr;
while (nblocks--) {
@@ -2264,9 +2264,9 @@ static void test_pointer_array(FileData *fd, void **mat)
* the new dna format.
*/
if (*mat) {
len = MEM_allocN_len(*mat) / fd->filesdna->pointerlen;
len = MEM_allocN_len(*mat) / fd->filesdna->pointer_size;
if (fd->filesdna->pointerlen == 8 && fd->memsdna->pointerlen == 4) {
if (fd->filesdna->pointer_size == 8 && fd->memsdna->pointer_size == 4) {
ipoin = imat = MEM_malloc_arrayN(len, 4, "newmatar");
lpoin = *mat;
@@ -2281,7 +2281,7 @@ static void test_pointer_array(FileData *fd, void **mat)
*mat = imat;
}
if (fd->filesdna->pointerlen == 4 && fd->memsdna->pointerlen == 8) {
if (fd->filesdna->pointer_size == 4 && fd->memsdna->pointer_size == 8) {
lpoin = lmat = MEM_malloc_arrayN(len, 8, "newmatar");
ipoin = *mat;

View File

@@ -531,7 +531,7 @@ static void writestruct_at_address_nr(
bh.SDNAnr = struct_nr;
sp = wd->sdna->structs[bh.SDNAnr];
bh.len = nr * wd->sdna->typelens[sp[0]];
bh.len = nr * wd->sdna->types_size[sp[0]];
if (bh.len == 0) {
return;
@@ -4047,7 +4047,7 @@ static bool write_file_handle(
*
* Note that we *borrow* the pointer to 'DNAstr',
* so writing each time uses the same address and doesn't cause unnecessary undo overhead. */
writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data);
writedata(wd, DNA1, wd->sdna->data_len, wd->sdna->data);
#ifdef USE_NODE_COMPAT_CUSTOMNODES
/* compatibility data not created on undo */

View File

@@ -1720,6 +1720,27 @@ static BMOpDefine bmo_create_cube_def = {
BMO_OPTYPE_FLAG_SELECT_FLUSH),
};
/*
*Create Wedge
*
* Creates a wedge.
*/
static BMOpDefine bmo_create_wedge_def = {
"create_wedge",
/* slots_in */
{{"size", BMO_OP_SLOT_FLT}, /* size of the wedge */
{"matrix", BMO_OP_SLOT_MAT}, /* matrix to multiply the new geometry with */
{{'\0'}},
},
/* slots_out */
{{"verts.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT}}, /* output verts */
{{'\0'}},
},
bmo_create_wedge_exec,
(BMO_OPTYPE_FLAG_NORMALS_CALC |
BMO_OPTYPE_FLAG_SELECT_FLUSH),
};
static BMO_FlagSet bmo_enum_bevel_offset_type[] = {
{BEVEL_AMT_OFFSET, "OFFSET"},
{BEVEL_AMT_WIDTH, "WIDTH"},
@@ -2087,6 +2108,7 @@ const BMOpDefine *bmo_opdefines[] = {
&bmo_create_circle_def,
&bmo_create_cone_def,
&bmo_create_cube_def,
&bmo_create_wedge_def,
&bmo_create_grid_def,
&bmo_create_icosphere_def,
&bmo_create_monkey_def,

View File

@@ -43,6 +43,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op);
void bmo_create_circle_exec(BMesh *bm, BMOperator *op);
void bmo_create_cone_exec(BMesh *bm, BMOperator *op);
void bmo_create_cube_exec(BMesh *bm, BMOperator *op);
void bmo_create_wedge_exec(BMesh *bm, BMOperator *op);
void bmo_create_grid_exec(BMesh *bm, BMOperator *op);
void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op);
void bmo_create_monkey_exec(BMesh *bm, BMOperator *op);

View File

@@ -1684,6 +1684,69 @@ void bmo_create_cube_exec(BMesh *bm, BMOperator *op)
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "verts.out", BM_VERT, VERT_MARK);
}
void bmo_create_wedge_exec(BMesh *bm, BMOperator *op)
{
BMVert * v1, *v2, *v3, *v4, *v5, *v6;
float vec[3], mat[4][4], off = BMO_slot_float_get(op->slots_in, "size") / 2.0f;
BMO_slot_mat4_get(op->slots_in, "matrix", mat);
if (!off) off = 0.5f;
vec[0] = off;
vec[1] = off;
vec[2] = -off;
mul_m4_v3(mat, vec);
v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP);
BMO_elem_flag_enable(bm, v1, VERT_MARK);
vec[0] = off;
vec[1] = -off;
vec[2] = -off;
mul_m4_v3(mat, vec);
v2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP);
BMO_elem_flag_enable(bm, v2, VERT_MARK);
vec[0] = -off;
vec[1] = -off;
vec[2] = off;
mul_m4_v3(mat, vec);
v3 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP);
BMO_elem_flag_enable(bm, v3, VERT_MARK);
vec[0] = -off;
vec[1] = off;
vec[2] = off;
mul_m4_v3(mat, vec);
v4 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP);
BMO_elem_flag_enable(bm, v4, VERT_MARK);
vec[0] = off;
vec[1] = off;
vec[2] = off;
mul_m4_v3(mat, vec);
v5 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP);
BMO_elem_flag_enable(bm, v5, VERT_MARK);
vec[0] = off;
vec[1] = -off;
vec[2] = off;
mul_m4_v3(mat, vec);
v6 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP);
BMO_elem_flag_enable(bm, v6, VERT_MARK);
/* the four sides */
BM_face_create_quad_tri(bm, v3, v4, v1, v2, NULL, false);
BM_face_create_quad_tri(bm, v4, v5, v1, NULL, NULL, false);
BM_face_create_quad_tri(bm, v5, v6, v2, v1, NULL, false);
BM_face_create_quad_tri(bm, v6, v3, v2, NULL, NULL, false);
/* top */
BM_face_create_quad_tri(bm, v6, v5, v4, v3, NULL, false);
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "verts.out", BM_VERT, VERT_MARK);
}
/**
* Fills first available UVmap with cube-like UVs for all faces OpFlag-ged by given flag.
*

View File

@@ -85,11 +85,11 @@ tGPencilObjectCache *gpencil_object_cache_add(
/* save wire mode (object mode is always primary option) */
if (ob->dt == OB_WIRE) {
cache_elem->shading_type = (int)OB_WIRE;
cache_elem->shading_type[0] = (int)OB_WIRE;
}
else {
if (v3d) {
cache_elem->shading_type = (int)v3d->shading.type;
cache_elem->shading_type[0] = (int)v3d->shading.type;
}
}

View File

@@ -268,11 +268,11 @@ static void set_wireframe_color(Object *ob, bGPDlayer *gpl, View3D *v3d,
/* wire color */
if ((v3d) && (id > -1)) {
const char type = (stl->shgroups[id].shading_type == OB_WIRE) ?
const char type = (stl->shgroups[id].shading_type[0] == OB_WIRE) ?
v3d->shading.wire_color_type :
v3d->shading.color_type;
/* if fill and wire, use background color */
if ((is_fill) && (stl->shgroups[id].shading_type == OB_WIRE)) {
if ((is_fill) && (stl->shgroups[id].shading_type[0] == OB_WIRE)) {
if (v3d->shading.background_type == V3D_SHADING_BACKGROUND_THEME) {
UI_GetThemeColor4fv(TH_BACK, stl->shgroups[id].wire_color);
stl->shgroups[id].wire_color[3] = 1.0f;
@@ -296,7 +296,7 @@ static void set_wireframe_color(Object *ob, bGPDlayer *gpl, View3D *v3d,
switch (type) {
case V3D_SHADING_SINGLE_COLOR:
{
if (stl->shgroups[id].shading_type == OB_WIRE) {
if (stl->shgroups[id].shading_type[0] == OB_WIRE) {
UI_GetThemeColor4fv(TH_WIRE, color);
}
else {
@@ -342,13 +342,18 @@ static void set_wireframe_color(Object *ob, bGPDlayer *gpl, View3D *v3d,
else {
copy_v4_v4(stl->shgroups[id].wire_color, color);
}
/* if solid, the alpha must be set to 1.0 */
if (stl->shgroups[id].shading_type[0] == OB_SOLID) {
stl->shgroups[id].wire_color[3] = 1.0f;
}
}
/* create shading group for filling */
static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass,
GPUShader *shader, Object *ob, bGPdata *gpd, bGPDlayer *gpl,
MaterialGPencilStyle *gp_style, int id, int shading_type)
MaterialGPencilStyle *gp_style, int id, int shading_type[2])
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -416,8 +421,14 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
/* shading type */
stl->shgroups[id].shading_type = GPENCIL_USE_SOLID(stl) ? (int)OB_RENDER : shading_type;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
stl->shgroups[id].shading_type[0] = GPENCIL_USE_SOLID(stl) ? (int)OB_RENDER : shading_type[0];
if (v3d) {
stl->shgroups[id].shading_type[1] = (stl->shgroups[id].shading_type[0] == OB_WIRE) ?
v3d->shading.wire_color_type :
v3d->shading.color_type;
}
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, true);
@@ -475,7 +486,7 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
bGPdata *gpd, bGPDlayer *gpl, bGPDstroke *gps,
MaterialGPencilStyle *gp_style, int id,
bool onion, const float scale, int shading_type)
bool onion, const float scale, const int shading_type[2])
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const float *viewport_size = DRW_viewport_size_get();
@@ -519,8 +530,13 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_RENDER : shading_type;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
stl->shgroups[id].shading_type[0] = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_RENDER : shading_type[0];
if (v3d) {
stl->shgroups[id].shading_type[1] = (stl->shgroups[id].shading_type[0] == OB_WIRE) ?
v3d->shading.wire_color_type :
v3d->shading.color_type;
}
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
@@ -545,8 +561,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (int)OB_RENDER;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
stl->shgroups[id].shading_type[0] = (int)OB_RENDER;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
}
if ((gpd) && (id > -1)) {
@@ -591,7 +607,7 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
bGPdata *gpd, bGPDlayer *gpl,
MaterialGPencilStyle *gp_style, int id, bool onion,
const float scale, int shading_type)
const float scale, const int shading_type[2])
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const float *viewport_size = DRW_viewport_size_get();
@@ -632,8 +648,13 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_RENDER : shading_type;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
stl->shgroups[id].shading_type[0] = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_RENDER : shading_type[0];
if (v3d) {
stl->shgroups[id].shading_type[1] = (stl->shgroups[id].shading_type[0] == OB_WIRE) ?
v3d->shading.wire_color_type :
v3d->shading.color_type;
}
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
@@ -658,8 +679,8 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (int)OB_RENDER;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
stl->shgroups[id].shading_type[0] = (int)OB_RENDER;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
}
if (gpd) {
@@ -1318,7 +1339,7 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
bGPdata *gpd = (bGPdata *)DEG_get_original_id(&gpd_eval->id);
MaterialGPencilStyle *gp_style = NULL;
const int shade_render[2] = { OB_RENDER, 0 };
float obscale = mat4_to_scale(ob->obmat);
/* use the brush material */
@@ -1346,12 +1367,12 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
if ((gp_style) && (gp_style->mode == GP_STYLE_MODE_LINE)) {
stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(
e_data, vedata, psl->drawing_pass, e_data->gpencil_stroke_sh, NULL,
gpd, NULL, NULL, gp_style, -1, false, 1.0f, (int)OB_RENDER);
gpd, NULL, NULL, gp_style, -1, false, 1.0f, shade_render);
}
else {
stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_point_create(
e_data, vedata, psl->drawing_pass, e_data->gpencil_point_sh, NULL,
gpd, NULL, gp_style, -1, false, 1.0f, (int)OB_RENDER);
gpd, NULL, gp_style, -1, false, 1.0f, shade_render);
}
/* clean previous version of the batch */

View File

@@ -558,7 +558,7 @@ static void gpencil_add_draw_data(void *vedata, Object *ob)
/* FX passses */
cache_ob->has_fx = false;
if ((!stl->storage->simplify_fx) &&
(!ELEM(cache_ob->shading_type, OB_WIRE, OB_SOLID)) &&
(!ELEM(cache_ob->shading_type[0], OB_WIRE, OB_SOLID)) &&
(BKE_shaderfx_has_gpencil(ob)))
{
cache_ob->has_fx = true;

View File

@@ -93,7 +93,7 @@ typedef struct tGPencilObjectCache {
float scale;
/* shading type */
int shading_type;
int shading_type[2];
/* GPU data size */
int tot_vertex;
@@ -121,8 +121,8 @@ typedef struct GPENCIL_shgroup {
/* color of the wireframe */
float wire_color[4];
/* shading type */
int shading_type;
/* shading type and mode */
int shading_type[2];
} GPENCIL_shgroup;
typedef struct GPENCIL_Storage {
@@ -380,7 +380,7 @@ struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
struct Object *ob, struct bGPdata *gpd,
struct bGPDlayer *gpl, struct bGPDstroke *gps,
struct MaterialGPencilStyle *gp_style, int id, bool onion,
const float scale, int shading_type);
const float scale, const int shading_type[2]);
void DRW_gpencil_populate_datablock(
struct GPENCIL_e_data *e_data, void *vedata,
struct Object *ob, struct tGPencilObjectCache *cache_ob);

View File

@@ -746,7 +746,7 @@ void DRW_gpencil_fx_prepare(
tGPencilObjectCache *cache_ob)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const bool wiremode = (bool)(cache_ob->shading_type == OB_WIRE);
const bool wiremode = (bool)(cache_ob->shading_type[0] == OB_WIRE);
int ob_idx = cache_ob->idx;

View File

@@ -22,7 +22,7 @@ uniform sampler2D myTexture;
uniform int texture_clamp;
uniform int viewport_xray;
uniform int shading_type;
uniform int shading_type[2];
uniform vec4 wire_color;
/* keep this list synchronized with list in gpencil_draw_utils.c */
@@ -43,6 +43,9 @@ uniform vec4 wire_color;
#define OB_WIRE 2
#define OB_SOLID 3
#define V3D_SHADING_MATERIAL_COLOR 0
#define V3D_SHADING_TEXTURE_COLOR 3
in vec4 finalColor;
in vec2 texCoord_interp;
out vec4 fragColor;
@@ -92,7 +95,7 @@ void main()
vec4 chesscolor;
/* wireframe with x-ray discard */
if ((viewport_xray == 1) && (shading_type == OB_WIRE)) {
if ((viewport_xray == 1) && (shading_type[0] == OB_WIRE)) {
discard;
}
@@ -168,18 +171,18 @@ void main()
}
/* if wireframe override colors */
if (shading_type == OB_WIRE) {
if (shading_type[0] == OB_WIRE) {
fragColor = wire_color;
}
/* solid with x-ray discard */
if (shading_type == OB_SOLID) {
if (viewport_xray == 1) {
/* use 50% of color */
fragColor = vec4(wire_color.rgb, wire_color.a * 0.5);
}
else {
/* for solid override color */
if (shading_type[0] == OB_SOLID) {
if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) {
fragColor = wire_color;
}
if (viewport_xray == 1) {
fragColor.a *= 0.5;
}
}
}

View File

@@ -6,7 +6,7 @@ uniform int keep_size;
uniform float objscale;
uniform float pixfactor;
uniform int viewport_xray;
uniform int shading_type;
uniform int shading_type[2];
uniform vec4 wire_color;
in vec3 pos;
@@ -23,6 +23,9 @@ out vec2 finaluvdata;
#define OB_WIRE 2
#define OB_SOLID 3
#define V3D_SHADING_MATERIAL_COLOR 0
#define V3D_SHADING_TEXTURE_COLOR 3
float defaultpixsize = pixsize * (1000.0 / pixfactor);
void main()
@@ -39,18 +42,18 @@ void main()
}
/* for wireframe override size and color */
if (shading_type == OB_WIRE) {
if (shading_type[0] == OB_WIRE) {
finalThickness = 2.0;
finalColor = wire_color;
}
/* for solid override color */
if (shading_type == OB_SOLID) {
if (viewport_xray == 1) {
finalColor = vec4(wire_color.rgb, wire_color.a * 0.5);
}
else {
if (shading_type[0] == OB_SOLID) {
if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) {
finalColor = wire_color;
}
if (viewport_xray == 1) {
finalColor.a *= 0.5;
}
}
finaluvdata = uvdata;

View File

@@ -6,7 +6,7 @@ uniform int keep_size;
uniform float objscale;
uniform float pixfactor;
uniform int viewport_xray;
uniform int shading_type;
uniform int shading_type[2];
uniform vec4 wire_color;
in vec3 pos;
@@ -23,6 +23,9 @@ out vec2 finaluvdata;
#define OB_WIRE 2
#define OB_SOLID 3
#define V3D_SHADING_MATERIAL_COLOR 0
#define V3D_SHADING_TEXTURE_COLOR 3
float defaultpixsize = pixsize * (1000.0 / pixfactor);
void main(void)
@@ -39,18 +42,18 @@ void main(void)
}
/* for wireframe override size and color */
if (shading_type == OB_WIRE) {
if (shading_type[0] == OB_WIRE) {
finalThickness = 1.0;
finalColor = wire_color;
}
/* for solid override color */
if (shading_type == OB_SOLID) {
if (viewport_xray == 1) {
finalColor = vec4(wire_color.rgb, wire_color.a * 0.5);
}
else {
if (shading_type[0] == OB_SOLID) {
if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) {
finalColor = wire_color;
}
if (viewport_xray == 1) {
finalColor.a *= 0.5;
}
}
finaluvdata = uvdata;

View File

@@ -206,10 +206,10 @@ void DRW_displist_vertbuf_create_pos_and_nor(ListBase *lb, GPUVertBuf *vbo)
void DRW_displist_vertbuf_create_wiredata(ListBase *lb, GPUVertBuf *vbo)
{
static GPUVertFormat format = { 0 };
static struct { uint wd; } attr_id;
// static struct { uint wd; } attr_id; /* UNUSED */
if (format.attr_len == 0) {
/* initialize vertex format */
attr_id.wd = GPU_vertformat_attr_add(&format, "wd", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
/* attr_id.wd = */ GPU_vertformat_attr_add(&format, "wd", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
}
int vbo_len_used = curve_render_surface_vert_len_get(lb);

View File

@@ -7,10 +7,14 @@ uniform mat3 NormalMatrix;
uniform float wireStepParam;
uniform float ofs;
in vec3 pos;
in vec3 nor;
in float wd; /* wiredata */
#ifndef USE_SCULPT
float get_edge_sharpness(float wd)
{
return ((wd == 1.0) ? 1.0 : ((wd == 0.0) ? -1.5 : wd)) + wireStepParam;
return ((wd == 0.0) ? -1.5 : wd) + wireStepParam;
}
#else
float get_edge_sharpness(float wd) { return 1.0; }
@@ -18,11 +22,6 @@ float get_edge_sharpness(float wd) { return 1.0; }
/* Geometry shader version */
#if defined(SELECT_EDGES) || defined(USE_GEOM)
in vec3 pos;
in vec3 nor;
in float wd; /* wiredata */
out float facing_g;
out float edgeSharpness_g;
@@ -43,23 +42,18 @@ void main()
}
#else /* USE_GEOM */
in vec3 pos;
in vec3 nor;
in float wd;
out float facing;
flat out float edgeSharpness;
void main()
{
edgeSharpness = get_edge_sharpness(wd);
mat4 projmat = ProjectionMatrix;
projmat[3][2] -= ofs;
gl_Position = projmat * (ModelViewMatrix * vec4(pos, 1.0));
edgeSharpness = get_edge_sharpness(wd);
facing = normalize(NormalMatrix * nor).z;
#ifdef USE_WORLD_CLIP_PLANES

View File

@@ -204,6 +204,54 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot)
ED_object_add_generic_props(ot, true);
}
static int add_primitive_wedge_exec(bContext *C, wmOperator *op)
{
MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
float loc[3], rot[3];
bool enter_editmode;
ushort local_view_bits;
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &local_view_bits, NULL);
obedit = make_prim_init(
C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Wedge"),
loc, rot, local_view_bits, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (!EDBM_op_call_and_selectf(
em, op, "verts.out", false,
"create_wedge matrix=%m4 size=%f",
creation_data.mat, RNA_float_get(op->ptr, "size") * 2.0f))
{
return OPERATOR_CANCELLED;
}
make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
void MESH_OT_primitive_wedge_add(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Add Wedge";
ot->description = "Construct a wedge mesh";
ot->idname = "MESH_OT_primitive_wedge_add";
/* api callbacks */
ot->exec = add_primitive_wedge_exec;
ot->poll = ED_operator_scene_editable;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
ED_object_add_unit_props_size(ot);
ED_object_add_generic_props(ot, true);
}
static const EnumPropertyItem fill_type_items[] = {
{0, "NOTHING", 0, "Nothing", "Don't fill at all"},
{1, "NGON", 0, "Ngon", "Use ngons"},

View File

@@ -76,6 +76,7 @@ struct BMElem *EDBM_elem_from_index_any(struct BMEditMesh *em, int index);
/* *** editmesh_add.c *** */
void MESH_OT_primitive_plane_add(struct wmOperatorType *ot);
void MESH_OT_primitive_cube_add(struct wmOperatorType *ot);
void MESH_OT_primitive_wedge_add(struct wmOperatorType *ot);
void MESH_OT_primitive_circle_add(struct wmOperatorType *ot);
void MESH_OT_primitive_cylinder_add(struct wmOperatorType *ot);
void MESH_OT_primitive_cone_add(struct wmOperatorType *ot);

View File

@@ -63,6 +63,7 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_edges_select_sharp);
WM_operatortype_append(MESH_OT_primitive_plane_add);
WM_operatortype_append(MESH_OT_primitive_cube_add);
WM_operatortype_append(MESH_OT_primitive_wedge_add);
WM_operatortype_append(MESH_OT_primitive_circle_add);
WM_operatortype_append(MESH_OT_primitive_cylinder_add);
WM_operatortype_append(MESH_OT_primitive_cone_add);

View File

@@ -1066,6 +1066,9 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op)
/* if this is a new object, initialise default stuff (colors, etc.) */
if (newob) {
/* set default viewport color to black */
copy_v3_fl(ob->color, 0.0f);
ED_gpencil_add_defaults(C, ob);
}

View File

@@ -1431,14 +1431,14 @@ void sequencer_draw_preview(
}
}
if (draw_gpencil && show_imbuf) {
sequencer_draw_gpencil(C);
}
if (show_imbuf) {
sequencer_draw_borders(sseq, v2d, scene);
}
if (draw_gpencil && show_imbuf) {
sequencer_draw_gpencil(C);
}
/* TODO */
/* sequencer_draw_maskedit(C, scene, ar, sseq); */

View File

@@ -78,7 +78,7 @@ enum eSDNA_StructCompare {
};
struct SDNA *DNA_sdna_from_data(
const void *data, const int datalen,
const void *data, const int data_len,
bool do_endian_swap, bool data_alloc,
const char **r_error_message);
void DNA_sdna_free(struct SDNA *sdna);

View File

@@ -19,8 +19,7 @@
/** \file
* \ingroup DNA
* \brief These structs are the foundation for all linked lists in the
* library system.
* \brief These structs are the foundation for all linked lists in the library system.
*
* Doubly-linked lists start from a ListBase and contain elements beginning
* with Link.
@@ -33,19 +32,19 @@
extern "C" {
#endif
/* generic - all structs which are put into linked lists begin with this */
/** Generic - all structs which are put into linked lists begin with this. */
typedef struct Link {
struct Link *next, *prev;
} Link;
/* simple subclass of Link--use this when it is not worth defining a custom one... */
/** Simple subclass of Link. Use this when it is not worth defining a custom one. */
typedef struct LinkData {
struct LinkData *next, *prev;
void *data;
} LinkData;
/* never change the size of this! genfile.c detects pointerlen with it */
/** Never change the size of this! dna_genfile.c detects pointer_size with it. */
typedef struct ListBase {
void *first, *last;
} ListBase;

View File

@@ -31,7 +31,7 @@ typedef struct SDNA {
/** Full copy of 'encoded' data (when data_alloc is set, otherwise borrowed). */
const char *data;
/** Length of data. */
int datalen;
int data_len;
bool data_alloc;
/** Total number of struct members. */
@@ -40,14 +40,14 @@ typedef struct SDNA {
const char **names;
/** Size of a pointer in bytes. */
int pointerlen;
int pointer_size;
/** Number of basic types + struct types. */
int nr_types;
/** Type names. */
const char **types;
/** Type lengths. */
short *typelens;
short *types_size;
/** Number of struct types. */
int nr_structs;

View File

@@ -175,7 +175,7 @@ static bool ispointer(const char *name)
/**
* Returns the size of struct fields of the specified type and name.
*
* \param type: Index into sdna->types/typelens
* \param type: Index into sdna->types/types_size
* \param name: Index into sdna->names,
* needed to extract possible pointer/array information.
*/
@@ -196,16 +196,16 @@ static int elementsize(const SDNA *sdna, short type, short name)
mul = DNA_elem_array_size(cp);
}
len = sdna->pointerlen * mul;
len = sdna->pointer_size * mul;
}
else if (sdna->typelens[type]) {
else if (sdna->types_size[type]) {
/* has the name an extra length? (array) */
mul = 1;
if (cp[namelen - 1] == ']') {
mul = DNA_elem_array_size(cp);
}
len = mul * sdna->typelens[type];
len = mul * sdna->types_size[type];
}
@@ -397,7 +397,7 @@ static bool init_structDNA(
if (*data == MAKE_ID('T', 'L', 'E', 'N')) {
data++;
sp = (short *)data;
sdna->typelens = sp;
sdna->types_size = sp;
if (do_endian_swap) {
BLI_endian_switch_int16_array(sp, sdna->nr_types);
@@ -476,7 +476,7 @@ static bool init_structDNA(
}
#endif
/* Calculate 'sdna->pointerlen' */
/* Calculate 'sdna->pointer_size' */
{
const int nr = DNA_struct_find_nr(sdna, "ListBase");
@@ -486,13 +486,13 @@ static bool init_structDNA(
return false;
}
/* finally pointerlen: use struct ListBase to test it, never change the size of it! */
/* finally pointer_size: use struct ListBase to test it, never change the size of it! */
sp = sdna->structs[nr];
/* weird; i have no memory of that... I think I used sizeof(void *) before... (ton) */
sdna->pointerlen = sdna->typelens[sp[0]] / 2;
sdna->pointer_size = sdna->types_size[sp[0]] / 2;
if (sp[1] != 2 || (sdna->pointerlen != 4 && sdna->pointerlen != 8)) {
if (sp[1] != 2 || (sdna->pointer_size != 4 && sdna->pointer_size != 8)) {
*r_error_message = "ListBase struct error! Needs it to calculate pointerize.";
/* well, at least sizeof(ListBase) is error proof! (ton) */
return false;
@@ -506,17 +506,17 @@ static bool init_structDNA(
* Constructs and returns a decoded SDNA structure from the given encoded SDNA data block.
*/
SDNA *DNA_sdna_from_data(
const void *data, const int datalen,
const void *data, const int data_len,
bool do_endian_swap, bool data_alloc,
const char **r_error_message)
{
SDNA *sdna = MEM_mallocN(sizeof(*sdna), "sdna");
const char *error_message = NULL;
sdna->datalen = datalen;
sdna->data_len = data_len;
if (data_alloc) {
char *data_copy = MEM_mallocN(datalen, "sdna_data");
memcpy(data_copy, data, datalen);
char *data_copy = MEM_mallocN(data_len, "sdna_data");
memcpy(data_copy, data, data_len);
sdna->data = data_copy;
}
else {
@@ -641,7 +641,7 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
/* compare length and amount of elems */
if (sp_new[1] == sp_old[1]) {
if (newsdna->typelens[sp_new[0]] == oldsdna->typelens[sp_old[0]]) {
if (newsdna->types_size[sp_new[0]] == oldsdna->types_size[sp_old[0]]) {
/* same length, same amount of elems, now per type and name */
b = sp_old[1];
@@ -658,7 +658,7 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
/* same type and same name, now pointersize */
if (ispointer(str1)) {
if (oldsdna->pointerlen != newsdna->pointerlen) break;
if (oldsdna->pointer_size != newsdna->pointer_size) break;
}
b--;
@@ -1004,7 +1004,7 @@ static void reconstruct_elem(
if (strcmp(name, oname) == 0) { /* name equal */
if (ispointer(name)) { /* pointer of functionpointer afhandelen */
cast_pointer(newsdna->pointerlen, oldsdna->pointerlen, name, curdata, olddata);
cast_pointer(newsdna->pointer_size, oldsdna->pointer_size, name, curdata, olddata);
}
else if (strcmp(type, otype) == 0) { /* type equal */
memcpy(curdata, olddata, len);
@@ -1023,7 +1023,7 @@ static void reconstruct_elem(
oldsize = DNA_elem_array_size(oname);
if (ispointer(name)) { /* handle pointer or functionpointer */
cast_pointer(newsdna->pointerlen, oldsdna->pointerlen,
cast_pointer(newsdna->pointer_size, oldsdna->pointer_size,
cursize > oldsize ? oname : name,
curdata, olddata);
}
@@ -1096,7 +1096,7 @@ static void reconstruct_struct(
if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) {
/* if recursive: test for equal */
spo = oldsdna->structs[oldSDNAnr];
elen = oldsdna->typelens[spo[0]];
elen = oldsdna->types_size[spo[0]];
memcpy(cur, data, elen);
return;
@@ -1214,7 +1214,7 @@ void DNA_struct_switch_endian(const SDNA *oldsdna, int oldSDNAnr, char *data)
else {
/* non-struct field type */
if (ispointer(name)) {
if (oldsdna->pointerlen == 8) {
if (oldsdna->pointer_size == 8) {
BLI_endian_switch_int64_array((int64_t *)cur, DNA_elem_array_size(name));
}
}
@@ -1271,13 +1271,13 @@ void *DNA_struct_reconstruct(
/* oldSDNAnr == structnr, we're looking for the corresponding 'cur' number */
spo = oldsdna->structs[oldSDNAnr];
type = oldsdna->types[spo[0]];
oldlen = oldsdna->typelens[spo[0]];
oldlen = oldsdna->types_size[spo[0]];
curSDNAnr = DNA_struct_find_nr(newsdna, type);
/* init data and alloc */
if (curSDNAnr != -1) {
spc = newsdna->structs[curSDNAnr];
curlen = newsdna->typelens[spc[0]];
curlen = newsdna->types_size[spc[0]];
}
if (curlen == 0) {
return NULL;

View File

@@ -267,7 +267,7 @@ void DNA_alias_maps(
for (int i = 0; i < ARRAY_SIZE(data); i++) {
const char **str_pair = MEM_mallocN(sizeof(char *) * 2, __func__);
str_pair[0] = BLI_ghash_lookup_default(struct_map_local, data[i][0], (void *)data[i][0]);
str_pair[1] = data[i][elem_key],
str_pair[1] = data[i][elem_key];
BLI_ghash_insert(elem_map, str_pair, (void *)data[i][elem_val]);
}
*r_elem_map = elem_map;

View File

@@ -147,20 +147,21 @@ static int maxdata = 500000, maxnr = 50000;
static int nr_names = 0;
static int nr_types = 0;
static int nr_structs = 0;
/** at address names[a] is string a */
/** At address `names[a]` is string `a`. */
static char **names;
/** at address types[a] is string a */
/** At address `types[a]` is string `a`. */
static char **types;
/** at typelens[a] is the length of type 'a' on this systems bitness (32 or 64) */
static short *typelens_native;
/** contains sizes as they are calculated on 32 bit systems */
static short *typelens_32;
/** contains sizes as they are calculated on 64 bit systems */
static short *typelens_64;
/** at sp = structs[a] is the first address of a struct definition
* sp[0] is type number
* sp[1] is amount of elements
* sp[2] sp[3] is typenr, namenr (etc) */
/** At `types_size[a]` is the size of type `a` on this systems bitness (32 or 64). */
static short *types_size_native;
/** Contains sizes as they are calculated on 32 bit systems. */
static short *types_size_32;
/** Contains sizes as they are calculated on 64 bit systems. */
static short *types_size_64;
/** At `sp = structs[a]` is the first address of a struct definition:
* - `sp[0]` is type number.
* - `sp[1]` is the length of the element array (next).
* - `sp[2]` sp[3] is [(type_nr, name_nr), ..] (number of pairs is defined by `sp[1]`),
*/
static short **structs, *structdata;
/** Versioning data */
@@ -205,7 +206,7 @@ void BLI_system_backtrace(FILE *fp)
* \param len: The struct size in bytes.
* \return Index in the #types array.
*/
static int add_type(const char *str, int len);
static int add_type(const char *str, int size);
/**
* Ensure \c str is int the #names array.
@@ -224,7 +225,7 @@ static short *add_struct(int namecode);
* Remove comments from this buffer. Assumes that the buffer refers to
* ascii-code text.
*/
static int preprocess_include(char *maindata, int len);
static int preprocess_include(char *maindata, const int maindata_len);
/**
* Scan this file for serializable types.
@@ -234,7 +235,7 @@ static int convert_include(const char *filename);
/**
* Determine how many bytes are needed for each struct.
*/
static int calculate_structlens(int);
static int calculate_struct_sizes(int);
/**
* Construct the DNA.c file
@@ -244,7 +245,7 @@ static void dna_write(FILE *file, const void *pntr, const int size);
/**
* Report all structures found so far, and print their lengths.
*/
void printStructLengths(void);
void print_struct_sizes(void);
/** \} */
@@ -334,7 +335,7 @@ static bool is_name_legal(const char *name)
}
static int add_type(const char *str, int len)
static int add_type(const char *str, int size)
{
int nr;
char *cp;
@@ -354,10 +355,10 @@ static int add_type(const char *str, int len)
/* search through type array */
for (nr = 0; nr < nr_types; nr++) {
if (strcmp(str, types[nr]) == 0) {
if (len) {
typelens_native[nr] = len;
typelens_32[nr] = len;
typelens_64[nr] = len;
if (size) {
types_size_native[nr] = size;
types_size_32[nr] = size;
types_size_64[nr] = size;
}
return nr;
}
@@ -368,9 +369,9 @@ static int add_type(const char *str, int len)
cp = BLI_memarena_alloc(mem_arena, str_size);
memcpy(cp, str, str_size);
types[nr_types] = cp;
typelens_native[nr_types] = len;
typelens_32[nr_types] = len;
typelens_64[nr_types] = len;
types_size_native[nr_types] = size;
types_size_32[nr_types] = size;
types_size_64[nr_types] = size;
if (nr_types >= maxnr) {
printf("too many types\n");
@@ -552,22 +553,22 @@ static short *add_struct(int namecode)
return sp;
}
static int preprocess_include(char *maindata, int len)
static int preprocess_include(char *maindata, const int maindata_len)
{
int a, newlen, comment = 0;
char *cp, *temp, *md;
/* note: len + 1, last character is a dummy to prevent
* comparisons using uninitialized memory */
temp = MEM_mallocN(len + 1, "preprocess_include");
temp[len] = ' ';
temp = MEM_mallocN(maindata_len + 1, "preprocess_include");
temp[maindata_len] = ' ';
memcpy(temp, maindata, len);
memcpy(temp, maindata, maindata_len);
/* remove all c++ comments */
/* replace all enters/tabs/etc with spaces */
cp = temp;
a = len;
a = maindata_len;
comment = 0;
while (a--) {
if (cp[0] == '/' && cp[1] == '/') {
@@ -586,7 +587,7 @@ static int preprocess_include(char *maindata, int len)
md = maindata;
newlen = 0;
comment = 0;
a = len;
a = maindata_len;
while (a--) {
if (cp[0] == '/' && cp[1] == '*') {
@@ -682,24 +683,24 @@ static int convert_include(const char *filename)
/* read include file, skip structs with a '#' before it.
* store all data in temporal arrays.
*/
int filelen, count, slen, type, name, strct;
int maindata_len, count, slen, type, name, strct;
short *structpoin, *sp;
char *maindata, *mainend, *md, *md1;
bool skip_struct;
md = maindata = read_file_data(filename, &filelen);
if (filelen == -1) {
md = maindata = read_file_data(filename, &maindata_len);
if (maindata_len == -1) {
fprintf(stderr, "Can't read file %s\n", filename);
return 1;
}
filelen = preprocess_include(maindata, filelen);
mainend = maindata + filelen - 1;
maindata_len = preprocess_include(maindata, maindata_len);
mainend = maindata + maindata_len - 1;
/* we look for '{' and then back to 'struct' */
count = 0;
skip_struct = false;
while (count < filelen) {
while (count < maindata_len) {
/* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
if (md[0] == '#' && md[1] == ' ' && md[2] == '#') {
@@ -837,17 +838,17 @@ static bool check_field_alignment(int firststruct, int structtype, int type, int
const char *name, const char *detail)
{
bool result = true;
if (type < firststruct && typelens_native[type] > 4 && (len % 8)) {
if (type < firststruct && types_size_native[type] > 4 && (len % 8)) {
fprintf(stderr, "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
detail, types[structtype], name, len % 8);
result = false;
}
if (typelens_native[type] > 3 && (len % 4) ) {
if (types_size_native[type] > 3 && (len % 4) ) {
fprintf(stderr, "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
detail, types[structtype], name, len % 4);
result = false;
}
if (typelens_native[type] == 2 && (len % 2) ) {
if (types_size_native[type] == 2 && (len % 2) ) {
fprintf(stderr, "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
detail, types[structtype], name, len % 2);
result = false;
@@ -855,7 +856,7 @@ static bool check_field_alignment(int firststruct, int structtype, int type, int
return result;
}
static int calculate_structlens(int firststruct)
static int calculate_struct_sizes(int firststruct)
{
int unknown = nr_structs, lastunknown;
bool dna_error = false;
@@ -870,12 +871,12 @@ static int calculate_structlens(int firststruct)
const int structtype = structpoin[0];
/* when length is not known... */
if (typelens_native[structtype] == 0) {
if (types_size_native[structtype] == 0) {
const short *sp = structpoin + 2;
int len_native = 0;
int len_32 = 0;
int len_64 = 0;
int size_native = 0;
int size_32 = 0;
int size_64 = 0;
bool has_pointer = false;
/* check all elements in struct */
@@ -901,29 +902,29 @@ static int calculate_structlens(int firststruct)
/* 4-8 aligned/ */
if (sizeof(void *) == 4) {
if (len_native % 4) {
fprintf(stderr, "Align pointer error in struct (len_native 4): %s %s\n",
if (size_native % 4) {
fprintf(stderr, "Align pointer error in struct (size_native 4): %s %s\n",
types[structtype], cp);
dna_error = 1;
}
}
else {
if (len_native % 8) {
fprintf(stderr, "Align pointer error in struct (len_native 8): %s %s\n",
if (size_native % 8) {
fprintf(stderr, "Align pointer error in struct (size_native 8): %s %s\n",
types[structtype], cp);
dna_error = 1;
}
}
if (len_64 % 8) {
fprintf(stderr, "Align pointer error in struct (len_64 8): %s %s\n",
if (size_64 % 8) {
fprintf(stderr, "Align pointer error in struct (size_64 8): %s %s\n",
types[structtype], cp);
dna_error = 1;
}
len_native += sizeof(void *) * mul;
len_32 += 4 * mul;
len_64 += 8 * mul;
size_native += sizeof(void *) * mul;
size_32 += 4 * mul;
size_64 += 8 * mul;
}
else if (cp[0] == '[') {
@@ -933,7 +934,7 @@ static int calculate_structlens(int firststruct)
types[structtype], cp);
dna_error = 1;
}
else if (typelens_native[type]) {
else if (types_size_native[type]) {
/* has the name an extra length? (array) */
int mul = 1;
if (cp[namelen - 1] == ']') {
@@ -948,7 +949,7 @@ static int calculate_structlens(int firststruct)
/* struct alignment */
if (type >= firststruct) {
if (sizeof(void *) == 8 && (len_native % 8) ) {
if (sizeof(void *) == 8 && (size_native % 8) ) {
fprintf(stderr, "Align struct error: %s %s\n",
types[structtype], cp);
dna_error = 1;
@@ -956,46 +957,46 @@ static int calculate_structlens(int firststruct)
}
/* Check 2-4-8 aligned. */
if (!check_field_alignment(firststruct, structtype, type, len_32, cp, "32 bit")) {
if (!check_field_alignment(firststruct, structtype, type, size_32, cp, "32 bit")) {
dna_error = 1;
}
if (!check_field_alignment(firststruct, structtype, type, len_64, cp, "64 bit")) {
if (!check_field_alignment(firststruct, structtype, type, size_64, cp, "64 bit")) {
dna_error = 1;
}
len_native += mul * typelens_native[type];
len_32 += mul * typelens_32[type];
len_64 += mul * typelens_64[type];
size_native += mul * types_size_native[type];
size_32 += mul * types_size_32[type];
size_64 += mul * types_size_64[type];
}
else {
len_native = 0;
len_32 = 0;
len_64 = 0;
size_native = 0;
size_32 = 0;
size_64 = 0;
break;
}
}
if (len_native == 0) {
if (size_native == 0) {
unknown++;
}
else {
typelens_native[structtype] = len_native;
typelens_32[structtype] = len_32;
typelens_64[structtype] = len_64;
types_size_native[structtype] = size_native;
types_size_32[structtype] = size_32;
types_size_64[structtype] = size_64;
/* two ways to detect if a struct contains a pointer:
* has_pointer is set or len_native doesn't match any of 32/64bit lengths*/
if (has_pointer || len_64 != len_native || len_32 != len_native) {
if (len_64 % 8) {
* has_pointer is set or size_native doesn't match any of 32/64bit lengths*/
if (has_pointer || size_64 != size_native || size_32 != size_native) {
if (size_64 % 8) {
fprintf(stderr, "Sizeerror 8 in struct: %s (add %d bytes)\n",
types[structtype], len_64 % 8);
types[structtype], size_64 % 8);
dna_error = 1;
}
}
if (len_native % 4) {
if (size_native % 4) {
fprintf(stderr, "Sizeerror 4 in struct: %s (add %d bytes)\n",
types[structtype], len_native % 4);
types[structtype], size_native % 4);
dna_error = 1;
}
@@ -1017,7 +1018,7 @@ static int calculate_structlens(int firststruct)
const int structtype = structpoin[0];
/* length unknown */
if (typelens_native[structtype] != 0) {
if (types_size_native[structtype] != 0) {
fprintf(stderr, " %s\n", types[structtype]);
}
}
@@ -1031,7 +1032,7 @@ static int calculate_structlens(int firststruct)
const int structtype = structpoin[0];
/* length unknown yet */
if (typelens_native[structtype] == 0) {
if (types_size_native[structtype] == 0) {
fprintf(stderr, " %s\n", types[structtype]);
}
}
@@ -1062,7 +1063,7 @@ static void dna_write(FILE *file, const void *pntr, const int size)
}
}
void printStructLengths(void)
void print_struct_sizes(void)
{
int a, unknown = nr_structs, structtype;
/*int lastunknown;*/ /*UNUSED*/
@@ -1077,7 +1078,7 @@ void printStructLengths(void)
for (a = 0; a < nr_structs; a++) {
structpoin = structs[a];
structtype = structpoin[0];
printf("\t%s\t:%d\n", types[structtype], typelens_native[structtype]);
printf("\t%s\t:%d\n", types[structtype], types_size_native[structtype]);
}
}
@@ -1108,9 +1109,9 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
/* a maximum of 5000 variables, must be sufficient? */
names = MEM_callocN(sizeof(char *) * maxnr, "names");
types = MEM_callocN(sizeof(char *) * maxnr, "types");
typelens_native = MEM_callocN(sizeof(short) * maxnr, "typelens_native");
typelens_32 = MEM_callocN(sizeof(short) * maxnr, "typelens_32");
typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64");
types_size_native = MEM_callocN(sizeof(short) * maxnr, "types_size_native");
types_size_32 = MEM_callocN(sizeof(short) * maxnr, "types_size_32");
types_size_64 = MEM_callocN(sizeof(short) * maxnr, "types_size_64");
structs = MEM_callocN(sizeof(short *) * maxnr, "structs");
/* Build versioning data */
@@ -1164,7 +1165,7 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
}
DEBUG_PRINTF(0, "\tFinished scanning %d headers.\n", i);
if (calculate_structlens(firststruct)) {
if (calculate_struct_sizes(firststruct)) {
/* error */
return 1;
}
@@ -1181,7 +1182,7 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
}
printf("\n");
sp = typelens_native;
sp = types_size_native;
for (a = 0; a < nr_types; a++, sp++) {
printf(" %s %d\n", types[a], *sp);
}
@@ -1189,7 +1190,7 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
for (a = 0; a < nr_structs; a++) {
sp = structs[a];
printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens_native[sp[0]]);
printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], types_size_native[sp[0]]);
num_types = sp[1];
sp += 2;
/* ? num_types was elem? */
@@ -1249,7 +1250,7 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
len = 2 * nr_types;
if (nr_types & 1) len += 2;
dna_write(file, typelens_native, len);
dna_write(file, types_size_native, len);
/* WRITE STRUCTS */
dna_write(file, "STRC", 4);
@@ -1281,7 +1282,7 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
}
fprintf(fp, "main() {\n");
sp = typelens_native;
sp = types_size_native;
sp += firststruct;
for (a = firststruct; a < nr_types; a++, sp++) {
if (*sp) {
@@ -1338,9 +1339,9 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
MEM_freeN(structdata);
MEM_freeN(names);
MEM_freeN(types);
MEM_freeN(typelens_native);
MEM_freeN(typelens_32);
MEM_freeN(typelens_64);
MEM_freeN(types_size_native);
MEM_freeN(types_size_32);
MEM_freeN(types_size_64);
MEM_freeN(structs);
BLI_memarena_free(mem_arena);