diff options
615 files changed, 11744 insertions, 7338 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bb5d8af627..ff3195224bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ option(WITH_BULLET "Enable Bullet (Physics Engine)" ON) option(WITH_GAMEENGINE "Enable Game Engine" ON) option(WITH_PLAYER "Build Player" OFF) option(WITH_COMPOSITOR "Enable the tile based nodal compositor" ON) -option(WITH_COMPOSITOR_LEGACY "Enable legacy compositor" ON) +option(WITH_COMPOSITOR_LEGACY "Enable legacy compositor" OFF) # GHOST Windowing Library Options option(WITH_GHOST_DEBUG "Enable debugging output for the GHOST library" OFF) @@ -672,6 +672,31 @@ if(UNIX AND NOT APPLE) endif() endif() + if(WITH_CYCLES_OSL) + set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation") + + message(STATUS "CYCLES_OSL = ${CYCLES_OSL}") + + find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib) + find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib) + find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib) + # WARNING! depends on correct order of OSL libs linking + list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY}) + find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include) + find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin) + + if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER) + set(OSL_FOUND TRUE) + message(STATUS "OSL includes = ${OSL_INCLUDES}") + message(STATUS "OSL library = ${OSL_LIBRARIES}") + message(STATUS "OSL compiler = ${OSL_COMPILER}") + else() + message(STATUS "OSL not found") + endif() + + include_directories(${OSL_INCLUDES}) + endif() + # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++") @@ -816,6 +841,31 @@ elseif(WIN32) add_definitions(-D__SSE__ -D__MMX__) endif() + if(WITH_CYCLES_OSL) + set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation") + + message(STATUS "CYCLES_OSL = ${CYCLES_OSL}") + + find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib) + find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib) + find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib) + # WARNING! depends on correct order of OSL libs linking + list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY}) + find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include) + find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin) + + if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER) + set(OSL_FOUND TRUE) + message(STATUS "OSL includes = ${OSL_INCLUDES}") + message(STATUS "OSL library = ${OSL_LIBRARIES}") + message(STATUS "OSL compiler = ${OSL_COMPILER}") + else() + message(STATUS "OSL not found") + endif() + + include_directories(${OSL_INCLUDES}) + endif() + if(MSVC) set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid) @@ -1432,6 +1482,31 @@ elseif(APPLE) set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD") endif() + if(WITH_CYCLES_OSL) + set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation") + + message(STATUS "CYCLES_OSL = ${CYCLES_OSL}") + + find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib) + find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib) + find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib) + # WARNING! depends on correct order of OSL libs linking + list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY}) + find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include) + find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin) + + if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER) + set(OSL_FOUND TRUE) + message(STATUS "OSL includes = ${OSL_INCLUDES}") + message(STATUS "OSL library = ${OSL_LIBRARIES}") + message(STATUS "OSL compiler = ${OSL_COMPILER}") + else() + message(STATUS "OSL not found") + endif() + + include_directories(${OSL_INCLUDES}) + endif() + set(EXETYPE MACOSX_BUNDLE) set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g") diff --git a/GNUmakefile b/GNUmakefile index f48ac5c2e41..1f1de3f6b99 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -251,6 +251,10 @@ check_sparse: $(CMAKE_CONFIG) cd $(BUILD_DIR) ; python3.2 $(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py +check_smatch: + $(CMAKE_CONFIG) + cd $(BUILD_DIR) ; python3.2 $(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py + check_spelling_py: cd $(BUILD_DIR) ; PYTHONIOENCODING=utf_8 python3.2 $(BLENDER_DIR)/source/tools/spell_check_source.py $(BLENDER_DIR)/release/scripts diff --git a/build_files/cmake/cmake_static_check_smatch.py b/build_files/cmake/cmake_static_check_smatch.py new file mode 100644 index 00000000000..779945b030a --- /dev/null +++ b/build_files/cmake/cmake_static_check_smatch.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3.2 + +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contributor(s): Campbell Barton +# +# ***** END GPL LICENSE BLOCK ***** + +# <pep8 compliant> + +CHECKER_IGNORE_PREFIX = [ + "extern", + "intern/moto", + ] + +CHECKER_BIN = "smatch" +CHECKER_ARGS = [ + "--full-path", + "--two-passes", + ] + +import project_source_info +import subprocess +import sys + + +def main(): + source_info = project_source_info.build_info(use_cxx=False, ignore_prefix_list=CHECKER_IGNORE_PREFIX) + + check_commands = [] + for c, inc_dirs, defs in source_info: + + cmd = ([CHECKER_BIN] + + CHECKER_ARGS + + [c] + + [("-I%s" % i) for i in inc_dirs] + + [("-D%s" % d) for d in defs] + ) + + check_commands.append((c, cmd)) + + def my_process(i, c, cmd): + percent = 100.0 * (i / (len(check_commands) - 1)) + percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:" + + sys.stdout.flush() + sys.stdout.write("%s %s\n" % (percent_str, c)) + + return subprocess.Popen(cmd) + + process_functions = [] + for i, (c, cmd) in enumerate(check_commands): + process_functions.append((my_process, (i, c, cmd))) + + project_source_info.queue_processes(process_functions) + + +if __name__ == "__main__": + main() diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 62e1e83326c..317fcf0f120 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -27,7 +27,10 @@ macro(list_insert_after list_id item_check item_add ) set(_index) - list(FIND ${list_id} "${item_check}" _index) + list(FIND "${list_id}" "${item_check}" _index) + if("${_index}" MATCHES "-1") + message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'") + endif() math(EXPR _index "${_index} + 1") list(INSERT ${list_id} "${_index}" ${item_add}) unset(_index) @@ -37,7 +40,10 @@ macro(list_insert_before list_id item_check item_add ) set(_index) - list(FIND ${list_id} "${item_check}" _index) + list(FIND "${list_id}" "${item_check}" _index) + if("${_index}" MATCHES "-1") + message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'") + endif() list(INSERT ${list_id} "${_index}" ${item_add}) unset(_index) endmacro() @@ -367,6 +373,9 @@ macro(setup_liblinks if(WITH_MOD_CLOTH_ELTOPO) target_link_libraries(${target} ${LAPACK_LIBRARIES}) endif() + if(WITH_CYCLES_OSL) + target_link_libraries(${target} ${OSL_LIBRARIES}) + endif() if(WIN32 AND NOT UNIX) target_link_libraries(${target} ${PTHREADS_LIBRARIES}) endif() diff --git a/build_files/scons/config/win32-mingw-config.py b/build_files/scons/config/win32-mingw-config.py index 723651971d0..d46aaca5a07 100644 --- a/build_files/scons/config/win32-mingw-config.py +++ b/build_files/scons/config/win32-mingw-config.py @@ -172,7 +172,7 @@ BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse'] #CUDA WITH_BF_CYCLES_CUDA_BINARIES = False #BF_CYCLES_CUDA_NVCC = "" # Path to the nvidia compiler -BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21'] # don't build sm_13 until the compile can fit in 32bit process again :) +BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21', 'sm_30'] ## CC = 'gcc' diff --git a/build_files/scons/config/win64-mingw-config.py b/build_files/scons/config/win64-mingw-config.py index ffd37065e35..66ec65bb6ca 100644 --- a/build_files/scons/config/win64-mingw-config.py +++ b/build_files/scons/config/win64-mingw-config.py @@ -151,7 +151,7 @@ BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' WITH_BF_CYCLES = True WITH_BF_CYCLES_CUDA_BINARIES = False BF_CYCLES_CUDA_NVCC = "" # Path to the NVIDIA CUDA compiler -BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21'] +BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21', 'sm_30'] WITH_BF_OIIO = True BF_OIIO = LIBDIR + '/openimageio' diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index ed014f7553b..24223ad1ad0 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -851,7 +851,7 @@ def pymodule2sphinx(basepath, module_name, module, title): elif value_type in (bool, int, float, str, tuple): # constant, not much fun we can do here except to list it. # TODO, figure out some way to document these! - #fw(".. data:: %s\n\n" % attribute) + fw(".. data:: %s\n\n" % attribute) write_indented_lines(" ", fw, "constant value %s" % repr(value), False) fw("\n") else: diff --git a/extern/bullet2/CMakeLists.txt b/extern/bullet2/CMakeLists.txt index 4bf26ab3794..c57474f99f2 100644 --- a/extern/bullet2/CMakeLists.txt +++ b/extern/bullet2/CMakeLists.txt @@ -314,6 +314,7 @@ set(SRC src/BulletDynamics/Character/btKinematicCharacterController.h src/BulletSoftBody/btSoftBody.h + src/BulletSoftBody/btSoftBodyInternals.h src/BulletSoftBody/btSoftBodyData.h src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h src/BulletSoftBody/btSoftBodyHelpers.h @@ -355,6 +356,7 @@ set(SRC src/btBulletCollisionCommon.h src/btBulletDynamicsCommon.h + src/Bullet-C-Api.h ) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/extern/libmv/third_party/ceres/SConscript b/extern/libmv/third_party/ceres/SConscript index 6b5f1b8d64d..c629fa00176 100644 --- a/extern/libmv/third_party/ceres/SConscript +++ b/extern/libmv/third_party/ceres/SConscript @@ -25,6 +25,11 @@ defs.append('CERES_RESTRICT_SCHUR_SPECIALIZATION') incs = '. ../../ ../../../Eigen3 ./include ./internal ../gflags' +# work around broken hashtable in 10.5 SDK +if env['OURPLATFORM'] == 'darwin' and env['WITH_BF_BOOST']: + incs += ' ' + env['BF_BOOST_INC'] + defs.append('CERES_HASH_BOOST') + if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'): if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'): incs += ' ../msinttypes' diff --git a/extern/libmv/third_party/ceres/internal/ceres/collections_port.h b/extern/libmv/third_party/ceres/internal/ceres/collections_port.h index 6f8a830a85e..9dff0efe245 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/collections_port.h +++ b/extern/libmv/third_party/ceres/internal/ceres/collections_port.h @@ -33,6 +33,10 @@ #ifndef CERES_INTERNAL_COLLECTIONS_PORT_H_ #define CERES_INTERNAL_COLLECTIONS_PORT_H_ +#ifdef CERES_HASH_BOOST +#include <boost/tr1/unordered_map.hpp> +#include <boost/tr1/unordered_set.hpp> +#else #if defined(_MSC_VER) && _MSC_VER <= 1700 #include <unordered_map> #include <unordered_set> @@ -40,6 +44,8 @@ #include <tr1/unordered_map> #include <tr1/unordered_set> #endif +#endif + #include <utility> #include "ceres/integral_types.h" #include "ceres/internal/port.h" @@ -118,7 +124,11 @@ CERES_HASH_NAMESPACE_START // Hasher for STL pairs. Requires hashers for both members to be defined. template<typename T> +#ifdef CERES_HASH_BOOST +struct hash { +#else struct hash<pair<T, T> > { +#endif size_t operator()(const pair<T, T>& p) const { size_t h1 = hash<T>()(p.first); size_t h2 = hash<T>()(p.second); diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index a7d37da0426..46bba237cff 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -99,11 +99,11 @@ typedef AUD_Reference<AUD_SequencerEntry> AUD_SEntry; #include "AUD_C-API.h" #ifndef NULL -#define NULL 0 +# define NULL (void *)0 #endif static AUD_Reference<AUD_IDevice> AUD_device; -static AUD_I3DDevice* AUD_3ddevice; +static AUD_I3DDevice *AUD_3ddevice; void AUD_initOnce() { @@ -116,13 +116,12 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize) { AUD_Reference<AUD_IDevice> dev; - if(!AUD_device.isNull()) + if (!AUD_device.isNull()) { AUD_exit(); + } - try - { - switch(device) - { + try { + switch(device) { case AUD_NULL_DEVICE: dev = new AUD_NULLDevice(); break; @@ -140,8 +139,7 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize) case AUD_JACK_DEVICE: #ifdef __APPLE__ struct stat st; - if(stat("/Library/Frameworks/Jackmp.framework", &st) != 0) - { + if (stat("/Library/Frameworks/Jackmp.framework", &st) != 0) { printf("Warning: Jack Framework not installed\n"); // No break, fall through to default, to return false } @@ -159,7 +157,7 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize) } AUD_device = dev; - AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get()); + AUD_3ddevice = dynamic_cast<AUD_I3DDevice *>(AUD_device.get()); return true; } @@ -176,48 +174,44 @@ void AUD_exit() } #ifdef WITH_PYTHON -static PyObject* AUD_getCDevice(PyObject* self) +static PyObject *AUD_getCDevice(PyObject *self) { - if(!AUD_device.isNull()) - { - Device* device = (Device*)Device_empty(); - if(device != NULL) - { + if (!AUD_device.isNull()) { + Device *device = (Device *)Device_empty(); + if (device != NULL) { device->device = new AUD_Reference<AUD_IDevice>(AUD_device); - return (PyObject*)device; + return (PyObject *)device; } } Py_RETURN_NONE; } -static PyMethodDef meth_getcdevice[] = {{ "device", (PyCFunction)AUD_getCDevice, METH_NOARGS, - "device()\n\n" - "Returns the application's :class:`Device`.\n\n" - ":return: The application's :class:`Device`.\n" - ":rtype: :class:`Device`"}}; +static PyMethodDef meth_getcdevice[] = { + {"device", (PyCFunction)AUD_getCDevice, METH_NOARGS, + "device()\n\n" + "Returns the application's :class:`Device`.\n\n" + ":return: The application's :class:`Device`.\n" + ":rtype: :class:`Device`"} +}; extern "C" { -extern void* sound_get_factory(void* sound); +extern void *sound_get_factory(void *sound); } -static PyObject* AUD_getSoundFromPointer(PyObject* self, PyObject* args) +static PyObject *AUD_getSoundFromPointer(PyObject *self, PyObject *args) { long int lptr; - if(PyArg_Parse(args, "l:_sound_from_pointer", &lptr)) - { - if(lptr) - { - AUD_Reference<AUD_IFactory>* factory = (AUD_Reference<AUD_IFactory>*) sound_get_factory((void*) lptr); + if (PyArg_Parse(args, "l:_sound_from_pointer", &lptr)) { + if (lptr) { + AUD_Reference<AUD_IFactory>* factory = (AUD_Reference<AUD_IFactory>*) sound_get_factory((void *) lptr); - if(factory) - { - Factory* obj = (Factory*) Factory_empty(); - if(obj) - { + if (factory) { + Factory *obj = (Factory *)Factory_empty(); + if (obj) { obj->factory = new AUD_Reference<AUD_IFactory>(*factory); - return (PyObject*) obj; + return (PyObject *) obj; } } } @@ -226,44 +220,44 @@ static PyObject* AUD_getSoundFromPointer(PyObject* self, PyObject* args) Py_RETURN_NONE; } -static PyMethodDef meth_sound_from_pointer[] = {{ "_sound_from_pointer", (PyCFunction)AUD_getSoundFromPointer, METH_O, - "_sound_from_pointer(pointer)\n\n" - "Returns the corresponding :class:`Factory` object.\n\n" - ":arg pointer: The pointer to the bSound object as long.\n" - ":type pointer: long\n" - ":return: The corresponding :class:`Factory` object.\n" - ":rtype: :class:`Factory`"}}; +static PyMethodDef meth_sound_from_pointer[] = { + {"_sound_from_pointer", (PyCFunction)AUD_getSoundFromPointer, METH_O, + "_sound_from_pointer(pointer)\n\n" + "Returns the corresponding :class:`Factory` object.\n\n" + ":arg pointer: The pointer to the bSound object as long.\n" + ":type pointer: long\n" + ":return: The corresponding :class:`Factory` object.\n" + ":rtype: :class:`Factory`"} +}; -PyObject* AUD_initPython() +PyObject *AUD_initPython() { - PyObject* module = PyInit_aud(); - PyModule_AddObject(module, "device", (PyObject*)PyCFunction_New(meth_getcdevice, NULL)); - PyModule_AddObject(module, "_sound_from_pointer", (PyObject*)PyCFunction_New(meth_sound_from_pointer, NULL)); + PyObject *module = PyInit_aud(); + PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL)); + PyModule_AddObject(module, "_sound_from_pointer", (PyObject *)PyCFunction_New(meth_sound_from_pointer, NULL)); PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module); return module; } -void* AUD_getPythonFactory(AUD_Sound* sound) +void *AUD_getPythonFactory(AUD_Sound *sound) { - if(sound) - { - Factory* obj = (Factory*) Factory_empty(); - if(obj) - { + if (sound) { + Factory *obj = (Factory *) Factory_empty(); + if (obj) { obj->factory = new AUD_Reference<AUD_IFactory>(*sound); - return (PyObject*) obj; + return (PyObject *) obj; } } return NULL; } -AUD_Sound* AUD_getPythonSound(void* sound) +AUD_Sound *AUD_getPythonSound(void *sound) { - Factory* factory = checkFactory((PyObject *)sound); + Factory *factory = checkFactory((PyObject *)sound); - if(!factory) + if (!factory) return NULL; return new AUD_Reference<AUD_IFactory>(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(factory->factory)); @@ -281,7 +275,7 @@ void AUD_unlock() AUD_device->unlock(); } -AUD_SoundInfo AUD_getInfo(AUD_Sound* sound) +AUD_SoundInfo AUD_getInfo(AUD_Sound *sound) { assert(sound); @@ -290,12 +284,10 @@ AUD_SoundInfo AUD_getInfo(AUD_Sound* sound) info.specs.rate = AUD_RATE_INVALID; info.length = 0.0f; - try - { + try { AUD_Reference<AUD_IReader> reader = (*sound)->createReader(); - if(!reader.isNull()) - { + if (!reader.isNull()) { info.specs = reader->getSpecs(); info.length = reader->getLength() / (float) info.specs.rate; } @@ -307,24 +299,23 @@ AUD_SoundInfo AUD_getInfo(AUD_Sound* sound) return info; } -AUD_Sound* AUD_load(const char* filename) +AUD_Sound *AUD_load(const char *filename) { assert(filename); return new AUD_Sound(new AUD_FileFactory(filename)); } -AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size) +AUD_Sound *AUD_loadBuffer(unsigned char *buffer, int size) { assert(buffer); return new AUD_Sound(new AUD_FileFactory(buffer, size)); } -AUD_Sound* AUD_bufferSound(AUD_Sound* sound) +AUD_Sound *AUD_bufferSound(AUD_Sound *sound) { assert(sound); - try - { + try { return new AUD_Sound(new AUD_StreamBufferFactory(*sound)); } catch(AUD_Exception&) @@ -333,12 +324,11 @@ AUD_Sound* AUD_bufferSound(AUD_Sound* sound) } } -AUD_Sound* AUD_monoSound(AUD_Sound* sound) +AUD_Sound *AUD_monoSound(AUD_Sound *sound) { assert(sound); - try - { + try { AUD_DeviceSpecs specs; specs.channels = AUD_CHANNELS_MONO; specs.rate = AUD_RATE_INVALID; @@ -351,12 +341,11 @@ AUD_Sound* AUD_monoSound(AUD_Sound* sound) } } -AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay) +AUD_Sound *AUD_delaySound(AUD_Sound *sound, float delay) { assert(sound); - try - { + try { return new AUD_Sound(new AUD_DelayFactory(*sound, delay)); } catch(AUD_Exception&) @@ -365,12 +354,11 @@ AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay) } } -AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end) +AUD_Sound *AUD_limitSound(AUD_Sound *sound, float start, float end) { assert(sound); - try - { + try { return new AUD_Sound(new AUD_LimiterFactory(*sound, start, end)); } catch(AUD_Exception&) @@ -379,12 +367,11 @@ AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end) } } -AUD_Sound* AUD_pingpongSound(AUD_Sound* sound) +AUD_Sound *AUD_pingpongSound(AUD_Sound *sound) { assert(sound); - try - { + try { return new AUD_Sound(new AUD_PingPongFactory(*sound)); } catch(AUD_Exception&) @@ -393,12 +380,11 @@ AUD_Sound* AUD_pingpongSound(AUD_Sound* sound) } } -AUD_Sound* AUD_loopSound(AUD_Sound* sound) +AUD_Sound *AUD_loopSound(AUD_Sound *sound) { assert(sound); - try - { + try { return new AUD_Sound(new AUD_LoopFactory(*sound)); } catch(AUD_Exception&) @@ -407,12 +393,11 @@ AUD_Sound* AUD_loopSound(AUD_Sound* sound) } } -int AUD_setLoop(AUD_Handle* handle, int loops) +int AUD_setLoop(AUD_Handle *handle, int loops) { assert(handle); - try - { + try { return (*handle)->setLoopCount(loops); } catch(AUD_Exception&) @@ -422,12 +407,11 @@ int AUD_setLoop(AUD_Handle* handle, int loops) return false; } -AUD_Sound* AUD_rectifySound(AUD_Sound* sound) +AUD_Sound *AUD_rectifySound(AUD_Sound *sound) { assert(sound); - try - { + try { return new AUD_Sound(new AUD_RectifyFactory(*sound)); } catch(AUD_Exception&) @@ -436,20 +420,20 @@ AUD_Sound* AUD_rectifySound(AUD_Sound* sound) } } -void AUD_unload(AUD_Sound* sound) +void AUD_unload(AUD_Sound *sound) { assert(sound); delete sound; } -AUD_Handle* AUD_play(AUD_Sound* sound, int keep) +AUD_Handle *AUD_play(AUD_Sound *sound, int keep) { assert(sound); - try - { + try { AUD_Handle handle = AUD_device->play(*sound, keep); - if(!handle.isNull()) + if (!handle.isNull()) { return new AUD_Handle(handle); + } } catch(AUD_Exception&) { @@ -457,19 +441,19 @@ AUD_Handle* AUD_play(AUD_Sound* sound, int keep) return NULL; } -int AUD_pause(AUD_Handle* handle) +int AUD_pause(AUD_Handle *handle) { assert(handle); return (*handle)->pause(); } -int AUD_resume(AUD_Handle* handle) +int AUD_resume(AUD_Handle *handle) { assert(handle); return (*handle)->resume(); } -int AUD_stop(AUD_Handle* handle) +int AUD_stop(AUD_Handle *handle) { assert(handle); int result = (*handle)->stop(); @@ -477,34 +461,33 @@ int AUD_stop(AUD_Handle* handle) return result; } -int AUD_setKeep(AUD_Handle* handle, int keep) +int AUD_setKeep(AUD_Handle *handle, int keep) { assert(handle); return (*handle)->setKeep(keep); } -int AUD_seek(AUD_Handle* handle, float seekTo) +int AUD_seek(AUD_Handle *handle, float seekTo) { assert(handle); return (*handle)->seek(seekTo); } -float AUD_getPosition(AUD_Handle* handle) +float AUD_getPosition(AUD_Handle *handle) { assert(handle); return (*handle)->getPosition(); } -AUD_Status AUD_getStatus(AUD_Handle* handle) +AUD_Status AUD_getStatus(AUD_Handle *handle) { assert(handle); return (*handle)->getStatus(); } -int AUD_setListenerLocation(const float* location) +int AUD_setListenerLocation(const float location[3]) { - if(AUD_3ddevice) - { + if (AUD_3ddevice) { AUD_Vector3 v(location[0], location[1], location[2]); AUD_3ddevice->setListenerLocation(v); return true; @@ -513,10 +496,9 @@ int AUD_setListenerLocation(const float* location) return false; } -int AUD_setListenerVelocity(const float* velocity) +int AUD_setListenerVelocity(const float velocity[3]) { - if(AUD_3ddevice) - { + if (AUD_3ddevice) { AUD_Vector3 v(velocity[0], velocity[1], velocity[2]); AUD_3ddevice->setListenerVelocity(v); return true; @@ -525,10 +507,9 @@ int AUD_setListenerVelocity(const float* velocity) return false; } -int AUD_setListenerOrientation(const float* orientation) +int AUD_setListenerOrientation(const float orientation[4]) { - if(AUD_3ddevice) - { + if (AUD_3ddevice) { AUD_Quaternion q(orientation[3], orientation[0], orientation[1], orientation[2]); AUD_3ddevice->setListenerOrientation(q); return true; @@ -539,8 +520,7 @@ int AUD_setListenerOrientation(const float* orientation) int AUD_setSpeedOfSound(float speed) { - if(AUD_3ddevice) - { + if (AUD_3ddevice) { AUD_3ddevice->setSpeedOfSound(speed); return true; } @@ -550,8 +530,7 @@ int AUD_setSpeedOfSound(float speed) int AUD_setDopplerFactor(float factor) { - if(AUD_3ddevice) - { + if (AUD_3ddevice) { AUD_3ddevice->setDopplerFactor(factor); return true; } @@ -561,8 +540,7 @@ int AUD_setDopplerFactor(float factor) int AUD_setDistanceModel(AUD_DistanceModel model) { - if(AUD_3ddevice) - { + if (AUD_3ddevice) { AUD_3ddevice->setDistanceModel(model); return true; } @@ -570,13 +548,12 @@ int AUD_setDistanceModel(AUD_DistanceModel model) return false; } -int AUD_setSourceLocation(AUD_Handle* handle, const float* location) +int AUD_setSourceLocation(AUD_Handle *handle, const float location[3]) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { AUD_Vector3 v(location[0], location[1], location[2]); return h->setSourceLocation(v); } @@ -584,13 +561,12 @@ int AUD_setSourceLocation(AUD_Handle* handle, const float* location) return false; } -int AUD_setSourceVelocity(AUD_Handle* handle, const float* velocity) +int AUD_setSourceVelocity(AUD_Handle *handle, const float velocity[3]) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { AUD_Vector3 v(velocity[0], velocity[1], velocity[2]); return h->setSourceVelocity(v); } @@ -598,13 +574,12 @@ int AUD_setSourceVelocity(AUD_Handle* handle, const float* velocity) return false; } -int AUD_setSourceOrientation(AUD_Handle* handle, const float* orientation) +int AUD_setSourceOrientation(AUD_Handle *handle, const float orientation[4]) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { AUD_Quaternion q(orientation[3], orientation[0], orientation[1], orientation[2]); return h->setSourceOrientation(q); } @@ -612,149 +587,137 @@ int AUD_setSourceOrientation(AUD_Handle* handle, const float* orientation) return false; } -int AUD_setRelative(AUD_Handle* handle, int relative) +int AUD_setRelative(AUD_Handle *handle, int relative) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setRelative(relative); } return false; } -int AUD_setVolumeMaximum(AUD_Handle* handle, float volume) +int AUD_setVolumeMaximum(AUD_Handle *handle, float volume) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setVolumeMaximum(volume); } return false; } -int AUD_setVolumeMinimum(AUD_Handle* handle, float volume) +int AUD_setVolumeMinimum(AUD_Handle *handle, float volume) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setVolumeMinimum(volume); } return false; } -int AUD_setDistanceMaximum(AUD_Handle* handle, float distance) +int AUD_setDistanceMaximum(AUD_Handle *handle, float distance) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setDistanceMaximum(distance); } return false; } -int AUD_setDistanceReference(AUD_Handle* handle, float distance) +int AUD_setDistanceReference(AUD_Handle *handle, float distance) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setDistanceReference(distance); } return false; } -int AUD_setAttenuation(AUD_Handle* handle, float factor) +int AUD_setAttenuation(AUD_Handle *handle, float factor) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setAttenuation(factor); } return false; } -int AUD_setConeAngleOuter(AUD_Handle* handle, float angle) +int AUD_setConeAngleOuter(AUD_Handle *handle, float angle) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setConeAngleOuter(angle); } return false; } -int AUD_setConeAngleInner(AUD_Handle* handle, float angle) +int AUD_setConeAngleInner(AUD_Handle *handle, float angle) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setConeAngleInner(angle); } return false; } -int AUD_setConeVolumeOuter(AUD_Handle* handle, float volume) +int AUD_setConeVolumeOuter(AUD_Handle *handle, float volume) { assert(handle); AUD_Reference<AUD_I3DHandle> h(*handle); - if(!h.isNull()) - { + if (!h.isNull()) { return h->setConeVolumeOuter(volume); } return false; } -int AUD_setSoundVolume(AUD_Handle* handle, float volume) +int AUD_setSoundVolume(AUD_Handle *handle, float volume) { assert(handle); - try - { + try { return (*handle)->setVolume(volume); } catch(AUD_Exception&) {} return false; } -int AUD_setSoundPitch(AUD_Handle* handle, float pitch) +int AUD_setSoundPitch(AUD_Handle *handle, float pitch) { assert(handle); - try - { + try { return (*handle)->setPitch(pitch); } catch(AUD_Exception&) {} return false; } -AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs) +AUD_Device *AUD_openReadDevice(AUD_DeviceSpecs specs) { - try - { + try { return new AUD_Device(new AUD_ReadDevice(specs)); } catch(AUD_Exception&) @@ -763,16 +726,14 @@ AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs) } } -AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek) +AUD_Handle *AUD_playDevice(AUD_Device *device, AUD_Sound *sound, float seek) { assert(device); assert(sound); - try - { + try { AUD_Handle handle = (*device)->play(*sound); - if(!handle.isNull()) - { + if (!handle.isNull()) { handle->seek(seek); return new AUD_Handle(handle); } @@ -783,12 +744,11 @@ AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek) return NULL; } -int AUD_setDeviceVolume(AUD_Device* device, float volume) +int AUD_setDeviceVolume(AUD_Device *device, float volume) { assert(device); - try - { + try { (*device)->setVolume(volume); return true; } @@ -797,13 +757,12 @@ int AUD_setDeviceVolume(AUD_Device* device, float volume) return false; } -int AUD_readDevice(AUD_Device* device, data_t* buffer, int length) +int AUD_readDevice(AUD_Device *device, data_t *buffer, int length) { assert(device); assert(buffer); - try - { + try { return (*device)->read(buffer, length); } catch(AUD_Exception&) @@ -812,12 +771,11 @@ int AUD_readDevice(AUD_Device* device, data_t* buffer, int length) } } -void AUD_closeReadDevice(AUD_Device* device) +void AUD_closeReadDevice(AUD_Device *device) { assert(device); - try - { + try { delete device; } catch(AUD_Exception&) @@ -825,10 +783,10 @@ void AUD_closeReadDevice(AUD_Device* device) } } -float* AUD_readSoundBuffer(const char* filename, float low, float high, - float attack, float release, float threshold, - int accumulate, int additive, int square, - float sthreshold, double samplerate, int* length) +float *AUD_readSoundBuffer(const char *filename, float low, float high, + float attack, float release, float threshold, + int accumulate, int additive, int square, + float sthreshold, double samplerate, int *length) { AUD_Buffer buffer; AUD_DeviceSpecs specs; @@ -840,33 +798,32 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high, int position = 0; - try - { + try { AUD_Reference<AUD_IReader> reader = file->createReader(); AUD_SampleRate rate = reader->getSpecs().rate; sound = new AUD_ChannelMapperFactory(file, specs); - if(high < rate) + if (high < rate) sound = new AUD_LowpassFactory(sound, high); - if(low > 0) + if (low > 0) sound = new AUD_HighpassFactory(sound, low); sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f); sound = new AUD_LinearResampleFactory(sound, specs); - if(square) + if (square) sound = new AUD_SquareFactory(sound, sthreshold); - if(accumulate) + if (accumulate) sound = new AUD_AccumulatorFactory(sound, additive); - else if(additive) + else if (additive) sound = new AUD_SumFactory(sound); reader = sound->createReader(); - if(reader.isNull()) + if (reader.isNull()) return NULL; int len; @@ -884,30 +841,28 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high, return NULL; } - float* result = (float*)malloc(position * sizeof(float)); + float * result = (float *)malloc(position * sizeof(float)); memcpy(result, buffer.getBuffer(), position * sizeof(float)); *length = position; return result; } -static void pauseSound(AUD_Handle* handle) +static void pauseSound(AUD_Handle *handle) { assert(handle); (*handle)->pause(); } -AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds) +AUD_Handle *AUD_pauseAfter(AUD_Handle *handle, float seconds) { AUD_Reference<AUD_IFactory> silence = new AUD_SilenceFactory; AUD_Reference<AUD_IFactory> limiter = new AUD_LimiterFactory(silence, 0, seconds); AUD_device->lock(); - try - { + try { AUD_Handle handle2 = AUD_device->play(limiter); - if(!handle2.isNull()) - { + if (!handle2.isNull()) { handle2->setStopCallback((stopCallback)pauseSound, handle); AUD_device->unlock(); return new AUD_Handle(handle2); @@ -922,125 +877,127 @@ AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds) return NULL; } -AUD_Sound* AUD_createSequencer(float fps, int muted) +AUD_Sound *AUD_createSequencer(float fps, int muted) { // specs are changed at a later point! AUD_Specs specs; specs.channels = AUD_CHANNELS_STEREO; specs.rate = AUD_RATE_44100; - AUD_Sound* sequencer = new AUD_Sound(AUD_Reference<AUD_SequencerFactory>(new AUD_SequencerFactory(specs, fps, muted))); + AUD_Sound *sequencer = new AUD_Sound(AUD_Reference<AUD_SequencerFactory>(new AUD_SequencerFactory(specs, fps, muted))); return sequencer; } -void AUD_destroySequencer(AUD_Sound* sequencer) +void AUD_destroySequencer(AUD_Sound *sequencer) { delete sequencer; } -void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted) +void AUD_setSequencerMuted(AUD_Sound *sequencer, int muted) { - dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->mute(muted); + dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->mute(muted); } -void AUD_setSequencerFPS(AUD_Sound* sequencer, float fps) +void AUD_setSequencerFPS(AUD_Sound *sequencer, float fps) { - dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setFPS(fps); + dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setFPS(fps); } -AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound, - float begin, float end, float skip) +AUD_SEntry *AUD_addSequence(AUD_Sound *sequencer, AUD_Sound *sound, + float begin, float end, float skip) { - if(!sound) - return new AUD_SEntry(((AUD_SequencerFactory*)sequencer->get())->add(AUD_Sound(), begin, end, skip)); - return new AUD_SEntry(((AUD_SequencerFactory*)sequencer->get())->add(*sound, begin, end, skip)); + if (!sound) + return new AUD_SEntry(((AUD_SequencerFactory *)sequencer->get())->add(AUD_Sound(), begin, end, skip)); + return new AUD_SEntry(((AUD_SequencerFactory *)sequencer->get())->add(*sound, begin, end, skip)); } -void AUD_removeSequence(AUD_Sound* sequencer, AUD_SEntry* entry) +void AUD_removeSequence(AUD_Sound *sequencer, AUD_SEntry *entry) { - dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->remove(*entry); + dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->remove(*entry); delete entry; } -void AUD_moveSequence(AUD_SEntry* entry, float begin, float end, float skip) +void AUD_moveSequence(AUD_SEntry *entry, float begin, float end, float skip) { (*entry)->move(begin, end, skip); } -void AUD_muteSequence(AUD_SEntry* entry, char mute) +void AUD_muteSequence(AUD_SEntry *entry, char mute) { (*entry)->mute(mute); } -void AUD_setRelativeSequence(AUD_SEntry* entry, char relative) +void AUD_setRelativeSequence(AUD_SEntry *entry, char relative) { (*entry)->setRelative(relative); } -void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound) +void AUD_updateSequenceSound(AUD_SEntry *entry, AUD_Sound *sound) { - if(sound) + if (sound) (*entry)->setSound(*sound); else (*entry)->setSound(AUD_Sound()); } -void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType type, int frame, float* data, char animated) +void AUD_setSequenceAnimData(AUD_SEntry *entry, AUD_AnimateablePropertyType type, int frame, float *data, char animated) { - AUD_AnimateableProperty* prop = (*entry)->getAnimProperty(type); - if(animated) - { - if(frame >= 0) + AUD_AnimateableProperty *prop = (*entry)->getAnimProperty(type); + if (animated) { + if (frame >= 0) prop->write(data, frame, 1); } - else + else { prop->write(data); + } } -void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateablePropertyType type, int frame, float* data, char animated) +void AUD_setSequencerAnimData(AUD_Sound *sequencer, AUD_AnimateablePropertyType type, int frame, float *data, char animated) { - AUD_AnimateableProperty* prop = dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->getAnimProperty(type); - if(animated) - { - if(frame >= 0) + AUD_AnimateableProperty *prop = dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->getAnimProperty(type); + if (animated) { + if (frame >= 0) { prop->write(data, frame, 1); + } } - else + else { prop->write(data); + } } -void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float volume_min, - float distance_max, float distance_reference, float attenuation, - float cone_angle_outer, float cone_angle_inner, float cone_volume_outer) +void AUD_updateSequenceData(AUD_SEntry *entry, float volume_max, float volume_min, + float distance_max, float distance_reference, float attenuation, + float cone_angle_outer, float cone_angle_inner, float cone_volume_outer) { (*entry)->updateAll(volume_max, volume_min, distance_max, distance_reference, attenuation, - cone_angle_outer, cone_angle_inner, cone_volume_outer); + cone_angle_outer, cone_angle_inner, cone_volume_outer); } -void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound, - float factor, AUD_DistanceModel model) +void AUD_updateSequencerData(AUD_Sound *sequencer, float speed_of_sound, + float factor, AUD_DistanceModel model) { - AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sequencer->get()); + AUD_SequencerFactory *f = dynamic_cast<AUD_SequencerFactory *>(sequencer->get()); f->setSpeedOfSound(speed_of_sound); f->setDopplerFactor(factor); f->setDistanceModel(model); } -void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer) +void AUD_setSequencerDeviceSpecs(AUD_Sound *sequencer) { - dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(AUD_device->getSpecs().specs); + dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setSpecs(AUD_device->getSpecs().specs); } -void AUD_setSequencerSpecs(AUD_Sound* sequencer, AUD_Specs specs) +void AUD_setSequencerSpecs(AUD_Sound *sequencer, AUD_Specs specs) { - dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(specs); + dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setSpecs(specs); } -void AUD_seekSequencer(AUD_Handle* handle, float time) +void AUD_seekSequencer(AUD_Handle *handle, float time) { #ifdef WITH_JACK - AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get()); - if(device) + AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get()); + if (device) { device->seekPlayback(time); + } else #endif { @@ -1049,12 +1006,13 @@ void AUD_seekSequencer(AUD_Handle* handle, float time) } } -float AUD_getSequencerPosition(AUD_Handle* handle) +float AUD_getSequencerPosition(AUD_Handle *handle) { #ifdef WITH_JACK - AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get()); - if(device) + AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get()); + if (device) { return device->getPlaybackPosition(); + } else #endif { @@ -1066,44 +1024,48 @@ float AUD_getSequencerPosition(AUD_Handle* handle) void AUD_startPlayback() { #ifdef WITH_JACK - AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get()); - if(device) + AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get()); + if (device) { device->startPlayback(); + } #endif } void AUD_stopPlayback() { #ifdef WITH_JACK - AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get()); - if(device) + AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get()); + if (device) { device->stopPlayback(); + } #endif } #ifdef WITH_JACK -void AUD_setSyncCallback(AUD_syncFunction function, void* data) +void AUD_setSyncCallback(AUD_syncFunction function, void *data) { - AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get()); - if(device) + AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get()); + if (device) { device->setSyncCallback(function, data); + } } #endif int AUD_doesPlayback() { #ifdef WITH_JACK - AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get()); - if(device) + AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get()); + if (device) { return device->doesPlayback(); + } #endif return -1; } -int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_per_second) +int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int samples_per_second) { AUD_DeviceSpecs specs; - sample_t* buf; + sample_t *buf; AUD_Buffer aBuffer; specs.rate = AUD_RATE_INVALID; @@ -1120,8 +1082,7 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe overallmax = 0; - for(int i = 0; i < length; i++) - { + for (int i = 0; i < length; i++) { len = floor(samplejump * (i+1)) - floor(samplejump * i); aBuffer.assureSize(len * AUD_SAMPLE_SIZE(specs)); @@ -1131,11 +1092,10 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe max = min = *buf; power = *buf * *buf; - for(int j = 1; j < len; j++) - { - if(buf[j] < min) + for (int j = 1; j < len; j++) { + if (buf[j] < min) min = buf[j]; - if(buf[j] > max) + if (buf[j] > max) max = buf[j]; power += buf[j] * buf[j]; } @@ -1144,22 +1104,19 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe buffer[i * 3 + 1] = max; buffer[i * 3 + 2] = sqrt(power) / len; - if(overallmax < max) + if (overallmax < max) overallmax = max; - if(overallmax < -min) + if (overallmax < -min) overallmax = -min; - if(eos) - { + if (eos) { length = i; break; } } - if(overallmax > 1.0f) - { - for(int i = 0; i < length * 3; i++) - { + if (overallmax > 1.0f) { + for (int i = 0; i < length * 3; i++) { buffer[i] /= overallmax; } } @@ -1167,48 +1124,46 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe return length; } -AUD_Sound* AUD_copy(AUD_Sound* sound) +AUD_Sound *AUD_copy(AUD_Sound *sound) { return new AUD_Reference<AUD_IFactory>(*sound); } -void AUD_freeHandle(AUD_Handle* handle) +void AUD_freeHandle(AUD_Handle *handle) { delete handle; } -void* AUD_createSet() +void *AUD_createSet() { - return new std::set<void*>(); + return new std::set<void *>(); } -void AUD_destroySet(void* set) +void AUD_destroySet(void *set) { - delete reinterpret_cast<std::set<void*>*>(set); + delete reinterpret_cast<std::set<void *>*>(set); } -char AUD_removeSet(void* set, void* entry) +char AUD_removeSet(void *set, void *entry) { - if(set) - return reinterpret_cast<std::set<void*>*>(set)->erase(entry); + if (set) + return reinterpret_cast<std::set<void *>*>(set)->erase(entry); return 0; } -void AUD_addSet(void* set, void* entry) +void AUD_addSet(void *set, void *entry) { - if(entry) - reinterpret_cast<std::set<void*>*>(set)->insert(entry); + if (entry) + reinterpret_cast<std::set<void *>*>(set)->insert(entry); } -void* AUD_getSet(void* set) +void *AUD_getSet(void *set) { - if(set) - { - std::set<void*>* rset = reinterpret_cast<std::set<void*>*>(set); - if(!rset->empty()) - { - std::set<void*>::iterator it = rset->begin(); - void* result = *it; + if (set) { + std::set<void *>* rset = reinterpret_cast<std::set<void *>*>(set); + if (!rset->empty()) { + std::set<void *>::iterator it = rset->begin(); + void *result = *it; rset->erase(it); return result; } @@ -1217,11 +1172,10 @@ void* AUD_getSet(void* set) return NULL; } -const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) +const char *AUD_mixdown(AUD_Sound *sound, unsigned int start, unsigned int length, unsigned int buffersize, const char *filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) { - try - { - AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sound->get()); + try { + AUD_SequencerFactory *f = dynamic_cast<AUD_SequencerFactory *>(sound->get()); f->setSpecs(specs.specs); AUD_Reference<AUD_IReader> reader = f->createQualityReader(); @@ -1237,11 +1191,10 @@ const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int lengt } } -const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) +const char *AUD_mixdown_per_channel(AUD_Sound *sound, unsigned int start, unsigned int length, unsigned int buffersize, const char *filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) { - try - { - AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sound->get()); + try { + AUD_SequencerFactory *f = dynamic_cast<AUD_SequencerFactory *>(sound->get()); f->setSpecs(specs.specs); @@ -1250,19 +1203,22 @@ const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsign int channels = specs.channels; specs.channels = AUD_CHANNELS_MONO; - for(int i = 0; i < channels; i++) - { + for (int i = 0; i < channels; i++) { std::stringstream stream; std::string fn = filename; size_t index = fn.find_last_of('.'); size_t index_slash = fn.find_last_of('/'); size_t index_backslash = fn.find_last_of('\\'); - if((index == std::string::npos) || - ((index < index_slash) && (index_slash != std::string::npos)) || - ((index < index_backslash) && (index_backslash != std::string::npos))) + + if ((index == std::string::npos) || + ((index < index_slash) && (index_slash != std::string::npos)) || + ((index < index_backslash) && (index_backslash != std::string::npos))) + { stream << filename << "_" << (i + 1); - else + } + else { stream << fn.substr(0, index) << "_" << (i + 1) << fn.substr(index); + } writers.push_back(AUD_FileWriter::createWriter(stream.str(), specs, format, codec, bitrate)); } @@ -1278,19 +1234,19 @@ const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsign } } -AUD_Device* AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound* sequencer, float volume, float start) +AUD_Device *AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound *sequencer, float volume, float start) { - try - { - AUD_ReadDevice* device = new AUD_ReadDevice(specs); + try { + AUD_ReadDevice *device = new AUD_ReadDevice(specs); device->setQuality(true); device->setVolume(volume); - dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(specs.specs); + dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setSpecs(specs.specs); AUD_Handle handle = device->play(*sequencer); - if(!handle.isNull()) + if (!handle.isNull()) { handle->seek(start); + } return new AUD_Device(device); } @@ -1305,7 +1261,7 @@ AUD_Reference<AUD_IDevice> AUD_getDevice() return AUD_device; } -AUD_I3DDevice* AUD_get3DDevice() +AUD_I3DDevice *AUD_get3DDevice() { return AUD_3ddevice; } diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h index 6af0c648d0e..75e3456de9a 100644 --- a/intern/audaspace/intern/AUD_C-API.h +++ b/intern/audaspace/intern/AUD_C-API.h @@ -56,8 +56,8 @@ typedef struct typedef void AUD_Handle; typedef void AUD_Device; typedef void AUD_SEntry; - typedef float (*AUD_volumeFunction)(void*, void*, float); - typedef void (*AUD_syncFunction)(void*, int, float); + typedef float (*AUD_volumeFunction)(void *, void *, float); + typedef void (*AUD_syncFunction)(void *, int, float); #endif /** @@ -94,14 +94,14 @@ extern void AUD_unlock(void); * \param sound The sound to get the info about. * \return The AUD_SoundInfo structure with filled in data. */ -extern AUD_SoundInfo AUD_getInfo(AUD_Sound* sound); +extern AUD_SoundInfo AUD_getInfo(AUD_Sound *sound); /** * Loads a sound file. * \param filename The filename of the sound file. * \return A handle of the sound file. */ -extern AUD_Sound* AUD_load(const char* filename); +extern AUD_Sound *AUD_load(const char *filename); /** * Loads a sound file. @@ -109,21 +109,21 @@ extern AUD_Sound* AUD_load(const char* filename); * \param size The size of the buffer. * \return A handle of the sound file. */ -extern AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size); +extern AUD_Sound *AUD_loadBuffer(unsigned char *buffer, int size); /** * Buffers a sound. * \param sound The sound to buffer. * \return A handle of the sound buffer. */ -extern AUD_Sound* AUD_bufferSound(AUD_Sound* sound); +extern AUD_Sound *AUD_bufferSound(AUD_Sound *sound); /** * Rechannels the sound to be mono. * \param sound The sound to rechannel. * \return The mono sound. */ -extern AUD_Sound* AUD_monoSound(AUD_Sound* sound); +extern AUD_Sound *AUD_monoSound(AUD_Sound *sound); /** * Delays a sound. @@ -131,7 +131,7 @@ extern AUD_Sound* AUD_monoSound(AUD_Sound* sound); * \param delay The delay in seconds. * \return A handle of the delayed sound. */ -extern AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay); +extern AUD_Sound *AUD_delaySound(AUD_Sound *sound, float delay); /** * Limits a sound. @@ -140,21 +140,21 @@ extern AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay); * \param end The stop time in seconds. * \return A handle of the limited sound. */ -extern AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end); +extern AUD_Sound *AUD_limitSound(AUD_Sound *sound, float start, float end); /** * Ping pongs a sound. * \param sound The sound to ping pong. * \return A handle of the ping pong sound. */ -extern AUD_Sound* AUD_pingpongSound(AUD_Sound* sound); +extern AUD_Sound *AUD_pingpongSound(AUD_Sound *sound); /** * Loops a sound. * \param sound The sound to loop. * \return A handle of the looped sound. */ -extern AUD_Sound* AUD_loopSound(AUD_Sound* sound); +extern AUD_Sound *AUD_loopSound(AUD_Sound *sound); /** * Sets a remaining loop count of a looping sound that currently plays. @@ -162,20 +162,20 @@ extern AUD_Sound* AUD_loopSound(AUD_Sound* sound); * \param loops The count of remaining loops, -1 for infinity. * \return Whether the handle is valid. */ -extern int AUD_setLoop(AUD_Handle* handle, int loops); +extern int AUD_setLoop(AUD_Handle *handle, int loops); /** * Rectifies a sound. * \param sound The sound to rectify. * \return A handle of the rectified sound. */ -extern AUD_Sound* AUD_rectifySound(AUD_Sound* sound); +extern AUD_Sound *AUD_rectifySound(AUD_Sound *sound); /** * Unloads a sound of any type. * \param sound The handle of the sound. */ -extern void AUD_unload(AUD_Sound* sound); +extern void AUD_unload(AUD_Sound *sound); /** * Plays back a sound file. @@ -184,28 +184,28 @@ extern void AUD_unload(AUD_Sound* sound); * paused when its end has been reached. * \return A handle to the played back sound. */ -extern AUD_Handle* AUD_play(AUD_Sound* sound, int keep); +extern AUD_Handle *AUD_play(AUD_Sound *sound, int keep); /** * Pauses a played back sound. * \param handle The handle to the sound. * \return Whether the handle has been playing or not. */ -extern int AUD_pause(AUD_Handle* handle); +extern int AUD_pause(AUD_Handle *handle); /** * Resumes a paused sound. * \param handle The handle to the sound. * \return Whether the handle has been paused or not. */ -extern int AUD_resume(AUD_Handle* handle); +extern int AUD_resume(AUD_Handle *handle); /** * Stops a playing or paused sound. * \param handle The handle to the sound. * \return Whether the handle has been valid or not. */ -extern int AUD_stop(AUD_Handle* handle); +extern int AUD_stop(AUD_Handle *handle); /** * Sets the end behaviour of a playing or paused sound. @@ -214,7 +214,7 @@ extern int AUD_stop(AUD_Handle* handle); * paused when its end has been reached. * \return Whether the handle has been valid or not. */ -extern int AUD_setKeep(AUD_Handle* handle, int keep); +extern int AUD_setKeep(AUD_Handle *handle, int keep); /** * Seeks a playing or paused sound. @@ -222,7 +222,7 @@ extern int AUD_setKeep(AUD_Handle* handle, int keep); * \param seekTo From where the sound file should be played back in seconds. * \return Whether the handle has been valid or not. */ -extern int AUD_seek(AUD_Handle* handle, float seekTo); +extern int AUD_seek(AUD_Handle *handle, float seekTo); /** * Retrieves the playback position of a handle. @@ -230,32 +230,32 @@ extern int AUD_seek(AUD_Handle* handle, float seekTo); * \return The current playback position in seconds or 0.0 if the handle is * invalid. */ -extern float AUD_getPosition(AUD_Handle* handle); +extern float AUD_getPosition(AUD_Handle *handle); /** * Returns the status of a playing, paused or stopped sound. * \param handle The handle to the sound. * \return The status of the sound behind the handle. */ -extern AUD_Status AUD_getStatus(AUD_Handle* handle); +extern AUD_Status AUD_getStatus(AUD_Handle *handle); /** * Sets the listener location. * \param location The new location. */ -extern int AUD_setListenerLocation(const float* location); +extern int AUD_setListenerLocation(const float location[3]); /** * Sets the listener velocity. * \param velocity The new velocity. */ -extern int AUD_setListenerVelocity(const float* velocity); +extern int AUD_setListenerVelocity(const float velocity[3]); /** * Sets the listener orientation. * \param orientation The new orientation as quaternion. */ -extern int AUD_setListenerOrientation(const float* orientation); +extern int AUD_setListenerOrientation(const float orientation[4]); /** * Sets the speed of sound. @@ -284,7 +284,7 @@ extern int AUD_setDistanceModel(AUD_DistanceModel model); * \param location The new location. * \return Whether the action succeeded. */ -extern int AUD_setSourceLocation(AUD_Handle* handle, const float* location); +extern int AUD_setSourceLocation(AUD_Handle *handle, const float location[3]); /** * Sets the velocity of a source. @@ -292,7 +292,7 @@ extern int AUD_setSourceLocation(AUD_Handle* handle, const float* location); * \param velocity The new velocity. * \return Whether the action succeeded. */ -extern int AUD_setSourceVelocity(AUD_Handle* handle, const float* velocity); +extern int AUD_setSourceVelocity(AUD_Handle *handle, const float velocity[3]); /** * Sets the orientation of a source. @@ -300,7 +300,7 @@ extern int AUD_setSourceVelocity(AUD_Handle* handle, const float* velocity); * \param orientation The new orientation as quaternion. * \return Whether the action succeeded. */ -extern int AUD_setSourceOrientation(AUD_Handle* handle, const float* orientation); +extern int AUD_setSourceOrientation(AUD_Handle *handle, const float orientation[4]); /** * Sets whether the source location, velocity and orientation are relative @@ -309,7 +309,7 @@ extern int AUD_setSourceOrientation(AUD_Handle* handle, const float* orientation * \param relative Whether the source is relative. * \return Whether the action succeeded. */ -extern int AUD_setRelative(AUD_Handle* handle, int relative); +extern int AUD_setRelative(AUD_Handle *handle, int relative); /** * Sets the maximum volume of a source. @@ -317,7 +317,7 @@ extern int AUD_setRelative(AUD_Handle* handle, int relative); * \param volume The new maximum volume. * \return Whether the action succeeded. */ -extern int AUD_setVolumeMaximum(AUD_Handle* handle, float volume); +extern int AUD_setVolumeMaximum(AUD_Handle *handle, float volume); /** * Sets the minimum volume of a source. @@ -325,7 +325,7 @@ extern int AUD_setVolumeMaximum(AUD_Handle* handle, float volume); * \param volume The new minimum volume. * \return Whether the action succeeded. */ -extern int AUD_setVolumeMinimum(AUD_Handle* handle, float volume); +extern int AUD_setVolumeMinimum(AUD_Handle *handle, float volume); /** * Sets the maximum distance of a source. @@ -335,7 +335,7 @@ extern int AUD_setVolumeMinimum(AUD_Handle* handle, float volume); * \param distance The new maximum distance. * \return Whether the action succeeded. */ -extern int AUD_setDistanceMaximum(AUD_Handle* handle, float distance); +extern int AUD_setDistanceMaximum(AUD_Handle *handle, float distance); /** * Sets the reference distance of a source. @@ -343,7 +343,7 @@ extern int AUD_setDistanceMaximum(AUD_Handle* handle, float distance); * \param distance The new reference distance. * \return Whether the action succeeded. */ -extern int AUD_setDistanceReference(AUD_Handle* handle, float distance); +extern int AUD_setDistanceReference(AUD_Handle *handle, float distance); /** * Sets the attenuation of a source. @@ -352,7 +352,7 @@ extern int AUD_setDistanceReference(AUD_Handle* handle, float distance); * \param factor The new attenuation. * \return Whether the action succeeded. */ -extern int AUD_setAttenuation(AUD_Handle* handle, float factor); +extern int AUD_setAttenuation(AUD_Handle *handle, float factor); /** * Sets the outer angle of the cone of a source. @@ -360,7 +360,7 @@ extern int AUD_setAttenuation(AUD_Handle* handle, float factor); * \param angle The new outer angle of the cone. * \return Whether the action succeeded. */ -extern int AUD_setConeAngleOuter(AUD_Handle* handle, float angle); +extern int AUD_setConeAngleOuter(AUD_Handle *handle, float angle); /** * Sets the inner angle of the cone of a source. @@ -368,7 +368,7 @@ extern int AUD_setConeAngleOuter(AUD_Handle* handle, float angle); * \param angle The new inner angle of the cone. * \return Whether the action succeeded. */ -extern int AUD_setConeAngleInner(AUD_Handle* handle, float angle); +extern int AUD_setConeAngleInner(AUD_Handle *handle, float angle); /** * Sets the outer volume of the cone of a source. @@ -378,7 +378,7 @@ extern int AUD_setConeAngleInner(AUD_Handle* handle, float angle); * \param volume The new outer volume of the cone. * \return Whether the action succeeded. */ -extern int AUD_setConeVolumeOuter(AUD_Handle* handle, float volume); +extern int AUD_setConeVolumeOuter(AUD_Handle *handle, float volume); /** * Sets the volume of a played back sound. @@ -386,7 +386,7 @@ extern int AUD_setConeVolumeOuter(AUD_Handle* handle, float volume); * \param volume The new volume, must be between 0.0 and 1.0. * \return Whether the action succeeded. */ -extern int AUD_setSoundVolume(AUD_Handle* handle, float volume); +extern int AUD_setSoundVolume(AUD_Handle *handle, float volume); /** * Sets the pitch of a played back sound. @@ -394,14 +394,14 @@ extern int AUD_setSoundVolume(AUD_Handle* handle, float volume); * \param pitch The new pitch. * \return Whether the action succeeded. */ -extern int AUD_setSoundPitch(AUD_Handle* handle, float pitch); +extern int AUD_setSoundPitch(AUD_Handle *handle, float pitch); /** * Opens a read device, with which audio data can be read. * \param specs The specification of the audio data. * \return A device handle. */ -extern AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs); +extern AUD_Device *AUD_openReadDevice(AUD_DeviceSpecs specs); /** * Sets the main volume of a device. @@ -409,7 +409,7 @@ extern AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs); * \param volume The new volume, must be between 0.0 and 1.0. * \return Whether the action succeeded. */ -extern int AUD_setDeviceVolume(AUD_Device* device, float volume); +extern int AUD_setDeviceVolume(AUD_Device *device, float volume); /** * Plays back a sound file through a read device. @@ -418,7 +418,7 @@ extern int AUD_setDeviceVolume(AUD_Device* device, float volume); * \param seek The position where the sound should be seeked to. * \return A handle to the played back sound. */ -extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek); +extern AUD_Handle *AUD_playDevice(AUD_Device *device, AUD_Sound *sound, float seek); /** * Reads the next samples into the supplied buffer. @@ -429,23 +429,23 @@ extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float se * played back currently, in that case the buffer is filled with * silence. */ -extern int AUD_readDevice(AUD_Device* device, data_t* buffer, int length); +extern int AUD_readDevice(AUD_Device *device, data_t *buffer, int length); /** * Closes a read device. * \param device The read device. */ -extern void AUD_closeReadDevice(AUD_Device* device); +extern void AUD_closeReadDevice(AUD_Device *device); /** * Reads a sound file into a newly created float buffer. * The sound is therefore bandpassed, rectified and resampled. */ -extern float* AUD_readSoundBuffer(const char* filename, float low, float high, +extern float *AUD_readSoundBuffer(const char *filename, float low, float high, float attack, float release, float threshold, int accumulate, int additive, int square, float sthreshold, double samplerate, - int* length); + int *length); /** * Pauses a playing sound after a specific amount of time. @@ -453,7 +453,7 @@ extern float* AUD_readSoundBuffer(const char* filename, float low, float high, * \param seconds The time in seconds. * \return The silence handle. */ -extern AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds); +extern AUD_Handle *AUD_pauseAfter(AUD_Handle *handle, float seconds); /** * Creates a new sequenced sound scene. @@ -461,27 +461,27 @@ extern AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds); * \param muted Whether the scene is muted. * \return The new sound scene. */ -extern AUD_Sound* AUD_createSequencer(float fps, int muted); +extern AUD_Sound *AUD_createSequencer(float fps, int muted); /** * Deletes a sound scene. * \param sequencer The sound scene. */ -extern void AUD_destroySequencer(AUD_Sound* sequencer); +extern void AUD_destroySequencer(AUD_Sound *sequencer); /** * Sets the muting state of the scene. * \param sequencer The sound scene. * \param muted Whether the scene is muted. */ -extern void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted); +extern void AUD_setSequencerMuted(AUD_Sound *sequencer, int muted); /** * Sets the scene's FPS. * \param sequencer The sound scene. * \param fps The new FPS. */ -extern void AUD_setSequencerFPS(AUD_Sound* sequencer, float fps); +extern void AUD_setSequencerFPS(AUD_Sound *sequencer, float fps); /** * Adds a new entry to the scene. @@ -492,7 +492,7 @@ extern void AUD_setSequencerFPS(AUD_Sound* sequencer, float fps); * \param skip How much seconds should be skipped at the beginning. * \return The entry added. */ -extern AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound, +extern AUD_SEntry *AUD_addSequence(AUD_Sound *sequencer, AUD_Sound *sound, float begin, float end, float skip); /** @@ -500,7 +500,7 @@ extern AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound, * \param sequencer The sound scene. * \param entry The entry to remove. */ -extern void AUD_removeSequence(AUD_Sound* sequencer, AUD_SEntry* entry); +extern void AUD_removeSequence(AUD_Sound *sequencer, AUD_SEntry *entry); /** * Moves the entry. @@ -509,14 +509,14 @@ extern void AUD_removeSequence(AUD_Sound* sequencer, AUD_SEntry* entry); * \param end The new end time or a negative value if unknown. * \param skip How many seconds to skip at the beginning. */ -extern void AUD_moveSequence(AUD_SEntry* entry, float begin, float end, float skip); +extern void AUD_moveSequence(AUD_SEntry *entry, float begin, float end, float skip); /** * Sets the muting state of the entry. * \param entry The sequenced entry. * \param mute Whether the entry should be muted or not. */ -extern void AUD_muteSequence(AUD_SEntry* entry, char mute); +extern void AUD_muteSequence(AUD_SEntry *entry, char mute); /** * Sets whether the entrie's location, velocity and orientation are relative @@ -525,14 +525,14 @@ extern void AUD_muteSequence(AUD_SEntry* entry, char mute); * \param relative Whether the source is relative. * \return Whether the action succeeded. */ -extern void AUD_setRelativeSequence(AUD_SEntry* entry, char relative); +extern void AUD_setRelativeSequence(AUD_SEntry *entry, char relative); /** * Sets the sound of the entry. * \param entry The sequenced entry. * \param sound The new sound. */ -extern void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound); +extern void AUD_updateSequenceSound(AUD_SEntry *entry, AUD_Sound *sound); /** * Writes animation data to a sequenced entry. @@ -542,7 +542,7 @@ extern void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound); * \param data The data to write. * \param animated Whether the attribute is animated. */ -extern void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType type, int frame, float* data, char animated); +extern void AUD_setSequenceAnimData(AUD_SEntry *entry, AUD_AnimateablePropertyType type, int frame, float *data, char animated); /** * Writes animation data to a sequenced entry. @@ -552,7 +552,7 @@ extern void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyTy * \param data The data to write. * \param animated Whether the attribute is animated. */ -extern void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateablePropertyType type, int frame, float* data, char animated); +extern void AUD_setSequencerAnimData(AUD_Sound *sequencer, AUD_AnimateablePropertyType type, int frame, float *data, char animated); /** * Updates all non-animated parameters of the entry. @@ -566,7 +566,7 @@ extern void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateableProper * \param cone_angle_inner The inner cone opening angle. * \param cone_volume_outer The volume outside the outer cone. */ -extern void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float volume_min, +extern void AUD_updateSequenceData(AUD_SEntry *entry, float volume_max, float volume_min, float distance_max, float distance_reference, float attenuation, float cone_angle_outer, float cone_angle_inner, float cone_volume_outer); @@ -577,7 +577,7 @@ extern void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float vo * \param factor The doppler factor to control the effect's strength. * \param model The distance model for distance calculation. */ -extern void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound, +extern void AUD_updateSequencerData(AUD_Sound *sequencer, float speed_of_sound, float factor, AUD_DistanceModel model); /** @@ -585,28 +585,28 @@ extern void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound, * current playback device. * \param sequencer The sound scene. */ -extern void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer); +extern void AUD_setSequencerDeviceSpecs(AUD_Sound *sequencer); /** * Sets the audio output specification of the sound scene. * \param sequencer The sound scene. * \param specs The new specification. */ -extern void AUD_setSequencerSpecs(AUD_Sound* sequencer, AUD_Specs specs); +extern void AUD_setSequencerSpecs(AUD_Sound *sequencer, AUD_Specs specs); /** * Seeks sequenced sound scene playback. * \param handle Playback handle. * \param time Time in seconds to seek to. */ -extern void AUD_seekSequencer(AUD_Handle* handle, float time); +extern void AUD_seekSequencer(AUD_Handle *handle, float time); /** * Returns the current sound scene playback time. * \param handle Playback handle. * \return The playback time in seconds. */ -extern float AUD_getSequencerPosition(AUD_Handle* handle); +extern float AUD_getSequencerPosition(AUD_Handle *handle); /** * Starts the playback of jack transport if possible. @@ -624,7 +624,7 @@ extern void AUD_stopPlayback(void); * \param function The callback function. * \param data The data parameter for the callback. */ -extern void AUD_setSyncCallback(AUD_syncFunction function, void* data); +extern void AUD_setSyncCallback(AUD_syncFunction function, void *data); #endif /** @@ -641,32 +641,32 @@ extern int AUD_doesPlayback(void); * \param samples_per_second How many samples to read per second of the sound. * \return How many samples really have been read. Always <= length. */ -extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_per_second); +extern int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int samples_per_second); /** * Copies a sound. * \param sound Sound to copy. * \return Copied sound. */ -extern AUD_Sound* AUD_copy(AUD_Sound* sound); +extern AUD_Sound *AUD_copy(AUD_Sound *sound); /** * Frees a handle. * \param channel Handle to free. */ -extern void AUD_freeHandle(AUD_Handle* channel); +extern void AUD_freeHandle(AUD_Handle *channel); /** * Creates a new set. * \return The new set. */ -extern void* AUD_createSet(void); +extern void *AUD_createSet(void); /** * Deletes a set. * \param set The set to delete. */ -extern void AUD_destroySet(void* set); +extern void AUD_destroySet(void *set); /** * Removes an entry from a set. @@ -674,21 +674,21 @@ extern void AUD_destroySet(void* set); * \param entry The entry to remove. * \return Whether the entry was in the set or not. */ -extern char AUD_removeSet(void* set, void* entry); +extern char AUD_removeSet(void *set, void *entry); /** * Adds a new entry to a set. * \param set The set work on. * \param entry The entry to add. */ -extern void AUD_addSet(void* set, void* entry); +extern void AUD_addSet(void *set, void *entry); /** * Removes one entry from a set and returns it. * \param set The set work on. * \return The entry or NULL if the set is empty. */ -extern void* AUD_getSet(void* set); +extern void *AUD_getSet(void *set); /** * Mixes a sound down into a file. @@ -703,7 +703,10 @@ extern void* AUD_getSet(void* set); * \param bitrate The bitrate for encoding. * \return An error message or NULL in case of success. */ -extern const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate); +extern const char *AUD_mixdown(AUD_Sound *sound, unsigned int start, unsigned int length, + unsigned int buffersize, const char *filename, + AUD_DeviceSpecs specs, AUD_Container format, + AUD_Codec codec, unsigned int bitrate); /** * Mixes a sound down into multiple files. @@ -718,7 +721,10 @@ extern const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned in * \param bitrate The bitrate for encoding. * \return An error message or NULL in case of success. */ -extern const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate); +extern const char *AUD_mixdown_per_channel(AUD_Sound *sound, unsigned int start, unsigned int length, + unsigned int buffersize, const char *filename, + AUD_DeviceSpecs specs, AUD_Container format, + AUD_Codec codec, unsigned int bitrate); /** * Opens a read device and prepares it for mixdown of the sound scene. @@ -728,7 +734,7 @@ extern const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, * \param start The start time of the mixdown in the sound scene. * \return The read device for the mixdown. */ -extern AUD_Device* AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound* sequencer, float volume, float start); +extern AUD_Device *AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound *sequencer, float volume, float start); #ifdef WITH_PYTHON /** @@ -736,14 +742,14 @@ extern AUD_Device* AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound* seque * \param sound The sound factory. * \return The python factory. */ -extern void* AUD_getPythonFactory(AUD_Sound* sound); +extern void *AUD_getPythonFactory(AUD_Sound *sound); /** * Retrieves the sound factory of a python factory. * \param sound The python factory. * \return The sound factory. */ -extern AUD_Sound* AUD_getPythonSound(void* sound); +extern AUD_Sound *AUD_getPythonSound(void *sound); #endif #ifdef __cplusplus @@ -763,7 +769,7 @@ AUD_Reference<AUD_IDevice> AUD_getDevice(); * Returns the current playback 3D device. * \return The playback 3D device. */ -AUD_I3DDevice* AUD_get3DDevice(); +AUD_I3DDevice *AUD_get3DDevice(); #endif #endif //__AUD_C_API_H__ diff --git a/intern/audaspace/intern/AUD_ReferenceHandler.cpp b/intern/audaspace/intern/AUD_ReferenceHandler.cpp index 3e9f6707262..6aa4f87ea96 100644 --- a/intern/audaspace/intern/AUD_ReferenceHandler.cpp +++ b/intern/audaspace/intern/AUD_ReferenceHandler.cpp @@ -22,7 +22,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file audaspace/intern/AUD_Reference.cpp +/** \file audaspace/intern/AUD_ReferenceHandler.cpp * \ingroup audaspaceintern */ diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index 697427081c3..337eebe4be0 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -20,8 +20,8 @@ elseif(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math") endif() -# for OSL, not needed yet -# set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID") +# for OSL +set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID") # set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID") # Definitions and Includes diff --git a/intern/cycles/app/cycles_test.cpp b/intern/cycles/app/cycles_test.cpp index 75f76efc8e1..e921cc46fe4 100644 --- a/intern/cycles/app/cycles_test.cpp +++ b/intern/cycles/app/cycles_test.cpp @@ -66,12 +66,13 @@ static void session_print(const string& str) static void session_print_status() { - int sample; + int sample, tile; double total_time, sample_time; string status, substatus; /* get status */ - options.session->progress.get_sample(sample, total_time, sample_time); + sample = options.session->progress.get_sample(); + options.session->progress.get_tile(tile, total_time, sample_time); options.session->progress.get_status(status, substatus); if(substatus != "") @@ -111,7 +112,7 @@ static void session_init() static void scene_init(int width, int height) { - options.scene = new Scene(options.scene_params); + options.scene = new Scene(options.scene_params, options.session_params.device); xml_read_file(options.scene, options.filepath.c_str()); if (width == 0 || height == 0) { @@ -147,11 +148,12 @@ static void display_info(Progress& progress) latency = (elapsed - last); last = elapsed; - int sample; + int sample, tile; double total_time, sample_time; string status, substatus; - progress.get_sample(sample, total_time, sample_time); + sample = progress.get_sample(); + progress.get_tile(tile, total_time, sample_time); progress.get_status(status, substatus); if(substatus != "") @@ -270,6 +272,9 @@ static void options_parse(int argc, const char **argv) options.scene_params.shadingsystem = SceneParams::OSL; else if(ssname == "svm") options.scene_params.shadingsystem = SceneParams::SVM; + + /* Progressive rendering */ + options.session_params.progressive = true; /* find matching device */ DeviceType device_type = Device::type_from_string(devicename.c_str()); diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index 5ec5cb929d6..87a238e508c 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -379,6 +379,9 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug else if(string_iequals(node.name(), "checker_texture")) { snode = new CheckerTextureNode(); } + else if(string_iequals(node.name(), "brick_texture")) { + snode = new BrickTextureNode(); + } else if(string_iequals(node.name(), "gradient_texture")) { GradientTextureNode *blend = new GradientTextureNode(); xml_read_enum(&blend->type, GradientTextureNode::type_enum, node, "type"); @@ -484,6 +487,7 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug else if(string_iequals(node.name(), "mix")) { MixNode *mix = new MixNode(); xml_read_enum(&mix->type, MixNode::type_enum, node, "type"); + xml_read_bool(&mix->use_clamp, node, "use_clamp"); snode = mix; } else if(string_iequals(node.name(), "gamma")) { @@ -515,6 +519,7 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug else if(string_iequals(node.name(), "math")) { MathNode *math = new MathNode(); xml_read_enum(&math->type, MathNode::type_enum, node, "type"); + xml_read_bool(&math->use_clamp, node, "use_clamp"); snode = math; } else if(string_iequals(node.name(), "vector_math")) { diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index 7a22cba316e..7f3eca471e6 100644 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@ -241,12 +241,14 @@ class CyclesRenderSettings(bpy.types.PropertyGroup): min=1, max=4096, default=1024, ) - cls.debug_min_size = IntProperty( - name="Min Size", - description="", - min=1, max=4096, - default=64, + + cls.resolution_divider = IntProperty( + name="Resolution Divider", + description="For viewport render, the number of lower resolutions to render before the full resolution", + min=1, max=512, + default=4, ) + cls.debug_reset_timeout = FloatProperty( name="Reset timeout", description="", diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 5234db5255e..7486edf2319 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -53,19 +53,20 @@ class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel): scene = context.scene cscene = scene.cycles + device_type = context.user_preferences.system.compute_device_type split = layout.split() col = split.column() sub = col.column() - sub.active = cscene.device == 'CPU' + sub.enabled = (device_type == 'NONE' or cscene.device == 'CPU') sub.prop(cscene, "progressive") sub = col.column(align=True) sub.prop(cscene, "seed") sub.prop(cscene, "sample_clamp") - if cscene.progressive or cscene.device != 'CPU': + if cscene.progressive or (device_type != 'NONE' and cscene.device == 'GPU'): col = split.column() col.label(text="Samples:") sub = col.column(align=True) @@ -197,8 +198,13 @@ class CyclesRender_PT_performance(CyclesButtonsPanel, Panel): sub = col.column(align=True) sub.label(text="Tiles:") - sub.prop(cscene, "debug_tile_size") - sub.prop(cscene, "debug_min_size") + + sub.prop(rd, "parts_x", text="X") + sub.prop(rd, "parts_y", text="Y") + + subsub = sub.column() + subsub.enabled = not rd.use_border + subsub.prop(rd, "use_save_buffers") col = split.column() @@ -208,6 +214,10 @@ class CyclesRender_PT_performance(CyclesButtonsPanel, Panel): sub.prop(cscene, "debug_use_spatial_splits") sub.prop(cscene, "use_cache") + sub = col.column(align=True) + sub.label(text="Viewport:") + sub.prop(cscene, "resolution_divider") + class CyclesRender_PT_layers(CyclesButtonsPanel, Panel): bl_label = "Layers" @@ -920,6 +930,9 @@ def draw_device(self, context): layout.prop(cscene, "device") elif device_type == 'OPENCL' and cscene.feature_set == 'EXPERIMENTAL': layout.prop(cscene, "device") + + if cscene.feature_set == 'EXPERIMENTAL' and cscene.device == 'CPU' and engine.with_osl(): + layout.prop(cscene, "shading_system") def draw_pause(self, context): diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 16e4ceded89..9764f24a893 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -317,11 +317,11 @@ void BlenderSync::sync_mesh_motion(BL::Object b_ob, Mesh *mesh, int motion) BL::Mesh::vertices_iterator v; AttributeStandard std = (motion == -1)? ATTR_STD_MOTION_PRE: ATTR_STD_MOTION_POST; Attribute *attr_M = mesh->attributes.add(std); - float3 *M = attr_M->data_float3(); + float3 *M = attr_M->data_float3(), *cur_M; size_t i = 0; - for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end() && i < size; ++v, M++, i++) - *M = get_float3(v->co()); + for(b_mesh.vertices.begin(v), cur_M = M; v != b_mesh.vertices.end() && i < size; ++v, cur_M++, i++) + *cur_M = get_float3(v->co()); /* if number of vertices changed, or if coordinates stayed the same, drop it */ if(i != size || memcmp(M, &mesh->verts[0], sizeof(float3)*size) == 0) diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index eb9cc7bc4de..eb9deb0de2d 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -247,11 +247,10 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, scene->object_manager->tag_update(scene); } - /* updated dupli objects require particle sync */ - bool need_particle_update = object_need_particle_update(b_ob); - /* object sync */ - if(object_updated || (object->mesh && object->mesh->need_update) || need_particle_update) { + /* transform comparison should not be needed, but duplis don't work perfect + * in the depsgraph and may not signal changes, so this is a workaround */ + if(object_updated || (object->mesh && object->mesh->need_update) || tfm != object->tfm) { object->name = b_ob.name().c_str(); object->pass_id = b_ob.pass_index(); object->tfm = tfm; @@ -277,10 +276,6 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, object->particle_id = particle_id; - /* particle sync */ - if (need_particle_update) - sync_particles(object, b_ob); - object->tag_update(scene); } } @@ -303,16 +298,18 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion) /* object loop */ BL::Scene::objects_iterator b_ob; BL::Scene b_sce = b_scene; - int particle_offset = 0; + int particle_offset = 1; /* first particle is dummy for regular, non-instanced objects */ + + bool cancel = false; - for(; b_sce; b_sce = b_sce.background_set()) { - for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end(); ++b_ob) { + for(; b_sce && !cancel; b_sce = b_sce.background_set()) { + for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end() && !cancel; ++b_ob) { bool hide = (render_layer.use_viewport_visibility)? b_ob->hide(): b_ob->hide_render(); - uint ob_layer = get_layer(b_ob->layers(), b_ob->layers_local_view(), object_is_light(*b_ob)); - CYCLES_LOCAL_LAYER_HACK(render_layer.use_localview, ob_layer); + uint ob_layer = get_layer(b_ob->layers(), b_ob->layers_local_view(), render_layer.use_localview, object_is_light(*b_ob)); hide = hide || !(ob_layer & scene_layer); if(!hide) { + progress.set_status("Synchronizing object", (*b_ob).name()); int num_particles = object_count_particles(*b_ob); @@ -354,10 +351,12 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion) particle_offset += num_particles; } + + cancel = progress.get_cancel(); } } - if(!motion) { + if(!cancel && !motion) { sync_background_light(); /* handle removed data and modified pointers */ diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp index e32c80a51b5..f309960fc55 100644 --- a/intern/cycles/blender/blender_particles.cpp +++ b/intern/cycles/blender/blender_particles.cpp @@ -16,9 +16,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "object.h" - #include "mesh.h" +#include "particles.h" + #include "blender_sync.h" #include "blender_util.h" @@ -31,7 +31,7 @@ CCL_NAMESPACE_BEGIN /* Particles Sync */ -bool BlenderSync::object_need_particle_update(BL::Object b_ob) +bool BlenderSync::psys_need_update(BL::ParticleSystem b_psys) { /* Particle data is only needed for * a) Billboard render mode if object's own material uses particle info @@ -41,9 +41,7 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) */ bool need_update = false; - BL::Object::particle_systems_iterator b_psys; - for (b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { - switch (b_psys->settings().render_type()) { + switch (b_psys.settings().render_type()) { /* XXX not implemented yet! * billboards/strands would become part of the mesh data (?), * so the mesh attributes would store whether particle info is required. @@ -61,7 +59,7 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) #endif case BL::ParticleSettings::render_type_OBJECT: { - BL::Object b_dupli_ob = b_psys->settings().dupli_object(); + BL::Object b_dupli_ob = b_psys.settings().dupli_object(); if (b_dupli_ob) { BL::ID key = (BKE_object_is_modified(b_dupli_ob))? b_dupli_ob: b_dupli_ob.data(); Mesh *mesh = mesh_map.find(key); @@ -73,7 +71,7 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) } case BL::ParticleSettings::render_type_GROUP: { - BL::Group b_dupli_group = b_psys->settings().dupli_group(); + BL::Group b_dupli_group = b_psys.settings().dupli_group(); if (b_dupli_group) { BL::Group::objects_iterator b_gob; for (b_dupli_group.objects.begin(b_gob); b_gob != b_dupli_group.objects.end(); ++b_gob) { @@ -90,7 +88,6 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) default: /* avoid compiler warning */ break; - } } return need_update; @@ -114,7 +111,19 @@ static bool use_particle_system(BL::ParticleSystem b_psys) static bool use_particle(BL::Particle b_pa) { - return b_pa.is_exist() && b_pa.is_visible() && b_pa.alive_state()==BL::Particle::alive_state_ALIVE; + return b_pa.is_exist() && b_pa.is_visible() && + (b_pa.alive_state()==BL::Particle::alive_state_ALIVE || b_pa.alive_state()==BL::Particle::alive_state_DYING); +} + +static int psys_count_particles(BL::ParticleSystem b_psys) +{ + int tot = 0; + BL::ParticleSystem::particles_iterator b_pa; + for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) { + if(use_particle(*b_pa)) + ++tot; + } + return tot; } int BlenderSync::object_count_particles(BL::Object b_ob) @@ -122,45 +131,88 @@ int BlenderSync::object_count_particles(BL::Object b_ob) int tot = 0; BL::Object::particle_systems_iterator b_psys; for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { - if (use_particle_system(*b_psys)) { - BL::ParticleSystem::particles_iterator b_pa; - for(b_psys->particles.begin(b_pa); b_pa != b_psys->particles.end(); ++b_pa) { - if(use_particle(*b_pa)) - ++tot; - } - } + if (use_particle_system(*b_psys)) + tot += psys_count_particles(*b_psys); } return tot; } -void BlenderSync::sync_particles(Object *ob, BL::Object b_ob) +void BlenderSync::sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys) { - int tot = object_count_particles(b_ob); + /* depending on settings the psys may not even be rendered */ + if (!use_particle_system(b_psys)) + return; - ob->particles.clear(); - ob->particles.reserve(tot); + /* key to lookup particle system */ + ParticleSystemKey key(b_ob, b_psys); + ParticleSystem *psys; - int index; - BL::Object::particle_systems_iterator b_psys; - for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { - if (use_particle_system(*b_psys)) { - int pa_index = 0; - BL::ParticleSystem::particles_iterator b_pa; - for(b_psys->particles.begin(b_pa), index = 0; b_pa != b_psys->particles.end(); ++b_pa, ++index) { - if(use_particle(*b_pa)) { - Particle pa; - - pa.index = pa_index; - pa.age = b_scene.frame_current() - b_pa->birth_time(); - pa.lifetime = b_pa->lifetime(); - - ob->particles.push_back(pa); - } + /* test if we need to sync */ + bool object_updated = false; + + if(particle_system_map.sync(&psys, b_ob, b_ob, key)) + object_updated = true; + + bool need_update = psys_need_update(b_psys); + + if (object_updated || need_update) { + int tot = psys_count_particles(b_psys); + psys->particles.clear(); + psys->particles.reserve(tot); + + int index = 0; + BL::ParticleSystem::particles_iterator b_pa; + for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) { + if(use_particle(*b_pa)) { + Particle pa; + + pa.index = index; + pa.age = b_scene.frame_current() - b_pa->birth_time(); + pa.lifetime = b_pa->lifetime(); + pa.location = get_float3(b_pa->location()); + pa.rotation = get_float4(b_pa->rotation()); + pa.size = b_pa->size(); + pa.velocity = get_float3(b_pa->velocity()); + pa.angular_velocity = get_float3(b_pa->angular_velocity()); - ++pa_index; + psys->particles.push_back(pa); + } + + ++index; + } + + psys->tag_update(scene); + } +} + +void BlenderSync::sync_particle_systems() +{ + /* layer data */ + uint scene_layer = render_layer.scene_layer; + + particle_system_map.pre_sync(); + + /* object loop */ + BL::Scene::objects_iterator b_ob; + BL::Scene b_sce = b_scene; + + for(; b_sce; b_sce = b_sce.background_set()) { + for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end(); ++b_ob) { + bool hide = (render_layer.use_viewport_visibility)? b_ob->hide(): b_ob->hide_render(); + uint ob_layer = get_layer(b_ob->layers(), b_ob->layers_local_view(), render_layer.use_localview, object_is_light(*b_ob)); + hide = hide || !(ob_layer & scene_layer); + + if(!hide) { + BL::Object::particle_systems_iterator b_psys; + for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) + sync_particles(*b_ob, *b_psys); } } } + + /* handle removed data and modified pointers */ + if(particle_system_map.post_sync()) + scene->particle_system_manager->tag_update(scene); } CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index 4560c2f8543..96d5bb61ff8 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -80,6 +80,8 @@ static PyObject *create_func(PyObject *self, PyObject *args) /* create session */ BlenderSession *session; + Py_BEGIN_ALLOW_THREADS + if(rv3d) { /* interactive session */ int width = region.width(); @@ -91,7 +93,9 @@ static PyObject *create_func(PyObject *self, PyObject *args) /* offline session */ session = new BlenderSession(engine, userpref, data, scene); } - + + Py_END_ALLOW_THREADS + return PyLong_FromVoidPtr(session); } @@ -136,9 +140,13 @@ static PyObject *draw_func(PyObject *self, PyObject *args) static PyObject *sync_func(PyObject *self, PyObject *value) { + Py_BEGIN_ALLOW_THREADS + BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value); session->synchronize(); + Py_END_ALLOW_THREADS + Py_RETURN_NONE; } diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index d09e43bd76d..5930a2800bf 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -42,14 +42,13 @@ CCL_NAMESPACE_BEGIN BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_, BL::BlendData b_data_, BL::Scene b_scene_) : b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_scene(b_scene_), - b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL), - b_rr(PointerRNA_NULL), b_rlay(PointerRNA_NULL) + b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL) { /* offline render */ - BL::RenderSettings r = b_scene.render(); - width = (int)(r.resolution_x()*r.resolution_percentage()/100); - height = (int)(r.resolution_y()*r.resolution_percentage()/100); + width = b_engine.resolution_x(); + height = b_engine.resolution_y(); + background = true; last_redraw_time = 0.0f; @@ -60,7 +59,7 @@ BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b BL::BlendData b_data_, BL::Scene b_scene_, BL::SpaceView3D b_v3d_, BL::RegionView3D b_rv3d_, int width_, int height_) : b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_scene(b_scene_), - b_v3d(b_v3d_), b_rv3d(b_rv3d_), b_rr(PointerRNA_NULL), b_rlay(PointerRNA_NULL) + b_v3d(b_v3d_), b_rv3d(b_rv3d_) { /* 3d view render */ width = width_; @@ -80,17 +79,24 @@ BlenderSession::~BlenderSession() void BlenderSession::create_session() { SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background); - SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background); + SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background); /* reset status/progress */ last_status = ""; last_progress = -1.0f; /* create scene */ - scene = new Scene(scene_params); + scene = new Scene(scene_params, session_params.device); + + /* create session */ + session = new Session(session_params); + session->scene = scene; + session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this)); + session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this)); + session->set_pause(BlenderSync::get_session_pause(b_scene, background)); /* create sync */ - sync = new BlenderSync(b_data, b_scene, scene, !background); + sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress); sync->sync_data(b_v3d, b_engine.camera_override()); if(b_rv3d) @@ -98,13 +104,6 @@ void BlenderSession::create_session() else sync->sync_camera(b_engine.camera_override(), width, height); - /* create session */ - session = new Session(session_params); - session->scene = scene; - session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this)); - session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this)); - session->set_pause(BlenderSync::get_session_pause(b_scene, background)); - /* set buffer parameters */ BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height); session->reset(buffer_params, session_params.samples); @@ -177,35 +176,100 @@ static PassType get_pass_type(BL::RenderPass b_pass) return PASS_NONE; } +static BL::RenderResult begin_render_result(BL::RenderEngine b_engine, int x, int y, int w, int h, const char *layername) +{ + RenderResult *rrp = RE_engine_begin_result((RenderEngine*)b_engine.ptr.data, x, y, w, h, layername); + PointerRNA rrptr; + RNA_pointer_create(NULL, &RNA_RenderResult, rrp, &rrptr); + return BL::RenderResult(rrptr); +} + +static void end_render_result(BL::RenderEngine b_engine, BL::RenderResult b_rr, bool cancel = false) +{ + RE_engine_end_result((RenderEngine*)b_engine.ptr.data, (RenderResult*)b_rr.ptr.data, (int)cancel); +} + +void BlenderSession::do_write_update_render_tile(RenderTile& rtile, bool do_update_only) +{ + BufferParams& params = rtile.buffers->params; + int x = params.full_x - session->tile_manager.params.full_x; + int y = params.full_y - session->tile_manager.params.full_y; + int w = params.width; + int h = params.height; + + /* get render result */ + BL::RenderResult b_rr = begin_render_result(b_engine, x, y, w, h, b_rlay_name.c_str()); + + /* can happen if the intersected rectangle gives 0 width or height */ + if (b_rr.ptr.data == NULL) { + return; + } + + BL::RenderResult::layers_iterator b_single_rlay; + b_rr.layers.begin(b_single_rlay); + BL::RenderLayer b_rlay = *b_single_rlay; + + if (do_update_only) { + /* update only needed */ + update_render_result(b_rr, b_rlay, rtile); + end_render_result(b_engine, b_rr, true); + } + else { + /* write result */ + write_render_result(b_rr, b_rlay, rtile); + end_render_result(b_engine, b_rr); + } +} + +void BlenderSession::write_render_tile(RenderTile& rtile) +{ + do_write_update_render_tile(rtile, false); +} + +void BlenderSession::update_render_tile(RenderTile& rtile) +{ + do_write_update_render_tile(rtile, true); +} + void BlenderSession::render() { + /* set callback to write out render results */ + session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1); + session->update_render_tile_cb = function_bind(&BlenderSession::update_render_tile, this, _1); + /* get buffer parameters */ - SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background); + SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background); BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height); - int w = buffer_params.width, h = buffer_params.height; - - /* create render result */ - RenderResult *rrp = RE_engine_begin_result((RenderEngine*)b_engine.ptr.data, 0, 0, w, h); - PointerRNA rrptr; - RNA_pointer_create(NULL, &RNA_RenderResult, rrp, &rrptr); - b_rr = BL::RenderResult(rrptr); + /* render each layer */ BL::RenderSettings r = b_scene.render(); - BL::RenderResult::layers_iterator b_iter; - BL::RenderLayers b_rr_layers(r.ptr); + BL::RenderSettings::layers_iterator b_iter; - /* render each layer */ - for(b_rr.layers.begin(b_iter); b_iter != b_rr.layers.end(); ++b_iter) { - /* set layer */ - b_rlay = *b_iter; + for(r.layers.begin(b_iter); b_iter != r.layers.end(); ++b_iter) { + b_rlay_name = b_iter->name(); + + /* temporary render result to find needed passes */ + BL::RenderResult b_rr = begin_render_result(b_engine, 0, 0, 1, 1, b_rlay_name.c_str()); + BL::RenderResult::layers_iterator b_single_rlay; + b_rr.layers.begin(b_single_rlay); + + /* layer will be missing if it was disabled in the UI */ + if(b_single_rlay == b_rr.layers.end()) { + end_render_result(b_engine, b_rr, true); + continue; + } + + BL::RenderLayer b_rlay = *b_single_rlay; /* add passes */ vector<Pass> passes; Pass::add(PASS_COMBINED, passes); if(session_params.device.advanced_shading) { + + /* loop over passes */ BL::RenderLayer::passes_iterator b_pass_iter; - + for(b_rlay.passes.begin(b_pass_iter); b_pass_iter != b_rlay.passes.end(); ++b_pass_iter) { BL::RenderPass b_pass(*b_pass_iter); PassType pass_type = get_pass_type(b_pass); @@ -217,13 +281,16 @@ void BlenderSession::render() } } + /* free result without merging */ + end_render_result(b_engine, b_rr, true); + buffer_params.passes = passes; scene->film->tag_passes_update(scene, passes); scene->film->tag_update(scene); scene->integrator->tag_update(scene); /* update scene */ - sync->sync_data(b_v3d, b_engine.camera_override(), b_iter->name().c_str()); + sync->sync_data(b_v3d, b_engine.camera_override(), b_rlay_name.c_str()); /* update session */ int samples = sync->get_layer_samples(); @@ -235,19 +302,16 @@ void BlenderSession::render() if(session->progress.get_cancel()) break; - - /* write result */ - write_render_result(); } - /* delete render result */ - RE_engine_end_result((RenderEngine*)b_engine.ptr.data, (RenderResult*)b_rr.ptr.data); + /* clear callback */ + session->write_render_tile_cb = NULL; + session->update_render_tile_cb = NULL; } -void BlenderSession::write_render_result() +void BlenderSession::do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only) { - /* get state */ - RenderBuffers *buffers = session->buffers; + RenderBuffers *buffers = rtile.buffers; /* copy data from device */ if(!buffers->copy_from_device()) @@ -255,41 +319,49 @@ void BlenderSession::write_render_result() BufferParams& params = buffers->params; float exposure = scene->film->exposure; - double total_time, sample_time; - int sample; - - session->progress.get_sample(sample, total_time, sample_time); vector<float> pixels(params.width*params.height*4); - /* copy each pass */ - BL::RenderLayer::passes_iterator b_iter; - - for(b_rlay.passes.begin(b_iter); b_iter != b_rlay.passes.end(); ++b_iter) { - BL::RenderPass b_pass(*b_iter); + if (!do_update_only) { + /* copy each pass */ + BL::RenderLayer::passes_iterator b_iter; - /* find matching pass type */ - PassType pass_type = get_pass_type(b_pass); - int components = b_pass.channels(); + for(b_rlay.passes.begin(b_iter); b_iter != b_rlay.passes.end(); ++b_iter) { + BL::RenderPass b_pass(*b_iter); - /* copy pixels */ - if(buffers->get_pass(pass_type, exposure, sample, components, &pixels[0])) - rna_RenderPass_rect_set(&b_pass.ptr, &pixels[0]); + /* find matching pass type */ + PassType pass_type = get_pass_type(b_pass); + int components = b_pass.channels(); + + /* copy pixels */ + if(buffers->get_pass_rect(pass_type, exposure, rtile.sample, components, &pixels[0])) + rna_RenderPass_rect_set(&b_pass.ptr, &pixels[0]); + } } /* copy combined pass */ - if(buffers->get_pass(PASS_COMBINED, exposure, sample, 4, &pixels[0])) + if(buffers->get_pass_rect(PASS_COMBINED, exposure, rtile.sample, 4, &pixels[0])) rna_RenderLayer_rect_set(&b_rlay.ptr, &pixels[0]); /* tag result as updated */ RE_engine_update_result((RenderEngine*)b_engine.ptr.data, (RenderResult*)b_rr.ptr.data); } +void BlenderSession::write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile) +{ + do_write_update_render_result(b_rr, b_rlay, rtile, false); +} + +void BlenderSession::update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile) +{ + do_write_update_render_result(b_rr, b_rlay, rtile, true); +} + void BlenderSession::synchronize() { /* on session/scene parameter changes, we recreate session entirely */ SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background); - SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background); + SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background); if(session->params.modified(session_params) || scene->params.modified(scene_params)) @@ -300,6 +372,12 @@ void BlenderSession::synchronize() return; } + /* if the session is still resetting the device come back later */ + if(session->resetting()) { + tag_update(); + return; + } + /* increase samples, but never decrease */ session->set_samples(session_params.samples); session->set_pause(BlenderSync::get_session_pause(b_scene, background)); @@ -364,7 +442,7 @@ bool BlenderSession::draw(int w, int h) /* reset if requested */ if(reset) { - SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background); + SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background); BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, w, h); session->reset(buffer_params, session_params.samples); @@ -387,11 +465,16 @@ void BlenderSession::get_status(string& status, string& substatus) void BlenderSession::get_progress(float& progress, double& total_time) { - double sample_time; - int sample; + double tile_time; + int tile, sample, samples_per_tile; + int tile_total = session->tile_manager.state.num_tiles; + + session->progress.get_tile(tile, total_time, tile_time); - session->progress.get_sample(sample, total_time, sample_time); - progress = ((float)sample/(float)session->params.samples); + sample = session->progress.get_sample(); + samples_per_tile = session->tile_manager.state.num_samples; + + progress = ((float)sample/(float)(tile_total * samples_per_tile)); } void BlenderSession::update_status_progress() @@ -404,8 +487,13 @@ void BlenderSession::update_status_progress() get_status(status, substatus); get_progress(progress, total_time); + timestatus = b_scene.name(); + if(b_rlay_name != "") + timestatus += ", " + b_rlay_name; + timestatus += " | "; + BLI_timestr(total_time, time_str); - timestatus = "Elapsed: " + string(time_str) + " | "; + timestatus += "Elapsed: " + string(time_str) + " | "; if(substatus.size() > 0) status += " | " + substatus; @@ -435,7 +523,6 @@ void BlenderSession::tag_redraw() /* offline render, redraw if timeout passed */ if(time_dt() - last_redraw_time > 1.0) { - write_render_result(); engine_tag_redraw((RenderEngine*)b_engine.ptr.data); last_redraw_time = time_dt(); } diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index b98e3ffed54..d52e0103bbf 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -29,6 +29,8 @@ CCL_NAMESPACE_BEGIN class Scene; class Session; +class RenderBuffers; +class RenderTile; class BlenderSession { public: @@ -46,7 +48,14 @@ public: /* offline render */ void render(); - void write_render_result(); + + void write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile); + void write_render_tile(RenderTile& rtile); + + /* update functions are used to update display buffer only after sample was rendered + * only needed for better visual feedback */ + void update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile); + void update_render_tile(RenderTile& rtile); /* interactive updates */ void synchronize(); @@ -72,13 +81,16 @@ public: BL::Scene b_scene; BL::SpaceView3D b_v3d; BL::RegionView3D b_rv3d; - BL::RenderResult b_rr; - BL::RenderLayer b_rlay; + string b_rlay_name; string last_status; float last_progress; int width, height; + +protected: + void do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only); + void do_write_update_render_tile(RenderTile& rtile, bool do_update_only); }; CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 2c15a60dab6..9758d9bf92a 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -221,6 +221,7 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph BL::ShaderNodeMixRGB b_mix_node(b_node); MixNode *mix = new MixNode(); mix->type = MixNode::type_enum[b_mix_node.blend_type()]; + mix->use_clamp = b_mix_node.use_clamp(); node = mix; break; } @@ -244,6 +245,7 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph BL::ShaderNodeMath b_math_node(b_node); MathNode *math = new MathNode(); math->type = MathNode::type_enum[b_math_node.operation()]; + math->use_clamp = b_math_node.use_clamp(); node = math; break; } @@ -404,6 +406,8 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph if(b_image) image->filename = image_user_file_path(b_image_node.image_user(), b_image, b_scene.frame_current()); image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()]; + image->projection = ImageTextureNode::projection_enum[(int)b_image_node.projection()]; + image->projection_blend = b_image_node.projection_blend(); get_tex_mapping(&image->tex_mapping, b_image_node.texture_mapping()); node = image; break; @@ -459,6 +463,17 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph node = checker; break; } + case BL::ShaderNode::type_TEX_BRICK: { + BL::ShaderNodeTexBrick b_brick_node(b_node); + BrickTextureNode *brick = new BrickTextureNode(); + brick->offset = b_brick_node.offset(); + brick->offset_frequency = b_brick_node.offset_frequency(); + brick->squash = b_brick_node.squash(); + brick->squash_frequency = b_brick_node.squash_frequency(); + get_tex_mapping(&brick->tex_mapping, b_brick_node.texture_mapping()); + node = brick; + break; + } case BL::ShaderNode::type_TEX_NOISE: { BL::ShaderNodeTexNoise b_noise_node(b_node); NoiseTextureNode *noise = new NoiseTextureNode(); diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index ae28453a696..907573cf072 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -40,15 +40,18 @@ CCL_NAMESPACE_BEGIN /* Constructor */ -BlenderSync::BlenderSync(BL::BlendData b_data_, BL::Scene b_scene_, Scene *scene_, bool preview_) -: b_data(b_data_), b_scene(b_scene_), +BlenderSync::BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data_, BL::Scene b_scene_, Scene *scene_, bool preview_, Progress &progress_) +: b_engine(b_engine_), + b_data(b_data_), b_scene(b_scene_), shader_map(&scene_->shaders), object_map(&scene_->objects), mesh_map(&scene_->meshes), light_map(&scene_->lights), + particle_system_map(&scene_->particle_systems), world_map(NULL), world_recalc(false), - experimental(false) + experimental(false), + progress(progress_) { scene = scene_; preview = preview_; @@ -95,6 +98,12 @@ bool BlenderSync::sync_recalc() if(b_ob->is_updated_data() || b_ob->data().is_updated()) light_map.set_recalc(*b_ob); } + + if(b_ob->is_updated_data()) { + BL::Object::particle_systems_iterator b_psys; + for (b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) + particle_system_map.set_recalc(*b_ob); + } } BL::BlendData::meshes_iterator b_mesh; @@ -118,6 +127,7 @@ bool BlenderSync::sync_recalc() object_map.has_recalc() || light_map.has_recalc() || mesh_map.has_recalc() || + particle_system_map.has_recalc() || BlendDataObjects_is_updated_get(&b_data.ptr) || world_recalc; @@ -131,6 +141,7 @@ void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, const sync_film(); sync_shaders(); sync_objects(b_v3d); + sync_particle_systems(); sync_motion(b_v3d, b_override); } @@ -220,8 +231,7 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer) } else { render_layer.use_localview = (b_v3d.local_view() ? true : false); - render_layer.scene_layer = get_layer(b_v3d.layers(), b_v3d.layers_local_view()); - CYCLES_LOCAL_LAYER_HACK(render_layer.use_localview, render_layer.scene_layer); + render_layer.scene_layer = get_layer(b_v3d.layers(), b_v3d.layers_local_view(), render_layer.use_localview); render_layer.layer = render_layer.scene_layer; render_layer.holdout_layer = 0; render_layer.material_override = PointerRNA_NULL; @@ -287,7 +297,7 @@ bool BlenderSync::get_session_pause(BL::Scene b_scene, bool background) return (background)? false: get_boolean(cscene, "preview_pause"); } -SessionParams BlenderSync::get_session_params(BL::UserPreferences b_userpref, BL::Scene b_scene, bool background) +SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine, BL::UserPreferences b_userpref, BL::Scene b_scene, bool background) { SessionParams params; PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); @@ -341,25 +351,39 @@ SessionParams BlenderSync::get_session_params(BL::UserPreferences b_userpref, BL } } + /* tiles */ + if(params.device.type != DEVICE_CPU && !background) { + /* currently GPU could be much slower than CPU when using tiles, + * still need to be investigated, but meanwhile make it possible + * to work in viewport smoothly + */ + int debug_tile_size = get_int(cscene, "debug_tile_size"); + + params.tile_size = make_int2(debug_tile_size, debug_tile_size); + } + else { + int tile_x = b_engine.tile_x(); + int tile_y = b_engine.tile_y(); + + params.tile_size = make_int2(tile_x, tile_y); + } + + params.resolution = 1 << get_int(cscene, "resolution_divider"); + /* other parameters */ params.threads = b_scene.render().threads(); - params.tile_size = get_int(cscene, "debug_tile_size"); - params.min_size = get_int(cscene, "debug_min_size"); + params.cancel_timeout = get_float(cscene, "debug_cancel_timeout"); params.reset_timeout = get_float(cscene, "debug_reset_timeout"); params.text_timeout = get_float(cscene, "debug_text_timeout"); if(background) { - params.progressive = true; - params.min_size = INT_MAX; + params.progressive = false; + params.resolution = 1; } else params.progressive = true; - /* todo: multi device only works with single tiles now */ - if(params.device.type == DEVICE_MULTI) - params.tile_size = INT_MAX; - return params; } diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 6065235a278..27f6b6ee4ee 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -49,7 +49,7 @@ class ShaderNode; class BlenderSync { public: - BlenderSync(BL::BlendData b_data, BL::Scene b_scene, Scene *scene_, bool preview_); + BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data, BL::Scene b_scene, Scene *scene_, bool preview_, Progress &progress_); ~BlenderSync(); /* sync */ @@ -61,7 +61,7 @@ public: /* get parameters */ static SceneParams get_scene_params(BL::Scene b_scene, bool background); - static SessionParams get_session_params(BL::UserPreferences b_userpref, BL::Scene b_scene, bool background); + static SessionParams get_session_params(BL::RenderEngine b_engine, BL::UserPreferences b_userpref, BL::Scene b_scene, bool background); static bool get_session_pause(BL::Scene b_scene, bool background); static BufferParams get_buffer_params(BL::Scene b_scene, Camera *cam, int width, int height); @@ -77,6 +77,7 @@ private: void sync_world(); void sync_render_layers(BL::SpaceView3D b_v3d, const char *layer); void sync_shaders(); + void sync_particle_systems(); void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree); Mesh *sync_mesh(BL::Object b_ob, bool object_updated); @@ -85,17 +86,18 @@ private: void sync_background_light(); void sync_mesh_motion(BL::Object b_ob, Mesh *mesh, int motion); void sync_camera_motion(BL::Object b_ob, int motion); - void sync_particles(Object *ob, BL::Object b_ob); + void sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys); /* util */ void find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader); bool BKE_object_is_modified(BL::Object b_ob); bool object_is_mesh(BL::Object b_ob); bool object_is_light(BL::Object b_ob); - bool object_need_particle_update(BL::Object b_ob); + bool psys_need_update(BL::ParticleSystem b_psys); int object_count_particles(BL::Object b_ob); /* variables */ + BL::RenderEngine b_engine; BL::BlendData b_data; BL::Scene b_scene; @@ -103,6 +105,7 @@ private: id_map<ObjectKey, Object> object_map; id_map<void*, Mesh> mesh_map; id_map<ObjectKey, Light> light_map; + id_map<ParticleSystemKey, ParticleSystem> particle_system_map; set<Mesh*> mesh_synced; void *world_map; bool world_recalc; @@ -130,21 +133,9 @@ private: bool use_localview; int samples; } render_layer; -}; -/* we don't have spare bits for localview (normally 20-28) - * because PATH_RAY_LAYER_SHIFT uses 20-32. - * So - check if we have localview and if so, shift local - * view bits down to 1-8, since this is done for the view - * port only - it should be OK and not conflict with - * render layers. - Campbell. - * - * ... as an alternative we could use uint64_t - */ -#define CYCLES_LOCAL_LAYER_HACK(use_localview, layer) \ - if (use_localview) { \ - layer >>= 20; \ - } (void)0 + Progress &progress; +}; CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index ebbd4e1221c..d0fca9a9fb9 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -40,9 +40,9 @@ void rna_Object_create_duplilist(void *ob, void *reports, void *sce); void rna_Object_free_duplilist(void *ob, void *reports); void rna_RenderLayer_rect_set(PointerRNA *ptr, const float *values); void rna_RenderPass_rect_set(PointerRNA *ptr, const float *values); -struct RenderResult *RE_engine_begin_result(struct RenderEngine *engine, int x, int y, int w, int h); +struct RenderResult *RE_engine_begin_result(struct RenderEngine *engine, int x, int y, int w, int h, const char *layername); void RE_engine_update_result(struct RenderEngine *engine, struct RenderResult *result); -void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result); +void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result, int cancel); int RE_engine_test_break(struct RenderEngine *engine); void RE_engine_update_stats(struct RenderEngine *engine, const char *stats, const char *info); void RE_engine_update_progress(struct RenderEngine *engine, float progress); @@ -55,7 +55,6 @@ void rna_ColorRamp_eval(void *coba, float position, float color[4]); void rna_Scene_frame_set(void *scene, int frame, float subframe); void BKE_image_user_frame_calc(void *iuser, int cfra, int fieldnr); void BKE_image_user_file_path(void *iuser, void *ima, char *path); - } CCL_NAMESPACE_BEGIN @@ -150,6 +149,11 @@ static inline float3 get_float3(BL::Array<float, 4> array) return make_float3(array[0], array[1], array[2]); } +static inline float4 get_float4(BL::Array<float, 4> array) +{ + return make_float4(array[0], array[1], array[2], array[3]); +} + static inline int4 get_int4(BL::Array<int, 4> array) { return make_int4(array[0], array[1], array[2], array[3]); @@ -166,7 +170,7 @@ static inline uint get_layer(BL::Array<int, 20> array) return layer; } -static inline uint get_layer(BL::Array<int, 20> array, BL::Array<int, 8> local_array, bool is_light = false) +static inline uint get_layer(BL::Array<int, 20> array, BL::Array<int, 8> local_array, bool use_local, bool is_light = false) { uint layer = 0; @@ -184,7 +188,14 @@ static inline uint get_layer(BL::Array<int, 20> array, BL::Array<int, 8> local_a if(local_array[i]) layer |= (1 << (20+i)); } - + + /* we don't have spare bits for localview (normally 20-28) because + * PATH_RAY_LAYER_SHIFT uses 20-32. So - check if we have localview and if + * so, shift local view bits down to 1-8, since this is done for the view + * port only - it should be OK and not conflict with render layers. */ + if(use_local) + layer >>= 20; + return layer; } @@ -389,6 +400,17 @@ struct ObjectKey { { return (parent < k.parent || (parent == k.parent && (index < k.index || (index == k.index && ob < k.ob)))); } }; +struct ParticleSystemKey { + void *ob; + void *psys; + + ParticleSystemKey(void *ob_, void *psys_) + : ob(ob_), psys(psys_) {} + + bool operator<(const ParticleSystemKey& k) const + { return (ob < k.ob && psys < k.psys); } +}; + CCL_NAMESPACE_END #endif /* __BLENDER_UTIL_H__ */ diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake index 23a919530f9..332d3d74715 100644 --- a/intern/cycles/cmake/external_libs.cmake +++ b/intern/cycles/cmake/external_libs.cmake @@ -18,32 +18,6 @@ else() endif() ########################################################################### -# OpenShadingLanguage - -if(WITH_CYCLES_OSL) - - set(CYCLES_OSL "" CACHE PATH "Path to OpenShadingLanguage installation") - - message(STATUS "CYCLES_OSL = ${CYCLES_OSL}") - - find_library(OSL_LIBRARIES NAMES oslexec oslcomp oslquery PATHS ${CYCLES_OSL}/lib ${CYCLES_OSL}/dist) - find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include ${CYCLES_OSL}/dist) - find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin ${CYCLES_OSL}/dist) - - if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER) - set(OSL_FOUND TRUE) - message(STATUS "OSL includes = ${OSL_INCLUDES}") - message(STATUS "OSL library = ${OSL_LIBRARIES}") - message(STATUS "OSL compiler = ${OSL_COMPILER}") - else() - message(STATUS "OSL not found") - endif() - - include_directories(${OSL_INCLUDES} ${OSL_INCLUDES}/OSL ${OSL_INCLUDES}/../../../src/liboslexec) - -endif() - -########################################################################### # Partio if(WITH_CYCLES_PARTIO) diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index 17072d230bb..6038abd815e 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -17,6 +17,7 @@ set(SRC device_multi.cpp device_network.cpp device_opencl.cpp + device_task.cpp ) set(SRC_HEADERS @@ -24,6 +25,7 @@ set(SRC_HEADERS device_memory.h device_intern.h device_network.h + device_task.h ) add_definitions(-DGLEW_STATIC) diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index 33040f287d1..9a4d364a9b8 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -33,65 +33,6 @@ CCL_NAMESPACE_BEGIN -/* Device Task */ - -DeviceTask::DeviceTask(Type type_) -: type(type_), x(0), y(0), w(0), h(0), rng_state(0), rgba(0), buffer(0), - sample(0), resolution(0), - shader_input(0), shader_output(0), - shader_eval_type(0), shader_x(0), shader_w(0) -{ -} - -void DeviceTask::split_max_size(list<DeviceTask>& tasks, int max_size) -{ - int num; - - if(type == SHADER) { - num = (shader_w + max_size - 1)/max_size; - } - else { - max_size = max(1, max_size/w); - num = (h + max_size - 1)/max_size; - } - - split(tasks, num); -} - -void DeviceTask::split(list<DeviceTask>& tasks, int num) -{ - if(type == SHADER) { - num = min(shader_w, num); - - for(int i = 0; i < num; i++) { - int tx = shader_x + (shader_w/num)*i; - int tw = (i == num-1)? shader_w - i*(shader_w/num): shader_w/num; - - DeviceTask task = *this; - - task.shader_x = tx; - task.shader_w = tw; - - tasks.push_back(task); - } - } - else { - num = min(h, num); - - for(int i = 0; i < num; i++) { - int ty = y + (h/num)*i; - int th = (i == num-1)? h - i*(h/num): h/num; - - DeviceTask task = *this; - - task.y = ty; - task.h = th; - - tasks.push_back(task); - } - } -} - /* Device */ void Device::pixels_alloc(device_memory& mem) diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index b17abac2a1b..8e3bc408399 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -22,10 +22,10 @@ #include <stdlib.h> #include "device_memory.h" +#include "device_task.h" #include "util_list.h" #include "util_string.h" -#include "util_task.h" #include "util_thread.h" #include "util_types.h" #include "util_vector.h" @@ -33,6 +33,7 @@ CCL_NAMESPACE_BEGIN class Progress; +class RenderTile; /* Device Types */ @@ -67,32 +68,6 @@ public: } }; -/* Device Task */ - -class DeviceTask : public Task { -public: - typedef enum { PATH_TRACE, TONEMAP, SHADER } Type; - Type type; - - int x, y, w, h; - device_ptr rng_state; - device_ptr rgba; - device_ptr buffer; - int sample; - int resolution; - int offset, stride; - - device_ptr shader_input; - device_ptr shader_output; - int shader_eval_type; - int shader_x, shader_w; - - DeviceTask(Type type = PATH_TRACE); - - void split(list<DeviceTask>& tasks, int num); - void split_max_size(list<DeviceTask>& tasks, int max_size); -}; - /* Device */ class Device { @@ -140,6 +115,7 @@ public: virtual void task_add(DeviceTask& task) = 0; virtual void task_wait() = 0; virtual void task_cancel() = 0; + virtual bool task_cancelled() = 0; /* opengl drawing */ virtual void draw_pixels(device_memory& mem, int y, int w, int h, @@ -150,6 +126,10 @@ public: void server_run(); #endif + /* multi device */ + virtual void map_tile(Device *sub_device, RenderTile& tile) {} + virtual int device_number(Device *sub_device) { return 0; } + /* static */ static Device *create(DeviceInfo& info, bool background = true, int threads = 0); diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 070b20aec49..e2f612ee233 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -27,6 +27,8 @@ #include "osl_shader.h" +#include "buffers.h" + #include "util_debug.h" #include "util_foreach.h" #include "util_function.h" @@ -141,28 +143,56 @@ public: OSLShader::thread_init(kg); #endif -#ifdef WITH_OPTIMIZED_KERNEL - if(system_cpu_support_optimized()) { - for(int y = task.y; y < task.y + task.h; y++) { - for(int x = task.x; x < task.x + task.w; x++) - kernel_cpu_optimized_path_trace(kg, (float*)task.buffer, (unsigned int*)task.rng_state, - task.sample, x, y, task.offset, task.stride); + RenderTile tile; + + while(task.acquire_tile(this, tile)) { + float *render_buffer = (float*)tile.buffer; + uint *rng_state = (uint*)tile.rng_state; + int start_sample = tile.start_sample; + int end_sample = tile.start_sample + tile.num_samples; - if(task_pool.cancelled()) - break; +#ifdef WITH_OPTIMIZED_KERNEL + if(system_cpu_support_optimized()) { + for(int sample = start_sample; sample < end_sample; sample++) { + if (task.get_cancel() || task_pool.cancelled()) + break; + + for(int y = tile.y; y < tile.y + tile.h; y++) { + for(int x = tile.x; x < tile.x + tile.w; x++) { + kernel_cpu_optimized_path_trace(kg, render_buffer, rng_state, + sample, x, y, tile.offset, tile.stride); + } + } + + tile.sample = sample + 1; + + task.update_progress(tile); + } } - } - else + else #endif - { - for(int y = task.y; y < task.y + task.h; y++) { - for(int x = task.x; x < task.x + task.w; x++) - kernel_cpu_path_trace(kg, (float*)task.buffer, (unsigned int*)task.rng_state, - task.sample, x, y, task.offset, task.stride); - - if(task_pool.cancelled()) - break; + { + for(int sample = start_sample; sample < end_sample; sample++) { + if (task.get_cancel() || task_pool.cancelled()) + break; + + for(int y = tile.y; y < tile.y + tile.h; y++) { + for(int x = tile.x; x < tile.x + tile.w; x++) { + kernel_cpu_path_trace(kg, render_buffer, rng_state, + sample, x, y, tile.offset, tile.stride); + } + } + + tile.sample = sample + 1; + + task.update_progress(tile); + } } + + task.release_tile(tile); + + if(task_pool.cancelled()) + break; } #ifdef WITH_OSL @@ -228,8 +258,7 @@ public: /* split task into smaller ones, more than number of threads for uneven * workloads where some parts of the image render slower than others */ list<DeviceTask> tasks; - - task.split(tasks, TaskScheduler::num_threads()*10); + task.split(tasks, TaskScheduler::num_threads()+1); foreach(DeviceTask& task, tasks) task_pool.push(new CPUDeviceTask(this, task)); @@ -244,6 +273,11 @@ public: { task_pool.cancel(); } + + bool task_cancelled() + { + return task_pool.cancelled(); + } }; Device *device_cpu_create(DeviceInfo& info, int threads) diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index 357f99145b2..acc1086cc35 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -23,6 +23,8 @@ #include "device.h" #include "device_intern.h" +#include "buffers.h" + #include "util_cuda.h" #include "util_debug.h" #include "util_map.h" @@ -37,6 +39,7 @@ CCL_NAMESPACE_BEGIN class CUDADevice : public Device { public: + TaskPool task_pool; CUdevice cuDevice; CUcontext cuContext; CUmodule cuModule; @@ -192,6 +195,8 @@ public: ~CUDADevice() { + task_pool.stop(); + cuda_push_context(); cuda_assert(cuCtxDetach(cuContext)) } @@ -466,13 +471,13 @@ public: } } - void path_trace(DeviceTask& task) + void path_trace(RenderTile& rtile, int sample) { cuda_push_context(); CUfunction cuPathTrace; - CUdeviceptr d_buffer = cuda_device_ptr(task.buffer); - CUdeviceptr d_rng_state = cuda_device_ptr(task.rng_state); + CUdeviceptr d_buffer = cuda_device_ptr(rtile.buffer); + CUdeviceptr d_rng_state = cuda_device_ptr(rtile.rng_state); /* get kernel function */ cuda_assert(cuModuleGetFunction(&cuPathTrace, cuModule, "kernel_cuda_path_trace")) @@ -486,29 +491,28 @@ public: cuda_assert(cuParamSetv(cuPathTrace, offset, &d_rng_state, sizeof(d_rng_state))) offset += sizeof(d_rng_state); - int sample = task.sample; offset = align_up(offset, __alignof(sample)); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.sample)) - offset += sizeof(task.sample); + cuda_assert(cuParamSeti(cuPathTrace, offset, sample)) + offset += sizeof(sample); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.x)) - offset += sizeof(task.x); + cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.x)) + offset += sizeof(rtile.x); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.y)) - offset += sizeof(task.y); + cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.y)) + offset += sizeof(rtile.y); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.w)) - offset += sizeof(task.w); + cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.w)) + offset += sizeof(rtile.w); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.h)) - offset += sizeof(task.h); + cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.h)) + offset += sizeof(rtile.h); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.offset)) - offset += sizeof(task.offset); + cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.offset)) + offset += sizeof(rtile.offset); - cuda_assert(cuParamSeti(cuPathTrace, offset, task.stride)) - offset += sizeof(task.stride); + cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.stride)) + offset += sizeof(rtile.stride); cuda_assert(cuParamSetSize(cuPathTrace, offset)) @@ -520,23 +524,25 @@ public: int xthreads = 8; int ythreads = 8; #endif - int xblocks = (task.w + xthreads - 1)/xthreads; - int yblocks = (task.h + ythreads - 1)/ythreads; + int xblocks = (rtile.w + xthreads - 1)/xthreads; + int yblocks = (rtile.h + ythreads - 1)/ythreads; cuda_assert(cuFuncSetCacheConfig(cuPathTrace, CU_FUNC_CACHE_PREFER_L1)) cuda_assert(cuFuncSetBlockShape(cuPathTrace, xthreads, ythreads, 1)) cuda_assert(cuLaunchGrid(cuPathTrace, xblocks, yblocks)) + cuda_assert(cuCtxSynchronize()) + cuda_pop_context(); } - void tonemap(DeviceTask& task) + void tonemap(DeviceTask& task, device_ptr buffer, device_ptr rgba) { cuda_push_context(); CUfunction cuFilmConvert; - CUdeviceptr d_rgba = map_pixels(task.rgba); - CUdeviceptr d_buffer = cuda_device_ptr(task.buffer); + CUdeviceptr d_rgba = map_pixels(rgba); + CUdeviceptr d_buffer = cuda_device_ptr(buffer); /* get kernel function */ cuda_assert(cuModuleGetFunction(&cuFilmConvert, cuModule, "kernel_cuda_tonemap")) @@ -820,27 +826,76 @@ public: Device::draw_pixels(mem, y, w, h, dy, width, height, transparent); } - void task_add(DeviceTask& task) + void thread_run(DeviceTask *task) { - if(task.type == DeviceTask::TONEMAP) - tonemap(task); - else if(task.type == DeviceTask::PATH_TRACE) - path_trace(task); - else if(task.type == DeviceTask::SHADER) - shader(task); + if(task->type == DeviceTask::PATH_TRACE) { + RenderTile tile; + + /* keep rendering tiles until done */ + while(task->acquire_tile(this, tile)) { + int start_sample = tile.start_sample; + int end_sample = tile.start_sample + tile.num_samples; + + for(int sample = start_sample; sample < end_sample; sample++) { + if (task->get_cancel()) + break; + + path_trace(tile, sample); + + tile.sample = sample + 1; + + task->update_progress(tile); + } + + task->release_tile(tile); + } + } + else if(task->type == DeviceTask::SHADER) { + shader(*task); + + cuda_push_context(); + cuda_assert(cuCtxSynchronize()) + cuda_pop_context(); + } } - void task_wait() + class CUDADeviceTask : public DeviceTask { + public: + CUDADeviceTask(CUDADevice *device, DeviceTask& task) + : DeviceTask(task) + { + run = function_bind(&CUDADevice::thread_run, device, this); + } + }; + + void task_add(DeviceTask& task) { - cuda_push_context(); + if(task.type == DeviceTask::TONEMAP) { + /* must be done in main thread due to opengl access */ + tonemap(task, task.buffer, task.rgba); - cuda_assert(cuCtxSynchronize()) + cuda_push_context(); + cuda_assert(cuCtxSynchronize()) + cuda_pop_context(); + } + else { + task_pool.push(new CUDADeviceTask(this, task)); + } + } - cuda_pop_context(); + void task_wait() + { + task_pool.wait_work(); } void task_cancel() { + task_pool.cancel(); + } + + bool task_cancelled() + { + return task_pool.cancelled(); } }; diff --git a/intern/cycles/device/device_multi.cpp b/intern/cycles/device/device_multi.cpp index 83e69b98f5d..4923e5c9e66 100644 --- a/intern/cycles/device/device_multi.cpp +++ b/intern/cycles/device/device_multi.cpp @@ -23,6 +23,8 @@ #include "device_intern.h" #include "device_network.h" +#include "buffers.h" + #include "util_foreach.h" #include "util_list.h" #include "util_map.h" @@ -255,6 +257,30 @@ public: rgba.device_pointer = tmp; } + void map_tile(Device *sub_device, RenderTile& tile) + { + foreach(SubDevice& sub, devices) { + if(sub.device == sub_device) { + if(tile.buffer) tile.buffer = sub.ptr_map[tile.buffer]; + if(tile.rng_state) tile.rng_state = sub.ptr_map[tile.rng_state]; + if(tile.rgba) tile.rgba = sub.ptr_map[tile.rgba]; + } + } + } + + int device_number(Device *sub_device) + { + int i = 0; + + foreach(SubDevice& sub, devices) { + if(sub.device == sub_device) + return i; + i++; + } + + return -1; + } + void task_add(DeviceTask& task) { list<DeviceTask> tasks; @@ -266,7 +292,6 @@ public: tasks.pop_front(); if(task.buffer) subtask.buffer = sub.ptr_map[task.buffer]; - if(task.rng_state) subtask.rng_state = sub.ptr_map[task.rng_state]; if(task.rgba) subtask.rgba = sub.ptr_map[task.rgba]; if(task.shader_input) subtask.shader_input = sub.ptr_map[task.shader_input]; if(task.shader_output) subtask.shader_output = sub.ptr_map[task.shader_output]; @@ -287,6 +312,14 @@ public: foreach(SubDevice& sub, devices) sub.device->task_cancel(); } + + bool task_cancelled() + { + foreach(SubDevice& sub, devices) + if (sub.device->task_cancelled()) + return true; + return false; + } }; Device *device_multi_create(DeviceInfo& info, bool background) diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp index c9ec7c75063..ed7229d49da 100644 --- a/intern/cycles/device/device_opencl.cpp +++ b/intern/cycles/device/device_opencl.cpp @@ -25,6 +25,8 @@ #include "device.h" #include "device_intern.h" +#include "buffers.h" + #include "util_foreach.h" #include "util_map.h" #include "util_math.h" @@ -41,6 +43,7 @@ CCL_NAMESPACE_BEGIN class OpenCLDevice : public Device { public: + TaskPool task_pool; cl_context cxContext; cl_command_queue cqCommandQueue; cl_platform_id cpPlatform; @@ -435,6 +438,8 @@ public: ~OpenCLDevice() { + task_pool.stop(); + if(null_mem) clReleaseMemObject(CL_MEM_PTR(null_mem)); @@ -540,19 +545,19 @@ public: return global_size + ((r == 0)? 0: group_size - r); } - void path_trace(DeviceTask& task) + void path_trace(RenderTile& rtile, int sample) { /* cast arguments to cl types */ cl_mem d_data = CL_MEM_PTR(const_mem_map["__data"]->device_pointer); - cl_mem d_buffer = CL_MEM_PTR(task.buffer); - cl_mem d_rng_state = CL_MEM_PTR(task.rng_state); - cl_int d_x = task.x; - cl_int d_y = task.y; - cl_int d_w = task.w; - cl_int d_h = task.h; - cl_int d_sample = task.sample; - cl_int d_offset = task.offset; - cl_int d_stride = task.stride; + cl_mem d_buffer = CL_MEM_PTR(rtile.buffer); + cl_mem d_rng_state = CL_MEM_PTR(rtile.rng_state); + cl_int d_x = rtile.x; + cl_int d_y = rtile.y; + cl_int d_w = rtile.w; + cl_int d_h = rtile.h; + cl_int d_sample = sample; + cl_int d_offset = rtile.offset; + cl_int d_stride = rtile.stride; /* sample arguments */ int narg = 0; @@ -613,12 +618,12 @@ public: return err; } - void tonemap(DeviceTask& task) + void tonemap(DeviceTask& task, device_ptr buffer, device_ptr rgba) { /* cast arguments to cl types */ cl_mem d_data = CL_MEM_PTR(const_mem_map["__data"]->device_pointer); - cl_mem d_rgba = CL_MEM_PTR(task.rgba); - cl_mem d_buffer = CL_MEM_PTR(task.buffer); + cl_mem d_rgba = CL_MEM_PTR(rgba); + cl_mem d_buffer = CL_MEM_PTR(buffer); cl_int d_x = task.x; cl_int d_y = task.y; cl_int d_w = task.w; @@ -667,30 +672,62 @@ public: opencl_assert(clFinish(cqCommandQueue)); } - void task_add(DeviceTask& maintask) + void thread_run(DeviceTask *task) { - list<DeviceTask> tasks; + if(task->type == DeviceTask::TONEMAP) { + tonemap(*task, task->buffer, task->rgba); + } + else if(task->type == DeviceTask::PATH_TRACE) { + RenderTile tile; + + /* keep rendering tiles until done */ + while(task->acquire_tile(this, tile)) { + int start_sample = tile.start_sample; + int end_sample = tile.start_sample + tile.num_samples; - /* arbitrary limit to work around apple ATI opencl issue */ - if(platform_name == "Apple") - maintask.split_max_size(tasks, 76800); - else - tasks.push_back(maintask); + for(int sample = start_sample; sample < end_sample; sample++) { + if (task->get_cancel()) + break; + + path_trace(tile, sample); - foreach(DeviceTask& task, tasks) { - if(task.type == DeviceTask::TONEMAP) - tonemap(task); - else if(task.type == DeviceTask::PATH_TRACE) - path_trace(task); + tile.sample = sample + 1; + + task->update_progress(tile); + } + + task->release_tile(tile); + } } } + class OpenCLDeviceTask : public DeviceTask { + public: + OpenCLDeviceTask(OpenCLDevice *device, DeviceTask& task) + : DeviceTask(task) + { + run = function_bind(&OpenCLDevice::thread_run, device, this); + } + }; + + void task_add(DeviceTask& task) + { + task_pool.push(new OpenCLDeviceTask(this, task)); + } + void task_wait() { + task_pool.wait_work(); } void task_cancel() { + task_pool.cancel(); + } + + bool task_cancelled() + { + return task_pool.cancelled(); } }; @@ -702,29 +739,31 @@ Device *device_opencl_create(DeviceInfo& info, bool background) void device_opencl_info(vector<DeviceInfo>& devices) { vector<cl_device_id> device_ids; - cl_uint num_devices; - cl_platform_id platform_id; - cl_uint num_platforms; + cl_uint num_devices = 0; + vector<cl_platform_id> platform_ids; + cl_uint num_platforms = 0; /* get devices */ if(clGetPlatformIDs(0, NULL, &num_platforms) != CL_SUCCESS || num_platforms == 0) return; + + platform_ids.resize(num_platforms); - if(clGetPlatformIDs(1, &platform_id, NULL) != CL_SUCCESS) + if(clGetPlatformIDs(num_platforms, &platform_ids[0], NULL) != CL_SUCCESS) return; - if(clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &num_devices) != CL_SUCCESS) + if(clGetDeviceIDs(platform_ids[0], CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &num_devices) != CL_SUCCESS || num_devices == 0) return; device_ids.resize(num_devices); - if(clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR, num_devices, &device_ids[0], NULL) != CL_SUCCESS) + if(clGetDeviceIDs(platform_ids[0], CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR, num_devices, &device_ids[0], NULL) != CL_SUCCESS) return; /* add devices */ for(int num = 0; num < num_devices; num++) { cl_device_id device_id = device_ids[num]; - char name[1024]; + char name[1024] = "\0"; if(clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(name), &name, NULL) != CL_SUCCESS) continue; diff --git a/intern/cycles/device/device_task.cpp b/intern/cycles/device/device_task.cpp new file mode 100644 index 00000000000..c85e182d629 --- /dev/null +++ b/intern/cycles/device/device_task.cpp @@ -0,0 +1,113 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <stdlib.h> +#include <string.h> + +#include "device_task.h" + +#include "util_algorithm.h" +#include "util_time.h" + +CCL_NAMESPACE_BEGIN + +/* Device Task */ + +DeviceTask::DeviceTask(Type type_) +: type(type_), x(0), y(0), w(0), h(0), rgba(0), buffer(0), + sample(0), num_samples(1), resolution(0), + shader_input(0), shader_output(0), + shader_eval_type(0), shader_x(0), shader_w(0) +{ + last_update_time = time_dt(); +} + +void DeviceTask::split_max_size(list<DeviceTask>& tasks, int max_size) +{ + int num; + + if(type == SHADER) { + num = (shader_w + max_size - 1)/max_size; + } + else { + max_size = max(1, max_size/w); + num = (h + max_size - 1)/max_size; + } + + split(tasks, num); +} + +void DeviceTask::split(list<DeviceTask>& tasks, int num) +{ + if(type == SHADER) { + num = min(shader_w, num); + + for(int i = 0; i < num; i++) { + int tx = shader_x + (shader_w/num)*i; + int tw = (i == num-1)? shader_w - i*(shader_w/num): shader_w/num; + + DeviceTask task = *this; + + task.shader_x = tx; + task.shader_w = tw; + + tasks.push_back(task); + } + } + else if(type == PATH_TRACE) { + for(int i = 0; i < num; i++) + tasks.push_back(*this); + } + else { + num = min(h, num); + + for(int i = 0; i < num; i++) { + int ty = y + (h/num)*i; + int th = (i == num-1)? h - i*(h/num): h/num; + + DeviceTask task = *this; + + task.y = ty; + task.h = th; + + tasks.push_back(task); + } + } +} + +void DeviceTask::update_progress(RenderTile &rtile) +{ + if (type != PATH_TRACE) + return; + + if(update_progress_sample) + update_progress_sample(); + + if(update_tile_sample) { + double current_time = time_dt(); + + if (current_time - last_update_time >= 1.0f) { + update_tile_sample(rtile); + + last_update_time = current_time; + } + } +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/device/device_task.h b/intern/cycles/device/device_task.h new file mode 100644 index 00000000000..cfb3d8d988e --- /dev/null +++ b/intern/cycles/device/device_task.h @@ -0,0 +1,75 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __DEVICE_TASK_H__ +#define __DEVICE_TASK_H__ + +#include "device_memory.h" + +#include "util_function.h" +#include "util_list.h" +#include "util_task.h" + +CCL_NAMESPACE_BEGIN + +/* Device Task */ + +class Device; +class RenderBuffers; +class RenderTile; +class Tile; + +class DeviceTask : public Task { +public: + typedef enum { PATH_TRACE, TONEMAP, SHADER } Type; + Type type; + + int x, y, w, h; + device_ptr rgba; + device_ptr buffer; + int sample; + int num_samples; + int resolution; + int offset, stride; + + device_ptr shader_input; + device_ptr shader_output; + int shader_eval_type; + int shader_x, shader_w; + + DeviceTask(Type type = PATH_TRACE); + + void split(list<DeviceTask>& tasks, int num); + void split_max_size(list<DeviceTask>& tasks, int max_size); + + void update_progress(RenderTile &rtile); + + boost::function<bool(Device *device, RenderTile&)> acquire_tile; + boost::function<void(void)> update_progress_sample; + boost::function<void(RenderTile&)> update_tile_sample; + boost::function<void(RenderTile&)> release_tile; + boost::function<bool(void)> get_cancel; + +protected: + double last_update_time; +}; + +CCL_NAMESPACE_END + +#endif /* __DEVICE_TASK_H__ */ + diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index 98cb16d5dfc..b43aca24496 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -16,6 +16,7 @@ set(SRC set(SRC_HEADERS kernel.h kernel_accumulate.h + kernel_attribute.h kernel_bvh.h kernel_camera.h kernel_compat_cpu.h @@ -61,6 +62,7 @@ set(SRC_SVM_HEADERS svm/svm_closure.h svm/svm_convert.h svm/svm_checker.h + svm/svm_brick.h svm/svm_displace.h svm/svm_fresnel.h svm/svm_gamma.h diff --git a/intern/cycles/kernel/kernel.cpp b/intern/cycles/kernel/kernel.cpp index 667db1e5f03..62d79bdd946 100644 --- a/intern/cycles/kernel/kernel.cpp +++ b/intern/cycles/kernel/kernel.cpp @@ -87,14 +87,10 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t else if(strstr(name, "__tex_image_float")) { texture_image_float4 *tex = NULL; int id = atoi(name + strlen("__tex_image_float_")); + int array_index = id; - switch(id) { - case 95: tex = &kg->__tex_image_float_095; break; - case 96: tex = &kg->__tex_image_float_096; break; - case 97: tex = &kg->__tex_image_float_097; break; - case 98: tex = &kg->__tex_image_float_098; break; - case 99: tex = &kg->__tex_image_float_099; break; - default: break; + if (array_index >= 0 && array_index < MAX_FLOAT_IMAGES) { + tex = &kg->texture_float_images[array_index]; } if(tex) { @@ -106,104 +102,10 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t else if(strstr(name, "__tex_image")) { texture_image_uchar4 *tex = NULL; int id = atoi(name + strlen("__tex_image_")); + int array_index = id - MAX_FLOAT_IMAGES; - switch(id) { - case 0: tex = &kg->__tex_image_000; break; - case 1: tex = &kg->__tex_image_001; break; - case 2: tex = &kg->__tex_image_002; break; - case 3: tex = &kg->__tex_image_003; break; - case 4: tex = &kg->__tex_image_004; break; - case 5: tex = &kg->__tex_image_005; break; - case 6: tex = &kg->__tex_image_006; break; - case 7: tex = &kg->__tex_image_007; break; - case 8: tex = &kg->__tex_image_008; break; - case 9: tex = &kg->__tex_image_009; break; - case 10: tex = &kg->__tex_image_010; break; - case 11: tex = &kg->__tex_image_011; break; - case 12: tex = &kg->__tex_image_012; break; - case 13: tex = &kg->__tex_image_013; break; - case 14: tex = &kg->__tex_image_014; break; - case 15: tex = &kg->__tex_image_015; break; - case 16: tex = &kg->__tex_image_016; break; - case 17: tex = &kg->__tex_image_017; break; - case 18: tex = &kg->__tex_image_018; break; - case 19: tex = &kg->__tex_image_019; break; - case 20: tex = &kg->__tex_image_020; break; - case 21: tex = &kg->__tex_image_021; break; - case 22: tex = &kg->__tex_image_022; break; - case 23: tex = &kg->__tex_image_023; break; - case 24: tex = &kg->__tex_image_024; break; - case 25: tex = &kg->__tex_image_025; break; - case 26: tex = &kg->__tex_image_026; break; - case 27: tex = &kg->__tex_image_027; break; - case 28: tex = &kg->__tex_image_028; break; - case 29: tex = &kg->__tex_image_029; break; - case 30: tex = &kg->__tex_image_030; break; - case 31: tex = &kg->__tex_image_031; break; - case 32: tex = &kg->__tex_image_032; break; - case 33: tex = &kg->__tex_image_033; break; - case 34: tex = &kg->__tex_image_034; break; - case 35: tex = &kg->__tex_image_035; break; - case 36: tex = &kg->__tex_image_036; break; - case 37: tex = &kg->__tex_image_037; break; - case 38: tex = &kg->__tex_image_038; break; - case 39: tex = &kg->__tex_image_039; break; - case 40: tex = &kg->__tex_image_040; break; - case 41: tex = &kg->__tex_image_041; break; - case 42: tex = &kg->__tex_image_042; break; - case 43: tex = &kg->__tex_image_043; break; - case 44: tex = &kg->__tex_image_044; break; - case 45: tex = &kg->__tex_image_045; break; - case 46: tex = &kg->__tex_image_046; break; - case 47: tex = &kg->__tex_image_047; break; - case 48: tex = &kg->__tex_image_048; break; - case 49: tex = &kg->__tex_image_049; break; - case 50: tex = &kg->__tex_image_050; break; - case 51: tex = &kg->__tex_image_051; break; - case 52: tex = &kg->__tex_image_052; break; - case 53: tex = &kg->__tex_image_053; break; - case 54: tex = &kg->__tex_image_054; break; - case 55: tex = &kg->__tex_image_055; break; - case 56: tex = &kg->__tex_image_056; break; - case 57: tex = &kg->__tex_image_057; break; - case 58: tex = &kg->__tex_image_058; break; - case 59: tex = &kg->__tex_image_059; break; - case 60: tex = &kg->__tex_image_060; break; - case 61: tex = &kg->__tex_image_061; break; - case 62: tex = &kg->__tex_image_062; break; - case 63: tex = &kg->__tex_image_063; break; - case 64: tex = &kg->__tex_image_064; break; - case 65: tex = &kg->__tex_image_065; break; - case 66: tex = &kg->__tex_image_066; break; - case 67: tex = &kg->__tex_image_067; break; - case 68: tex = &kg->__tex_image_068; break; - case 69: tex = &kg->__tex_image_069; break; - case 70: tex = &kg->__tex_image_070; break; - case 71: tex = &kg->__tex_image_071; break; - case 72: tex = &kg->__tex_image_072; break; - case 73: tex = &kg->__tex_image_073; break; - case 74: tex = &kg->__tex_image_074; break; - case 75: tex = &kg->__tex_image_075; break; - case 76: tex = &kg->__tex_image_076; break; - case 77: tex = &kg->__tex_image_077; break; - case 78: tex = &kg->__tex_image_078; break; - case 79: tex = &kg->__tex_image_079; break; - case 80: tex = &kg->__tex_image_080; break; - case 81: tex = &kg->__tex_image_081; break; - case 82: tex = &kg->__tex_image_082; break; - case 83: tex = &kg->__tex_image_083; break; - case 84: tex = &kg->__tex_image_084; break; - case 85: tex = &kg->__tex_image_085; break; - case 86: tex = &kg->__tex_image_086; break; - case 87: tex = &kg->__tex_image_087; break; - case 88: tex = &kg->__tex_image_088; break; - case 89: tex = &kg->__tex_image_089; break; - case 90: tex = &kg->__tex_image_090; break; - case 91: tex = &kg->__tex_image_091; break; - case 92: tex = &kg->__tex_image_092; break; - case 93: tex = &kg->__tex_image_093; break; - case 94: tex = &kg->__tex_image_094; break; - default: break; + if (array_index >= 0 && array_index < MAX_BYTE_IMAGES) { + tex = &kg->texture_byte_images[array_index]; } if(tex) { diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h index d99beb8905a..2f2314c9a8b 100644 --- a/intern/cycles/kernel/kernel_accumulate.h +++ b/intern/cycles/kernel/kernel_accumulate.h @@ -301,6 +301,10 @@ __device_inline float3 path_radiance_sum(KernelGlobals *kg, PathRadiance *L) __device_inline void path_radiance_clamp(PathRadiance *L, float3 *L_sum, float clamp) { + #ifdef __OSL__ + using std::isfinite; + #endif + float sum = fabsf((*L_sum).x) + fabsf((*L_sum).y) + fabsf((*L_sum).z); if(!isfinite(sum)) { diff --git a/intern/cycles/kernel/kernel_attribute.h b/intern/cycles/kernel/kernel_attribute.h new file mode 100644 index 00000000000..115de2fdbdb --- /dev/null +++ b/intern/cycles/kernel/kernel_attribute.h @@ -0,0 +1,68 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __KERNEL_ATTRIBUTE_CL__ +#define __KERNEL_ATTRIBUTE_CL__ + +#include "util_types.h" + +#ifdef __OSL__ +#include <string> +#include "util_attribute.h" +#endif + +CCL_NAMESPACE_BEGIN + +/* note: declared in kernel.h, have to add it here because kernel.h is not available */ +bool kernel_osl_use(KernelGlobals *kg); + +__device_inline int find_attribute(KernelGlobals *kg, ShaderData *sd, uint id) +{ + +#ifdef __OSL__ + if (kernel_osl_use(kg)) { + /* for OSL, a hash map is used to lookup the attribute by name. */ + OSLGlobals::AttributeMap &attr_map = kg->osl.attribute_map[sd->object]; + ustring stdname(std::string("std::") + std::string(attribute_standard_name((AttributeStandard)id))); + OSLGlobals::AttributeMap::const_iterator it = attr_map.find(stdname); + if (it != attr_map.end()) { + const OSLGlobals::Attribute &osl_attr = it->second; + /* return result */ + return (osl_attr.elem == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : osl_attr.offset; + } + else + return (int)ATTR_STD_NOT_FOUND; + } + else +#endif + { + /* for SVM, find attribute by unique id */ + uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride; + uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + + while(attr_map.x != id) + attr_map = kernel_tex_fetch(__attributes_map, ++attr_offset); + + /* return result */ + return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : attr_map.z; + } +} + +CCL_NAMESPACE_END + +#endif /* __KERNEL_ATTRIBUTE_CL__ */ diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h index cc8f1f3323b..45f653a686c 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -158,7 +158,7 @@ typedef texture_image<uchar4> texture_image_uchar4; #define kernel_tex_fetch_m128(tex, index) (kg->tex.fetch_m128(index)) #define kernel_tex_fetch_m128i(tex, index) (kg->tex.fetch_m128i(index)) #define kernel_tex_interp(tex, t, size) (kg->tex.interp(t, size)) -#define kernel_tex_image_interp(tex, x, y) (kg->tex.interp(x, y)) +#define kernel_tex_image_interp(tex, x, y) ((tex < MAX_FLOAT_IMAGES) ? kg->texture_float_images[tex].interp(x, y) : kg->texture_byte_images[tex - MAX_FLOAT_IMAGES].interp(x, y)) #define kernel_data (kg->__data) diff --git a/intern/cycles/kernel/kernel_displace.h b/intern/cycles/kernel/kernel_displace.h index f4b33605f5b..6461a1eea38 100644 --- a/intern/cycles/kernel/kernel_displace.h +++ b/intern/cycles/kernel/kernel_displace.h @@ -63,6 +63,8 @@ __device void kernel_shader_evaluate(KernelGlobals *kg, uint4 *input, float4 *ou out = shader_eval_background(kg, &sd, flag); } + shader_release(kg, &sd); + /* write output */ output[i] = make_float4(out.x, out.y, out.z, 0.0f); } diff --git a/intern/cycles/kernel/kernel_globals.h b/intern/cycles/kernel/kernel_globals.h index a99fffbc519..1e56c11ab90 100644 --- a/intern/cycles/kernel/kernel_globals.h +++ b/intern/cycles/kernel/kernel_globals.h @@ -35,10 +35,15 @@ CCL_NAMESPACE_BEGIN #ifdef __KERNEL_CPU__ +#define MAX_BYTE_IMAGES 512 +#define MAX_FLOAT_IMAGES 5 + typedef struct KernelGlobals { + texture_image_uchar4 texture_byte_images[MAX_BYTE_IMAGES]; + texture_image_float4 texture_float_images[MAX_FLOAT_IMAGES]; #define KERNEL_TEX(type, ttype, name) ttype name; -#define KERNEL_IMAGE_TEX(type, ttype, name) ttype name; +#define KERNEL_IMAGE_TEX(type, ttype, name) #include "kernel_textures.h" KernelData __data; diff --git a/intern/cycles/kernel/kernel_object.h b/intern/cycles/kernel/kernel_object.h index 4ff315ca265..222ade504cc 100644 --- a/intern/cycles/kernel/kernel_object.h +++ b/intern/cycles/kernel/kernel_object.h @@ -172,24 +172,61 @@ __device int shader_pass_id(KernelGlobals *kg, ShaderData *sd) __device_inline float particle_index(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; - float4 f = kernel_tex_fetch(__particles, offset); + float4 f = kernel_tex_fetch(__particles, offset + 0); return f.x; } __device float particle_age(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; - float4 f = kernel_tex_fetch(__particles, offset); + float4 f = kernel_tex_fetch(__particles, offset + 0); return f.y; } __device float particle_lifetime(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; - float4 f = kernel_tex_fetch(__particles, offset); + float4 f = kernel_tex_fetch(__particles, offset + 0); return f.z; } +__device float particle_size(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset + 0); + return f.w; +} + +__device float4 particle_rotation(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset + 1); + return f; +} + +__device float3 particle_location(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset + 2); + return make_float3(f.x, f.y, f.z); +} + +__device float3 particle_velocity(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f2 = kernel_tex_fetch(__particles, offset + 2); + float4 f3 = kernel_tex_fetch(__particles, offset + 3); + return make_float3(f2.w, f3.x, f3.y); +} + +__device float3 particle_angular_velocity(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f3 = kernel_tex_fetch(__particles, offset + 3); + float4 f4 = kernel_tex_fetch(__particles, offset + 4); + return make_float3(f3.z, f3.w, f4.x); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index f5188345948..d606c3d634a 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -209,6 +209,8 @@ __device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *ra if(ray->t != FLT_MAX) ray->D = normalize_len(Pend - ray->P, &ray->t); + shader_release(kg, &sd); + bounce++; } } @@ -294,8 +296,10 @@ __device float4 kernel_path_progressive(KernelGlobals *kg, RNG *rng, int sample, L_transparent += average(holdout_weight*throughput); } - if(sd.flag & SD_HOLDOUT_MASK) + if(sd.flag & SD_HOLDOUT_MASK) { + shader_release(kg, &sd); break; + } } #endif @@ -313,8 +317,10 @@ __device float4 kernel_path_progressive(KernelGlobals *kg, RNG *rng, int sample, float probability = path_state_terminate_probability(kg, &state, throughput); float terminate = path_rng(kg, rng, sample, rng_offset + PRNG_TERMINATE); - if(terminate >= probability) + if(terminate >= probability) { + shader_release(kg, &sd); break; + } throughput /= probability; @@ -380,8 +386,10 @@ __device float4 kernel_path_progressive(KernelGlobals *kg, RNG *rng, int sample, #endif /* no BSDF? we can stop here */ - if(!(sd.flag & SD_BSDF)) + if(!(sd.flag & SD_BSDF)) { + shader_release(kg, &sd); break; + } /* sample BSDF */ float bsdf_pdf; @@ -486,8 +494,10 @@ __device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, int sample, Ray float probability = path_state_terminate_probability(kg, &state, throughput); float terminate = path_rng(kg, rng, sample, rng_offset + PRNG_TERMINATE); - if(terminate >= probability) + if(terminate >= probability) { + shader_release(kg, &sd); break; + } throughput /= probability; @@ -554,8 +564,10 @@ __device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, int sample, Ray #endif /* no BSDF? we can stop here */ - if(!(sd.flag & SD_BSDF)) + if(!(sd.flag & SD_BSDF)) { + shader_release(kg, &sd); break; + } /* sample BSDF */ float bsdf_pdf; @@ -661,8 +673,10 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam L_transparent += average(holdout_weight*throughput); } - if(sd.flag & SD_HOLDOUT_MASK) + if(sd.flag & SD_HOLDOUT_MASK) { + shader_release(kg, &sd); break; + } } #endif @@ -682,8 +696,10 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam float probability = path_state_terminate_probability(kg, &state, throughput); float terminate = path_rng(kg, rng, sample, rng_offset + PRNG_TERMINATE); - if(terminate >= probability) + if(terminate >= probability) { + shader_release(kg, &sd); break; + } throughput /= probability; } @@ -693,7 +709,7 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam if(kernel_data.integrator.use_ambient_occlusion) { int num_samples = kernel_data.integrator.ao_samples; float num_samples_inv = 1.0f/num_samples; - float ao_factor = kernel_data.background.ao_factor/num_samples; + float ao_factor = kernel_data.background.ao_factor; for(int j = 0; j < num_samples; j++) { /* todo: solve correlation */ @@ -842,15 +858,20 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam path_state_next(kg, &ps, label); /* setup ray */ - ray.P = ray_offset(sd.P, (label & LABEL_TRANSMIT)? -sd.Ng: sd.Ng); - ray.D = bsdf_omega_in; - ray.t = FLT_MAX; + Ray bsdf_ray; + + bsdf_ray.P = ray_offset(sd.P, (label & LABEL_TRANSMIT)? -sd.Ng: sd.Ng); + bsdf_ray.D = bsdf_omega_in; + bsdf_ray.t = FLT_MAX; #ifdef __RAY_DIFFERENTIALS__ - ray.dP = sd.dP; - ray.dD = bsdf_domega_in; + bsdf_ray.dP = sd.dP; + bsdf_ray.dD = bsdf_domega_in; +#endif +#ifdef __MOTION__ + bsdf_ray.time = sd.time; #endif - kernel_path_indirect(kg, rng, sample*num_samples, ray, buffer, + kernel_path_indirect(kg, rng, sample*num_samples, bsdf_ray, buffer, tp*num_samples_inv, min_ray_pdf, bsdf_pdf, ps, rng_offset+PRNG_BOUNCE_NUM, &L); } } diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index bc873f4e112..b57e27bc8ed 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -30,7 +30,7 @@ #include "osl_shader.h" -#else +#endif #include "svm/bsdf.h" #include "svm/emissive.h" @@ -38,7 +38,6 @@ #include "svm/svm_bsdf.h" #include "svm/svm.h" -#endif CCL_NAMESPACE_BEGIN @@ -47,6 +46,11 @@ CCL_NAMESPACE_BEGIN __device_inline void shader_setup_from_ray(KernelGlobals *kg, ShaderData *sd, const Intersection *isect, const Ray *ray) { +#ifdef __OSL__ + if (kernel_osl_use(kg)) + OSLShader::init(kg, sd); +#endif + /* fetch triangle data */ int prim = kernel_tex_fetch(__prim_index, isect->prim); float4 Ns = kernel_tex_fetch(__tri_normal, prim); @@ -130,6 +134,11 @@ __device void shader_setup_from_sample(KernelGlobals *kg, ShaderData *sd, const float3 P, const float3 Ng, const float3 I, int shader, int object, int prim, float u, float v, float t, float time) { +#ifdef __OSL__ + if (kernel_osl_use(kg)) + OSLShader::init(kg, sd); +#endif + /* vectors */ sd->P = P; sd->N = Ng; @@ -234,6 +243,8 @@ __device void shader_setup_from_sample(KernelGlobals *kg, ShaderData *sd, __device void shader_setup_from_displace(KernelGlobals *kg, ShaderData *sd, int object, int prim, float u, float v) { + /* Note: no OSLShader::init call here, this is done in shader_setup_from_sample! */ + float3 P, Ng, I = make_float3(0.0f, 0.0f, 0.0f); int shader; @@ -252,6 +263,11 @@ __device void shader_setup_from_displace(KernelGlobals *kg, ShaderData *sd, __device_inline void shader_setup_from_background(KernelGlobals *kg, ShaderData *sd, const Ray *ray) { +#ifdef __OSL__ + if (kernel_osl_use(kg)) + OSLShader::init(kg, sd); +#endif + /* vectors */ sd->P = ray->D; sd->N = -sd->P; @@ -294,7 +310,8 @@ __device_inline void shader_setup_from_background(KernelGlobals *kg, ShaderData #ifdef __MULTI_CLOSURE__ -__device_inline void _shader_bsdf_multi_eval(const ShaderData *sd, const float3 omega_in, float *pdf, +#ifdef __OSL__ +__device_inline void _shader_bsdf_multi_eval_osl(const ShaderData *sd, const float3 omega_in, float *pdf, int skip_bsdf, BsdfEval *bsdf_eval, float sum_pdf, float sum_sample_weight) { for(int i = 0; i< sd->num_closure; i++) { @@ -305,12 +322,36 @@ __device_inline void _shader_bsdf_multi_eval(const ShaderData *sd, const float3 if(CLOSURE_IS_BSDF(sc->type)) { float bsdf_pdf = 0.0f; -#ifdef __OSL__ + float3 eval = OSLShader::bsdf_eval(sd, sc, omega_in, bsdf_pdf); -#else - float3 eval = svm_bsdf_eval(sd, sc, omega_in, &bsdf_pdf); + + if(bsdf_pdf != 0.0f) { + bsdf_eval_accum(bsdf_eval, sc->type, eval*sc->weight); + sum_pdf += bsdf_pdf*sc->sample_weight; + } + + sum_sample_weight += sc->sample_weight; + } + } + + *pdf = (sum_sample_weight > 0.0f)? sum_pdf/sum_sample_weight: 0.0f; +} #endif +__device_inline void _shader_bsdf_multi_eval_svm(const ShaderData *sd, const float3 omega_in, float *pdf, + int skip_bsdf, BsdfEval *bsdf_eval, float sum_pdf, float sum_sample_weight) +{ + for(int i = 0; i< sd->num_closure; i++) { + if(i == skip_bsdf) + continue; + + const ShaderClosure *sc = &sd->closure[i]; + + if(CLOSURE_IS_BSDF(sc->type)) { + float bsdf_pdf = 0.0f; + + float3 eval = svm_bsdf_eval(sd, sc, omega_in, &bsdf_pdf); + if(bsdf_pdf != 0.0f) { bsdf_eval_accum(bsdf_eval, sc->type, eval*sc->weight); sum_pdf += bsdf_pdf*sc->sample_weight; @@ -331,7 +372,12 @@ __device void shader_bsdf_eval(KernelGlobals *kg, const ShaderData *sd, #ifdef __MULTI_CLOSURE__ bsdf_eval_init(eval, NBUILTIN_CLOSURES, make_float3(0.0f, 0.0f, 0.0f), kernel_data.film.use_light_pass); - return _shader_bsdf_multi_eval(sd, omega_in, pdf, -1, eval, 0.0f, 0.0f); +#ifdef __OSL__ + if (kernel_osl_use(kg)) + return _shader_bsdf_multi_eval_osl(sd, omega_in, pdf, -1, eval, 0.0f, 0.0f); + else +#endif + return _shader_bsdf_multi_eval_svm(sd, omega_in, pdf, -1, eval, 0.0f, 0.0f); #else const ShaderClosure *sc = &sd->closure; @@ -384,16 +430,23 @@ __device int shader_bsdf_sample(KernelGlobals *kg, const ShaderData *sd, *pdf = 0.0f; #ifdef __OSL__ - label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); -#else - label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if (kernel_osl_use(kg)) + label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); + else #endif + label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if(*pdf != 0.0f) { bsdf_eval_init(bsdf_eval, sc->type, eval*sc->weight, kernel_data.film.use_light_pass); if(sd->num_closure > 1) { float sweight = sc->sample_weight; - _shader_bsdf_multi_eval(sd, *omega_in, pdf, sampled, bsdf_eval, *pdf*sweight, sweight); +#ifdef __OSL__ + if (kernel_osl_use(kg)) + _shader_bsdf_multi_eval_osl(sd, *omega_in, pdf, sampled, bsdf_eval, *pdf*sweight, sweight); + else +#endif + _shader_bsdf_multi_eval_svm(sd, *omega_in, pdf, sampled, bsdf_eval, *pdf*sweight, sweight); } } @@ -416,10 +469,12 @@ __device int shader_bsdf_sample_closure(KernelGlobals *kg, const ShaderData *sd, *pdf = 0.0f; #ifdef __OSL__ - label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); -#else - label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if (kernel_osl_use(kg)) + label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); + else #endif + label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if(*pdf != 0.0f) bsdf_eval_init(bsdf_eval, sc->type, eval*sc->weight, kernel_data.film.use_light_pass); @@ -539,10 +594,12 @@ __device float3 shader_emissive_eval(KernelGlobals *kg, ShaderData *sd) if(CLOSURE_IS_EMISSION(sc->type)) { #ifdef __OSL__ - eval += OSLShader::emissive_eval(sd, sc)*sc->weight; -#else - eval += svm_emissive_eval(sd, sc)*sc->weight; + if (kernel_osl_use(kg)) + eval += OSLShader::emissive_eval(sd, sc)*sc->weight; + else #endif + eval += svm_emissive_eval(sd, sc)*sc->weight; + } } #else @@ -581,17 +638,18 @@ __device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { #ifdef __OSL__ - OSLShader::eval_surface(kg, sd, randb, path_flag); -#else - + if (kernel_osl_use(kg)) + OSLShader::eval_surface(kg, sd, randb, path_flag); + else +#endif + { #ifdef __SVM__ - svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, randb, path_flag); + svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, randb, path_flag); #else - bsdf_diffuse_setup(sd, &sd->closure); - sd->closure.weight = make_float3(0.8f, 0.8f, 0.8f); -#endif - + bsdf_diffuse_setup(sd, &sd->closure); + sd->closure.weight = make_float3(0.8f, 0.8f, 0.8f); #endif + } } /* Background Evaluation */ @@ -599,35 +657,37 @@ __device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, __device float3 shader_eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag) { #ifdef __OSL__ - return OSLShader::eval_background(kg, sd, path_flag); -#else + if (kernel_osl_use(kg)) + return OSLShader::eval_background(kg, sd, path_flag); + else +#endif + { #ifdef __SVM__ - svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, 0.0f, path_flag); + svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, 0.0f, path_flag); #ifdef __MULTI_CLOSURE__ - float3 eval = make_float3(0.0f, 0.0f, 0.0f); + float3 eval = make_float3(0.0f, 0.0f, 0.0f); - for(int i = 0; i< sd->num_closure; i++) { - const ShaderClosure *sc = &sd->closure[i]; + for(int i = 0; i< sd->num_closure; i++) { + const ShaderClosure *sc = &sd->closure[i]; - if(CLOSURE_IS_BACKGROUND(sc->type)) - eval += sc->weight; - } + if(CLOSURE_IS_BACKGROUND(sc->type)) + eval += sc->weight; + } - return eval; + return eval; #else - if(sd->closure.type == CLOSURE_BACKGROUND_ID) - return sd->closure.weight; - else - return make_float3(0.0f, 0.0f, 0.0f); + if(sd->closure.type == CLOSURE_BACKGROUND_ID) + return sd->closure.weight; + else + return make_float3(0.0f, 0.0f, 0.0f); #endif #else - return make_float3(0.8f, 0.8f, 0.8f); -#endif - + return make_float3(0.8f, 0.8f, 0.8f); #endif + } } /* Volume */ @@ -643,10 +703,11 @@ __device float3 shader_volume_eval_phase(KernelGlobals *kg, ShaderData *sd, if(CLOSURE_IS_VOLUME(sc->type)) { #ifdef __OSL__ - eval += OSLShader::volume_eval_phase(sd, sc, omega_in, omega_out); -#else - eval += volume_eval_phase(sd, sc, omega_in, omega_out); + if (kernel_osl_use(kg)) + eval += OSLShader::volume_eval_phase(sd, sc, omega_in, omega_out); + else #endif + eval += volume_eval_phase(sd, sc, omega_in, omega_out); } } @@ -663,10 +724,11 @@ __device void shader_eval_volume(KernelGlobals *kg, ShaderData *sd, { #ifdef __SVM__ #ifdef __OSL__ - OSLShader::eval_volume(kg, sd, randb, path_flag); -#else - svm_eval_nodes(kg, sd, SHADER_TYPE_VOLUME, randb, path_flag); + if (kernel_osl_use(kg)) + OSLShader::eval_volume(kg, sd, randb, path_flag); + else #endif + svm_eval_nodes(kg, sd, SHADER_TYPE_VOLUME, randb, path_flag); #endif } @@ -677,10 +739,11 @@ __device void shader_eval_displacement(KernelGlobals *kg, ShaderData *sd) /* this will modify sd->P */ #ifdef __SVM__ #ifdef __OSL__ - OSLShader::eval_displacement(kg, sd); -#else - svm_eval_nodes(kg, sd, SHADER_TYPE_DISPLACEMENT, 0.0f, 0); + if (kernel_osl_use(kg)) + OSLShader::eval_displacement(kg, sd); + else #endif + svm_eval_nodes(kg, sd, SHADER_TYPE_DISPLACEMENT, 0.0f, 0); #endif } @@ -732,7 +795,8 @@ __device void shader_merge_closures(KernelGlobals *kg, ShaderData *sd) __device void shader_release(KernelGlobals *kg, ShaderData *sd) { #ifdef __OSL__ - OSLShader::release(kg, sd); + if (kernel_osl_use(kg)) + OSLShader::release(kg, sd); #endif } diff --git a/intern/cycles/kernel/kernel_textures.h b/intern/cycles/kernel/kernel_textures.h index c1b8eed3dff..4855a948c6e 100644 --- a/intern/cycles/kernel/kernel_textures.h +++ b/intern/cycles/kernel/kernel_textures.h @@ -66,12 +66,14 @@ KERNEL_TEX(float, texture_float, __filter_table) /* sobol */ KERNEL_TEX(uint, texture_uint, __sobol_directions) +/* full-float image */ +KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_000) +KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_001) +KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_002) +KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_003) +KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_004) + /* image */ -KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_000) -KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_001) -KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_002) -KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_003) -KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_004) KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_005) KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_006) KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_007) @@ -162,13 +164,11 @@ KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_091) KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_092) KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_093) KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_094) - -/* full-float image */ -KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_095) -KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_096) -KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_097) -KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_098) -KERNEL_IMAGE_TEX(float4, texture_image_float4, __tex_image_float_099) +KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_095) +KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_096) +KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_097) +KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_098) +KERNEL_IMAGE_TEX(uchar4, texture_image_uchar4, __tex_image_099) /* packed image (opencl) */ KERNEL_TEX(uchar4, texture_uchar4, __tex_image_packed) diff --git a/intern/cycles/kernel/kernel_triangle.h b/intern/cycles/kernel/kernel_triangle.h index 6c1ea465515..f57c59a45eb 100644 --- a/intern/cycles/kernel/kernel_triangle.h +++ b/intern/cycles/kernel/kernel_triangle.h @@ -16,6 +16,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "kernel_attribute.h" +#include "kernel_projection.h" + CCL_NAMESPACE_BEGIN /* Point on triangle for Moller-Trumbore triangles */ @@ -181,26 +184,13 @@ __device float3 triangle_attribute_float3(KernelGlobals *kg, const ShaderData *s /* motion */ -__device int triangle_find_attribute(KernelGlobals *kg, ShaderData *sd, uint id) -{ - /* find attribute by unique id */ - uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride; - uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); - - while(attr_map.x != id) - attr_map = kernel_tex_fetch(__attributes_map, ++attr_offset); - - /* return result */ - return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : attr_map.z; -} - __device float4 triangle_motion_vector(KernelGlobals *kg, ShaderData *sd) { float3 motion_pre = sd->P, motion_post = sd->P; /* deformation motion */ - int offset_pre = triangle_find_attribute(kg, sd, ATTR_STD_MOTION_PRE); - int offset_post = triangle_find_attribute(kg, sd, ATTR_STD_MOTION_POST); + int offset_pre = find_attribute(kg, sd, ATTR_STD_MOTION_PRE); + int offset_post = find_attribute(kg, sd, ATTR_STD_MOTION_POST); if(offset_pre != ATTR_STD_NOT_FOUND) motion_pre = triangle_attribute_float3(kg, sd, ATTR_ELEMENT_VERTEX, offset_pre, NULL, NULL); @@ -259,7 +249,7 @@ __device float4 triangle_motion_vector(KernelGlobals *kg, ShaderData *sd) __device float3 triangle_uv(KernelGlobals *kg, ShaderData *sd) { - int offset_uv = triangle_find_attribute(kg, sd, ATTR_STD_UV); + int offset_uv = find_attribute(kg, sd, ATTR_STD_UV); if(offset_uv == ATTR_STD_NOT_FOUND) return make_float3(0.0f, 0.0f, 0.0f); diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 30d45ad1118..ce21ab994f0 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -33,7 +33,7 @@ CCL_NAMESPACE_BEGIN #define LIGHT_SIZE 4 #define FILTER_TABLE_SIZE 256 #define RAMP_TABLE_SIZE 256 -#define PARTICLE_SIZE 1 +#define PARTICLE_SIZE 5 #define TIME_INVALID FLT_MAX /* device capabilities */ @@ -352,22 +352,6 @@ typedef enum AttributeElement { ATTR_ELEMENT_NONE } AttributeElement; -typedef enum AttributeStandard { - ATTR_STD_NONE = 0, - ATTR_STD_VERTEX_NORMAL, - ATTR_STD_FACE_NORMAL, - ATTR_STD_UV, - ATTR_STD_GENERATED, - ATTR_STD_POSITION_UNDEFORMED, - ATTR_STD_POSITION_UNDISPLACED, - ATTR_STD_MOTION_PRE, - ATTR_STD_MOTION_POST, - ATTR_STD_PARTICLE, - ATTR_STD_NUM, - - ATTR_STD_NOT_FOUND = ~0 -} AttributeStandard; - /* Closure data */ #define MAX_CLOSURE 8 @@ -382,10 +366,9 @@ typedef struct ShaderClosure { #ifdef __OSL__ void *prim; -#else +#endif float data0; float data1; -#endif } ShaderClosure; diff --git a/intern/cycles/kernel/osl/CMakeLists.txt b/intern/cycles/kernel/osl/CMakeLists.txt index 13b2a39d7d0..d4ea8b12f5a 100644 --- a/intern/cycles/kernel/osl/CMakeLists.txt +++ b/intern/cycles/kernel/osl/CMakeLists.txt @@ -13,6 +13,7 @@ set(SRC bsdf_ashikhmin_velvet.cpp bsdf_diffuse.cpp bsdf_oren_nayar.cpp + bsdf_phong.cpp bsdf_microfacet.cpp bsdf_reflection.cpp bsdf_refraction.cpp diff --git a/intern/cycles/kernel/osl/bsdf_phong.cpp b/intern/cycles/kernel/osl/bsdf_phong.cpp new file mode 100644 index 00000000000..57745079d33 --- /dev/null +++ b/intern/cycles/kernel/osl/bsdf_phong.cpp @@ -0,0 +1,277 @@ +/* + * Adapted from Open Shading Language with this license: + * + * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. + * All Rights Reserved. + * + * Modifications Copyright 2012, Blender Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Sony Pictures Imageworks nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <OpenImageIO/fmath.h> + +#include <OSL/genclosure.h> +#include "osl_closures.h" +#include "util_math.h" + +CCL_NAMESPACE_BEGIN + +using namespace OSL; + +// vanilla phong - leaks energy at grazing angles +// see Global Illumination Compendium entry (66) +class PhongClosure : public BSDFClosure { +public: + Vec3 m_N; + float m_exponent; + PhongClosure() : BSDFClosure(Labels::GLOSSY) { } + + void setup() {}; + + bool mergeable (const ClosurePrimitive *other) const { + const PhongClosure *comp = (const PhongClosure *)other; + return m_N == comp->m_N && m_exponent == comp->m_exponent && + BSDFClosure::mergeable(other); + } + + size_t memsize () const { return sizeof(*this); } + + const char *name () const { return "phong"; } + + void print_on (std::ostream &out) const { + out << name() << " (("; + out << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_exponent << ")"; + } + + float albedo (const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + float cosNI = m_N.dot(omega_in); + float cosNO = m_N.dot(omega_out); + if (cosNI > 0 && cosNO > 0) { + // reflect the view vector + Vec3 R = (2 * cosNO) * m_N - omega_out; + float cosRI = R.dot(omega_in); + if (cosRI > 0) { + float common = 0.5f * (float) M_1_PI * powf(cosRI, m_exponent); + float out = cosNI * (m_exponent + 2) * common; + pdf = (m_exponent + 1) * common; + return Color3 (out, out, out); + } + } + return Color3 (0, 0, 0); + } + + Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3 (0, 0, 0); + } + + ustring sample (const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + // reflect the view vector + Vec3 R = (2 * cosNO) * m_N - omega_out; + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + Vec3 T, B; + make_orthonormals (R, T, B); + float phi = 2 * (float) M_PI * randu; + float cosTheta = powf(randv, 1 / (m_exponent + 1)); + float sinTheta2 = 1 - cosTheta * cosTheta; + float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0; + omega_in = (cosf(phi) * sinTheta) * T + + (sinf(phi) * sinTheta) * B + + ( cosTheta) * R; + if (Ng.dot(omega_in) > 0) + { + // common terms for pdf and eval + float cosNI = m_N.dot(omega_in); + // make sure the direction we chose is still in the right hemisphere + if (cosNI > 0) + { + float common = 0.5f * (float) M_1_PI * powf(cosTheta, m_exponent); + pdf = (m_exponent + 1) * common; + float out = cosNI * (m_exponent + 2) * common; + eval.setValue(out, out, out); + // Since there is some blur to this reflection, make the + // derivatives a bit bigger. In theory this varies with the + // exponent but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; + } + } + } + return Labels::REFLECT; + } +}; + + +class PhongRampClosure : public BSDFClosure { +public: + static const int MAXCOLORS = 8; + Vec3 m_N; + float m_exponent; + Color3 m_colors[MAXCOLORS]; + PhongRampClosure() : BSDFClosure(Labels::GLOSSY) { } + + void setup() {}; + + bool mergeable (const ClosurePrimitive *other) const { + const PhongRampClosure *comp = (const PhongRampClosure *)other; + if (! (m_N == comp->m_N && m_exponent == comp->m_exponent && + BSDFClosure::mergeable(other))) + return false; + for (int i = 0; i < MAXCOLORS; ++i) + if (m_colors[i] != comp->m_colors[i]) + return false; + return true; + } + + size_t memsize () const { return sizeof(*this); } + + const char *name () const { return "phong_ramp"; } + + void print_on (std::ostream &out) const { + out << name() << " (("; + out << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_exponent << ")"; + } + + Color3 get_color (float pos) const + { + float npos = pos * (float)(MAXCOLORS - 1); + int ipos = (int)npos; + if (ipos >= (MAXCOLORS - 1)) + return m_colors[MAXCOLORS - 1]; + float offset = npos - (float)ipos; + return m_colors[ipos] * (1.0f - offset) + m_colors[ipos+1] * offset; + } + + float albedo (const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + float cosNI = m_N.dot(omega_in); + float cosNO = m_N.dot(omega_out); + if (cosNI > 0 && cosNO > 0) { + // reflect the view vector + Vec3 R = (2 * cosNO) * m_N - omega_out; + float cosRI = R.dot(omega_in); + if (cosRI > 0) { + float cosp = powf(cosRI, m_exponent); + float common = 0.5f * (float) M_1_PI * cosp; + float out = cosNI * (m_exponent + 2) * common; + pdf = (m_exponent + 1) * common; + return get_color(cosp) * out; + } + } + return Color3 (0, 0, 0); + } + + Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3 (0, 0, 0); + } + + ustring sample (const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + // reflect the view vector + Vec3 R = (2 * cosNO) * m_N - omega_out; + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + Vec3 T, B; + make_orthonormals (R, T, B); + float phi = 2 * (float) M_PI * randu; + float cosTheta = powf(randv, 1 / (m_exponent + 1)); + float sinTheta2 = 1 - cosTheta * cosTheta; + float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0; + omega_in = (cosf(phi) * sinTheta) * T + + (sinf(phi) * sinTheta) * B + + ( cosTheta) * R; + if (Ng.dot(omega_in) > 0) + { + // common terms for pdf and eval + float cosNI = m_N.dot(omega_in); + // make sure the direction we chose is still in the right hemisphere + if (cosNI > 0) + { + float cosp = powf(cosTheta, m_exponent); + float common = 0.5f * (float) M_1_PI * cosp; + pdf = (m_exponent + 1) * common; + float out = cosNI * (m_exponent + 2) * common; + eval = get_color(cosp) * out; + // Since there is some blur to this reflection, make the + // derivatives a bit bigger. In theory this varies with the + // exponent but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; + } + } + } + return Labels::REFLECT; + } +}; + + + +ClosureParam bsdf_phong_params[] = { + CLOSURE_VECTOR_PARAM(PhongClosure, m_N), + CLOSURE_FLOAT_PARAM (PhongClosure, m_exponent), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(PhongClosure) }; + +ClosureParam bsdf_phong_ramp_params[] = { + CLOSURE_VECTOR_PARAM (PhongRampClosure, m_N), + CLOSURE_FLOAT_PARAM (PhongRampClosure, m_exponent), + CLOSURE_COLOR_ARRAY_PARAM(PhongRampClosure, m_colors, PhongRampClosure::MAXCOLORS), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM (PhongRampClosure) }; + +CLOSURE_PREPARE(bsdf_phong_prepare, PhongClosure) +CLOSURE_PREPARE(bsdf_phong_ramp_prepare, PhongRampClosure) + +CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt index 5a645919358..729d4dae1c9 100644 --- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -5,9 +5,11 @@ set(SRC_OSL node_add_closure.osl node_attribute.osl node_background.osl + node_brick_texture.osl node_bump.osl node_camera.osl node_checker_texture.osl + node_combine_rgb.osl node_convert_from_color.osl node_convert_from_float.osl node_convert_from_normal.osl @@ -23,6 +25,7 @@ set(SRC_OSL node_geometry.osl node_glass_bsdf.osl node_glossy_bsdf.osl + node_holdout.osl node_hsv.osl node_image_texture.osl node_invert.osl @@ -34,12 +37,13 @@ set(SRC_OSL node_mix_closure.osl node_musgrave_texture.osl node_normal.osl - node_blend_weight_texture.osl node_noise_texture.osl + node_object_info.osl node_output_displacement.osl node_output_surface.osl node_output_volume.osl - node_sepcomb_rgb.osl + node_particle_info.osl + node_separate_rgb.osl node_sky_texture.osl node_texture_coordinate.osl node_translucent_bsdf.osl @@ -57,6 +61,7 @@ set(SRC_OSL_HEADERS node_color.h node_fresnel.h stdosl.h + oslutil.h ) set(SRC_OSO @@ -82,4 +87,5 @@ endforeach() add_custom_target(shader ALL DEPENDS ${SRC_OSO} ${SRC_OSL_HEADERS}) -delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_OSO}" ${CYCLES_INSTALL_PATH}/shader) +# CMAKE_CURRENT_SOURCE_DIR is already included in OSO paths +delayed_install("" "${SRC_OSO}" ${CYCLES_INSTALL_PATH}/shader) diff --git a/intern/cycles/kernel/osl/nodes/node_brick_texture.osl b/intern/cycles/kernel/osl/nodes/node_brick_texture.osl new file mode 100644 index 00000000000..4daceb4018e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_brick_texture.osl @@ -0,0 +1,94 @@ +/* + * Copyright 2012, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "stdosl.h" +#include "node_texture.h" + +/* Brick */ + +float brick_noise(int n) /* fast integer noise */ +{ + int nn; + n = (n >> 13) ^ n; + nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647; + return 0.5 * ((float)nn / 1073741824.0); +} + +float brick(point p, float mortar_size, float bias, + float BrickWidth, float row_height, float offset_amount, int offset_frequency, + float squash_amount, int squash_frequency, float tint) +{ + int bricknum, rownum; + float offset = 0.0; + float brick_width = BrickWidth; + float x, y; + + rownum = (int)floor(p[1] / row_height); + + if(offset_frequency && squash_frequency) { + brick_width *= ((int)(rownum) % squash_frequency ) ? 1.0 : squash_amount; /* squash */ + offset = ((int)(rownum) % offset_frequency ) ? 0 : (brick_width*offset_amount); /* offset */ + } + + bricknum = (int)floor((p[0]+offset) / brick_width); + + x = (p[0]+offset) - brick_width*bricknum; + y = p[1] - row_height*rownum; + + tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0); + + return (x < mortar_size || y < mortar_size || + x > (brick_width - mortar_size) || + y > (row_height - mortar_size)) ? 1.0 : 0.0; +} + +shader node_brick_texture( + float Offset = 0.5, + int OffsetFrequency = 2, + float Squash = 1.0, + int SquashFrequency = 1, + point Vector = P, + color Color1 = color(0.2, 0.2, 0.2), + color Color2 = color(0.8, 0.8, 0.8), + color Mortar = color(0.0, 0.0, 0.0), + float Scale = 5.0, + float MortarSize = 0.02, + float Bias = 0.0, + float BrickWidth = 0.5, + float RowHeight = 0.25, + output float Fac = 0.0, + output color Color = color(0.2, 0.2, 0.2)) +{ + float tint = 0.0; + color Col = Color1; + + Fac = brick(Vector*Scale, MortarSize, Bias, BrickWidth, RowHeight, + Offset, OffsetFrequency, Squash, SquashFrequency, tint); + + if(Fac != 1.0) { + float facm = 1.0 - tint; + + Col[0] = facm * (Color1[0]) + tint * Color2[0]; + Col[1] = facm * (Color1[1]) + tint * Color2[1]; + Col[2] = facm * (Color1[2]) + tint * Color2[2]; + } + + Color = (Fac == 1.0) ? Mortar: Col; + +} + diff --git a/intern/cycles/kernel/osl/nodes/node_brightness.osl b/intern/cycles/kernel/osl/nodes/node_brightness.osl index a93ff06d443..4f19a20f736 100644 --- a/intern/cycles/kernel/osl/nodes/node_brightness.osl +++ b/intern/cycles/kernel/osl/nodes/node_brightness.osl @@ -20,15 +20,16 @@ shader node_brightness( color ColorIn = color(0.8, 0.8, 0.8), - float Bright = 0.0, + float Brightness = 0.0, float Contrast = 0.0, - output ColorOut = color(0.8, 0.8, 0.8) + output color ColorOut = color(0.8, 0.8, 0.8)) { float delta = Contrast * (1.0/200.0); float a = 1.0 - delta * 2.0; float b; - Bright *= 1.0/100.0; + /* input value is a percentage */ + float bright_factor = Brightness / 100.0; /* * The algorithm is by Werner D. Streidt @@ -38,11 +39,11 @@ shader node_brightness( if (Contrast > 0.0) { a = (a < 0.0 ? 1.0/a : 0.0); - b = a * (Brightness - delta); + b = a * (bright_factor - delta); } else { delta *= -1.0; - b = a * (Brightness + delta); + b = a * (bright_factor + delta); } ColorOut = a * ColorIn + b; diff --git a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl index 306798b645f..e92d7be34fc 100644 --- a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl @@ -49,10 +49,10 @@ shader node_checker_texture( { Fac = checker(Vector*Scale); if(Fac == 1.0) { - Color = color(Color1, Color1, Color1); + Color = Color1; } else { - Color = color(Color2, Color2, Color2); + Color = Color2; } } diff --git a/intern/cycles/kernel/osl/nodes/node_combine_rgb.osl b/intern/cycles/kernel/osl/nodes/node_combine_rgb.osl new file mode 100644 index 00000000000..546369f660e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_combine_rgb.osl @@ -0,0 +1,29 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "stdosl.h" + +shader node_combine_rgb( + float R = 0.0, + float G = 0.0, + float B = 0.0, + output color Image = color(0.8, 0.8, 0.8)) +{ + Image = color(R, G, B); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_gamma.osl b/intern/cycles/kernel/osl/nodes/node_gamma.osl index 4dae07d70bc..d55e908b0b7 100644 --- a/intern/cycles/kernel/osl/nodes/node_gamma.osl +++ b/intern/cycles/kernel/osl/nodes/node_gamma.osl @@ -21,13 +21,7 @@ shader node_gamma( color ColorIn = color(0.8, 0.8, 0.8), float Gamma = 1.0, - output ColorOut = color(0.8, 0.8, 0.8) + output color ColorOut = color(0.0, 0.0, 0.0)) { - int i; - for (i=0;i<3;i++) { - if (ColorIn[i] > 0.0) - ColorIn[i] = powf(ColorIn[i], Gamma); - } - - ColorOut = ColorIn; + ColorOut = pow(ColorIn, Gamma); } diff --git a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl index cc2104af56f..52743669c99 100644 --- a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl @@ -34,8 +34,8 @@ shader node_glass_bsdf( if(distribution == "Sharp") BSDF = Color*(Fr*reflection(Normal) + (1.0-Fr)*refraction(Normal, eta)); else if(distribution == "Beckmann") - BSDF = Color*(Fr*microfacet_beckmann(Normal, Roughness) + (1.0-Fr)*microfacet_beckmann_refraction(Normal, Roughness, eta)); + BSDF = Color*(Fr*microfacet_beckmann(Normal, Roughness, eta) + (1.0-Fr)*microfacet_beckmann_refraction(Normal, Roughness, eta)); else if(distribution == "GGX") - BSDF = Color*(Fr*microfacet_ggx(Normal, Roughness) + (1.0-Fr)*microfacet_ggx_refraction(Normal, Roughness, eta)); + BSDF = Color*(Fr*microfacet_ggx(Normal, Roughness, eta) + (1.0-Fr)*microfacet_ggx_refraction(Normal, Roughness, eta)); } diff --git a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl index aa446b66cfb..3890630e8a2 100644 --- a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl @@ -29,9 +29,9 @@ shader node_glossy_bsdf( if(distribution == "Sharp") BSDF = Color*reflection(Normal); else if(distribution == "Beckmann") - BSDF = Color*microfacet_beckmann(Normal, Roughness); + BSDF = Color*microfacet_beckmann(Normal, Roughness, 1.0); else if(distribution == "GGX") - BSDF = Color*microfacet_ggx(Normal, Roughness); + BSDF = Color*microfacet_ggx(Normal, Roughness, 1.0); } diff --git a/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl b/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl index e6fa014324c..a8dd65ae23b 100644 --- a/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl @@ -21,46 +21,40 @@ /* Gradient */ -float gradient(point p, string progression, string axis) +float gradient(point p, string type) { float x, y; - - if(axis == "Vertical") { - x= p[1]; - y= p[0]; - } - else { - x= p[0]; - y= p[1]; - } + + x = p[0]; + y = p[1]; float result = 0.0; - if(progression == "Linear") { + if(type == "Linear") { result = (1.0 + x)/2.0; } - else if(progression == "Quadratic") { + else if(type == "Quadratic") { float r = max((1.0 + x)/2.0, 0.0); result = r*r; } - else if(progression == "Easing") { + else if(type == "Easing") { float r = min(max((1.0 + x)/2.0, 0.0), 1.0); float t = r*r; result = (3.0*t - 2.0*t*r); } - else if(progression == "Diagonal") { + else if(type == "Diagonal") { result = (2.0 + x + y)/4.0; } - else if(progression == "Radial") { + else if(type == "Radial") { result = atan2(y, x)/(2*M_PI) + 0.5; } else { float r = max(1.0 - sqrt(x*x + y*y + p[2]*p[2]), 0.0); - if(progression == "Quadratic Sphere") + if(type == "Quadratic Sphere") result = r*r; - else if(progression == "Spherical") + else if(type == "Spherical") result = r; } @@ -68,11 +62,12 @@ float gradient(point p, string progression, string axis) } shader node_gradient_texture( - string Progression = "Linear", - string Axis = "Horizontal", + string Type = "Linear", point Vector = P, - output float Fac = 0.0) + output float Fac = 0.0, + output color Color = color(0.0, 0.0, 0.0)) { - Fac = gradient(Vector, Progression, Axis); + Fac = gradient(Vector, Type); + Color = color(Fac, Fac, Fac); } diff --git a/intern/cycles/kernel/osl/nodes/node_holdout.osl b/intern/cycles/kernel/osl/nodes/node_holdout.osl index 69f8d85a82e..aede50c7ca0 100644 --- a/intern/cycles/kernel/osl/nodes/node_holdout.osl +++ b/intern/cycles/kernel/osl/nodes/node_holdout.osl @@ -18,11 +18,9 @@ #include "stdosl.h" -shader node_background( - color Color = color(0.8, 0.8, 0.8), - float Strength = 1.0, - output closure color Background = background()) +shader node_holdout( + output closure color Holdout = holdout()) { - Background = Color*Strength*background(); + } diff --git a/intern/cycles/kernel/osl/nodes/node_invert.osl b/intern/cycles/kernel/osl/nodes/node_invert.osl index 817198c4561..27021942558 100644 --- a/intern/cycles/kernel/osl/nodes/node_invert.osl +++ b/intern/cycles/kernel/osl/nodes/node_invert.osl @@ -21,7 +21,7 @@ shader node_invert( float Fac = 1.0, color ColorIn = color(0.8, 0.8, 0.8), - output ColorOut = color(0.8, 0.8, 0.8) + output color ColorOut = color(0.8, 0.8, 0.8)) { color ColorInv = color(1.0) - ColorIn; ColorOut = mix(ColorIn, ColorInv, Fac); diff --git a/intern/cycles/kernel/osl/nodes/node_math.osl b/intern/cycles/kernel/osl/nodes/node_math.osl index be9bb71d511..3327795286a 100644 --- a/intern/cycles/kernel/osl/nodes/node_math.osl +++ b/intern/cycles/kernel/osl/nodes/node_math.osl @@ -40,6 +40,7 @@ float safe_log(float a, float b) shader node_math( string type = "Add", + int Clamp = 0, float Value1 = 0.0, float Value2 = 0.0, output float Value = 0.0) @@ -80,5 +81,8 @@ shader node_math( Value = Value1 < Value2; if(type == "Greater Than") Value = Value1 > Value2; + + if(Clamp) + Value = clamp(Value1, 0.0, 1.0); } diff --git a/intern/cycles/kernel/osl/nodes/node_mix.osl b/intern/cycles/kernel/osl/nodes/node_mix.osl index 8a462c995d3..661e543fdd8 100644 --- a/intern/cycles/kernel/osl/nodes/node_mix.osl +++ b/intern/cycles/kernel/osl/nodes/node_mix.osl @@ -267,8 +267,20 @@ color node_mix_linear(float t, color col1, color col2) return outcol; } +color node_mix_clamp(color col) +{ + color outcol = col; + + outcol[0] = clamp(col[0], 0.0, 1.0); + outcol[1] = clamp(col[2], 0.0, 1.0); + outcol[2] = clamp(col[2], 0.0, 1.0); + + return outcol; +} + shader node_mix( string type = "Mix", + int Clamp = 0, float Fac = 0.5, color Color1 = color(0.0, 0.0, 0.0), color Color2 = color(0.0, 0.0, 0.0), @@ -312,5 +324,8 @@ shader node_mix( Color = node_mix_soft(t, Color1, Color2); if(type == "Linear Light") Color = node_mix_linear(t, Color1, Color2); + + if(Clamp) + Color = node_mix_clamp(Color); } diff --git a/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl b/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl index 3ab345279f1..3e1a6862660 100644 --- a/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl @@ -186,32 +186,35 @@ float noise_musgrave_ridged_multi_fractal(point p, string basis, float H, float shader node_musgrave_texture( string Type = "fBM", - string Basis = "Perlin", float Dimension = 2.0, float Lacunarity = 1.0, - float Octaves = 2.0, + float Detail = 2.0, float Offset = 0.0, - float Intensity = 1.0, float Gain = 1.0, float Scale = 5.0, point Vector = P, - output float Fac = 0.0) + output float Fac = 0.0, + output color Color = color(0.0, 0.0, 0.0)) { - float dimension = max(Dimension, 0.0); - float octaves = max(Octaves, 0.0); + float dimension = max(Dimension, 1e-5); + float octaves = clamp(Detail, 0.0, 16.0); float lacunarity = max(Lacunarity, 1e-5); + string Basis = "Perlin"; + float intensity = 1.0; point p = Vector*Scale; if(Type == "Multifractal") - Fac = Intensity*noise_musgrave_multi_fractal(p, Basis, dimension, lacunarity, octaves); + Fac = intensity*noise_musgrave_multi_fractal(p, Basis, dimension, lacunarity, octaves); else if(Type == "fBM") - Fac = Intensity*noise_musgrave_fBm(p, Basis, dimension, lacunarity, octaves); + Fac = intensity*noise_musgrave_fBm(p, Basis, dimension, lacunarity, octaves); else if(Type == "Hybrid Multifractal") - Fac = Intensity*noise_musgrave_hybrid_multi_fractal(p, Basis, dimension, lacunarity, octaves, Offset, Gain); + Fac = intensity*noise_musgrave_hybrid_multi_fractal(p, Basis, dimension, lacunarity, octaves, Offset, Gain); else if(Type == "Ridged Multifractal") - Fac = Intensity*noise_musgrave_ridged_multi_fractal(p, Basis, dimension, lacunarity, octaves, Offset, Gain); + Fac = intensity*noise_musgrave_ridged_multi_fractal(p, Basis, dimension, lacunarity, octaves, Offset, Gain); else if(Type == "Hetero Terrain") - Fac = Intensity*noise_musgrave_hetero_terrain(p, Basis, dimension, lacunarity, octaves, Offset); + Fac = intensity*noise_musgrave_hetero_terrain(p, Basis, dimension, lacunarity, octaves, Offset); + + Color = color(Fac, Fac, Fac); } diff --git a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl index fd9fc1dedc0..1ddb4d8a08b 100644 --- a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl @@ -21,13 +21,12 @@ /* Noise */ -float noise(point p, string basis, float distortion, float detail) +float noise(point p, string basis, float distortion, float detail, float fac, color Color) { point r; int hard = 0; - float fac = 0.0; - if(distortion != 0.0( { + if(distortion != 0.0) { r[0] = noise_basis(p + point(13.5), basis) * distortion; r[1] = noise_basis(p, basis) * distortion; r[2] = noise_basis(p - point(13.5), basis) * distortion; @@ -37,23 +36,21 @@ float noise(point p, string basis, float distortion, float detail) fac = noise_turbulence(p, basis, detail, hard); + Color = color(fac, noise_turbulence(point(p[1], p[0], p[2]), basis, detail, hard), + noise_turbulence(point(p[1], p[2], p[0]), basis, detail, hard)); + return fac; - - /* - Color[0] = Fac; - Color[1] = noise_turbulence(point(p[1], p[0], p[2]), basis, detail, hard); - Color[2] = noise_turbulence(point(p[1], p[2], p[0]), basis, detail, hard); - */ } shader node_noise_texture( - string Basis = "Perlin", float Distortion = 0.0, float Scale = 5.0, float Detail = 2.0, point Vector = P, - output float Fac = 0.0) + output float Fac = 0.0, + output color Color = color(0.2, 0.2, 0.2)) { - Fac = noise(Vector*Scale, Basis, Distortion, Detail); + string Basis = "Perlin"; + Fac = noise(Vector*Scale, Basis, Distortion, Detail, Fac, Color); } diff --git a/intern/cycles/kernel/osl/nodes/node_normal.osl b/intern/cycles/kernel/osl/nodes/node_normal.osl index 038a33c9898..d5f16acb88c 100644 --- a/intern/cycles/kernel/osl/nodes/node_normal.osl +++ b/intern/cycles/kernel/osl/nodes/node_normal.osl @@ -22,10 +22,9 @@ shader node_normal( normal Direction = normal(0.0, 0.0, 0.0), normal NormalIn = normal(0.0, 0.0, 0.0), output normal NormalOut = normal(0.0, 0.0, 0.0), - output float Dot = 1.0 + output float Dot = 1.0) { - Direction = normalize(Direction); - NormalOut = Direction; - Dot = dot(Direction, NormalIn); + NormalOut = normalize(Direction); + Dot = dot(NormalOut, NormalIn); } diff --git a/intern/cycles/kernel/osl/nodes/node_object_info.osl b/intern/cycles/kernel/osl/nodes/node_object_info.osl new file mode 100644 index 00000000000..21e50d8a43e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_object_info.osl @@ -0,0 +1,33 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "stdosl.h" + +shader node_object_info( + output point Location = point(0.0, 0.0, 0.0), + output float ObjectIndex = 0.0, + output float MaterialIndex = 0.0, + output float Random = 0.0 + ) +{ + getattribute("std::object_location", Location); + getattribute("std::object_index", ObjectIndex); + getattribute("std::material_index", MaterialIndex); + getattribute("std::object_random", Random); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_particle_info.osl b/intern/cycles/kernel/osl/nodes/node_particle_info.osl new file mode 100644 index 00000000000..aadc2812865 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_particle_info.osl @@ -0,0 +1,39 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "stdosl.h" + +shader node_particle_info( + output float Index = 0.0, + output float Age = 0.0, + output float Lifetime = 0.0, + output point Location = point(0.0, 0.0, 0.0), + output float Size = 0.0, + output vector Velocity = point(0.0, 0.0, 0.0), + output vector AngularVelocity = point(0.0, 0.0, 0.0) + ) +{ + getattribute("std::particle_index", Index); + getattribute("std::particle_age", Age); + getattribute("std::particle_lifetime", Lifetime); + getattribute("std::particle_location", Location); + getattribute("std::particle_size", Size); + getattribute("std::particle_velocity", Velocity); + getattribute("std::particle_angular_velocity", AngularVelocity); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl b/intern/cycles/kernel/osl/nodes/node_separate_rgb.osl index a02f31f4b07..b48bd7e59d6 100644 --- a/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl +++ b/intern/cycles/kernel/osl/nodes/node_separate_rgb.osl @@ -24,17 +24,7 @@ shader node_separate_rgb( output float G = 0.0, output float B = 0.0) { - R = Image[0]; - G = Image[1]; - B = Image[2]; + R = Image[0]; + G = Image[1]; + B = Image[2]; } - -shader node_combine_rgb( - float R = 0.0, - float G = 0.0, - float B = 0.0, - output color Image = color(0.8, 0.8, 0.8) -{ - Image = color(R, G, B) -} - diff --git a/intern/cycles/kernel/osl/nodes/node_texture.h b/intern/cycles/kernel/osl/nodes/node_texture.h index d2dbd6db8b3..b00bf6ab31f 100644 --- a/intern/cycles/kernel/osl/nodes/node_texture.h +++ b/intern/cycles/kernel/osl/nodes/node_texture.h @@ -212,14 +212,17 @@ float noise_wave(string wave, float a) /* Turbulence */ -float noise_turbulence(point p, string basis, int octaves, int hard) +float noise_turbulence(point p, string basis, float details, int hard) { float fscale = 1.0; float amp = 1.0; float sum = 0.0; - int i; + int i, n; + + float octaves = clamp(details, 0.0, 16.0); + n = (int)octaves; - for (i = 0; i <= octaves; i++) { + for (i = 0; i <= n; i++) { float t = noise_basis(fscale * p, basis); if (hard) @@ -229,10 +232,26 @@ float noise_turbulence(point p, string basis, int octaves, int hard) amp *= 0.5; fscale *= 2.0; } + + float rmd = octaves - floor(octaves); + + if(rmd != 0.0) { + float t = noise_basis(fscale*p, basis); + + if(hard) + t = fabs(2.0*t - 1.0); - sum *= ((float)(1 << octaves) / (float)((1 << (octaves + 1)) - 1)); + float sum2 = sum + t*amp; - return sum; + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + sum2 *= ((float)(1 << (n+1))/(float)((1 << (n+2)) - 1)); + + return (1.0 - rmd)*sum + rmd*sum2; + } + else { + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + return sum; + } } /* Utility */ diff --git a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl index 7a336c148db..5e0cae8cbd1 100644 --- a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl @@ -27,6 +27,6 @@ shader node_velvet_bsdf( { float sigma = clamp(Sigma, 0.0, 1.0); - BSDF = Color*ashikhmin_velvet(Normal, sigma); + BSDF = Color*ashikhmin_velvet(Normal, sigma, 1.0); } diff --git a/intern/cycles/kernel/osl/nodes/node_wave_texture.osl b/intern/cycles/kernel/osl/nodes/node_wave_texture.osl index b55ec771be8..db53faaf94b 100644 --- a/intern/cycles/kernel/osl/nodes/node_wave_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_wave_texture.osl @@ -31,14 +31,14 @@ float wave(point p, float scale, string type, float detail, float distortion, fl float n = 0.0; if(type == "Bands") { - n = (x + y + z)*10.0); + n = (x + y + z)*10.0; } else if(type == "Rings") { n = (sqrt(x*x + y*y + z*z)*20.0); } if(distortion != 0.0) { - n = n +(distortion * noise_turbulence(p*dscale, "Perlin", detail, 0); + n = n +(distortion * noise_turbulence(p*dscale, "Perlin", detail, 0)); } result = noise_wave("Sine", n); @@ -48,12 +48,14 @@ float wave(point p, float scale, string type, float detail, float distortion, fl shader node_wave_texture( string Type = "Bands", float Scale = 5.0, - float distortion = 0.0, - float detail = 2.0, - float dscale = 1.0, + float Distortion = 0.0, + float Detail = 2.0, + float DetailScale = 1.0, point Vector = P, - output float Fac = 0.0) + output float Fac = 0.0, + output color Color = color (0.0, 0.0, 0.0)) { - Fac = wave(Vector, Scale, Type, detail, distortion, dscale); + Fac = wave(Vector, Scale, Type, Detail, Distortion, DetailScale); + Color = color(Fac, Fac, Fac); } diff --git a/intern/cycles/kernel/osl/nodes/oslutil.h b/intern/cycles/kernel/osl/nodes/oslutil.h new file mode 100644 index 00000000000..08611187a3c --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/oslutil.h @@ -0,0 +1,91 @@ +///////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of Sony Pictures Imageworks nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +///////////////////////////////////////////////////////////////////////////// + + +#ifndef CCL_OSLUTIL_H +#define CCL_OSLUTIL_H + +// Return wireframe opacity factor [0, 1] given a geometry type in +// ("triangles", "polygons" or "patches"), and a line_width in raster +// or world space depending on the last (raster) boolean argument. +// +float wireframe(string edge_type, float line_width, int raster) +{ + // ray differentials are so big in diffuse context that this function would always return "wire" + if (raytype("path:diffuse")) return 0.0; + + int np = 0; + point p[64]; + float pixelWidth = 1; + + if (edge_type == "triangles") + { + np = 3; + if (!getattribute("geom:trianglevertices", p)) + return 0.0; + } + else if (edge_type == "polygons" || edge_type == "patches") + { + getattribute("geom:numpolyvertices", np); + if (np < 3 || !getattribute("geom:polyvertices", p)) + return 0.0; + } + + if (raster) + { + // Project the derivatives of P to the viewing plane defined + // by I so we have a measure of how big is a pixel at this point + float pixelWidthX = length(Dx(P) - dot(Dx(P), I) * I); + float pixelWidthY = length(Dy(P) - dot(Dy(P), I) * I); + // Take the average of both axis' length + pixelWidth = (pixelWidthX + pixelWidthY) / 2; + } + + // Use half the width as the neighbor face will render the + // other half. And take the square for fast comparison + pixelWidth *= 0.5 * line_width; + pixelWidth *= pixelWidth; + for (int i = 0; i < np; i++) + { + int i2 = i ? i - 1 : np - 1; + vector dir = P - p[i]; + vector edge = p[i] - p[i2]; + vector crs = cross(edge, dir); + // At this point dot(crs, crs) / dot(edge, edge) is + // the square of area / length(edge) == square of the + // distance to the edge. + if (dot(crs, crs) < (dot(edge, edge) * pixelWidth)) + return 1; + } + return 0; +} + +float wireframe(string edge_type, float line_width) { return wireframe(edge_type, line_width, 1); } +float wireframe(string edge_type) { return wireframe(edge_type, 1.0, 1); } +float wireframe() { return wireframe("polygons", 1.0, 1); } + +#endif /* CCL_OSLUTIL_H */ diff --git a/intern/cycles/kernel/osl/nodes/stdosl.h b/intern/cycles/kernel/osl/nodes/stdosl.h index 0c07c501d69..e5accf4eb54 100644 --- a/intern/cycles/kernel/osl/nodes/stdosl.h +++ b/intern/cycles/kernel/osl/nodes/stdosl.h @@ -35,6 +35,8 @@ #define M_PI_2 1.5707963267948966 /* pi/2 */ #define M_PI_4 0.7853981633974483 /* pi/4 */ #define M_2_PI 0.6366197723675813 /* 2/pi */ +#define M_2PI 6.2831853071795865 /* 2*pi */ +#define M_4PI 12.566370614359173 /* 4*pi */ #define M_2_SQRTPI 1.1283791670955126 /* 2/sqrt(pi) */ #define M_E 2.7182818284590452 /* e (Euler's number) */ #define M_LN2 0.6931471805599453 /* ln(2) */ @@ -121,9 +123,16 @@ PERCOMP1 (round) PERCOMP1 (trunc) PERCOMP2 (fmod) PERCOMP2F (fmod) -PERCOMP2 (mod) -PERCOMP2F (mod) -int mod (int x, int y) BUILTIN; +int mod (int a, int b) { return a - b*(int)floor(a/b); } +point mod (point a, point b) { return a - b*floor(a/b); } +vector mod (vector a, vector b) { return a - b*floor(a/b); } +normal mod (normal a, normal b) { return a - b*floor(a/b); } +color mod (color a, color b) { return a - b*floor(a/b); } +point mod (point a, float b) { return a - b*floor(a/b); } +vector mod (vector a, float b) { return a - b*floor(a/b); } +normal mod (normal a, float b) { return a - b*floor(a/b); } +color mod (color a, float b) { return a - b*floor(a/b); } +float mod (float a, float b) { return a - b*floor(a/b); } PERCOMP2 (min) PERCOMP2 (max) normal clamp (normal x, normal minval, normal maxval) { return max(min(x,maxval),minval); } @@ -131,11 +140,6 @@ vector clamp (vector x, vector minval, vector maxval) { return max(min(x,maxval) point clamp (point x, point minval, point maxval) { return max(min(x,maxval),minval); } color clamp (color x, color minval, color maxval) { return max(min(x,maxval),minval); } float clamp (float x, float minval, float maxval) { return max(min(x,maxval),minval); } -//normal clamp (normal x, normal minval, normal maxval) BUILTIN; -//vector clamp (vector x, vector minval, vector maxval) BUILTIN; -//point clamp (point x, point minval, point maxval) BUILTIN; -//color clamp (color x, color minval, color maxval) BUILTIN; -//float clamp (float x, float minval, float maxval) BUILTIN; normal mix (normal x, normal y, normal a) { return x*(1-a) + y*a; } normal mix (normal x, normal y, float a) { return x*(1-a) + y*a; } vector mix (vector x, vector y, vector a) { return x*(1-a) + y*a; } @@ -163,246 +167,234 @@ vector normalize (vector v) BUILTIN; vector faceforward (vector N, vector I, vector Nref) BUILTIN; vector faceforward (vector N, vector I) BUILTIN; vector reflect (vector I, vector N) { return I - 2*dot(N,I)*N; } -vector refract(vector I, vector N, float eta) { - float IdotN = dot(I, N); - float k = 1 - eta * eta * (1 - IdotN * IdotN); - return (k < 0) ? vector(0, 0, 0) : (eta * I - N * (eta * IdotN + sqrt(k))); +vector refract (vector I, vector N, float eta) { + float IdotN = dot (I, N); + float k = 1 - eta*eta * (1 - IdotN*IdotN); + return (k < 0) ? vector(0,0,0) : (eta*I - N * (eta*IdotN + sqrt(k))); } -void fresnel(vector I, normal N, float eta, - output float Kr, output float Kt, - output vector R, output vector T) +void fresnel (vector I, normal N, float eta, + output float Kr, output float Kt, + output vector R, output vector T) { - float sqr(float x) { - return x * x; - } - float c = dot(I, N); - if (c < 0) - c = -c; - R = reflect(I, N); - float g = 1.0 / sqr(eta) - 1.0 + c * c; - if (g >= 0.0) { - g = sqrt(g); - float beta = g - c; - float F = (c * (g + c) - 1.0) / (c * beta + 1.0); - F = 0.5 * (1.0 + sqr(F)); - F *= sqr(beta / (g + c)); - Kr = F; - Kt = (1.0 - Kr) * eta * eta; - // OPT: the following recomputes some of the above values, but it - // gives us the same result as if the shader-writer called refract() - T = refract(I, N, eta); - } - else { - // total internal reflection - Kr = 1.0; - Kt = 0.0; - T = vector(0, 0, 0); - } -#undef sqr + float sqr(float x) { return x*x; } + float c = dot(I, N); + if (c < 0) + c = -c; + R = reflect(I, N); + float g = 1.0 / sqr(eta) - 1.0 + c * c; + if (g >= 0.0) { + g = sqrt (g); + float beta = g - c; + float F = (c * (g+c) - 1.0) / (c * beta + 1.0); + F = 0.5 * (1.0 + sqr(F)); + F *= sqr (beta / (g+c)); + Kr = F; + Kt = (1.0 - Kr) * eta*eta; + // OPT: the following recomputes some of the above values, but it + // gives us the same result as if the shader-writer called refract() + T = refract(I, N, eta); + } else { + // total internal reflection + Kr = 1.0; + Kt = 0.0; + T = vector (0,0,0); + } } -void fresnel(vector I, normal N, float eta, - output float Kr, output float Kt) +void fresnel (vector I, normal N, float eta, + output float Kr, output float Kt) { - vector R, T; - fresnel(I, N, eta, Kr, Kt, R, T); + vector R, T; + fresnel(I, N, eta, Kr, Kt, R, T); } -point rotate(point q, float angle, point a, point b) BUILTIN; -normal transform(matrix Mto, normal p) BUILTIN; -vector transform(matrix Mto, vector p) BUILTIN; -point transform(matrix Mto, point p) BUILTIN; +normal transform (matrix Mto, normal p) BUILTIN; +vector transform (matrix Mto, vector p) BUILTIN; +point transform (matrix Mto, point p) BUILTIN; +normal transform (string from, string to, normal p) BUILTIN; +vector transform (string from, string to, vector p) BUILTIN; +point transform (string from, string to, point p) BUILTIN; +normal transform (string to, normal p) { return transform("common",to,p); } +vector transform (string to, vector p) { return transform("common",to,p); } +point transform (string to, point p) { return transform("common",to,p); } -// Implementation of transform-with-named-space in terms of matrices: +float transformu (string tounits, float x) BUILTIN; +float transformu (string fromunits, string tounits, float x) BUILTIN; -point transform(string tospace, point x) +point rotate (point p, float angle, point a, point b) { - return transform(matrix("common", tospace), x); + vector axis = normalize (b - a); + float cosang, sinang; + sincos (angle, sinang, cosang); + float cosang1 = 1.0 - cosang; + float x = axis[0], y = axis[1], z = axis[2]; + matrix M = matrix (x * x + (1.0 - x * x) * cosang, + x * y * cosang1 + z * sinang, + x * z * cosang1 - y * sinang, + 0.0, + x * y * cosang1 - z * sinang, + y * y + (1.0 - y * y) * cosang, + y * z * cosang1 + x * sinang, + 0.0, + x * z * cosang1 + y * sinang, + y * z * cosang1 - x * sinang, + z * z + (1.0 - z * z) * cosang, + 0.0, + 0.0, 0.0, 0.0, 1.0); + return transform (M, p-a) + a; } -point transform(string fromspace, string tospace, point x) -{ - return transform(matrix(fromspace, tospace), x); -} - - -vector transform(string tospace, vector x) -{ - return transform(matrix("common", tospace), x); -} - -vector transform(string fromspace, string tospace, vector x) -{ - return transform(matrix(fromspace, tospace), x); -} - - -normal transform(string tospace, normal x) -{ - return transform(matrix("common", tospace), x); -} - -normal transform(string fromspace, string tospace, normal x) -{ - return transform(matrix(fromspace, tospace), x); -} - -float transformu(string tounits, float x) BUILTIN; -float transformu(string fromunits, string tounits, float x) BUILTIN; // Color functions -float luminance(color c) { - return dot((vector)c, vector(0.2126, 0.7152, 0.0722)); -} - +float luminance (color c) BUILTIN; +color blackbody (float temperatureK) BUILTIN; +color wavelength_color (float wavelength_nm) BUILTIN; -color transformc(string to, color x) +color transformc (string to, color x) { - color rgb_to_hsv(color rgb) { // See Foley & van Dam - float r = rgb[0], g = rgb[1], b = rgb[2]; - float mincomp = min(r, min(g, b)); - float maxcomp = max(r, max(g, b)); - float delta = maxcomp - mincomp; // chroma - float h, s, v; - v = maxcomp; - if (maxcomp > 0) - s = delta / maxcomp; - else s = 0; - if (s <= 0) - h = 0; - else { - if (r >= maxcomp) h = (g - b) / delta; - else if (g >= maxcomp) h = 2 + (b - r) / delta; - else h = 4 + (r - g) / delta; - h /= 6; - if (h < 0) - h += 1; - } - return color(h, s, v); - } - - color rgb_to_hsl(color rgb) { // See Foley & van Dam - // First convert rgb to hsv, then to hsl - float minval = min(rgb[0], min(rgb[1], rgb[2])); - color hsv = rgb_to_hsv(rgb); - float maxval = hsv[2]; // v == maxval - float h = hsv[0], s, l = (minval + maxval) / 2; - if (minval == maxval) - s = 0; // special 'achromatic' case, hue is 0 - else if (l <= 0.5) - s = (maxval - minval) / (maxval + minval); - else - s = (maxval - minval) / (2 - maxval - minval); - return color(h, s, l); - } - - color r; - if (to == "rgb" || to == "RGB") - r = x; - else if (to == "hsv") - r = rgb_to_hsv(x); - else if (to == "hsl") - r = rgb_to_hsl(x); - else if (to == "YIQ") - r = color(dot(vector(0.299, 0.587, 0.114), (vector)x), - dot(vector(0.596, -0.275, -0.321), (vector)x), - dot(vector(0.212, -0.523, 0.311), (vector)x)); - else if (to == "xyz") - r = color(dot(vector(0.412453, 0.357580, 0.180423), (vector)x), - dot(vector(0.212671, 0.715160, 0.072169), (vector)x), - dot(vector(0.019334, 0.119193, 0.950227), (vector)x)); - else { - error("Unknown color space \"%s\"", to); - r = x; - } - return r; + color rgb_to_hsv (color rgb) { // See Foley & van Dam + float r = rgb[0], g = rgb[1], b = rgb[2]; + float mincomp = min (r, min (g, b)); + float maxcomp = max (r, max (g, b)); + float delta = maxcomp - mincomp; // chroma + float h, s, v; + v = maxcomp; + if (maxcomp > 0) + s = delta / maxcomp; + else s = 0; + if (s <= 0) + h = 0; + else { + if (r >= maxcomp) h = (g-b) / delta; + else if (g >= maxcomp) h = 2 + (b-r) / delta; + else h = 4 + (r-g) / delta; + h /= 6; + if (h < 0) + h += 1; + } + return color (h, s, v); + } + + color rgb_to_hsl (color rgb) { // See Foley & van Dam + // First convert rgb to hsv, then to hsl + float minval = min (rgb[0], min (rgb[1], rgb[2])); + color hsv = rgb_to_hsv (rgb); + float maxval = hsv[2]; // v == maxval + float h = hsv[0], s, l = (minval+maxval) / 2; + if (minval == maxval) + s = 0; // special 'achromatic' case, hue is 0 + else if (l <= 0.5) + s = (maxval - minval) / (maxval + minval); + else + s = (maxval - minval) / (2 - maxval - minval); + return color (h, s, l); + } + + color r; + if (to == "rgb" || to == "RGB") + r = x; + else if (to == "hsv") + r = rgb_to_hsv (x); + else if (to == "hsl") + r = rgb_to_hsl (x); + else if (to == "YIQ") + r = color (dot (vector(0.299, 0.587, 0.114), (vector)x), + dot (vector(0.596, -0.275, -0.321), (vector)x), + dot (vector(0.212, -0.523, 0.311), (vector)x)); + else if (to == "xyz") + r = color (dot (vector(0.412453, 0.357580, 0.180423), (vector)x), + dot (vector(0.212671, 0.715160, 0.072169), (vector)x), + dot (vector(0.019334, 0.119193, 0.950227), (vector)x)); + else { + error ("Unknown color space \"%s\"", to); + r = x; + } + return r; } -color transformc(string from, string to, color x) +color transformc (string from, string to, color x) { - color hsv_to_rgb(color c) { // Reference: Foley & van Dam - float h = c[0], s = c[1], v = c[2]; - color r; - if (s < 0.0001) { - r = v; - } - else { - h = 6 * (h - floor(h)); // expand to [0..6) - int hi = (int)h; - float f = h - hi; - float p = v * (1 - s); - float q = v * (1 - s * f); - float t = v * (1 - s * (1 - f)); - if (hi == 0) r = color(v, t, p); - else if (hi == 1) r = color(q, v, p); - else if (hi == 2) r = color(p, v, t); - else if (hi == 3) r = color(p, q, v); - else if (hi == 4) r = color(t, p, v); - else r = color(v, p, q); - } - return r; - } - - color hsl_to_rgb(color c) { - float h = c[0], s = c[1], l = c[2]; - // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam) - float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s); - color r; - if (v <= 0) { - r = 0; - } - else { - float min = 2 * l - v; - s = (v - min) / v; - r = hsv_to_rgb(color(h, s, v)); - } - return r; - } - - color r; - if (from == "rgb" || from == "RGB") - r = x; - else if (from == "hsv") - r = hsv_to_rgb(x); - else if (from == "hsl") - r = hsl_to_rgb(x); - else if (from == "YIQ") - r = color(dot(vector(1, 0.9557, 0.6199), (vector)x), - dot(vector(1, -0.2716, -0.6469), (vector)x), - dot(vector(1, -1.1082, 1.7051), (vector)x)); - else if (from == "xyz") - r = color(dot(vector(3.240479, -1.537150, -0.498535), (vector)x), - dot(vector(-0.969256, 1.875991, 0.041556), (vector)x), - dot(vector(0.055648, -0.204043, 1.057311), (vector)x)); - else { - error("Unknown color space \"%s\"", to); - r = x; - } - return transformc(to, r); + color hsv_to_rgb (color c) { // Reference: Foley & van Dam + float h = c[0], s = c[1], v = c[2]; + color r; + if (s < 0.0001) { + r = v; + } else { + h = 6 * (h - floor(h)); // expand to [0..6) + int hi = (int)h; + float f = h - hi; + float p = v * (1-s); + float q = v * (1-s*f); + float t = v * (1-s*(1-f)); + if (hi == 0) r = color (v, t, p); + else if (hi == 1) r = color (q, v, p); + else if (hi == 2) r = color (p, v, t); + else if (hi == 3) r = color (p, q, v); + else if (hi == 4) r = color (t, p, v); + else r = color (v, p, q); + } + return r; + } + + color hsl_to_rgb (color c) { + float h = c[0], s = c[1], l = c[2]; + // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam) + float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s); + color r; + if (v <= 0) { + r = 0; + } else { + float min = 2 * l - v; + s = (v - min) / v; + r = hsv_to_rgb (color (h, s, v)); + } + return r; + } + + color r; + if (from == "rgb" || from == "RGB") + r = x; + else if (from == "hsv") + r = hsv_to_rgb (x); + else if (from == "hsl") + r = hsl_to_rgb (x); + else if (from == "YIQ") + r = color (dot (vector(1, 0.9557, 0.6199), (vector)x), + dot (vector(1, -0.2716, -0.6469), (vector)x), + dot (vector(1, -1.1082, 1.7051), (vector)x)); + else if (from == "xyz") + r = color (dot (vector( 3.240479, -1.537150, -0.498535), (vector)x), + dot (vector(-0.969256, 1.875991, 0.041556), (vector)x), + dot (vector( 0.055648, -0.204043, 1.057311), (vector)x)); + else { + error ("Unknown color space \"%s\"", to); + r = x; + } + return transformc (to, r); } // Matrix functions -float determinant(matrix m) BUILTIN; -matrix transpose(matrix m) BUILTIN; +float determinant (matrix m) BUILTIN; +matrix transpose (matrix m) BUILTIN; // Pattern generation -float step(float edge, float x) BUILTIN; -color step(color edge, color x) BUILTIN; -point step(point edge, point x) BUILTIN; -vector step(vector edge, vector x) BUILTIN; -normal step(normal edge, normal x) BUILTIN; -float smoothstep(float edge0, float edge1, float x) BUILTIN; +float step (float edge, float x) BUILTIN; +color step (color edge, color x) BUILTIN; +point step (point edge, point x) BUILTIN; +vector step (vector edge, vector x) BUILTIN; +normal step (normal edge, normal x) BUILTIN; +float smoothstep (float edge0, float edge1, float x) BUILTIN; // Derivatives and area operators @@ -413,26 +405,24 @@ float smoothstep(float edge0, float edge1, float x) BUILTIN; // String functions -int strlen(string s) BUILTIN; -int startswith(string s, string prefix) BUILTIN; -int endswith(string s, string suffix) BUILTIN; -string substr(string s, int start, int len) BUILTIN; -string substr(string s, int start) { - return substr(s, start, strlen(s)); -} +int strlen (string s) BUILTIN; +int startswith (string s, string prefix) BUILTIN; +int endswith (string s, string suffix) BUILTIN; +string substr (string s, int start, int len) BUILTIN; +string substr (string s, int start) { return substr (s, start, strlen(s)); } // Define concat in terms of shorter concat -string concat(string a, string b, string c) { - return concat(concat(a, b), c); +string concat (string a, string b, string c) { + return concat(concat(a,b), c); } -string concat(string a, string b, string c, string d) { - return concat(concat(a, b, c), d); +string concat (string a, string b, string c, string d) { + return concat(concat(a,b,c), d); } -string concat(string a, string b, string c, string d, string e) { - return concat(concat(a, b, c, d), e); +string concat (string a, string b, string c, string d, string e) { + return concat(concat(a,b,c,d), e); } -string concat(string a, string b, string c, string d, string e, string f) { - return concat(concat(a, b, c, d, e), f); +string concat (string a, string b, string c, string d, string e, string f) { + return concat(concat(a,b,c,d,e), f); } @@ -445,16 +435,20 @@ closure color diffuse(normal N) BUILTIN; closure color oren_nayar(normal N, float sigma) BUILTIN; closure color translucent(normal N) BUILTIN; closure color reflection(normal N, float eta) BUILTIN; -closure color reflection(normal N) { return reflection(N, 0.0); } +closure color reflection(normal N) { return reflection (N, 0.0); } closure color refraction(normal N, float eta) BUILTIN; closure color dielectric(normal N, float eta) BUILTIN; closure color transparent() BUILTIN; -closure color microfacet_ggx(normal N, float ag) BUILTIN; +closure color microfacet_ggx(normal N, float ag, float eta) BUILTIN; closure color microfacet_ggx_refraction(normal N, float ag, float eta) BUILTIN; -closure color microfacet_beckmann(normal N, float ab) BUILTIN; +closure color microfacet_beckmann(normal N, float ab, float eta) BUILTIN; closure color microfacet_beckmann_refraction(normal N, float ab, float eta) BUILTIN; -closure color ward(normal N, vector T, float ax, float ay) BUILTIN; -closure color ashikhmin_velvet(normal N, float sigma) BUILTIN; +closure color ward(normal N, vector T,float ax, float ay) BUILTIN; +closure color phong(normal N, float exponent) BUILTIN; +closure color phong_ramp(normal N, float exponent, color colors[8]) BUILTIN; +closure color hair_diffuse(vector T) BUILTIN; +closure color hair_specular(vector T, float offset, float exponent) BUILTIN; +closure color ashikhmin_velvet(normal N, float sigma, float eta) BUILTIN; closure color westin_backscatter(normal N, float roughness) BUILTIN; closure color westin_sheen(normal N, float edginess) BUILTIN; closure color bssrdf_cubic(color radius) BUILTIN; @@ -464,10 +458,75 @@ closure color emission() BUILTIN; closure color debug(string tag) BUILTIN; closure color background() BUILTIN; closure color holdout() BUILTIN; -closure color subsurface(float eta, float g, float mfp, float albedo) BUILTIN; +closure color subsurface(float eta, float g, color mfp, color albedo) BUILTIN; + +closure color cloth(normal N, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, + float area_scaled, vector dPdu, color diff_warp_col, color diff_weft_col, + color spec_warp_col, color spec_weft_col, float fresnel_warp, float fresnel_weft, + float spread_x_mult, float spread_y_mult, int pattern, float pattern_angle, + float warp_width_scale, float weft_width_scale, float thread_count_mult_u, + float thread_count_mult_v) BUILTIN; +closure color cloth_specular(normal N, color spec_col[4], float eta[4], int thread_pattern[4], + float pattern_weight[4], int current_thread, float brdf_interp, + float btf_interp, float uux, float vvx, float area_scaled, vector dPdu, + float eccentricity[4], float angle[4], float Kx[4], float Ky[4], + float Sx[4], float Sy[4]) BUILTIN; +closure color fakefur_diffuse(normal N, vector T, float fur_reflectivity, float fur_transmission, + float shadow_start, float shadow_end, float fur_attenuation, float fur_density, + float fur_avg_radius, float fur_length, float fur_shadow_fraction) BUILTIN; +closure color fakefur_specular(normal N, vector T, float offset, float exp, float fur_reflectivity, + float fur_transmission, float shadow_start, float shadow_end, + float fur_attenuation, float fur_density, float fur_avg_radius, + float fur_length, float fur_shadow_fraction) BUILTIN; + +closure color fakefur_skin(vector N, vector T, float fur_reflectivity, float fur_transmission, + float shadow_start, float shadow_end, float fur_attenuation, float fur_density, + float fur_avg_radius, float fur_length) BUILTIN; + + +closure color cloth(normal N, float s, float t, color diff_warp, color diff_weft, + color spec_warp, color spec_weft, float fresnel_warp, float fresnel_weft, + float spread_x_mult, float spread_y_mult, int pattern, float pattern_angle, + float warp_width_scale, float weft_width_scale, float thread_count_mult_u, + float thread_count_mult_v) +{ + + return cloth(N, s, t, Dx(s), Dx(t), Dy(s), Dy(t), area(P), dPdu, diff_warp, diff_weft, spec_warp, spec_weft, + fresnel_warp, fresnel_weft, spread_x_mult, spread_y_mult, pattern, pattern_angle, + warp_width_scale, weft_width_scale, thread_count_mult_u, thread_count_mult_v); +} + +closure color cloth(normal N, float s, float t, color diff_warp, color diff_weft, + color spec_warp, color spec_weft, float fresnel_warp, float fresnel_weft, + float spread_x_mult, float spread_y_mult, int pattern, float pattern_angle, + float warp_width_scale, float weft_width_scale, float thread_count_mult_u, + float thread_count_mult_v, string tok, string val) +{ + + return cloth(N, s, t, Dx(s), Dx(t), Dy(s), Dy(t), area(P), dPdu, diff_warp, diff_weft, spec_warp, spec_weft, + fresnel_warp, fresnel_weft, spread_x_mult, spread_y_mult, pattern, pattern_angle, + warp_width_scale, weft_width_scale, thread_count_mult_u, thread_count_mult_v, tok, val); +} + + // Renderer state -int raytype(string typename) BUILTIN; +int raytype (string typename) BUILTIN; +// the individual 'isFOOray' functions are deprecated +int iscameraray () { return raytype("camera"); } +int isdiffuseray () { return raytype("diffuse"); } +int isglossyray () { return raytype("glossy"); } +int isshadowray () { return raytype("shadow"); } +int getmatrix (string fromspace, string tospace, output matrix M) BUILTIN; +int getmatrix (string fromspace, output matrix M) { + return getmatrix (fromspace, "common", M); +} + + +// Miscellaneous + + + #undef BUILTIN #undef BUILTIN_DERIV @@ -476,4 +535,3 @@ int raytype(string typename) BUILTIN; #undef PERCOMP2F #endif /* CCL_STDOSL_H */ - diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp index 0793b29d1ac..a1a108a1b1d 100644 --- a/intern/cycles/kernel/osl/osl_closures.cpp +++ b/intern/cycles/kernel/osl/osl_closures.cpp @@ -75,6 +75,8 @@ void OSLShader::register_closures(OSL::ShadingSystem *ss) register_closure(ss, "microfacet_beckmann", OSL_CLOSURE_BSDF_MICROFACET_BECKMANN_ID, bsdf_microfacet_beckmann_params, bsdf_microfacet_beckmann_prepare); register_closure(ss, "microfacet_beckmann_refraction", OSL_CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID, bsdf_microfacet_beckmann_refraction_params, bsdf_microfacet_beckmann_refraction_prepare); register_closure(ss, "ward", OSL_CLOSURE_BSDF_WARD_ID, bsdf_ward_params, bsdf_ward_prepare); + register_closure(ss, "phong", OSL_CLOSURE_BSDF_PHONG_ID, bsdf_phong_params, bsdf_phong_prepare); + register_closure(ss, "phong_ramp", OSL_CLOSURE_BSDF_PHONG_RAMP_ID, bsdf_phong_ramp_params, bsdf_phong_ramp_prepare); register_closure(ss, "ashikhmin_velvet", OSL_CLOSURE_BSDF_ASHIKHMIN_VELVET_ID, bsdf_ashikhmin_velvet_params, bsdf_ashikhmin_velvet_prepare); register_closure(ss, "westin_backscatter", OSL_CLOSURE_BSDF_WESTIN_BACKSCATTER_ID, bsdf_westin_backscatter_params, bsdf_westin_backscatter_prepare); register_closure(ss, "westin_sheen", OSL_CLOSURE_BSDF_WESTIN_SHEEN_ID, bsdf_westin_sheen_params, bsdf_westin_sheen_prepare); diff --git a/intern/cycles/kernel/osl/osl_closures.h b/intern/cycles/kernel/osl/osl_closures.h index 1b4288b8601..00794183ca5 100644 --- a/intern/cycles/kernel/osl/osl_closures.h +++ b/intern/cycles/kernel/osl/osl_closures.h @@ -51,6 +51,8 @@ enum { OSL_CLOSURE_BSDF_MICROFACET_BECKMANN_ID, OSL_CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID, OSL_CLOSURE_BSDF_WARD_ID, + OSL_CLOSURE_BSDF_PHONG_ID, + OSL_CLOSURE_BSDF_PHONG_RAMP_ID, OSL_CLOSURE_BSDF_ASHIKHMIN_VELVET_ID, OSL_CLOSURE_BSDF_WESTIN_BACKSCATTER_ID, OSL_CLOSURE_BSDF_WESTIN_SHEEN_ID, @@ -73,6 +75,8 @@ extern OSL::ClosureParam bsdf_microfacet_ggx_refraction_params[]; extern OSL::ClosureParam bsdf_microfacet_beckmann_params[]; extern OSL::ClosureParam bsdf_microfacet_beckmann_refraction_params[]; extern OSL::ClosureParam bsdf_ward_params[]; +extern OSL::ClosureParam bsdf_phong_params[]; +extern OSL::ClosureParam bsdf_phong_ramp_params[]; extern OSL::ClosureParam bsdf_ashikhmin_velvet_params[]; extern OSL::ClosureParam bsdf_westin_backscatter_params[]; extern OSL::ClosureParam bsdf_westin_sheen_params[]; @@ -94,6 +98,8 @@ void bsdf_microfacet_ggx_refraction_prepare(OSL::RendererServices *, int id, voi void bsdf_microfacet_beckmann_prepare(OSL::RendererServices *, int id, void *data); void bsdf_microfacet_beckmann_refraction_prepare(OSL::RendererServices *, int id, void *data); void bsdf_ward_prepare(OSL::RendererServices *, int id, void *data); +void bsdf_phong_prepare(OSL::RendererServices *, int id, void *data); +void bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void *data); void bsdf_ashikhmin_velvet_prepare(OSL::RendererServices *, int id, void *data); void bsdf_westin_backscatter_prepare(OSL::RendererServices *, int id, void *data); void bsdf_westin_sheen_prepare(OSL::RendererServices *, int id, void *data); diff --git a/intern/cycles/kernel/osl/osl_globals.h b/intern/cycles/kernel/osl/osl_globals.h index 90746c385c7..8cbbfc8dbb1 100644 --- a/intern/cycles/kernel/osl/osl_globals.h +++ b/intern/cycles/kernel/osl/osl_globals.h @@ -30,12 +30,15 @@ CCL_NAMESPACE_BEGIN +class OSLRenderServices; + struct OSLGlobals { /* use */ bool use; - /* shading system */ + /* shading system */ OSL::ShadingSystem *ss; + OSLRenderServices *services; /* shader states */ vector<OSL::ShadingAttribStateRef> surface_state; @@ -60,7 +63,7 @@ struct OSLGlobals { /* thread key for thread specific data lookup */ struct ThreadData { OSL::ShaderGlobals globals; - void *thread_info; + OSL::PerThreadInfo *thread_info; }; static tls_ptr(ThreadData, thread_data); diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index a1574d6e0db..f1deaa9db9d 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -160,6 +160,18 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl return false; } +bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform) +{ + // XXX implementation + return true; +} + +bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, ustring from) +{ + // XXX implementation + return true; +} + bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives, ustring object, TypeDesc type, ustring name, int index, void *val) @@ -167,55 +179,68 @@ bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives, return false; } -static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd, - const OSLGlobals::Attribute& attr, bool derivatives, void *val) +static void set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val) { - if (attr.type == TypeDesc::TypeFloat) { - float *fval = (float *)val; - fval[0] = triangle_attribute_float(kg, sd, attr.elem, attr.offset, - (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); + if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || + type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) + { + float3 *fval = (float3 *)val; + fval[0] = f[0]; + if (derivatives) { + fval[1] = f[1]; + fval[2] = f[2]; + } } else { - /* todo: this won't work when float3 has w component */ - float3 *fval = (float3 *)val; - fval[0] = triangle_attribute_float3(kg, sd, attr.elem, attr.offset, - (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); + float *fval = (float *)val; + fval[0] = average(f[0]); + if (derivatives) { + fval[1] = average(f[1]); + fval[2] = average(f[2]); + } } - - return true; } -static bool get_mesh_attribute_convert(KernelGlobals *kg, const ShaderData *sd, - const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val) +static void set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val) { - if (attr.type == TypeDesc::TypeFloat) { - float tmp[3]; + if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || + type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) + { float3 *fval = (float3 *)val; - - get_mesh_attribute(kg, sd, attr, derivatives, tmp); - - fval[0] = make_float3(tmp[0], tmp[0], tmp[0]); + fval[0] = make_float3(f[0], f[0], f[0]); if (derivatives) { - fval[1] = make_float3(tmp[1], tmp[1], tmp[1]); - fval[2] = make_float3(tmp[2], tmp[2], tmp[2]); + fval[1] = make_float3(f[1], f[2], f[1]); + fval[2] = make_float3(f[2], f[2], f[2]); } + } + else { + float *fval = (float *)val; + fval[0] = f[0]; + if (derivatives) { + fval[1] = f[1]; + fval[2] = f[2]; + } + } +} +static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd, const OSLGlobals::Attribute& attr, + const TypeDesc& type, bool derivatives, void *val) +{ + if (attr.type == TypeDesc::TypeFloat) { + float fval[3]; + fval[0] = triangle_attribute_float(kg, sd, attr.elem, attr.offset, + (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); + set_attribute_float(fval, type, derivatives, val); return true; } else if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector || attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) { - float3 tmp[3]; - float *fval = (float *)val; - - get_mesh_attribute(kg, sd, attr, derivatives, tmp); - - fval[0] = average(tmp[0]); - if (derivatives) { - fval[1] = average(tmp[1]); - fval[2] = average(tmp[2]); - } - + /* todo: this won't work when float3 has w component */ + float3 fval[3]; + fval[0] = triangle_attribute_float3(kg, sd, attr.elem, attr.offset, + (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); + set_attribute_float3(fval, type, derivatives, val); return true; } else @@ -231,11 +256,116 @@ static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivat memset((char *)val + datasize, 0, datasize * 2); } +static bool get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name, + TypeDesc type, bool derivatives, void *val) +{ + /* Object Attributes */ + if (name == "std::object_location") { + float3 fval[3]; + fval[0] = object_location(kg, sd); + fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */ + set_attribute_float3(fval, type, derivatives, val); + return true; + } + else if (name == "std::object_index") { + float fval[3]; + fval[0] = object_pass_id(kg, sd->object); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + else if (name == "std::material_index") { + float fval[3]; + fval[0] = shader_pass_id(kg, sd); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + else if (name == "std::object_random") { + float fval[3]; + fval[0] = object_random_number(kg, sd->object); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + + /* Particle Attributes */ + else if (name == "std::particle_index") { + float fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_index(kg, particle_id); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + else if (name == "std::particle_age") { + float fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_age(kg, particle_id); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + else if (name == "std::particle_lifetime") { + float fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_lifetime(kg, particle_id); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + else if (name == "std::particle_location") { + float3 fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_location(kg, particle_id); + fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */ + set_attribute_float3(fval, type, derivatives, val); + return true; + } +#if 0 /* unsupported */ + else if (name == "std::particle_rotation") { + float4 fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_rotation(kg, particle_id); + fval[1] = fval[2] = make_float4(0.0, 0.0, 0.0, 0.0); /* derivates set to 0 */ + set_attribute_float4(fval, type, derivatives, val); + return true; + } +#endif + else if (name == "std::particle_size") { + float fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_size(kg, particle_id); + fval[1] = fval[2] = 0.0; /* derivates set to 0 */ + set_attribute_float(fval, type, derivatives, val); + return true; + } + else if (name == "std::particle_velocity") { + float3 fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_velocity(kg, particle_id); + fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */ + set_attribute_float3(fval, type, derivatives, val); + return true; + } + else if (name == "std::particle_angular_velocity") { + float3 fval[3]; + uint particle_id = object_particle_id(kg, sd->object); + fval[0] = particle_angular_velocity(kg, particle_id); + fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */ + set_attribute_float3(fval, type, derivatives, val); + return true; + } + + else + return false; +} + bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustring object_name, TypeDesc type, ustring name, void *val) { KernelGlobals *kg = kernel_globals; - const ShaderData *sd = (const ShaderData *)renderstate; + ShaderData *sd = (ShaderData *)renderstate; int object = sd->object; int tri = sd->prim; @@ -258,29 +388,23 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri OSLGlobals::AttributeMap& attribute_map = kg->osl.attribute_map[object]; OSLGlobals::AttributeMap::iterator it = attribute_map.find(name); - if (it == attribute_map.end()) - return false; - - /* type mistmatch? */ - const OSLGlobals::Attribute& attr = it->second; - - if (attr.elem != ATTR_ELEMENT_VALUE) { - /* triangle and vertex attributes */ - if (tri != ~0) { - if (attr.type == type || (attr.type == TypeDesc::TypeColor && - (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal))) - { - return get_mesh_attribute(kg, sd, attr, derivatives, val); - } - else { - return get_mesh_attribute_convert(kg, sd, attr, type, derivatives, val); - } + if (it != attribute_map.end()) { + const OSLGlobals::Attribute& attr = it->second; + + if (attr.elem != ATTR_ELEMENT_VALUE) { + /* triangle and vertex attributes */ + if (tri != ~0) + return get_mesh_attribute(kg, sd, attr, type, derivatives, val); + } + else { + /* object attribute */ + get_object_attribute(attr, derivatives, val); + return true; } } else { - /* object attribute */ - get_object_attribute(attr, derivatives, val); - return true; + /* not found in attribute, check standard object info */ + return get_object_standard_attribute(kg, sd, name, type, derivatives, val); } return false; @@ -297,137 +421,17 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst return false; /* never called by OSL */ } -void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names, - TypeDesc *attr_types, int nattrs) +int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 ¢er, + float radius, int max_points, bool sort, + size_t *out_indices, float *out_distances, int derivs_offset) { -#ifdef WITH_PARTIO - m_attr_queries.push_back(AttrQuery()); - AttrQuery &query = m_attr_queries.back(); - - /* make space for what we need. the only reason to use - * std::vector is to skip the delete */ - query.attr_names.resize(nattrs); - query.attr_partio_types.resize(nattrs); - /* capacity will keep the length of the smallest array passed - * to the query. Just to prevent buffer overruns */ - query.capacity = -1; - - for (int i = 0; i < nattrs; ++i) { - query.attr_names[i] = attr_names[i]; - - TypeDesc element_type = attr_types[i].elementtype(); - - if (query.capacity < 0) - query.capacity = attr_types[i].numelements(); - else - query.capacity = min(query.capacity, (int)attr_types[i].numelements()); - - /* convert the OSL (OIIO) type to the equivalent Partio type so - * we can do a fast check at query time. */ - if (element_type == TypeDesc::TypeFloat) { - query.attr_partio_types[i] = Partio::FLOAT; - } - else if (element_type == TypeDesc::TypeInt) { - query.attr_partio_types[i] = Partio::INT; - } - else if (element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint || - element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal) - { - query.attr_partio_types[i] = Partio::VECTOR; - } - else { - return NULL; /* report some error of unknown type */ - } - } - - /* this is valid until the end of RenderServices */ - return &query; -#else - return NULL; -#endif + return 0; } -#ifdef WITH_PARTIO -Partio::ParticlesData *OSLRenderServices::get_pointcloud(ustring filename) +int OSLRenderServices::pointcloud_get(ustring filename, size_t *indices, int count, + ustring attr_name, TypeDesc attr_type, void *out_data) { - return Partio::readCached(filename.c_str(), true); -} - -#endif - -int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius, - int max_points, void *_attr_query, void **attr_outdata) -{ - /* todo: this code has never been tested, and most likely does not - * work. it's based on the example code in OSL */ - -#ifdef WITH_PARTIO - /* query Partio for this pointcloud lookup using cached attr_query */ - if (!_attr_query) - return 0; - - AttrQuery *attr_query = (AttrQuery *)_attr_query; - if (attr_query->capacity < max_points) - return 0; - - /* get the pointcloud entry for the given filename */ - Partio::ParticlesData *cloud = get_pointcloud(filename); - - /* now we have to look up all the attributes in the file. we can't do this - * before hand cause we never know what we are going to load. */ - int nattrs = attr_query->attr_names.size(); - Partio::ParticleAttribute *attr = (Partio::ParticleAttribute *)alloca(sizeof(Partio::ParticleAttribute) * nattrs); - - for (int i = 0; i < nattrs; ++i) { - /* special case attributes */ - if (attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index) - continue; - - /* lookup the attribute by name*/ - if (!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) { - /* issue an error here and return, types don't match */ - Partio::endCachedAccess(cloud); - cloud->release(); - return 0; - } - } - - std::vector<Partio::ParticleIndex> indices; - std::vector<float> dist2; - - Partio::beginCachedAccess(cloud); - - /* finally, do the lookup */ - cloud->findNPoints((const float *)¢er, max_points, radius, indices, dist2); - int count = indices.size(); - - /* retrieve the attributes directly to user space */ - for (int j = 0; j < nattrs; ++j) { - /* special cases */ - if (attr_query->attr_names[j] == u_distance) { - for (int i = 0; i < count; ++i) - ((float *)attr_outdata[j])[i] = sqrtf(dist2[i]); - } - else if (attr_query->attr_names[j] == u_index) { - for (int i = 0; i < count; ++i) - ((int *)attr_outdata[j])[i] = indices[i]; - } - else { - /* note we make a single call per attribute, we don't loop over the - * points. Partio does it, so it is there that we have to care about - * performance */ - cloud->data(attr[j], count, &indices[0], true, attr_outdata[j]); - } - } - - Partio::endCachedAccess(cloud); - cloud->release(); - - return count; -#else return 0; -#endif } CCL_NAMESPACE_END - diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h index e637b53ab78..790b02a8abc 100644 --- a/intern/cycles/kernel/osl/osl_services.h +++ b/intern/cycles/kernel/osl/osl_services.h @@ -30,18 +30,14 @@ #include <OSL/oslexec.h> #include <OSL/oslclosure.h> -#ifdef WITH_PARTIO -#include <Partio.h> -#endif - CCL_NAMESPACE_BEGIN class Object; class Scene; class Shader; -class ShaderData; -class float3; -class KernelGlobals; +struct ShaderData; +struct float3; +struct KernelGlobals; class OSLRenderServices : public OSL::RendererServices { @@ -53,48 +49,33 @@ public: bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time); bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time); + bool get_matrix(OSL::Matrix44 &result, ustring from, float time); bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time); + + bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform); + bool get_matrix(OSL::Matrix44 &result, ustring from); - bool get_array_attribute(void *renderstate, bool derivatives, + bool get_array_attribute(void *renderstate, bool derivatives, ustring object, TypeDesc type, ustring name, int index, void *val); bool get_attribute(void *renderstate, bool derivatives, ustring object, TypeDesc type, ustring name, void *val); - bool get_userdata(bool derivatives, ustring name, TypeDesc type, + bool get_userdata(bool derivatives, ustring name, TypeDesc type, void *renderstate, void *val); bool has_userdata(ustring name, TypeDesc type, void *renderstate); - void *get_pointcloud_attr_query(ustring *attr_names, - TypeDesc *attr_types, int nattrs); - int pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius, - int max_points, void *attr_query, void **attr_outdata); + int pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 ¢er, + float radius, int max_points, bool sort, size_t *out_indices, + float *out_distances, int derivs_offset); + + int pointcloud_get(ustring filename, size_t *indices, int count, ustring attr_name, + TypeDesc attr_type, void *out_data); private: KernelGlobals *kernel_globals; -#ifdef WITH_PARTIO - /* OSL gets pointers to this but its definition is private. - * right now it only caches the types already converted to - * Partio constants. this is what get_pointcloud_attr_query - * returns */ - struct AttrQuery { - /* names of the attributes to query */ - std::vector<ustring> attr_names; - /* types as (enum Partio::ParticleAttributeType) of the - * attributes in the query */ - std::vector<int> attr_partio_types; - /* for sanity checks, capacity of the output arrays */ - int capacity; - }; - - Partio::ParticlesData *get_pointcloud(ustring filename); - - /* keep a list so adding elements doesn't invalidate pointers */ - std::list<AttrQuery> m_attr_queries; -#endif - static ustring u_distance; static ustring u_index; static ustring u_camera; diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index d8d510a7c9b..98ede0e4f60 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -36,25 +36,25 @@ tls_ptr(OSLGlobals::ThreadData, OSLGlobals::thread_data); void OSLShader::thread_init(KernelGlobals *kg) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = new OSLGlobals::ThreadData(); memset(&tdata->globals, 0, sizeof(OSL::ShaderGlobals)); - tdata->thread_info = ssi->create_thread_info(); + tdata->thread_info = ss->create_thread_info(); tls_set(kg->osl.thread_data, tdata); - ((OSLRenderServices *)ssi->renderer())->thread_init(kg); + kg->osl.services->thread_init(kg); } void OSLShader::thread_free(KernelGlobals *kg) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); - ssi->destroy_thread_info(tdata->thread_info); + ss->destroy_thread_info(tdata->thread_info); delete tdata; } @@ -123,7 +123,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sc.weight = weight; switch (prim->category()) { - case ClosurePrimitive::BSDF: { + case OSL::ClosurePrimitive::BSDF: { if (sd->num_closure == MAX_CLOSURE) return; @@ -137,11 +137,9 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, /* sample weight */ float albedo = bsdf->albedo(TO_VEC3(sd->I)); float sample_weight = fabsf(average(weight)) * albedo; - float sample_sum = sd->osl_closure.bsdf_sample_sum + sample_weight; sc.sample_weight = sample_weight; sc.type = CLOSURE_BSDF_ID; - sd->osl_closure.bsdf_sample_sum = sample_sum; /* scattering flags */ if (scattering == OSL::Labels::DIFFUSE) @@ -155,17 +153,15 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->closure[sd->num_closure++] = sc; break; } - case ClosurePrimitive::Emissive: { + case OSL::ClosurePrimitive::Emissive: { if (sd->num_closure == MAX_CLOSURE) return; /* sample weight */ float sample_weight = fabsf(average(weight)); - float sample_sum = sd->osl_closure.emissive_sample_sum + sample_weight; sc.sample_weight = sample_weight; sc.type = CLOSURE_EMISSION_ID; - sd->osl_closure.emissive_sample_sum = sample_sum; /* flag */ sd->flag |= SD_EMISSION; @@ -173,7 +169,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->closure[sd->num_closure++] = sc; break; } - case ClosurePrimitive::Holdout: + case OSL::ClosurePrimitive::Holdout: if (sd->num_closure == MAX_CLOSURE) return; @@ -182,11 +178,11 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->flag |= SD_HOLDOUT; sd->closure[sd->num_closure++] = sc; break; - case ClosurePrimitive::BSSRDF: - case ClosurePrimitive::Debug: + case OSL::ClosurePrimitive::BSSRDF: + case OSL::ClosurePrimitive::Debug: break; /* not implemented */ - case ClosurePrimitive::Background: - case ClosurePrimitive::Volume: + case OSL::ClosurePrimitive::Background: + case OSL::ClosurePrimitive::Volume: break; /* not relevant */ } } @@ -205,20 +201,19 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx; /* setup shader globals from shader data */ - sd->osl_ctx = ctx; shaderdata_to_shaderglobals(kg, sd, path_flag, globals); /* execute shader for this point */ int shader = sd->shader & SHADER_MASK; if (kg->osl.surface_state[shader]) - ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.surface_state[shader]), *globals); + ss->execute(*ctx, *(kg->osl.surface_state[shader]), *globals); /* flatten closure tree */ sd->num_closure = 0; @@ -263,18 +258,17 @@ static float3 flatten_background_closure_tree(const OSL::ClosureColor *closure) float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx; /* setup shader globals from shader data */ - sd->osl_ctx = ctx; shaderdata_to_shaderglobals(kg, sd, path_flag, globals); /* execute shader for this point */ if (kg->osl.background_state) - ctx->execute(OSL::pvt::ShadUseSurface, *kg->osl.background_state, *globals); + ss->execute(*ctx, *(kg->osl.background_state), *globals); /* return background color immediately */ if (globals->Ci) @@ -301,29 +295,27 @@ static void flatten_volume_closure_tree(ShaderData *sd, sc.weight = weight; switch (prim->category()) { - case ClosurePrimitive::Volume: { + case OSL::ClosurePrimitive::Volume: { if (sd->num_closure == MAX_CLOSURE) return; /* sample weight */ float sample_weight = fabsf(average(weight)); - float sample_sum = sd->osl_closure.volume_sample_sum + sample_weight; sc.sample_weight = sample_weight; sc.type = CLOSURE_VOLUME_ID; - sd->osl_closure.volume_sample_sum = sample_sum; /* add */ sd->closure[sd->num_closure++] = sc; break; } - case ClosurePrimitive::Holdout: - case ClosurePrimitive::Debug: + case OSL::ClosurePrimitive::Holdout: + case OSL::ClosurePrimitive::Debug: break; /* not implemented */ - case ClosurePrimitive::Background: - case ClosurePrimitive::BSDF: - case ClosurePrimitive::Emissive: - case ClosurePrimitive::BSSRDF: + case OSL::ClosurePrimitive::Background: + case OSL::ClosurePrimitive::BSDF: + case OSL::ClosurePrimitive::Emissive: + case OSL::ClosurePrimitive::BSSRDF: break; /* not relevant */ } } @@ -342,25 +334,19 @@ static void flatten_volume_closure_tree(ShaderData *sd, void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx; /* setup shader globals from shader data */ - sd->osl_ctx = ctx; shaderdata_to_shaderglobals(kg, sd, path_flag, globals); /* execute shader */ int shader = sd->shader & SHADER_MASK; if (kg->osl.volume_state[shader]) - ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.volume_state[shader]), *globals); - - /* retrieve resulting closures */ - sd->osl_closure.volume_sample_sum = 0.0f; - sd->osl_closure.num_volume = 0; - sd->osl_closure.randb = randb; + ss->execute(*ctx, *(kg->osl.volume_state[shader]), *globals); if (globals->Ci) flatten_volume_closure_tree(sd, globals->Ci); @@ -371,31 +357,37 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx; /* setup shader globals from shader data */ - sd->osl_ctx = ctx; shaderdata_to_shaderglobals(kg, sd, 0, globals); /* execute shader */ int shader = sd->shader & SHADER_MASK; if (kg->osl.displacement_state[shader]) - ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.displacement_state[shader]), *globals); + ss->execute(*ctx, *(kg->osl.displacement_state[shader]), *globals); /* get back position */ sd->P = TO_FLOAT3(globals->P); } -void OSLShader::release(KernelGlobals *kg, const ShaderData *sd) +void OSLShader::init(KernelGlobals *kg, ShaderData *sd) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); + + sd->osl_ctx = ss->get_context(tdata->thread_info); +} - ssi->release_context((OSL::pvt::ShadingContext *)sd->osl_ctx, tdata->thread_info); +void OSLShader::release(KernelGlobals *kg, ShaderData *sd) +{ + OSL::ShadingSystem *ss = kg->osl.ss; + + ss->release_context((OSL::ShadingContext *)sd->osl_ctx); } /* BSDF Closure */ @@ -458,9 +450,8 @@ float3 OSLShader::emissive_eval(const ShaderData *sd, const ShaderClosure *sc) { OSL::EmissiveClosure *emissive = (OSL::EmissiveClosure *)sc->prim; OSL::Color3 emissive_eval = emissive->eval(TO_VEC3(sd->Ng), TO_VEC3(sd->I)); - eval += TO_FLOAT3(emissive_eval); - return eval; + return TO_FLOAT3(emissive_eval); } /* Volume Closure */ diff --git a/intern/cycles/kernel/osl/osl_shader.h b/intern/cycles/kernel/osl/osl_shader.h index 815557ed203..e2f4d1e94b8 100644 --- a/intern/cycles/kernel/osl/osl_shader.h +++ b/intern/cycles/kernel/osl/osl_shader.h @@ -46,10 +46,10 @@ namespace OSL = ::OSL; class OSLRenderServices; class Scene; -class ShaderClosure; -class ShaderData; -class differential3; -class KernelGlobals; +struct ShaderClosure; +struct ShaderData; +struct differential3; +struct KernelGlobals; class OSLShader { public: @@ -79,7 +79,8 @@ public: const float3 omega_in, const float3 omega_out); /* release */ - static void release(KernelGlobals *kg, const ShaderData *sd); + static void init(KernelGlobals *kg, ShaderData *sd); + static void release(KernelGlobals *kg, ShaderData *sd); }; CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 8901e5e9628..5b0f192ea47 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -154,6 +154,7 @@ CCL_NAMESPACE_END #include "svm_value.h" #include "svm_voronoi.h" #include "svm_checker.h" +#include "svm_brick.h" CCL_NAMESPACE_BEGIN @@ -220,6 +221,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_TEX_IMAGE: svm_node_tex_image(kg, sd, stack, node); break; + case NODE_TEX_IMAGE_BOX: + svm_node_tex_image_box(kg, sd, stack, node); + break; case NODE_TEX_ENVIRONMENT: svm_node_tex_environment(kg, sd, stack, node); break; @@ -249,6 +253,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_TEX_CHECKER: svm_node_tex_checker(kg, sd, stack, node, &offset); break; + case NODE_TEX_BRICK: + svm_node_tex_brick(kg, sd, stack, node, &offset); + break; #endif case NODE_CAMERA: svm_node_camera(kg, sd, stack, node.y, node.z, node.w); diff --git a/intern/cycles/kernel/svm/svm_brick.h b/intern/cycles/kernel/svm/svm_brick.h new file mode 100644 index 00000000000..7e38ac84bf1 --- /dev/null +++ b/intern/cycles/kernel/svm/svm_brick.h @@ -0,0 +1,114 @@ +/* + * Copyright 2012, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +CCL_NAMESPACE_BEGIN + +/* Brick */ + +__device_noinline float brick_noise(int n) /* fast integer noise */ +{ + int nn; + n = (n >> 13) ^ n; + nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; + return 0.5f * ((float)nn / 1073741824.0f); +} + +__device_noinline float svm_brick(float3 p, float scale, float mortar_size, float bias, + float brick_width, float row_height, float offset_amount, int offset_frequency, + float squash_amount, int squash_frequency, float *tint) +{ + p *= scale; + + int bricknum, rownum; + float offset = 0.0f; + float x, y; + + rownum = (int)floor(p.y / row_height); + + if(offset_frequency && squash_frequency) { + brick_width *= ((int)(rownum) % squash_frequency ) ? 1.0f : squash_amount; /* squash */ + offset = ((int)(rownum) % offset_frequency ) ? 0 : (brick_width*offset_amount); /* offset */ + } + + bricknum = (int)floor((p.x+offset) / brick_width); + + x = (p.x+offset) - brick_width*bricknum; + y = p.y - row_height*rownum; + + *tint = clamp((brick_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0f, 1.0f); + + return (x < mortar_size || y < mortar_size || + x > (brick_width - mortar_size) || + y > (row_height - mortar_size)) ? 1.0f : 0.0f; +} + +__device void svm_node_tex_brick(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) +{ + uint4 node2 = read_node(kg, offset); + uint4 node3 = read_node(kg, offset); + + /* Input and Output Sockets */ + uint co_offset, color1_offset, color2_offset, mortar_offset, scale_offset; + uint mortar_size_offset, bias_offset, brick_width_offset, row_height_offset; + uint color_offset, fac_offset; + + /* RNA properties */ + uint offset_frequency, squash_frequency; + + float tint = 0.0f; + + decode_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &mortar_offset); + decode_node_uchar4(node.z, &scale_offset, &mortar_size_offset, &bias_offset, &brick_width_offset); + decode_node_uchar4(node.w, &row_height_offset, &color_offset, &fac_offset, NULL); + + decode_node_uchar4(node2.x, &offset_frequency, &squash_frequency, NULL, NULL); + + float3 co = stack_load_float3(stack, co_offset); + + float3 color1 = stack_load_float3(stack, color1_offset); + float3 color2 = stack_load_float3(stack, color2_offset); + float3 mortar = stack_load_float3(stack, mortar_offset); + + float scale = stack_load_float_default(stack, scale_offset, node2.y); + float mortar_size = stack_load_float_default(stack, mortar_size_offset, node2.z); + float bias = stack_load_float_default(stack, bias_offset, node2.w); + float brick_width = stack_load_float_default(stack, brick_width_offset, node3.x); + float row_height = stack_load_float_default(stack, row_height_offset, node3.y); + float offset_amount = __int_as_float(node3.z); + float squash_amount = __int_as_float(node3.w); + + float f = svm_brick(co, scale, mortar_size, bias, brick_width, row_height, + offset_amount, offset_frequency, squash_amount, squash_frequency, + &tint); + + if(f != 1.0f) { + float facm = 1.0f - tint; + + color1.x = facm * (color1.x) + tint * color2.x; + color1.y = facm * (color1.y) + tint * color2.y; + color1.z = facm * (color1.z) + tint * color2.z; + } + + if(stack_valid(color_offset)) + stack_store_float3(stack, color_offset, (f == 1.0f)? mortar: color1); + if(stack_valid(fac_offset)) + stack_store_float(stack, fac_offset, f); +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/kernel/svm/svm_geometry.h b/intern/cycles/kernel/svm/svm_geometry.h index 3cfce1d087a..22741bdb067 100644 --- a/intern/cycles/kernel/svm/svm_geometry.h +++ b/intern/cycles/kernel/svm/svm_geometry.h @@ -98,25 +98,47 @@ __device void svm_node_object_info(KernelGlobals *kg, ShaderData *sd, float *sta __device void svm_node_particle_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset) { - float data; - switch(type) { case NODE_INFO_PAR_INDEX: { uint particle_id = object_particle_id(kg, sd->object); - data = particle_index(kg, particle_id); - stack_store_float(stack, out_offset, data); + stack_store_float(stack, out_offset, particle_index(kg, particle_id)); break; } case NODE_INFO_PAR_AGE: { uint particle_id = object_particle_id(kg, sd->object); - data = particle_age(kg, particle_id); - stack_store_float(stack, out_offset, data); + stack_store_float(stack, out_offset, particle_age(kg, particle_id)); break; } case NODE_INFO_PAR_LIFETIME: { uint particle_id = object_particle_id(kg, sd->object); - data = particle_lifetime(kg, particle_id); - stack_store_float(stack, out_offset, data); + stack_store_float(stack, out_offset, particle_lifetime(kg, particle_id)); + break; + } + case NODE_INFO_PAR_LOCATION: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float3(stack, out_offset, particle_location(kg, particle_id)); + break; + } + #if 0 /* XXX float4 currently not supported in SVM stack */ + case NODE_INFO_PAR_ROTATION: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float4(stack, out_offset, particle_rotation(kg, particle_id)); + break; + } + #endif + case NODE_INFO_PAR_SIZE: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float(stack, out_offset, particle_size(kg, particle_id)); + break; + } + case NODE_INFO_PAR_VELOCITY: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float3(stack, out_offset, particle_velocity(kg, particle_id)); + break; + } + case NODE_INFO_PAR_ANGULAR_VELOCITY: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float3(stack, out_offset, particle_angular_velocity(kg, particle_id)); break; } } diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h index 3b2b9204d86..662419418e3 100644 --- a/intern/cycles/kernel/svm/svm_image.h +++ b/intern/cycles/kernel/svm/svm_image.h @@ -50,7 +50,7 @@ __device_inline float svm_image_texture_frac(float x, int *ix) return x - (float)i; } -__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) +__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb) { uint4 info = kernel_tex_fetch(__tex_image_packed_info, id); uint width = info.x; @@ -82,15 +82,24 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) r += ty*(1.0f - tx)*svm_image_texture_read(kg, offset + ix + niy*width); r += ty*tx*svm_image_texture_read(kg, offset + nix + niy*width); + if(srgb) { + r.x = color_srgb_to_scene_linear(r.x); + r.y = color_srgb_to_scene_linear(r.y); + r.z = color_srgb_to_scene_linear(r.z); + } + return r; } #else -__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) +__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb) { float4 r; +#ifdef __KERNEL_CPU__ + r = kernel_tex_image_interp(id, x, y); +#else /* not particularly proud of this massive switch, what are the * alternatives? * - use a single big 1D texture, and do our own lookup/filtering @@ -101,11 +110,11 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) * we still need some for other storage */ switch(id) { - case 0: r = kernel_tex_image_interp(__tex_image_000, x, y); break; - case 1: r = kernel_tex_image_interp(__tex_image_001, x, y); break; - case 2: r = kernel_tex_image_interp(__tex_image_002, x, y); break; - case 3: r = kernel_tex_image_interp(__tex_image_003, x, y); break; - case 4: r = kernel_tex_image_interp(__tex_image_004, x, y); break; + case 0: r = kernel_tex_image_interp(__tex_image_float_000, x, y); break; + case 1: r = kernel_tex_image_interp(__tex_image_float_001, x, y); break; + case 2: r = kernel_tex_image_interp(__tex_image_float_002, x, y); break; + case 3: r = kernel_tex_image_interp(__tex_image_float_003, x, y); break; + case 4: r = kernel_tex_image_interp(__tex_image_float_004, x, y); break; case 5: r = kernel_tex_image_interp(__tex_image_005, x, y); break; case 6: r = kernel_tex_image_interp(__tex_image_006, x, y); break; case 7: r = kernel_tex_image_interp(__tex_image_007, x, y); break; @@ -196,15 +205,22 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) case 92: r = kernel_tex_image_interp(__tex_image_092, x, y); break; case 93: r = kernel_tex_image_interp(__tex_image_093, x, y); break; case 94: r = kernel_tex_image_interp(__tex_image_094, x, y); break; - case 95: r = kernel_tex_image_interp(__tex_image_float_095, x, y); break; - case 96: r = kernel_tex_image_interp(__tex_image_float_096, x, y); break; - case 97: r = kernel_tex_image_interp(__tex_image_float_097, x, y); break; - case 98: r = kernel_tex_image_interp(__tex_image_float_098, x, y); break; - case 99: r = kernel_tex_image_interp(__tex_image_float_099, x, y); break; + case 95: r = kernel_tex_image_interp(__tex_image_095, x, y); break; + case 96: r = kernel_tex_image_interp(__tex_image_096, x, y); break; + case 97: r = kernel_tex_image_interp(__tex_image_097, x, y); break; + case 98: r = kernel_tex_image_interp(__tex_image_098, x, y); break; + case 99: r = kernel_tex_image_interp(__tex_image_099, x, y); break; default: kernel_assert(0); return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } +#endif + + if(srgb) { + r.x = color_srgb_to_scene_linear(r.x); + r.y = color_srgb_to_scene_linear(r.y); + r.z = color_srgb_to_scene_linear(r.z); + } return r; } @@ -219,21 +235,102 @@ __device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); float3 co = stack_load_float3(stack, co_offset); - float4 f = svm_image_texture(kg, id, co.x, co.y); - float3 r = make_float3(f.x, f.y, f.z); + float4 f = svm_image_texture(kg, id, co.x, co.y, srgb); - if(srgb) { - r.x = color_srgb_to_scene_linear(r.x); - r.y = color_srgb_to_scene_linear(r.y); - r.z = color_srgb_to_scene_linear(r.z); + if(stack_valid(out_offset)) + stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); + if(stack_valid(alpha_offset)) + stack_store_float(stack, alpha_offset, f.w); +} + +__device void svm_node_tex_image_box(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) +{ + /* get object space normal */ + float3 N = sd->N; + + N = sd->N; + if(sd->object != ~0) + object_inverse_normal_transform(kg, sd, &N); + + /* project from direction vector to barycentric coordinates in triangles */ + N.x = fabsf(N.x); + N.y = fabsf(N.y); + N.z = fabsf(N.z); + + N /= (N.x + N.y + N.z); + + /* basic idea is to think of this as a triangle, each corner representing + * one of the 3 faces of the cube. in the corners we have single textures, + * in between we blend between two textures, and in the middle we a blend + * between three textures. + * + * the Nxyz values are the barycentric coordinates in an equilateral + * triangle, which in case of blending in the middle has a smaller + * equilateral triangle where 3 textures blend. this divides things into + * 7 zones, with an if() test for each zone */ + + float3 weight = make_float3(0.0f, 0.0f, 0.0f); + float blend = __int_as_float(node.w); + float limit = 0.5f*(1.0f + blend); + + /* first test for corners with single texture */ + if(N.x > limit*(N.x + N.y) && N.x > limit*(N.x + N.z)) { + weight.x = 1.0f; + } + else if(N.y > limit*(N.x + N.y) && N.y > limit*(N.y + N.z)) { + weight.y = 1.0f; } + else if(N.z > limit*(N.x + N.z) && N.z > limit*(N.y + N.z)) { + weight.z = 1.0f; + } + else if(blend > 0.0f) { + /* in case of blending, test for mixes between two textures */ + if(N.z < (1.0f - limit)*(N.y + N.x)) { + weight.x = N.x/(N.x + N.y); + weight.x = clamp((weight.x - 0.5f*(1.0f - blend))/blend, 0.0f, 1.0f); + weight.y = 1.0f - weight.x; + } + else if(N.x < (1.0f - limit)*(N.y + N.z)) { + weight.y = N.y/(N.y + N.z); + weight.y = clamp((weight.y - 0.5f*(1.0f - blend))/blend, 0.0f, 1.0f); + weight.z = 1.0f - weight.y; + } + else if(N.y < (1.0f - limit)*(N.x + N.z)) { + weight.x = N.x/(N.x + N.z); + weight.x = clamp((weight.x - 0.5f*(1.0f - blend))/blend, 0.0f, 1.0f); + weight.z = 1.0f - weight.x; + } + else { + /* last case, we have a mix between three */ + weight.x = ((2.0f - limit)*N.x + (limit - 1.0f))/(2.0f*limit - 1.0f); + weight.y = ((2.0f - limit)*N.y + (limit - 1.0f))/(2.0f*limit - 1.0f); + weight.z = ((2.0f - limit)*N.z + (limit - 1.0f))/(2.0f*limit - 1.0f); + } + } + + /* now fetch textures */ + uint co_offset, out_offset, alpha_offset, srgb; + decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); + + float3 co = stack_load_float3(stack, co_offset); + uint id = node.y; + + float4 f = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + + if(weight.x > 0.0f) + f += weight.x*svm_image_texture(kg, id, co.y, co.z, srgb); + if(weight.y > 0.0f) + f += weight.y*svm_image_texture(kg, id, co.x, co.z, srgb); + if(weight.z > 0.0f) + f += weight.z*svm_image_texture(kg, id, co.y, co.x, srgb); if(stack_valid(out_offset)) - stack_store_float3(stack, out_offset, r); + stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); if(stack_valid(alpha_offset)) stack_store_float(stack, alpha_offset, f.w); } + __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { uint id = node.y; @@ -252,17 +349,10 @@ __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float else uv = direction_to_mirrorball(co); - float4 f = svm_image_texture(kg, id, uv.x, uv.y); - float3 r = make_float3(f.x, f.y, f.z); - - if(srgb) { - r.x = color_srgb_to_scene_linear(r.x); - r.y = color_srgb_to_scene_linear(r.y); - r.z = color_srgb_to_scene_linear(r.z); - } + float4 f = svm_image_texture(kg, id, uv.x, uv.y, srgb); if(stack_valid(out_offset)) - stack_store_float3(stack, out_offset, r); + stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); if(stack_valid(alpha_offset)) stack_store_float(stack, alpha_offset, f.w); } diff --git a/intern/cycles/kernel/svm/svm_math.h b/intern/cycles/kernel/svm/svm_math.h index bc2f774097e..e39c7a4ba6c 100644 --- a/intern/cycles/kernel/svm/svm_math.h +++ b/intern/cycles/kernel/svm/svm_math.h @@ -108,6 +108,8 @@ __device float svm_math(NodeMath type, float Fac1, float Fac2) Fac = Fac1 < Fac2; else if(type == NODE_MATH_GREATER_THAN) Fac = Fac1 > Fac2; + else if(type == NODE_MATH_CLAMP) + Fac = clamp(Fac1, 0.0f, 1.0f); else Fac = 0.0f; diff --git a/intern/cycles/kernel/svm/svm_mix.h b/intern/cycles/kernel/svm/svm_mix.h index 6b455e713c2..888e4d9645e 100644 --- a/intern/cycles/kernel/svm/svm_mix.h +++ b/intern/cycles/kernel/svm/svm_mix.h @@ -276,6 +276,17 @@ __device float3 svm_mix_linear(float t, float3 col1, float3 col2) return outcol; } +__device float3 svm_mix_clamp(float3 col) +{ + float3 outcol = col; + + outcol.x = clamp(col.x, 0.0f, 1.0f); + outcol.y = clamp(col.y, 0.0f, 1.0f); + outcol.z = clamp(col.z, 0.0f, 1.0f); + + return outcol; +} + __device float3 svm_mix(NodeMix type, float fac, float3 c1, float3 c2) { float t = clamp(fac, 0.0f, 1.0f); @@ -299,6 +310,7 @@ __device float3 svm_mix(NodeMix type, float fac, float3 c1, float3 c2) case NODE_MIX_COLOR: return svm_mix_color(t, c1, c2); case NODE_MIX_SOFT: return svm_mix_soft(t, c1, c2); case NODE_MIX_LINEAR: return svm_mix_linear(t, c1, c2); + case NODE_MIX_CLAMP: return svm_mix_clamp(c1); } return make_float3(0.0f, 0.0f, 0.0f); diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index 854a708a988..fbaf253177d 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -29,7 +29,7 @@ __device_inline float3 svm_background_offset(KernelGlobals *kg) __device_inline float3 svm_world_to_ndc(KernelGlobals *kg, ShaderData *sd, float3 P) { if(kernel_data.cam.type != CAMERA_PANORAMA) { - if(sd->object != ~0) + if(sd->object == ~0) P += svm_background_offset(kg); Transform tfm = kernel_data.cam.worldtondc; diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index cbff0c099ea..c82eafc790a 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -40,6 +40,7 @@ typedef enum NodeType { NODE_MIX_CLOSURE, NODE_JUMP, NODE_TEX_IMAGE, + NODE_TEX_IMAGE_BOX, NODE_TEX_SKY, NODE_GEOMETRY, NODE_LIGHT_PATH, @@ -89,7 +90,8 @@ typedef enum NodeType { NODE_MIN_MAX, NODE_LIGHT_FALLOFF, NODE_OBJECT_INFO, - NODE_PARTICLE_INFO + NODE_PARTICLE_INFO, + NODE_TEX_BRICK } NodeType; typedef enum NodeAttributeType { @@ -116,7 +118,12 @@ typedef enum NodeObjectInfo { typedef enum NodeParticleInfo { NODE_INFO_PAR_INDEX, NODE_INFO_PAR_AGE, - NODE_INFO_PAR_LIFETIME + NODE_INFO_PAR_LIFETIME, + NODE_INFO_PAR_LOCATION, + NODE_INFO_PAR_ROTATION, + NODE_INFO_PAR_SIZE, + NODE_INFO_PAR_VELOCITY, + NODE_INFO_PAR_ANGULAR_VELOCITY } NodeParticleInfo; typedef enum NodeLightPath { @@ -163,7 +170,8 @@ typedef enum NodeMix { NODE_MIX_VAL, NODE_MIX_COLOR, NODE_MIX_SOFT, - NODE_MIX_LINEAR + NODE_MIX_LINEAR, + NODE_MIX_CLAMP /* used for the clamp UI option */ } NodeMix; typedef enum NodeMath { @@ -183,7 +191,8 @@ typedef enum NodeMath { NODE_MATH_MAXIMUM, NODE_MATH_ROUND, NODE_MATH_LESS_THAN, - NODE_MATH_GREATER_THAN + NODE_MATH_GREATER_THAN, + NODE_MATH_CLAMP /* used for the clamp UI option */ } NodeMath; typedef enum NodeVectorMath { diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt index 4d4fbfe6814..85b476e60d9 100644 --- a/intern/cycles/render/CMakeLists.txt +++ b/intern/cycles/render/CMakeLists.txt @@ -27,6 +27,7 @@ set(SRC nodes.cpp object.cpp osl.cpp + particles.cpp scene.cpp session.cpp shader.cpp @@ -51,6 +52,7 @@ set(SRC_HEADERS nodes.h object.h osl.h + particles.h scene.h session.h shader.h diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index 5c7966d6d96..5122c1af410 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -84,28 +84,6 @@ bool Attribute::same_storage(TypeDesc a, TypeDesc b) return false; } -ustring Attribute::standard_name(AttributeStandard std) -{ - if(std == ATTR_STD_VERTEX_NORMAL) - return ustring("N"); - else if(std == ATTR_STD_FACE_NORMAL) - return ustring("Ng"); - else if(std == ATTR_STD_UV) - return ustring("uv"); - else if(std == ATTR_STD_GENERATED) - return ustring("generated"); - else if(std == ATTR_STD_POSITION_UNDEFORMED) - return ustring("undeformed"); - else if(std == ATTR_STD_POSITION_UNDISPLACED) - return ustring("undisplaced"); - else if(std == ATTR_STD_MOTION_PRE) - return ustring("motion_pre"); - else if(std == ATTR_STD_MOTION_POST) - return ustring("motion_post"); - - return ustring(); -} - /* Attribute Set */ AttributeSet::AttributeSet() @@ -176,7 +154,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name) Attribute *attr = NULL; if(name == ustring()) - name = Attribute::standard_name(std); + name = attribute_standard_name(std); if(std == ATTR_STD_VERTEX_NORMAL) attr = add(name, TypeDesc::TypeNormal, Attribute::VERTEX); diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h index 707d558fc79..d05952edfd7 100644 --- a/intern/cycles/render/attribute.h +++ b/intern/cycles/render/attribute.h @@ -21,6 +21,7 @@ #include "kernel_types.h" +#include "util_attribute.h" #include "util_list.h" #include "util_param.h" #include "util_types.h" @@ -71,7 +72,6 @@ public: const float *data_float() const { return (float*)data(); } static bool same_storage(TypeDesc a, TypeDesc b); - static ustring standard_name(AttributeStandard std); }; /* Attribute Set diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp index a79a3591e0f..51568f65323 100644 --- a/intern/cycles/render/buffers.cpp +++ b/intern/cycles/render/buffers.cpp @@ -74,6 +74,29 @@ int BufferParams::get_passes_size() return align_up(size, 4); } +/* Render Buffer Task */ + +RenderTile::RenderTile() +{ + x = 0; + y = 0; + w = 0; + h = 0; + + start_sample = 0; + num_samples = 0; + resolution = 0; + + offset = 0; + stride = 0; + + buffer = 0; + rng_state = 0; + rgba = 0; + + buffers = NULL; +} + /* Render Buffers */ RenderBuffers::RenderBuffers(Device *device_) @@ -135,7 +158,7 @@ bool RenderBuffers::copy_from_device() return true; } -bool RenderBuffers::get_pass(PassType type, float exposure, int sample, int components, float *pixels) +bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int components, float *pixels) { int pass_offset = 0; diff --git a/intern/cycles/render/buffers.h b/intern/cycles/render/buffers.h index 78712ed89ef..ee0d78a1cd8 100644 --- a/intern/cycles/render/buffers.h +++ b/intern/cycles/render/buffers.h @@ -67,12 +67,11 @@ class RenderBuffers { public: /* buffer parameters */ BufferParams params; + /* float buffer */ device_vector<float> buffer; /* random number generator state */ device_vector<uint> rng_state; - /* mutex, must be locked manually by callers */ - thread_mutex mutex; RenderBuffers(Device *device); ~RenderBuffers(); @@ -80,7 +79,7 @@ public: void reset(Device *device, BufferParams& params); bool copy_from_device(); - bool get_pass(PassType type, float exposure, int sample, int components, float *pixels); + bool get_pass_rect(PassType type, float exposure, int sample, int components, float *pixels); protected: void device_free(); @@ -105,8 +104,6 @@ public: bool transparent; /* byte buffer for tonemapped result */ device_vector<uchar4> rgba; - /* mutex, must be locked manually by callers */ - thread_mutex mutex; DisplayBuffer(Device *device); ~DisplayBuffer(); @@ -124,6 +121,28 @@ protected: Device *device; }; +/* Render Tile + * Rendering task on a buffer */ + +class RenderTile { +public: + int x, y, w, h; + int start_sample; + int num_samples; + int sample; + int resolution; + int offset; + int stride; + + device_ptr buffer; + device_ptr rng_state; + device_ptr rgba; + + RenderBuffers *buffers; + + RenderTile(); +}; + CCL_NAMESPACE_END #endif /* __BUFFERS_H__ */ diff --git a/intern/cycles/render/camera.cpp b/intern/cycles/render/camera.cpp index 55a0f23f8d0..e44caa90f12 100644 --- a/intern/cycles/render/camera.cpp +++ b/intern/cycles/render/camera.cpp @@ -75,6 +75,7 @@ Camera::Camera() need_update = true; need_device_update = true; + previous_need_motion = -1; } Camera::~Camera() @@ -140,8 +141,17 @@ void Camera::update() void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene) { + Scene::MotionType need_motion = scene->need_motion(); + update(); + if (previous_need_motion != need_motion) { + /* scene's motion model could have been changed since previous device + * camera update this could happen for example in case when one render + * layer has got motion pass and another not */ + need_device_update = true; + } + if(!need_device_update) return; @@ -159,7 +169,6 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene) kcam->worldtocamera = transform_inverse(cameratoworld); /* camera motion */ - Scene::MotionType need_motion = scene->need_motion(); kcam->have_motion = 0; if(need_motion == Scene::MOTION_PASS) { @@ -226,6 +235,7 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene) kcam->cliplength = (farclip == FLT_MAX)? FLT_MAX: farclip - nearclip; need_device_update = false; + previous_need_motion = need_motion; } void Camera::device_free(Device *device, DeviceScene *dscene) diff --git a/intern/cycles/render/camera.h b/intern/cycles/render/camera.h index d2a3cce1817..82852bde5e0 100644 --- a/intern/cycles/render/camera.h +++ b/intern/cycles/render/camera.h @@ -91,6 +91,7 @@ public: /* update */ bool need_update; bool need_device_update; + int previous_need_motion; /* functions */ Camera(); diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index 18e802b610d..20fbfa0cf27 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -55,6 +55,7 @@ ShaderNode::ShaderNode(const char *name_) name = name_; id = -1; bump = SHADER_BUMP_NONE; + special_type = SHADER_SPECIAL_TYPE_NONE; } ShaderNode::~ShaderNode() @@ -298,8 +299,8 @@ void ShaderGraph::copy_nodes(set<ShaderNode*>& nodes, map<ShaderNode*, ShaderNod void ShaderGraph::remove_proxy_nodes(vector<bool>& removed) { foreach(ShaderNode *node, nodes) { - ProxyNode *proxy = dynamic_cast<ProxyNode*>(node); - if (proxy) { + if (node->special_type == SHADER_SPECIAL_TYPE_PROXY) { + ProxyNode *proxy = static_cast<ProxyNode*>(node); ShaderInput *input = proxy->inputs[0]; ShaderOutput *output = proxy->outputs[0]; @@ -330,9 +331,8 @@ void ShaderGraph::remove_proxy_nodes(vector<bool>& removed) } /* remove useless mix closures nodes */ - MixClosureNode *mix = dynamic_cast<MixClosureNode*>(node); - - if(mix) { + if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) { + MixClosureNode *mix = static_cast<MixClosureNode*>(node); if(mix->outputs[0]->links.size() && mix->inputs[1]->link == mix->inputs[2]->link) { ShaderOutput *output = mix->inputs[1]->link; vector<ShaderInput*> inputs = mix->outputs[0]->links; @@ -402,6 +402,20 @@ void ShaderGraph::clean() /* break cycles */ break_cycles(output(), visited, on_stack); + /* disconnect unused nodes */ + foreach(ShaderNode *node, nodes) { + if(!visited[node->id]) { + foreach(ShaderInput *to, node->inputs) { + ShaderOutput *from = to->link; + + if (from) { + to->link = NULL; + from->links.erase(remove(from->links.begin(), from->links.end(), to), from->links.end()); + } + } + } + } + /* remove unused nodes */ foreach(ShaderNode *node, nodes) { if(visited[node->id]) diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index 91ec83aba21..c3b674d0f23 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -63,6 +63,17 @@ enum ShaderBump { SHADER_BUMP_DY }; +/* Identifiers for some special node types. + * + * The graph needs to identify these in the clean function. + * Cannot use dynamic_cast, as this is disabled for OSL. */ + +enum ShaderNodeSpecialType { + SHADER_SPECIAL_TYPE_NONE, + SHADER_SPECIAL_TYPE_PROXY, + SHADER_SPECIAL_TYPE_MIX_CLOSURE +}; + /* Enum * * Utility class for enum values. */ @@ -167,6 +178,8 @@ public: ustring name; /* name, not required to be unique */ int id; /* index in graph node array */ ShaderBump bump; /* for bump mapping utility */ + + ShaderNodeSpecialType special_type; /* special node type */ }; diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index 1af0972ecf9..4ee024dd52a 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -36,6 +36,10 @@ ImageManager::ImageManager() need_update = true; pack_images = false; osl_texture_system = NULL; + + tex_num_images = TEX_NUM_IMAGES; + tex_num_float_images = TEX_NUM_FLOAT_IMAGES; + tex_image_byte_start = TEX_IMAGE_BYTE_START; } ImageManager::~ImageManager() @@ -56,6 +60,13 @@ void ImageManager::set_osl_texture_system(void *texture_system) osl_texture_system = texture_system; } +void ImageManager::set_extended_image_limits(void) +{ + tex_num_images = TEX_EXTENDED_NUM_IMAGES; + tex_num_float_images = TEX_EXTENDED_NUM_FLOAT_IMAGES; + tex_image_byte_start = TEX_EXTENDED_IMAGE_BYTE_START; +} + static bool is_float_image(const string& filename) { ImageInput *in = ImageInput::create(filename); @@ -97,7 +108,7 @@ int ImageManager::add_image(const string& filename, bool& is_float) for(slot = 0; slot < float_images.size(); slot++) { if(float_images[slot] && float_images[slot]->filename == filename) { float_images[slot]->users++; - return slot+TEX_IMAGE_FLOAT_START; + return slot; } } @@ -110,8 +121,8 @@ int ImageManager::add_image(const string& filename, bool& is_float) if(slot == float_images.size()) { /* max images limit reached */ if(float_images.size() == TEX_NUM_FLOAT_IMAGES) { - printf("ImageManager::add_image: byte image limit reached %d, skipping '%s'\n", - TEX_NUM_IMAGES, filename.c_str()); + printf("ImageManager::add_image: float image limit reached %d, skipping '%s'\n", + tex_num_float_images, filename.c_str()); return -1; } @@ -125,14 +136,12 @@ int ImageManager::add_image(const string& filename, bool& is_float) img->users = 1; float_images[slot] = img; - /* report slot out of total set of textures */ - slot += TEX_IMAGE_FLOAT_START; } else { for(slot = 0; slot < images.size(); slot++) { if(images[slot] && images[slot]->filename == filename) { images[slot]->users++; - return slot; + return slot+tex_image_byte_start; } } @@ -144,9 +153,9 @@ int ImageManager::add_image(const string& filename, bool& is_float) if(slot == images.size()) { /* max images limit reached */ - if(images.size() == TEX_NUM_IMAGES) { + if(images.size() == tex_num_images) { printf("ImageManager::add_image: byte image limit reached %d, skipping '%s'\n", - TEX_NUM_IMAGES, filename.c_str()); + tex_num_images, filename.c_str()); return -1; } @@ -160,6 +169,8 @@ int ImageManager::add_image(const string& filename, bool& is_float) img->users = 1; images[slot] = img; + + slot += tex_image_byte_start; } need_update = true; @@ -340,20 +351,20 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl Image *img; bool is_float; - if(slot < TEX_IMAGE_FLOAT_START) { - img = images[slot]; + if(slot >= tex_image_byte_start) { + img = images[slot - tex_image_byte_start]; is_float = false; } else { - img = float_images[slot - TEX_IMAGE_FLOAT_START]; + img = float_images[slot]; is_float = true; } if(is_float) { - string filename = path_filename(float_images[slot - TEX_IMAGE_FLOAT_START]->filename); + string filename = path_filename(float_images[slot]->filename); progress->set_status("Updating Images", "Loading " + filename); - device_vector<float4>& tex_img = dscene->tex_float_image[slot - TEX_IMAGE_FLOAT_START]; + device_vector<float4>& tex_img = dscene->tex_float_image[slot]; if(tex_img.device_pointer) device->tex_free(tex_img); @@ -377,10 +388,10 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl device->tex_alloc(name.c_str(), tex_img, true, true); } else { - string filename = path_filename(images[slot]->filename); + string filename = path_filename(images[slot - tex_image_byte_start]->filename); progress->set_status("Updating Images", "Loading " + filename); - device_vector<uchar4>& tex_img = dscene->tex_image[slot]; + device_vector<uchar4>& tex_img = dscene->tex_image[slot - tex_image_byte_start]; if(tex_img.device_pointer) device->tex_free(tex_img); @@ -412,12 +423,12 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, int sl Image *img; bool is_float; - if(slot < TEX_IMAGE_FLOAT_START) { - img = images[slot]; + if(slot >= tex_image_byte_start) { + img = images[slot - tex_image_byte_start]; is_float = false; } else { - img = float_images[slot - TEX_IMAGE_FLOAT_START]; + img = float_images[slot]; is_float = true; } @@ -429,18 +440,18 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, int sl #endif } else if(is_float) { - device->tex_free(dscene->tex_float_image[slot - TEX_IMAGE_FLOAT_START]); - dscene->tex_float_image[slot - TEX_IMAGE_FLOAT_START].clear(); + device->tex_free(dscene->tex_float_image[slot]); + dscene->tex_float_image[slot].clear(); - delete float_images[slot - TEX_IMAGE_FLOAT_START]; - float_images[slot - TEX_IMAGE_FLOAT_START] = NULL; + delete float_images[slot]; + float_images[slot] = NULL; } else { - device->tex_free(dscene->tex_image[slot]); - dscene->tex_image[slot].clear(); + device->tex_free(dscene->tex_image[slot - tex_image_byte_start]); + dscene->tex_image[slot - tex_image_byte_start].clear(); - delete images[slot]; - images[slot] = NULL; + delete images[slot - tex_image_byte_start]; + images[slot - tex_image_byte_start] = NULL; } } } @@ -457,11 +468,11 @@ void ImageManager::device_update(Device *device, DeviceScene *dscene, Progress& continue; if(images[slot]->users == 0) { - device_free_image(device, dscene, slot); + device_free_image(device, dscene, slot + tex_image_byte_start); } else if(images[slot]->need_load) { if(!osl_texture_system) - pool.push(function_bind(&ImageManager::device_load_image, this, device, dscene, slot, &progress)); + pool.push(function_bind(&ImageManager::device_load_image, this, device, dscene, slot + tex_image_byte_start, &progress)); } } @@ -470,11 +481,11 @@ void ImageManager::device_update(Device *device, DeviceScene *dscene, Progress& continue; if(float_images[slot]->users == 0) { - device_free_image(device, dscene, slot + TEX_IMAGE_FLOAT_START); + device_free_image(device, dscene, slot); } else if(float_images[slot]->need_load) { if(!osl_texture_system) - pool.push(function_bind(&ImageManager::device_load_image, this, device, dscene, slot + TEX_IMAGE_FLOAT_START, &progress)); + pool.push(function_bind(&ImageManager::device_load_image, this, device, dscene, slot, &progress)); } } @@ -526,9 +537,9 @@ void ImageManager::device_pack_images(Device *device, DeviceScene *dscene, Progr void ImageManager::device_free(Device *device, DeviceScene *dscene) { for(size_t slot = 0; slot < images.size(); slot++) - device_free_image(device, dscene, slot); + device_free_image(device, dscene, slot + tex_image_byte_start); for(size_t slot = 0; slot < float_images.size(); slot++) - device_free_image(device, dscene, slot + TEX_IMAGE_FLOAT_START); + device_free_image(device, dscene, slot); device->tex_free(dscene->tex_image_packed); dscene->tex_image_packed.clear(); diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index ef046cfcafb..04a705c27bf 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -28,8 +28,11 @@ CCL_NAMESPACE_BEGIN #define TEX_NUM_FLOAT_IMAGES 5 #define TEX_NUM_IMAGES 95 -#define TEX_IMAGE_MAX (TEX_NUM_IMAGES + TEX_NUM_FLOAT_IMAGES) -#define TEX_IMAGE_FLOAT_START TEX_NUM_IMAGES +#define TEX_IMAGE_BYTE_START TEX_NUM_FLOAT_IMAGES + +#define TEX_EXTENDED_NUM_FLOAT_IMAGES 5 +#define TEX_EXTENDED_NUM_IMAGES 512 +#define TEX_EXTENDED_IMAGE_BYTE_START TEX_EXTENDED_NUM_FLOAT_IMAGES /* color to use when textures are not found */ #define TEX_IMAGE_MISSING_R 1 @@ -55,9 +58,15 @@ public: void set_osl_texture_system(void *texture_system); void set_pack_images(bool pack_images_); + void set_extended_image_limits(void); + bool need_update; private: + int tex_num_images; + int tex_num_float_images; + int tex_image_byte_start; + struct Image { string filename; diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index d00b242d153..6445c04257f 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -289,8 +289,14 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen /* CDF */ device->tex_alloc("__light_distribution", dscene->light_distribution); } - else + else { dscene->light_distribution.clear(); + + kintegrator->num_distribution = 0; + kintegrator->num_all_lights = 0; + kintegrator->pdf_triangles = 0.0f; + kintegrator->pdf_lights = 0.0f; + } } void LightManager::device_update_background(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 8f5f2647ebf..7037e36f313 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -366,7 +366,7 @@ void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<Att if(req.std != ATTR_STD_NONE) { /* if standard attribute, add lookup by std:: name convention */ - ustring stdname = ustring(string("std::") + Attribute::standard_name(req.std).c_str()); + ustring stdname(std::string("std::") + std::string(attribute_standard_name(req.std))); og->attribute_map[i][stdname] = osl_attr; } else if(req.name != ustring()) { diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 250570e1d65..1f03ab4e347 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -112,7 +112,18 @@ static ShaderEnum color_space_init() return enm; } +static ShaderEnum image_projection_init() +{ + ShaderEnum enm; + + enm.insert("Flat", 0); + enm.insert("Box", 1); + + return enm; +} + ShaderEnum ImageTextureNode::color_space_enum = color_space_init(); +ShaderEnum ImageTextureNode::projection_enum = image_projection_init(); ImageTextureNode::ImageTextureNode() : TextureNode("image_texture") @@ -122,6 +133,8 @@ ImageTextureNode::ImageTextureNode() is_float = false; filename = ""; color_space = ustring("Color"); + projection = ustring("Flat");; + projection_blend = 0.0f; add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_UV); add_output("Color", SHADER_SOCKET_COLOR); @@ -169,13 +182,25 @@ void ImageTextureNode::compile(SVMCompiler& compiler) tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset); } - compiler.add_node(NODE_TEX_IMAGE, - slot, - compiler.encode_uchar4( - vector_offset, - color_out->stack_offset, - alpha_out->stack_offset, - srgb)); + if(projection == "Flat") { + compiler.add_node(NODE_TEX_IMAGE, + slot, + compiler.encode_uchar4( + vector_offset, + color_out->stack_offset, + alpha_out->stack_offset, + srgb)); + } + else { + compiler.add_node(NODE_TEX_IMAGE_BOX, + slot, + compiler.encode_uchar4( + vector_offset, + color_out->stack_offset, + alpha_out->stack_offset, + srgb), + __float_as_int(projection_blend)); + } if(vector_offset != vector_in->stack_offset) compiler.stack_clear_offset(vector_in->type, vector_offset); @@ -205,7 +230,7 @@ void ImageTextureNode::compile(OSLCompiler& compiler) /* Environment Texture */ -static ShaderEnum projection_init() +static ShaderEnum env_projection_init() { ShaderEnum enm; @@ -216,7 +241,7 @@ static ShaderEnum projection_init() } ShaderEnum EnvironmentTextureNode::color_space_enum = color_space_init(); -ShaderEnum EnvironmentTextureNode::projection_enum = projection_init(); +ShaderEnum EnvironmentTextureNode::projection_enum = env_projection_init(); EnvironmentTextureNode::EnvironmentTextureNode() : TextureNode("environment_texture") @@ -873,6 +898,98 @@ void CheckerTextureNode::compile(OSLCompiler& compiler) compiler.add(this, "node_checker_texture"); } +/* Brick Texture */ + +BrickTextureNode::BrickTextureNode() +: TextureNode("brick_texture") +{ + offset = 0.5f; + offset_frequency = 2; + squash = 1.0f; + squash_frequency = 2; + + add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); + add_input("Color1", SHADER_SOCKET_COLOR); + add_input("Color2", SHADER_SOCKET_COLOR); + add_input("Mortar", SHADER_SOCKET_COLOR); + add_input("Scale", SHADER_SOCKET_FLOAT, 5.0f); + add_input("Mortar Size", SHADER_SOCKET_FLOAT, 0.02f); + add_input("Bias", SHADER_SOCKET_FLOAT, 0.0f); + add_input("Brick Width", SHADER_SOCKET_FLOAT, 0.5f); + add_input("Row Height", SHADER_SOCKET_FLOAT, 0.25f); + + add_output("Color", SHADER_SOCKET_COLOR); + add_output("Fac", SHADER_SOCKET_FLOAT); +} + +void BrickTextureNode::compile(SVMCompiler& compiler) +{ + ShaderInput *vector_in = input("Vector"); + ShaderInput *color1_in = input("Color1"); + ShaderInput *color2_in = input("Color2"); + ShaderInput *mortar_in = input("Mortar"); + ShaderInput *scale_in = input("Scale"); + ShaderInput *mortar_size_in = input("Mortar Size"); + ShaderInput *bias_in = input("Bias"); + ShaderInput *brick_width_in = input("Brick Width"); + ShaderInput *row_height_in = input("Row Height"); + + ShaderOutput *color_out = output("Color"); + ShaderOutput *fac_out = output("Fac"); + + compiler.stack_assign(vector_in); + compiler.stack_assign(color1_in); + compiler.stack_assign(color2_in); + compiler.stack_assign(mortar_in); + if(scale_in->link) compiler.stack_assign(scale_in); + if(mortar_size_in->link) compiler.stack_assign(mortar_size_in); + if(bias_in->link) compiler.stack_assign(bias_in); + if(brick_width_in->link) compiler.stack_assign(brick_width_in); + if(row_height_in->link) compiler.stack_assign(row_height_in); + + int vector_offset = vector_in->stack_offset; + + if(!tex_mapping.skip()) { + vector_offset = compiler.stack_find_offset(SHADER_SOCKET_VECTOR); + tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset); + } + + if(!color_out->links.empty()) + compiler.stack_assign(color_out); + if(!fac_out->links.empty()) + compiler.stack_assign(fac_out); + + compiler.add_node(NODE_TEX_BRICK, + compiler.encode_uchar4(vector_offset, + color1_in->stack_offset, color2_in->stack_offset, mortar_in->stack_offset), + compiler.encode_uchar4(scale_in->stack_offset, + mortar_size_in->stack_offset, bias_in->stack_offset, brick_width_in->stack_offset), + compiler.encode_uchar4(row_height_in->stack_offset, + color_out->stack_offset, fac_out->stack_offset)); + + compiler.add_node(compiler.encode_uchar4(offset_frequency, squash_frequency), + __float_as_int(scale_in->value.x), + __float_as_int(mortar_size_in->value.x), + __float_as_int(bias_in->value.x)); + + compiler.add_node(__float_as_int(brick_width_in->value.x), + __float_as_int(row_height_in->value.x), + __float_as_int(offset), + __float_as_int(squash)); + + if(vector_offset != vector_in->stack_offset) + compiler.stack_clear_offset(vector_in->type, vector_offset); +} + +void BrickTextureNode::compile(OSLCompiler& compiler) +{ + compiler.parameter("Offset", offset); + compiler.parameter("OffsetFrequency", offset_frequency); + compiler.parameter("Squash", squash); + compiler.parameter("SquashFrequency", squash_frequency); + compiler.add(this, "node_brick_texture"); +} + /* Normal */ NormalNode::NormalNode() @@ -1036,6 +1153,7 @@ ProxyNode::ProxyNode(ShaderSocketType from_, ShaderSocketType to_) { from = from_; to = to_; + special_type = SHADER_SPECIAL_TYPE_PROXY; add_input("Input", from); add_output("Output", to); @@ -1801,6 +1919,13 @@ ParticleInfoNode::ParticleInfoNode() add_output("Index", SHADER_SOCKET_FLOAT); add_output("Age", SHADER_SOCKET_FLOAT); add_output("Lifetime", SHADER_SOCKET_FLOAT); + add_output("Location", SHADER_SOCKET_POINT); + #if 0 /* not yet supported */ + add_output("Rotation", SHADER_SOCKET_QUATERNION); + #endif + add_output("Size", SHADER_SOCKET_FLOAT); + add_output("Velocity", SHADER_SOCKET_VECTOR); + add_output("Angular Velocity", SHADER_SOCKET_VECTOR); } void ParticleInfoNode::attributes(AttributeRequestSet *attributes) @@ -1811,6 +1936,18 @@ void ParticleInfoNode::attributes(AttributeRequestSet *attributes) attributes->add(ATTR_STD_PARTICLE); if(!output("Lifetime")->links.empty()) attributes->add(ATTR_STD_PARTICLE); + if(!output("Location")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + #if 0 /* not yet supported */ + if(!output("Rotation")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + #endif + if(!output("Size")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + if(!output("Velocity")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + if(!output("Angular Velocity")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); ShaderNode::attributes(attributes); } @@ -1836,6 +1973,38 @@ void ParticleInfoNode::compile(SVMCompiler& compiler) compiler.stack_assign(out); compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LIFETIME, out->stack_offset); } + + out = output("Location"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LOCATION, out->stack_offset); + } + + #if 0 /* XXX Quaternion data is not yet supported by Cycles */ + out = output("Rotation"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ROTATION, out->stack_offset); + } + #endif + + out = output("Size"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_SIZE, out->stack_offset); + } + + out = output("Velocity"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_VELOCITY, out->stack_offset); + } + + out = output("Angular Velocity"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ANGULAR_VELOCITY, out->stack_offset); + } } void ParticleInfoNode::compile(OSLCompiler& compiler) @@ -1920,6 +2089,8 @@ void AddClosureNode::compile(OSLCompiler& compiler) MixClosureNode::MixClosureNode() : ShaderNode("mix_closure") { + special_type = SHADER_SPECIAL_TYPE_MIX_CLOSURE; + add_input("Fac", SHADER_SOCKET_FLOAT, 0.5f); add_input("Closure1", SHADER_SOCKET_CLOSURE); add_input("Closure2", SHADER_SOCKET_CLOSURE); @@ -1971,6 +2142,8 @@ MixNode::MixNode() { type = ustring("Mix"); + use_clamp = false; + add_input("Fac", SHADER_SOCKET_FLOAT, 0.5f); add_input("Color1", SHADER_SOCKET_COLOR); add_input("Color2", SHADER_SOCKET_COLOR); @@ -2019,11 +2192,17 @@ void MixNode::compile(SVMCompiler& compiler) compiler.add_node(NODE_MIX, fac_in->stack_offset, color1_in->stack_offset, color2_in->stack_offset); compiler.add_node(NODE_MIX, type_enum[type], color_out->stack_offset); + + if(use_clamp) { + compiler.add_node(NODE_MIX, 0, color_out->stack_offset); + compiler.add_node(NODE_MIX, NODE_MIX_CLAMP, color_out->stack_offset); + } } void MixNode::compile(OSLCompiler& compiler) { compiler.parameter("type", type); + compiler.parameter("Clamp", use_clamp); compiler.add(this, "node_mix"); } @@ -2349,7 +2528,7 @@ void LayerWeightNode::compile(SVMCompiler& compiler) void LayerWeightNode::compile(OSLCompiler& compiler) { - compiler.add(this, "node_layer_height"); + compiler.add(this, "node_blend_weight"); } /* Output */ @@ -2391,6 +2570,8 @@ MathNode::MathNode() { type = ustring("Add"); + use_clamp = false; + add_input("Value1", SHADER_SOCKET_FLOAT); add_input("Value2", SHADER_SOCKET_FLOAT); add_output("Value", SHADER_SOCKET_FLOAT); @@ -2435,11 +2616,17 @@ void MathNode::compile(SVMCompiler& compiler) compiler.add_node(NODE_MATH, type_enum[type], value1_in->stack_offset, value2_in->stack_offset); compiler.add_node(NODE_MATH, value_out->stack_offset); + + if(use_clamp) { + compiler.add_node(NODE_MATH, NODE_MATH_CLAMP, value_out->stack_offset); + compiler.add_node(NODE_MATH, value_out->stack_offset); + } } void MathNode::compile(OSLCompiler& compiler) { compiler.parameter("type", type); + compiler.parameter("Clamp", use_clamp); compiler.add(this, "node_math"); } diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index efd814e4ae6..82bead7e41a 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -70,8 +70,11 @@ public: bool is_float; string filename; ustring color_space; + ustring projection; + float projection_blend; static ShaderEnum color_space_enum; + static ShaderEnum projection_enum; }; class EnvironmentTextureNode : public TextureNode { @@ -155,6 +158,14 @@ public: SHADER_NODE_CLASS(CheckerTextureNode) }; +class BrickTextureNode : public TextureNode { +public: + SHADER_NODE_CLASS(BrickTextureNode) + + float offset, squash; + int offset_frequency, squash_frequency; +}; + class MappingNode : public ShaderNode { public: SHADER_NODE_CLASS(MappingNode) @@ -329,6 +340,8 @@ class MixNode : public ShaderNode { public: SHADER_NODE_CLASS(MixNode) + bool use_clamp; + ustring type; static ShaderEnum type_enum; }; @@ -385,6 +398,8 @@ class MathNode : public ShaderNode { public: SHADER_NODE_CLASS(MathNode) + bool use_clamp; + ustring type; static ShaderEnum type_enum; }; diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 0fe227fd171..7389b239627 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -249,38 +249,6 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene device->tex_alloc("__object_flag", dscene->object_flag); } -void ObjectManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) -{ - /* count particles. - * adds one dummy particle at the beginning to avoid invalid lookups, - * in case a shader uses particle info without actual particle data. - */ - int num_particles = 1; - foreach(Object *ob, scene->objects) - num_particles += ob->particles.size(); - - float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); - - /* dummy particle */ - particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - - int i = 1; - foreach(Object *ob, scene->objects) { - foreach(Particle &pa, ob->particles) { - /* pack in texture */ - int offset = i*PARTICLE_SIZE; - - particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, 0.0f); - - i++; - - if(progress.get_cancel()) return; - } - } - - device->tex_alloc("__particles", dscene->particles); -} - void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) { if(!need_update) @@ -306,11 +274,6 @@ void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *sc if(progress.get_cancel()) return; - progress.set_status("Updating Objects", "Copying Particles to device"); - device_update_particles(device, dscene, scene, progress); - - if(progress.get_cancel()) return; - need_update = false; } @@ -321,9 +284,6 @@ void ObjectManager::device_free(Device *device, DeviceScene *dscene) device->tex_free(dscene->object_flag); dscene->object_flag.clear(); - - device->tex_free(dscene->particles); - dscene->particles.clear(); } void ObjectManager::apply_static_transforms(Scene *scene, Progress& progress) diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index 9b2f5bc8768..88677d79dff 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -35,12 +35,6 @@ struct Transform; /* Object */ -struct Particle { - int index; - float age; - float lifetime; -}; - class Object { public: Mesh *mesh; @@ -56,7 +50,6 @@ public: bool use_holdout; int particle_id; - vector<Particle> particles; Object(); ~Object(); @@ -78,7 +71,6 @@ public: void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); void device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); - void device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); void device_free(Device *device, DeviceScene *dscene); void tag_update(Scene *scene); diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 04af9b48280..dbd6b0ac9d9 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -101,8 +101,9 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene /* setup shader engine */ og->ss = ss; + og->services = services; int background_id = scene->shader_manager->get_shader_id(scene->default_background); - og->background_state = og->surface_state[background_id]; + og->background_state = og->surface_state[background_id & SHADER_MASK]; og->use = true; tls_create(OSLGlobals::ThreadData, og->thread_data); @@ -199,19 +200,19 @@ void OSLCompiler::add(ShaderNode *node, const char *name) switch(input->type) { case SHADER_SOCKET_COLOR: - parameter_color(input->name, input->value); + parameter_color(compatible_name(input->name).c_str(), input->value); break; case SHADER_SOCKET_POINT: - parameter_point(input->name, input->value); + parameter_point(compatible_name(input->name).c_str(), input->value); break; case SHADER_SOCKET_VECTOR: - parameter_vector(input->name, input->value); + parameter_vector(compatible_name(input->name).c_str(), input->value); break; case SHADER_SOCKET_NORMAL: - parameter_normal(input->name, input->value); + parameter_normal(compatible_name(input->name).c_str(), input->value); break; case SHADER_SOCKET_FLOAT: - parameter(input->name, input->value.x); + parameter(compatible_name(input->name).c_str(), input->value.x); break; case SHADER_SOCKET_CLOSURE: break; diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp new file mode 100644 index 00000000000..9f951d9673f --- /dev/null +++ b/intern/cycles/render/particles.cpp @@ -0,0 +1,123 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "device.h" +#include "particles.h" +#include "scene.h" + +#include "util_foreach.h" +#include "util_map.h" +#include "util_progress.h" +#include "util_vector.h" + +CCL_NAMESPACE_BEGIN + +/* Particle System */ + +ParticleSystem::ParticleSystem() +{ +} + +ParticleSystem::~ParticleSystem() +{ +} + +void ParticleSystem::tag_update(Scene *scene) +{ + scene->particle_system_manager->need_update = true; +} + +/* Particle System Manager */ + +ParticleSystemManager::ParticleSystemManager() +{ + need_update = true; +} + +ParticleSystemManager::~ParticleSystemManager() +{ +} + +void ParticleSystemManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) +{ + /* count particles. + * adds one dummy particle at the beginning to avoid invalid lookups, + * in case a shader uses particle info without actual particle data. + */ + int num_particles = 1; + foreach(ParticleSystem *psys, scene->particle_systems) + num_particles += psys->particles.size(); + + float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); + + /* dummy particle */ + particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[3] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[4] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + + int i = 1; + foreach(ParticleSystem *psys, scene->particle_systems) { + foreach(Particle &pa, psys->particles) { + /* pack in texture */ + int offset = i*PARTICLE_SIZE; + + particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, pa.size); + particles[offset+1] = pa.rotation; + particles[offset+2] = make_float4(pa.location.x, pa.location.y, pa.location.z, pa.velocity.x); + particles[offset+3] = make_float4(pa.velocity.y, pa.velocity.z, pa.angular_velocity.x, pa.angular_velocity.y); + particles[offset+4] = make_float4(pa.angular_velocity.z, 0.0f, 0.0f, 0.0f); + + i++; + + if(progress.get_cancel()) return; + } + } + + device->tex_alloc("__particles", dscene->particles); +} + +void ParticleSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) +{ + if(!need_update) + return; + + device_free(device, dscene); + + progress.set_status("Updating Particle Systems", "Copying Particles to device"); + device_update_particles(device, dscene, scene, progress); + + if(progress.get_cancel()) return; + + need_update = false; +} + +void ParticleSystemManager::device_free(Device *device, DeviceScene *dscene) +{ + device->tex_free(dscene->particles); + dscene->particles.clear(); +} + +void ParticleSystemManager::tag_update(Scene *scene) +{ + need_update = true; +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/render/particles.h b/intern/cycles/render/particles.h new file mode 100644 index 00000000000..afc8b2b2dcb --- /dev/null +++ b/intern/cycles/render/particles.h @@ -0,0 +1,74 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __PARTICLES_H__ +#define __PARTICLES_H__ + +#include "util_types.h" +#include "util_vector.h" + +CCL_NAMESPACE_BEGIN + +class Device; +class DeviceScene; +class Progress; +class Scene; + +/* Particle System */ + +struct Particle { + int index; + float age; + float lifetime; + float3 location; + float4 rotation; + float size; + float3 velocity; + float3 angular_velocity; +}; + +class ParticleSystem { +public: + ParticleSystem(); + ~ParticleSystem(); + + void tag_update(Scene *scene); + + vector<Particle> particles; +}; + +/* ParticleSystem Manager */ + +class ParticleSystemManager { +public: + bool need_update; + + ParticleSystemManager(); + ~ParticleSystemManager(); + + void device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); + void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); + void device_free(Device *device, DeviceScene *dscene); + + void tag_update(Scene *scene); +}; + +CCL_NAMESPACE_END + +#endif /* __PARTICLES_H__ */ + diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp index 45c8a05c27d..071338d49c2 100644 --- a/intern/cycles/render/scene.cpp +++ b/intern/cycles/render/scene.cpp @@ -28,6 +28,7 @@ #include "shader.h" #include "mesh.h" #include "object.h" +#include "particles.h" #include "scene.h" #include "svm.h" #include "osl.h" @@ -37,7 +38,7 @@ CCL_NAMESPACE_BEGIN -Scene::Scene(const SceneParams& params_) +Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_) : params(params_) { device = NULL; @@ -53,6 +54,10 @@ Scene::Scene(const SceneParams& params_) integrator = new Integrator(); image_manager = new ImageManager(); shader_manager = ShaderManager::create(this); + particle_system_manager = new ParticleSystemManager(); + + if (device_info_.type == DEVICE_CPU) + image_manager->set_extended_image_limits(); } Scene::~Scene() @@ -92,9 +97,14 @@ Scene::~Scene() delete o; foreach(Light *l, lights) delete l; + foreach(ParticleSystem *p, particle_systems) + delete p; if(device) image_manager->device_free(device, &dscene); delete image_manager; + + if(device) particle_system_manager->device_free(device, &dscene); + delete particle_system_manager; } void Scene::device_update(Device *device_, Progress& progress) @@ -149,6 +159,11 @@ void Scene::device_update(Device *device_, Progress& progress) if(progress.get_cancel()) return; + progress.set_status("Updating Particle Systems"); + particle_system_manager->device_update(device, &dscene, this, progress); + + if(progress.get_cancel()) return; + progress.set_status("Updating Filter"); filter->device_update(device, &dscene); @@ -210,7 +225,8 @@ bool Scene::need_reset() || light_manager->need_update || filter->need_update || integrator->need_update - || shader_manager->need_update); + || shader_manager->need_update + || particle_system_manager->need_update); } CCL_NAMESPACE_END diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h index 8b9944cb76e..09087fb2970 100644 --- a/intern/cycles/render/scene.h +++ b/intern/cycles/render/scene.h @@ -25,6 +25,7 @@ #include "kernel_types.h" +#include "util_attribute.h" #include "util_param.h" #include "util_string.h" #include "util_thread.h" @@ -37,6 +38,7 @@ class AttributeRequestSet; class Background; class Camera; class Device; +class DeviceInfo; class Film; class Filter; class Integrator; @@ -46,6 +48,8 @@ class Mesh; class MeshManager; class Object; class ObjectManager; +class ParticleSystemManager; +class ParticleSystem; class Shader; class ShaderManager; class Progress; @@ -97,8 +101,8 @@ public: device_vector<uint> sobol_directions; /* images */ - device_vector<uchar4> tex_image[TEX_NUM_IMAGES]; - device_vector<float4> tex_float_image[TEX_NUM_FLOAT_IMAGES]; + device_vector<uchar4> tex_image[TEX_EXTENDED_NUM_IMAGES]; + device_vector<float4> tex_float_image[TEX_EXTENDED_NUM_FLOAT_IMAGES]; /* opencl images */ device_vector<uchar4> tex_image_packed; @@ -154,6 +158,7 @@ public: vector<Mesh*> meshes; vector<Shader*> shaders; vector<Light*> lights; + vector<ParticleSystem*> particle_systems; /* data managers */ ImageManager *image_manager; @@ -161,6 +166,7 @@ public: ShaderManager *shader_manager; MeshManager *mesh_manager; ObjectManager *object_manager; + ParticleSystemManager *particle_system_manager; /* default shaders */ int default_surface; @@ -179,7 +185,7 @@ public: /* mutex must be locked manually by callers */ thread_mutex mutex; - Scene(const SceneParams& params); + Scene(const SceneParams& params, const DeviceInfo& device_info); ~Scene(); void device_update(Device *device, Progress& progress); diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index a9f7e5beb56..05c57ba48ec 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -27,6 +27,7 @@ #include "util_foreach.h" #include "util_function.h" +#include "util_math.h" #include "util_opengl.h" #include "util_task.h" #include "util_time.h" @@ -35,15 +36,23 @@ CCL_NAMESPACE_BEGIN Session::Session(const SessionParams& params_) : params(params_), - tile_manager(params.progressive, params.samples, params.tile_size, params.min_size) + tile_manager(params.progressive, params.samples, params.tile_size, params.resolution, + (params.background)? 1: max(params.device.multi_devices.size(), 1)) { device_use_gl = ((params.device.type != DEVICE_CPU) && !params.background); TaskScheduler::init(params.threads); device = Device::create(params.device, params.background, params.threads); - buffers = new RenderBuffers(device); - display = new DisplayBuffer(device); + + if(params.background) { + buffers = NULL; + display = NULL; + } + else { + buffers = new RenderBuffers(device); + display = new DisplayBuffer(device); + } session_thread = NULL; scene = NULL; @@ -52,7 +61,6 @@ Session::Session(const SessionParams& params_) reset_time = 0.0; preview_time = 0.0; paused_time = 0.0; - sample = 0; delayed_reset.do_reset = false; delayed_reset.samples = 0; @@ -81,7 +89,7 @@ Session::~Session() wait(); } - if(params.output_path != "") { + if(display && params.output_path != "") { tonemap(); progress.set_status("Writing Image", params.output_path); @@ -118,8 +126,8 @@ void Session::reset_gpu(BufferParams& buffer_params, int samples) /* block for buffer acces and reset immediately. we can't do this * in the thread, because we need to allocate an OpenGL buffer, and * that only works in the main thread */ - thread_scoped_lock display_lock(display->mutex); - thread_scoped_lock buffers_lock(buffers->mutex); + thread_scoped_lock display_lock(display_mutex); + thread_scoped_lock buffers_lock(buffers_mutex); display_outdated = true; reset_time = time_dt(); @@ -132,10 +140,16 @@ void Session::reset_gpu(BufferParams& buffer_params, int samples) pause_cond.notify_all(); } +bool Session::resetting_gpu() const +{ + /* no need to wait for gpu device */ + return false; +} + bool Session::draw_gpu(BufferParams& buffer_params) { /* block for buffer access */ - thread_scoped_lock display_lock(display->mutex); + thread_scoped_lock display_lock(display_mutex); /* first check we already rendered something */ if(gpu_draw_ready) { @@ -145,7 +159,7 @@ bool Session::draw_gpu(BufferParams& buffer_params) /* for CUDA we need to do tonemapping still, since we can * only access GL buffers from the main thread */ if(gpu_need_tonemap) { - thread_scoped_lock buffers_lock(buffers->mutex); + thread_scoped_lock buffers_lock(buffers_mutex); tonemap(); gpu_need_tonemap = false; gpu_need_tonemap_cond.notify_all(); @@ -226,23 +240,18 @@ void Session::run_gpu() /* buffers mutex is locked entirely while rendering each * sample, and released/reacquired on each iteration to allow * reset and draw in between */ - thread_scoped_lock buffers_lock(buffers->mutex); + thread_scoped_lock buffers_lock(buffers_mutex); /* update status and timing */ update_status_time(); /* path trace */ - foreach(Tile& tile, tile_manager.state.tiles) { - path_trace(tile); - - device->task_wait(); + path_trace(); - if(device->error_message() != "") - progress.set_cancel(device->error_message()); + device->task_wait(); - if(progress.get_cancel()) - break; - } + if(device->error_message() != "") + progress.set_cancel(device->error_message()); /* update status and timing */ update_status_time(); @@ -287,9 +296,14 @@ void Session::reset_cpu(BufferParams& buffer_params, int samples) pause_cond.notify_all(); } +bool Session::resetting_cpu() const +{ + return device->task_cancelled(); +} + bool Session::draw_cpu(BufferParams& buffer_params) { - thread_scoped_lock display_lock(display->mutex); + thread_scoped_lock display_lock(display_mutex); /* first check we already rendered something */ if(display->draw_ready()) { @@ -308,13 +322,101 @@ bool Session::draw_cpu(BufferParams& buffer_params) return false; } +bool Session::acquire_tile(Device *tile_device, RenderTile& rtile) +{ + if(progress.get_cancel()) + return false; + + thread_scoped_lock tile_lock(tile_mutex); + + /* get next tile from manager */ + Tile tile; + int device_num = (params.background)? 0: device->device_number(tile_device); + + if(!tile_manager.next_tile(tile, device_num)) + return false; + + /* fill render tile */ + rtile.x = tile_manager.state.buffer.full_x + tile.x; + rtile.y = tile_manager.state.buffer.full_y + tile.y; + rtile.w = tile.w; + rtile.h = tile.h; + rtile.start_sample = tile_manager.state.sample; + rtile.num_samples = tile_manager.state.num_samples; + rtile.resolution = tile_manager.state.resolution; + + tile_lock.unlock(); + + /* in case of a permant buffer, return it, otherwise we will allocate + * a new temporary buffer */ + if(!write_render_tile_cb) { + tile_manager.state.buffer.get_offset_stride(rtile.offset, rtile.stride); + + rtile.buffer = buffers->buffer.device_pointer; + rtile.rng_state = buffers->rng_state.device_pointer; + rtile.rgba = display->rgba.device_pointer; + rtile.buffers = buffers; + + device->map_tile(tile_device, rtile); + + return true; + } + + /* fill buffer parameters */ + BufferParams buffer_params = tile_manager.params; + buffer_params.full_x = rtile.x; + buffer_params.full_y = rtile.y; + buffer_params.width = rtile.w; + buffer_params.height = rtile.h; + + buffer_params.get_offset_stride(rtile.offset, rtile.stride); + + /* allocate buffers */ + RenderBuffers *tilebuffers = new RenderBuffers(tile_device); + tilebuffers->reset(tile_device, buffer_params); + + rtile.buffer = tilebuffers->buffer.device_pointer; + rtile.rng_state = tilebuffers->rng_state.device_pointer; + rtile.rgba = 0; + rtile.buffers = tilebuffers; + + return true; +} + +void Session::update_tile_sample(RenderTile& rtile) +{ + thread_scoped_lock tile_lock(tile_mutex); + + if(update_render_tile_cb) { + /* todo: optimize this by making it thread safe and removing lock */ + + update_render_tile_cb(rtile); + } + + update_status_time(); +} + +void Session::release_tile(RenderTile& rtile) +{ + thread_scoped_lock tile_lock(tile_mutex); + + if(write_render_tile_cb) { + /* todo: optimize this by making it thread safe and removing lock */ + write_render_tile_cb(rtile); + + delete rtile.buffers; + } + + update_status_time(); +} + void Session::run_cpu() { { /* reset once to start */ thread_scoped_lock reset_lock(delayed_reset.mutex); - thread_scoped_lock buffers_lock(buffers->mutex); - thread_scoped_lock display_lock(display->mutex); + thread_scoped_lock buffers_lock(buffers_mutex); + thread_scoped_lock display_lock(display_mutex); reset_(delayed_reset.params, delayed_reset.samples); delayed_reset.do_reset = false; @@ -364,7 +466,7 @@ void Session::run_cpu() /* buffers mutex is locked entirely while rendering each * sample, and released/reacquired on each iteration to allow * reset and draw in between */ - thread_scoped_lock buffers_lock(buffers->mutex); + thread_scoped_lock buffers_lock(buffers_mutex); /* update scene */ update_scene(); @@ -379,8 +481,7 @@ void Session::run_cpu() update_status_time(); /* path trace */ - foreach(Tile& tile, tile_manager.state.tiles) - path_trace(tile); + path_trace(); /* update status and timing */ update_status_time(); @@ -396,8 +497,8 @@ void Session::run_cpu() { thread_scoped_lock reset_lock(delayed_reset.mutex); - thread_scoped_lock buffers_lock(buffers->mutex); - thread_scoped_lock display_lock(display->mutex); + thread_scoped_lock buffers_lock(buffers_mutex); + thread_scoped_lock display_lock(display_mutex); if(delayed_reset.do_reset) { /* reset rendering if request from main thread */ @@ -442,6 +543,9 @@ void Session::run() /* run */ if(!progress.get_cancel()) { + /* reset number of rendered samples */ + progress.reset_sample(); + if(device_use_gl) run_gpu(); else @@ -465,10 +569,12 @@ bool Session::draw(BufferParams& buffer_params) void Session::reset_(BufferParams& buffer_params, int samples) { - if(buffer_params.modified(buffers->params)) { - gpu_draw_ready = false; - buffers->reset(device, buffer_params); - display->reset(device, buffer_params); + if(buffers) { + if(buffer_params.modified(buffers->params)) { + gpu_draw_ready = false; + buffers->reset(device, buffer_params); + display->reset(device, buffer_params); + } } tile_manager.reset(buffer_params, samples); @@ -476,7 +582,6 @@ void Session::reset_(BufferParams& buffer_params, int samples) start_time = time_dt(); preview_time = 0.0; paused_time = 0.0; - sample = 0; if(!params.background) progress.set_start_time(start_time + paused_time); @@ -490,6 +595,14 @@ void Session::reset(BufferParams& buffer_params, int samples) reset_cpu(buffer_params, samples); } +bool Session::resetting() const +{ + if(device_use_gl) + return resetting_gpu(); + else + return resetting_cpu(); +} + void Session::set_samples(int samples) { if(samples != params.samples) { @@ -532,8 +645,6 @@ void Session::update_scene() { thread_scoped_lock scene_lock(scene->mutex); - progress.set_status("Updating Scene"); - /* update camera if dimensions changed for progressive render. the camera * knows nothing about progressive or cropped rendering, it just gets the * image dimensions passed in */ @@ -548,20 +659,47 @@ void Session::update_scene() } /* update scene */ - if(scene->need_update()) + if(scene->need_update()) { + progress.set_status("Updating Scene"); scene->device_update(device, progress); + } } void Session::update_status_time(bool show_pause, bool show_done) { int sample = tile_manager.state.sample; int resolution = tile_manager.state.resolution; + int num_tiles = tile_manager.state.num_tiles; + int tile = tile_manager.state.num_rendered_tiles; /* update status */ string status, substatus; - if(!params.progressive) - substatus = "Path Tracing"; + if(!params.progressive) { + substatus = string_printf("Path Tracing Tile %d/%d", tile, num_tiles); + + if(params.device.type == DEVICE_CUDA || params.device.type == DEVICE_OPENCL || + (params.device.type == DEVICE_CPU && num_tiles == 1)) { + /* when rendering on GPU multithreading happens within single tile, as in + * tiles are handling sequentially and in this case we could display + * currently rendering sample number + * this helps a lot from feedback point of view. + * also display the info on CPU, when using 1 tile only + */ + + int sample = progress.get_sample(), num_samples = tile_manager.state.num_samples; + + if(tile > 1) { + /* sample counter is global for all tiles, subtract samples + * from already finished tiles to get sample counter for + * current tile only + */ + sample -= (tile - 1) * num_samples; + } + + substatus += string_printf(", Sample %d/%d", sample, num_samples); + } + } else if(params.samples == INT_MAX) substatus = string_printf("Path Tracing Sample %d", sample+1); else @@ -580,28 +718,29 @@ void Session::update_status_time(bool show_pause, bool show_done) if(preview_time == 0.0 && resolution == 1) preview_time = time_dt(); - double sample_time = (sample == 0)? 0.0: (time_dt() - preview_time - paused_time)/(sample); + double tile_time = (tile == 0)? 0.0: (time_dt() - preview_time - paused_time)/(sample); /* negative can happen when we pause a bit before rendering, can discard that */ if(preview_time < 0.0) preview_time = 0.0; - progress.set_sample(sample + 1, sample_time); + progress.set_tile(tile, tile_time); +} + +void Session::update_progress_sample() +{ + progress.increment_sample(); } -void Session::path_trace(Tile& tile) +void Session::path_trace() { /* add path trace task */ DeviceTask task(DeviceTask::PATH_TRACE); - - task.x = tile_manager.state.buffer.full_x + tile.x; - task.y = tile_manager.state.buffer.full_y + tile.y; - task.w = tile.w; - task.h = tile.h; - task.buffer = buffers->buffer.device_pointer; - task.rng_state = buffers->rng_state.device_pointer; - task.sample = tile_manager.state.sample; - task.resolution = tile_manager.state.resolution; - tile_manager.state.buffer.get_offset_stride(task.offset, task.stride); + + task.acquire_tile = function_bind(&Session::acquire_tile, this, _1, _2); + task.release_tile = function_bind(&Session::release_tile, this, _1); + task.get_cancel = function_bind(&Progress::get_cancel, &this->progress); + task.update_tile_sample = function_bind(&Session::update_tile_sample, this, _1); + task.update_progress_sample = function_bind(&Session::update_progress_sample, this); device->task_add(task); } diff --git a/intern/cycles/render/session.h b/intern/cycles/render/session.h index 90616f011ea..e45753d22a0 100644 --- a/intern/cycles/render/session.h +++ b/intern/cycles/render/session.h @@ -47,8 +47,8 @@ public: bool progressive; bool experimental; int samples; - int tile_size; - int min_size; + int2 tile_size; + int resolution; int threads; double cancel_timeout; @@ -63,8 +63,8 @@ public: progressive = false; experimental = false; samples = INT_MAX; - tile_size = 64; - min_size = 64; + tile_size = make_int2(64, 64); + resolution = 4; threads = 0; cancel_timeout = 0.1; @@ -81,7 +81,7 @@ public: && progressive == params.progressive && experimental == params.experimental && tile_size == params.tile_size - && min_size == params.min_size + && resolution == params.resolution && threads == params.threads && cancel_timeout == params.cancel_timeout && reset_timeout == params.reset_timeout @@ -102,7 +102,10 @@ public: DisplayBuffer *display; Progress progress; SessionParams params; - int sample; + TileManager tile_manager; + + boost::function<void(RenderTile&)> write_render_tile_cb; + boost::function<void(RenderTile&)> update_render_tile_cb; Session(const SessionParams& params); ~Session(); @@ -113,6 +116,7 @@ public: bool ready_to_reset(); void reset(BufferParams& params, int samples); + bool resetting() const; void set_samples(int samples); void set_pause(bool pause); @@ -130,18 +134,25 @@ protected: void update_status_time(bool show_pause = false, bool show_done = false); void tonemap(); - void path_trace(Tile& tile); + void path_trace(); void reset_(BufferParams& params, int samples); void run_cpu(); bool draw_cpu(BufferParams& params); void reset_cpu(BufferParams& params, int samples); + bool resetting_cpu() const; void run_gpu(); bool draw_gpu(BufferParams& params); void reset_gpu(BufferParams& params, int samples); + bool resetting_gpu() const; + + bool acquire_tile(Device *tile_device, RenderTile& tile); + void update_tile_sample(RenderTile& tile); + void release_tile(RenderTile& tile); + + void update_progress_sample(); - TileManager tile_manager; bool device_use_gl; thread *session_thread; @@ -155,6 +166,9 @@ protected: bool pause; thread_condition_variable pause_cond; thread_mutex pause_mutex; + thread_mutex tile_mutex; + thread_mutex buffers_mutex; + thread_mutex display_mutex; bool kernels_loaded; diff --git a/intern/cycles/render/tile.cpp b/intern/cycles/render/tile.cpp index 04e48d44029..b4156fd9471 100644 --- a/intern/cycles/render/tile.cpp +++ b/intern/cycles/render/tile.cpp @@ -19,14 +19,16 @@ #include "tile.h" #include "util_algorithm.h" +#include "util_types.h" CCL_NAMESPACE_BEGIN -TileManager::TileManager(bool progressive_, int samples_, int tile_size_, int min_size_) +TileManager::TileManager(bool progressive_, int num_samples_, int2 tile_size_, int resolution_, int num_devices_) { progressive = progressive_; tile_size = tile_size_; - min_size = min_size_; + resolution = resolution_; + num_devices = num_devices_; BufferParams buffer_params; reset(buffer_params, 0); @@ -36,34 +38,24 @@ TileManager::~TileManager() { } -void TileManager::reset(BufferParams& params_, int samples_) +void TileManager::reset(BufferParams& params_, int num_samples_) { params = params_; - start_resolution = 1; - - int w = params.width, h = params.height; - - if(min_size != INT_MAX) { - while(w*h > min_size*min_size) { - w = max(1, w/2); - h = max(1, h/2); - - start_resolution *= 2; - } - } - - samples = samples_; + num_samples = num_samples_; state.buffer = BufferParams(); state.sample = -1; - state.resolution = start_resolution; + state.num_tiles = 0; + state.num_rendered_tiles = 0; + state.num_samples = 0; + state.resolution = resolution; state.tiles.clear(); } -void TileManager::set_samples(int samples_) +void TileManager::set_samples(int num_samples_) { - samples = samples_; + num_samples = num_samples_; } void TileManager::set_tiles() @@ -71,24 +63,34 @@ void TileManager::set_tiles() int resolution = state.resolution; int image_w = max(1, params.width/resolution); int image_h = max(1, params.height/resolution); - int tile_w = (tile_size >= image_w)? 1: (image_w + tile_size - 1)/tile_size; - int tile_h = (tile_size >= image_h)? 1: (image_h + tile_size - 1)/tile_size; - int sub_w = image_w/tile_w; - int sub_h = image_h/tile_h; state.tiles.clear(); - for(int tile_y = 0; tile_y < tile_h; tile_y++) { - for(int tile_x = 0; tile_x < tile_w; tile_x++) { - int x = tile_x * sub_w; - int y = tile_y * sub_h; - int w = (tile_x == tile_w-1)? image_w - x: sub_w; - int h = (tile_y == tile_h-1)? image_h - y: sub_h; + int num = min(image_h, num_devices); + + for(int device = 0; device < num; device++) { + int device_y = (image_h/num)*device; + int device_h = (device == num-1)? image_h - device*(image_h/num): image_h/num; + + int tile_w = (tile_size.x >= image_w)? 1: (image_w + tile_size.x - 1)/tile_size.x; + int tile_h = (tile_size.y >= device_h)? 1: (device_h + tile_size.y - 1)/tile_size.y; + int sub_w = (image_w + tile_w - 1)/tile_w; + int sub_h = (device_h + tile_h - 1)/tile_h; - state.tiles.push_back(Tile(x, y, w, h)); + for(int tile_y = 0; tile_y < tile_h; tile_y++) { + for(int tile_x = 0; tile_x < tile_w; tile_x++) { + int x = tile_x * sub_w; + int y = tile_y * sub_h; + int w = (tile_x == tile_w-1)? image_w - x: sub_w; + int h = (tile_y == tile_h-1)? device_h - y: sub_h; + + state.tiles.push_back(Tile(x, y + device_y, w, h, device)); + } } } + state.num_tiles = state.tiles.size(); + state.buffer.width = image_w; state.buffer.height = image_h; @@ -98,9 +100,74 @@ void TileManager::set_tiles() state.buffer.full_height = max(1, params.full_height/resolution); } +list<Tile>::iterator TileManager::next_center_tile(int device) +{ + list<Tile>::iterator iter, best = state.tiles.end(); + + int resolution = state.resolution; + int image_w = max(1, params.width/resolution); + int image_h = max(1, params.height/resolution); + + int num = min(image_h, num_devices); + + int device_y = (image_h / num) * device; + int device_h = (device == num - 1) ? image_h - device * (image_h / num) : image_h / num; + + int64_t centx = image_w / 2, centy = device_y + device_h / 2, tot = 1; + int64_t mindist = (int64_t) image_w * (int64_t) device_h; + + /* find center of rendering tiles, image center counts for 1 too */ + for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) { + if(iter->rendering) { + Tile &cur_tile = *iter; + centx += cur_tile.x + cur_tile.w / 2; + centy += cur_tile.y + cur_tile.h / 2; + tot++; + } + } + + centx /= tot; + centy /= tot; + + /* closest of the non-rendering tiles */ + for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) { + if(iter->device == device && iter->rendering == false) { + Tile &cur_tile = *iter; + + int64_t distx = centx - (cur_tile.x + cur_tile.w / 2); + int64_t disty = centy - (cur_tile.y + cur_tile.h / 2); + distx = (int64_t) sqrt((double)distx * distx + disty * disty); + + if(distx < mindist) { + best = iter; + mindist = distx; + } + } + } + + return best; +} + +bool TileManager::next_tile(Tile& tile, int device) +{ + list<Tile>::iterator tile_it; + + tile_it = next_center_tile(device); + + if(tile_it != state.tiles.end()) { + tile_it->rendering = true; + tile = *tile_it; + state.num_rendered_tiles++; + + return true; + } + + return false; +} + bool TileManager::done() { - return (state.sample+1 >= samples && state.resolution == 1); + return (state.sample+state.num_samples >= num_samples && state.resolution == 1); } bool TileManager::next() @@ -111,10 +178,17 @@ bool TileManager::next() if(progressive && state.resolution > 1) { state.sample = 0; state.resolution /= 2; + state.num_samples = 1; set_tiles(); } else { state.sample++; + + if(progressive) + state.num_samples = 1; + else + state.num_samples = num_samples; + state.resolution = 1; set_tiles(); } diff --git a/intern/cycles/render/tile.h b/intern/cycles/render/tile.h index b6e610c8d90..29f2b1ef9f9 100644 --- a/intern/cycles/render/tile.h +++ b/intern/cycles/render/tile.h @@ -31,9 +31,14 @@ CCL_NAMESPACE_BEGIN class Tile { public: int x, y, w, h; + int device; + bool rendering; - Tile(int x_, int y_, int w_, int h_) - : x(x_), y(y_), w(w_), h(h_) {} + Tile() + {} + + Tile(int x_, int y_, int w_, int h_, int device_) + : x(x_), y(y_), w(w_), h(h_), device(device_), rendering(false) {} }; /* Tile Manager */ @@ -45,27 +50,34 @@ public: struct State { BufferParams buffer; int sample; + int num_samples; int resolution; + int num_tiles; + int num_rendered_tiles; list<Tile> tiles; } state; - TileManager(bool progressive, int samples, int tile_size, int min_size); + TileManager(bool progressive, int num_samples, int2 tile_size, int resolution, int num_devices = 1); ~TileManager(); - void reset(BufferParams& params, int samples); - void set_samples(int samples); + void reset(BufferParams& params, int num_samples); + void set_samples(int num_samples); bool next(); + bool next_tile(Tile& tile, int device = 0); bool done(); protected: void set_tiles(); bool progressive; - int samples; - int tile_size; - int min_size; + int num_samples; + int2 tile_size; + int resolution; + int num_devices; int start_resolution; + + list<Tile>::iterator next_center_tile(int device = 0); }; CCL_NAMESPACE_END diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt index 87bd84b4e0f..ae8403a14a8 100644 --- a/intern/cycles/util/CMakeLists.txt +++ b/intern/cycles/util/CMakeLists.txt @@ -6,6 +6,7 @@ set(INC ) set(SRC + util_attribute.cpp util_cache.cpp util_cuda.cpp util_dynlib.cpp @@ -29,6 +30,7 @@ endif() set(SRC_HEADERS util_algorithm.h util_args.h + util_attribute.h util_boundbox.h util_cache.h util_cuda.h diff --git a/intern/cycles/util/util_attribute.cpp b/intern/cycles/util/util_attribute.cpp new file mode 100644 index 00000000000..3a1c2b6f332 --- /dev/null +++ b/intern/cycles/util/util_attribute.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "util_attribute.h" + +CCL_NAMESPACE_BEGIN + +const char *attribute_standard_name(AttributeStandard std) +{ + if(std == ATTR_STD_VERTEX_NORMAL) + return "N"; + else if(std == ATTR_STD_FACE_NORMAL) + return "Ng"; + else if(std == ATTR_STD_UV) + return "uv"; + else if(std == ATTR_STD_GENERATED) + return "generated"; + else if(std == ATTR_STD_POSITION_UNDEFORMED) + return "undeformed"; + else if(std == ATTR_STD_POSITION_UNDISPLACED) + return "undisplaced"; + else if(std == ATTR_STD_MOTION_PRE) + return "motion_pre"; + else if(std == ATTR_STD_MOTION_POST) + return "motion_post"; + else if(std == ATTR_STD_PARTICLE) + return "particle"; + + return ""; +} + +CCL_NAMESPACE_END diff --git a/intern/cycles/util/util_attribute.h b/intern/cycles/util/util_attribute.h new file mode 100644 index 00000000000..334864c7f44 --- /dev/null +++ b/intern/cycles/util/util_attribute.h @@ -0,0 +1,31 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __UTIL_ATTRIBUTE_H__ +#define __UTIL_ATTRIBUTE_H__ + +#include "util_types.h" + +CCL_NAMESPACE_BEGIN + +const char *attribute_standard_name(AttributeStandard std); + +CCL_NAMESPACE_END + +#endif /* __UTIL_ATTRIBUTE_H__ */ + diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index a6bc478ee64..71a5dedeaa4 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -277,6 +277,11 @@ __device_inline float cross(const float2 a, const float2 b) #ifndef __KERNEL_OPENCL__ +__device_inline bool operator==(const int2 a, const int2 b) +{ + return (a.x == b.x && a.y == b.y); +} + __device_inline float len(const float2 a) { return sqrtf(dot(a, a)); diff --git a/intern/cycles/util/util_opencl.cpp b/intern/cycles/util/util_opencl.cpp index c9df9c2ff5c..40b637f5cb7 100644 --- a/intern/cycles/util/util_opencl.cpp +++ b/intern/cycles/util/util_opencl.cpp @@ -235,8 +235,10 @@ int clLibraryInit() __clewEnqueueBarrier = (PFNCLENQUEUEBARRIER )CLCC_DYNLIB_IMPORT(module, "clEnqueueBarrier"); __clewGetExtensionFunctionAddress = (PFNCLGETEXTENSIONFUNCTIONADDRESS )CLCC_DYNLIB_IMPORT(module, "clGetExtensionFunctionAddress"); - if(__clewGetPlatformIDs == NULL) - return 0; + if(__clewGetPlatformIDs == NULL) return 0; + if(__clewGetPlatformInfo == NULL) return 0; + if(__clewGetDeviceIDs == NULL) return 0; + if(__clewGetDeviceInfo == NULL) return 0; return 1; } diff --git a/intern/cycles/util/util_progress.h b/intern/cycles/util/util_progress.h index c63aa841c52..ab9ab7243e9 100644 --- a/intern/cycles/util/util_progress.h +++ b/intern/cycles/util/util_progress.h @@ -36,10 +36,11 @@ class Progress { public: Progress() { + tile = 0; sample = 0; start_time = time_dt(); total_time = 0.0f; - sample_time = 0.0f; + tile_time = 0.0f; status = "Initializing"; substatus = ""; update_cb = NULL; @@ -57,8 +58,10 @@ public: { thread_scoped_lock lock(progress.progress_mutex); - progress.get_sample(sample, total_time, sample_time); progress.get_status(status, substatus); + progress.get_tile(tile, total_time, tile_time); + + sample = progress.get_sample(); return *this; } @@ -90,7 +93,7 @@ public: cancel_cb = function; } - /* sample and timing information */ + /* tile and timing information */ void set_start_time(double start_time_) { @@ -99,22 +102,41 @@ public: start_time = start_time_; } - void set_sample(int sample_, double sample_time_) + void set_tile(int tile_, double tile_time_) { thread_scoped_lock lock(progress_mutex); - sample = sample_; + tile = tile_; total_time = time_dt() - start_time; - sample_time = sample_time_; + tile_time = tile_time_; } - void get_sample(int& sample_, double& total_time_, double& sample_time_) + void get_tile(int& tile_, double& total_time_, double& tile_time_) { thread_scoped_lock lock(progress_mutex); - sample_ = sample; + tile_ = tile; total_time_ = (total_time > 0.0)? total_time: 0.0; - sample_time_ = sample_time; + tile_time_ = tile_time; + } + + void reset_sample() + { + thread_scoped_lock lock(progress_mutex); + + sample = 0; + } + + void increment_sample() + { + thread_scoped_lock lock(progress_mutex); + + sample++; + } + + int get_sample() + { + return sample; } /* status messages */ @@ -170,11 +192,12 @@ protected: boost::function<void(void)> update_cb; boost::function<void(void)> cancel_cb; - int sample; + int tile; /* counter for rendered tiles */ + int sample; /* counter of rendered samples, global for all tiles */ double start_time; double total_time; - double sample_time; + double tile_time; string status; string substatus; diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp index ea0abd6f54f..2b209c135f4 100644 --- a/intern/cycles/util/util_task.cpp +++ b/intern/cycles/util/util_task.cpp @@ -38,6 +38,8 @@ TaskPool::~TaskPool() void TaskPool::push(Task *task, bool front) { + thread_scoped_lock num_lock(num_mutex); + TaskScheduler::Entry entry; entry.task = task; @@ -102,22 +104,17 @@ void TaskPool::wait_work() void TaskPool::cancel() { + thread_scoped_lock num_lock(num_mutex); + do_cancel = true; TaskScheduler::clear(this); - - { - thread_scoped_lock num_lock(num_mutex); - - while(num) - num_cond.wait(num_lock); - } - - do_cancel = false; } void TaskPool::stop() { + thread_scoped_lock num_lock(num_mutex); + TaskScheduler::clear(this); assert(num == 0); @@ -130,20 +127,20 @@ bool TaskPool::cancelled() void TaskPool::num_decrease(int done) { - num_mutex.lock(); num -= done; - assert(num >= 0); - if(num == 0) + + if(num == 0) { + do_cancel = false; + num_cond.notify_all(); - - num_mutex.unlock(); + } } void TaskPool::num_increase() { - thread_scoped_lock num_lock(num_mutex); num++; + num_cond.notify_all(); } @@ -239,7 +236,11 @@ void TaskScheduler::thread_run(int thread_id) delete entry.task; /* notify pool task was done */ - entry.pool->num_decrease(1); + { + /* not called from TaskPool, have to explicitly lock the mutex here */ + thread_scoped_lock num_lock(entry.pool->num_mutex); + entry.pool->num_decrease(1); + } } } diff --git a/intern/cycles/util/util_types.h b/intern/cycles/util/util_types.h index 0451d877c45..5c6b9d5bb78 100644 --- a/intern/cycles/util/util_types.h +++ b/intern/cycles/util/util_types.h @@ -444,6 +444,22 @@ __device_inline int4 make_int4(const float3& f) #endif +typedef enum AttributeStandard { + ATTR_STD_NONE = 0, + ATTR_STD_VERTEX_NORMAL, + ATTR_STD_FACE_NORMAL, + ATTR_STD_UV, + ATTR_STD_GENERATED, + ATTR_STD_POSITION_UNDEFORMED, + ATTR_STD_POSITION_UNDISPLACED, + ATTR_STD_MOTION_PRE, + ATTR_STD_MOTION_POST, + ATTR_STD_PARTICLE, + ATTR_STD_NUM, + + ATTR_STD_NOT_FOUND = ~0 +} AttributeStandard; + CCL_NAMESPACE_END #endif /* __UTIL_TYPES_H__ */ diff --git a/intern/ghost/GHOST_IEvent.h b/intern/ghost/GHOST_IEvent.h index ef63c57caa5..ba5d9ee33b9 100644 --- a/intern/ghost/GHOST_IEvent.h +++ b/intern/ghost/GHOST_IEvent.h @@ -45,10 +45,10 @@ class GHOST_IWindow; * Use the getType() method to retrieve the type of event and the getData() * method to get the event data out. Using the event type you can cast the * event data to the correct event dat structure. - * @see GHOST_IEventConsumer#processEvent - * @see GHOST_TEventType - * @author Maarten Gribnau - * @date May 31, 2001 + * \see GHOST_IEventConsumer#processEvent + * \see GHOST_TEventType + * \author Maarten Gribnau + * \date May 31, 2001 */ class GHOST_IEvent { @@ -62,26 +62,26 @@ public: /** * Returns the event type. - * @return The event type. + * \return The event type. */ virtual GHOST_TEventType getType() = 0; /** * Returns the time this event was generated. - * @return The event generation time. + * \return The event generation time. */ virtual GHOST_TUns64 getTime() = 0; /** * Returns the window this event was generated on, * or NULL if it is a 'system' event. - * @return The generating window. + * \return The generating window. */ virtual GHOST_IWindow *getWindow() = 0; /** * Returns the event data. - * @return The event data. + * \return The event data. */ virtual GHOST_TEventDataPtr getData() = 0; diff --git a/intern/ghost/GHOST_IEventConsumer.h b/intern/ghost/GHOST_IEventConsumer.h index cfc4fae7978..5682d04d434 100644 --- a/intern/ghost/GHOST_IEventConsumer.h +++ b/intern/ghost/GHOST_IEventConsumer.h @@ -41,9 +41,9 @@ * processEvent() method. They should then be registered with the system that * they want to receive events. The system will call the processEvent() method * for every installed event consumer to pass events. - * @see GHOST_ISystem#addEventConsumer - * @author Maarten Gribnau - * @date May 14, 2001 + * \see GHOST_ISystem#addEventConsumer + * \author Maarten Gribnau + * \date May 14, 2001 */ class GHOST_IEventConsumer { @@ -57,9 +57,9 @@ public: /** * This method is called by the system when it has events to dispatch. - * @see GHOST_ISystem#dispatchEvents - * @param event The event that can be handled or ignored. - * @return Indication as to whether the event was handled. + * \see GHOST_ISystem#dispatchEvents + * \param event The event that can be handled or ignored. + * \return Indication as to whether the event was handled. */ virtual bool processEvent(GHOST_IEvent *event) = 0; diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index 474e3e97c45..8aef81bb762 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -136,27 +136,27 @@ class GHOST_IEventConsumer; * -# Access to the state of the mouse buttons and the keyboard. * -# Menus for windows with events generated when they are accessed (this is * work in progress). - * @author Maarten Gribnau - * @date May 30, 2001 + * \author Maarten Gribnau + * \date May 30, 2001 */ class GHOST_ISystem { public: /** * Creates the one and only system. - * @return An indication of success. + * \return An indication of success. */ static GHOST_TSuccess createSystem(); /** * Disposes the one and only system. - * @return An indication of success. + * \return An indication of success. */ static GHOST_TSuccess disposeSystem(); /** * Returns a pointer to the one and only system (nil if it hasn't been created). - * @return A pointer to the system. + * \return A pointer to the system. */ static GHOST_ISystem *getSystem(); @@ -184,7 +184,7 @@ public: * Returns the system time. * Returns the number of milliseconds since the start of the system process. * Based on ANSI clock() routine. - * @return The number of milliseconds. + * \return The number of milliseconds. */ virtual GHOST_TUns64 getMilliSeconds() const = 0; @@ -192,11 +192,11 @@ public: * Installs a timer. * Note that, on most operating systems, messages need to be processed in order * for the timer callbacks to be invoked. - * @param delay The time to wait for the first call to the timerProc (in milliseconds) - * @param interval The interval between calls to the timerProc (in milliseconds) - * @param timerProc The callback invoked when the interval expires, - * @param userData Placeholder for user data. - * @return A timer task (0 if timer task installation failed). + * \param delay The time to wait for the first call to the timerProc (in milliseconds) + * \param interval The interval between calls to the timerProc (in milliseconds) + * \param timerProc The callback invoked when the interval expires, + * \param userData Placeholder for user data. + * \return A timer task (0 if timer task installation failed). */ virtual GHOST_ITimerTask *installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, @@ -205,8 +205,8 @@ public: /** * Removes a timer. - * @param timerTask Timer task to be removed. - * @return Indication of success. + * \param timerTask Timer task to be removed. + * \return Indication of success. */ virtual GHOST_TSuccess removeTimer(GHOST_ITimerTask *timerTask) = 0; @@ -216,13 +216,13 @@ public: /** * Returns the number of displays on this system. - * @return The number of displays. + * \return The number of displays. */ virtual GHOST_TUns8 getNumDisplays() const = 0; /** * Returns the dimensions of the main display on this system. - * @return The dimension of the main display. + * \return The dimension of the main display. */ virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const = 0; @@ -230,17 +230,17 @@ public: * Create a new window. * The new window is added to the list of windows managed. * Never explicitly delete the window, use disposeWindow() instead. - * @param title The name of the window (displayed in the title bar of the window if the OS supports it). - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state of the window when opened. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Create a stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) - * @param parentWindow Parent (embedder) window - * @return The new window (or 0 if creation failed). + * \param title The name of the window (displayed in the title bar of the window if the OS supports it). + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state of the window when opened. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Create a stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) + * \param parentWindow Parent (embedder) window + * \return The new window (or 0 if creation failed). */ virtual GHOST_IWindow *createWindow( const STR_String& title, @@ -252,46 +252,46 @@ public: /** * Dispose a window. - * @param window Pointer to the window to be disposed. - * @return Indication of success. + * \param window Pointer to the window to be disposed. + * \return Indication of success. */ virtual GHOST_TSuccess disposeWindow(GHOST_IWindow *window) = 0; /** * Returns whether a window is valid. - * @param window Pointer to the window to be checked. - * @return Indication of validity. + * \param window Pointer to the window to be checked. + * \return Indication of validity. */ virtual bool validWindow(GHOST_IWindow *window) = 0; /** * Begins full screen mode. - * @param setting The new setting of the display. - * @param window Window displayed in full screen. + * \param setting The new setting of the display. + * \param window Window displayed in full screen. * This window is invalid after full screen has been ended. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow **window, const bool stereoVisual, const GHOST_TUns16 numOfAASamples = 0) = 0; /** * Updates the resolution while in fullscreen mode. - * @param setting The new setting of the display. - * @param window Window displayed in full screen. + * \param setting The new setting of the display. + * \param window Window displayed in full screen. * - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow **window) = 0; /** * Ends full screen mode. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess endFullScreen(void) = 0; /** * Returns current full screen mode status. - * @return The current status. + * \return The current status. */ virtual bool getFullScreen(void) = 0; @@ -301,28 +301,28 @@ public: /** * Retrieves events from the system and stores them in the queue. - * @param waitForEvent Flag to wait for an event (or return immediately). - * @return Indication of the presence of events. + * \param waitForEvent Flag to wait for an event (or return immediately). + * \return Indication of the presence of events. */ virtual bool processEvents(bool waitForEvent) = 0; /** * Retrieves events from the queue and send them to the event consumers. - * @return Indication of the presence of events. + * \return Indication of the presence of events. */ virtual bool dispatchEvents() = 0; /** * Adds the given event consumer to our list. - * @param consumer The event consumer to add. - * @return Indication of success. + * \param consumer The event consumer to add. + * \return Indication of success. */ virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer *consumer) = 0; /** * Removes the given event consumer to our list. - * @param consumer The event consumer to remove. - * @return Indication of success. + * \param consumer The event consumer to remove. + * \return Indication of success. */ virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer *consumer) = 0; @@ -332,18 +332,18 @@ public: /** * Returns the current location of the cursor (location in screen coordinates) - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const = 0; /** * Updates the location of the cursor (location in screen coordinates). * Not all operating systems allow the cursor to be moved (without the input device being moved). - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) = 0; @@ -353,28 +353,29 @@ public: /** * Returns the state of a modifier key (ouside the message queue). - * @param mask The modifier key state to retrieve. - * @param isDown The state of a modifier key (true == pressed). - * @return Indication of success. + * \param mask The modifier key state to retrieve. + * \param isDown The state of a modifier key (true == pressed). + * \return Indication of success. */ virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const = 0; /** * Returns the state of a mouse button (ouside the message queue). - * @param mask The button state to retrieve. - * @param isDown Button state. - * @return Indication of success. + * \param mask The button state to retrieve. + * \param isDown Button state. + * \return Indication of success. */ virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0; /** * Toggles console - * @action 0 - Hides - * 1 - Shows - * 2 - Toggles - * 3 - Hides if it runs not from command line - * * - Does nothing - * @return current status (1 -visible, 0 - hidden) + * \param action + * - 0: Hides + * - 1: Shows + * - 2: Toggles + * - 3: Hides if it runs not from command line + * - *: Does nothing + * \return current status (1 -visible, 0 - hidden) */ virtual int toggleConsole(int action) = 0; @@ -384,7 +385,7 @@ public: /** * Returns the selection buffer - * @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer + * \return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer * */ virtual GHOST_TUns8 *getClipboard(bool selection) const = 0; @@ -402,13 +403,13 @@ public: protected: /** * Initialize the system. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess init() = 0; /** * Shut the system down. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess exit() = 0; diff --git a/intern/ghost/GHOST_ISystemPaths.h b/intern/ghost/GHOST_ISystemPaths.h index 1ba4ceaaaba..8f81a226f94 100644 --- a/intern/ghost/GHOST_ISystemPaths.h +++ b/intern/ghost/GHOST_ISystemPaths.h @@ -38,19 +38,19 @@ class GHOST_ISystemPaths public: /** * Creates the one and only system. - * @return An indication of success. + * \return An indication of success. */ static GHOST_TSuccess create(); /** * Disposes the one and only system. - * @return An indication of success. + * \return An indication of success. */ static GHOST_TSuccess dispose(); /** * Returns a pointer to the one and only system (nil if it hasn't been created). - * @return A pointer to the system. + * \return A pointer to the system. */ static GHOST_ISystemPaths *get(); @@ -73,20 +73,20 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). + * \return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const = 0; /** * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/.blender/). + * \return Unsigned char string pointing to user dir (eg ~/.blender/). */ virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const = 0; /** * Determine the directory of the current binary - * @return Unsigned char string pointing to the binary dir + * \return Unsigned char string pointing to the binary dir */ virtual const GHOST_TUns8 *getBinaryDir() const = 0; diff --git a/intern/ghost/GHOST_ITimerTask.h b/intern/ghost/GHOST_ITimerTask.h index 08c4890939f..fcd42db59da 100644 --- a/intern/ghost/GHOST_ITimerTask.h +++ b/intern/ghost/GHOST_ITimerTask.h @@ -45,10 +45,10 @@ * <br> * Note that GHOST processes timers in the UI thread. You should ask GHOST * process messages in order for the timer-callbacks to be called. - * @see GHOST_ISystem#installTimer - * @see GHOST_TimerProcPtr - * @author Maarten Gribnau - * @date May 31, 2001 + * \see GHOST_ISystem#installTimer + * \see GHOST_TimerProcPtr + * \author Maarten Gribnau + * \date May 31, 2001 */ class GHOST_ITimerTask { @@ -62,25 +62,25 @@ public: /** * Returns the timer callback. - * @return The timer callback. + * \return The timer callback. */ virtual GHOST_TimerProcPtr getTimerProc() const = 0; /** * Changes the timer callback. - * @param timerProc The timer callback. + * \param timerProc The timer callback. */ virtual void setTimerProc(const GHOST_TimerProcPtr timerProc) = 0; /** * Returns the timer user data. - * @return The timer user data. + * \return The timer user data. */ virtual GHOST_TUserDataPtr getUserData() const = 0; /** * Changes the time user data. - * @param data The timer user data. + * \param data The timer user data. */ virtual void setUserData(const GHOST_TUserDataPtr userData) = 0; diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h index b606294e97d..a1a1acfca75 100644 --- a/intern/ghost/GHOST_IWindow.h +++ b/intern/ghost/GHOST_IWindow.h @@ -43,7 +43,7 @@ * * You can create a window with the system's GHOST_ISystem::createWindow * method. - * @see GHOST_ISystem#createWindow + * \see GHOST_ISystem#createWindow * * There are two coordinate systems: * <ul> @@ -53,8 +53,8 @@ * is the area that is drawable by the application (excluding title bars etc.). * </li> * </ul> - * @author Maarten Gribnau - * @date May 31, 2001 + * \author Maarten Gribnau + * \date May 31, 2001 */ class GHOST_IWindow { @@ -68,89 +68,89 @@ public: /** * Returns indication as to whether the window is valid. - * @return The validity of the window. + * \return The validity of the window. */ virtual bool getValid() const = 0; /** * Returns the associated OS object/handle - * @return The associated OS object/handle + * \return The associated OS object/handle */ virtual void *getOSWindow() const = 0; /** * Returns the type of drawing context used in this window. - * @return The current type of drawing context. + * \return The current type of drawing context. */ virtual GHOST_TDrawingContextType getDrawingContextType() = 0; /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) = 0; /** * Sets the title displayed in the title bar. - * @param title The title to display in the title bar. + * \param title The title to display in the title bar. */ virtual void setTitle(const STR_String& title) = 0; /** * Returns the title displayed in the title bar. - * @param title The title displayed in the title bar. + * \param title The title displayed in the title bar. */ virtual void getTitle(STR_String& title) const = 0; /** * Returns the window rectangle dimensions. * These are screen coordinates. - * @param bounds The bounding rectangle of the window. + * \param bounds The bounding rectangle of the window. */ virtual void getWindowBounds(GHOST_Rect& bounds) const = 0; /** * Returns the client rectangle dimensions. * The left and top members of the rectangle are always zero. - * @param bounds The bounding rectangle of the client area of the window. + * \param bounds The bounding rectangle of the client area of the window. */ virtual void getClientBounds(GHOST_Rect& bounds) const = 0; /** * Resizes client rectangle width. - * @param width The new width of the client area of the window. + * \param width The new width of the client area of the window. */ virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width) = 0; /** * Resizes client rectangle height. - * @param height The new height of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height) = 0; /** * Resizes client rectangle. - * @param width The new width of the client area of the window. - * @param height The new height of the client area of the window. + * \param width The new width of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height) = 0; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate on the screen. - * @param inY The y-coordinate on the screen. - * @param outX The x-coordinate in the client rectangle. - * @param outY The y-coordinate in the client rectangle. + * \param inX The x-coordinate on the screen. + * \param inY The y-coordinate on the screen. + * \param outX The x-coordinate in the client rectangle. + * \param outY The y-coordinate in the client rectangle. */ virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate in the client rectangle. - * @param inY The y-coordinate in the client rectangle. - * @param outX The x-coordinate on the screen. - * @param outY The y-coordinate on the screen. + * \param inX The x-coordinate in the client rectangle. + * \param inY The y-coordinate in the client rectangle. + * \param outX The x-coordinate on the screen. + * \param outY The y-coordinate on the screen. */ virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0; @@ -167,70 +167,70 @@ public: /** * Returns the state of the window (normal, minimized, maximized). - * @return The state of the window. + * \return The state of the window. */ virtual GHOST_TWindowState getState() const = 0; /** * Sets the state of the window (normal, minimized, maximized). - * @param state The state of the window. - * @return Indication of success. + * \param state The state of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setState(GHOST_TWindowState state) = 0; /** * Sets the window "modified" status, indicating unsaved changes - * @param isUnsavedChanges Unsaved changes or not - * @return Indication of success. + * \param isUnsavedChanges Unsaved changes or not + * \return Indication of success. */ virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges) = 0; /** * Gets the window "modified" status, indicating unsaved changes - * @return True if there are unsaved changes + * \return True if there are unsaved changes */ virtual bool getModifiedState() = 0; /** * Sets the order of the window (bottom, top). - * @param order The order of the window. - * @return Indication of success. + * \param order The order of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0; /** * Swaps front and back buffers of a window. - * @return A boolean success indicator. + * \return A boolean success indicator. */ virtual GHOST_TSuccess swapBuffers() = 0; /** * Activates the drawing context of this window. - * @return A boolean success indicator. + * \return A boolean success indicator. */ virtual GHOST_TSuccess activateDrawingContext() = 0; /** * Invalidates the contents of this window. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess invalidate() = 0; /** * Returns the window user data. - * @return The window user data. + * \return The window user data. */ virtual GHOST_TUserDataPtr getUserData() const = 0; /** * Changes the window user data. - * @param data The window user data. + * \param data The window user data. */ virtual void setUserData(const GHOST_TUserDataPtr userData) = 0; /** * Returns the tablet data (pressure etc). - * @return The tablet data (pressure etc). + * \return The tablet data (pressure etc). */ virtual const GHOST_TabletData *GetTabletData() = 0; @@ -240,7 +240,7 @@ public: /** * Sets the progress bar value displayed in the window/application icon - * @param progress The progress % + * \param progress The progress % */ virtual GHOST_TSuccess setProgressBar(float progress) = 0; @@ -255,24 +255,24 @@ public: /** * Returns the current cursor shape. - * @return The current cursor shape. + * \return The current cursor shape. */ virtual GHOST_TStandardCursor getCursorShape() const = 0; /** * Set the shape of the cursor. - * @param cursor The new cursor shape type id. - * @return Indication of success. + * \param cursor The new cursor shape type id. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape) = 0; /** * Set the shape of the cursor to a custom cursor. - * @param bitmap The bitmap data for the cursor. - * @param mask The mask data for the cursor. - * @param hotX The X coordinate of the cursor hotspot. - * @param hotY The Y coordinate of the cursor hotspot. - * @return Indication of success. + * \param bitmap The bitmap data for the cursor. + * \param mask The mask data for the cursor. + * \param hotX The X coordinate of the cursor hotspot. + * \param hotY The Y coordinate of the cursor hotspot. + * \return Indication of success. */ virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], @@ -287,21 +287,21 @@ public: /** * Returns the visibility state of the cursor. - * @return The visibility state of the cursor. + * \return The visibility state of the cursor. */ virtual bool getCursorVisibility() const = 0; /** * Shows or hides the cursor. - * @param visible The new visibility state of the cursor. - * @return Indication of success. + * \param visible The new visibility state of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorVisibility(bool visible) = 0; /** * Grabs the cursor for a modal operation. - * @param grab The new grab state of the cursor. - * @return Indication of success. + * \param grab The new grab state of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds) { return GHOST_kSuccess; } diff --git a/intern/ghost/GHOST_Path-api.h b/intern/ghost/GHOST_Path-api.h index a037f2e3760..5af3adaa570 100644 --- a/intern/ghost/GHOST_Path-api.h +++ b/intern/ghost/GHOST_Path-api.h @@ -43,33 +43,33 @@ GHOST_DECLARE_HANDLE(GHOST_SystemPathsHandle); /** * Creates the one and only instance of the system path access. - * @return An indication of success. + * \return An indication of success. */ extern GHOST_TSuccess GHOST_CreateSystemPaths(void); /** * Disposes the one and only system. - * @return An indication of success. + * \return An indication of success. */ extern GHOST_TSuccess GHOST_DisposeSystemPaths(void); /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). + * \return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ extern const GHOST_TUns8 *GHOST_getSystemDir(int version, const char *versionstr); /** * Determine the base dir in which user configuration is stored, including versioning. - * @return Unsigned char string pointing to user dir (eg ~). + * \return Unsigned char string pointing to user dir (eg ~). */ extern const GHOST_TUns8 *GHOST_getUserDir(int version, const char *versionstr); /** * Determine the dir in which the binary file is found. - * @return Unsigned char string pointing to binary dir (eg ~/usr/local/bin/). + * \return Unsigned char string pointing to binary dir (eg ~/usr/local/bin/). */ extern const GHOST_TUns8 *GHOST_getBinaryDir(void); diff --git a/intern/ghost/GHOST_Rect.h b/intern/ghost/GHOST_Rect.h index 745e402cdc8..e52d6a7e6a0 100644 --- a/intern/ghost/GHOST_Rect.h +++ b/intern/ghost/GHOST_Rect.h @@ -41,8 +41,8 @@ * The four extreme coordinates are stored as left, top, right and bottom. * To be valid, a rectangle should have a left coordinate smaller than or equal to right. * To be valid, a rectangle should have a top coordinate smaller than or equal to bottom. - * @author Maarten Gribnau - * @date May 10, 2001 + * \author Maarten Gribnau + * \date May 10, 2001 */ class GHOST_Rect { @@ -50,10 +50,10 @@ public: /** * Constructs a rectangle with the given values. - * @param l requested left coordinate of the rectangle - * @param t requested top coordinate of the rectangle - * @param r requested right coordinate of the rectangle - * @param b requested bottom coordinate of the rectangle + * \param l requested left coordinate of the rectangle + * \param t requested top coordinate of the rectangle + * \param r requested right coordinate of the rectangle + * \param b requested bottom coordinate of the rectangle */ GHOST_Rect(GHOST_TInt32 l = 0, GHOST_TInt32 t = 0, GHOST_TInt32 r = 0, GHOST_TInt32 b = 0) : m_l(l), m_t(t), m_r(r), m_b(b) @@ -61,7 +61,7 @@ public: /** * Copy constructor. - * @param r rectangle to copy + * \param r rectangle to copy */ GHOST_Rect(const GHOST_Rect& r) : m_l(r.m_l), m_t(r.m_t), m_r(r.m_r), m_b(r.m_b) @@ -75,88 +75,88 @@ public: /** * Access to rectangle width. - * @return width of the rectangle + * \return width of the rectangle */ virtual inline GHOST_TInt32 getWidth() const; /** * Access to rectangle height. - * @return height of the rectangle + * \return height of the rectangle */ virtual inline GHOST_TInt32 getHeight() const; /** * Sets all members of the rectangle. - * @param l requested left coordinate of the rectangle - * @param t requested top coordinate of the rectangle - * @param r requested right coordinate of the rectangle - * @param b requested bottom coordinate of the rectangle + * \param l requested left coordinate of the rectangle + * \param t requested top coordinate of the rectangle + * \param r requested right coordinate of the rectangle + * \param b requested bottom coordinate of the rectangle */ virtual inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b); /** * Returns whether this rectangle is empty. * Empty rectangles are rectangles that have width==0 and/or height==0. - * @return boolean value (true==empty rectangle) + * \return boolean value (true==empty rectangle) */ virtual inline bool isEmpty() const; /** * Returns whether this rectangle is valid. * Valid rectangles are rectangles that have m_l <= m_r and m_t <= m_b. Thus, emapty rectangles are valid. - * @return boolean value (true==valid rectangle) + * \return boolean value (true==valid rectangle) */ virtual inline bool isValid() const; /** * Grows (or shrinks the rectangle). * The method avoids negative insets making the rectangle invalid - * @param i The amount of offset given to each extreme (negative values shrink the rectangle). + * \param i The amount of offset given to each extreme (negative values shrink the rectangle). */ virtual void inset(GHOST_TInt32 i); /** * Does a union of the rectangle given and this rectangle. * The result is stored in this rectangle. - * @param r The rectangle that is input for the union operation. + * \param r The rectangle that is input for the union operation. */ virtual inline void unionRect(const GHOST_Rect& r); /** * Grows the rectangle to included a point. - * @param x The x-coordinate of the point. - * @param y The y-coordinate of the point. + * \param x The x-coordinate of the point. + * \param y The y-coordinate of the point. */ virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y); /** * Grows the rectangle to included a point. - * @param x The x-coordinate of the point. - * @param y The y-coordinate of the point. + * \param x The x-coordinate of the point. + * \param y The y-coordinate of the point. */ virtual inline void wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32 ofs); /** * Returns whether the point is inside this rectangle. * Point on the boundary is considered inside. - * @param x x-coordinate of point to test. - * @param y y-coordinate of point to test. - * @return boolean value (true if point is inside). + * \param x x-coordinate of point to test. + * \param y y-coordinate of point to test. + * \return boolean value (true if point is inside). */ virtual inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const; /** * Returns whether the rectangle is inside this rectangle. - * @param r rectangle to test. - * @return visibility (not, partially or fully visible). + * \param r rectangle to test. + * \return visibility (not, partially or fully visible). */ virtual GHOST_TVisibility getVisibility(GHOST_Rect& r) const; /** * Sets rectangle members. * Sets rectangle members such that it is centered at the given location. - * @param cx requested center x-coordinate of the rectangle - * @param cy requested center y-coordinate of the rectangle + * \param cx requested center x-coordinate of the rectangle + * \param cy requested center y-coordinate of the rectangle */ virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy); @@ -164,10 +164,10 @@ public: * Sets rectangle members. * Sets rectangle members such that it is centered at the given location, * with the width requested. - * @param cx requested center x-coordinate of the rectangle - * @param cy requested center y-coordinate of the rectangle - * @param w requested width of the rectangle - * @param h requested height of the rectangle + * \param cx requested center x-coordinate of the rectangle + * \param cy requested center y-coordinate of the rectangle + * \param w requested width of the rectangle + * \param h requested height of the rectangle */ virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h); @@ -175,8 +175,8 @@ public: * Clips a rectangle. * Updates the rectangle given such that it will fit within this one. * This can result in an empty rectangle. - * @param r the rectangle to clip - * @return whether clipping has occurred + * \param r the rectangle to clip + * \return whether clipping has occurred */ virtual bool clip(GHOST_Rect& r) const; diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index 4921acde670..c6d364c361c 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -507,8 +507,8 @@ typedef int GHOST_TEmbedderWindowID; /** * A timer task callback routine. - * @param task The timer task object. - * @param time The current time. + * \param task The timer task object. + * \param time The current time. */ #ifdef __cplusplus class GHOST_ITimerTask; diff --git a/intern/ghost/intern/GHOST_Buttons.h b/intern/ghost/intern/GHOST_Buttons.h index edcf0102201..6b0d74e7eb9 100644 --- a/intern/ghost/intern/GHOST_Buttons.h +++ b/intern/ghost/intern/GHOST_Buttons.h @@ -39,8 +39,8 @@ /** * This struct stores the state of the mouse buttons. * Buttons can be set using button masks. - * @author Maarten Gribnau - * @date May 15, 2001 + * \author Maarten Gribnau + * \date May 15, 2001 */ struct GHOST_Buttons { /** @@ -52,15 +52,15 @@ struct GHOST_Buttons { /** * Returns the state of a single button. - * @param mask Key button to return. - * @return The state of the button (pressed == true). + * \param mask Key button to return. + * \return The state of the button (pressed == true). */ virtual bool get(GHOST_TButtonMask mask) const; /** * Updates the state of a single button. - * @param mask Button state to update. - * @param down The new state of the button. + * \param mask Button state to update. + * \param down The new state of the button. */ virtual void set(GHOST_TButtonMask mask, bool down); diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index bb6c90cd431..0a4325930d5 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -529,7 +529,10 @@ char *GHOST_GetTitle(GHOST_WindowHandle windowhandle) char *ctitle = (char *) malloc(title.Length() + 1); - if (ctitle == NULL) return NULL; + if (ctitle == NULL) { + return NULL; + } + strcpy(ctitle, title.Ptr()); return ctitle; diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp b/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp index 47121562604..9d20a62d70c 100644 --- a/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp +++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date October 25, 2001 + * \author Maarten Gribnau + * \date October 25, 2001 */ #include "GHOST_Debug.h" diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.h b/intern/ghost/intern/GHOST_CallbackEventConsumer.h index e13a56c38f4..770ebdc8b78 100644 --- a/intern/ghost/intern/GHOST_CallbackEventConsumer.h +++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.h @@ -39,16 +39,16 @@ /** * Event consumer that will forward events to a call-back routine. * Especially useful for the C-API. - * @author Maarten Gribnau - * @date October 25, 2001 + * \author Maarten Gribnau + * \date October 25, 2001 */ class GHOST_CallbackEventConsumer : public GHOST_IEventConsumer { public: /** * Constructor. - * @param eventCallback The call-back routine invoked. - * @param userData The data passed back though the call-back routine. + * \param eventCallback The call-back routine invoked. + * \param userData The data passed back though the call-back routine. */ GHOST_CallbackEventConsumer( GHOST_EventCallbackProcPtr eventCallback, @@ -63,8 +63,8 @@ public: /** * This method is called by an event producer when an event is available. - * @param event The event that can be handled or ignored. - * @return Indication as to whether the event was handled. + * \param event The event that can be handled or ignored. + * \return Indication as to whether the event was handled. */ virtual bool processEvent(GHOST_IEvent *event); diff --git a/intern/ghost/intern/GHOST_DisplayManager.cpp b/intern/ghost/intern/GHOST_DisplayManager.cpp index 380fb817ab0..7ca4c8182b9 100644 --- a/intern/ghost/intern/GHOST_DisplayManager.cpp +++ b/intern/ghost/intern/GHOST_DisplayManager.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date September 21, 2001 + * \author Maarten Gribnau + * \date September 21, 2001 */ #include "GHOST_DisplayManager.h" diff --git a/intern/ghost/intern/GHOST_DisplayManager.h b/intern/ghost/intern/GHOST_DisplayManager.h index 7893f0936b3..7dc0cf2ca04 100644 --- a/intern/ghost/intern/GHOST_DisplayManager.h +++ b/intern/ghost/intern/GHOST_DisplayManager.h @@ -39,8 +39,8 @@ /** * Manages system displays (platform independent implementation). - * @author Maarten Gribnau - * @date September 21, 2001 + * \author Maarten Gribnau + * \date September 21, 2001 */ class GHOST_DisplayManager { @@ -58,32 +58,32 @@ public: /** * Initializes the list with devices and settings. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess initialize(void); /** * Returns the number of display devices on this system. - * @param numDisplays The number of displays on this system. - * @return Indication of success. + * \param numDisplays The number of displays on this system. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const; /** * Returns the number of display settings for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param numSettings The number of settings of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param numSettings The number of settings of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param index The setting index to be returned. - * @param setting The setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param index The setting index to be returned. + * \param setting The setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, @@ -91,9 +91,9 @@ public: /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const; @@ -102,9 +102,9 @@ public: * Changes the current setting for this display device. * The setting given to this method is matched againts the available diplay settings. * The best match is activated (@see findMatch()). - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The setting of the display device to be matched and activated. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The setting of the display device to be matched and activated. + * \return Indication of success. */ virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting); @@ -114,10 +114,10 @@ protected: /** * Finds the best display settings match. - * @param display The index of the display device. - * @param setting The setting to match. - * @param match The optimal display setting. - * @return Indication of success. + * \param display The index of the display device. + * \param setting The setting to match. + * \param match The optimal display setting. + * \return Indication of success. */ GHOST_TSuccess findMatch(GHOST_TUns8 display, const GHOST_DisplaySetting& setting, @@ -125,7 +125,7 @@ protected: /** * Retrieves settings for each display device and stores them. - * @return Indication of success. + * \return Indication of success. */ GHOST_TSuccess initializeSettings(void); diff --git a/intern/ghost/intern/GHOST_DisplayManagerCarbon.cpp b/intern/ghost/intern/GHOST_DisplayManagerCarbon.cpp index 21798ed2d0a..3f7d2102dac 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerCarbon.cpp +++ b/intern/ghost/intern/GHOST_DisplayManagerCarbon.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date September 21, 2001 + * \author Maarten Gribnau + * \date September 21, 2001 */ #include "GHOST_DisplayManagerCarbon.h" diff --git a/intern/ghost/intern/GHOST_DisplayManagerCarbon.h b/intern/ghost/intern/GHOST_DisplayManagerCarbon.h index d9af12ba13f..1ac6540b7bd 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerCarbon.h +++ b/intern/ghost/intern/GHOST_DisplayManagerCarbon.h @@ -44,9 +44,9 @@ /** * Manages system displays (Mac OSX/Carbon implementation). - * @see GHOST_DisplayManager - * @author Maarten Gribnau - * @date September 21, 2001 + * \see GHOST_DisplayManager + * \author Maarten Gribnau + * \date September 21, 2001 */ class GHOST_DisplayManagerCarbon : public GHOST_DisplayManager { @@ -58,50 +58,50 @@ public: /** * Returns the number of display devices on this system. - * @param numDisplays The number of displays on this system. - * @return Indication of success. + * \param numDisplays The number of displays on this system. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const; /** * Returns the number of display settings for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The number of settings of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The number of settings of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param index The setting index to be returned. - * @param setting The setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param index The setting index to be returned. + * \param setting The setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const; /** * Changes the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting); protected: /** * Returns a value from a dictionary. - * @param values Dictionary to return value from. - * @param key Key to return value for. - * @return The value for this key. + * \param values Dictionary to return value from. + * \param key Key to return value for. + * \return The value for this key. */ long getValue(CFDictionaryRef values, CFStringRef key) const; diff --git a/intern/ghost/intern/GHOST_DisplayManagerCocoa.h b/intern/ghost/intern/GHOST_DisplayManagerCocoa.h index bf194ad0492..1f17b4dd976 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerCocoa.h +++ b/intern/ghost/intern/GHOST_DisplayManagerCocoa.h @@ -41,9 +41,9 @@ /** * Manages system displays (Mac OSX/Cocoa implementation). - * @see GHOST_DisplayManager - * @author Maarten Gribnau - * @date September 21, 2001 + * \see GHOST_DisplayManager + * \author Maarten Gribnau + * \date September 21, 2001 */ class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager { @@ -55,41 +55,41 @@ public: /** * Returns the number of display devices on this system. - * @param numDisplays The number of displays on this system. - * @return Indication of success. + * \param numDisplays The number of displays on this system. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const; /** * Returns the number of display settings for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The number of settings of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The number of settings of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param index The setting index to be returned. - * @param setting The setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param index The setting index to be returned. + * \param setting The setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const; /** * Changes the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting); diff --git a/intern/ghost/intern/GHOST_DisplayManagerCocoa.mm b/intern/ghost/intern/GHOST_DisplayManagerCocoa.mm index 9050c3f946f..c5a2fecd3b8 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerCocoa.mm +++ b/intern/ghost/intern/GHOST_DisplayManagerCocoa.mm @@ -101,7 +101,7 @@ GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(GHOST_TUns8 d NSScreen *askedDisplay; GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported"); - + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; if (display == kMainDisplay) //Screen #0 may not be the main one @@ -162,6 +162,6 @@ GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(GHOST_TUns8 d #endif // GHOST_DEBUG //CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues); - + return /*err == CGDisplayNoErr ?*/ GHOST_kSuccess /*: GHOST_kFailure*/; } diff --git a/intern/ghost/intern/GHOST_DisplayManagerWin32.h b/intern/ghost/intern/GHOST_DisplayManagerWin32.h index 534274ec878..ced4ceac044 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerWin32.h +++ b/intern/ghost/intern/GHOST_DisplayManagerWin32.h @@ -42,8 +42,8 @@ /** * Manages system displays (WIN32 implementation). - * @author Maarten Gribnau - * @date September 21, 2001 + * \author Maarten Gribnau + * \date September 21, 2001 */ class GHOST_DisplayManagerWin32 : public GHOST_DisplayManager { @@ -55,41 +55,41 @@ public: /** * Returns the number of display devices on this system. - * @param numDisplays The number of displays on this system. - * @return Indication of success. + * \param numDisplays The number of displays on this system. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const; /** * Returns the number of display settings for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The number of settings of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The number of settings of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param index The setting index to be returned. - * @param setting The setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param index The setting index to be returned. + * \param setting The setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const; /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const; /** * Changes the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting); diff --git a/intern/ghost/intern/GHOST_DisplayManagerX11.h b/intern/ghost/intern/GHOST_DisplayManagerX11.h index 61b4578cac3..66fd1e5c15e 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerX11.h +++ b/intern/ghost/intern/GHOST_DisplayManagerX11.h @@ -40,8 +40,8 @@ class GHOST_SystemX11; /** * Manages system displays (X11 implementation). - * @author Laurence Bourn - * @date October 26, 2001 + * \author Laurence Bourn + * \date October 26, 2001 */ class GHOST_DisplayManagerX11 : public GHOST_DisplayManager { @@ -55,8 +55,8 @@ public: /** * Returns the number of display devices on this system. - * @param numDisplays The number of displays on this system. - * @return Indication of success. + * \param numDisplays The number of displays on this system. + * \return Indication of success. */ GHOST_TSuccess getNumDisplays( @@ -65,9 +65,9 @@ public: /** * Returns the number of display settings for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The number of settings of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The number of settings of the display device with this index. + * \return Indication of success. */ GHOST_TSuccess getNumDisplaySettings( @@ -77,10 +77,10 @@ public: /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param index The setting index to be returned. - * @param setting The setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param index The setting index to be returned. + * \param setting The setting of the display device with this index. + * \return Indication of success. */ GHOST_TSuccess getDisplaySetting( @@ -91,9 +91,9 @@ public: /** * Returns the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ GHOST_TSuccess getCurrentDisplaySetting( @@ -103,9 +103,9 @@ public: /** * Changes the current setting for this display device. - * @param display The index of the display to query with 0 <= display < getNumDisplays(). - * @param setting The current setting of the display device with this index. - * @return Indication of success. + * \param display The index of the display to query with 0 <= display < getNumDisplays(). + * \param setting The current setting of the display device with this index. + * \return Indication of success. */ GHOST_TSuccess setCurrentDisplaySetting( diff --git a/intern/ghost/intern/GHOST_DropTargetWin32.cpp b/intern/ghost/intern/GHOST_DropTargetWin32.cpp index 4142b19f21d..89e9a91b34c 100644 --- a/intern/ghost/intern/GHOST_DropTargetWin32.cpp +++ b/intern/ghost/intern/GHOST_DropTargetWin32.cpp @@ -51,14 +51,10 @@ GHOST_DropTargetWin32::GHOST_DropTargetWin32(GHOST_WindowWin32 *window, GHOST_Sy m_cRef = 1; m_hWnd = window->getHWND(); m_draggedObjectType = GHOST_kDragnDropTypeUnknown; - - // register our window as drop target - ::RegisterDragDrop(m_hWnd, this); } GHOST_DropTargetWin32::~GHOST_DropTargetWin32() { - ::RevokeDragDrop(m_hWnd); } diff --git a/intern/ghost/intern/GHOST_DropTargetWin32.h b/intern/ghost/intern/GHOST_DropTargetWin32.h index 88a4032ac23..f746a50d469 100644 --- a/intern/ghost/intern/GHOST_DropTargetWin32.h +++ b/intern/ghost/intern/GHOST_DropTargetWin32.h @@ -80,8 +80,8 @@ public: * With the modifier keys, we want to distinguish left and right keys. * Sometimes this is not possible (Windows ME for instance). Then, we want * events generated for both keys. - * @param window The window to register as drop target. - * @param system The associated system. + * \param window The window to register as drop target. + * \param system The associated system. */ GHOST_DropTargetWin32(GHOST_WindowWin32 *window, GHOST_SystemWin32 *system); @@ -97,37 +97,37 @@ private: /** * Base the effect on those allowed by the dropsource. - * @param dwAllowed Drop sources allowed drop effect. - * @return The allowed drop effect. + * \param dwAllowed Drop sources allowed drop effect. + * \return The allowed drop effect. */ DWORD allowedDropEffect(DWORD dwAllowed); /** * Query DataObject for the data types it supports. - * @param pDataObject Pointer to the DataObject. - * @return GHOST data type. + * \param pDataObject Pointer to the DataObject. + * \return GHOST data type. */ GHOST_TDragnDropTypes getGhostType(IDataObject *pDataObject); /** * Get data to pass in event. * It checks the type and calls specific functions for each type. - * @param pDataObject Pointer to the DataObject. - * @return Pointer to data. + * \param pDataObject Pointer to the DataObject. + * \return Pointer to data. */ void *getGhostData(IDataObject *pDataObject); /** * Allocate data as file array to pass in event. - * @param pDataObject Pointer to the DataObject. - * @return Pointer to data. + * \param pDataObject Pointer to the DataObject. + * \return Pointer to data. */ void *getDropDataAsFilenames(IDataObject *pDataObject); /** * Allocate data as string to pass in event. - * @param pDataObject Pointer to the DataObject. - * @return Pointer to data. + * \param pDataObject Pointer to the DataObject. + * \return Pointer to data. */ void *getDropDataAsString(IDataObject *pDataObject); @@ -135,9 +135,9 @@ private: * Convert Unicode to ANSI, replacing unconvertable chars with '?'. * The ANSI codepage is the system default codepage, * and can change from system to system. - * @param in LPCWSTR. - * @param out char *. Is set to NULL on failure. - * @return 0 on failure. Else the size of the string including '\0'. + * \param in LPCWSTR. + * \param out char *. Is set to NULL on failure. + * \return 0 on failure. Else the size of the string including '\0'. */ int WideCharToANSI(LPCWSTR in, char * &out); diff --git a/intern/ghost/intern/GHOST_DropTargetX11.h b/intern/ghost/intern/GHOST_DropTargetX11.h index 10d76bbb165..3fed5798611 100644 --- a/intern/ghost/intern/GHOST_DropTargetX11.h +++ b/intern/ghost/intern/GHOST_DropTargetX11.h @@ -44,8 +44,8 @@ public: /** * Constructor * - * @param window The window to register as drop target. - * @param system The associated system. + * \param window The window to register as drop target. + * \param system The associated system. */ GHOST_DropTargetX11(GHOST_WindowX11 *window, GHOST_SystemX11 *system); @@ -62,10 +62,10 @@ public: /** * Get data to pass in event. * It checks the type and calls specific functions for each type. - * @param dropType - type of dropped entity. - * @param dropBuffer - buffer returned from source application - * @param dropBufferSize - size of returned buffer - * @return Pointer to data. + * \param dropType - type of dropped entity. + * \param dropBuffer - buffer returned from source application + * \param dropBufferSize - size of returned buffer + * \return Pointer to data. */ void *getGhostData(Atom dropType, unsigned char *dropBuffer, int dropBufferSize); @@ -84,24 +84,24 @@ private: /** * Get data to be passed to event from text/uri-list mime type - * @param dropBuffer - buffer returned from source application - * @param dropBufferSize - size of dropped buffer - * @return pointer to newly created GHOST data + * \param dropBuffer - buffer returned from source application + * \param dropBufferSize - size of dropped buffer + * \return pointer to newly created GHOST data */ void *getURIListGhostData(unsigned char *dropBuffer, int dropBufferSize); /** * Decode URL (i.e. converts "file:///a%20b/test" to "file:///a b/test") - * @param decodedOut - buffer for decoded URL - * @param bufferSize - size of output buffer - * @param encodedIn - input encoded buffer to be decoded + * \param decodedOut - buffer for decoded URL + * \param bufferSize - size of output buffer + * \param encodedIn - input encoded buffer to be decoded */ void UrlDecode(char *decodedOut, int bufferSize, const char *encodedIn); /** * Fully decode file URL (i.e. converts "file:///a%20b/test" to "/a b/test") - * @param fileUrl - file path URL to be fully decoded - * @return decoded file path (resutl shold be free-d) + * \param fileUrl - file path URL to be fully decoded + * \return decoded file path (resutl shold be free-d) */ char *FileUrlDecode(char *fileUrl); diff --git a/intern/ghost/intern/GHOST_Event.h b/intern/ghost/intern/GHOST_Event.h index 6e12a34d149..c9a51f29559 100644 --- a/intern/ghost/intern/GHOST_Event.h +++ b/intern/ghost/intern/GHOST_Event.h @@ -38,17 +38,17 @@ /** * Base class for events received the operating system. - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ class GHOST_Event : public GHOST_IEvent { public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of this event. - * @param window The generating window (or NULL if system event). + * \param msec The time this event was generated. + * \param type The type of this event. + * \param window The generating window (or NULL if system event). */ GHOST_Event(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow *window) : m_type(type), m_time(msec), m_window(window), m_data(0) @@ -57,7 +57,7 @@ public: /** * Returns the event type. - * @return The event type. + * \return The event type. */ virtual GHOST_TEventType getType() { @@ -66,7 +66,7 @@ public: /** * Returns the time this event was generated. - * @return The event generation time. + * \return The event generation time. */ virtual GHOST_TUns64 getTime() { @@ -76,7 +76,7 @@ public: /** * Returns the window this event was generated on, * or NULL if it is a 'system' event. - * @return The generating window. + * \return The generating window. */ virtual GHOST_IWindow *getWindow() { @@ -85,7 +85,7 @@ public: /** * Returns the event data. - * @return The event data. + * \return The event data. */ virtual GHOST_TEventDataPtr getData() { diff --git a/intern/ghost/intern/GHOST_EventButton.h b/intern/ghost/intern/GHOST_EventButton.h index 7ad840bb964..f88fe6e201d 100644 --- a/intern/ghost/intern/GHOST_EventButton.h +++ b/intern/ghost/intern/GHOST_EventButton.h @@ -37,19 +37,19 @@ /** * Mouse button event. - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ class GHOST_EventButton : public GHOST_Event { public: /** * Constructor. - * @param time The time this event was generated. - * @param type The type of this event. - * @param x The x-coordinate of the location the cursor was at at the time of the event. - * @param y The y-coordinate of the location the cursor was at at the time of the event. - * @param buttons The state of the buttons was at at the time of the event. + * \param time The time this event was generated. + * \param type The type of this event. + * \param x The x-coordinate of the location the cursor was at at the time of the event. + * \param y The y-coordinate of the location the cursor was at at the time of the event. + * \param buttons The state of the buttons was at at the time of the event. */ GHOST_EventButton(GHOST_TUns64 time, GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask button) : GHOST_Event(time, type, window) diff --git a/intern/ghost/intern/GHOST_EventCursor.h b/intern/ghost/intern/GHOST_EventCursor.h index 0ff703ba254..1c6f762cd9e 100644 --- a/intern/ghost/intern/GHOST_EventCursor.h +++ b/intern/ghost/intern/GHOST_EventCursor.h @@ -37,18 +37,18 @@ /** * Cursor event. - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ class GHOST_EventCursor : public GHOST_Event { public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of this event. - * @param x The x-coordinate of the location the cursor was at at the time of the event. - * @param y The y-coordinate of the location the cursor was at at the time of the event. + * \param msec The time this event was generated. + * \param type The type of this event. + * \param x The x-coordinate of the location the cursor was at at the time of the event. + * \param y The y-coordinate of the location the cursor was at at the time of the event. */ GHOST_EventCursor(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow *window, GHOST_TInt32 x, GHOST_TInt32 y) : GHOST_Event(msec, type, window) diff --git a/intern/ghost/intern/GHOST_EventDragnDrop.h b/intern/ghost/intern/GHOST_EventDragnDrop.h index 1a05a4b9b68..cef9bb0a34a 100644 --- a/intern/ghost/intern/GHOST_EventDragnDrop.h +++ b/intern/ghost/intern/GHOST_EventDragnDrop.h @@ -72,13 +72,13 @@ class GHOST_EventDragnDrop : public GHOST_Event public: /** * Constructor. - * @param time The time this event was generated. - * @param type The type of this event. - * @param dataType The type of the drop candidate object - * @param window The window where the event occurred - * @param x The x-coordinate of the location the cursor was at at the time of the event. - * @param y The y-coordinate of the location the cursor was at at the time of the event. - * @param data The "content" dropped in the window + * \param time The time this event was generated. + * \param type The type of this event. + * \param dataType The type of the drop candidate object + * \param window The window where the event occurred + * \param x The x-coordinate of the location the cursor was at at the time of the event. + * \param y The y-coordinate of the location the cursor was at at the time of the event. + * \param data The "content" dropped in the window */ GHOST_EventDragnDrop(GHOST_TUns64 time, GHOST_TEventType type, diff --git a/intern/ghost/intern/GHOST_EventKey.h b/intern/ghost/intern/GHOST_EventKey.h index 66817576f0f..54e38c00d05 100644 --- a/intern/ghost/intern/GHOST_EventKey.h +++ b/intern/ghost/intern/GHOST_EventKey.h @@ -37,17 +37,17 @@ /** * Key event. - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ class GHOST_EventKey : public GHOST_Event { public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of key event. - * @param key The key code of the key. + * \param msec The time this event was generated. + * \param type The type of key event. + * \param key The key code of the key. */ GHOST_EventKey(GHOST_TUns64 msec, GHOST_TEventType type, @@ -63,10 +63,10 @@ public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of key event. - * @param key The key code of the key. - * @param ascii The ascii code for the key event. + * \param msec The time this event was generated. + * \param type The type of key event. + * \param key The key code of the key. + * \param ascii The ascii code for the key event. */ GHOST_EventKey(GHOST_TUns64 msec, GHOST_TEventType type, diff --git a/intern/ghost/intern/GHOST_EventManager.cpp b/intern/ghost/intern/GHOST_EventManager.cpp index 33e0afb797a..b8660b3038e 100644 --- a/intern/ghost/intern/GHOST_EventManager.cpp +++ b/intern/ghost/intern/GHOST_EventManager.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 14, 2001 + * \author Maarten Gribnau + * \date May 14, 2001 */ #include "GHOST_EventManager.h" diff --git a/intern/ghost/intern/GHOST_EventManager.h b/intern/ghost/intern/GHOST_EventManager.h index eec00789800..fea8214c7f2 100644 --- a/intern/ghost/intern/GHOST_EventManager.h +++ b/intern/ghost/intern/GHOST_EventManager.h @@ -62,21 +62,21 @@ public: /** * Returns the number of events currently on the stack. - * @return The number of events on the stack. + * \return The number of events on the stack. */ virtual GHOST_TUns32 getNumEvents(); /** * Returns the number of events of a certain type currently on the stack. - * @param type The type of events to be counted. - * @return The number of events on the stack of this type. + * \param type The type of events to be counted. + * \return The number of events on the stack of this type. */ virtual GHOST_TUns32 getNumEvents(GHOST_TEventType type); /** * Return the event at the top of the stack without removal. * Do not delete the event! - * @return The event at the top of the stack. + * \return The event at the top of the stack. */ virtual GHOST_IEvent *peekEvent(); @@ -84,47 +84,47 @@ public: * Pushes an event on the stack. * To dispatch it, call dispatchEvent() or dispatchEvents(). * Do not delete the event! - * @param event The event to push on the stack. + * \param event The event to push on the stack. */ virtual GHOST_TSuccess pushEvent(GHOST_IEvent *event); /** * Dispatches the given event directly, bypassing the event stack. - * @return Indication as to whether any of the consumers handled the event. + * \return Indication as to whether any of the consumers handled the event. */ virtual bool dispatchEvent(GHOST_IEvent *event); /** * Dispatches the event at the back of the stack. * The event will be removed from the stack. - * @return Indication as to whether any of the consumers handled the event. + * \return Indication as to whether any of the consumers handled the event. */ virtual bool dispatchEvent(); /** * Dispatches all the events on the stack. * The event stack will be empty afterwards. - * @return Indication as to whether any of the consumers handled the events. + * \return Indication as to whether any of the consumers handled the events. */ virtual bool dispatchEvents(); /** * Adds a consumer to the list of event consumers. - * @param consumer The consumer added to the list. - * @return Indication as to whether addition has succeeded. + * \param consumer The consumer added to the list. + * \return Indication as to whether addition has succeeded. */ virtual GHOST_TSuccess addConsumer(GHOST_IEventConsumer *consumer); /** * Removes a consumer from the list of event consumers. - * @param consumer The consumer removed from the list. - * @return Indication as to whether removal has succeeded. + * \param consumer The consumer removed from the list. + * \return Indication as to whether removal has succeeded. */ virtual GHOST_TSuccess removeConsumer(GHOST_IEventConsumer *consumer); /** * Removes all events for a window from the stack. - * @param window The window to remove events for. + * \param window The window to remove events for. */ virtual void removeWindowEvents( @@ -135,8 +135,8 @@ public: * Removes all events of a certain type from the stack. * The window parameter is optional. If non-null, the routine will remove * events only associated with that window. - * @param type The type of events to be removed. - * @param window The window to remove the events for. + * \param type The type of events to be removed. + * \param window The window to remove the events for. */ virtual void removeTypeEvents( @@ -148,7 +148,7 @@ protected: /** * Returns the event at the top of the stack and removes it. * Delete the event after use! - * @return The event at the top of the stack. + * \return The event at the top of the stack. */ virtual GHOST_IEvent *popEvent(); diff --git a/intern/ghost/intern/GHOST_EventPrinter.h b/intern/ghost/intern/GHOST_EventPrinter.h index f5fe303f9bc..280d4208413 100644 --- a/intern/ghost/intern/GHOST_EventPrinter.h +++ b/intern/ghost/intern/GHOST_EventPrinter.h @@ -46,16 +46,16 @@ class GHOST_EventPrinter : public GHOST_IEventConsumer public: /** * Prints all the events received to std out. - * @param event The event that can be handled or not. - * @return Indication as to whether the event was handled. + * \param event The event that can be handled or not. + * \return Indication as to whether the event was handled. */ virtual bool processEvent(GHOST_IEvent *event); protected: /** * Converts GHOST key code to a readable string. - * @param key The GHOST key code to convert. - * @param str The GHOST key code converted to a readable string. + * \param key The GHOST key code to convert. + * \param str The GHOST key code converted to a readable string. */ void getKeyString(GHOST_TKey key, char str[32]) const; }; diff --git a/intern/ghost/intern/GHOST_EventString.h b/intern/ghost/intern/GHOST_EventString.h index 8611944197d..391af0f8e2d 100644 --- a/intern/ghost/intern/GHOST_EventString.h +++ b/intern/ghost/intern/GHOST_EventString.h @@ -38,18 +38,18 @@ /** * Generic class for events with string data - * @author Damien Plisson - * @date Feb 1, 2010 + * \author Damien Plisson + * \date Feb 1, 2010 */ class GHOST_EventString : public GHOST_Event { public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of this event. - * @param window The generating window (or NULL if system event). - * @param data_ptr Pointer to the (unformatted) data associated with the event + * \param msec The time this event was generated. + * \param type The type of this event. + * \param window The generating window (or NULL if system event). + * \param data_ptr Pointer to the (unformatted) data associated with the event */ GHOST_EventString(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow *window, GHOST_TEventDataPtr data_ptr) : GHOST_Event(msec, type, window) diff --git a/intern/ghost/intern/GHOST_EventTrackpad.h b/intern/ghost/intern/GHOST_EventTrackpad.h index ab576fb9ec3..dc8b1649754 100644 --- a/intern/ghost/intern/GHOST_EventTrackpad.h +++ b/intern/ghost/intern/GHOST_EventTrackpad.h @@ -44,11 +44,11 @@ class GHOST_EventTrackpad : public GHOST_Event public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of this event. - * @param subtype The subtype of the event. - * @param x The x-delta of the pan event. - * @param y The y-delta of the pan event. + * \param msec The time this event was generated. + * \param type The type of this event. + * \param subtype The subtype of the event. + * \param x The x-delta of the pan event. + * \param y The y-delta of the pan event. */ GHOST_EventTrackpad(GHOST_TUns64 msec, GHOST_IWindow *window, diff --git a/intern/ghost/intern/GHOST_EventWheel.h b/intern/ghost/intern/GHOST_EventWheel.h index 7d6137af575..216f13fda4e 100644 --- a/intern/ghost/intern/GHOST_EventWheel.h +++ b/intern/ghost/intern/GHOST_EventWheel.h @@ -39,17 +39,17 @@ * Mouse wheel event. * The displacement of the mouse wheel is counted in ticks. * A positive value means the wheel is turned away from the user. - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ class GHOST_EventWheel : public GHOST_Event { public: /** * Constructor. - * @param msec The time this event was generated. - * @param type The type of this event. - * @param z The displacement of the mouse wheel. + * \param msec The time this event was generated. + * \param type The type of this event. + * \param z The displacement of the mouse wheel. */ GHOST_EventWheel(GHOST_TUns64 msec, GHOST_IWindow *window, GHOST_TInt32 z) : GHOST_Event(msec, GHOST_kEventWheel, window) diff --git a/intern/ghost/intern/GHOST_ISystem.cpp b/intern/ghost/intern/GHOST_ISystem.cpp index fe1132e7996..f6973caad03 100644 --- a/intern/ghost/intern/GHOST_ISystem.cpp +++ b/intern/ghost/intern/GHOST_ISystem.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 7, 2001 + * \author Maarten Gribnau + * \date May 7, 2001 */ #include "GHOST_ISystem.h" diff --git a/intern/ghost/intern/GHOST_ISystemPaths.cpp b/intern/ghost/intern/GHOST_ISystemPaths.cpp index f84c50770f0..ae9a8e49057 100644 --- a/intern/ghost/intern/GHOST_ISystemPaths.cpp +++ b/intern/ghost/intern/GHOST_ISystemPaths.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 7, 2001 + * \author Maarten Gribnau + * \date May 7, 2001 */ #include "GHOST_ISystemPaths.h" diff --git a/intern/ghost/intern/GHOST_ModifierKeys.cpp b/intern/ghost/intern/GHOST_ModifierKeys.cpp index ffc7a09e4dd..d25d0beb34c 100644 --- a/intern/ghost/intern/GHOST_ModifierKeys.cpp +++ b/intern/ghost/intern/GHOST_ModifierKeys.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 31, 2001 + * \author Maarten Gribnau + * \date May 31, 2001 */ #include "GHOST_ModifierKeys.h" diff --git a/intern/ghost/intern/GHOST_ModifierKeys.h b/intern/ghost/intern/GHOST_ModifierKeys.h index 064af8d2e6c..8189006f602 100644 --- a/intern/ghost/intern/GHOST_ModifierKeys.h +++ b/intern/ghost/intern/GHOST_ModifierKeys.h @@ -38,8 +38,8 @@ /** * Stores the state of modifier keys. * Discriminates between left and right modifier keys. - * @author Maarten Gribnau - * @date May 17, 2001 + * \author Maarten Gribnau + * \date May 17, 2001 */ struct GHOST_ModifierKeys { /** @@ -51,23 +51,23 @@ struct GHOST_ModifierKeys { /** * Returns the modifier key's key code from a modifier key mask. - * @param mask The mask of the modifier key. - * @return The modifier key's key code. + * \param mask The mask of the modifier key. + * \return The modifier key's key code. */ static GHOST_TKey getModifierKeyCode(GHOST_TModifierKeyMask mask); /** * Returns the state of a single modifier key. - * @param mask. Key state to return. - * @return The state of the key (pressed == true). + * \param mask. Key state to return. + * \return The state of the key (pressed == true). */ virtual bool get(GHOST_TModifierKeyMask mask) const; /** * Updates the state of a single modifier key. - * @param mask. Key state to update. - * @param down. The new state of the key. + * \param mask. Key state to update. + * \param down. The new state of the key. */ virtual void set(GHOST_TModifierKeyMask mask, bool down); @@ -78,8 +78,8 @@ struct GHOST_ModifierKeys { /** * Determines whether to modifier key states are equal. - * @param keys. The modifier key state to compare to. - * @return Indication of equality. + * \param keys. The modifier key state to compare to. + * \return Indication of equality. */ virtual bool equals(const GHOST_ModifierKeys& keys) const; diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index de475c79f43..070bf914dda 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -55,9 +55,9 @@ class GHOST_NDOFManager; * interface. * GHOST_System is an abstract class because not all methods of GHOST_ISystem * are implemented. - * @see GHOST_ISystem. - * @author Maarten Gribnau - * @date May 7, 2001 + * \see GHOST_ISystem. + * \author Maarten Gribnau + * \date May 7, 2001 */ class GHOST_System : public GHOST_ISystem { @@ -83,7 +83,7 @@ public: * Returns the system time. * Returns the number of milliseconds since the start of the system process. * Based on ANSI clock() routine. - * @return The number of milliseconds. + * \return The number of milliseconds. */ virtual GHOST_TUns64 getMilliSeconds() const; @@ -91,11 +91,11 @@ public: * Installs a timer. * Note that, on most operating systems, messages need to be processed in order * for the timer callbacks to be invoked. - * @param delay The time to wait for the first call to the timerProc (in milliseconds) - * @param interval The interval between calls to the timerProc - * @param timerProc The callback invoked when the interval expires, - * @param userData Placeholder for user data. - * @return A timer task (0 if timer task installation failed). + * \param delay The time to wait for the first call to the timerProc (in milliseconds) + * \param interval The interval between calls to the timerProc + * \param timerProc The callback invoked when the interval expires, + * \param userData Placeholder for user data. + * \return A timer task (0 if timer task installation failed). */ virtual GHOST_ITimerTask *installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, @@ -104,8 +104,8 @@ public: /** * Removes a timer. - * @param timerTask Timer task to be removed. - * @return Indication of success. + * \param timerTask Timer task to be removed. + * \return Indication of success. */ virtual GHOST_TSuccess removeTimer(GHOST_ITimerTask *timerTask); @@ -123,47 +123,47 @@ public: /** * Dispose a window. - * @param window Pointer to the window to be disposed. - * @return Indication of success. + * \param window Pointer to the window to be disposed. + * \return Indication of success. */ virtual GHOST_TSuccess disposeWindow(GHOST_IWindow *window); /** * Returns whether a window is valid. - * @param window Pointer to the window to be checked. - * @return Indication of validity. + * \param window Pointer to the window to be checked. + * \return Indication of validity. */ virtual bool validWindow(GHOST_IWindow *window); /** * Begins full screen mode. - * @param setting The new setting of the display. - * @param window Window displayed in full screen. - * @param stereoVisual Stereo visual for quad buffered stereo. + * \param setting The new setting of the display. + * \param window Window displayed in full screen. + * \param stereoVisual Stereo visual for quad buffered stereo. * This window is invalid after full screen has been ended. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow **window, const bool stereoVisual, const GHOST_TUns16 numOfAASamples = 0); /** * Updates the resolution while in fullscreen mode. - * @param setting The new setting of the display. - * @param window Window displayed in full screen. + * \param setting The new setting of the display. + * \param window Window displayed in full screen. * - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow **window); /** * Ends full screen mode. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess endFullScreen(void); /** * Returns current full screen mode status. - * @return The current status. + * \return The current status. */ virtual bool getFullScreen(void); @@ -183,21 +183,21 @@ public: /** * Dispatches all the events on the stack. * The event stack will be empty afterwards. - * @return Indication as to whether any of the consumers handled the events. + * \return Indication as to whether any of the consumers handled the events. */ virtual bool dispatchEvents(); /** * Adds the given event consumer to our list. - * @param consumer The event consumer to add. - * @return Indication of success. + * \param consumer The event consumer to add. + * \return Indication of success. */ virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer *consumer); /** * Remove the given event consumer to our list. - * @param consumer The event consumer to remove. - * @return Indication of success. + * \param consumer The event consumer to remove. + * \return Indication of success. */ virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer *consumer); @@ -216,17 +216,17 @@ public: /** * Returns the state of a modifier key (ouside the message queue). - * @param mask The modifier key state to retrieve. - * @param isDown The state of a modifier key (true == pressed). - * @return Indication of success. + * \param mask The modifier key state to retrieve. + * \param isDown The state of a modifier key (true == pressed). + * \return Indication of success. */ virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const; /** * Returns the state of a mouse button (ouside the message queue). - * @param mask The button state to retrieve. - * @param isDown Button state. - * @return Indication of success. + * \param mask The button state to retrieve. + * \param isDown Button state. + * \return Indication of success. */ virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const; @@ -238,62 +238,62 @@ public: * Pushes an event on the stack. * To dispatch it, call dispatchEvent() or dispatchEvents(). * Do not delete the event! - * @param event The event to push on the stack. + * \param event The event to push on the stack. */ virtual GHOST_TSuccess pushEvent(GHOST_IEvent *event); /** * Returns the timer manager. - * @return The timer manager. + * \return The timer manager. */ inline virtual GHOST_TimerManager *getTimerManager() const; /** * Returns a pointer to our event manager. - * @return A pointer to our event manager. + * \return A pointer to our event manager. */ virtual inline GHOST_EventManager *getEventManager() const; /** * Returns a pointer to our window manager. - * @return A pointer to our window manager. + * \return A pointer to our window manager. */ virtual inline GHOST_WindowManager *getWindowManager() const; #ifdef WITH_INPUT_NDOF /** * Returns a pointer to our n-degree of freedeom manager. - * @return A pointer to our n-degree of freedeom manager. + * \return A pointer to our n-degree of freedeom manager. */ virtual inline GHOST_NDOFManager *getNDOFManager() const; #endif /** * Returns the state of all modifier keys. - * @param keys The state of all modifier keys (true == pressed). - * @return Indication of success. + * \param keys The state of all modifier keys (true == pressed). + * \return Indication of success. */ virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const = 0; /** * Returns the state of the mouse buttons (ouside the message queue). - * @param buttons The state of the buttons. - * @return Indication of success. + * \param buttons The state of the buttons. + * \return Indication of success. */ virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const = 0; /** * Returns the selection buffer - * @param selection Only used on X11 - * @return Returns the clipboard data + * \param selection Only used on X11 + * \return Returns the clipboard data * */ virtual GHOST_TUns8 *getClipboard(bool selection) const = 0; /** * Put data to the Clipboard - * @param buffer The buffer to copy to the clipboard - * @param selection The clipboard to copy too only used on X11 + * \param buffer The buffer to copy to the clipboard + * \param selection The clipboard to copy too only used on X11 */ virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0; @@ -308,20 +308,20 @@ public: protected: /** * Initialize the system. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess init(); /** * Shut the system down. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess exit(); /** * Creates a fullscreen window. - * @param window The window created. - * @return Indication of success. + * \param window The window created. + * \return Indication of success. */ virtual GHOST_TSuccess createFullScreenWindow(GHOST_Window **window, const bool stereoVisual, const GHOST_TUns16 numOfAASamples = 0); diff --git a/intern/ghost/intern/GHOST_SystemCarbon.cpp b/intern/ghost/intern/GHOST_SystemCarbon.cpp index ffb8388543b..bb68ce8889c 100644 --- a/intern/ghost/intern/GHOST_SystemCarbon.cpp +++ b/intern/ghost/intern/GHOST_SystemCarbon.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 7, 2001 + * \author Maarten Gribnau + * \date May 7, 2001 */ #include <Carbon/Carbon.h> @@ -990,7 +990,7 @@ bool GHOST_SystemCarbon::handleMouseDown(EventRef event) /* * The DragWindow() routine creates a lot of kEventWindowBoundsChanged * events. By setting m_ignoreWindowSizedMessages these are suppressed. - * @see GHOST_SystemCarbon::handleWindowEvent(EventRef event) + * \see GHOST_SystemCarbon::handleWindowEvent(EventRef event) */ /* even worse: scale window also generates a load of events, and nothing * is handled (read: client's event proc called) until you release mouse (ton) */ diff --git a/intern/ghost/intern/GHOST_SystemCarbon.h b/intern/ghost/intern/GHOST_SystemCarbon.h index 2415c57e094..61e5a086a0f 100644 --- a/intern/ghost/intern/GHOST_SystemCarbon.h +++ b/intern/ghost/intern/GHOST_SystemCarbon.h @@ -48,9 +48,9 @@ class GHOST_EventWindow; /** * OSX/Carbon Implementation of GHOST_System class. - * @see GHOST_System. - * @author Maarten Gribnau - * @date May 21, 2001 + * \see GHOST_System. + * \author Maarten Gribnau + * \date May 21, 2001 */ class GHOST_SystemCarbon : public GHOST_System { public: @@ -72,7 +72,7 @@ public: * Returns the system time. * Returns the number of milliseconds since the start of the system process. * Based on ANSI clock() routine. - * @return The number of milliseconds. + * \return The number of milliseconds. */ virtual GHOST_TUns64 getMilliSeconds() const; @@ -82,13 +82,13 @@ public: /** * Returns the number of displays on this system. - * @return The number of displays. + * \return The number of displays. */ virtual GHOST_TUns8 getNumDisplays() const; /** * Returns the dimensions of the main display on this system. - * @return The dimension of the main display. + * \return The dimension of the main display. */ virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const; @@ -96,15 +96,15 @@ public: * Create a new window. * The new window is added to the list of windows managed. * Never explicitly delete the window, use disposeWindow() instead. - * @param title The name of the window (displayed in the title bar of the window if the OS supports it). - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state of the window when opened. - * @param type The type of drawing context installed in this window. - * @param parentWindow Parent (embedder) window - * @return The new window (or 0 if creation failed). + * \param title The name of the window (displayed in the title bar of the window if the OS supports it). + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state of the window when opened. + * \param type The type of drawing context installed in this window. + * \param parentWindow Parent (embedder) window + * \return The new window (or 0 if creation failed). */ virtual GHOST_IWindow *createWindow( const STR_String& title, @@ -133,8 +133,8 @@ public: /** * Gets events from the system and stores them in the queue. - * @param waitForEvent Flag to wait for an event (or return immediately). - * @return Indication of the presence of events. + * \param waitForEvent Flag to wait for an event (or return immediately). + * \return Indication of the presence of events. */ virtual bool processEvents(bool waitForEvent); @@ -144,17 +144,17 @@ public: /** * Returns the current location of the cursor (location in screen coordinates) - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const; /** * Updates the location of the cursor (location in screen coordinates). - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y); @@ -164,34 +164,34 @@ public: /** * Returns the state of all modifier keys. - * @param keys The state of all modifier keys (true == pressed). - * @return Indication of success. + * \param keys The state of all modifier keys (true == pressed). + * \return Indication of success. */ virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const; /** * Returns the state of the mouse buttons (ouside the message queue). - * @param buttons The state of the buttons. - * @return Indication of success. + * \param buttons The state of the buttons. + * \return Indication of success. */ virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const; /** * Returns Clipboard data - * @param selection Indicate which buffer to return - * @return Returns the selected buffer + * \param selection Indicate which buffer to return + * \return Returns the selected buffer */ virtual GHOST_TUns8 *getClipboard(bool selection) const; /** * Puts buffer to system clipboard - * @param buffer The buffer to be copied - * @param selection Indicates which buffer to copy too, only used on X11 + * \param buffer The buffer to be copied + * \param selection Indicates which buffer to copy too, only used on X11 */ virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const; /** - * @see GHOST_ISystem + * \see GHOST_ISystem */ int toggleConsole(int action) { return 0; @@ -201,55 +201,55 @@ protected: /** * Initializes the system. * For now, it justs registers the window class (WNDCLASS). - * @return A success value. + * \return A success value. */ virtual GHOST_TSuccess init(); /** * Closes the system down. - * @return A success value. + * \return A success value. */ virtual GHOST_TSuccess exit(); /** * Handles a tablet event. - * @param event A Mac event. - * @return Indication whether the event was handled. + * \param event A Mac event. + * \return Indication whether the event was handled. */ OSStatus handleTabletEvent(EventRef event); /** * Handles a mouse event. - * @param event A Mac event. - * @return Indication whether the event was handled. + * \param event A Mac event. + * \return Indication whether the event was handled. */ OSStatus handleMouseEvent(EventRef event); /** * Handles a key event. - * @param event A Mac event. - * @return Indication whether the event was handled. + * \param event A Mac event. + * \return Indication whether the event was handled. */ OSStatus handleKeyEvent(EventRef event); /** * Handles a window event. - * @param event A Mac event. - * @return Indication whether the event was handled. + * \param event A Mac event. + * \return Indication whether the event was handled. */ OSStatus handleWindowEvent(EventRef event); /** * Handles all basic Mac application stuff for a mouse down event. - * @param event A Mac event. - * @return Indication whether the event was handled. + * \param event A Mac event. + * \return Indication whether the event was handled. */ bool handleMouseDown(EventRef event); /** * Handles a Mac menu command. - * @param menuResult A Mac menu/item identifier. - * @return Indication whether the event was handled. + * \param menuResult A Mac menu/item identifier. + * \return Indication whether the event was handled. */ bool handleMenuCommand(GHOST_TInt32 menuResult); @@ -270,7 +270,7 @@ protected: /** * Callback for Mac Timer tasks that expire. - * @param tmTask Pointer to the timer task that expired. + * \param tmTask Pointer to the timer task that expired. */ //static void s_timerCallback(TMTaskPtr tmTask); diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h index cb4e9fe3c99..08f982ffd3f 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -69,7 +69,7 @@ public: * Returns the system time. * Returns the number of milliseconds since the start of the system process. * Based on ANSI clock() routine. - * @return The number of milliseconds. + * \return The number of milliseconds. */ virtual GHOST_TUns64 getMilliSeconds() const; @@ -79,13 +79,13 @@ public: /** * Returns the number of displays on this system. - * @return The number of displays. + * \return The number of displays. */ virtual GHOST_TUns8 getNumDisplays() const; /** * Returns the dimensions of the main display on this system. - * @return The dimension of the main display. + * \return The dimension of the main display. */ virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const; @@ -93,17 +93,17 @@ public: * Create a new window. * The new window is added to the list of windows managed. * Never explicitly delete the window, use disposeWindow() instead. - * @param title The name of the window (displayed in the title bar of the window if the OS supports it). - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state of the window when opened. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) - * @param parentWindow Parent (embedder) window - * @return The new window (or 0 if creation failed). + * \param title The name of the window (displayed in the title bar of the window if the OS supports it). + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state of the window when opened. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) + * \param parentWindow Parent (embedder) window + * \return The new window (or 0 if creation failed). */ virtual GHOST_IWindow *createWindow( const STR_String& title, @@ -124,8 +124,8 @@ public: /** * Gets events from the system and stores them in the queue. - * @param waitForEvent Flag to wait for an event (or return immediately). - * @return Indication of the presence of events. + * \param waitForEvent Flag to wait for an event (or return immediately). + * \return Indication of the presence of events. */ virtual bool processEvents(bool waitForEvent); @@ -143,12 +143,12 @@ public: /** * Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass - * @param eventType The type of drag'n'drop event - * @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image) - * @param mouseX x mouse coordinate (in cocoa base window coordinates) - * @param mouseY y mouse coordinate - * @param window The window on which the event occurred - * @return Indication whether the event was handled. + * \param eventType The type of drag'n'drop event + * \param draggedObjectType The type object concerned (currently array of file names, string, TIFF image) + * \param mouseX x mouse coordinate (in cocoa base window coordinates) + * \param mouseY y mouse coordinate + * \param window The window on which the event occurred + * \return Indication whether the event was handled. */ GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, GHOST_WindowCocoa *window, int mouseX, int mouseY, void *data); @@ -159,17 +159,17 @@ public: /** * Returns the current location of the cursor (location in screen coordinates) - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const; /** * Updates the location of the cursor (location in screen coordinates). - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y); @@ -179,43 +179,43 @@ public: /** * Returns the state of all modifier keys. - * @param keys The state of all modifier keys (true == pressed). - * @return Indication of success. + * \param keys The state of all modifier keys (true == pressed). + * \return Indication of success. */ virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const; /** * Returns the state of the mouse buttons (ouside the message queue). - * @param buttons The state of the buttons. - * @return Indication of success. + * \param buttons The state of the buttons. + * \return Indication of success. */ virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const; /** * Returns Clipboard data - * @param selection Indicate which buffer to return - * @return Returns the selected buffer + * \param selection Indicate which buffer to return + * \return Returns the selected buffer */ virtual GHOST_TUns8 *getClipboard(bool selection) const; /** * Puts buffer to system clipboard - * @param buffer The buffer to be copied - * @param selection Indicates which buffer to copy too, only used on X11 + * \param buffer The buffer to be copied + * \param selection Indicates which buffer to copy too, only used on X11 */ virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const; /** * Handles a window event. Called by GHOST_WindowCocoa window delegate - * @param eventType The type of window event - * @param window The window on which the event occurred - * @return Indication whether the event was handled. + * \param eventType The type of window event + * \param window The window on which the event occurred + * \return Indication whether the event was handled. */ GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa *window); /** * Handles the Cocoa event telling the application has become active (again) - * @return Indication whether the event was handled. + * \return Indication whether the event was handled. */ GHOST_TSuccess handleApplicationBecomeActiveEvent(); @@ -225,7 +225,7 @@ public: void notifyExternalEventProcessed(); /** - * @see GHOST_ISystem + * \see GHOST_ISystem */ int toggleConsole(int action) { return 0; @@ -236,40 +236,40 @@ protected: /** * Initializes the system. * For now, it justs registers the window class (WNDCLASS). - * @return A success value. + * \return A success value. */ virtual GHOST_TSuccess init(); /** * Handles a tablet event. - * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) - * @param eventType The type of the event. + * \param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) + * \param eventType The type of the event. * It needs to be passed separately as it can be either directly in the event type, * or as a subtype if combined with a mouse button event. - * @return Indication whether the event was handled. + * \return Indication whether the event was handled. */ GHOST_TSuccess handleTabletEvent(void *eventPtr, short eventType); bool handleTabletEvent(void *eventPtr); /** * Handles a mouse event. - * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) - * @return Indication whether the event was handled. + * \param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) + * \return Indication whether the event was handled. */ GHOST_TSuccess handleMouseEvent(void *eventPtr); /** * Handles a key event. - * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) - * @return Indication whether the event was handled. + * \param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) + * \return Indication whether the event was handled. */ GHOST_TSuccess handleKeyEvent(void *eventPtr); /** * Performs the actual cursor position update (location in screen coordinates). - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ GHOST_TSuccess setMouseCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y); diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 1bffbc8eb85..7bc40287dc3 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -228,9 +228,9 @@ static GHOST_TButtonMask convertButton(int button) /** * Converts Mac rawkey codes (same for Cocoa & Carbon) * into GHOST key codes - * @param rawCode The raw physical key code - * @param recvChar the character ignoring modifiers (except for shift) - * @return Ghost key code + * \param rawCode The raw physical key code + * \param recvChar the character ignoring modifiers (except for shift) + * \return Ghost key code */ static GHOST_TKey convertKey(int rawCode, unichar recvChar, UInt16 keyAction) { @@ -594,9 +594,8 @@ GHOST_SystemCocoa::~GHOST_SystemCocoa() GHOST_TSuccess GHOST_SystemCocoa::init() { - - GHOST_TSuccess success = GHOST_System::init(); - if (success) { + GHOST_TSuccess success = GHOST_System::init(); + if (success) { #ifdef WITH_INPUT_NDOF m_ndofManager = new GHOST_NDOFManagerCocoa(*this); @@ -676,8 +675,8 @@ GHOST_TSuccess GHOST_SystemCocoa::init() [NSApp finishLaunching]; [pool drain]; - } - return success; + } + return success; } @@ -739,7 +738,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow( const GHOST_TEmbedderWindowID parentWindow ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; GHOST_IWindow* window = 0; //Get the available rect for including window contents @@ -755,45 +754,44 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow( window = new GHOST_WindowCocoa (this, title, left, bottom, width, height, state, type, stereoVisual, numOfAASamples); - if (window) { - if (window->getValid()) { - // Store the pointer to the window - GHOST_ASSERT(m_windowManager, "m_windowManager not initialized"); - m_windowManager->addWindow(window); - m_windowManager->setActiveWindow(window); + if (window) { + if (window->getValid()) { + // Store the pointer to the window + GHOST_ASSERT(m_windowManager, "m_windowManager not initialized"); + m_windowManager->addWindow(window); + m_windowManager->setActiveWindow(window); //Need to tell window manager the new window is the active one (Cocoa does not send the event activate upon window creation) - pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window)); + pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window)); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); - - } - else { + } + else { GHOST_PRINT("GHOST_SystemCocoa::createWindow(): window invalid\n"); - delete window; - window = 0; - } - } + delete window; + window = 0; + } + } else { GHOST_PRINT("GHOST_SystemCocoa::createWindow(): could not create window\n"); } [pool drain]; - return window; + return window; } /** - * @note : returns coordinates in Cocoa screen coordinates + * \note : returns coordinates in Cocoa screen coordinates */ GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const { - NSPoint mouseLoc = [NSEvent mouseLocation]; + NSPoint mouseLoc = [NSEvent mouseLocation]; - // Returns the mouse location in screen coordinates - x = (GHOST_TInt32)mouseLoc.x; - y = (GHOST_TInt32)mouseLoc.y; - return GHOST_kSuccess; + // Returns the mouse location in screen coordinates + x = (GHOST_TInt32)mouseLoc.x; + y = (GHOST_TInt32)mouseLoc.y; + return GHOST_kSuccess; } /** - * @note : expect Cocoa screen coordinates + * \note : expect Cocoa screen coordinates */ GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) { @@ -833,7 +831,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(GHOST_TInt32 x, GHOST_T CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf)); [pool drain]; - return GHOST_kSuccess; + return GHOST_kSuccess; } @@ -844,18 +842,18 @@ GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) cons keys.set(GHOST_kModifierKeyLeftShift, (m_modifierMask & NSShiftKeyMask) ? true : false); keys.set(GHOST_kModifierKeyLeftControl, (m_modifierMask & NSControlKeyMask) ? true : false); - return GHOST_kSuccess; + return GHOST_kSuccess; } GHOST_TSuccess GHOST_SystemCocoa::getButtons(GHOST_Buttons& buttons) const { buttons.clear(); - buttons.set(GHOST_kButtonMaskLeft, m_pressedMouseButtons & GHOST_kButtonMaskLeft); + buttons.set(GHOST_kButtonMaskLeft, m_pressedMouseButtons & GHOST_kButtonMaskLeft); buttons.set(GHOST_kButtonMaskRight, m_pressedMouseButtons & GHOST_kButtonMaskRight); buttons.set(GHOST_kButtonMaskMiddle, m_pressedMouseButtons & GHOST_kButtonMaskMiddle); buttons.set(GHOST_kButtonMaskButton4, m_pressedMouseButtons & GHOST_kButtonMaskButton4); buttons.set(GHOST_kButtonMaskButton5, m_pressedMouseButtons & GHOST_kButtonMaskButton5); - return GHOST_kSuccess; + return GHOST_kSuccess; } @@ -976,7 +974,7 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent) m_ignoreWindowSizedMessages = false; - return anyProcessed; + return anyProcessed; } //Note: called from NSApplication delegate @@ -1442,7 +1440,7 @@ bool GHOST_SystemCocoa::handleTabletEvent(void *eventPtr) GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) { NSEvent *event = (NSEvent *)eventPtr; - GHOST_WindowCocoa* window; + GHOST_WindowCocoa* window; window = (GHOST_WindowCocoa*)m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]); if (!window) { @@ -1450,8 +1448,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) return GHOST_kFailure; } - switch ([event type]) - { + switch ([event type]) { case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: @@ -1459,7 +1456,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) //Handle tablet events combined with mouse events handleTabletEvent(event); break; - + case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: diff --git a/intern/ghost/intern/GHOST_SystemPaths.h b/intern/ghost/intern/GHOST_SystemPaths.h index fe0fae71955..53cad347293 100644 --- a/intern/ghost/intern/GHOST_SystemPaths.h +++ b/intern/ghost/intern/GHOST_SystemPaths.h @@ -53,20 +53,20 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). + * \return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const = 0; /** * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/.blender/). + * \return Unsigned char string pointing to user dir (eg ~/.blender/). */ virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const = 0; /** * Determine the directory of the current binary - * @return Unsigned char string pointing to the binary dir + * \return Unsigned char string pointing to the binary dir */ virtual const GHOST_TUns8 *getBinaryDir() const = 0; diff --git a/intern/ghost/intern/GHOST_SystemPathsCarbon.h b/intern/ghost/intern/GHOST_SystemPathsCarbon.h index 6a94c1d6606..9d9a3a22564 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCarbon.h +++ b/intern/ghost/intern/GHOST_SystemPathsCarbon.h @@ -42,9 +42,9 @@ /** * OSX/Carbon Implementation of GHOST_SystemPaths class. - * @see GHOST_System. - * @author Andrea Weikert - * @date Aug 1, 2010 + * \see GHOST_System. + * \author Andrea Weikert + * \date Aug 1, 2010 */ class GHOST_SystemPathsCarbon : public GHOST_SystemPaths { public: @@ -61,20 +61,20 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). + * \return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/.blender/). + * \return Unsigned char string pointing to user dir (eg ~/.blender/). */ virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary - * @return Unsigned char string pointing to the binary dir + * \return Unsigned char string pointing to the binary dir */ virtual const GHOST_TUns8 *getBinaryDir() const; diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.h b/intern/ghost/intern/GHOST_SystemPathsCocoa.h index ad44396c3ff..cd8d161ff9c 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCocoa.h +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.h @@ -55,20 +55,20 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). + * \return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/.blender/). + * \return Unsigned char string pointing to user dir (eg ~/.blender/). */ virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary - * @return Unsigned char string pointing to the binary dir + * \return Unsigned char string pointing to the binary dir */ virtual const GHOST_TUns8 *getBinaryDir() const; diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.h b/intern/ghost/intern/GHOST_SystemPathsWin32.h index 3a243f8be16..c074a7902b8 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.h +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.h @@ -46,9 +46,9 @@ /** * WIN32 Implementation of GHOST_SystemPaths class. - * @see GHOST_SystemPaths. - * @author Andrea Weikert - * @date August 1, 2010 + * \see GHOST_SystemPaths. + * \author Andrea Weikert + * \date August 1, 2010 */ class GHOST_SystemPathsWin32 : public GHOST_SystemPaths { public: @@ -65,20 +65,20 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/). + * \return Unsigned char string pointing to system dir (eg /usr/share/). */ const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/). + * \return Unsigned char string pointing to user dir (eg ~/). */ const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary - * @return Unsigned char string pointing to the binary dir + * \return Unsigned char string pointing to the binary dir */ const GHOST_TUns8 *getBinaryDir() const; diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.h b/intern/ghost/intern/GHOST_SystemPathsX11.h index db6d5a6c6ea..1b5710e0f57 100644 --- a/intern/ghost/intern/GHOST_SystemPathsX11.h +++ b/intern/ghost/intern/GHOST_SystemPathsX11.h @@ -53,20 +53,20 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use * "unpack and run" path, then look for properly installed path, including versioning. - * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). + * \return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/.blender/). + * \return Unsigned char string pointing to user dir (eg ~/.blender/). */ const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary - * @return Unsigned char string pointing to the binary dir + * \return Unsigned char string pointing to the binary dir */ const GHOST_TUns8 *getBinaryDir() const; diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index 6c201c24c3d..52ebaf02404 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -724,7 +724,7 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINP int r; GetKeyboardState((PBYTE)state); - if (r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout)) { + if ((r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout))) { if ((r > 0 && r < 3)) { utf16[r] = 0; conv_utf_16_to_8(utf16, utf8_char, 6); diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h index f63ad38d0cc..6a756d35872 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.h +++ b/intern/ghost/intern/GHOST_SystemWin32.h @@ -57,9 +57,9 @@ class GHOST_EventDragnDrop; /** * WIN32 Implementation of GHOST_System class. - * @see GHOST_System. - * @author Maarten Gribnau - * @date May 10, 2001 + * \see GHOST_System. + * \author Maarten Gribnau + * \date May 10, 2001 */ class GHOST_SystemWin32 : public GHOST_System { public: @@ -81,7 +81,7 @@ public: * Returns the system time. * Returns the number of milliseconds since the start of the system process. * This overloaded method uses the high frequency timer if available. - * @return The number of milliseconds. + * \return The number of milliseconds. */ virtual GHOST_TUns64 getMilliSeconds() const; @@ -91,13 +91,13 @@ public: /** * Returns the number of displays on this system. - * @return The number of displays. + * \return The number of displays. */ virtual GHOST_TUns8 getNumDisplays() const; /** * Returns the dimensions of the main display on this system. - * @return The dimension of the main display. + * \return The dimension of the main display. */ virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const; @@ -105,17 +105,17 @@ public: * Create a new window. * The new window is added to the list of windows managed. * Never explicitly delete the window, use disposeWindow() instead. - * @param title The name of the window (displayed in the title bar of the window if the OS supports it). - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state of the window when opened. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) - * @param parentWindow Parent (embedder) window - * @return The new window (or 0 if creation failed). + * \param title The name of the window (displayed in the title bar of the window if the OS supports it). + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state of the window when opened. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) + * \param parentWindow Parent (embedder) window + * \return The new window (or 0 if creation failed). */ virtual GHOST_IWindow *createWindow( const STR_String& title, @@ -131,8 +131,8 @@ public: /** * Gets events from the system and stores them in the queue. - * @param waitForEvent Flag to wait for an event (or return immediately). - * @return Indication of the presence of events. + * \param waitForEvent Flag to wait for an event (or return immediately). + * \return Indication of the presence of events. */ virtual bool processEvents(bool waitForEvent); @@ -143,17 +143,17 @@ public: /** * Returns the current location of the cursor (location in screen coordinates) - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const; /** * Updates the location of the cursor (location in screen coordinates). - * @param x The x-coordinate of the cursor. - * @param y The y-coordinate of the cursor. - * @return Indication of success. + * \param x The x-coordinate of the cursor. + * \param y The y-coordinate of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y); @@ -163,41 +163,41 @@ public: /** * Returns the state of all modifier keys. - * @param keys The state of all modifier keys (true == pressed). - * @return Indication of success. + * \param keys The state of all modifier keys (true == pressed). + * \return Indication of success. */ virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const; /** * Returns the state of the mouse buttons (ouside the message queue). - * @param buttons The state of the buttons. - * @return Indication of success. + * \param buttons The state of the buttons. + * \return Indication of success. */ virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const; /** * Returns unsinged char from CUT_BUFFER0 - * @param selection Used by X11 only - * @return Returns the Clipboard + * \param selection Used by X11 only + * \return Returns the Clipboard */ virtual GHOST_TUns8 *getClipboard(bool selection) const; /** * Puts buffer to system clipboard - * @param selection Used by X11 only - * @return No return + * \param selection Used by X11 only + * \return No return */ virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const; /** * Creates a drag'n'drop event and pushes it immediately onto the event queue. * Called by GHOST_DropTargetWin32 class. - * @param eventType The type of drag'n'drop event - * @param draggedObjectType The type object concerned (currently array of file names, string, ?bitmap) - * @param mouseX x mouse coordinate (in window coordinates) - * @param mouseY y mouse coordinate - * @param window The window on which the event occurred - * @return Indication whether the event was handled. + * \param eventType The type of drag'n'drop event + * \param draggedObjectType The type object concerned (currently array of file names, string, ?bitmap) + * \param mouseX x mouse coordinate (in window coordinates) + * \param mouseY y mouse coordinate + * \param window The window on which the event occurred + * \return Indication whether the event was handled. */ static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, GHOST_IWindow *window, int mouseX, int mouseY, void *data); @@ -211,33 +211,33 @@ protected: /** * Initializes the system. * For now, it justs registers the window class (WNDCLASS). - * @return A success value. + * \return A success value. */ virtual GHOST_TSuccess init(); /** * Closes the system down. - * @return A success value. + * \return A success value. */ virtual GHOST_TSuccess exit(); /** * Converts raw WIN32 key codes from the wndproc to GHOST keys. - * @param window-> The window for this handling - * @param vKey The virtual key from hardKey - * @param ScanCode The ScanCode of pressed key (simular to PS/2 Set 1) - * @param extend Flag if key is not primerly (left or right) - * @return The GHOST key (GHOST_kKeyUnknown if no match). + * \param window-> The window for this handling + * \param vKey The virtual key from hardKey + * \param ScanCode The ScanCode of pressed key (simular to PS/2 Set 1) + * \param extend Flag if key is not primerly (left or right) + * \return The GHOST key (GHOST_kKeyUnknown if no match). */ virtual GHOST_TKey convertKey(GHOST_IWindow *window, short vKey, short ScanCode, short extend) const; /** * Catches raw WIN32 key codes from WM_INPUT in the wndproc. - * @param window The window for this handling - * @param raw RawInput structure with detailed info about the key event - * @param keyDown Pointer flag that specify if a key is down - * @param vk Pointer to virtual key - * @return The GHOST key (GHOST_kKeyUnknown if no match). + * \param window The window for this handling + * \param raw RawInput structure with detailed info about the key event + * \param keyDown Pointer flag that specify if a key is down + * \param vk Pointer to virtual key + * \return The GHOST key (GHOST_kKeyUnknown if no match). */ virtual GHOST_TKey hardKey(GHOST_IWindow *window, RAWINPUT const& raw, int *keyDown, char *vk); @@ -246,32 +246,32 @@ protected: * With the modifier keys, we want to distinguish left and right keys. * Sometimes this is not possible (Windows ME for instance). Then, we want * events generated for both keys. - * @param window The window receiving the event (the active window). + * \param window The window receiving the event (the active window). */ GHOST_EventKey *processModifierKeys(GHOST_IWindow *window); /** * Creates mouse button event. - * @param type The type of event to create. - * @param window The window receiving the event (the active window). - * @param mask The button mask of this event. - * @return The event created. + * \param type The type of event to create. + * \param window The window receiving the event (the active window). + * \param mask The button mask of this event. + * \return The event created. */ static GHOST_EventButton *processButtonEvent(GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask mask); /** * Creates cursor event. - * @param type The type of event to create. - * @param window The window receiving the event (the active window). - * @return The event created. + * \param type The type of event to create. + * \param window The window receiving the event (the active window). + * \return The event created. */ static GHOST_EventCursor *processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow); /** * Creates a mouse wheel event. - * @param window The window receiving the event (the active window). - * @param wParam The wParam from the wndproc - * @param lParam The lParam from the wndproc + * \param window The window receiving the event (the active window). + * \param wParam The wParam from the wndproc + * \param lParam The lParam from the wndproc */ static GHOST_EventWheel *processWheelEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam); @@ -279,31 +279,31 @@ protected: * Creates a key event and updates the key data stored locally (m_modifierKeys). * In most cases this is a straightforward conversion of key codes. * For the modifier keys however, we want to distinguish left and right keys. - * @param window The window receiving the event (the active window). - * @param raw RawInput structure with detailed info about the key event + * \param window The window receiving the event (the active window). + * \param raw RawInput structure with detailed info about the key event */ static GHOST_EventKey *processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw); /** * Process special keys (VK_OEM_*), to see if current key layout * gives us anything special, like ! on french AZERTY. - * @param window The window receiving the event (the active window). - * @param vKey The virtual key from hardKey - * @param ScanCode The ScanCode of pressed key (simular to PS/2 Set 1) + * \param window The window receiving the event (the active window). + * \param vKey The virtual key from hardKey + * \param ScanCode The ScanCode of pressed key (simular to PS/2 Set 1) */ virtual GHOST_TKey processSpecialKey(GHOST_IWindow *window, short vKey, short scanCode) const; /** * Creates a window event. - * @param type The type of event to create. - * @param window The window receiving the event (the active window). - * @return The event created. + * \param type The type of event to create. + * \param window The window receiving the event (the active window). + * \return The event created. */ static GHOST_Event *processWindowEvent(GHOST_TEventType type, GHOST_IWindow *window); /** * Handles minimum window size. - * @param minmax The MINMAXINFO structure. + * \param minmax The MINMAXINFO structure. */ static void processMinMaxInfo(MINMAXINFO *minmax); @@ -312,22 +312,22 @@ protected: * Handles Motion and Button events from a SpaceNavigator or related device. * Instead of returning an event object, this function communicates directly * with the GHOST_NDOFManager. - * @param raw RawInput structure with detailed info about the NDOF event - * @return Whether an event was generated and sent. + * \param raw RawInput structure with detailed info about the NDOF event + * \return Whether an event was generated and sent. */ bool processNDOF(RAWINPUT const& raw); #endif /** * Returns the local state of the modifier keys (from the message queue). - * @param keys The state of the keys. + * \param keys The state of the keys. */ inline virtual void retrieveModifierKeys(GHOST_ModifierKeys& keys) const; /** * Stores the state of the modifier keys locally. * For internal use only! - * @param keys The new state of the modifier keys. + * param keys The new state of the modifier keys. */ inline virtual void storeModifierKeys(const GHOST_ModifierKeys& keys); @@ -343,12 +343,13 @@ protected: /** * Toggles console - * @action 0 - Hides - * 1 - Shows - * 2 - Toggles - * 3 - Hides if it runs not from command line - * * - Does nothing - * @return current status (1 -visible, 0 - hidden) + * \param action + * - 0 - Hides + * - 1 - Shows + * - 2 - Toggles + * - 3 - Hides if it runs not from command line + * - * - Does nothing + * \return current status (1 -visible, 0 - hidden) */ int toggleConsole(int action); diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index 7ac9b0c3c24..e75ecfb641e 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -203,7 +203,7 @@ getNumDisplays() const /** * Returns the dimensions of the main display on this system. - * @return The dimension of the main display. + * \return The dimension of the main display. */ void GHOST_SystemX11:: @@ -221,17 +221,17 @@ getMainDisplayDimensions( * Create a new window. * The new window is added to the list of windows managed. * Never explicitly delete the window, use disposeWindow() instead. - * @param title The name of the window (displayed in the title bar of the window if the OS supports it). - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state of the window when opened. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) - * @param parentWindow Parent (embedder) window - * @return The new window (or 0 if creation failed). + * \param title The name of the window (displayed in the title bar of the window if the OS supports it). + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state of the window when opened. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) + * \param parentWindow Parent (embedder) window + * \return The new window (or 0 if creation failed). */ GHOST_IWindow * GHOST_SystemX11:: diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h index d86790e262f..92bffe46357 100644 --- a/intern/ghost/intern/GHOST_SystemX11.h +++ b/intern/ghost/intern/GHOST_SystemX11.h @@ -49,9 +49,9 @@ class GHOST_WindowX11; /** * X11 Implementation of GHOST_System class. - * @see GHOST_System. - * @author Laurence Bourn - * @date October 26, 2001 + * \see GHOST_System. + * \author Laurence Bourn + * \date October 26, 2001 */ class GHOST_SystemX11 : public GHOST_System { @@ -77,13 +77,13 @@ public: /** - * @section Interface Inherited from GHOST_ISystem + * \section Interface Inherited from GHOST_ISystem */ /** * Returns the system time. * Returns the number of milliseconds since the start of the system process. - * @return The number of milliseconds. + * \return The number of milliseconds. */ GHOST_TUns64 getMilliSeconds( @@ -92,7 +92,7 @@ public: /** * Returns the number of displays on this system. - * @return The number of displays. + * \return The number of displays. */ GHOST_TUns8 getNumDisplays( @@ -100,7 +100,7 @@ public: /** * Returns the dimensions of the main display on this system. - * @return The dimension of the main display. + * \return The dimension of the main display. */ void getMainDisplayDimensions( @@ -112,16 +112,16 @@ public: * Create a new window. * The new window is added to the list of windows managed. * Never explicitly delete the window, use disposeWindow() instead. - * @param title The name of the window (displayed in the title bar of the window if the OS supports it). - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state of the window when opened. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Create a stereo visual for quad buffered stereo. - * @param parentWindow Parent (embedder) window - * @return The new window (or 0 if creation failed). + * \param title The name of the window (displayed in the title bar of the window if the OS supports it). + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state of the window when opened. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Create a stereo visual for quad buffered stereo. + * \param parentWindow Parent (embedder) window + * \return The new window (or 0 if creation failed). */ GHOST_IWindow * createWindow( @@ -138,13 +138,13 @@ public: ); /** - * @section Interface Inherited from GHOST_ISystem + * \section Interface Inherited from GHOST_ISystem */ /** * Retrieves events from the system and stores them in the queue. - * @param waitForEvent Flag to wait for an event (or return immediately). - * @return Indication of the presence of events. + * \param waitForEvent Flag to wait for an event (or return immediately). + * \return Indication of the presence of events. */ bool processEvents( @@ -152,7 +152,7 @@ public: ); /** - * @section Interface Inherited from GHOST_System + * \section Interface Inherited from GHOST_System */ GHOST_TSuccess getCursorPosition( @@ -168,8 +168,8 @@ public: /** * Returns the state of all modifier keys. - * @param keys The state of all modifier keys (true == pressed). - * @return Indication of success. + * \param keys The state of all modifier keys (true == pressed). + * \return Indication of success. */ GHOST_TSuccess getModifierKeys( @@ -178,8 +178,8 @@ public: /** * Returns the state of the mouse buttons (ouside the message queue). - * @param buttons The state of the buttons. - * @return Indication of success. + * \param buttons The state of the buttons. + * \return Indication of success. */ GHOST_TSuccess getButtons( @@ -187,7 +187,7 @@ public: ) const; /** - * @section Interface Dirty + * \section Interface Dirty * Flag a window as dirty. This will * generate a GHOST window update event on a call to processEvents() */ @@ -223,15 +223,15 @@ public: /** * Returns unsinged char from CUT_BUFFER0 - * @param selection Get selection, X11 only feature - * @return Returns the Clipboard indicated by Flag + * \param selection Get selection, X11 only feature + * \return Returns the Clipboard indicated by Flag */ GHOST_TUns8 *getClipboard(bool selection) const; /** * Puts buffer to system clipboard - * @param buffer The buffer to copy to the clipboard - * @param selection Set the selection into the clipboard, X11 only feature + * \param buffer The buffer to copy to the clipboard + * \param selection Set the selection into the clipboard, X11 only feature */ void putClipboard(GHOST_TInt8 *buffer, bool selection) const; @@ -239,18 +239,18 @@ public: /** * Creates a drag'n'drop event and pushes it immediately onto the event queue. * Called by GHOST_DropTargetX11 class. - * @param eventType The type of drag'n'drop event - * @param draggedObjectType The type object concerned (currently array of file names, string, ?bitmap) - * @param mouseX x mouse coordinate (in window coordinates) - * @param mouseY y mouse coordinate - * @param window The window on which the event occurred - * @return Indication whether the event was handled. + * \param eventType The type of drag'n'drop event + * \param draggedObjectType The type object concerned (currently array of file names, string, ?bitmap) + * \param mouseX x mouse coordinate (in window coordinates) + * \param mouseY y mouse coordinate + * \param window The window on which the event occurred + * \return Indication whether the event was handled. */ static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, GHOST_IWindow *window, int mouseX, int mouseY, void *data); #endif /** - * @see GHOST_ISystem + * \see GHOST_ISystem */ int toggleConsole(int action) { return 0; diff --git a/intern/ghost/intern/GHOST_TimerManager.cpp b/intern/ghost/intern/GHOST_TimerManager.cpp index 4ad28d6633d..b1186507028 100644 --- a/intern/ghost/intern/GHOST_TimerManager.cpp +++ b/intern/ghost/intern/GHOST_TimerManager.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 31, 2001 + * \author Maarten Gribnau + * \date May 31, 2001 */ #include "GHOST_TimerManager.h" diff --git a/intern/ghost/intern/GHOST_TimerManager.h b/intern/ghost/intern/GHOST_TimerManager.h index 88d27088c1d..5a24c56ef10 100644 --- a/intern/ghost/intern/GHOST_TimerManager.h +++ b/intern/ghost/intern/GHOST_TimerManager.h @@ -44,8 +44,8 @@ class GHOST_TimerTask; * Manages a list of timer tasks. * Timer tasks added are owned by the manager. * Don't delete timer task objects. - * @author Maarten Gribnau - * @date May 31, 2001 + * \author Maarten Gribnau + * \date May 31, 2001 */ class GHOST_TimerManager { @@ -62,51 +62,51 @@ public: /** * Returns the number of timer tasks. - * @return The number of events on the stack. + * \return The number of events on the stack. */ virtual GHOST_TUns32 getNumTimers(); /** * Returns whther this timer task ins in our list. - * @return Indication of presence. + * \return Indication of presence. */ virtual bool getTimerFound(GHOST_TimerTask *timer); /** * Adds a timer task to the list. * It is only added when it not already present in the list. - * @param timer The timer task added to the list. - * @return Indication as to whether addition has succeeded. + * \param timer The timer task added to the list. + * \return Indication as to whether addition has succeeded. */ virtual GHOST_TSuccess addTimer(GHOST_TimerTask *timer); /** * Removes a timer task from the list. * It is only removed when it is found in the list. - * @param timer The timer task to be removed from the list. - * @return Indication as to whether removal has succeeded. + * \param timer The timer task to be removed from the list. + * \return Indication as to whether removal has succeeded. */ virtual GHOST_TSuccess removeTimer(GHOST_TimerTask *timer); /** * Finds the soonest time the next timer would fire. - * @return The soonest time the next timer would fire, + * \return The soonest time the next timer would fire, * or GHOST_kFireTimeNever if no timers exist. */ virtual GHOST_TUns64 nextFireTime(); /** * Checks all timer tasks to see if they are expired and fires them if needed. - * @param time The current time. - * @return True if any timers were fired. + * \param time The current time. + * \return True if any timers were fired. */ virtual bool fireTimers(GHOST_TUns64 time); /** * Checks this timer task to see if they are expired and fires them if needed. - * @param time The current time. - * @param task The timer task to check and optionally fire. - * @return True if the timer fired. + * \param time The current time. + * \param task The timer task to check and optionally fire. + * \return True if the timer fired. */ virtual bool fireTimer(GHOST_TUns64 time, GHOST_TimerTask *task); diff --git a/intern/ghost/intern/GHOST_TimerTask.h b/intern/ghost/intern/GHOST_TimerTask.h index d74d705d511..0731bc066af 100644 --- a/intern/ghost/intern/GHOST_TimerTask.h +++ b/intern/ghost/intern/GHOST_TimerTask.h @@ -38,18 +38,18 @@ /** * Implementation of a timer task. - * @author Maarten Gribnau - * @date May 28, 2001 + * \author Maarten Gribnau + * \date May 28, 2001 */ class GHOST_TimerTask : public GHOST_ITimerTask { public: /** * Constructor. - * @param start The timer start time. - * @param interval The interval between calls to the timerProc - * @param timerProc The callbak invoked when the interval expires. - * @param data The timer user data. + * \param start The timer start time. + * \param interval The interval between calls to the timerProc + * \param timerProc The callbak invoked when the interval expires. + * \param data The timer user data. */ GHOST_TimerTask(GHOST_TUns64 start, GHOST_TUns64 interval, @@ -66,7 +66,7 @@ public: /** * Returns the timer start time. - * @return The timer start time. + * \return The timer start time. */ inline virtual GHOST_TUns64 getStart() const { @@ -75,7 +75,7 @@ public: /** * Changes the timer start time. - * @param start The timer start time. + * \param start The timer start time. */ virtual void setStart(GHOST_TUns64 start) { @@ -84,7 +84,7 @@ public: /** * Returns the timer interval. - * @return The timer interval. + * \return The timer interval. */ inline virtual GHOST_TUns64 getInterval() const { @@ -93,7 +93,7 @@ public: /** * Changes the timer interval. - * @param interval The timer interval. + * \param interval The timer interval. */ virtual void setInterval(GHOST_TUns64 interval) { @@ -102,7 +102,7 @@ public: /** * Returns the time the timerProc will be called. - * @return The time the timerProc will be called. + * \return The time the timerProc will be called. */ inline virtual GHOST_TUns64 getNext() const { @@ -111,7 +111,7 @@ public: /** * Changes the time the timerProc will be called. - * @param next The time the timerProc will be called. + * \param next The time the timerProc will be called. */ virtual void setNext(GHOST_TUns64 next) { @@ -120,7 +120,7 @@ public: /** * Returns the timer callback. - * @return the timer callback. + * \return the timer callback. */ inline virtual GHOST_TimerProcPtr getTimerProc() const { @@ -129,7 +129,7 @@ public: /** * Changes the timer callback. - * @param The timer callback. + * \param The timer callback. */ inline virtual void setTimerProc(const GHOST_TimerProcPtr timerProc) { @@ -138,7 +138,7 @@ public: /** * Returns the timer user data. - * @return The timer user data. + * \return The timer user data. */ inline virtual GHOST_TUserDataPtr getUserData() const { @@ -147,7 +147,7 @@ public: /** * Changes the time user data. - * @param data The timer user data. + * \param data The timer user data. */ virtual void setUserData(const GHOST_TUserDataPtr userData) { @@ -156,7 +156,7 @@ public: /** * Returns the auxiliary storage room. - * @return The auxiliary storage room. + * \return The auxiliary storage room. */ inline virtual GHOST_TUns32 getAuxData() const { @@ -165,7 +165,7 @@ public: /** * Changes the auxiliary storage room. - * @param auxData The auxiliary storage room. + * \param auxData The auxiliary storage room. */ virtual void setAuxData(GHOST_TUns32 auxData) { diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp index c3244d1594d..eb80a073b44 100644 --- a/intern/ghost/intern/GHOST_Window.cpp +++ b/intern/ghost/intern/GHOST_Window.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 10, 2001 + * \author Maarten Gribnau + * \date May 10, 2001 */ #include "GHOST_Window.h" diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h index 10a6a57b9fe..3043b107aa1 100644 --- a/intern/ghost/intern/GHOST_Window.h +++ b/intern/ghost/intern/GHOST_Window.h @@ -43,14 +43,14 @@ class STR_String; * upper-left corner of the screen. * Implements part of the GHOST_IWindow interface and adds some methods to * be implemented by childs of this class. - * @author Maarten Gribnau - * @date May 7, 2001 + * \author Maarten Gribnau + * \date May 7, 2001 */ class GHOST_Window : public GHOST_IWindow { public: /** - * @section Interface inherited from GHOST_IWindow left for derived class + * \section Interface inherited from GHOST_IWindow left for derived class * implementation. * virtual bool getValid() const = 0; * virtual void setTitle(const STR_String& title) = 0; @@ -75,12 +75,12 @@ public: * Constructor. * Creates a new window and opens it. * To check if the window was created properly, use the getValid() method. - * @param width The width the window. - * @param heigh The height the window. - * @param state The state the window is initially opened with. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) + * \param width The width the window. + * \param heigh The height the window. + * \param state The state the window is initially opened with. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) */ GHOST_Window( GHOST_TUns32 width, @@ -91,7 +91,7 @@ public: const GHOST_TUns16 numOfAASamples = 0); /** - * @section Interface inherited from GHOST_IWindow left for derived class + * \section Interface inherited from GHOST_IWindow left for derived class * implementation. * virtual bool getValid() const = 0; * virtual void setTitle(const STR_String& title) = 0; @@ -119,30 +119,30 @@ public: /** * Returns the associated OS object/handle - * @return The associated OS object/handle + * \return The associated OS object/handle */ virtual void *getOSWindow() const; /** * Returns the current cursor shape. - * @return The current cursor shape. + * \return The current cursor shape. */ inline virtual GHOST_TStandardCursor getCursorShape() const; /** * Set the shape of the cursor. - * @param cursor The new cursor shape type id. - * @return Indication of success. + * \param cursor The new cursor shape type id. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape); /** * Set the shape of the cursor to a custom cursor. - * @param bitmap The bitmap data for the cursor. - * @param mask The mask data for the cursor. - * @param hotX The X coordinate of the cursor hotspot. - * @param hotY The Y coordinate of the cursor hotspot. - * @return Indication of success. + * \param bitmap The bitmap data for the cursor. + * \param mask The mask data for the cursor. + * \param hotX The X coordinate of the cursor hotspot. + * \param hotY The Y coordinate of the cursor hotspot. + * \return Indication of success. */ virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], @@ -157,7 +157,7 @@ public: /** * Returns the visibility state of the cursor. - * @return The visibility state of the cursor. + * \return The visibility state of the cursor. */ inline virtual bool getCursorVisibility() const; inline virtual GHOST_TGrabCursorMode getCursorGrabMode() const; @@ -168,15 +168,15 @@ public: /** * Shows or hides the cursor. - * @param visible The new visibility state of the cursor. - * @return Indication of success. + * \param visible The new visibility state of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorVisibility(bool visible); /** * Sets the cursor grab. - * @param mode The new grab state of the cursor. - * @return Indication of success. + * \param mode The new grab state of the cursor. + * \return Indication of success. */ virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds); @@ -188,7 +188,7 @@ public: /** * Sets the progress bar value displayed in the window/application icon - * @param progress The progress % (0.0 to 1.0) + * \param progress The progress % (0.0 to 1.0) */ virtual GHOST_TSuccess setProgressBar(float progress) { return GHOST_kFailure; @@ -214,20 +214,20 @@ public: /** * Sets the window "modified" status, indicating unsaved changes - * @param isUnsavedChanges Unsaved changes or not - * @return Indication of success. + * \param isUnsavedChanges Unsaved changes or not + * \return Indication of success. */ virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges); /** * Gets the window "modified" status, indicating unsaved changes - * @return True if there are unsaved changes + * \return True if there are unsaved changes */ virtual bool getModifiedState(); /** * Returns the type of drawing context used in this window. - * @return The current type of drawing context. + * \return The current type of drawing context. */ inline virtual GHOST_TDrawingContextType getDrawingContextType(); @@ -235,14 +235,14 @@ public: * Tries to install a rendering context in this window. * Child classes do not need to overload this method. * They should overload the installDrawingContext and removeDrawingContext instead. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type); /** * Returns the window user data. - * @return The window user data. + * \return The window user data. */ inline virtual GHOST_TUserDataPtr getUserData() const { @@ -251,7 +251,7 @@ public: /** * Changes the window user data. - * @param data The window user data. + * \param data The window user data. */ virtual void setUserData(const GHOST_TUserDataPtr userData) { @@ -261,14 +261,14 @@ public: protected: /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type) = 0; /** * Removes the current drawing context. - * @return Indication as to whether removal has succeeded. + * \return Indication as to whether removal has succeeded. */ virtual GHOST_TSuccess removeDrawingContext() = 0; diff --git a/intern/ghost/intern/GHOST_WindowCarbon.cpp b/intern/ghost/intern/GHOST_WindowCarbon.cpp index ca3366004d3..c7be02cc7af 100644 --- a/intern/ghost/intern/GHOST_WindowCarbon.cpp +++ b/intern/ghost/intern/GHOST_WindowCarbon.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 10, 2001 + * \author Maarten Gribnau + * \date May 10, 2001 */ #include "GHOST_WindowCarbon.h" diff --git a/intern/ghost/intern/GHOST_WindowCarbon.h b/intern/ghost/intern/GHOST_WindowCarbon.h index 1291fb1a2c4..d25d57156f6 100644 --- a/intern/ghost/intern/GHOST_WindowCarbon.h +++ b/intern/ghost/intern/GHOST_WindowCarbon.h @@ -54,8 +54,8 @@ * which is called the gutter. * When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent * OpenGL drawing outside the reduced client rectangle. - * @author Maarten Gribnau - * @date May 23, 2001 + * \author Maarten Gribnau + * \date May 23, 2001 */ class GHOST_WindowCarbon : public GHOST_Window { public: @@ -63,14 +63,14 @@ public: * Constructor. * Creates a new window and opens it. * To check if the window was created properly, use the getValid() method. - * @param title The text shown in the title bar of the window. - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state the window is initially opened with. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. + * \param title The text shown in the title bar of the window. + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state the window is initially opened with. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. */ GHOST_WindowCarbon( const STR_String& title, @@ -92,109 +92,109 @@ public: /** * Returns indication as to whether the window is valid. - * @return The validity of the window. + * \return The validity of the window. */ virtual bool getValid() const; /** * Sets the title displayed in the title bar. - * @param title The title to display in the title bar. + * \param title The title to display in the title bar. */ virtual void setTitle(const STR_String& title); /** * Returns the title displayed in the title bar. - * @param title The title displayed in the title bar. + * \param title The title displayed in the title bar. */ virtual void getTitle(STR_String& title) const; /** * Returns the window rectangle dimensions. * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. - * @param bounds The bounding rectangle of the window. + * \param bounds The bounding rectangle of the window. */ virtual void getWindowBounds(GHOST_Rect& bounds) const; /** * Returns the client rectangle dimensions. * The left and top members of the rectangle are always zero. - * @param bounds The bounding rectangle of the cleient area of the window. + * \param bounds The bounding rectangle of the cleient area of the window. */ virtual void getClientBounds(GHOST_Rect& bounds) const; /** * Resizes client rectangle width. - * @param width The new width of the client area of the window. + * \param width The new width of the client area of the window. */ virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width); /** * Resizes client rectangle height. - * @param height The new height of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height); /** * Resizes client rectangle. - * @param width The new width of the client area of the window. - * @param height The new height of the client area of the window. + * \param width The new width of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height); /** * Returns the state of the window (normal, minimized, maximized). - * @return The state of the window. + * \return The state of the window. */ virtual GHOST_TWindowState getState() const; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate on the screen. - * @param inY The y-coordinate on the screen. - * @param outX The x-coordinate in the client rectangle. - * @param outY The y-coordinate in the client rectangle. + * \param inX The x-coordinate on the screen. + * \param inY The y-coordinate on the screen. + * \param outX The x-coordinate in the client rectangle. + * \param outY The y-coordinate in the client rectangle. */ virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate in the client rectangle. - * @param inY The y-coordinate in the client rectangle. - * @param outX The x-coordinate on the screen. - * @param outY The y-coordinate on the screen. + * \param inX The x-coordinate in the client rectangle. + * \param inY The y-coordinate in the client rectangle. + * \param outX The x-coordinate on the screen. + * \param outY The y-coordinate on the screen. */ virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Sets the state of the window (normal, minimized, maximized). - * @param state The state of the window. - * @return Indication of success. + * \param state The state of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setState(GHOST_TWindowState state); /** * Sets the order of the window (bottom, top). - * @param order The order of the window. - * @return Indication of success. + * \param order The order of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order); /** * Swaps front and back buffers of a window. - * @return A boolean success indicator. + * \return A boolean success indicator. */ virtual GHOST_TSuccess swapBuffers(); /** * Updates the drawing context of this window. Needed * whenever the window is changed. - * @return Indication of success. + * \return Indication of success. */ GHOST_TSuccess updateDrawingContext(); /** * Activates the drawing context of this window. - * @return A boolean success indicator. + * \return A boolean success indicator. */ virtual GHOST_TSuccess activateDrawingContext(); @@ -202,7 +202,7 @@ public: /** * Returns the dirty state of the window when in full-screen mode. - * @return Whether it is dirty. + * \return Whether it is dirty. */ virtual bool getFullScreenDirty(); @@ -223,20 +223,20 @@ public: protected: /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type); /** * Removes the current drawing context. - * @return Indication as to whether removal has succeeded. + * \return Indication as to whether removal has succeeded. */ virtual GHOST_TSuccess removeDrawingContext(); /** * Invalidates the contents of this window. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess invalidate(); @@ -263,15 +263,15 @@ protected: /** * Converts a string object to a Mac Pascal string. - * @param in The string object to be converted. - * @param out The converted string. + * \param in The string object to be converted. + * \param out The converted string. */ virtual void gen2mac(const STR_String& in, Str255 out) const; /** * Converts a Mac Pascal string to a string object. - * @param in The string to be converted. - * @param out The converted string object. + * \param in The string to be converted. + * \param out The converted string object. */ virtual void mac2gen(const Str255 in, STR_String& out) const; diff --git a/intern/ghost/intern/GHOST_WindowCocoa.h b/intern/ghost/intern/GHOST_WindowCocoa.h index d53dfa71d95..3e5c675d4a7 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.h +++ b/intern/ghost/intern/GHOST_WindowCocoa.h @@ -53,8 +53,8 @@ class GHOST_SystemCocoa; * which is called the gutter. * When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent * OpenGL drawing outside the reduced client rectangle. - * @author Maarten Gribnau - * @date May 23, 2001 + * \author Maarten Gribnau + * \date May 23, 2001 */ class GHOST_WindowCocoa : public GHOST_Window { public: @@ -62,16 +62,16 @@ public: * Constructor. * Creates a new window and opens it. * To check if the window was created properly, use the getValid() method. - * @param systemCocoa The associated system class to forward events to - * @param title The text shown in the title bar of the window. - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state the window is initially opened with. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) + * \param systemCocoa The associated system class to forward events to + * \param title The text shown in the title bar of the window. + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state the window is initially opened with. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) */ GHOST_WindowCocoa( GHOST_SystemCocoa *systemCocoa, @@ -94,148 +94,148 @@ public: /** * Returns indication as to whether the window is valid. - * @return The validity of the window. + * \return The validity of the window. */ virtual bool getValid() const; /** * Returns the associated NSWindow object - * @return The associated NSWindow object + * \return The associated NSWindow object */ virtual void *getOSWindow() const; /** * Sets the title displayed in the title bar. - * @param title The title to display in the title bar. + * \param title The title to display in the title bar. */ virtual void setTitle(const STR_String& title); /** * Returns the title displayed in the title bar. - * @param title The title displayed in the title bar. + * \param title The title displayed in the title bar. */ virtual void getTitle(STR_String& title) const; /** * Returns the window rectangle dimensions. * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. - * @param bounds The bounding rectangle of the window. + * \param bounds The bounding rectangle of the window. */ virtual void getWindowBounds(GHOST_Rect& bounds) const; /** * Returns the client rectangle dimensions. * The left and top members of the rectangle are always zero. - * @param bounds The bounding rectangle of the cleient area of the window. + * \param bounds The bounding rectangle of the cleient area of the window. */ virtual void getClientBounds(GHOST_Rect& bounds) const; /** * Resizes client rectangle width. - * @param width The new width of the client area of the window. + * \param width The new width of the client area of the window. */ virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width); /** * Resizes client rectangle height. - * @param height The new height of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height); /** * Resizes client rectangle. - * @param width The new width of the client area of the window. - * @param height The new height of the client area of the window. + * \param width The new width of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height); /** * Returns the state of the window (normal, minimized, maximized). - * @return The state of the window. + * \return The state of the window. */ virtual GHOST_TWindowState getState() const; /** * Sets the window "modified" status, indicating unsaved changes - * @param isUnsavedChanges Unsaved changes or not - * @return Indication of success. + * \param isUnsavedChanges Unsaved changes or not + * \return Indication of success. */ virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges); /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate on the screen. - * @param inY The y-coordinate on the screen. - * @param outX The x-coordinate in the client rectangle. - * @param outY The y-coordinate in the client rectangle. + * \param inX The x-coordinate on the screen. + * \param inY The y-coordinate on the screen. + * \param outX The x-coordinate in the client rectangle. + * \param outY The y-coordinate in the client rectangle. */ virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate in the client rectangle. - * @param inY The y-coordinate in the client rectangle. - * @param outX The x-coordinate on the screen. - * @param outY The y-coordinate on the screen. + * \param inX The x-coordinate in the client rectangle. + * \param inY The y-coordinate in the client rectangle. + * \param outX The x-coordinate on the screen. + * \param outY The y-coordinate on the screen. */ virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Converts a point in screen coordinates to client rectangle coordinates * but without the y coordinate conversion needed for ghost compatibility. - * @param inX The x-coordinate in the client rectangle. - * @param inY The y-coordinate in the client rectangle. - * @param outX The x-coordinate on the screen. - * @param outY The y-coordinate on the screen. + * \param inX The x-coordinate in the client rectangle. + * \param inY The y-coordinate in the client rectangle. + * \param outX The x-coordinate on the screen. + * \param outY The y-coordinate on the screen. */ void clientToScreenIntern(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Converts a point in screen coordinates to client rectangle coordinates, * but without the y coordinate conversion needed for ghost compatibility. - * @param inX The x-coordinate in the client rectangle. - * @param inY The y-coordinate in the client rectangle. - * @param outX The x-coordinate on the screen. - * @param outY The y-coordinate on the screen. + * \param inX The x-coordinate in the client rectangle. + * \param inY The y-coordinate in the client rectangle. + * \param outX The x-coordinate on the screen. + * \param outY The y-coordinate on the screen. */ void screenToClientIntern(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Gets the screen the window is displayed in - * @return The NSScreen object + * \return The NSScreen object */ NSScreen *getScreen(); /** * Sets the state of the window (normal, minimized, maximized). - * @param state The state of the window. - * @return Indication of success. + * \param state The state of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setState(GHOST_TWindowState state); /** * Sets the order of the window (bottom, top). - * @param order The order of the window. - * @return Indication of success. + * \param order The order of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order); /** * Swaps front and back buffers of a window. - * @return A boolean success indicator. + * \return A boolean success indicator. */ virtual GHOST_TSuccess swapBuffers(); /** * Updates the drawing context of this window. Needed * whenever the window is changed. - * @return Indication of success. + * \return Indication of success. */ GHOST_TSuccess updateDrawingContext(); /** * Activates the drawing context of this window. - * @return A boolean success indicator. + * \return A boolean success indicator. */ virtual GHOST_TSuccess activateDrawingContext(); @@ -254,7 +254,7 @@ public: /** * Sets the progress bar value displayed in the window/application icon - * @param progress The progress % (0.0 to 1.0) + * \param progress The progress % (0.0 to 1.0) */ virtual GHOST_TSuccess setProgressBar(float progress); @@ -265,20 +265,20 @@ public: protected: /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type); /** * Removes the current drawing context. - * @return Indication as to whether removal has succeeded. + * \return Indication as to whether removal has succeeded. */ virtual GHOST_TSuccess removeDrawingContext(); /** * Invalidates the contents of this window. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess invalidate(); diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index 294766cba24..31589003131 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -213,7 +213,7 @@ extern "C" { switch (m_draggedObjectType) { case GHOST_kDragnDropTypeBitmap: - if([NSImage canInitWithPasteboard:draggingPBoard]) { + if ([NSImage canInitWithPasteboard:draggingPBoard]) { droppedImg = [[NSImage alloc]initWithPasteboard:draggingPBoard]; data = droppedImg; //[draggingPBoard dataForType:NSTIFFPboardType]; } @@ -244,8 +244,8 @@ extern "C" { GHOST_SystemCocoa *systemCocoa; GHOST_WindowCocoa *associatedWindow; - bool composing; - NSString *composing_text; + bool composing; + NSString *composing_text; } - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa; @end @@ -256,34 +256,35 @@ extern "C" { systemCocoa = sysCocoa; associatedWindow = winCocoa; - composing = false; - composing_text = nil; + composing = false; + composing_text = nil; } - (BOOL)acceptsFirstResponder { - return YES; + return YES; } // The trick to prevent Cocoa from complaining (beeping) - (void)keyDown:(NSEvent *)event { - // Start or continue composing? - if([[event characters] length] == 0 || - [[event charactersIgnoringModifiers] length] == 0 || - composing) { - composing = YES; - - // interpret event to call insertText - NSMutableArray *events; - events = [[NSMutableArray alloc] initWithCapacity:1]; - [events addObject:event]; - [self interpretKeyEvents:events]; // calls insertText - [events removeObject:event]; - [events release]; + /* Start or continue composing? */ + if ([[event characters] length] == 0 || + [[event charactersIgnoringModifiers] length] == 0 || + composing) + { + composing = YES; - return; - } + // interpret event to call insertText + NSMutableArray *events; + events = [[NSMutableArray alloc] initWithCapacity:1]; + [events addObject:event]; + [self interpretKeyEvents:events]; // calls insertText + [events removeObject:event]; + [events release]; + + return; + } } #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 @@ -314,62 +315,60 @@ extern "C" { - (BOOL)isOpaque { - return YES; + return YES; } - (void) drawRect:(NSRect)rect { - if ([self inLiveResize]) - { - //Don't redraw while in live resize - } - else - { - [super drawRect:rect]; - systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow); - } + if ([self inLiveResize]) { + /* Don't redraw while in live resize */ + } + else { + [super drawRect:rect]; + systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow); + } } // Text input - (void)composing_free { - composing = NO; + composing = NO; - if(composing_text) { - [composing_text release]; - composing_text = nil; - } + if (composing_text) { + [composing_text release]; + composing_text = nil; + } } - (void)insertText:(id)chars { - [self composing_free]; + [self composing_free]; } - (void)setMarkedText:(id)chars selectedRange:(NSRange)range { - [self composing_free]; - if([chars length] == 0) - return; - - // start composing - composing = YES; - composing_text = [chars copy]; + [self composing_free]; + if ([chars length] == 0) + return; + + // start composing + composing = YES; + composing_text = [chars copy]; - // if empty, cancel - if([composing_text length] == 0) - [self composing_free]; + // if empty, cancel + if ([composing_text length] == 0) + [self composing_free]; } - (void)unmarkText { - [self composing_free]; + [self composing_free]; } - (BOOL)hasMarkedText { - return (composing)? YES: NO; + return (composing)? YES: NO; } - (void)doCommandBySelector:(SEL)selector @@ -378,48 +377,48 @@ extern "C" { - (BOOL)isComposing { - return composing; + return composing; } - (NSInteger)conversationIdentifier { - return (NSInteger)self; + return (NSInteger)self; } - (NSAttributedString *)attributedSubstringFromRange:(NSRange)range { - return [NSAttributedString new]; // XXX does this leak? + return [NSAttributedString new]; // XXX does this leak? } - (NSRange)markedRange { - unsigned int length = (composing_text)? [composing_text length]: 0; + unsigned int length = (composing_text)? [composing_text length]: 0; - if(composing) - return NSMakeRange(0, length); + if (composing) + return NSMakeRange(0, length); - return NSMakeRange(NSNotFound, 0); + return NSMakeRange(NSNotFound, 0); } - (NSRange)selectedRange { - unsigned int length = (composing_text)? [composing_text length]: 0; - return NSMakeRange(0, length); + unsigned int length = (composing_text)? [composing_text length]: 0; + return NSMakeRange(0, length); } - (NSRect)firstRectForCharacterRange:(NSRange)range { - return NSZeroRect; + return NSZeroRect; } - (NSUInteger)characterIndexForPoint:(NSPoint)point { - return NSNotFound; + return NSNotFound; } - (NSArray*)validAttributesForMarkedText { - return [NSArray array]; // XXX does this leak? + return [NSArray array]; // XXX does this leak? } @end @@ -487,7 +486,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore; // Force software OpenGL, for debugging - if(getenv("BLENDER_SOFTWAREGL")) { + if (getenv("BLENDER_SOFTWAREGL")) { pixelFormatAttrsWindow[i++] = NSOpenGLPFARendererID; pixelFormatAttrsWindow[i++] = kCGLRendererGenericID; } @@ -530,7 +529,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore; // Force software OpenGL, for debugging - if(getenv("BLENDER_SOFTWAREGL")) { + if (getenv("BLENDER_SOFTWAREGL")) { pixelFormatAttrsWindow[i++] = NSOpenGLPFARendererID; pixelFormatAttrsWindow[i++] = kCGLRendererGenericID; } @@ -600,7 +599,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( GHOST_WindowCocoa::~GHOST_WindowCocoa() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; if (m_customCursor) { [m_customCursor release]; @@ -638,14 +637,13 @@ void* GHOST_WindowCocoa::getOSWindow() const void GHOST_WindowCocoa::setTitle(const STR_String& title) { - GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid") + GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid") NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *windowTitle = [[NSString alloc] initWithCString:title encoding:NSUTF8StringEncoding]; //Set associated file if applicable - if (windowTitle && [windowTitle hasPrefix:@"Blender"]) - { + if (windowTitle && [windowTitle hasPrefix:@"Blender"]) { NSRange fileStrRange; NSString *associatedFileName; int len; @@ -653,8 +651,7 @@ void GHOST_WindowCocoa::setTitle(const STR_String& title) fileStrRange.location = [windowTitle rangeOfString:@"["].location+1; len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location; - if (len > 0) - { + if (len > 0) { fileStrRange.length = len; associatedFileName = [windowTitle substringWithRange:fileStrRange]; [m_window setTitle:[associatedFileName lastPathComponent]]; @@ -686,14 +683,14 @@ void GHOST_WindowCocoa::setTitle(const STR_String& title) void GHOST_WindowCocoa::getTitle(STR_String& title) const { - GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid") + GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid") NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *windowTitle = [m_window title]; if (windowTitle != nil) { - title = [windowTitle UTF8String]; + title = [windowTitle UTF8String]; } [pool drain]; @@ -727,8 +724,7 @@ void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - if (!m_fullScreen) - { + if (!m_fullScreen) { NSRect screenSize = [[m_window screen] visibleFrame]; //Max window contents as screen size (excluding title bar...) @@ -794,8 +790,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; GHOST_Rect cBnds, wBnds; getClientBounds(cBnds); - if ((((GHOST_TUns32)cBnds.getWidth()) != width) || - (((GHOST_TUns32)cBnds.getHeight()) != height)) { + if ((((GHOST_TUns32)cBnds.getWidth()) != width) || + (((GHOST_TUns32)cBnds.getHeight()) != height)) + { NSSize size; size.width=width; size.height=height; @@ -889,35 +886,36 @@ NSScreen* GHOST_WindowCocoa::getScreen() /** - * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features. + * \note Fullscreen switch is not actual fullscreen with display capture. + * As this capture removes all OS X window manager features. + * * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged. * Thus, process switch, exposé, spaces, ... still work in fullscreen mode */ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) { GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid") - switch (state) { + switch (state) { case GHOST_kWindowStateMinimized: - [m_window miniaturize:nil]; - break; + [m_window miniaturize:nil]; + break; case GHOST_kWindowStateMaximized: [m_window zoom:nil]; break; case GHOST_kWindowStateFullScreen: - if (!m_fullScreen) - { + if (!m_fullScreen) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - //This status change needs to be done before Cocoa call to enter fullscreen mode - //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference + /* This status change needs to be done before Cocoa call to enter fullscreen mode + * to give window delegate hint not to forward its deactivation to ghost wm that + * doesn't know view/window difference. */ m_fullScreen = true; #ifdef MAC_OS_X_VERSION_10_6 //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style //Hide menu & dock if needed - if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) - { + if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) { [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)]; } //Make window borderless and enlarge it @@ -927,8 +925,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) #else //With 10.5, we need to create a new window to change its style to borderless //Hide menu & dock if needed - if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) - { + if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) { //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO]; //One of the very few 64bit compatible Carbon function SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar); @@ -947,7 +944,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) [tmpWindow setDelegate:[m_window delegate]]; [tmpWindow setSystemAndWindowCocoa:[m_window systemCocoa] windowCocoa:this]; [tmpWindow registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, - NSStringPboardType, NSTIFFPboardType, nil]]; + NSStringPboardType, NSTIFFPboardType, nil]]; //Assign the openGL view to the new window [tmpWindow setContentView:m_openGLView]; @@ -968,17 +965,15 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) } break; case GHOST_kWindowStateNormal: - default: + default: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - if (m_fullScreen) - { + if (m_fullScreen) { m_fullScreen = false; //Exit fullscreen #ifdef MAC_OS_X_VERSION_10_6 //Show again menu & dock if needed - if ([[m_window screen] isEqual:[NSScreen mainScreen]]) - { + if ([[m_window screen] isEqual:[NSScreen mainScreen]]) { [NSApp setPresentationOptions:NSApplicationPresentationDefault]; } //Make window normal and resize it @@ -989,8 +984,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) #else //With 10.5, we need to create a new window to change its style to borderless //Show menu & dock if needed - if ([[m_window screen] isEqual:[NSScreen mainScreen]]) - { + if ([[m_window screen] isEqual:[NSScreen mainScreen]]) { //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES]; SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function } @@ -1027,15 +1021,15 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) //Tell WM of view new size m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this); } - else if ([m_window isMiniaturized]) + else if ([m_window isMiniaturized]) [m_window deminiaturize:nil]; else if ([m_window isZoomed]) [m_window zoom:nil]; [pool drain]; - break; - } + break; + } - return GHOST_kSuccess; + return GHOST_kSuccess; } GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges) @@ -1055,10 +1049,10 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid") - if (order == GHOST_kWindowOrderTop) { + if (order == GHOST_kWindowOrderTop) { [m_window makeKeyAndOrderFront:nil]; - } - else { + } + else { NSArray *windowsList; [m_window orderBack:nil]; @@ -1068,10 +1062,10 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order) if ([windowsList count]) { [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil]; } - } + } [pool drain]; - return GHOST_kSuccess; + return GHOST_kSuccess; } #pragma mark Drawing context @@ -1080,15 +1074,15 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order) GHOST_TSuccess GHOST_WindowCocoa::swapBuffers() { - if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) { - if (m_openGLContext != nil) { + if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) { + if (m_openGLContext != nil) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [m_openGLContext flushBuffer]; [pool drain]; - return GHOST_kSuccess; - } - } - return GHOST_kFailure; + return GHOST_kSuccess; + } + } + return GHOST_kFailure; } GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext() @@ -1184,8 +1178,7 @@ GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; switch (m_drawingContextType) { case GHOST_kDrawingContextTypeOpenGL: - if (m_openGLContext) - { + if (m_openGLContext) { [m_openGLView clearGLContext]; if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil; m_openGLContext = nil; @@ -1222,24 +1215,24 @@ GHOST_TSuccess GHOST_WindowCocoa::setProgressBar(float progress) NSImage* dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(128,128)]; [dockIcon lockFocus]; - NSRect progressBox = {{4, 4}, {120, 16}}; - - [[NSImage imageNamed:@"NSApplicationIcon"] dissolveToPoint:NSZeroPoint fraction:1.0]; - - // Track & Outline - [[NSColor blackColor] setFill]; - NSRectFill(progressBox); - - [[NSColor whiteColor] set]; - NSFrameRect(progressBox); - - // Progress fill - progressBox = NSInsetRect(progressBox, 1, 1); - - progressBox.size.width = progressBox.size.width * progress; - NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor darkGrayColor] endingColor:[NSColor lightGrayColor]]; - [gradient drawInRect:progressBox angle:90]; - [gradient release]; + NSRect progressBox = {{4, 4}, {120, 16}}; + + [[NSImage imageNamed:@"NSApplicationIcon"] dissolveToPoint:NSZeroPoint fraction:1.0]; + + // Track & Outline + [[NSColor blackColor] setFill]; + NSRectFill(progressBox); + + [[NSColor whiteColor] set]; + NSFrameRect(progressBox); + + // Progress fill + progressBox = NSInsetRect(progressBox, 1, 1); + + progressBox.size.width = progressBox.size.width * progress; + NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor darkGrayColor] endingColor:[NSColor lightGrayColor]]; + [gradient drawInRect:progressBox angle:90]; + [gradient release]; [dockIcon unlockFocus]; @@ -1364,10 +1357,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode { GHOST_TSuccess err = GHOST_kSuccess; - if (mode != GHOST_kGrabDisable) - { + if (mode != GHOST_kGrabDisable) { //No need to perform grab without warp as it is always on in OS X - if(mode != GHOST_kGrabNormal) { + if (mode != GHOST_kGrabNormal) { GHOST_TInt32 x_old,y_old; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -1376,7 +1368,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode //Warp position is stored in client (window base) coordinates setCursorGrabAccum(0, 0); - if(mode == GHOST_kGrabHide) { + if (mode == GHOST_kGrabHide) { setWindowCursorVisibility(false); } @@ -1390,8 +1382,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode } } else { - if(m_cursorGrab==GHOST_kGrabHide) - { + if (m_cursorGrab==GHOST_kGrabHide) { //No need to set again cursor position, as it has not changed for Cocoa setWindowCursorVisibility(true); } diff --git a/intern/ghost/intern/GHOST_WindowManager.cpp b/intern/ghost/intern/GHOST_WindowManager.cpp index 2b7fb6686f2..1816c57a150 100644 --- a/intern/ghost/intern/GHOST_WindowManager.cpp +++ b/intern/ghost/intern/GHOST_WindowManager.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ #include "GHOST_WindowManager.h" diff --git a/intern/ghost/intern/GHOST_WindowManager.h b/intern/ghost/intern/GHOST_WindowManager.h index e754595e881..ecf0cb30860 100644 --- a/intern/ghost/intern/GHOST_WindowManager.h +++ b/intern/ghost/intern/GHOST_WindowManager.h @@ -41,8 +41,8 @@ /** * Manages system windows (platform independent implementation). - * @author Maarten Gribnau - * @date May 11, 2001 + * \author Maarten Gribnau + * \date May 11, 2001 */ class GHOST_WindowManager { @@ -60,68 +60,68 @@ public: /** * Add a window to our list. * It is only added if it is not already in the list. - * @param window Pointer to the window to be added. - * @return Indication of success. + * \param window Pointer to the window to be added. + * \return Indication of success. */ virtual GHOST_TSuccess addWindow(GHOST_IWindow *window); /** * Remove a window from our list. - * @param window Pointer to the window to be removed. - * @return Indication of success. + * \param window Pointer to the window to be removed. + * \return Indication of success. */ virtual GHOST_TSuccess removeWindow(const GHOST_IWindow *window); /** * Returns whether the window is in our list. - * @param window Pointer to the window to query. - * @return A boolean indicator. + * \param window Pointer to the window to query. + * \return A boolean indicator. */ virtual bool getWindowFound(const GHOST_IWindow *window) const; /** * Returns whether one of the windows is fullscreen. - * @return A boolean indicator. + * \return A boolean indicator. */ virtual bool getFullScreen(void) const; /** * Returns pointer to the full-screen window. - * @return The fll-screen window (0 if not in full-screen). + * \return The fll-screen window (0 if not in full-screen). */ virtual GHOST_IWindow *getFullScreenWindow(void) const; /** * Activates fullscreen mode for a window. - * @param window The window displayed fullscreen. - * @return Indication of success. + * \param window The window displayed fullscreen. + * \return Indication of success. */ virtual GHOST_TSuccess beginFullScreen(GHOST_IWindow *window, const bool stereoVisual); /** * Closes fullscreen mode down. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess endFullScreen(void); /** * Sets new window as active window (the window receiving events). * There can be only one window active which should be in the current window list. - * @param window The new active window. + * \param window The new active window. */ virtual GHOST_TSuccess setActiveWindow(GHOST_IWindow *window); /** * Returns the active window (the window receiving events). * There can be only one window active which should be in the current window list. - * @return window The active window (or NULL if there is none). + * \return window The active window (or NULL if there is none). */ virtual GHOST_IWindow *getActiveWindow(void) const; /** * Set this window to be inactive (not receiving events). - * @param window The window to decativate. + * \param window The window to decativate. */ virtual void setWindowInactive(const GHOST_IWindow *window); @@ -129,7 +129,7 @@ public: /** * Return a vector of the windows currently managed by this * class. - * @warning It is very dangerous to mess with the contents of + * \warning It is very dangerous to mess with the contents of * this vector. Please do not destroy or add windows use the * interface above for this, */ @@ -137,14 +137,14 @@ public: /** * Finds the window associated with an OS window object/handle - * @param osWindow The OS window object/handle - * @return The associated window, null if none corresponds + * \param osWindow The OS window object/handle + * \return The associated window, null if none corresponds */ virtual GHOST_IWindow *getWindowAssociatedWithOSWindow(void *osWindow); /** * Return true if any windows has a modified status - * @return True if any window has unsaved changes + * \return True if any window has unsaved changes */ bool getAnyModifiedState(); diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp index 3a6e646de11..0e8ff438998 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cpp +++ b/intern/ghost/intern/GHOST_WindowWin32.cpp @@ -32,8 +32,8 @@ /** * Copyright (C) 2001 NaN Technologies B.V. - * @author Maarten Gribnau - * @date May 10, 2001 + * \author Maarten Gribnau + * \date May 10, 2001 */ #include <string.h> @@ -271,6 +271,10 @@ GHOST_WindowWin32::GHOST_WindowWin32( // Register this window as a droptarget. Requires m_hWnd to be valid. // Note that OleInitialize(0) has to be called prior to this. Done in GHOST_SystemWin32. m_dropTarget = new GHOST_DropTargetWin32(this, m_system); + if (m_dropTarget) { + ::RegisterDragDrop(m_hWnd, m_dropTarget); + } + // Store a pointer to this class in the window structure ::SetWindowLongPtr(m_hWnd, GWL_USERDATA, (LONG_PTR) this); @@ -415,7 +419,13 @@ GHOST_WindowWin32::~GHOST_WindowWin32() m_hDC = 0; } if (m_hWnd) { - m_dropTarget->Release(); // frees itself. + if (m_dropTarget) { + // Disable DragDrop + RevokeDragDrop(m_hWnd); + // Release our reference of the DropTarget and it will delete itself eventually. + m_dropTarget->Release(); + } + ::DestroyWindow(m_hWnd); m_hWnd = 0; } diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h index cf5a7fe808d..3f52f9e22b0 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.h +++ b/intern/ghost/intern/GHOST_WindowWin32.h @@ -61,8 +61,8 @@ typedef BOOL (API * GHOST_WIN32_WTPacket)(HCTX, UINT, LPVOID); /** * GHOST window on M$ Windows OSs. - * @author Maarten Gribnau - * @date May 10, 2001 + * \author Maarten Gribnau + * \date May 10, 2001 */ class GHOST_WindowWin32 : public GHOST_Window { public: @@ -70,15 +70,15 @@ public: * Constructor. * Creates a new window and opens it. * To check if the window was created properly, use the getValid() method. - * @param title The text shown in the title bar of the window. - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state the window is initially opened with. - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) + * \param title The text shown in the title bar of the window. + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state the window is initially opened with. + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) */ GHOST_WindowWin32( GHOST_SystemWin32 *system, @@ -104,115 +104,115 @@ public: /** * Returns the window to replace this one if it's getting replaced - * @return The window replacing this one. + * \return The window replacing this one. */ GHOST_Window *getNextWindow(); /** * Returns indication as to whether the window is valid. - * @return The validity of the window. + * \return The validity of the window. */ virtual bool getValid() const; /** * Access to the handle of the window. - * @return The handle of the window. + * \return The handle of the window. */ virtual HWND getHWND() const; /** * Sets the title displayed in the title bar. - * @param title The title to display in the title bar. + * \param title The title to display in the title bar. */ virtual void setTitle(const STR_String& title); /** * Returns the title displayed in the title bar. - * @param title The title displayed in the title bar. + * \param title The title displayed in the title bar. */ virtual void getTitle(STR_String& title) const; /** * Returns the window rectangle dimensions. * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. - * @param bounds The bounding rectangle of the window. + * \param bounds The bounding rectangle of the window. */ virtual void getWindowBounds(GHOST_Rect& bounds) const; /** * Returns the client rectangle dimensions. * The left and top members of the rectangle are always zero. - * @param bounds The bounding rectangle of the cleient area of the window. + * \param bounds The bounding rectangle of the cleient area of the window. */ virtual void getClientBounds(GHOST_Rect& bounds) const; /** * Resizes client rectangle width. - * @param width The new width of the client area of the window. + * \param width The new width of the client area of the window. */ virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width); /** * Resizes client rectangle height. - * @param height The new height of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height); /** * Resizes client rectangle. - * @param width The new width of the client area of the window. - * @param height The new height of the client area of the window. + * \param width The new width of the client area of the window. + * \param height The new height of the client area of the window. */ virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height); /** * Returns the state of the window (normal, minimized, maximized). - * @return The state of the window. + * \return The state of the window. */ virtual GHOST_TWindowState getState() const; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate on the screen. - * @param inY The y-coordinate on the screen. - * @param outX The x-coordinate in the client rectangle. - * @param outY The y-coordinate in the client rectangle. + * \param inX The x-coordinate on the screen. + * \param inY The y-coordinate on the screen. + * \param outX The x-coordinate in the client rectangle. + * \param outY The y-coordinate in the client rectangle. */ virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Converts a point in screen coordinates to client rectangle coordinates - * @param inX The x-coordinate in the client rectangle. - * @param inY The y-coordinate in the client rectangle. - * @param outX The x-coordinate on the screen. - * @param outY The y-coordinate on the screen. + * \param inX The x-coordinate in the client rectangle. + * \param inY The y-coordinate in the client rectangle. + * \param outX The x-coordinate on the screen. + * \param outY The y-coordinate on the screen. */ virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; /** * Sets the state of the window (normal, minimized, maximized). - * @param state The state of the window. - * @return Indication of success. + * \param state The state of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setState(GHOST_TWindowState state); /** * Sets the order of the window (bottom, top). - * @param order The order of the window. - * @return Indication of success. + * \param order The order of the window. + * \return Indication of success. */ virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order); /** * Swaps front and back buffers of a window. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess swapBuffers(); /** * Activates the drawing context of this window. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess activateDrawingContext(); @@ -223,7 +223,7 @@ public: /** * Sets the progress bar value displayed in the window/application icon - * @param progress The progress % + * \param progress The progress % */ virtual GHOST_TSuccess setProgressBar(float progress); @@ -234,7 +234,7 @@ public: /** * Returns the name of the window class. - * @return The name of the window class. + * \return The name of the window class. */ static wchar_t *getWindowClassName() { return s_windowClassName; @@ -245,7 +245,7 @@ public: * for any real button press, controls mouse * capturing). * - * @param press + * \param press * 0 - mouse pressed * 1 - mouse released * 2 - operator grab @@ -261,8 +261,8 @@ public: /** * Loads the windows equivalent of a standard GHOST cursor. - * @param visible Flag for cursor visibility. - * @param cursorShape The cursor shape. + * \param visible Flag for cursor visibility. + * \param cursorShape The cursor shape. */ void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const; @@ -279,14 +279,14 @@ protected: /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication of success. + * \param type The type of rendering context installed. + * \return Indication of success. */ virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type); /** * Removes the current drawing context. - * @return Indication of success. + * \return Indication of success. */ virtual GHOST_TSuccess removeDrawingContext(); @@ -299,7 +299,7 @@ protected: /** * Sets the cursor grab on the window using native window system calls. * Using registerMouseClickEvent. - * @param mode GHOST_TGrabCursorMode. + * \param mode GHOST_TGrabCursorMode. */ virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode); diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp index 17efecb4a82..4ad95fcab53 100644 --- a/intern/ghost/intern/GHOST_WindowX11.cpp +++ b/intern/ghost/intern/GHOST_WindowX11.cpp @@ -1376,8 +1376,8 @@ GHOST_WindowX11:: /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ GHOST_TSuccess GHOST_WindowX11:: @@ -1418,7 +1418,7 @@ installDrawingContext( /** * Removes the current drawing context. - * @return Indication as to whether removal has succeeded. + * \return Indication as to whether removal has succeeded. */ GHOST_TSuccess GHOST_WindowX11:: diff --git a/intern/ghost/intern/GHOST_WindowX11.h b/intern/ghost/intern/GHOST_WindowX11.h index 753d8960a18..5b2ffced29c 100644 --- a/intern/ghost/intern/GHOST_WindowX11.h +++ b/intern/ghost/intern/GHOST_WindowX11.h @@ -53,8 +53,8 @@ class GHOST_DropTargetX11; /** * X11 implementation of GHOST_IWindow. * Dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. - * @author Laurence Bourn - * @date October 26, 2001 + * \author Laurence Bourn + * \date October 26, 2001 */ class GHOST_WindowX11 : public GHOST_Window @@ -64,16 +64,16 @@ public: * Constructor. * Creates a new window and opens it. * To check if the window was created properly, use the getValid() method. - * @param title The text shown in the title bar of the window. - * @param left The coordinate of the left edge of the window. - * @param top The coordinate of the top edge of the window. - * @param width The width the window. - * @param height The height the window. - * @param state The state the window is initially opened with. - * @param parentWindow Parent (embedder) window - * @param type The type of drawing context installed in this window. - * @param stereoVisual Stereo visual for quad buffered stereo. - * @param numOfAASamples Number of samples used for AA (zero if no AA) + * \param title The text shown in the title bar of the window. + * \param left The coordinate of the left edge of the window. + * \param top The coordinate of the top edge of the window. + * \param width The width the window. + * \param height The height the window. + * \param state The state the window is initially opened with. + * \param parentWindow Parent (embedder) window + * \param type The type of drawing context installed in this window. + * \param stereoVisual Stereo visual for quad buffered stereo. + * \param numOfAASamples Number of samples used for AA (zero if no AA) */ GHOST_WindowX11( GHOST_SystemX11 *system, @@ -176,7 +176,7 @@ public: ~GHOST_WindowX11(); /** - * @section x11specific X11 system specific calls + * \section x11specific X11 system specific calls */ /** @@ -256,8 +256,8 @@ public: protected: /** * Tries to install a rendering context in this window. - * @param type The type of rendering context installed. - * @return Indication as to whether installation has succeeded. + * \param type The type of rendering context installed. + * \return Indication as to whether installation has succeeded. */ GHOST_TSuccess installDrawingContext( @@ -266,7 +266,7 @@ protected: /** * Removes the current drawing context. - * @return Indication as to whether removal has succeeded. + * \return Indication as to whether removal has succeeded. */ GHOST_TSuccess removeDrawingContext( @@ -284,7 +284,7 @@ protected: /** * Sets the cursor grab on the window using * native window system calls. - * @param warp Only used when grab is enabled, hides the mouse and allows gragging outside the screen. + * \param warp Only used when grab is enabled, hides the mouse and allows gragging outside the screen. */ GHOST_TSuccess setWindowCursorGrab( diff --git a/intern/ghost/test/gears/GHOST_C-Test.c b/intern/ghost/test/gears/GHOST_C-Test.c index 98e2b9c2497..00ae4bb25b4 100644 --- a/intern/ghost/test/gears/GHOST_C-Test.c +++ b/intern/ghost/test/gears/GHOST_C-Test.c @@ -31,8 +31,8 @@ * Simple test file for the GHOST library. * The OpenGL gear code is taken from the Qt sample code which, * in turn, is probably taken from somewhere as well. - * @author Maarten Gribnau - * @date May 31, 2001 + * \author Maarten Gribnau + * \date May 31, 2001 */ #include <stdlib.h> diff --git a/intern/ghost/test/gears/GHOST_Test.cpp b/intern/ghost/test/gears/GHOST_Test.cpp index c02272094f4..1e641a8643c 100644 --- a/intern/ghost/test/gears/GHOST_Test.cpp +++ b/intern/ghost/test/gears/GHOST_Test.cpp @@ -30,8 +30,8 @@ * Simple test file for the GHOST library. * The OpenGL gear code is taken from the Qt sample code which, * in turn, is probably taken from somewhere as well. - * @author Maarten Gribnau - * @date May 31, 2001 + * \author Maarten Gribnau + * \date May 31, 2001 * Stereo code by Raymond de Vries, januari 2002 */ diff --git a/intern/ghost/test/multitest/EventToBuf.c b/intern/ghost/test/multitest/EventToBuf.c index 034fbe04447..0eb37a58be2 100644 --- a/intern/ghost/test/multitest/EventToBuf.c +++ b/intern/ghost/test/multitest/EventToBuf.c @@ -203,33 +203,36 @@ void event_to_buf(GHOST_EventHandle evt, char buf[128]) void *data= GHOST_GetEventData(evt); char *pos= buf; - pos+= sprintf(pos, "event: %6.2f, %16s", time, eventtype_to_string(type)); + pos += sprintf(pos, "event: %6.2f, %16s", time, eventtype_to_string(type)); if (win) { char *s= GHOST_GetTitle(win); - pos+= sprintf(pos, " - win: %s", s); + pos += sprintf(pos, " - win: %s", s); free(s); } else { pos+= sprintf(pos, " - sys evt"); } switch (type) { - case GHOST_kEventCursorMove: { - GHOST_TEventCursorData *cd= data; - pos+= sprintf(pos, " - pos: (%d, %d)", cd->x, cd->y); - break; - } - case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { - GHOST_TEventButtonData *bd= data; - pos+= sprintf(pos, " - but: %d", bd->button); - break; - } - - case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { - GHOST_TEventKeyData *kd= data; - pos+= sprintf(pos, " - key: %s (%d)", keytype_to_string(kd->key), kd->key); - if (kd->ascii) pos+= sprintf(pos, " ascii: '%c' (%d)", kd->ascii, kd->ascii); - break; - } + case GHOST_kEventCursorMove: + { + GHOST_TEventCursorData *cd= data; + pos += sprintf(pos, " - pos: (%d, %d)", cd->x, cd->y); + break; + } + case GHOST_kEventButtonDown: + case GHOST_kEventButtonUp: + { + GHOST_TEventButtonData *bd= data; + pos += sprintf(pos, " - but: %d", bd->button); + break; + } + + case GHOST_kEventKeyDown: + case GHOST_kEventKeyUp: + { + GHOST_TEventKeyData *kd= data; + pos += sprintf(pos, " - key: %s (%d)", keytype_to_string(kd->key), kd->key); + if (kd->ascii) pos+= sprintf(pos, " ascii: '%c' (%d)", kd->ascii, kd->ascii); + break; + } } } diff --git a/intern/ghost/test/multitest/MultiTest.c b/intern/ghost/test/multitest/MultiTest.c index da1c56d0a3a..5d207dafaaf 100644 --- a/intern/ghost/test/multitest/MultiTest.c +++ b/intern/ghost/test/multitest/MultiTest.c @@ -267,7 +267,8 @@ static void mainwindow_handle(void *priv, GHOST_EventHandle evt) mainwindow_log(mw, buf); switch (type) { - case GHOST_kEventCursorMove: { + case GHOST_kEventCursorMove: + { GHOST_TEventCursorData *cd = GHOST_GetEventData(evt); int x, y; GHOST_ScreenToClient(mw->win, cd->x, cd->y, &x, &y); @@ -275,13 +276,15 @@ static void mainwindow_handle(void *priv, GHOST_EventHandle evt) break; } case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { + case GHOST_kEventButtonUp: + { GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); mainwindow_do_button(mw, bd->button, (type == GHOST_kEventButtonDown)); break; } case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { + case GHOST_kEventKeyUp: + { GHOST_TEventKeyData *kd = GHOST_GetEventData(evt); mainwindow_do_key(mw, kd->key, (type == GHOST_kEventKeyDown)); break; @@ -541,7 +544,8 @@ static void loggerwindow_handle(void *priv, GHOST_EventHandle evt) GHOST_TEventType type = GHOST_GetEventType(evt); switch (type) { - case GHOST_kEventCursorMove: { + case GHOST_kEventCursorMove: + { GHOST_TEventCursorData *cd = GHOST_GetEventData(evt); int x, y; GHOST_ScreenToClient(lw->win, cd->x, cd->y, &x, &y); @@ -549,13 +553,15 @@ static void loggerwindow_handle(void *priv, GHOST_EventHandle evt) break; } case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { + case GHOST_kEventButtonUp: + { GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); loggerwindow_do_button(lw, bd->button, (type == GHOST_kEventButtonDown)); break; } case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { + case GHOST_kEventKeyUp: + { GHOST_TEventKeyData *kd = GHOST_GetEventData(evt); loggerwindow_do_key(lw, kd->key, (type == GHOST_kEventKeyDown)); break; @@ -743,13 +749,15 @@ static void extrawindow_handle(void *priv, GHOST_EventHandle evt) switch (type) { case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { + case GHOST_kEventKeyUp: + { GHOST_TEventKeyData *kd = GHOST_GetEventData(evt); extrawindow_do_key(ew, kd->key, (type == GHOST_kEventKeyDown)); break; } - case GHOST_kEventCursorMove: { + case GHOST_kEventCursorMove: + { extrawindow_spin_cursor(ew, GHOST_GetEventTime(evt)); break; } diff --git a/intern/guardedalloc/intern/mmap_win.c b/intern/guardedalloc/intern/mmap_win.c index a133f92fec4..ab50edb811e 100644 --- a/intern/guardedalloc/intern/mmap_win.c +++ b/intern/guardedalloc/intern/mmap_win.c @@ -44,7 +44,7 @@ #define FILE_MAP_EXECUTE 0x0020 #endif -/* copied from BKE_utildefines.h ugh */ +/* copied from BLI_utildefines.h, ugh */ #ifdef __GNUC__ # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) #else diff --git a/intern/opennl/intern/opennl.c b/intern/opennl/intern/opennl.c index 20b4c0a6681..71809cc7480 100644 --- a/intern/opennl/intern/opennl.c +++ b/intern/opennl/intern/opennl.c @@ -569,6 +569,8 @@ void nlDeleteContext(NLContext context_in) { __NL_DELETE(context->variable[i].a); } } + + __NL_DELETE_ARRAY(context->variable); } if(context->alloc_b) { __NL_DELETE_ARRAY(context->b); diff --git a/intern/string/STR_String.h b/intern/string/STR_String.h index 98de5be9647..6e9f6007e0b 100644 --- a/intern/string/STR_String.h +++ b/intern/string/STR_String.h @@ -66,8 +66,8 @@ typedef const STR_String& rcSTR_String; typedef unsigned char byte; /** - * Smart String Value class. Is used by parser when an expression tree is build containing string. -*/ + * Smart String Value class. Is used by parser when an expression tree is build containing string. + */ class STR_String { @@ -85,16 +85,16 @@ public: explicit STR_String(dword val); explicit STR_String(float val); explicit STR_String(double val); - inline ~STR_String() { delete[] pData; } + inline ~STR_String() { delete[] this->m_data; } // Operations STR_String& Format(const char *fmt, ...); // Set formatted text to string STR_String& FormatAdd(const char *fmt, ...); // Add formatted text to string - inline void Clear() { Len = pData[0] = 0; } + inline void Clear() { this->m_len = this->m_data[0] = 0; } inline const STR_String & Reverse() { - for (int i1 = 0, i2 = Len - 1; i1 < i2; i1++, i2--) { - std::swap(pData[i1], pData[i2]); + for (int i1 = 0, i2 = this->m_len - 1; i1 < i2; i1++, i2--) { + std::swap(this->m_data[i1], this->m_data[i2]); } return *this; } @@ -102,28 +102,28 @@ public: // Properties bool IsUpper() const; bool IsLower() const; - inline bool IsEmpty() const { return Len == 0; } - inline int Length() const { return Len; } + inline bool IsEmpty() const { return this->m_len == 0; } + inline int Length() const { return this->m_len; } // Data access - inline STR_String& SetLength(int len) { AllocBuffer(len, true); Len=len; pData[len]=0; return *this; } - inline char GetAt(int pos) const { assertd(pos<Len); return pData[pos]; } - inline void SetAt(int pos, char c) { assertd(pos<Len); pData[pos]=c; } + inline STR_String& SetLength(int len) { AllocBuffer(len, true); this->m_len = len; this->m_data[len] = 0; return *this; } + inline char GetAt(int pos) const { assertd(pos<this->m_len); return this->m_data[pos]; } + inline void SetAt(int pos, char c) { assertd(pos<this->m_len); this->m_data[pos] = c; } inline void SetAt(int pos, rcSTR_String str); inline void SetAt(int pos, int num, rcSTR_String str); void Replace(int pos, rcSTR_String str); void Replace(int pos, int num, rcSTR_String str); // Substrings - inline STR_String Left(int num) const { num = (num < Len ? num:Len ); return STR_String(pData, num); } - inline STR_String Right(int num) const { num = (num < Len ? num:Len ); return STR_String(pData+Len-num, num); } - inline STR_String Mid(int pos, int num = INT_MAX) const { pos = (pos < Len ? pos:Len ); num = (num < (Len - pos) ? num : (Len - pos)); return STR_String(pData+pos, num); } + inline STR_String Left(int num) const { num = (num < this->m_len ? num:this->m_len ); return STR_String(this->m_data, num); } + inline STR_String Right(int num) const { num = (num < this->m_len ? num:this->m_len ); return STR_String(this->m_data + this->m_len - num, num); } + inline STR_String Mid(int pos, int num = INT_MAX) const { pos = (pos < this->m_len ? pos:this->m_len ); num = (num < (this->m_len - pos) ? num : (this->m_len - pos)); return STR_String(this->m_data + pos, num); } // Comparison int Compare(rcSTR_String rhs) const; int CompareNoCase(rcSTR_String rhs) const; - inline bool IsEqual(rcSTR_String rhs) const { return (Compare(rhs) == 0); } - inline bool IsEqualNoCase(rcSTR_String rhs) const { return (CompareNoCase(rhs) == 0); } + inline bool IsEqual(rcSTR_String rhs) const { return (Compare(rhs) == 0); } + inline bool IsEqualNoCase(rcSTR_String rhs) const { return (CompareNoCase(rhs) == 0); } // Search/replace int Find(char c, int pos = 0) const; @@ -148,12 +148,12 @@ public: STR_String& TrimQuotes(); // Conversions -// inline operator char*() { return pData; } - inline operator const char *() const { return pData; } - inline char *Ptr() { return pData; } - inline const char *ReadPtr() const { return pData; } - inline float ToFloat() const { float x=(float)(atof(pData)); return x; } - inline int ToInt() const { return atoi(pData); } +// inline operator char*() { return this->m_data; } + inline operator const char *() const { return this->m_data; } + inline char *Ptr() { return this->m_data; } + inline const char *ReadPtr() const { return this->m_data; } + inline float ToFloat() const { float x=(float)(atof(this->m_data)); return x; } + inline int ToInt() const { return atoi(this->m_data); } // Operators inline rcSTR_String operator=(const byte *rhs) { return Copy((const char *)rhs, strlen((const char *)rhs)); } @@ -198,9 +198,9 @@ protected: static bool isUpper(char c) { return (c>='A') && (c <= 'Z'); } static bool isSpace(char c) { return (c==' ') || (c=='\t'); } - char *pData; // -> STR_String data - int Len; // Data length - int Max; // Space in data buffer + char *m_data; // -> STR_String data + int m_len; //z Data length + int m_max; // Space in data buffer #ifdef WITH_CXX_GUARDEDALLOC diff --git a/intern/string/intern/STR_String.cpp b/intern/string/intern/STR_String.cpp index bea6e88cfff..4b2261e89f9 100644 --- a/intern/string/intern/STR_String.cpp +++ b/intern/string/intern/STR_String.cpp @@ -27,14 +27,9 @@ /** \file string/intern/STR_String.cpp * \ingroup string - */ - - -/** - + * * Copyright (C) 2001 NaN Technologies B.V. * This file was formerly known as: GEN_StdString.cpp. - * @date April, 25, 2001 */ #include <stdio.h> @@ -51,17 +46,18 @@ Construction / destruction -------------------------------------------------------------------------------------------------*/ - +#define STR_STRING_SIZE_DEFAULT_WORD 32 /* default size for a new word */ +#define STR_STRING_SIZE_DEFAULT_CHAR 9 /* default size for a new char */ // // Construct an empty string // STR_String::STR_String() : - pData(new char[32]), - Len(0), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_len(0), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - pData[0] = 0; + this->m_data[0] = 0; } @@ -70,12 +66,12 @@ STR_String::STR_String() : // Construct a string of one character // STR_String::STR_String(char c) : - pData(new char[9]), - Len(1), - Max(9) + m_data(new char[STR_STRING_SIZE_DEFAULT_CHAR]), + m_len(1), + m_max(STR_STRING_SIZE_DEFAULT_CHAR) { - pData[0] = c; - pData[1] = 0; + this->m_data[0] = c; + this->m_data[1] = 0; } @@ -84,13 +80,13 @@ STR_String::STR_String(char c) : // Construct a string of multiple repeating characters // STR_String::STR_String(char c, int len) : - pData(new char[len + 8]), - Len(len), - Max(len + 8) + m_data(new char[len + 8]), + m_len(len), + m_max(len + 8) { - assertd(pData != NULL); - memset(pData, c, len); - pData[len] = 0; + assertd(this->m_data != NULL); + memset(this->m_data, c, len); + this->m_data[len] = 0; } @@ -102,17 +98,17 @@ STR_String::STR_String(char c, int len) : STR_String::STR_String(const char *str) { if (str) { - Len = ::strlen(str); - Max = Len + 8; - pData = new char[Max]; - assertd(pData != NULL); - ::memcpy(pData, str, Len); - pData[Len] = 0; + this->m_len = ::strlen(str); + this->m_max = this->m_len + 8; + this->m_data = new char[this->m_max]; + assertd(this->m_data != NULL); + ::memcpy(this->m_data, str, this->m_len); + this->m_data[this->m_len] = 0; } else { - pData = 0; - Len = 0; - Max = 8; + this->m_data = 0; + this->m_len = 0; + this->m_max = 8; } } @@ -122,13 +118,13 @@ STR_String::STR_String(const char *str) // Construct a string from a pointer-to-ASCII-string and a length // STR_String::STR_String(const char *str, int len) : - pData(new char[len + 8]), - Len(len), - Max(len + 8) + m_data(new char[len + 8]), + m_len(len), + m_max(len + 8) { - assertd(pData != NULL); - memcpy(pData, str, len); - pData[len] = 0; + assertd(this->m_data != NULL); + memcpy(this->m_data, str, len); + this->m_data[len] = 0; } @@ -137,14 +133,14 @@ STR_String::STR_String(const char *str, int len) : // Construct a string from another string // STR_String::STR_String(rcSTR_String str) : - pData(new char[str.Length() + 8]), - Len(str.Length()), - Max(str.Length() + 8) + m_data(new char[str.Length() + 8]), + m_len(str.Length()), + m_max(str.Length() + 8) { - assertd(pData != NULL); - assertd(str.pData != NULL); - memcpy(pData, str.pData, str.Length()); - pData[str.Length()] = 0; + assertd(this->m_data != NULL); + assertd(str.this->m_data != NULL); + memcpy(this->m_data, str.ReadPtr(), str.Length()); + this->m_data[str.Length()] = 0; } @@ -153,14 +149,14 @@ STR_String::STR_String(rcSTR_String str) : // Construct a string from the first number of characters in another string // STR_String::STR_String(rcSTR_String str, int len) : - pData(new char[len + 8]), - Len(len), - Max(len + 8) + m_data(new char[len + 8]), + m_len(len), + m_max(len + 8) { - assertd(pData != NULL); - assertd(str.pData != NULL); - memcpy(pData, str.pData, str.Length()); - pData[str.Length()] = 0; + assertd(this->m_data != NULL); + assertd(str.this->m_data != NULL); + memcpy(this->m_data, str.ReadPtr(), str.Length()); + this->m_data[str.Length()] = 0; } @@ -169,14 +165,14 @@ STR_String::STR_String(rcSTR_String str, int len) : // Create a string by concatenating two sources // STR_String::STR_String(const char *src1, int len1, const char *src2, int len2) : - pData(new char[len1 + len2 + 8]), - Len(len1 + len2), - Max(len1 + len2 + 8) + m_data(new char[len1 + len2 + 8]), + m_len(len1 + len2), + m_max(len1 + len2 + 8) { - assertd(pData != NULL); - memcpy(pData, src1, len1); - memcpy(pData + len1, src2, len2); - pData[len1 + len2] = 0; + assertd(this->m_data != NULL); + memcpy(this->m_data, src1, len1); + memcpy(this->m_data + len1, src2, len2); + this->m_data[len1 + len2] = 0; } @@ -185,11 +181,11 @@ STR_String::STR_String(const char *src1, int len1, const char *src2, int len2) : // Create a string with an integer value // STR_String::STR_String(int val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%d", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%d", val); } @@ -199,11 +195,11 @@ STR_String::STR_String(int val) : // Create a string with a dword value // STR_String::STR_String(dword val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%lu", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%lu", val); } @@ -212,11 +208,11 @@ STR_String::STR_String(dword val) : // Create a string with a floating point value // STR_String::STR_String(float val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%g", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%g", val); } @@ -225,11 +221,11 @@ STR_String::STR_String(float val) : // Create a string with a double value // STR_String::STR_String(double val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%g", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%g", val); } @@ -246,17 +242,19 @@ STR_String::STR_String(double val) : void STR_String::AllocBuffer(int len, bool keep_contents) { // Check if we have enough space - if (len + 1 <= Max) return; + if (len + 1 <= this->m_max) return; // Reallocate string char *new_data = new char[len + 8]; - if (keep_contents) memcpy(new_data, pData, Len); - delete[] pData; + if (keep_contents) { + memcpy(new_data, this->m_data, this->m_len); + } + delete[] this->m_data; // Accept new data - Max = len + 8; - pData = new_data; - assertd(pData != NULL); + this->m_max = len + 8; + this->m_data = new_data; + assertd(this->m_data != NULL); } @@ -274,12 +272,12 @@ STR_String& STR_String::Format(const char *fmt, ...) { AllocBuffer(2048, false); - assertd(pData != NULL); + assertd(this->m_data != NULL); // Expand arguments and format to string va_list args; va_start(args, fmt); - Len = vsprintf(pData, fmt, args); - assertd(Len <= 2048); + this->m_len = vsprintf(this->m_data, fmt, args); + assertd(this->m_len <= 2048); va_end(args); return *this; @@ -294,12 +292,12 @@ STR_String& STR_String::FormatAdd(const char *fmt, ...) { AllocBuffer(2048, false); - assertd(pData != NULL); + assertd(this->m_data != NULL); // Expand arguments and format to string va_list args; va_start(args, fmt); - Len += vsprintf(pData + Len, fmt, args); - assertd(Len <= 2048); + this->m_len += vsprintf(this->m_data + this->m_len, fmt, args); + assertd(this->m_len <= 2048); va_end(args); return *this; @@ -318,8 +316,8 @@ STR_String& STR_String::FormatAdd(const char *fmt, ...) // bool STR_String::IsUpper() const { - for (int i = 0; i < Len; i++) - if (isLower(pData[i])) + for (int i = 0; i < this->m_len; i++) + if (isLower(this->m_data[i])) return false; return true; @@ -332,8 +330,8 @@ bool STR_String::IsUpper() const // bool STR_String::IsLower() const { - for (int i = 0; i < Len; i++) - if (isUpper(pData[i])) + for (int i = 0; i < this->m_len; i++) + if (isUpper(this->m_data[i])) return false; return true; @@ -353,10 +351,10 @@ bool STR_String::IsLower() const int STR_String::Find(char c, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strchr(pData + pos, c); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strchr(this->m_data + pos, c); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -367,10 +365,10 @@ int STR_String::Find(char c, int pos) const int STR_String::Find(const char *str, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strstr(pData + pos, str); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strstr(this->m_data + pos, str); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -381,10 +379,10 @@ int STR_String::Find(const char *str, int pos) const int STR_String::Find(rcSTR_String str, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strstr(pData + pos, str.ReadPtr()); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strstr(this->m_data + pos, str.ReadPtr()); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -394,9 +392,9 @@ int STR_String::Find(rcSTR_String str, int pos) const // int STR_String::RFind(char c) const { - assertd(pData != NULL); - char *pos = strrchr(pData, c); - return (pos) ? (pos - pData) : -1; + assertd(this->m_data != NULL); + char *pos = strrchr(this->m_data, c); + return (pos) ? (pos - this->m_data) : -1; } @@ -407,10 +405,10 @@ int STR_String::RFind(char c) const int STR_String::FindOneOf(const char *set, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strpbrk(pData + pos, set); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strpbrk(this->m_data + pos, set); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -425,16 +423,16 @@ void STR_String::Replace(int pos, rcSTR_String str) if (str.Length() < 1) { // Remove one character from the string - memcpy(pData + pos, pData + pos + 1, Len - pos); + memcpy(this->m_data + pos, this->m_data + pos + 1, this->m_len - pos); } else { // Insert zero or more characters into the string - AllocBuffer(Len + str.Length() - 1, true); - if (str.Length() != 1) memcpy(pData + pos + str.Length(), pData + pos + 1, Length() - pos); - memcpy(pData + pos, str.ReadPtr(), str.Length()); + AllocBuffer(this->m_len + str.Length() - 1, true); + if (str.Length() != 1) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + 1, Length() - pos); + memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } - Len += str.Length() - 1; + this->m_len += str.Length() - 1; } @@ -451,17 +449,17 @@ void STR_String::Replace(int pos, int num, rcSTR_String str) if (str.Length() < num) { // Remove some data from the string by replacement - memcpy(pData + pos + str.Length(), pData + pos + num, Len - pos - num + 1); - memcpy(pData + pos, str.ReadPtr(), str.Length()); + memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, this->m_len - pos - num + 1); + memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } else { // Insert zero or more characters into the string - AllocBuffer(Len + str.Length() - num, true); - if (str.Length() != num) memcpy(pData + pos + str.Length(), pData + pos + num, Length() - pos - num + 1); - memcpy(pData + pos, str.ReadPtr(), str.Length()); + AllocBuffer(this->m_len + str.Length() - num, true); + if (str.Length() != num) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, Length() - pos - num + 1); + memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } - Len += str.Length() - num; + this->m_len += str.Length() - num; } @@ -477,7 +475,7 @@ void STR_String::Replace(int pos, int num, rcSTR_String str) // int STR_String::Compare(rcSTR_String rhs) const { - return strcmp(pData, rhs.pData); + return strcmp(this->ReadPtr(), rhs.ReadPtr()); } @@ -488,9 +486,9 @@ int STR_String::Compare(rcSTR_String rhs) const int STR_String::CompareNoCase(rcSTR_String rhs) const { #ifdef WIN32 - return stricmp(pData, rhs.pData); + return stricmp(this->ReadPtr(), rhs.ReadPtr()); #else - return strcasecmp(pData, rhs.pData); + return strcasecmp(this->ReadPtr(), rhs.ReadPtr()); #endif } @@ -507,12 +505,12 @@ int STR_String::CompareNoCase(rcSTR_String rhs) const // STR_String& STR_String::Upper() { - assertd(pData != NULL); + assertd(this->m_data != NULL); #ifdef WIN32 - _strupr(pData); + _strupr(this->m_data); #else - for (int i = 0; i < Len; i++) - pData[i] = (pData[i] >= 'a' && pData[i] <= 'z') ? pData[i] + 'A' - 'a' : pData[i]; + for (int i = 0; i < this->m_len; i++) + this->m_data[i] = (this->m_data[i] >= 'a' && this->m_data[i] <= 'z') ? this->m_data[i] + 'A' - 'a' : this->m_data[i]; #endif return *this; } @@ -524,12 +522,12 @@ STR_String& STR_String::Upper() // STR_String& STR_String::Lower() { - assertd(pData != NULL); + assertd(this->m_data != NULL); #ifdef WIN32 - _strlwr(pData); + _strlwr(this->m_data); #else - for (int i = 0; i < Len; i++) - pData[i] = (pData[i] >= 'A' && pData[i] <= 'Z') ? pData[i] + 'a' - 'A' : pData[i]; + for (int i = 0; i < this->m_len; i++) + this->m_data[i] = (this->m_data[i] >= 'A' && this->m_data[i] <= 'Z') ? this->m_data[i] + 'a' - 'A' : this->m_data[i]; #endif return *this; } @@ -541,15 +539,15 @@ STR_String& STR_String::Lower() // STR_String& STR_String::Capitalize() { - assertd(pData != NULL); + assertd(this->m_data != NULL); #ifdef WIN32 - if (Len > 0) pData[0] = toupper(pData[0]); - if (Len > 1) _strlwr(pData + 1); + if (this->m_len > 0) this->m_data[0] = toupper(this->m_data[0]); + if (this->m_len > 1) _strlwr(this->m_data + 1); #else - if (Len > 0) - pData[0] = (pData[0] >= 'A' && pData[0] <= 'A') ? pData[0] + 'a' - 'A' : pData[0]; - for (int i = 1; i < Len; i++) - pData[i] = (pData[i] >= 'a' && pData[i] <= 'z') ? pData[i] + 'A' - 'a' : pData[i]; + if (this->m_len > 0) + this->m_data[0] = (this->m_data[0] >= 'A' && this->m_data[0] <= 'A') ? this->m_data[0] + 'a' - 'A' : this->m_data[0]; + for (int i = 1; i < this->m_len; i++) + this->m_data[i] = (this->m_data[i] >= 'a' && this->m_data[i] <= 'z') ? this->m_data[i] + 'A' - 'a' : this->m_data[i]; #endif return *this; } @@ -562,10 +560,10 @@ STR_String& STR_String::Capitalize() STR_String& STR_String::TrimLeft() { int skip; - assertd(pData != NULL); - for (skip = 0; isSpace(pData[skip]); skip++, Len--) + assertd(this->m_data != NULL); + for (skip = 0; isSpace(this->m_data[skip]); skip++, this->m_len--) {}; - memmove(pData, pData + skip, Len + 1); + memmove(this->m_data, this->m_data + skip, this->m_len + 1); return *this; } @@ -576,9 +574,9 @@ STR_String& STR_String::TrimLeft() // STR_String& STR_String::TrimRight() { - assertd(pData != NULL); - while (Len && isSpace(pData[Len - 1])) Len--; - pData[Len] = 0; + assertd(this->m_data != NULL); + while (this->m_len && isSpace(this->m_data[this->m_len - 1])) this->m_len--; + this->m_data[this->m_len] = 0; return *this; } @@ -602,10 +600,10 @@ STR_String& STR_String::Trim() STR_String& STR_String::TrimLeft(char *set) { int skip; - assertd(pData != NULL); - for (skip = 0; Len && strchr(set, pData[skip]); skip++, Len--) + assertd(this->m_data != NULL); + for (skip = 0; this->m_len && strchr(set, this->m_data[skip]); skip++, this->m_len--) {}; - memmove(pData, pData + skip, Len + 1); + memmove(this->m_data, this->m_data + skip, this->m_len + 1); return *this; } @@ -616,9 +614,9 @@ STR_String& STR_String::TrimLeft(char *set) // STR_String& STR_String::TrimRight(char *set) { - assertd(pData != NULL); - while (Len && strchr(set, pData[Len - 1])) Len--; - pData[Len] = 0; + assertd(this->m_data != NULL); + while (this->m_len && strchr(set, this->m_data[this->m_len - 1])) this->m_len--; + this->m_data[this->m_len] = 0; return *this; } @@ -642,11 +640,11 @@ STR_String& STR_String::Trim(char *set) STR_String& STR_String::TrimQuotes() { // Trim quotes if they are on both sides of the string - assertd(pData != NULL); - if ((Len >= 2) && (pData[0] == '\"') && (pData[Len - 1] == '\"')) + assertd(this->m_data != NULL); + if ((this->m_len >= 2) && (this->m_data[0] == '\"') && (this->m_data[this->m_len - 1] == '\"')) { - memmove(pData, pData + 1, Len - 2 + 1); - Len -= 2; + memmove(this->m_data, this->m_data + 1, this->m_len - 2 + 1); + this->m_len -= 2; } return *this; } @@ -666,12 +664,12 @@ rcSTR_String STR_String::Copy(const char *src, int len) { assertd(len >= 0); assertd(src); - assertd(pData != NULL); + assertd(this->m_data != NULL); AllocBuffer(len, false); - Len = len; - memcpy(pData, src, len); - pData[Len] = 0; + this->m_len = len; + memcpy(this->m_data, src, len); + this->m_data[this->m_len] = 0; return *this; } @@ -683,15 +681,15 @@ rcSTR_String STR_String::Copy(const char *src, int len) // rcSTR_String STR_String::Concat(const char *data, int len) { - assertd(Len >= 0); + assertd(this->m_len >= 0); assertd(len >= 0); assertd(data); - assertd(pData != NULL); + assertd(this->m_data != NULL); - AllocBuffer(Len + len, true); - memcpy(pData + Len, data, len); - Len += len; - pData[Len] = 0; + AllocBuffer(this->m_len + len, true); + memcpy(this->m_data + this->m_len, data, len); + this->m_len += len; + this->m_data[this->m_len] = 0; return *this; } @@ -702,8 +700,7 @@ std::vector<STR_String> STR_String::Explode(char c) const STR_String lcv = *this; std::vector<STR_String> uc; - while (lcv.Length()) - { + while (lcv.Length()) { int pos = lcv.Find(c); if (pos < 0) { uc.push_back(lcv); @@ -729,16 +726,16 @@ int STR_String::Serialize(pCStream stream) int ln; stream->Read(&ln, sizeof(ln)); AllocBuffer(ln, false); - stream->Read(pData, ln); - pData[ln] = '\0'; - Len = ln; + stream->Read(this->m_data, ln); + this->m_data[ln] = '\0'; + this->m_len = ln; } else { - stream->Write(&Len, sizeof(Len)); - stream->Write(pData, Len); + stream->Write(&this->m_len, sizeof(this->m_len)); + stream->Write(this->m_data, this->m_len); } - return Len + sizeof(Len); + return this->m_len + sizeof(this->m_len); } #endif diff --git a/intern/utfconv/utf_winfunc.c b/intern/utfconv/utf_winfunc.c index 3840dc25648..18f0e808562 100644 --- a/intern/utfconv/utf_winfunc.c +++ b/intern/utfconv/utf_winfunc.c @@ -37,7 +37,7 @@ FILE * ufopen(const char * filename, const char * mode) { FILE *f = NULL; UTF16_ENCODE(filename); - UTF16_ENCODE (mode); + UTF16_ENCODE(mode); if (filename_16 && mode_16) { f = _wfopen(filename_16, mode_16); @@ -79,9 +79,11 @@ int urename(const char *oldname, const char *newname ) { int r = -1; UTF16_ENCODE(oldname); - UTF16_ENCODE (newname); + UTF16_ENCODE(newname); - if (oldname_16 && newname_16) r = _wrename(oldname_16, newname_16); + if (oldname_16 && newname_16) { + r = _wrename(oldname_16, newname_16); + } UTF16_UN_ENCODE(newname); UTF16_UN_ENCODE(oldname); @@ -94,7 +96,9 @@ int umkdir(const char *pathname) BOOL r = 0; UTF16_ENCODE(pathname); - if (pathname_16) r = CreateDirectoryW(pathname_16, NULL); + if (pathname_16) { + r = CreateDirectoryW(pathname_16, NULL); + } UTF16_UN_ENCODE(pathname); @@ -123,7 +127,10 @@ int uput_getenv(const char *varname, char * value, size_t buffsize) { int r = 0; wchar_t * str; - if (!buffsize) return r; + + if (!buffsize) { + return r; + } UTF16_ENCODE(varname); if (varname_16) { @@ -133,7 +140,9 @@ int uput_getenv(const char *varname, char * value, size_t buffsize) } UTF16_UN_ENCODE(varname); - if (!r) value[0] = 0; + if (!r) { + value[0] = 0; + } return r; } @@ -143,6 +152,7 @@ int uputenv(const char *name, const char *value) int r = -1; UTF16_ENCODE(name); UTF16_ENCODE(value); + if (name_16 && value_16) { r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1; } diff --git a/release/datafiles/fonts/droidsans.ttf.gz b/release/datafiles/fonts/droidsans.ttf.gz Binary files differindex b2eb31af4b9..439515e5bb4 100644 --- a/release/datafiles/fonts/droidsans.ttf.gz +++ b/release/datafiles/fonts/droidsans.ttf.gz diff --git a/release/scripts/modules/addon_utils.py b/release/scripts/modules/addon_utils.py index 433d9024e0a..485b4829b71 100644 --- a/release/scripts/modules/addon_utils.py +++ b/release/scripts/modules/addon_utils.py @@ -148,7 +148,7 @@ def modules(module_cache): for path in path_list: # force all contrib addons to be 'TESTING' - if path.endswith("addons_contrib") or path.endswith("addons_extern"): + if path.endswith(("addons_contrib", "addons_extern")): force_support = 'TESTING' else: force_support = None diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py index 62844d11443..35b496b6dd0 100644 --- a/release/scripts/startup/bl_operators/object_quick_effects.py +++ b/release/scripts/startup/bl_operators/object_quick_effects.py @@ -510,6 +510,6 @@ class QuickFluid(Operator): mat.raytrace_transparency.depth = 4 if self.start_baking: - bpy.ops.fluid.bake() + bpy.ops.fluid.bake('INVOKE_DEFAULT') return {'FINISHED'} diff --git a/release/scripts/startup/bl_operators/screen_play_rendered_anim.py b/release/scripts/startup/bl_operators/screen_play_rendered_anim.py index b4733ac9d87..32658d353d9 100644 --- a/release/scripts/startup/bl_operators/screen_play_rendered_anim.py +++ b/release/scripts/startup/bl_operators/screen_play_rendered_anim.py @@ -104,11 +104,14 @@ class PlayRenderedAnim(Operator): file = ("".join((c if file_b[i] == c else "#") for i, c in enumerate(file_a))) + del file_a, file_b, frame_tmp + file = bpy.path.abspath(file) # expand '//' else: # works for movies and images file = rd.frame_path(frame=scene.frame_start) - - file = bpy.path.abspath(file) # expand '//' + file = bpy.path.abspath(file) # expand '//' + if not os.path.exists(file): + self.report({'WARNING'}, "File %r not found" % file) cmd = [player_path] # extra options, fps controls etc. @@ -143,8 +146,14 @@ class PlayRenderedAnim(Operator): # launch it print("Executing command:\n %r" % " ".join(cmd)) + # workaround for boost 1.46, can be eventually removed. bug: [#32350] + env_copy = os.environ.copy() + if preset == 'INTERNAL': + env_copy["LC_ALL"] = "C" + # end workaround + try: - subprocess.Popen(cmd) + subprocess.Popen(cmd, env=env_copy) except Exception as e: self.report({'ERROR'}, "Couldn't run external animation player with command " diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index ed4d5dd55f5..07d4096632f 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -735,7 +735,7 @@ class WM_OT_context_modal_mouse(Operator): if not self._values: self.report({'WARNING'}, "Nothing to operate on: %s[ ].%s" % - (self.data_path_iter, self.data_path_item)) + (self.data_path_iter, self.data_path_item)) return {'CANCELLED'} else: @@ -847,28 +847,35 @@ class WM_OT_doc_view_manual(Operator): doc_id = doc_id @staticmethod - def _find_reference(rna_id, url_mapping): - print("online manual check for: '%s'... " % rna_id) + def _find_reference(rna_id, url_mapping, verbose=True): + if verbose: + print("online manual check for: '%s'... " % rna_id) from fnmatch import fnmatch for pattern, url_suffix in url_mapping: if fnmatch(rna_id, pattern): - print(" match found: '%s' --> '%s'" % (pattern, url_suffix)) + if verbose: + print(" match found: '%s' --> '%s'" % (pattern, url_suffix)) return url_suffix - print("match not found") + if verbose: + print("match not found") return None - def execute(self, context): - rna_id = _wm_doc_get_id(self.doc_id, do_url=False) - if rna_id is None: - return {'PASS_THROUGH'} - + @staticmethod + def _lookup_rna_url(rna_id, verbose=True): url = None - for prefix, url_manual_mapping in bpy.utils.manual_map(): - rna_ref = self._find_reference(rna_id, url_manual_mapping) + rna_ref = WM_OT_doc_view_manual._find_reference(rna_id, url_manual_mapping, verbose=verbose) if rna_ref is not None: url = prefix + rna_ref break + return url + + def execute(self, context): + rna_id = _wm_doc_get_id(self.doc_id, do_url=False) + if rna_id is None: + return {'PASS_THROUGH'} + + url = self._lookup_rna_url(rna_id) if url is None: self.report({'WARNING'}, "No reference available %r, " diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py index 0b4d4cd19e4..5302ad9b471 100644 --- a/release/scripts/startup/bl_ui/space_image.py +++ b/release/scripts/startup/bl_ui/space_image.py @@ -774,7 +774,7 @@ class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel): toolsettings = context.tool_settings.image_paint brush = toolsettings.brush - layout.template_curve_mapping(brush, "curve", type='COLOR') + layout.template_curve_mapping(brush, "curve") row = layout.row(align=True) row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH' diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py index ebc73752aef..dd13b8a9b51 100644 --- a/release/scripts/startup/bl_ui/space_sequencer.py +++ b/release/scripts/startup/bl_ui/space_sequencer.py @@ -449,7 +449,7 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel): return strip.type in {'ADD', 'SUBTRACT', 'ALPHA_OVER', 'ALPHA_UNDER', 'CROSS', 'GAMMA_CROSS', 'MULTIPLY', 'OVER_DROP', 'WIPE', 'GLOW', 'TRANSFORM', 'COLOR', 'SPEED', - 'MULTICAM', 'ADJUSTMENT'} + 'MULTICAM'} def draw(self, context): layout = self.layout @@ -463,10 +463,6 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel): if strip.input_count > 1: col.prop(strip, "input_2") - if strip.is_supports_mask: - col = layout.column() - col.prop_search(strip, "input_mask_strip", sequencer, "sequences", text="Mask") - if strip.type == 'COLOR': layout.prop(strip, "color") @@ -793,10 +789,6 @@ class SEQUENCER_PT_filter(SequencerButtonsPanel, Panel): col.prop(strip, "use_premultiply") col.prop(strip, "use_float") - layout.prop(strip, "use_color_balance") - if strip.use_color_balance and strip.color_balance: # TODO - need to add this somehow - draw_color_balance(layout, strip.color_balance) - class SEQUENCER_PT_proxy(SequencerButtonsPanel, Panel): bl_label = "Proxy / Timecode" diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 2c1e963dcfe..1b67b30d17a 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -980,6 +980,7 @@ class VIEW3D_PT_tools_weightpaint_options(Panel, View3DPaintPanel): col = layout.column() + col.prop(wpaint, "use_all_faces") col.prop(wpaint, "use_normal") col.prop(wpaint, "use_spray") col.prop(wpaint, "use_group_restrict") diff --git a/release/scripts/templates/operator_modal.py b/release/scripts/templates/operator_modal.py index d8115bc95bf..88e5ee80590 100644 --- a/release/scripts/templates/operator_modal.py +++ b/release/scripts/templates/operator_modal.py @@ -26,9 +26,10 @@ class ModalOperator(bpy.types.Operator): def invoke(self, context, event): if context.object: - context.window_manager.modal_handler_add(self) self.first_mouse_x = event.mouse_x self.first_value = context.object.location.x + + context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} else: self.report({'WARNING'}, "No active object, could not finish") diff --git a/release/scripts/templates/operator_modal_draw.py b/release/scripts/templates/operator_modal_draw.py index f2d5ad8982b..f1c4e113b0a 100644 --- a/release/scripts/templates/operator_modal_draw.py +++ b/release/scripts/templates/operator_modal_draw.py @@ -53,14 +53,13 @@ class ModalDrawOperator(bpy.types.Operator): def invoke(self, context, event): if context.area.type == 'VIEW_3D': - context.window_manager.modal_handler_add(self) - # Add the region OpenGL drawing callback # draw in view space with 'POST_VIEW' and 'PRE_VIEW' self._handle = context.region.callback_add(draw_callback_px, (self, context), 'POST_PIXEL') self.mouse_path = [] + context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} else: self.report({'WARNING'}, "View3D not found, cannot run operator") diff --git a/release/scripts/templates/operator_modal_timer.py b/release/scripts/templates/operator_modal_timer.py index 6d2ec95aedb..72c153df9d2 100644 --- a/release/scripts/templates/operator_modal_timer.py +++ b/release/scripts/templates/operator_modal_timer.py @@ -21,8 +21,8 @@ class ModalTimerOperator(bpy.types.Operator): return {'PASS_THROUGH'} def execute(self, context): - context.window_manager.modal_handler_add(self) self._timer = context.window_manager.event_timer_add(0.1, context.window) + context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} def cancel(self, context): diff --git a/release/scripts/templates/operator_modal_view3d.py b/release/scripts/templates/operator_modal_view3d.py index 0babf169610..c870bbffdcf 100644 --- a/release/scripts/templates/operator_modal_view3d.py +++ b/release/scripts/templates/operator_modal_view3d.py @@ -45,14 +45,13 @@ class ViewOperator(bpy.types.Operator): v3d = context.space_data rv3d = v3d.region_3d - context.window_manager.modal_handler_add(self) - if rv3d.view_perspective == 'CAMERA': rv3d.view_perspective = 'PERSP' self._initial_mouse = Vector((event.mouse_x, event.mouse_y, 0.0)) self._initial_location = rv3d.view_location.copy() + context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} else: self.report({'WARNING'}, "Active space must be a View3d") diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index 39424057faf..cda2cf303eb 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -734,9 +734,10 @@ AviError AVI_close(AviMovie *movie) fclose(movie->fp); - for (i = 0; i < movie->header->Streams; i++) { - if (movie->streams[i].sf != NULL) + for (i = 0; movie->header && (i < movie->header->Streams); i++) { + if (movie->streams && (movie->streams[i].sf != NULL)) { MEM_freeN(movie->streams[i].sf); + } } if (movie->header != NULL) @@ -1081,9 +1082,10 @@ AviError AVI_close_compress(AviMovie *movie) fclose(movie->fp); - for (i = 0; i < movie->header->Streams; i++) { - if (movie->streams[i].sf != NULL) + for (i = 0; movie->header && (i < movie->header->Streams); i++) { + if (movie->streams && (movie->streams[i].sf != NULL)) { MEM_freeN(movie->streams[i].sf); + } } if (movie->header != NULL) MEM_freeN(movie->header); diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index da916067302..b6a98faa48c 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -41,8 +41,6 @@ #include "DNA_vec_types.h" -#include "BKE_utildefines.h" - #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index b37180d499c..2b7e225d709 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -82,7 +82,7 @@ static const char *locales[] = { "spanish", "es", "catalan", "ca_AD", "czech", "cs_CZ", - "portuguese", "pt", + "portuguese", "pt_PT", #if defined(_WIN32) && !defined(FREE_WINDOWS) "Chinese (Simplified)_China.1252", "zh_CN", "Chinese (Traditional)_China.1252", "zh_TW", @@ -107,6 +107,8 @@ static const char *locales[] = { "kyrgyz", "ky_KG", "turkish", "tr_TR", "hungarian", "hu_HU", + "brazilian portuguese", "pt_BR", + "hebrew", "he_IL", }; void BLF_lang_init(void) diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 64512dcaac8..fa9223ba6e2 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -698,6 +698,7 @@ void DM_init_origspace(DerivedMesh *dm); #ifndef NDEBUG char *DM_debug_info(DerivedMesh *dm); void DM_debug_print(DerivedMesh *dm); +void DM_debug_print_cdlayers(CustomData *cdata); #endif #endif diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index acb9234b2d4..f506c67a36c 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -60,12 +60,12 @@ void animviz_calc_motionpaths(struct Scene *scene, ListBase *targets); void free_path(struct Path *path); void calc_curvepath(struct Object *ob); -int interval_test(int min, int max, int p1, int cycl); int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], float quat[4], float *radius, float *weight); /* ---------------------------------------------------- */ /* Dupli-Geometry */ +struct ListBase *object_duplilist_ex(struct Scene *sce, struct Object *ob, int update); struct ListBase *object_duplilist(struct Scene *sce, struct Object *ob); void free_object_duplilist(struct ListBase *lb); int count_duplilist(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 44e47e779e7..d750e88ac04 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -101,8 +101,6 @@ void get_objectspace_bone_matrix(struct Bone *bone, float M_accumulatedMatrix[][ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[][3]); void mat3_to_vec_roll(float mat[][3], float *vec, float *roll); -int get_selected_defgroups(struct Object *ob, char *defbase_sel, int defbase_len); - /* Common Conversions Between Co-ordinate Spaces */ void BKE_armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]); void BKE_armature_loc_world_to_pose(struct Object *ob, const float inloc[3], float outloc[3]); diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index dec4d3cb8cb..1e67027ae8c 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -42,7 +42,7 @@ extern "C" { * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 263 -#define BLENDER_SUBVERSION 17 +#define BLENDER_SUBVERSION 18 /* 262 was the last editmesh release but its has compatibility code for bmesh data, * so set the minversion to 2.61 */ @@ -83,6 +83,8 @@ void BKE_userdef_free(void); void set_blender_test_break_cb(void (*func)(void) ); int blender_test_break(void); +#define BKE_UNDO_STR_MAX 64 + /* global undo */ extern void BKE_write_undo(struct bContext *C, const char *name); extern void BKE_undo_step(struct bContext *C, int step); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 8d486218d21..19dd67b88f8 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -124,8 +124,6 @@ void CustomData_free_temporary(struct CustomData *data, int totelem); /* adds a data layer of the given type to the CustomData object, optionally * backed by an external data array. the different allocation types are * defined above. returns the data of the layer. - * - * in editmode, use EDBM_data_layer_add instead of this function */ void *CustomData_add_layer(struct CustomData *data, int type, int alloctype, void *layer, int totelem); diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 25677165fc2..52a143ddf55 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -67,7 +67,8 @@ void defvert_remap(struct MDeformVert *dvert, int *map, const int map_len); void defvert_flip(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len); void defvert_flip_merged(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len); void defvert_normalize(struct MDeformVert *dvert); -void defvert_normalize_lock(struct MDeformVert *dvert, const int def_nr_lock); +void defvert_normalize_lock_single(struct MDeformVert *dvert, const int def_nr_lock); +void defvert_normalize_lock_map(struct MDeformVert *dvert, const char *lock_flags, const int defbase_tot); /* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only * used with defgroups currently */ diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 909ed471081..67461281674 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -106,6 +106,12 @@ struct RenderResult; #define IMA_TYPE_R_RESULT 4 #define IMA_TYPE_COMPOSITE 5 +enum { + IMA_GENTYPE_BLANK = 0, + IMA_GENTYPE_GRID = 1, + IMA_GENTYPE_GRID_COLOR = 2 +}; + /* ima->ok */ #define IMA_OK 1 #define IMA_OK_LOADED 2 @@ -196,6 +202,10 @@ int BKE_image_scale(struct Image *image, int width, int height); /* check if texture has alpha (depth=32) */ int BKE_image_has_alpha(struct Image *image); +void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int *width, int *height); +void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float size[2]); +void BKE_image_get_aspect(struct Image *image, float *aspx, float *aspy); + /* image_gen.c */ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]); void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width); diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 9cf5a7f31a5..51e301fec80 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -28,6 +28,8 @@ #ifndef __BKE_MASK_H__ #define __BKE_MASK_H__ +struct ImageUser; +struct Image; struct ListBase; struct Main; struct Mask; @@ -100,13 +102,15 @@ struct Mask *BKE_mask_new(const char *name); struct Mask *BKE_mask_copy_nolib(struct Mask *mask); struct Mask *BKE_mask_copy(struct Mask *mask); -void BKE_mask_free(struct Mask *mask); -void BKE_mask_unlink(struct Main *bmain, struct Mask *mask); +void BKE_mask_free_nolib(struct Mask *mask); +void BKE_mask_free(struct Main *bmain, struct Mask *mask); -void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]); -void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_from_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2]); void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]); +void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_to_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2]); /* parenting */ @@ -127,7 +131,6 @@ void BKE_mask_get_handle_point_adjacent(struct MaskSpline *spline, struct MaskSp void BKE_mask_layer_calc_handles(struct MaskLayer *masklay); void BKE_mask_layer_calc_handles_deform(struct MaskLayer *masklay); void BKE_mask_calc_handles(struct Mask *mask); -void BKE_mask_calc_handles_deform(struct Mask *mask); void BKE_mask_spline_ensure_deform(struct MaskSpline *spline); /* animation */ @@ -153,8 +156,6 @@ int BKE_mask_layer_shape_spline_from_index(struct MaskLayer *masklay, int index, struct MaskSpline **r_masklay_shape, int *r_index); int BKE_mask_layer_shape_spline_to_index(struct MaskLayer *masklay, struct MaskSpline *spline); -int BKE_mask_layer_shape_spline_index(struct MaskLayer *masklay, int index, - struct MaskSpline **r_masklay_shape, int *r_index); void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay, int index, int do_init, int do_init_interpolate); diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 739b63ca174..25d2678ea47 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -51,9 +51,10 @@ struct ImBuf *BKE_movieclip_get_postprocessed_ibuf(struct MovieClip *clip, struc struct ImBuf *BKE_movieclip_get_stable_ibuf(struct MovieClip *clip, struct MovieClipUser *user, float loc[2], float *scale, float *angle, int postprocess_flag); struct ImBuf *BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, struct MovieClipUser *user, int flag, int cache_flag); void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height); -int BKE_movieclip_get_duration(struct MovieClip *clip); -void BKE_movieclip_aspect(struct MovieClip *clip, float *aspx, float *aspy); -int BKE_movieclip_has_frame(struct MovieClip *clip, struct MovieClipUser *user); +void BKE_movieclip_get_size_fl(struct MovieClip *clip, struct MovieClipUser *user, float size[2]); +int BKE_movieclip_get_duration(struct MovieClip *clip); +void BKE_movieclip_get_aspect(struct MovieClip *clip, float *aspx, float *aspy); +int BKE_movieclip_has_frame(struct MovieClip *clip, struct MovieClipUser *user); void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr); void BKE_movieclip_update_scopes(struct MovieClip *clip, struct MovieClipUser *user, struct MovieClipScopes *scopes); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index c8b69898daa..438d5110666 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -546,6 +546,7 @@ struct ShadeResult; #define SH_NODE_LIGHT_FALLOFF 166 #define SH_NODE_OBJECT_INFO 167 #define SH_NODE_PARTICLE_INFO 168 +#define SH_NODE_TEX_BRICK 169 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 diff --git a/source/blender/blenkernel/BKE_object_deform.h b/source/blender/blenkernel/BKE_object_deform.h new file mode 100644 index 00000000000..ecc521a77fb --- /dev/null +++ b/source/blender/blenkernel/BKE_object_deform.h @@ -0,0 +1,38 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BKE_OBJECT_DEFORM_H__ +#define __BKE_OBJECT_DEFORM_H__ + +/** \file BKE_object_deform.h + * \ingroup bke + * \brief Functions for dealing with objects and deform verts, + * used by painting and tools. + */ + +struct Object; + +char *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot); +char *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot); +char *BKE_objdef_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot); + +#endif /* __BKE_OBJECT_DEFORM_H__ */ diff --git a/source/blender/blenkernel/BKE_script.h b/source/blender/blenkernel/BKE_script.h index 9976009c4c2..c3789733a04 100644 --- a/source/blender/blenkernel/BKE_script.h +++ b/source/blender/blenkernel/BKE_script.h @@ -40,8 +40,6 @@ extern "C" { struct Script; -void free_script(struct Script *script); - #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 2a90bb2c679..51a64c97ca6 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -291,12 +291,13 @@ void BKE_sequencer_dupe_animdata(struct Scene *scene, const char *name_src, cons int BKE_sequence_base_shuffle(struct ListBase *seqbasep, struct Sequence *test, struct Scene *evil_scene); int BKE_sequence_base_shuffle_time(ListBase *seqbasep, struct Scene *evil_scene); int BKE_sequence_base_isolated_sel_check(struct ListBase *seqbase); -void BKE_sequencer_free_imbuf(struct Scene *scene, struct ListBase *seqbasep, int check_mem_usage, int keep_file_handles); +void BKE_sequencer_free_imbuf(struct Scene *scene, struct ListBase *seqbasep, int for_render); struct Sequence *BKE_sequence_dupli_recursive(struct Scene *scene, struct Scene *scene_to, struct Sequence *seq, int dupe_flag); int BKE_sequence_swap(struct Sequence *seq_a, struct Sequence *seq_b, const char **error_str); int BKE_sequence_check_depend(struct Sequence *seq, struct Sequence *cur); void BKE_sequence_invalidate_cache(struct Scene *scene, struct Sequence *seq); +void BKE_sequence_invalidate_deendent(struct Scene *scene, struct Sequence *seq); void BKE_sequence_invalidate_cache_for_modifier(struct Scene *scene, struct Sequence *seq); void BKE_sequencer_update_sound_bounds_all(struct Scene *scene); @@ -380,7 +381,7 @@ typedef struct SequenceModifierTypeInfo { void (*copy_data) (struct SequenceModifierData *smd, struct SequenceModifierData *target); /* apply modifier on a given image buffer */ - struct ImBuf *(*apply) (struct SequenceModifierData *smd, struct ImBuf *ibuf, struct ImBuf *mask); + void (*apply) (struct SequenceModifierData *smd, struct ImBuf *ibuf, struct ImBuf *mask); } SequenceModifierTypeInfo; struct SequenceModifierTypeInfo *BKE_sequence_modifier_type_info_get(int type); diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h index a7b03cef933..d1332ba937e 100644 --- a/source/blender/blenkernel/BKE_shrinkwrap.h +++ b/source/blender/blenkernel/BKE_shrinkwrap.h @@ -52,7 +52,7 @@ struct DerivedMesh *object_get_derived_final(struct Object *ob); * the matrix calculation. * * A SpaceTransform is initialized using: - * space_transform_setup( &data, ob1, ob2 ) + * SPACE_TRANSFORM_SETUP( &data, ob1, ob2 ) * * After that the following calls can be used: * space_transform_apply (&data, co); //converts a coordinate in ob1 coords space to the corresponding ob2 coords @@ -75,7 +75,7 @@ void space_transform_from_matrixs(struct SpaceTransform *data, float local[4][4] void space_transform_apply(const struct SpaceTransform *data, float co[3]); void space_transform_invert(const struct SpaceTransform *data, float co[3]); -#define space_transform_setup(data, local, target) space_transform_from_matrixs(data, (local)->obmat, (target)->obmat) +#define SPACE_TRANSFORM_SETUP(data, local, target) space_transform_from_matrixs(data, (local)->obmat, (target)->obmat) /* Shrinkwrap stuff */ #include "BKE_bvhutils.h" @@ -126,7 +126,7 @@ void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, struct Object /* * This function casts a ray in the given BVHTree.. but it takes into consideration the space_transform, that is: * - * if transf was configured with "space_transform_setup( &transf, ob1, ob2 )" + * if transf was configured with "SPACE_TRANSFORM_SETUP( &transf, ob1, ob2 )" * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space * and the BVHTree must be built in ob2 coordinate space. * diff --git a/source/blender/blenkernel/BKE_tessmesh.h b/source/blender/blenkernel/BKE_tessmesh.h index 3a806651d61..dea5e726671 100644 --- a/source/blender/blenkernel/BKE_tessmesh.h +++ b/source/blender/blenkernel/BKE_tessmesh.h @@ -72,10 +72,12 @@ typedef struct BMEditMesh { short selectmode; short mat_nr; - /*Mesh structure this editmesh came from, if it came from one*/ - struct Mesh *me; + /* Object this editmesh came from (if it came from one) */ struct Object *ob; + /* Unused for now, we could bring it back and assign in the same way 'ob' is */ + // struct Mesh *me; + /*temp variables for x-mirror editing*/ int mirror_cdlayer; /* -1 is invalid */ int mirr_free_arrays; diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index 0ed2db2aad2..63f5ec59a0b 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -15,13 +15,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * * ***** END GPL LICENSE BLOCK ***** */ @@ -39,48 +32,7 @@ extern "C" { #endif -/* these values need to be hardcoded in structs, dna does not recognize defines */ -/* also defined in DNA_space_types.h */ -#ifndef FILE_MAXDIR -#define FILE_MAXDIR 768 -#define FILE_MAXFILE 256 -#define FILE_MAX 1024 -#endif - -/* this weirdo pops up in two places ... */ -#if !defined(WIN32) -# ifndef O_BINARY -# define O_BINARY 0 -# endif -#endif - -/* INTEGER CODES */ -#ifdef __BIG_ENDIAN__ -/* Big Endian */ -# define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) -#else -/* Little Endian */ -# define MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) -#endif - -#define DATA MAKE_ID('D', 'A', 'T', 'A') -#define GLOB MAKE_ID('G', 'L', 'O', 'B') - -#define DNA1 MAKE_ID('D', 'N', 'A', '1') -#define TEST MAKE_ID('T', 'E', 'S', 'T') /* used as preview between 'REND' and 'GLOB' */ -#define REND MAKE_ID('R', 'E', 'N', 'D') -#define USER MAKE_ID('U', 'S', 'E', 'R') - -#define ENDB MAKE_ID('E', 'N', 'D', 'B') - -/* Bit operations */ -#define BTST(a, b) ( ( (a) & 1 << (b) ) != 0) -#define BNTST(a, b) ( ( (a) & 1 << (b) ) == 0) -#define BTST2(a, b, c) (BTST( (a), (b) ) || BTST( (a), (c) ) ) -#define BSET(a, b) ( (a) | 1 << (b) ) -#define BCLR(a, b) ( (a) & ~(1 << (b)) ) -/* bit-row */ -#define BROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) +/* currently unused but we may want to add macros here for BKE later */ #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h index 67896fffc4d..7a23bff0184 100644 --- a/source/blender/blenkernel/BKE_world.h +++ b/source/blender/blenkernel/BKE_world.h @@ -35,7 +35,8 @@ struct World; -void BKE_world_free(struct World *sc); +void BKE_world_free(struct World *sc); +void BKE_world_free_ex(struct World *sc, int do_id_user); struct World *add_world(const char *name); struct World *BKE_world_copy(struct World *wrld); struct World *localize_world(struct World *wrld); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index d6422e89997..c89d0ecb142 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -116,6 +116,7 @@ set(SRC intern/nla.c intern/node.c intern/object.c + intern/object_deform.c intern/ocean.c intern/packedFile.c intern/paint.c @@ -205,6 +206,7 @@ set(SRC BKE_nla.h BKE_node.h BKE_object.h + BKE_object_deform.h BKE_ocean.h BKE_packedFile.h BKE_paint.h diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index a29484638c0..8c0aea5723f 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -59,6 +59,7 @@ #include "BKE_modifier.h" #include "BKE_mesh.h" #include "BKE_object.h" +#include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_texture.h" #include "BKE_multires.h" @@ -1015,14 +1016,14 @@ static void calc_weightpaint_vert_color( unsigned char r_col[4], MDeformVert *dv, ColorBand *coba, const int defbase_tot, const int defbase_act, - const char *dg_flags, - const int selected, const int draw_flag) + const char *defbase_sel, const int defbase_sel_tot, + const int draw_flag) { float input = 0.0f; int make_black = FALSE; - if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { + if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { int was_a_nonzero = FALSE; unsigned int i; @@ -1031,7 +1032,7 @@ static void calc_weightpaint_vert_color( /* in multipaint, get the average if auto normalize is inactive * get the sum if it is active */ if (dw->def_nr < defbase_tot) { - if (dg_flags[dw->def_nr]) { + if (defbase_sel[dw->def_nr]) { if (dw->weight) { input += dw->weight; was_a_nonzero = TRUE; @@ -1045,7 +1046,7 @@ static void calc_weightpaint_vert_color( make_black = TRUE; } else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) { - input /= selected; /* get the average */ + input /= defbase_sel_tot; /* get the average */ } } else { @@ -1090,14 +1091,21 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i /* variables for multipaint */ const int defbase_tot = BLI_countlist(&ob->defbase); const int defbase_act = ob->actdef - 1; - char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__); - const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot); + + int defbase_sel_tot = 0; + char *defbase_sel = NULL; + + if (draw_flag & CALC_WP_MULTIPAINT) { + defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot); + } for (i = numVerts; i != 0; i--, wc += 4, dv++) { - calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, dg_flags, selected, draw_flag); + calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag); } - MEM_freeN(dg_flags); + if (defbase_sel) { + MEM_freeN(defbase_sel); + } } else { int col_i; @@ -2073,7 +2081,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D if ((*final_r)->type != DM_TYPE_EDITBMESH) { DM_ensure_tessface(*final_r); } - if (cage_r) { + if (cage_r && *cage_r) { if ((*cage_r)->type != DM_TYPE_EDITBMESH) { if (*cage_r != *final_r) { DM_ensure_tessface(*cage_r); @@ -3187,4 +3195,25 @@ void DM_debug_print(DerivedMesh *dm) MEM_freeN(str); } +void DM_debug_print_cdlayers(CustomData *data) +{ + int i; + CustomDataLayer *layer; + + printf("{\n"); + + for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) { + + const char *name = CustomData_layertype_name(layer->type); + const int size = CustomData_sizeof(layer->type); + const char *structname; + int structnum; + CustomData_file_write_info(layer->type, &structname, &structnum); + printf(" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n", + name, structname, layer->type, (void *)layer->data, size, (int)(MEM_allocN_len(layer->data) / size)); + } + + printf("}\n"); +} + #endif /* NDEBUG */ diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 6a8ddd8e00a..06bf5211abb 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -526,18 +526,12 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) bPose *outPose; bPoseChannel *pchan; ListBase listb; - + if (!src) { *dst = NULL; return; } - if (*dst == src) { - printf("BKE_pose_copy_data source and target are the same\n"); - *dst = NULL; - return; - } - outPose = MEM_callocN(sizeof(bPose), "pose"); BLI_duplicatelist(&outPose->chanbase, &src->chanbase); @@ -810,7 +804,7 @@ void framechange_poses_clear_unkeyed(void) /* TODO: proxies may/may not be correctly handled here... (this needs checking) */ for (ob = G.main->object.first; ob; ob = ob->id.next) { /* we only need to do this on objects with a pose */ - if ( (pose = ob->pose) ) { + if ((pose = ob->pose)) { for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->bone) pchan->bone->flag &= ~BONE_UNKEYED; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 9b4f0a31e28..1b301ba43b3 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -63,7 +63,6 @@ #include "BKE_object.h" #include "BKE_particle.h" #include "BKE_scene.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_depsgraph.h" #include "BKE_anim.h" @@ -75,7 +74,8 @@ /* --------------------- */ /* forward declarations */ -static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, int level, int animated); +static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, + int level, short animated, short update); /* ******************************************************************** */ /* Animation Visualization */ @@ -494,36 +494,42 @@ void calc_curvepath(Object *ob) /* in a path vertices are with equal differences: path->len = number of verts */ /* NOW WITH BEVELCURVE!!! */ - if (ob == NULL || ob->type != OB_CURVE) return; + if (ob == NULL || ob->type != OB_CURVE) { + return; + } cu = ob->data; - nurbs = BKE_curve_nurbs_get(cu); - nu = nurbs->first; - if (cu->path) free_path(cu->path); cu->path = NULL; + /* weak! can only use first curve */ bl = cu->bev.first; - if (bl == NULL || !bl->nr) return; + if (bl == NULL || !bl->nr) { + return; + } + + nurbs = BKE_curve_nurbs_get(cu); + nu = nurbs->first; cu->path = path = MEM_callocN(sizeof(Path), "calc_curvepath"); /* if POLY: last vertice != first vertice */ cycl = (bl->poly != -1); - if (cycl) tot = bl->nr; - else tot = bl->nr - 1; + tot = cycl ? bl->nr : bl->nr - 1; path->len = tot + 1; /* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */ - if (path->len < nu->resolu * SEGMENTSU(nu)) path->len = nu->resolu * SEGMENTSU(nu); + if (path->len < nu->resolu * SEGMENTSU(nu)) { + path->len = nu->resolu * SEGMENTSU(nu); + } dist = (float *)MEM_mallocN((tot + 1) * 4, "calcpathdist"); /* all lengths in *dist */ bevp = bevpfirst = (BevPoint *)(bl + 1); fp = dist; - *fp = 0; + *fp = 0.0f; for (a = 0; a < tot; a++) { fp++; if (cycl && a == tot - 1) @@ -558,19 +564,16 @@ void calc_curvepath(Object *ob) fp++; if (bevp < bevplast) bevp++; bevpn = bevp + 1; - if (bevpn > bevplast) { - if (cycl) bevpn = bevpfirst; - else bevpn = bevplast; + if (UNLIKELY(bevpn > bevplast)) { + bevpn = cycl ? bevpfirst : bevplast; } } - fac1 = *(fp) - *(fp - 1); - fac2 = *(fp) - d; - fac1 = fac2 / fac1; + fac1 = (*(fp) - d) / (*(fp) - *(fp - 1)); fac2 = 1.0f - fac1; - + interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2); - pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa; + pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa; pp->radius = fac1 * bevp->radius + fac2 * bevpn->radius; pp->weight = fac1 * bevp->weight + fac2 * bevpn->weight; interp_qt_qtqt(pp->quat, bevp->quat, bevpn->quat, fac2); @@ -582,18 +585,14 @@ void calc_curvepath(Object *ob) MEM_freeN(dist); } - -/* is this only used internally?*/ -int interval_test(int min, int max, int p1, int cycl) +static int interval_test(const int min, const int max, int p1, const int cycl) { if (cycl) { - if (p1 < min) - p1 = ((p1 - min) % (max - min + 1)) + max + 1; - else if (p1 > max) - p1 = ((p1 - min) % (max - min + 1)) + min; + if (p1 < min) p1 = ((p1 - min) % (max - min + 1)) + max + 1; + else if (p1 > max) p1 = ((p1 - min) % (max - min + 1)) + min; } else { - if (p1 < min) p1 = min; + if (p1 < min) p1 = min; else if (p1 > max) p1 = max; } return p1; @@ -701,7 +700,7 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua /* ******************************************************************** */ /* Dupli-Geometry */ -static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int par_index, int type, int animated) +static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int par_index, int type, short animated) { DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject"); @@ -719,7 +718,8 @@ static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], i return dob; } -static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, int animated) +static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, + int level, short animated, short update) { DupliObject *dob; Group *group; @@ -733,8 +733,14 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde if (level > MAX_DUPLI_RECUR) return; /* handles animated groups, and */ + /* we need to check update for objects that are not in scene... */ - group_handle_recalc_and_update(scene, ob, group); + if (update) { + /* note: update is optional because we don't always need object + * transformations to be correct. Also fixes bug [#29616]. */ + group_handle_recalc_and_update(scene, ob, group); + } + animated = animated || group_is_animated(ob, group); for (go = group->gobject.first; go; go = go->next) { @@ -766,14 +772,14 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde if (go->ob->transflag & OB_DUPLI) { copy_m4_m4(dob->ob->obmat, dob->mat); - object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, par_index, level + 1, animated); + object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, par_index, level + 1, animated, update); copy_m4_m4(dob->ob->obmat, dob->omat); } } } } -static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, int animated) +static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, short animated) { extern int enable_cu_speed; /* object.c */ Object copyob; @@ -845,7 +851,8 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_ind typedef struct VertexDupliData { ID *id; /* scene or group, for recursive loops */ int level; - int animated; + short animated; + short update; ListBase *lb; float pmat[4][4]; float obmat[4][4]; /* Only used for dupliverts inside dupligroups, where the ob->obmat is modified */ @@ -901,12 +908,13 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], float tmpmat[4][4]; copy_m4_m4(tmpmat, vdd->ob->obmat); copy_m4_m4(vdd->ob->obmat, obmat); /* pretend we are really this mat */ - object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->par_index, vdd->level + 1, vdd->animated); + object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->par_index, vdd->level + 1, vdd->animated, vdd->update); copy_m4_m4(vdd->ob->obmat, tmpmat); } } -static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, int level, int animated) +static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, + int level, short animated, short update) { Object *ob, *ob_iter; Mesh *me = par->data; @@ -926,7 +934,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl /* simple preventing of too deep nested groups */ if (level > MAX_DUPLI_RECUR) return; - em = me->edit_btmesh; + em = BMEdit_FromObject(par); if (em) { dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); @@ -985,6 +993,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl vdd.id = id; vdd.level = level; vdd.animated = animated; + vdd.update = update; vdd.lb = lb; vdd.ob = ob; vdd.scene = scene; @@ -1029,7 +1038,8 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl dm->release(dm); } -static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, int level, int animated) +static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, + int level, short animated, short update) { Object *ob, *ob_iter; Base *base = NULL; @@ -1052,7 +1062,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa if (level > MAX_DUPLI_RECUR) return; copy_m4_m4(pmat, par->obmat); - em = me->edit_btmesh; + em = BMEdit_FromObject(par); if (em) { dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH); @@ -1199,7 +1209,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa float tmpmat[4][4]; copy_m4_m4(tmpmat, ob->obmat); copy_m4_m4(ob->obmat, obmat); /* pretend we are really this mat */ - object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, par_index, level + 1, animated); + object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, par_index, level + 1, animated, update); copy_m4_m4(ob->obmat, tmpmat); } } @@ -1219,7 +1229,8 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa dm->release(dm); } -static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int UNUSED(par_index), ParticleSystem *psys, int level, int animated) +static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int UNUSED(par_index), ParticleSystem *psys, + int level, short animated, short update) { GroupObject *go; Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL; @@ -1302,7 +1313,9 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* gather list of objects or single object */ if (part->ren_as == PART_DRAW_GR) { - group_handle_recalc_and_update(scene, par, part->dup_group); + if (update) { + group_handle_recalc_and_update(scene, par, part->dup_group); + } if (part->draw & PART_DRAW_COUNT_GR) { for (dw = part->dupliweights.first; dw; dw = dw->next) @@ -1557,7 +1570,7 @@ static Object *find_family_object(Object **obar, char *family, char ch) } -static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_index, int level, int animated) +static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_index, int level, short animated) { Object *ob, *obar[256] = {NULL}; Curve *cu; @@ -1605,7 +1618,8 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_inde /* ------------- */ -static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, int level, int animated) +static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, + int level, short animated, short update) { if ((ob->transflag & OB_DUPLI) == 0) return; @@ -1625,11 +1639,11 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas if (ob->transflag & OB_DUPLIPARTS) { ParticleSystem *psys = ob->particlesystem.first; for (; psys; psys = psys->next) - new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, psys, level + 1, animated); + new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, psys, level + 1, animated, update); } else if (ob->transflag & OB_DUPLIVERTS) { if (ob->type == OB_MESH) { - vertex_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated); + vertex_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated, update); } else if (ob->type == OB_FONT) { if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ @@ -1639,7 +1653,7 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas } else if (ob->transflag & OB_DUPLIFACES) { if (ob->type == OB_MESH) - face_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated); + face_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated, update); } else if (ob->transflag & OB_DUPLIFRAMES) { if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ @@ -1649,7 +1663,7 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas else if (ob->transflag & OB_DUPLIGROUP) { DupliObject *dob; - group_duplilist(duplilist, scene, ob, par_index, level + 1, animated); /* now recursive */ + group_duplilist(duplilist, scene, ob, par_index, level + 1, animated, update); /* now recursive */ if (level == 0) { for (dob = duplilist->first; dob; dob = dob->next) @@ -1661,14 +1675,22 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas /* Returns a list of DupliObject * note; group dupli's already set transform matrix. see note in group_duplilist() */ -ListBase *object_duplilist(Scene *sce, Object *ob) +ListBase *object_duplilist_ex(Scene *sce, Object *ob, int update) { ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist"); duplilist->first = duplilist->last = NULL; - object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, 0); + object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, 0, update); return duplilist; } +/* note: previously updating was always done, this is why it defaults to be on + * but there are likely places it can be called without updating */ +ListBase *object_duplilist(Scene *sce, Object *ob) +{ + return object_duplilist_ex(sce, ob, TRUE); +} + + void free_object_duplilist(ListBase *lb) { DupliObject *dob; diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index ea625ec7699..cf785a4bb42 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -59,7 +59,6 @@ #include "BKE_main.h" #include "BKE_library.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -622,15 +621,30 @@ static char *rna_path_rename_fix(ID *owner_id, const char *prefix, const char *o } /* Check RNA-Paths for a list of F-Curves */ -static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths) +static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, + const char *oldKey, const char *newKey, ListBase *curves, int verify_paths) { FCurve *fcu; /* we need to check every curve... */ for (fcu = curves->first; fcu; fcu = fcu->next) { - /* firstly, handle the F-Curve's own path */ - if (fcu->rna_path) - fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths); + if (fcu->rna_path) { + char *old_path = fcu->rna_path; + + /* firstly, handle the F-Curve's own path */ + fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); + + /* if path changed and the F-Curve is grouped, check if its group also needs renaming + * (i.e. F-Curve is first of a bone's F-Curves; hence renaming this should also trigger rename) + */ + if (fcu->rna_path != old_path) { + bActionGroup *agrp = fcu->grp; + + if ((agrp) && strcmp(oldName, agrp->name)==0) { + BLI_strncpy(agrp->name, newName, sizeof(agrp->name)); + } + } + } } } @@ -676,7 +690,8 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix } /* Fix all RNA-Paths for Actions linked to NLA Strips */ -static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths) +static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, + const char *oldKey, const char *newKey, ListBase *strips, int verify_paths) { NlaStrip *strip; @@ -684,11 +699,11 @@ static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *ol for (strip = strips->first; strip; strip = strip->next) { /* fix strip's action */ if (strip->act) - fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->act->curves, verify_paths); /* ignore own F-Curves, since those are local... */ /* check sub-strips (if metas) */ - nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips, verify_paths); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->strips, verify_paths); } } @@ -718,16 +733,16 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons /* Active action and temp action */ if (adt->action) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->action->curves, verify_paths); if (adt->tmpact) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->tmpact->curves, verify_paths); /* Drivers - Drivers are really F-Curves */ drivers_path_rename_fix(owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); /* NLA Data - Animation Data for Strips */ for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) - nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths); /* free the temp names */ MEM_freeN(oldN); @@ -1152,6 +1167,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in /* set value - only for animatable numerical values */ if (RNA_property_animateable(&new_ptr, prop)) { int array_len = RNA_property_array_length(&new_ptr, prop); + int written = FALSE; if (array_len && array_index >= array_len) { if (G.debug & G_DEBUG) { @@ -1165,25 +1181,52 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (array_len) - RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value)); - else - RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value)); + if (array_len) { + if (RNA_property_boolean_get_index(&new_ptr, prop, array_index) != ANIMSYS_FLOAT_AS_BOOL(value)) { + RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value)); + written = TRUE; + } + } + else { + if (RNA_property_boolean_get(&new_ptr, prop) != ANIMSYS_FLOAT_AS_BOOL(value)) { + RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value)); + written = TRUE; + } + } break; case PROP_INT: - if (array_len) - RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value); - else - RNA_property_int_set(&new_ptr, prop, (int)value); + if (array_len) { + if (RNA_property_int_get_index(&new_ptr, prop, array_index) != (int)value) { + RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value); + written = TRUE; + } + } + else { + if (RNA_property_int_get(&new_ptr, prop) != (int)value) { + RNA_property_int_set(&new_ptr, prop, (int)value); + written = TRUE; + } + } break; case PROP_FLOAT: - if (array_len) - RNA_property_float_set_index(&new_ptr, prop, array_index, value); - else - RNA_property_float_set(&new_ptr, prop, value); + if (array_len) { + if (RNA_property_float_get_index(&new_ptr, prop, array_index) != value) { + RNA_property_float_set_index(&new_ptr, prop, array_index, value); + written = TRUE; + } + } + else { + if (RNA_property_float_get(&new_ptr, prop) != value) { + RNA_property_float_set(&new_ptr, prop, value); + written = TRUE; + } + } break; case PROP_ENUM: - RNA_property_enum_set(&new_ptr, prop, (int)value); + if (RNA_property_enum_get(&new_ptr, prop) != (int)value) { + RNA_property_enum_set(&new_ptr, prop, (int)value); + written = TRUE; + } break; default: /* nothing can be done here... so it is unsuccessful? */ @@ -1193,7 +1236,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in /* RNA property update disabled for now - [#28525] [#28690] [#28774] [#28777] */ #if 0 /* buffer property update for later flushing */ - if (RNA_property_update_check(prop)) { + if (written && RNA_property_update_check(prop)) { short skip_updates_hack = 0; /* optimization hacks: skip property updates for those properties @@ -1213,7 +1256,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in /* as long as we don't do property update, we still tag datablock * as having been updated. this flag does not cause any updates to * be run, it's for e.g. render engines to synchronize data */ - if (new_ptr.id.data) { + if (written && new_ptr.id.data) { ID *id = new_ptr.id.data; id->flag |= LIB_ID_RECALC; DAG_id_type_tag(G.main, GS(id->name)); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 04585791135..b87342f85fa 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1551,7 +1551,7 @@ void BKE_armature_where_is(bArmature *arm) static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected) { bPose *pose = ob->pose, *frompose = from->pose; - bPoseChannel *pchan, *pchanp, pchanw; + bPoseChannel *pchan, *pchanp; bConstraint *con; int error = 0; @@ -1587,31 +1587,32 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { pchanp = BKE_pose_channel_find_name(frompose, pchan->name); - + if (UNLIKELY(pchanp == NULL)) { /* happens for proxies that become invalid because of a missing link * for regulat cases it shouldn't happen at all */ } else if (pchan->bone->layer & layer_protected) { ListBase proxylocal_constraints = {NULL, NULL}; - + bPoseChannel pchanw = {NULL}; + /* copy posechannel to temp, but restore important pointers */ pchanw = *pchanp; pchanw.prev = pchan->prev; pchanw.next = pchan->next; pchanw.parent = pchan->parent; pchanw.child = pchan->child; - + /* this is freed so copy a copy, else undo crashes */ if (pchanw.prop) { pchanw.prop = IDP_CopyProperty(pchanw.prop); - + /* use the values from the the existing props */ if (pchan->prop) { IDP_SyncGroupValues(pchanw.prop, pchan->prop); } } - + /* constraints - proxy constraints are flushed... local ones are added after * 1. extract constraints not from proxy (CONSTRAINT_PROXY_LOCAL) from pchan's constraints * 2. copy proxy-pchan's constraints on-to new @@ -1622,30 +1623,30 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected extract_proxylocal_constraints(&proxylocal_constraints, &pchan->constraints); copy_constraints(&pchanw.constraints, &pchanp->constraints, FALSE); BLI_movelisttolist(&pchanw.constraints, &proxylocal_constraints); - + /* constraints - set target ob pointer to own object */ for (con = pchanw.constraints.first; con; con = con->next) { bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - + if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == from) ct->tar = ob; } - + if (cti->flush_constraint_targets) cti->flush_constraint_targets(con, &targets, 0); } } - + /* free stuff from current channel */ BKE_pose_channel_free(pchan); - - /* the final copy */ + + /* copy data in temp back over to the cleaned-out (but still allocated) original channel */ *pchan = pchanw; } else { @@ -2516,36 +2517,6 @@ void BKE_pose_where_is(Scene *scene, Object *ob) } } - -/* Returns total selected vgroups, - * wpi.defbase_sel is assumed malloc'd, all values are set */ -int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_tot) -{ - bDeformGroup *defgroup; - unsigned int i; - Object *armob = BKE_object_pose_armature_get(ob); - int dg_flags_sel_tot = 0; - - if (armob) { - bPose *pose = armob->pose; - for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { - bPoseChannel *pchan = BKE_pose_channel_find_name(pose, defgroup->name); - if (pchan && (pchan->bone->flag & BONE_SELECTED)) { - dg_selection[i] = TRUE; - dg_flags_sel_tot++; - } - else { - dg_selection[i] = FALSE; - } - } - } - else { - memset(dg_selection, FALSE, sizeof(char) * defbase_tot); - } - - return dg_flags_sel_tot; -} - /************** Bounding box ********************/ static int minmax_armature(Object *ob, float r_min[3], float r_max[3]) { diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 0b5d0d90c67..09519f68415 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -44,7 +44,8 @@ #include <stdio.h> #include <stddef.h> #include <string.h> -#include <fcntl.h> // for open +#include <fcntl.h> /* for open */ +#include <errno.h> #include "MEM_guardedalloc.h" @@ -80,13 +81,10 @@ #include "BKE_sound.h" #include "RE_pipeline.h" - #include "BLO_undofile.h" #include "BLO_readfile.h" #include "BLO_writefile.h" -#include "BKE_utildefines.h" - #include "RNA_access.h" #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie @@ -465,11 +463,10 @@ int blender_test_break(void) #define UNDO_DISK 0 -#define MAXUNDONAME 64 typedef struct UndoElem { struct UndoElem *next, *prev; char str[FILE_MAX]; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; MemFile memfile; uintptr_t undosize; } UndoElem; @@ -515,8 +512,13 @@ void BKE_write_undo(bContext *C, const char *name) int nr /*, success */ /* UNUSED */; UndoElem *uel; - if ( (U.uiflag & USER_GLOBALUNDO) == 0) return; - if (U.undosteps == 0) return; + if ((U.uiflag & USER_GLOBALUNDO) == 0) { + return; + } + + if (U.undosteps == 0) { + return; + } /* remove all undos after (also when curundo == NULL) */ while (undobase.last != curundo) { @@ -717,38 +719,60 @@ void BKE_undo_save_quit(void) { UndoElem *uel; MemFileChunk *chunk; - int file; char str[FILE_MAX]; - - if ( (U.uiflag & USER_GLOBALUNDO) == 0) return; - + const int flag = O_BINARY + O_WRONLY + O_CREAT + O_TRUNC + O_EXCL; + int file; + + if ((U.uiflag & USER_GLOBALUNDO) == 0) { + return; + } + uel = curundo; if (uel == NULL) { - printf("No undo buffer to save recovery file\n"); + fprintf(stderr, "No undo buffer to save recovery file\n"); return; } - + /* no undo state to save */ - if (undobase.first == undobase.last) return; - + if (undobase.first == undobase.last) { + return; + } + + /* save the undo state as quit.blend */ BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend"); - file = BLI_open(str, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666); + /* first try create the file, if it exists call without 'O_CREAT', + * to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */ + errno = 0; + file = BLI_open(str, flag, 0666); if (file == -1) { - //XXX error("Unable to save %s, check you have permissions", str); + if (errno == EEXIST) { + errno = 0; + file = BLI_open(str, flag & ~O_CREAT, 0666); + } + } + + if (file == -1) { + fprintf(stderr, "Unable to save '%s': %s\n", + str, errno ? strerror(errno) : "Unknown error opening file"); return; } - chunk = uel->memfile.chunks.first; - while (chunk) { - if (write(file, chunk->buf, chunk->size) != chunk->size) break; - chunk = chunk->next; + for (chunk = uel->memfile.chunks.first; chunk; chunk = chunk->next) { + if (write(file, chunk->buf, chunk->size) != chunk->size) { + break; + } } - + close(file); - if (chunk) ; //XXX error("Unable to save %s, internal error", str); - else printf("Saved session recovery to %s\n", str); + if (chunk) { + fprintf(stderr, "Unable to save '%s': %s\n", + str, errno ? strerror(errno) : "Unknown error writing file"); + } + else { + printf("Saved session recovery to '%s'\n", str); + } } /* sets curscene */ diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 881caec8a58..b176ed429f8 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_paint.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_curve.h" diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 00130dd3583..6b9e0921c3b 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -416,8 +416,7 @@ void constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[][4] static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[][4]) { DerivedMesh *dm = NULL; - Mesh *me = ob->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(ob); float vec[3] = {0.0f, 0.0f, 0.0f}; float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3]; float imat[3][3], tmat[3][3]; @@ -4292,8 +4291,8 @@ bConstraintTypeInfo *get_constraint_typeinfo(int type) } /* only return for valid types */ - if ( (type >= CONSTRAINT_TYPE_NULL) && - (type < NUM_CONSTRAINT_TYPES) ) + if ((type >= CONSTRAINT_TYPE_NULL) && + (type < NUM_CONSTRAINT_TYPES)) { /* there shouldn't be any segfaults here... */ return constraintsTypeInfo[type]; @@ -4514,7 +4513,7 @@ static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED * since we've got the actual ID block, let's just inline this * code. * - * See ID_NEW(a) in BKE_utildefines.h + * See ID_NEW(a) in DNA_ID.h */ if ((*idpoin) && (*idpoin)->newid) (*idpoin) = (void *)(*idpoin)->newid; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index a00bea38e51..342ee5bba41 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -51,7 +51,6 @@ #include "BLI_mempool.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "BKE_customdata.h" #include "BKE_customdata_file.h" #include "BKE_global.h" diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c index 71801c4729f..78449879f72 100644 --- a/source/blender/blenkernel/intern/customdata_file.c +++ b/source/blender/blenkernel/intern/customdata_file.c @@ -32,6 +32,7 @@ #include "BLI_fileops.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BKE_customdata_file.h" #include "BKE_global.h" @@ -165,9 +166,9 @@ static int cdf_read_header(CDataFile *cdf) header->endian = cdf_endian(); if (cdf->switchendian) { - SWITCH_INT(header->type); - SWITCH_INT(header->totlayer); - SWITCH_INT(header->structbytes); + BLI_endian_switch_int32(&header->type); + BLI_endian_switch_int32(&header->totlayer); + BLI_endian_switch_int32(&header->structbytes); } if (!ELEM(header->type, CDF_TYPE_IMAGE, CDF_TYPE_MESH)) @@ -185,10 +186,10 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) { - SWITCH_INT(image->width); - SWITCH_INT(image->height); - SWITCH_INT(image->tile_size); - SWITCH_INT(image->structbytes); + BLI_endian_switch_int32(&image->width); + BLI_endian_switch_int32(&image->height); + BLI_endian_switch_int32(&image->tile_size); + BLI_endian_switch_int32(&image->structbytes); } offset += image->structbytes; @@ -200,7 +201,7 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) - SWITCH_INT(mesh->structbytes); + BLI_endian_switch_int32(&mesh->structbytes); offset += mesh->structbytes; mesh->structbytes = sizeof(CDataFileMeshHeader); @@ -219,10 +220,10 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) { - SWITCH_INT(layer->type); - SWITCH_INT(layer->datatype); - SWITCH_INT64(layer->datasize); - SWITCH_INT(layer->structbytes); + BLI_endian_switch_int32(&layer->type); + BLI_endian_switch_int32(&layer->datatype); + BLI_endian_switch_uint64(&layer->datasize); + BLI_endian_switch_int32(&layer->structbytes); } if (layer->datatype != CDF_DATA_FLOAT) @@ -317,20 +318,13 @@ int cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay) int cdf_read_data(CDataFile *cdf, unsigned int size, void *data) { - float *fdata; - unsigned int a; - /* read data */ if (!fread(data, size, 1, cdf->readf)) return 0; /* switch endian if necessary */ if (cdf->switchendian) { - fdata = data; - - for (a = 0; a < size / sizeof(float); a++) { - SWITCH_INT(fdata[a]); - } + BLI_endian_switch_float_array(data, size / sizeof(float)); } return 1; diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 547a64a70d4..4110d4565b2 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -33,6 +33,7 @@ #include <string.h> #include <math.h> #include <ctype.h> +#include <stdlib.h> #include "MEM_guardedalloc.h" @@ -41,7 +42,10 @@ #include "BKE_deform.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_path_util.h" +#include "BLI_string.h" #include "BLI_utildefines.h" @@ -204,13 +208,15 @@ void defvert_normalize(MDeformVert *dvert) } } -void defvert_normalize_lock(MDeformVert *dvert, const int def_nr_lock) +void defvert_normalize_lock_single(MDeformVert *dvert, const int def_nr_lock) { if (dvert->totweight <= 0) { /* nothing */ } else if (dvert->totweight == 1) { - dvert->dw[0].weight = 1.0f; + if (def_nr_lock != 0) { + dvert->dw[0].weight = 1.0f; + } } else { MDeformWeight *dw_lock = NULL; @@ -246,6 +252,50 @@ void defvert_normalize_lock(MDeformVert *dvert, const int def_nr_lock) } } +void defvert_normalize_lock_map(MDeformVert *dvert, const char *lock_flags, const int defbase_tot) +{ + if (dvert->totweight <= 0) { + /* nothing */ + } + else if (dvert->totweight == 1) { + if (LIKELY(defbase_tot >= 1) && lock_flags[0]) { + dvert->dw[0].weight = 1.0f; + } + } + else { + MDeformWeight *dw; + unsigned int i; + float tot_weight = 0.0f; + float lock_iweight = 0.0f; + + for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + if ((dw->def_nr < defbase_tot) && (lock_flags[dw->def_nr] == FALSE)) { + tot_weight += dw->weight; + } + else { + /* invert after */ + lock_iweight += dw->weight; + } + } + + lock_iweight = maxf(0.0f, 1.0f - lock_iweight); + + if (tot_weight > 0.0f) { + /* paranoid, should be 1.0 but in case of float error clamp anyway */ + + float scalar = (1.0f / tot_weight) * lock_iweight; + for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + if ((dw->def_nr < defbase_tot) && (lock_flags[dw->def_nr] == FALSE)) { + dw->weight *= scalar; + + /* in case of division errors with very low weights */ + CLAMP(dw->weight, 0.0f, 1.0f); + } + } + } + } +} + void defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len) { MDeformWeight *dw; diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 1b53f8980cb..b8d5294eabc 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -75,7 +75,6 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_tracking.h" -#include "BKE_utildefines.h" #include "depsgraph_private.h" diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 06807dfcbad..f47ac641cf9 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -2595,7 +2595,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam int format = (surface->image_fileformat & MOD_DPAINT_IMGFORMAT_OPENEXR) ? R_IMF_IMTYPE_OPENEXR : R_IMF_IMTYPE_PNG; char output_file[FILE_MAX]; - if (!sData || !sData->type_data) { setError(surface->canvas, "Image save failed: Invalid surface."); return; } + if (!sData->type_data) { setError(surface->canvas, "Image save failed: Invalid surface."); return; } /* if selected format is openexr, but current build doesnt support one */ #ifndef WITH_OPENEXR if (format == R_IMF_IMTYPE_OPENEXR) format = R_IMF_IMTYPE_PNG; @@ -4800,7 +4800,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su PaintBakeData *bData = sData->bData; DynamicPaintCanvasSettings *canvas = surface->canvas; int ret = 1; - if (!sData || sData->total_points < 1) return 0; + if (sData->total_points < 1) return 0; dynamicPaint_surfacePreStep(surface, timescale); /* @@ -4875,7 +4875,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* Apply brush on the surface depending on it's collision type */ /* Particle brush: */ if (brush->collision == MOD_DPAINT_COL_PSYS) { - if (brush && brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER && + if (brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER && psys_check_enabled(brushObj, brush->psys)) { diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index c6ba6a0d841..befec1907da 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -1747,5 +1747,11 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, BMEditMesh *BMEdit_FromObject(Object *ob) { BLI_assert(ob->type == OB_MESH); + /* sanity check */ +#ifndef NDEBUG + if (((Mesh *)ob->data)->edit_btmesh) { + BLI_assert(((Mesh *)ob->data)->edit_btmesh->ob == ob); + } +#endif return ((Mesh *)ob->data)->edit_btmesh; } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 53c12d32bc1..2dbc63e6944 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -55,7 +55,6 @@ #include "BKE_curve.h" #include "BKE_global.h" #include "BKE_object.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -75,12 +74,10 @@ void free_fcurve(FCurve *fcu) { if (fcu == NULL) return; - + /* free curve data */ - if (fcu) { - if (fcu->bezt) MEM_freeN(fcu->bezt); - if (fcu->fpt) MEM_freeN(fcu->fpt); - } + if (fcu->bezt) MEM_freeN(fcu->bezt); + if (fcu->fpt) MEM_freeN(fcu->fpt); /* free RNA-path, as this were allocated when getting the path string */ if (fcu->rna_path) @@ -507,8 +504,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo xmaxv = MAX3(xmaxv, bezt_last->vec[1][0], bezt_last->vec[2][0]); } else { - xminv = MIN2(xminv, bezt_first->vec[1][0]); - xmaxv = MAX2(xmaxv, bezt_last->vec[1][0]); + xminv = minf(xminv, bezt_first->vec[1][0]); + xmaxv = maxf(xmaxv, bezt_last->vec[1][0]); } } } @@ -524,8 +521,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo ymaxv = MAX4(ymaxv, bezt->vec[1][1], bezt->vec[0][1], bezt->vec[2][1]); } else { - yminv = MIN2(yminv, bezt->vec[1][1]); - ymaxv = MAX2(ymaxv, bezt->vec[1][1]); + yminv = minf(yminv, bezt->vec[1][1]); + ymaxv = maxf(ymaxv, bezt->vec[1][1]); } foundvert = TRUE; @@ -536,8 +533,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo else if (fcu->fpt) { /* frame range can be directly calculated from end verts */ if (xmin || xmax) { - xminv = MIN2(xminv, fcu->fpt[0].vec[0]); - xmaxv = MAX2(xmaxv, fcu->fpt[fcu->totvert - 1].vec[0]); + xminv = minf(xminv, fcu->fpt[0].vec[0]); + xmaxv = maxf(xmaxv, fcu->fpt[fcu->totvert - 1].vec[0]); } /* only loop over keyframes to find extents for values if needed */ @@ -594,15 +591,15 @@ void calc_fcurve_range(FCurve *fcu, float *start, float *end, if (bezt_first) { BLI_assert(bezt_last != NULL); - min = MIN2(min, bezt_first->vec[1][0]); - max = MAX2(max, bezt_last->vec[1][0]); + min = minf(min, bezt_first->vec[1][0]); + max = maxf(max, bezt_last->vec[1][0]); foundvert = TRUE; } } else if (fcu->fpt) { - min = MIN2(min, fcu->fpt[0].vec[0]); - max = MAX2(max, fcu->fpt[fcu->totvert - 1].vec[0]); + min = minf(min, fcu->fpt[0].vec[0]); + max = maxf(max, fcu->fpt[fcu->totvert - 1].vec[0]); foundvert = TRUE; } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 438188b1e2a..538d2469a93 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -965,8 +965,8 @@ FModifierTypeInfo *get_fmodifier_typeinfo(int type) } /* only return for valid types */ - if ( (type >= FMODIFIER_TYPE_NULL) && - (type <= FMODIFIER_NUM_TYPES) ) + if ((type >= FMODIFIER_TYPE_NULL) && + (type < FMODIFIER_NUM_TYPES)) { /* there shouldn't be any segfaults here... */ return fmodifiersTypeInfo[type]; diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 0ffd68c9079..8b35974ea62 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -50,7 +50,6 @@ #include "DNA_scene_types.h" #include "DNA_object_types.h" -#include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "BKE_library.h" #include "BKE_font.h" diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 7456f9aab8b..8229df28ab8 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -293,18 +293,6 @@ static IDProperty *IDP_CopyArray(IDProperty *prop) return newp; } -/*taken from readfile.c*/ -#define SWITCH_LONGINT(a) { \ - char s_i, *p_i; \ - p_i = (char *)& (a); \ - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \ - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \ - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; \ - } (void)0 - - - /* ---------- String Type ------------ */ IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 2b2128439c7..3f756e74b26 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -79,7 +79,6 @@ #include "BKE_scene.h" #include "BKE_node.h" #include "BKE_sequencer.h" /* seq_foreground_frame_get() */ -#include "BKE_utildefines.h" #include "BLF_api.h" @@ -595,7 +594,7 @@ Image *BKE_image_load_exists(const char *filepath) return BKE_image_load(filepath); } -static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) +static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4]) { ImBuf *ibuf; unsigned char *rect = NULL; @@ -615,11 +614,11 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char BLI_strncpy(ibuf->name, name, sizeof(ibuf->name)); ibuf->userflags |= IB_BITMAPDIRTY; - switch (uvtestgrid) { - case 1: + switch (gen_type) { + case IMA_GENTYPE_GRID: BKE_image_buf_fill_checker(rect, rect_float, width, height); break; - case 2: + case IMA_GENTYPE_GRID_COLOR: BKE_image_buf_fill_checker_color(rect, rect_float, width, height); break; default: @@ -630,7 +629,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char } /* adds new image block, creates ImBuf and initializes color */ -Image *BKE_image_add_generated(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) +Image *BKE_image_add_generated(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4]) { /* on save, type is changed to FILE in editsima.c */ Image *ima = image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); @@ -641,10 +640,10 @@ Image *BKE_image_add_generated(unsigned int width, unsigned int height, const ch /* BLI_strncpy(ima->name, name, FILE_MAX); */ /* don't do this, this writes in ain invalid filepath! */ ima->gen_x = width; ima->gen_y = height; - ima->gen_type = uvtestgrid; + ima->gen_type = gen_type; ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0); - ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, uvtestgrid, color); + ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); ima->ok = IMA_OK_LOADED; @@ -2527,7 +2526,9 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ dither = iuser->scene->r.dither_intensity; /* combined layer gets added as first layer */ - if (rres.have_combined && layer == 0) ; + if (rres.have_combined && layer == 0) { + /* pass */ + } else if (rres.layers.first) { RenderLayer *rl = BLI_findlink(&rres.layers, layer - (rres.have_combined ? 1 : 0)); if (rl) { @@ -2930,3 +2931,40 @@ int BKE_image_has_alpha(struct Image *image) else return 0; } + +void BKE_image_get_size(Image *image, ImageUser *iuser, int *width, int *height) +{ + ImBuf *ibuf = NULL; + void *lock; + + ibuf = BKE_image_acquire_ibuf(image, iuser, &lock); + + if (ibuf && ibuf->x > 0 && ibuf->y > 0) { + *width = ibuf->x; + *height = ibuf->y; + } + else { + *width = IMG_SIZE_FALLBACK; + *height = IMG_SIZE_FALLBACK; + } + + BKE_image_release_ibuf(image, lock); +} + +void BKE_image_get_size_fl(Image *image, ImageUser *iuser, float size[2]) +{ + int width, height; + BKE_image_get_size(image, iuser, &width, &height); + + size[0] = (float)width; + size[1] = (float)height; + +} + +void BKE_image_get_aspect(Image *image, float *aspx, float *aspy) +{ + *aspx = 1.0; + + /* x is always 1 */ + *aspy = image->aspy / image->aspx; +} diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 616214c21ff..1c6974b2615 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -193,7 +193,7 @@ DO_INLINE lfVector *create_lfvector(unsigned int verts) DO_INLINE void del_lfvector(float (*fLongVector)[3]) { if (fLongVector != NULL) { - MEM_freeN (fLongVector); + MEM_freeN(fLongVector); // cloth_aligned_free(&MEMORY_BASE, fLongVector); } } @@ -523,7 +523,7 @@ DO_INLINE fmatrix3x3 *create_bfmatrix(unsigned int verts, unsigned int springs) DO_INLINE void del_bfmatrix(fmatrix3x3 *matrix) { if (matrix != NULL) { - MEM_freeN (matrix); + MEM_freeN(matrix); } } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 17a3c595ea7..b79608342dd 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -691,8 +691,8 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const if (nu->bp) { step = nu->pntsu * nu->pntsv; - a1 = MAX2(a, start); - a2 = MIN2(a + step, end); + a1 = maxi(a, start); + a2 = mini(a + step, end); if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT); } @@ -700,8 +700,8 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const step = 3 * nu->pntsu; /* exception because keys prefer to work with complete blocks */ - a1 = MAX2(a, start); - a2 = MIN2(a + step, end); + a1 = maxi(a, start); + a2 = mini(a + step, end); if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BEZTRIPLE); } @@ -1217,7 +1217,7 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, const in remain = step; } - count = MIN2(remain, estep); + count = mini(remain, estep); if (mode == KEY_MODE_BEZTRIPLE) { count += 3 - count % 3; } @@ -1573,7 +1573,7 @@ void key_to_latt(KeyBlock *kb, Lattice *lt) fp = kb->data; tot = lt->pntsu * lt->pntsv * lt->pntsw; - tot = MIN2(kb->totelem, tot); + tot = mini(kb->totelem, tot); for (a = 0; a < tot; a++, fp += 3, bp++) { copy_v3_v3(bp->vec, fp); @@ -1645,7 +1645,7 @@ void key_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) tot = BKE_nurbList_verts_count(nurb); - tot = MIN2(kb->totelem, tot); + tot = mini(kb->totelem, tot); while (nu && tot > 0) { @@ -1713,7 +1713,7 @@ void key_to_mesh(KeyBlock *kb, Mesh *me) mvert = me->mvert; fp = kb->data; - tot = MIN2(kb->totelem, me->totvert); + tot = mini(kb->totelem, me->totvert); for (a = 0; a < tot; a++, fp += 3, mvert++) { copy_v3_v3(mvert->co, fp); diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 0e73d10fa5f..17e4103c7d3 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -488,7 +488,7 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir /* test for cyclic */ bl = cu->bev.first; if (!bl->nr) return 0; - if (bl && bl->poly > -1) cycl = 1; + if (bl->poly > -1) cycl = 1; if (cycl == 0) { ctime1 = CLAMPIS(ctime, 0.0f, 1.0f); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 77e7623ae3d..f6e86bdbb5a 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -107,7 +107,6 @@ #include "BKE_gpencil.h" #include "BKE_fcurve.h" #include "BKE_speaker.h" -#include "BKE_utildefines.h" #include "BKE_movieclip.h" #include "BKE_mask.h" #include "BKE_linestyle.h" @@ -813,6 +812,7 @@ static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata /* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */ void BKE_libblock_free(ListBase *lb, void *idv) { + Main *bmain = G.main; /* should eventually be an arg */ ID *id = idv; #ifdef WITH_PYTHON @@ -875,7 +875,7 @@ void BKE_libblock_free(ListBase *lb, void *idv) BKE_text_free((Text *)id); break; case ID_SCRIPT: - //XXX free_script((Script *)id); + /* deprecated */ break; case ID_SPK: BKE_speaker_free((Speaker *)id); @@ -912,7 +912,7 @@ void BKE_libblock_free(ListBase *lb, void *idv) BKE_movieclip_free((MovieClip *)id); break; case ID_MSK: - BKE_mask_free((Mask *)id); + BKE_mask_free(bmain, (Mask *)id); break; case ID_LS: FRS_free_linestyle((FreestyleLineStyle *)id); @@ -927,7 +927,7 @@ void BKE_libblock_free(ListBase *lb, void *idv) BLI_remlink(lb, id); /* this ID may be a driver target! */ - BKE_animdata_main_cb(G.main, animdata_dtar_clear_cb, (void *)id); + BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id); MEM_freeN(id); } @@ -962,9 +962,52 @@ void free_main(Main *mainvar) ID *id; while ( (id = lb->first) ) { +#if 1 BKE_libblock_free(lb, id); +#else + /* errors freeing ID's can be hard to track down, + * enable this so valgrind will give the line number in its error log */ + switch (a) { + case 0: BKE_libblock_free(lb, id); break; + case 1: BKE_libblock_free(lb, id); break; + case 2: BKE_libblock_free(lb, id); break; + case 3: BKE_libblock_free(lb, id); break; + case 4: BKE_libblock_free(lb, id); break; + case 5: BKE_libblock_free(lb, id); break; + case 6: BKE_libblock_free(lb, id); break; + case 7: BKE_libblock_free(lb, id); break; + case 8: BKE_libblock_free(lb, id); break; + case 9: BKE_libblock_free(lb, id); break; + case 10: BKE_libblock_free(lb, id); break; + case 11: BKE_libblock_free(lb, id); break; + case 12: BKE_libblock_free(lb, id); break; + case 13: BKE_libblock_free(lb, id); break; + case 14: BKE_libblock_free(lb, id); break; + case 15: BKE_libblock_free(lb, id); break; + case 16: BKE_libblock_free(lb, id); break; + case 17: BKE_libblock_free(lb, id); break; + case 18: BKE_libblock_free(lb, id); break; + case 19: BKE_libblock_free(lb, id); break; + case 20: BKE_libblock_free(lb, id); break; + case 21: BKE_libblock_free(lb, id); break; + case 22: BKE_libblock_free(lb, id); break; + case 23: BKE_libblock_free(lb, id); break; + case 24: BKE_libblock_free(lb, id); break; + case 25: BKE_libblock_free(lb, id); break; + case 26: BKE_libblock_free(lb, id); break; + case 27: BKE_libblock_free(lb, id); break; + case 28: BKE_libblock_free(lb, id); break; + case 29: BKE_libblock_free(lb, id); break; + case 30: BKE_libblock_free(lb, id); break; + case 31: BKE_libblock_free(lb, id); break; + case 32: BKE_libblock_free(lb, id); break; + default: + BLI_assert(0); + } +#endif } } + a = set_listbasepointers(mainvar, lbarray); MEM_freeN(mainvar); } @@ -1543,7 +1586,7 @@ void BKE_library_filepath_set(Library *lib, const char *filepath) /* not essential but set filepath is an absolute copy of value which * is more useful if its kept in sync */ - if (strncmp(lib->filepath, "//", 2) == 0) { + if (BLI_path_is_rel(lib->filepath)) { /* note that the file may be unsaved, in this case, setting the * filepath on an indirectly linked path is not allowed from the * outliner, and its not really supported but allow from here for now diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index f73fb3879b8..97b46d4829d 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -55,6 +55,7 @@ #include "BKE_sequencer.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" +#include "BKE_image.h" static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) { @@ -909,7 +910,8 @@ void BKE_mask_layer_free_list(ListBase *masklayers) } } -void BKE_mask_free(Mask *mask) +/** free for temp copy, but don't manage unlinking from other pointers */ +void BKE_mask_free_nolib(Mask *mask) { BKE_mask_layer_free_list(&mask->masklayers); } @@ -927,7 +929,7 @@ static void ntree_unlink_mask_cb(void *calldata, struct ID *UNUSED(owner_id), st } } -void BKE_mask_unlink(Main *bmain, Mask *mask) +void BKE_mask_free(Main *bmain, Mask *mask) { bScreen *scr; ScrArea *area; @@ -990,7 +992,8 @@ void BKE_mask_unlink(Main *bmain, Mask *mask) treetype->foreach_nodetree(bmain, (void *)mask, &ntree_unlink_mask_cb); } - BKE_libblock_free(&bmain->mask, mask); + /* free mask data */ + BKE_mask_layer_free_list(&mask->masklayers); } void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]) @@ -1010,14 +1013,26 @@ void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float fra } void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { - int width, height; + float aspx, aspy; float frame_size[2]; /* scaling for the clip */ - BKE_movieclip_get_size(clip, user, &width, &height); + BKE_movieclip_get_size_fl(clip, user, frame_size); + BKE_movieclip_get_aspect(clip, &aspx, &aspy); + + frame_size[1] *= (aspy / aspx); + + BKE_mask_coord_from_frame(r_co, co, frame_size); +} +void BKE_mask_coord_from_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2]) +{ + float aspx, aspy; + float frame_size[2]; + + BKE_image_get_size_fl(image, iuser, frame_size); + BKE_image_get_aspect(image, &aspx, &aspy); - frame_size[0] = (float)width; - frame_size[1] = (float)height; + frame_size[1] *= (aspy / aspx); BKE_mask_coord_from_frame(r_co, co, frame_size); } @@ -1040,14 +1055,27 @@ void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame } void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { - int width, height; + float aspx, aspy; + float frame_size[2]; + + /* scaling for the clip */ + BKE_movieclip_get_size_fl(clip, user, frame_size); + BKE_movieclip_get_aspect(clip, &aspx, &aspy); + + frame_size[1] /= (aspy / aspx); + + BKE_mask_coord_to_frame(r_co, co, frame_size); +} +void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2]) +{ + float aspx, aspy; float frame_size[2]; /* scaling for the clip */ - BKE_movieclip_get_size(clip, user, &width, &height); + BKE_image_get_size_fl(image, iuser, frame_size); + BKE_image_get_aspect(image, &aspx, &aspy); - frame_size[0] = (float)width; - frame_size[1] = (float)height; + frame_size[1] /= (aspy / aspx); BKE_mask_coord_to_frame(r_co, co, frame_size); } diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 065dc38c81e..4a8601df0b8 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -61,7 +61,6 @@ #include "BKE_sequencer.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" -#include "BKE_utildefines.h" unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index eb96d6726b9..18617f0ef2e 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -26,6 +26,46 @@ /** \file blender/blenkernel/intern/mask_rasterize.c * \ingroup bke + * + * This module exposes a rasterizer that works as a black box - implementation details are confined to this file, + * + * The basic method to access is: + * - create & initialize a handle from a #Mask datablock. + * - execute pixel lookups. + * - free the handle. + * + * This file is admittedly a bit confusticated, in quite few areas speed was chosen over readability, + * though it is commented - so shouldn't be so hard to see whats going on. + * + * + * Implementation: + * + * To rasterize the mask its converted into geometry that use a ray-cast for each pixel lookup. + * + * Initially 'kdopbvh' was used but this ended up being too slow. + * + * To gain some extra speed we take advantage of a few shortcuts that can be made rasterizing masks specifically. + * - all triangles are known to be completely white - so no depth check is done on triangle intersection. + * - all quads are known to be feather outlines - the 1 and 0 depths are known by the vertex order in the quad, + * - there is no color - just a value for each mask pixel. + * - the mask spacial structure always maps to space 0-1 on X and Y axis. + * - bucketing is used to speed up lookups for geometry. + * + * Other Details: + * - used unsigned values all over for some extra speed on some arch's. + * - anti-aliasing is faked, just ensuring at least one pixel feather - avoids oversampling. + * - initializing the spacial structure doesn't need to be as optimized as pixel lookups are. + * - mask lookups need not be pixel aligned so any sub-pixel values from x/y (0 - 1), can be found. + * (perhaps masks can be used as a vector texture in 3D later on) + * + * + * Currently, to build the spacial structure we have to calculate the total number of faces ahead of time. + * + * This is getting a bit complicated with the addition of unfilled splines and end capping - + * If large changes are needed here we would be better off using an iterable + * BLI_mempool for triangles and converting to a contiguous array afterwards. + * + * - Campbell */ #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index a92497ffb9d..3925c3cc858 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -157,17 +157,19 @@ struct pgn_elements { /* Forward declarations */ static int vertid(const CORNER *c1, const CORNER *c2, PROCESS *p, MetaBall *mb); -static int setcenter(CENTERLIST *table[], int i, int j, int k); +static int setcenter(CENTERLIST *table[], const int i, const int j, const int k); static CORNER *setcorner(PROCESS *p, int i, int j, int k); static void converge(const float p1[3], const float p2[3], float v1, float v2, float (*function)(float, float, float), float p[3], MetaBall *mb, int f); /* Global variables */ +static struct { + float thresh; + int totelem; + MetaElem **mainb; + octal_tree *metaball_tree; +} G_mb = {0}; -static float thresh = 0.6f; -static int totelem = 0; -static MetaElem **mainb; -static octal_tree *metaball_tree = NULL; /* Functions */ void BKE_mball_unlink(MetaBall *mb) @@ -523,7 +525,7 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); - totelem = 0; + G_mb.totelem = 0; /* XXX recursion check, see scene.c, just too simple code this BKE_scene_base_iter_next() */ if (F_ERROR == BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) @@ -564,9 +566,10 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) } } - while (ml) { - if (!(ml->flag & MB_HIDE)) totelem++; - ml = ml->next; + for ( ; ml; ml = ml->next) { + if (!(ml->flag & MB_HIDE)) { + G_mb.totelem++; + } } } } @@ -637,21 +640,6 @@ static float densfunc(MetaElem *ball, float x, float y, float z) case MB_BALL: /* do nothing */ break; - case MB_TUBEX: - if (dvec[0] > ball->len) dvec[0] -= ball->len; - else if (dvec[0] < -ball->len) dvec[0] += ball->len; - else dvec[0] = 0.0; - break; - case MB_TUBEY: - if (dvec[1] > ball->len) dvec[1] -= ball->len; - else if (dvec[1] < -ball->len) dvec[1] += ball->len; - else dvec[1] = 0.0; - break; - case MB_TUBEZ: - if (dvec[2] > ball->len) dvec[2] -= ball->len; - else if (dvec[2] < -ball->len) dvec[2] += ball->len; - else dvec[2] = 0.0; - break; case MB_TUBE: if (dvec[0] > ball->expx) dvec[0] -= ball->expx; else if (dvec[0] < -ball->expx) dvec[0] += ball->expx; @@ -683,6 +671,24 @@ static float densfunc(MetaElem *ball, float x, float y, float z) else if (dvec[2] < -ball->expz) dvec[2] += ball->expz; else dvec[2] = 0.0; break; + + /* *** deprecated, could be removed?, do-versioned at least *** */ + case MB_TUBEX: + if (dvec[0] > ball->len) dvec[0] -= ball->len; + else if (dvec[0] < -ball->len) dvec[0] += ball->len; + else dvec[0] = 0.0; + break; + case MB_TUBEY: + if (dvec[1] > ball->len) dvec[1] -= ball->len; + else if (dvec[1] < -ball->len) dvec[1] += ball->len; + else dvec[1] = 0.0; + break; + case MB_TUBEZ: + if (dvec[2] > ball->len) dvec[2] -= ball->len; + else if (dvec[2] < -ball->len) dvec[2] += ball->len; + else dvec[2] = 0.0; + break; + /* *** end deprecated *** */ } dist2 = 1.0f - (len_v3(dvec) / ball->rad2); @@ -771,27 +777,27 @@ static float metaball(float x, float y, float z) float dens = 0; int a; - if (totelem > 1) { - node = find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth); + if (G_mb.totelem > 1) { + node = find_metaball_octal_node(G_mb.metaball_tree->first, x, y, z, G_mb.metaball_tree->depth); if (node) { for (ml_p = node->elems.first; ml_p; ml_p = ml_p->next) { dens += densfunc(ml_p->ml, x, y, z); } - dens += -0.5f * (metaball_tree->pos - node->pos); - dens += 0.5f * (metaball_tree->neg - node->neg); + dens += -0.5f * (G_mb.metaball_tree->pos - node->pos); + dens += 0.5f * (G_mb.metaball_tree->neg - node->neg); } else { - for (a = 0; a < totelem; a++) { - dens += densfunc(mainb[a], x, y, z); + for (a = 0; a < G_mb.totelem; a++) { + dens += densfunc(G_mb.mainb[a], x, y, z); } } } else { - dens += densfunc(mainb[0], x, y, z); + dens += densfunc(G_mb.mainb[0], x, y, z); } - return thresh - dens; + return G_mb.thresh - dens; } /* ******************************************** */ @@ -1493,7 +1499,7 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) MetaElem *ml; float f = 0.0f; - ml = mainb[a]; + ml = G_mb.mainb[a]; f = 1.0 - (mb->thresh / ml->s); /* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be @@ -1619,7 +1625,7 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb) mbproc->edges = MEM_callocN(2 * HASHSIZE * sizeof(EDGELIST *), "mbproc->edges"); makecubetable(); - for (a = 0; a < totelem; a++) { + for (a = 0; a < G_mb.totelem; a++) { /* try to find 8 points on the surface for each MetaElem */ find_first_points(mbproc, mb, a); @@ -1712,7 +1718,7 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ ml_count++; ml = ml->next; } - totelem -= ml_count; + G_mb.totelem -= ml_count; } else { while (ml) { @@ -1741,9 +1747,9 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ mult_m4_m4m4(temp1, temp2, temp3); /* make a copy because of duplicates */ - mainb[a] = new_pgn_element(sizeof(MetaElem)); - *(mainb[a]) = *ml; - mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); + G_mb.mainb[a] = new_pgn_element(sizeof(MetaElem)); + *(G_mb.mainb[a]) = *ml; + G_mb.mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); mat = new_pgn_element(4 * 4 * sizeof(float)); imat = new_pgn_element(4 * 4 * sizeof(float)); @@ -1756,70 +1762,70 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ invert_m4_m4(imat, mat); - mainb[a]->rad2 = ml->rad * ml->rad; + G_mb.mainb[a]->rad2 = ml->rad * ml->rad; - mainb[a]->mat = (float *) mat; - mainb[a]->imat = (float *) imat; + G_mb.mainb[a]->mat = (float *) mat; + G_mb.mainb[a]->imat = (float *) imat; /* untransformed Bounding Box of MetaElem */ /* 0 */ - mainb[a]->bb->vec[0][0] = -ml->expx; - mainb[a]->bb->vec[0][1] = -ml->expy; - mainb[a]->bb->vec[0][2] = -ml->expz; + G_mb.mainb[a]->bb->vec[0][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[0][1] = -ml->expy; + G_mb.mainb[a]->bb->vec[0][2] = -ml->expz; /* 1 */ - mainb[a]->bb->vec[1][0] = ml->expx; - mainb[a]->bb->vec[1][1] = -ml->expy; - mainb[a]->bb->vec[1][2] = -ml->expz; + G_mb.mainb[a]->bb->vec[1][0] = ml->expx; + G_mb.mainb[a]->bb->vec[1][1] = -ml->expy; + G_mb.mainb[a]->bb->vec[1][2] = -ml->expz; /* 2 */ - mainb[a]->bb->vec[2][0] = ml->expx; - mainb[a]->bb->vec[2][1] = ml->expy; - mainb[a]->bb->vec[2][2] = -ml->expz; + G_mb.mainb[a]->bb->vec[2][0] = ml->expx; + G_mb.mainb[a]->bb->vec[2][1] = ml->expy; + G_mb.mainb[a]->bb->vec[2][2] = -ml->expz; /* 3 */ - mainb[a]->bb->vec[3][0] = -ml->expx; - mainb[a]->bb->vec[3][1] = ml->expy; - mainb[a]->bb->vec[3][2] = -ml->expz; + G_mb.mainb[a]->bb->vec[3][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[3][1] = ml->expy; + G_mb.mainb[a]->bb->vec[3][2] = -ml->expz; /* 4 */ - mainb[a]->bb->vec[4][0] = -ml->expx; - mainb[a]->bb->vec[4][1] = -ml->expy; - mainb[a]->bb->vec[4][2] = ml->expz; + G_mb.mainb[a]->bb->vec[4][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[4][1] = -ml->expy; + G_mb.mainb[a]->bb->vec[4][2] = ml->expz; /* 5 */ - mainb[a]->bb->vec[5][0] = ml->expx; - mainb[a]->bb->vec[5][1] = -ml->expy; - mainb[a]->bb->vec[5][2] = ml->expz; + G_mb.mainb[a]->bb->vec[5][0] = ml->expx; + G_mb.mainb[a]->bb->vec[5][1] = -ml->expy; + G_mb.mainb[a]->bb->vec[5][2] = ml->expz; /* 6 */ - mainb[a]->bb->vec[6][0] = ml->expx; - mainb[a]->bb->vec[6][1] = ml->expy; - mainb[a]->bb->vec[6][2] = ml->expz; + G_mb.mainb[a]->bb->vec[6][0] = ml->expx; + G_mb.mainb[a]->bb->vec[6][1] = ml->expy; + G_mb.mainb[a]->bb->vec[6][2] = ml->expz; /* 7 */ - mainb[a]->bb->vec[7][0] = -ml->expx; - mainb[a]->bb->vec[7][1] = ml->expy; - mainb[a]->bb->vec[7][2] = ml->expz; + G_mb.mainb[a]->bb->vec[7][0] = -ml->expx; + G_mb.mainb[a]->bb->vec[7][1] = ml->expy; + G_mb.mainb[a]->bb->vec[7][2] = ml->expz; /* transformation of Metalem bb */ for (i = 0; i < 8; i++) - mul_m4_v3((float (*)[4])mat, mainb[a]->bb->vec[i]); + mul_m4_v3((float (*)[4])mat, G_mb.mainb[a]->bb->vec[i]); /* find max and min of transformed bb */ for (i = 0; i < 8; i++) { /* find maximums */ - if (mainb[a]->bb->vec[i][0] > max_x) max_x = mainb[a]->bb->vec[i][0]; - if (mainb[a]->bb->vec[i][1] > max_y) max_y = mainb[a]->bb->vec[i][1]; - if (mainb[a]->bb->vec[i][2] > max_z) max_z = mainb[a]->bb->vec[i][2]; + if (G_mb.mainb[a]->bb->vec[i][0] > max_x) max_x = G_mb.mainb[a]->bb->vec[i][0]; + if (G_mb.mainb[a]->bb->vec[i][1] > max_y) max_y = G_mb.mainb[a]->bb->vec[i][1]; + if (G_mb.mainb[a]->bb->vec[i][2] > max_z) max_z = G_mb.mainb[a]->bb->vec[i][2]; /* find minimums */ - if (mainb[a]->bb->vec[i][0] < min_x) min_x = mainb[a]->bb->vec[i][0]; - if (mainb[a]->bb->vec[i][1] < min_y) min_y = mainb[a]->bb->vec[i][1]; - if (mainb[a]->bb->vec[i][2] < min_z) min_z = mainb[a]->bb->vec[i][2]; + if (G_mb.mainb[a]->bb->vec[i][0] < min_x) min_x = G_mb.mainb[a]->bb->vec[i][0]; + if (G_mb.mainb[a]->bb->vec[i][1] < min_y) min_y = G_mb.mainb[a]->bb->vec[i][1]; + if (G_mb.mainb[a]->bb->vec[i][2] < min_z) min_z = G_mb.mainb[a]->bb->vec[i][2]; } /* create "new" bb, only point 0 and 6, which are * necessary for octal tree filling */ - mainb[a]->bb->vec[0][0] = min_x - ml->rad; - mainb[a]->bb->vec[0][1] = min_y - ml->rad; - mainb[a]->bb->vec[0][2] = min_z - ml->rad; + G_mb.mainb[a]->bb->vec[0][0] = min_x - ml->rad; + G_mb.mainb[a]->bb->vec[0][1] = min_y - ml->rad; + G_mb.mainb[a]->bb->vec[0][2] = min_z - ml->rad; - mainb[a]->bb->vec[6][0] = max_x + ml->rad; - mainb[a]->bb->vec[6][1] = max_y + ml->rad; - mainb[a]->bb->vec[6][2] = max_z + ml->rad; + G_mb.mainb[a]->bb->vec[6][0] = max_x + ml->rad; + G_mb.mainb[a]->bb->vec[6][1] = max_y + ml->rad; + G_mb.mainb[a]->bb->vec[6][2] = max_z + ml->rad; a++; } @@ -1832,13 +1838,13 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ /* totsize (= 'manhattan' radius) */ totsize = 0.0; - for (a = 0; a < totelem; a++) { + for (a = 0; a < G_mb.totelem; a++) { - vec[0] = mainb[a]->x + mainb[a]->rad + mainb[a]->expx; - vec[1] = mainb[a]->y + mainb[a]->rad + mainb[a]->expy; - vec[2] = mainb[a]->z + mainb[a]->rad + mainb[a]->expz; + vec[0] = G_mb.mainb[a]->x + G_mb.mainb[a]->rad + G_mb.mainb[a]->expx; + vec[1] = G_mb.mainb[a]->y + G_mb.mainb[a]->rad + G_mb.mainb[a]->expy; + vec[2] = G_mb.mainb[a]->z + G_mb.mainb[a]->rad + G_mb.mainb[a]->expz; - calc_mballco(mainb[a], vec); + calc_mballco(G_mb.mainb[a], vec); size = fabsf(vec[0]); if (size > totsize) totsize = size; @@ -1847,11 +1853,11 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ size = fabsf(vec[2]); if (size > totsize) totsize = size; - vec[0] = mainb[a]->x - mainb[a]->rad; - vec[1] = mainb[a]->y - mainb[a]->rad; - vec[2] = mainb[a]->z - mainb[a]->rad; + vec[0] = G_mb.mainb[a]->x - G_mb.mainb[a]->rad; + vec[1] = G_mb.mainb[a]->y - G_mb.mainb[a]->rad; + vec[2] = G_mb.mainb[a]->z - G_mb.mainb[a]->rad; - calc_mballco(mainb[a], vec); + calc_mballco(G_mb.mainb[a], vec); size = fabsf(vec[0]); if (size > totsize) totsize = size; @@ -1861,8 +1867,8 @@ static float init_meta(Scene *scene, Object *ob) /* return totsize */ if (size > totsize) totsize = size; } - for (a = 0; a < totelem; a++) { - thresh += densfunc(mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize); + for (a = 0; a < G_mb.totelem; a++) { + G_mb.thresh += densfunc(G_mb.mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize); } return totsize; @@ -2178,13 +2184,13 @@ static void init_metaball_octal_tree(int depth) float size[3]; int a; - metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); - metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); + G_mb.metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); + G_mb.metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); /* maximal depth of octree */ - metaball_tree->depth = depth; + G_mb.metaball_tree->depth = depth; - metaball_tree->neg = node->neg = 0; - metaball_tree->pos = node->pos = 0; + G_mb.metaball_tree->neg = node->neg = 0; + G_mb.metaball_tree->pos = node->pos = 0; node->elems.first = NULL; node->elems.last = NULL; @@ -2197,26 +2203,26 @@ static void init_metaball_octal_tree(int depth) node->x_max = node->y_max = node->z_max = -FLT_MAX; /* size of octal tree scene */ - for (a = 0; a < totelem; a++) { - if (mainb[a]->bb->vec[0][0] < node->x_min) node->x_min = mainb[a]->bb->vec[0][0]; - if (mainb[a]->bb->vec[0][1] < node->y_min) node->y_min = mainb[a]->bb->vec[0][1]; - if (mainb[a]->bb->vec[0][2] < node->z_min) node->z_min = mainb[a]->bb->vec[0][2]; + for (a = 0; a < G_mb.totelem; a++) { + if (G_mb.mainb[a]->bb->vec[0][0] < node->x_min) node->x_min = G_mb.mainb[a]->bb->vec[0][0]; + if (G_mb.mainb[a]->bb->vec[0][1] < node->y_min) node->y_min = G_mb.mainb[a]->bb->vec[0][1]; + if (G_mb.mainb[a]->bb->vec[0][2] < node->z_min) node->z_min = G_mb.mainb[a]->bb->vec[0][2]; - if (mainb[a]->bb->vec[6][0] > node->x_max) node->x_max = mainb[a]->bb->vec[6][0]; - if (mainb[a]->bb->vec[6][1] > node->y_max) node->y_max = mainb[a]->bb->vec[6][1]; - if (mainb[a]->bb->vec[6][2] > node->z_max) node->z_max = mainb[a]->bb->vec[6][2]; + if (G_mb.mainb[a]->bb->vec[6][0] > node->x_max) node->x_max = G_mb.mainb[a]->bb->vec[6][0]; + if (G_mb.mainb[a]->bb->vec[6][1] > node->y_max) node->y_max = G_mb.mainb[a]->bb->vec[6][1]; + if (G_mb.mainb[a]->bb->vec[6][2] > node->z_max) node->z_max = G_mb.mainb[a]->bb->vec[6][2]; ml_p = MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); - ml_p->ml = mainb[a]; + ml_p->ml = G_mb.mainb[a]; BLI_addtail(&node->elems, ml_p); - if ((mainb[a]->flag & MB_NEGATIVE) == 0) { + if ((G_mb.mainb[a]->flag & MB_NEGATIVE) == 0) { /* number of positive MetaElem in scene */ - metaball_tree->pos++; + G_mb.metaball_tree->pos++; } else { /* number of negative MetaElem in scene */ - metaball_tree->neg++; + G_mb.metaball_tree->neg++; } } @@ -2226,7 +2232,7 @@ static void init_metaball_octal_tree(int depth) size[2] = node->z_max - node->z_min; /* first node is subdivided recursively */ - subdivide_metaball_octal_node(node, size[0], size[1], size[2], metaball_tree->depth); + subdivide_metaball_octal_node(node, size[0], size[1], size[2], G_mb.metaball_tree->depth); } void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) @@ -2239,48 +2245,48 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) mb = ob->data; - if (totelem == 0) return; + if (G_mb.totelem == 0) return; if ((G.is_rendering == FALSE) && (mb->flag == MB_UPDATE_NEVER)) return; if (G.moving && mb->flag == MB_UPDATE_FAST) return; curindex = totindex = 0; indices = NULL; - thresh = mb->thresh; + G_mb.thresh = mb->thresh; /* total number of MetaElems (totelem) is precomputed in find_basis_mball() function */ - mainb = MEM_mallocN(sizeof(void *) * totelem, "mainb"); + G_mb.mainb = MEM_mallocN(sizeof(void *) * G_mb.totelem, "mainb"); /* initialize all mainb (MetaElems) */ totsize = init_meta(scene, ob); - if (metaball_tree) { - free_metaball_octal_node(metaball_tree->first); - MEM_freeN(metaball_tree); - metaball_tree = NULL; + if (G_mb.metaball_tree) { + free_metaball_octal_node(G_mb.metaball_tree->first); + MEM_freeN(G_mb.metaball_tree); + G_mb.metaball_tree = NULL; } /* if scene includes more then one MetaElem, then octal tree optimization is used */ - if ((totelem > 1) && (totelem <= 64)) init_metaball_octal_tree(1); - if ((totelem > 64) && (totelem <= 128)) init_metaball_octal_tree(2); - if ((totelem > 128) && (totelem <= 512)) init_metaball_octal_tree(3); - if ((totelem > 512) && (totelem <= 1024)) init_metaball_octal_tree(4); - if (totelem > 1024) init_metaball_octal_tree(5); + if ((G_mb.totelem > 1) && (G_mb.totelem <= 64)) init_metaball_octal_tree(1); + if ((G_mb.totelem > 64) && (G_mb.totelem <= 128)) init_metaball_octal_tree(2); + if ((G_mb.totelem > 128) && (G_mb.totelem <= 512)) init_metaball_octal_tree(3); + if ((G_mb.totelem > 512) && (G_mb.totelem <= 1024)) init_metaball_octal_tree(4); + if (G_mb.totelem > 1024) init_metaball_octal_tree(5); /* don't polygonize metaballs with too high resolution (base mball to small) * note: Eps was 0.0001f but this was giving problems for blood animation for durian, using 0.00001f */ - if (metaball_tree) { - if (ob->size[0] <= 0.00001f * (metaball_tree->first->x_max - metaball_tree->first->x_min) || - ob->size[1] <= 0.00001f * (metaball_tree->first->y_max - metaball_tree->first->y_min) || - ob->size[2] <= 0.00001f * (metaball_tree->first->z_max - metaball_tree->first->z_min)) + if (G_mb.metaball_tree) { + if (ob->size[0] <= 0.00001f * (G_mb.metaball_tree->first->x_max - G_mb.metaball_tree->first->x_min) || + ob->size[1] <= 0.00001f * (G_mb.metaball_tree->first->y_max - G_mb.metaball_tree->first->y_min) || + ob->size[2] <= 0.00001f * (G_mb.metaball_tree->first->z_max - G_mb.metaball_tree->first->z_min)) { new_pgn_element(-1); /* free values created by init_meta */ - MEM_freeN(mainb); + MEM_freeN(G_mb.mainb); /* free tree */ - free_metaball_octal_node(metaball_tree->first); - MEM_freeN(metaball_tree); - metaball_tree = NULL; + free_metaball_octal_node(G_mb.metaball_tree->first); + MEM_freeN(G_mb.metaball_tree); + G_mb.metaball_tree = NULL; return; } @@ -2304,13 +2310,13 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) polygonize(&mbproc, mb); - MEM_freeN(mainb); + MEM_freeN(G_mb.mainb); /* free octal tree */ - if (totelem > 1) { - free_metaball_octal_node(metaball_tree->first); - MEM_freeN(metaball_tree); - metaball_tree = NULL; + if (G_mb.totelem > 1) { + free_metaball_octal_node(G_mb.metaball_tree->first); + MEM_freeN(G_mb.metaball_tree); + G_mb.metaball_tree = NULL; } if (curindex) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 4c23a370a5d..268234c7e73 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -69,7 +69,6 @@ #include "BKE_library.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_movieclip.h" #include "BKE_image.h" /* openanim */ #include "BKE_tracking.h" @@ -1002,6 +1001,14 @@ void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, in IMB_freeImBuf(ibuf); } } +void BKE_movieclip_get_size_fl(MovieClip *clip, MovieClipUser *user, float size[2]) +{ + int width, height; + BKE_movieclip_get_size(clip, user, &width, &height); + + size[0] = (float)width; + size[1] = (float)height; +} int BKE_movieclip_get_duration(MovieClip *clip) { @@ -1012,9 +1019,9 @@ int BKE_movieclip_get_duration(MovieClip *clip) return clip->len; } -void BKE_movieclip_aspect(MovieClip *clip, float *aspx, float *aspy) +void BKE_movieclip_get_aspect(MovieClip *clip, float *aspx, float *aspy) { - *aspx = *aspy = 1.0; + *aspx = 1.0; /* x is always 1 */ *aspy = clip->aspy / clip->aspx / clip->tracking.camera.pixel_aspect; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index c283db94103..ade418e409f 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -58,8 +58,6 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" -#include "BKE_utildefines.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -2265,6 +2263,7 @@ static void registerShaderNodes(bNodeTreeType *ttype) register_node_type_sh_tex_gradient(ttype); register_node_type_sh_tex_magic(ttype); register_node_type_sh_tex_checker(ttype); + register_node_type_sh_tex_brick(ttype); } static void registerTextureNodes(bNodeTreeType *ttype) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 5bb0e0929ff..f8f2ae86f1d 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2710,7 +2710,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob) if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID) == 0) { scene->physics_settings.quick_cache_step = scene->physics_settings.quick_cache_step ? - MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) : + mini(scene->physics_settings.quick_cache_step, pid->cache->step) : pid->cache->step; } } diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c new file mode 100644 index 00000000000..7f9578250f2 --- /dev/null +++ b/source/blender/blenkernel/intern/object_deform.c @@ -0,0 +1,156 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/object_deform.c + * \ingroup bke + */ + +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" +#include "BLI_ghash.h" + +#include "BKE_action.h" +#include "BKE_object_deform.h" /* own include */ +#include "BKE_object.h" +#include "BKE_modifier.h" + +#include "DNA_armature_types.h" +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" + +/* --- functions for getting vgroup aligned maps --- */ + +/** + * gets the status of "flag" for each bDeformGroup + * in ob->defbase and returns an array containing them + */ +char *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot) +{ + char is_locked = FALSE; + int i; + //int defbase_tot = BLI_countlist(&ob->defbase); + char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags"); + bDeformGroup *defgroup; + + for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { + lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); + is_locked |= lock_flags[i]; + } + if (is_locked) { + return lock_flags; + } + + MEM_freeN(lock_flags); + return NULL; +} + +char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot) +{ + bDeformGroup *dg; + ModifierData *md; + char *vgroup_validmap; + GHash *gh; + int i, step1 = 1; + //int defbase_tot = BLI_countlist(&ob->defbase); + + if (ob->defbase.first == NULL) { + return NULL; + } + + gh = BLI_ghash_str_new("BKE_objdef_validmap_get gh"); + + /* add all names to a hash table */ + for (dg = ob->defbase.first; dg; dg = dg->next) { + BLI_ghash_insert(gh, dg->name, NULL); + } + + BLI_assert(BLI_ghash_size(gh) == defbase_tot); + + /* now loop through the armature modifiers and identify deform bones */ + for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) { + if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual))) + continue; + + if (md->type == eModifierType_Armature) { + ArmatureModifierData *amd = (ArmatureModifierData *) md; + + if (amd->object && amd->object->pose) { + bPose *pose = amd->object->pose; + bPoseChannel *chan; + + for (chan = pose->chanbase.first; chan; chan = chan->next) { + if (chan->bone->flag & BONE_NO_DEFORM) + continue; + + if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) { + BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1)); + } + } + } + } + } + + vgroup_validmap = MEM_mallocN(defbase_tot, "wpaint valid map"); + + /* add all names to a hash table */ + for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) { + vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL); + } + + BLI_assert(i == BLI_ghash_size(gh)); + + BLI_ghash_free(gh, NULL, NULL); + + return vgroup_validmap; +} + +/* Returns total selected vgroups, + * wpi.defbase_sel is assumed malloc'd, all values are set */ +char *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot) +{ + char *dg_selection = MEM_mallocN(defbase_tot * sizeof(char), __func__); + bDeformGroup *defgroup; + unsigned int i; + Object *armob = BKE_object_pose_armature_get(ob); + (*r_dg_flags_sel_tot) = 0; + + if (armob) { + bPose *pose = armob->pose; + for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { + bPoseChannel *pchan = BKE_pose_channel_find_name(pose, defgroup->name); + if (pchan && (pchan->bone->flag & BONE_SELECTED)) { + dg_selection[i] = TRUE; + (*r_dg_flags_sel_tot) += 1; + } + else { + dg_selection[i] = FALSE; + } + } + } + else { + memset(dg_selection, FALSE, sizeof(char) * defbase_tot); + } + + return dg_selection; +} diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 66b0cff691e..b862a824d50 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -37,8 +37,6 @@ #include "BKE_image.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" - #include "BKE_global.h" // XXX TESTING #include "BLI_math_base.h" diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 9787a5025f7..03342d0f6d1 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -57,7 +57,6 @@ #include "BKE_packedFile.h" #include "BKE_report.h" #include "BKE_sound.h" -#include "BKE_utildefines.h" #ifdef _WIN32 #define open _open diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index e990f461d4c..780528f4a0d 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -69,7 +69,6 @@ #include "BKE_scene.h" #include "BKE_smoke.h" #include "BKE_softbody.h" -#include "BKE_utildefines.h" #include "BIK_api.h" @@ -1030,7 +1029,8 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup if (scene && (duplis-- > 0) && (ob->transflag & OB_DUPLI)) { ListBase *lb_dupli_ob; - if ((lb_dupli_ob=object_duplilist(scene, ob))) { + /* don't update the dupli groups, we only wan't their pid's */ + if ((lb_dupli_ob = object_duplilist_ex(scene, ob, FALSE))) { DupliObject *dob; for (dob= lb_dupli_ob->first; dob; dob= dob->next) { if (dob->ob != ob) { /* avoids recursive loops with dupliframes: bug 22988 */ @@ -1067,8 +1067,9 @@ static int ptcache_path(PTCacheID *pid, char *filename) if (pid->cache->flag & PTCACHE_EXTERNAL) { strcpy(filename, pid->cache->path); - if (strncmp(filename, "//", 2)==0) + if (BLI_path_is_rel(filename)) { BLI_path_abs(filename, blendfilename); + } return BLI_add_slash(filename); /* new strlen() */ } diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index c440d21f56d..7d9d2f02c06 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -44,7 +44,6 @@ #include "DNA_object_types.h" #include "BLI_blenlib.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_library.h" diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index d137393e698..4dbe0b6290c 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -49,7 +49,6 @@ #include "BKE_main.h" #include "BKE_sequencer.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" diff --git a/source/blender/blenkernel/intern/seqmodifier.c b/source/blender/blenkernel/intern/seqmodifier.c index 70f27db0f74..6028b40756d 100644 --- a/source/blender/blenkernel/intern/seqmodifier.c +++ b/source/blender/blenkernel/intern/seqmodifier.c @@ -43,7 +43,6 @@ #include "BKE_colortools.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -155,14 +154,11 @@ void colorBalance_init_data(SequenceModifierData *smd) } } -ImBuf *colorBalance_apply(SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void colorBalance_apply(SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { ColorBalanceModifierData *cbmd = (ColorBalanceModifierData *) smd; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); - BKE_sequencer_color_balance_apply(&cbmd->color_balance, ibuf_new, cbmd->color_multiply, FALSE, mask); - - return ibuf_new; + BKE_sequencer_color_balance_apply(&cbmd->color_balance, ibuf, cbmd->color_multiply, FALSE, mask); } static SequenceModifierTypeInfo seqModifier_ColorBalance = { @@ -253,10 +249,9 @@ void curves_apply_threaded(int width, int height, unsigned char *rect, float *re } } -ImBuf *curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { CurvesModifierData *cmd = (CurvesModifierData *) smd; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); float black[3] = {0.0f, 0.0f, 0.0f}; float white[3] = {1.0f, 1.0f, 1.0f}; @@ -266,11 +261,9 @@ ImBuf *curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) curvemapping_premultiply(&cmd->curve_mapping, 0); curvemapping_set_black_white(&cmd->curve_mapping, black, white); - modifier_apply_threaded(ibuf_new, mask, curves_apply_threaded, &cmd->curve_mapping); + modifier_apply_threaded(ibuf, mask, curves_apply_threaded, &cmd->curve_mapping); curvemapping_premultiply(&cmd->curve_mapping, 1); - - return ibuf_new; } static SequenceModifierTypeInfo seqModifier_Curves = { @@ -372,16 +365,13 @@ void hue_correct_apply_threaded(int width, int height, unsigned char *rect, floa } } -ImBuf *hue_correct_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void hue_correct_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); curvemapping_initialize(&hcmd->curve_mapping); - modifier_apply_threaded(ibuf_new, mask, hue_correct_apply_threaded, &hcmd->curve_mapping); - - return ibuf_new; + modifier_apply_threaded(ibuf, mask, hue_correct_apply_threaded, &hcmd->curve_mapping); } static SequenceModifierTypeInfo seqModifier_HueCorrect = { @@ -470,18 +460,15 @@ void brightcontrast_apply_threaded(int width, int height, unsigned char *rect, f } } -ImBuf *brightcontrast_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) +void brightcontrast_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask) { BrightContrastModifierData *bcmd = (BrightContrastModifierData *) smd; BrightContrastThreadData data; - ImBuf *ibuf_new = IMB_dupImBuf(ibuf); data.bright = bcmd->bright; data.contrast = bcmd->contrast; - modifier_apply_threaded(ibuf_new, mask, brightcontrast_apply_threaded, &data); - - return ibuf_new; + modifier_apply_threaded(ibuf, mask, brightcontrast_apply_threaded, &data); } static SequenceModifierTypeInfo seqModifier_BrightContrast = { @@ -596,7 +583,6 @@ ImBuf *BKE_sequence_modifier_apply_stack(SeqRenderData context, Sequence *seq, I for (smd = seq->modifiers.first; smd; smd = smd->next) { SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type); - ImBuf *ibuf_new; /* could happen if modifier is being removed or not exists in current version of blender */ if (!smti) @@ -612,12 +598,7 @@ ImBuf *BKE_sequence_modifier_apply_stack(SeqRenderData context, Sequence *seq, I if (processed_ibuf == ibuf) processed_ibuf = IMB_dupImBuf(ibuf); - ibuf_new = smti->apply(smd, processed_ibuf, mask); - - if (ibuf_new != processed_ibuf) { - IMB_freeImBuf(processed_ibuf); - processed_ibuf = ibuf_new; - } + smti->apply(smd, processed_ibuf, mask); if (mask) IMB_freeImBuf(mask); diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 8aab622148b..2596bf57f05 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -62,7 +62,6 @@ #include "BKE_fcurve.h" #include "BKE_scene.h" #include "BKE_mask.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -166,14 +165,12 @@ static void seq_free_strip(Strip *strip) if (strip->transform) { MEM_freeN(strip->transform); } - if (strip->color_balance) { - MEM_freeN(strip->color_balance); - } MEM_freeN(strip); } -void BKE_sequence_free(Scene *scene, Sequence *seq) +/* only give option to skip cache locally (static func) */ +static void BKE_sequence_free_ex(Scene *scene, Sequence *seq, const int do_cache) { if (seq->strip) seq_free_strip(seq->strip); @@ -209,21 +206,37 @@ void BKE_sequence_free(Scene *scene, Sequence *seq) /* free cached data used by this strip, * also invalidate cache for all dependent sequences + * + * be _very_ careful here, invalidating cache loops over the scene sequences and + * assumes the listbase is valid for all strips, this may not be the case if lists are being freed. + * this is optional BKE_sequence_invalidate_cache */ - BKE_sequence_invalidate_cache(scene, seq); + if (do_cache) { + if (scene) { + BKE_sequence_invalidate_cache(scene, seq); + } + } MEM_freeN(seq); } +void BKE_sequence_free(Scene *scene, Sequence *seq) +{ + BKE_sequence_free_ex(scene, seq, TRUE); +} + +/* cache must be freed before calling this function + * since it leaves the seqbase in an invalid state */ static void seq_free_sequence_recurse(Scene *scene, Sequence *seq) { - Sequence *iseq; + Sequence *iseq, *iseq_next; - for (iseq = seq->seqbase.first; iseq; iseq = iseq->next) { + for (iseq = seq->seqbase.first; iseq; iseq = iseq_next) { + iseq_next = iseq->next; seq_free_sequence_recurse(scene, iseq); } - BKE_sequence_free(scene, seq); + BKE_sequence_free_ex(scene, seq, FALSE); } @@ -244,7 +257,7 @@ static void seq_free_clipboard_recursive(Sequence *seq_parent) seq_free_clipboard_recursive(seq); } - BKE_sequence_free(NULL, seq_parent); + BKE_sequence_free_ex(NULL, seq_parent, FALSE); } void BKE_sequencer_free_clipboard(void) @@ -273,22 +286,22 @@ Editing *BKE_sequencer_editing_ensure(Scene *scene) void BKE_sequencer_editing_free(Scene *scene) { Editing *ed = scene->ed; - MetaStack *ms; Sequence *seq; if (ed == NULL) return; + /* this may not be the active scene!, could be smarter about this */ + BKE_sequencer_cache_cleanup(); + SEQ_BEGIN (ed, seq) { - BKE_sequence_free(scene, seq); + /* handle cache freeing above */ + BKE_sequence_free_ex(scene, seq, FALSE); } SEQ_END - while ((ms = ed->metastack.first)) { - BLI_remlink(&ed->metastack, ms); - MEM_freeN(ms); - } + BLI_freelistN(&ed->metastack); MEM_freeN(ed); @@ -1671,26 +1684,6 @@ void BKE_sequencer_color_balance_apply(StripColorBalance *cb, ImBuf *ibuf, float imb_freerectImBuf(ibuf); } -static void sequence_color_balance(SeqRenderData context, Sequence *seq, ImBuf *ibuf, float mul, int cfra) -{ - StripColorBalance *cb = seq->strip->color_balance; - ImBuf *mask_input = NULL; - short make_float = seq->flag & SEQ_MAKE_FLOAT; - - if (seq->mask_sequence) { - if (seq->mask_sequence != seq && !BKE_sequence_check_depend(seq, seq->mask_sequence)) { - int make_float = ibuf->rect_float != NULL; - - mask_input = BKE_sequencer_render_mask_input(context, SEQUENCE_MASK_INPUT_STRIP, seq->mask_sequence, NULL, cfra, make_float); - } - } - - BKE_sequencer_color_balance_apply(cb, ibuf, mul, make_float, mask_input); - - if (mask_input) - IMB_freeImBuf(mask_input); -} - /* * input preprocessing for SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_MOVIECLIP and SEQ_TYPE_SCENE * @@ -1713,9 +1706,7 @@ int BKE_sequencer_input_have_to_preprocess(SeqRenderData UNUSED(context), Sequen { float mul; - if (seq->flag & (SEQ_FILTERY | SEQ_USE_CROP | SEQ_USE_TRANSFORM | SEQ_FLIPX | - SEQ_FLIPY | SEQ_USE_COLOR_BALANCE | SEQ_MAKE_PREMUL)) - { + if (seq->flag & (SEQ_FILTERY | SEQ_USE_CROP | SEQ_USE_TRANSFORM | SEQ_FLIPX | SEQ_FLIPY | SEQ_MAKE_PREMUL)) { return TRUE; } @@ -1834,11 +1825,6 @@ static ImBuf *input_preprocess(SeqRenderData context, Sequence *seq, float cfra, mul *= seq->blend_opacity / 100.0f; } - if (seq->flag & SEQ_USE_COLOR_BALANCE && seq->strip->color_balance) { - sequence_color_balance(context, seq, ibuf, mul, cfra); - mul = 1.0; - } - if (seq->flag & SEQ_MAKE_FLOAT) { if (!ibuf->rect_float) IMB_float_from_rect_simple(ibuf); @@ -2171,7 +2157,7 @@ static ImBuf *seq_render_mask(SeqRenderData context, Mask *mask, float nr, short BKE_maskrasterize_handle_init(mr_handle, mask_temp, context.rectx, context.recty, TRUE, TRUE, TRUE); - BKE_mask_free(mask_temp); + BKE_mask_free_nolib(mask_temp); MEM_freeN(mask_temp); BKE_maskrasterize_buffer(mr_handle, context.rectx, context.recty, maskbuf); @@ -2962,13 +2948,18 @@ int BKE_sequence_check_depend(Sequence *seq, Sequence *cur) return TRUE; } -static void sequence_invalidate_cache(Scene *scene, Sequence *seq, int invalidate_preprocess) +static void sequence_invalidate_cache(Scene *scene, Sequence *seq, int invalidate_self, int invalidate_preprocess) { Editing *ed = scene->ed; Sequence *cur; /* invalidate cache for current sequence */ - BKE_sequencer_cache_cleanup_sequence(seq); + if (invalidate_self) + BKE_sequencer_cache_cleanup_sequence(seq); + + /* if invalidation is invoked from sequence free routine, effectdata would be NULL here */ + if (seq->effectdata && seq->type == SEQ_TYPE_SPEED) + BKE_sequence_effect_speed_rebuild_map(scene, seq, TRUE); if (invalidate_preprocess) BKE_sequencer_preprocessed_cache_cleanup_sequence(seq); @@ -2989,54 +2980,40 @@ static void sequence_invalidate_cache(Scene *scene, Sequence *seq, int invalidat void BKE_sequence_invalidate_cache(Scene *scene, Sequence *seq) { - sequence_invalidate_cache(scene, seq, TRUE); + sequence_invalidate_cache(scene, seq, TRUE, TRUE); +} + +void BKE_sequence_invalidate_deendent(Scene *scene, Sequence *seq) +{ + sequence_invalidate_cache(scene, seq, FALSE, TRUE); } void BKE_sequence_invalidate_cache_for_modifier(Scene *scene, Sequence *seq) { - sequence_invalidate_cache(scene, seq, FALSE); + sequence_invalidate_cache(scene, seq, TRUE, FALSE); } -void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int check_mem_usage, int keep_file_handles) +void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int for_render) { Sequence *seq; - if (check_mem_usage) { - /* Let the cache limitor take care of this (schlaile) */ - /* While render let's keep all memory available for render - * (ton) - * At least if free memory is tight... - * This can make a big difference in encoding speed - * (it is around 4 times(!) faster, if we do not waste time - * on freeing _all_ buffers every time on long timelines...) - * (schlaile) - */ - - uintptr_t mem_in_use; - uintptr_t mmap_in_use; - uintptr_t max; - - mem_in_use = MEM_get_memory_in_use(); - mmap_in_use = MEM_get_mapped_memory_in_use(); - max = MEM_CacheLimiter_get_maximum(); - - if (max == 0 || mem_in_use + mmap_in_use <= max) { - return; - } - } - BKE_sequencer_cache_cleanup(); - + for (seq = seqbase->first; seq; seq = seq->next) { + if (for_render && CFRA >= seq->startdisp && CFRA <= seq->enddisp) { + continue; + } + if (seq->strip) { - if (seq->type == SEQ_TYPE_MOVIE && !keep_file_handles) + if (seq->type == SEQ_TYPE_MOVIE) { free_anim_seq(seq); + } if (seq->type == SEQ_TYPE_SPEED) { BKE_sequence_effect_speed_rebuild_map(scene, seq, 1); } } if (seq->type == SEQ_TYPE_META) { - BKE_sequencer_free_imbuf(scene, &seq->seqbase, FALSE, keep_file_handles); + BKE_sequencer_free_imbuf(scene, &seq->seqbase, for_render); } if (seq->type == SEQ_TYPE_SCENE) { /* FIXME: recurs downwards, @@ -4038,10 +4015,6 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int dup seqn->strip->proxy->anim = NULL; } - if (seq->strip->color_balance) { - seqn->strip->color_balance = MEM_dupallocN(seq->strip->color_balance); - } - if (seqn->modifiers.first) { seqn->modifiers.first = seqn->modifiers.last = NULL; diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index f9399946570..9a8bcaabe0c 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -313,7 +313,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) auxMesh = object_get_derived_final(calc->smd->auxTarget); if (!auxMesh) return; - space_transform_setup(&local2aux, calc->ob, calc->smd->auxTarget); + SPACE_TRANSFORM_SETUP(&local2aux, calc->ob, calc->smd->auxTarget); } //After sucessufuly build the trees, start projection vertexs @@ -500,7 +500,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM //TODO there might be several "bugs" on non-uniform scales matrixs //because it will no longer be nearest surface, not sphere projection //because space has been deformed - space_transform_setup(&calc.local2target, ob, smd->target); + SPACE_TRANSFORM_SETUP(&calc.local2target, ob, smd->target); //TODO: smd->keepDist is in global units.. must change to local calc.keepDist = smd->keepDist; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 008dc332710..4a88bfbfdad 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2291,7 +2291,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo /* done goal stuff */ /* gravitation */ - if (sb && scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { + if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { float gravity[3]; copy_v3_v3(gravity, scene->physics_settings.gravity); mul_v3_fl(gravity, sb_grav_force_scale(ob)*_final_mass(ob, bp)*sb->effector_weights->global_gravity); /* individual mass of node here */ diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 2462de07a18..f340bcb5b1e 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -50,7 +50,6 @@ # include "AUD_C-API.h" #endif -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_sound.h" diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 7de5f97588b..787def5c20b 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1684,7 +1684,8 @@ void txt_print_undo(Text *text) printf("%c%c%c", text->undo_buf[i], text->undo_buf[i + 1], text->undo_buf[i + 2]); i += 3; break; - case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: { + case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: + { unsigned int uc; char c[BLI_UTF8_MAX + 1]; size_t c_len; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 2f54fe6cebd..ee904de4af6 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -56,7 +56,6 @@ #include "IMB_imbuf.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_ocean.h" diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 78e7dab045f..2ed9d992c3f 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -411,6 +411,8 @@ void BKE_tracking_clipboard_free(void) track = next_track; } + + tracking_clipboard.tracks.first = tracking_clipboard.tracks.last = NULL; } void BKE_tracking_clipboard_copy_tracks(MovieTracking *tracking, MovieTrackingObject *object) diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index dd71e43182e..434bfe19c1f 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -51,14 +51,14 @@ #include "BKE_node.h" #include "BKE_world.h" -void BKE_world_free(World *wrld) +void BKE_world_free_ex(World *wrld, int do_id_user) { MTex *mtex; int a; for (a = 0; a < MAX_MTEX; a++) { mtex = wrld->mtex[a]; - if (mtex && mtex->tex) mtex->tex->id.us--; + if (do_id_user && mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } BKE_previewimg_free(&wrld->preview); @@ -67,7 +67,7 @@ void BKE_world_free(World *wrld) /* is no lib link block, but world extension */ if (wrld->nodetree) { - ntreeFreeTree(wrld->nodetree); + ntreeFreeTree_ex(wrld->nodetree, do_id_user); MEM_freeN(wrld->nodetree); } @@ -75,6 +75,10 @@ void BKE_world_free(World *wrld) wrld->id.icon_id = 0; } +void BKE_world_free(World *wrld) +{ + BKE_world_free_ex(wrld, TRUE); +} World *add_world(const char *name) { diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 3526058e12b..bd25ff8c6e6 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -177,58 +177,71 @@ static AVFrame *alloc_picture(int pix_fmt, int width, int height) static const char **get_file_extensions(int format) { switch (format) { - case FFMPEG_DV: { + case FFMPEG_DV: + { static const char *rv[] = { ".dv", NULL }; return rv; } - case FFMPEG_MPEG1: { + case FFMPEG_MPEG1: + { static const char *rv[] = { ".mpg", ".mpeg", NULL }; return rv; } - case FFMPEG_MPEG2: { + case FFMPEG_MPEG2: + { static const char *rv[] = { ".dvd", ".vob", ".mpg", ".mpeg", NULL }; return rv; } - case FFMPEG_MPEG4: { + case FFMPEG_MPEG4: + { static const char *rv[] = { ".mp4", ".mpg", ".mpeg", NULL }; return rv; } - case FFMPEG_AVI: { + case FFMPEG_AVI: + { static const char *rv[] = { ".avi", NULL }; return rv; } - case FFMPEG_MOV: { + case FFMPEG_MOV: + { static const char *rv[] = { ".mov", NULL }; return rv; } - case FFMPEG_H264: { + case FFMPEG_H264: + { /* FIXME: avi for now... */ static const char *rv[] = { ".avi", NULL }; return rv; } - case FFMPEG_XVID: { + case FFMPEG_XVID: + { /* FIXME: avi for now... */ static const char *rv[] = { ".avi", NULL }; return rv; } - case FFMPEG_FLV: { + case FFMPEG_FLV: + { static const char *rv[] = { ".flv", NULL }; return rv; } - case FFMPEG_MKV: { + case FFMPEG_MKV: + { static const char *rv[] = { ".mkv", NULL }; return rv; } - case FFMPEG_OGG: { + case FFMPEG_OGG: + { static const char *rv[] = { ".ogg", ".ogv", NULL }; return rv; } - case FFMPEG_MP3: { + case FFMPEG_MP3: + { static const char *rv[] = { ".mp3", NULL }; return rv; } - case FFMPEG_WAV: { + case FFMPEG_WAV: + { static const char *rv[] = { ".wav", NULL }; return rv; } @@ -946,6 +959,7 @@ int BKE_ffmpeg_start(struct Scene *scene, RenderData *rd, int rectx, int recty, } void BKE_ffmpeg_end(void); +static void end_ffmpeg_impl(int is_autosplit); #ifdef WITH_AUDASPACE static void write_audio_frames(double to_pts) @@ -978,7 +992,7 @@ int BKE_ffmpeg_append(RenderData *rd, int start_frame, int frame, int *pixels, i if (ffmpeg_autosplit) { if (avio_tell(outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) { - BKE_ffmpeg_end(); + end_ffmpeg_impl(TRUE); ffmpeg_autosplit_count++; success &= start_ffmpeg_impl(rd, rectx, recty, reports); } @@ -991,7 +1005,7 @@ int BKE_ffmpeg_append(RenderData *rd, int start_frame, int frame, int *pixels, i return success; } -void BKE_ffmpeg_end(void) +static void end_ffmpeg_impl(int is_autosplit) { unsigned int i; @@ -1004,9 +1018,11 @@ void BKE_ffmpeg_end(void) #endif #ifdef WITH_AUDASPACE - if (audio_mixdown_device) { - AUD_closeReadDevice(audio_mixdown_device); - audio_mixdown_device = 0; + if (is_autosplit == FALSE) { + if (audio_mixdown_device) { + AUD_closeReadDevice(audio_mixdown_device); + audio_mixdown_device = 0; + } } #endif @@ -1069,6 +1085,11 @@ void BKE_ffmpeg_end(void) } } +void BKE_ffmpeg_end(void) +{ + end_ffmpeg_impl(FALSE); +} + /* properties */ void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_) diff --git a/source/blender/blenlib/BLI_endian_switch.h b/source/blender/blenlib/BLI_endian_switch.h new file mode 100644 index 00000000000..7017e7ba789 --- /dev/null +++ b/source/blender/blenlib/BLI_endian_switch.h @@ -0,0 +1,42 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_ENDIAN_SWITCH_H__ +#define __BLI_ENDIAN_SWITCH_H__ + +/** \file BLI_endian_switch.h + * \ingroup bli + */ + +#include "BLI_endian_switch_inline.h" + +/* endian_switch.c */ +void BLI_endian_switch_int16_array(short *val, const int size); +void BLI_endian_switch_uint16_array(unsigned short *val, const int size); +void BLI_endian_switch_int32_array(int *val, const int size); +void BLI_endian_switch_uint32_array(unsigned int *val, const int size); +void BLI_endian_switch_float_array(float *val, const int size); +void BLI_endian_switch_int64_array(int64_t *val, const int size); +void BLI_endian_switch_uint64_array(uint64_t *val, const int size); +void BLI_endian_switch_double_array(double *val, const int size); + +#endif /* __BLI_ENDIAN_SWITCH_H__ */ diff --git a/source/blender/blenlib/BLI_endian_switch_inline.h b/source/blender/blenlib/BLI_endian_switch_inline.h new file mode 100644 index 00000000000..b747da3b738 --- /dev/null +++ b/source/blender/blenlib/BLI_endian_switch_inline.h @@ -0,0 +1,116 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/* only include from header */ +#ifndef __BLI_ENDIAN_SWITCH_H__ +# error "this file isnt to be directly included" +#endif + +#ifndef __BLI_ENDIAN_SWITCH_INLINE_H__ +#define __BLI_ENDIAN_SWITCH_INLINE_H__ + +/** \file blender/blenlib/BLI_endian_switch_inline.h + * \ingroup bli + */ + + +BLI_INLINE void BLI_endian_switch_int16(short *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; + p_i[0] = p_i[1]; + p_i[1] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; + p_i[0] = p_i[1]; + p_i[1] = s_i; +} + +BLI_INLINE void BLI_endian_switch_int32(int *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_float(float *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_int64(int64_t *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; +} + +BLI_INLINE void BLI_endian_switch_double(double *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; +} + +#endif /* __BLI_ENDIAN_SWITCH_INLINE_H__ */ diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index ac0ec6a52a7..e8d6336a994 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -91,6 +91,13 @@ int BLI_file_older(const char *file1, const char *file2); struct LinkNode *BLI_file_read_as_lines(const char *file); void BLI_file_free_lines(struct LinkNode *lines); +/* this weirdo pops up in two places ... */ +#if !defined(WIN32) +# ifndef O_BINARY +# define O_BINARY 0 +# endif +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 4a89776a52e..886ed6f495d 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -164,7 +164,10 @@ #endif #ifndef CLAMP -# define CLAMP(a, b, c) if ((a) < (b)) (a) = (b); else if ((a) > (c)) (a) = (c) +# define CLAMP(a, b, c) { \ + if ((a) < (b)) (a) = (b); \ + else if ((a) > (c)) (a) = (c); \ +} (void)0 #endif #ifdef __BLI_MATH_INLINE_H__ diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index eef8c9daaef..6c81ca3f0a9 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -81,6 +81,7 @@ MINLINE void copy_v4db_v4fl(double r[4], const float a[4]); /********************************* Arithmetic ********************************/ +MINLINE void add_v2_fl(float r[2], float f); MINLINE void add_v3_fl(float r[3], float f); MINLINE void add_v4_fl(float r[4], float f); MINLINE void add_v2_v2(float r[2], const float a[2]); diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9b68406cc54..5e47adf25ef 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -97,7 +97,6 @@ typedef enum bli_rebase_state { } bli_rebase_state; int BLI_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir); -#define BKE_rebase_path BLI_rebase_path /* remove after a 2012 */ char *BLI_last_slash(const char *string); int BLI_add_slash(char *string); @@ -154,6 +153,8 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits); int BLI_path_cwd(char *path); void BLI_path_rel(char *file, const char *relfile); +int BLI_path_is_rel(const char *path); + #ifdef WIN32 # define BLI_path_cmp BLI_strcasecmp # define BLI_path_ncmp BLI_strncasecmp @@ -191,6 +192,14 @@ void BLI_system_temporary_dir(char *dir); void BLI_string_to_utf8(char *original, char *utf_8, const char *code); #endif +/* these values need to be hardcoded in structs, dna does not recognize defines */ +/* also defined in DNA_space_types.h */ +#ifndef FILE_MAXDIR +# define FILE_MAXDIR 768 +# define FILE_MAXFILE 256 +# define FILE_MAX 1024 +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 8a459b9b07c..29097a4c6c3 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -198,7 +198,10 @@ #define INPR(v1, v2) ( (v1)[0] * (v2)[0] + (v1)[1] * (v2)[1] + (v1)[2] * (v2)[2]) /* some misc stuff.... */ -#define CLAMP(a, b, c) if ((a) < (b)) (a) = (b); else if ((a) > (c)) (a) = (c) +#define CLAMP(a, b, c) { \ + if ((a) < (b)) (a) = (b); \ + else if ((a) > (c)) (a) = (c); \ +} (void)0 #define CLAMPIS(a, b, c) ((a) < (b) ? (b) : (a) > (c) ? (c) : (a)) #define CLAMPTEST(a, b, c) \ @@ -225,30 +228,6 @@ (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)) \ ) -/* This one rotates the bytes in an int64, int (32) and short (16) */ -#define SWITCH_INT64(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \ - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \ - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; \ - } (void)0 - -#define SWITCH_INT(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; \ - } (void)0 - -#define SWITCH_SHORT(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[1]; p_i[1] = s_i; \ - } (void)0 - - /* Warning-free macros for storing ints in pointers. Use these _only_ * for storing an int in a pointer, not a pointer in an int (64bit)! */ #define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i)) diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index e4c4166953c..eef0a72d3b2 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -56,6 +56,7 @@ set(SRC intern/cpu.c intern/dynlib.c intern/edgehash.c + intern/endian_switch.c intern/fileops.c intern/fnmatch.c intern/freetypefont.c @@ -106,6 +107,8 @@ set(SRC BLI_dynlib.h BLI_dynstr.h BLI_edgehash.h + BLI_endian_switch.h + BLI_endian_switch_inline.h BLI_fileops.h BLI_fileops_types.h BLI_fnmatch.h @@ -145,6 +148,7 @@ set(SRC BLI_utildefines.h BLI_uvproject.h BLI_vfontdata.h + BLI_voronoi.h BLI_voxel.h BLI_winstuff.h PIL_time.h diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 8c9993afee8..0ac6209fc95 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -46,7 +46,7 @@ struct MemArena { LinkNode *bufs; }; -MemArena *BLI_memarena_new(int bufsize, const char *name) +MemArena *BLI_memarena_new(const int bufsize, const char *name) { MemArena *ma = MEM_callocN(sizeof(*ma), "memarena"); ma->bufsize = bufsize; @@ -66,7 +66,7 @@ void BLI_memarena_use_malloc(MemArena *ma) ma->use_calloc = 0; } -void BLI_memarena_use_align(struct MemArena *ma, int align) +void BLI_memarena_use_align(struct MemArena *ma, const int align) { /* align should be a power of two */ ma->align = align; diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index c7e610edd9e..d98e63d88dd 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -45,7 +45,7 @@ #include <string.h> #include <stdlib.h> -/* note: copied from BKE_utildefines.h, don't use here because we're in BLI */ +/* note: copied from BLO_blend_defs.h, don't use here because we're in BLI */ #ifdef __BIG_ENDIAN__ /* Big Endian */ # define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index ccc45b465f4..5bafb75d9c0 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -79,7 +79,6 @@ #include "BKE_main.h" #include "BKE_report.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "BKE_image.h" /* so we can check the image's type */ static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src) @@ -114,13 +113,13 @@ static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char data->count_tot++; - if (strncmp(path_src, "//", 2) == 0) { + if (BLI_path_is_rel(path_src)) { return FALSE; /* already relative */ } else { strcpy(path_dst, path_src); BLI_path_rel(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2) == 0) { + if (BLI_path_is_rel(path_dst)) { data->count_changed++; } else { @@ -156,13 +155,13 @@ static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char data->count_tot++; - if (strncmp(path_src, "//", 2) != 0) { + if (BLI_path_is_rel(path_src) == FALSE) { return FALSE; /* already absolute */ } else { strcpy(path_dst, path_src); BLI_path_abs(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2) != 0) { + if (BLI_path_is_rel(path_dst) == FALSE) { data->count_changed++; } else { @@ -604,7 +603,7 @@ int BLI_bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *pat const char *base_new = ((char **)pathbase_v)[0]; const char *base_old = ((char **)pathbase_v)[1]; - if (strncmp(base_old, "//", 2) == 0) { + if (BLI_path_is_rel(base_old)) { printf("%s: error, old base path '%s' is not absolute.\n", __func__, base_old); return FALSE; diff --git a/source/blender/blenlib/intern/endian_switch.c b/source/blender/blenlib/intern/endian_switch.c new file mode 100644 index 00000000000..b9b18136863 --- /dev/null +++ b/source/blender/blenlib/intern/endian_switch.c @@ -0,0 +1,118 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/intern/endian_switch.c + * \ingroup bli + */ + +#include "BLO_sys_types.h" +#include "BLI_utildefines.h" +#include "BLI_endian_switch.h" + +void BLI_endian_switch_int16_array(short *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int16(val--); + } + } +} + +void BLI_endian_switch_uint16_array(unsigned short *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint16(val--); + } + } +} + +void BLI_endian_switch_int32_array(int *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int32(val--); + } + } +} + +void BLI_endian_switch_uint32_array(unsigned int *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint32(val--); + } + } +} + +void BLI_endian_switch_float_array(float *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_float(val--); + } + } +} + +void BLI_endian_switch_int64_array(int64_t *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int64(val--); + } + } +} + +void BLI_endian_switch_uint64_array(uint64_t *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint64(val--); + } + } +} + + +void BLI_endian_switch_double_array(double *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_double(val--); + } + } +} diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 7aa956a0548..f3107b565b9 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -60,8 +60,6 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" - #include "BLO_sys_types.h" // for intptr_t support diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 76f4f26b728..53e9a6b66cb 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2229,7 +2229,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[ t2 = mean_value_half_tan_v3(co, vmid, vnext); len = len_v3v3(co, vmid); - w[i] = (t1 + t2) / len; + w[i] = (len != 0.0f)? (t1 + t2) / len: 0.0f; totweight += w[i]; } @@ -2257,7 +2257,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[ t2 = mean_value_half_tan_v2(co, vmid, vnext); len = len_v2v2(co, vmid); - w[i] = (t1 + t2) / len; + w[i] = (len != 0.0f)? (t1 + t2) / len: 0.0f; totweight += w[i]; } diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 177c099d647..0a8f57214d7 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -231,6 +231,13 @@ MINLINE void swap_v4_v4(float a[4], float b[4]) /********************************* Arithmetic ********************************/ +MINLINE void add_v2_fl(float r[2], float f) +{ + r[0] += f; + r[1] += f; +} + + MINLINE void add_v3_fl(float r[3], float f) { r[0] += f; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 22b160ad0b4..a7a66718445 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -47,7 +47,6 @@ #include "BLI_string_utf8.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "BKE_blender.h" // BLENDER_VERSION #include "GHOST_Path-api.h" @@ -411,6 +410,11 @@ void BLI_cleanup_file(const char *relabase, char *dir) BLI_del_slash(dir); } +int BLI_path_is_rel(const char *path) +{ + return path[0] == '/' && path[1] == '/'; +} + void BLI_path_rel(char *file, const char *relfile) { char *lslash; @@ -418,10 +422,14 @@ void BLI_path_rel(char *file, const char *relfile) char res[FILE_MAX]; /* if file is already relative, bail out */ - if (file[0] == '/' && file[1] == '/') return; + if (BLI_path_is_rel(file)) { + return; + } /* also bail out if relative path is not set */ - if (relfile[0] == 0) return; + if (relfile[0] == '\0') { + return; + } #ifdef WIN32 if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') { @@ -630,7 +638,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) int BLI_path_abs(char *path, const char *basepath) { - int wasrelative = (strncmp(path, "//", 2) == 0); + int wasrelative = BLI_path_is_rel(path); char tmp[FILE_MAX]; char base[FILE_MAX]; #ifdef WIN32 diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 4ce718aeb16..32afaba2b5c 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -423,12 +423,16 @@ static void testvertexnearedge(ScanFillContext *sf_ctx) for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { if (eve->h == 1) { - /* find the edge which has vertex eve */ - ed1 = sf_ctx->filledgebase.first; - while (ed1) { - if (ed1->v1 == eve || ed1->v2 == eve) break; - ed1 = ed1->next; + /* find the edge which has vertex eve, + * note: we _know_ this will crash if 'ed1' becomes NULL + * but this will never happen. */ + for (ed1 = sf_ctx->filledgebase.first; + !(ed1->v1 == eve || ed1->v2 == eve); + ed1 = ed1->next) + { + /* do nothing */ } + if (ed1->v1 == eve) { ed1->v1 = ed1->v2; ed1->v2 = eve; diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 965e8b5eec3..0fccd91fc02 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -86,13 +86,10 @@ #include "BLI_listbase.h" #include "BLI_linklist.h" -#include "BLI_fileops.h" - -#include "BLI_fileops_types.h" #include "BLI_string.h" #include "BLI_fileops.h" - -#include "BKE_utildefines.h" +#include "BLI_fileops_types.h" +#include "BLI_path_util.h" /* vars: */ static int totnum, actnum; diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 0dc4d3c2db6..5b5f4cf8b80 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -41,12 +41,12 @@ #include "BLI_path_util.h" #include "BLI_string.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #include "BLI_winstuff.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "utf_winfunc.h" #include "utfconv.h" diff --git a/source/blender/blenloader/BLO_blend_defs.h b/source/blender/blenloader/BLO_blend_defs.h new file mode 100644 index 00000000000..8005be158ce --- /dev/null +++ b/source/blender/blenloader/BLO_blend_defs.h @@ -0,0 +1,47 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __BLO_BLEND_DEFS_H__ +#define __BLO_BLEND_DEFS_H__ + +/** \file BLO_blend_defs.h + * \ingroup blenloader + * \brief defines for blendfile codes + */ + +/* INTEGER CODES */ +#ifdef __BIG_ENDIAN__ +/* Big Endian */ +# define BLEND_MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) +#else +/* Little Endian */ +# define BLEND_MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) +#endif + +#define DATA BLEND_MAKE_ID('D', 'A', 'T', 'A') +#define GLOB BLEND_MAKE_ID('G', 'L', 'O', 'B') + +#define DNA1 BLEND_MAKE_ID('D', 'N', 'A', '1') +#define TEST BLEND_MAKE_ID('T', 'E', 'S', 'T') /* used as preview between 'REND' and 'GLOB' */ +#define REND BLEND_MAKE_ID('R', 'E', 'N', 'D') +#define USER BLEND_MAKE_ID('U', 'S', 'E', 'R') + +#define ENDB BLEND_MAKE_ID('E', 'N', 'D', 'B') + +#endif /* __BLO_BLEND_DEFS_H__ */ diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index a0fe042e7fb..74df5211dad 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -48,6 +48,7 @@ set(SRC intern/versioning_legacy.c intern/writefile.c + BLO_blend_defs.h BLO_readfile.h BLO_runtime.h BLO_soundfile.h diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index eb12a7bd837..e917ccdf342 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -40,12 +40,13 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_ghash.h" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_string.h" -#include "BLI_utildefines.h" #include "DNA_genfile.h" #include "DNA_sdna_types.h" @@ -55,10 +56,10 @@ #include "BKE_library.h" // for free_main #include "BKE_idcode.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "readfile.h" diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2dd6c8992d9..845228fb1b9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -101,6 +101,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_edgehash.h" @@ -141,7 +142,6 @@ #include "BKE_sequencer.h" #include "BKE_text.h" // for txt_extended_ascii_as_utf8 #include "BKE_tracking.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" #include "IMB_imbuf.h" // for proxy / timecode versioning stuff @@ -150,6 +150,7 @@ #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "RE_engine.h" @@ -222,16 +223,6 @@ /* from misc_util: flip the bytes from x */ /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */ -// only used here in readfile.c -#define SWITCH_LONGINT(a) { \ - char s_i, *p_i; \ - p_i= (char *)&(a); \ - s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \ - s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \ - s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \ - s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; \ -} (void)0 - /***/ typedef struct OldNew { @@ -578,9 +569,9 @@ static void switch_endian_bh4(BHead4 *bhead) if ((bhead->code & 0xFFFF)==0) bhead->code >>= 16; if (bhead->code != ENDB) { - SWITCH_INT(bhead->len); - SWITCH_INT(bhead->SDNAnr); - SWITCH_INT(bhead->nr); + BLI_endian_switch_int32(&bhead->len); + BLI_endian_switch_int32(&bhead->SDNAnr); + BLI_endian_switch_int32(&bhead->nr); } } @@ -590,9 +581,9 @@ static void switch_endian_bh8(BHead8 *bhead) if ((bhead->code & 0xFFFF)==0) bhead->code >>= 16; if (bhead->code != ENDB) { - SWITCH_INT(bhead->len); - SWITCH_INT(bhead->SDNAnr); - SWITCH_INT(bhead->nr); + BLI_endian_switch_int32(&bhead->len); + BLI_endian_switch_int32(&bhead->SDNAnr); + BLI_endian_switch_int32(&bhead->nr); } } @@ -613,7 +604,7 @@ static void bh4_from_bh8(BHead *bhead, BHead8 *bhead8, int do_endian_swap) * 0x0000000000000000000012345678 would become 0x12345678000000000000000000000000 */ if (do_endian_swap) { - SWITCH_LONGINT(bhead8->old); + BLI_endian_switch_int64(&bhead8->old); } /* this patch is to avoid a long long being read from not-eight aligned positions @@ -1477,11 +1468,7 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */ static void test_pointer_array(FileData *fd, void **mat) { -#if defined(WIN32) && !defined(FREE_WINDOWS) - __int64 *lpoin, *lmat; -#else - long long *lpoin, *lmat; -#endif + int64_t *lpoin, *lmat; int *ipoin, *imat; size_t len; @@ -1498,7 +1485,7 @@ static void test_pointer_array(FileData *fd, void **mat) while (len-- > 0) { if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN)) - SWITCH_LONGINT(*lpoin); + BLI_endian_switch_int64(lpoin); *ipoin = (int)((*lpoin) >> 3); ipoin++; lpoin++; @@ -1568,16 +1555,13 @@ static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, FileData *f } else if (prop->subtype == IDP_DOUBLE) { if (switch_endian) { - for (i = 0; i < prop->len; i++) { - SWITCH_LONGINT(((double *)prop->data.pointer)[i]); - } + BLI_endian_switch_double_array(prop->data.pointer, prop->len); } } else { if (switch_endian) { - for (i = 0; i < prop->len; i++) { - SWITCH_INT(((int *)prop->data.pointer)[i]); - } + /* also used for floats */ + BLI_endian_switch_int32_array(prop->data.pointer, prop->len); } } } @@ -1629,9 +1613,9 @@ static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData */ if (switch_endian) { - SWITCH_INT(prop->data.val); - SWITCH_INT(prop->data.val2); - SWITCH_LONGINT(prop->data.val); + BLI_endian_switch_int32(&prop->data.val); + BLI_endian_switch_int32(&prop->data.val2); + BLI_endian_switch_int64((int64_t *)&prop->data.val); } break; @@ -1872,9 +1856,7 @@ static void direct_link_fmodifiers(FileData *fd, ListBase *list) data->coefficients = newdataadr(fd, data->coefficients); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - unsigned int a; - for (a = 0; a < data->arraysize; a++) - SWITCH_INT(data->coefficients[a]); + BLI_endian_switch_float_array(data->coefficients, data->arraysize); } } break; @@ -2778,11 +2760,8 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb) case IPO_BPOINT: case IPO_BEZTRIPLE: b = cp[0]; - - while (b--) { - SWITCH_INT((*poin)); - poin += 4; - } + BLI_endian_switch_float_array((float *)poin, b); + poin += sizeof(float) * b; break; } @@ -3073,19 +3052,11 @@ static void lib_link_curve(FileData *fd, Main *main) static void switch_endian_knots(Nurb *nu) { - int len; - if (nu->knotsu) { - len = KNOTSU(nu); - while (len--) { - SWITCH_INT(nu->knotsu[len]); - } + BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu)); } if (nu->knotsv) { - len = KNOTSV(nu); - while (len--) { - SWITCH_INT(nu->knotsv[len]); - } + BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu)); } } @@ -3303,11 +3274,10 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache) /* the cache saves non-struct data without DNA */ if (pm->data[i] && ptcache_data_struct[i][0]=='\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { - int j, tot = (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */ + int tot = (BKE_ptcache_data_size (i) * pm->totpoint) / sizeof(int); /* data_size returns bytes */ int *poin = pm->data[i]; - for (j = 0; j < tot; j++) - SWITCH_INT(poin[j]); + BLI_endian_switch_int32_array(poin, tot); } } @@ -3776,12 +3746,7 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps)) { /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ /* this does swap for data written at write_mdisps() - readfile.c */ - int x; - float *tmpdisps = *mdisps[i].disps; - for (x = 0; x < mdisps[i].totdisp * 3; x++) { - SWITCH_INT(*tmpdisps); - tmpdisps++; - } + BLI_endian_switch_float_array(*mdisps[i].disps, mdisps[i].totdisp * 3); } if (!external && !mdisps[i].disps) mdisps[i].totdisp = 0; @@ -3951,11 +3916,8 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) TFace *tf = mesh->tface; int i; - for (i = 0; i < (mesh->totface); i++, tf++) { - SWITCH_INT(tf->col[0]); - SWITCH_INT(tf->col[1]); - SWITCH_INT(tf->col[2]); - SWITCH_INT(tf->col[3]); + for (i = 0; i < mesh->totface; i++, tf++) { + BLI_endian_switch_uint32_array(tf->col, 4); } } } @@ -4481,10 +4443,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) hmd->indexar = newdataadr(fd, hmd->indexar); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - for (a = 0; a < hmd->totindex; a++) { - SWITCH_INT(hmd->indexar[a]); - } + BLI_endian_switch_int32_array(hmd->indexar, hmd->totindex); } } else if (md->type == eModifierType_ParticleSystem) { @@ -4514,24 +4473,11 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) mmd->bindcos = newdataadr(fd, mmd->bindcos); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - - if (mmd->bindoffsets) - for (a=0; a<mmd->totvert+1; a++) - SWITCH_INT(mmd->bindoffsets[a]); - if (mmd->bindcagecos) - for (a=0; a<mmd->totcagevert*3; a++) - SWITCH_INT(mmd->bindcagecos[a]); - if (mmd->dynverts) - for (a=0; a<mmd->totvert; a++) - SWITCH_INT(mmd->dynverts[a]); - - if (mmd->bindweights) - for (a=0; a<mmd->totcagevert*mmd->totvert; a++) - SWITCH_INT(mmd->bindweights[a]); - if (mmd->bindcos) - for (a=0; a<mmd->totcagevert*3; a++) - SWITCH_INT(mmd->bindcos[a]); + if (mmd->bindoffsets) BLI_endian_switch_int32_array(mmd->bindoffsets, mmd->totvert + 1); + if (mmd->bindcagecos) BLI_endian_switch_float_array(mmd->bindcagecos, mmd->totcagevert * 3); + if (mmd->dynverts) BLI_endian_switch_int32_array(mmd->dynverts, mmd->totvert); + if (mmd->bindweights) BLI_endian_switch_float_array(mmd->bindweights, mmd->totvert); + if (mmd->bindcos) BLI_endian_switch_float_array(mmd->bindcos, mmd->totcagevert * 3); } } else if (md->type == eModifierType_Ocean) { @@ -4725,10 +4671,7 @@ static void direct_link_object(FileData *fd, Object *ob) hook->indexar= newdataadr(fd, hook->indexar); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - for (a = 0; a < hook->totindex; a++) { - SWITCH_INT(hook->indexar[a]); - } + BLI_endian_switch_int32_array(hook->indexar, hook->totindex); } /* Do conversion here because if we have loaded @@ -5023,7 +4966,6 @@ static void direct_link_scene(FileData *fd, Scene *sce) seq->seq1= newdataadr(fd, seq->seq1); seq->seq2= newdataadr(fd, seq->seq2); seq->seq3= newdataadr(fd, seq->seq3); - seq->mask_sequence= newdataadr(fd, seq->mask_sequence); /* a patch: after introduction of effects with 3 input strips */ if (seq->seq3 == NULL) seq->seq3 = seq->seq2; @@ -5069,16 +5011,9 @@ static void direct_link_scene(FileData *fd, Scene *sce) else { seq->strip->proxy = NULL; } - if (seq->flag & SEQ_USE_COLOR_BALANCE) { - seq->strip->color_balance = newdataadr( - fd, seq->strip->color_balance); - } - else { - seq->strip->color_balance = NULL; - } - if (seq->strip->color_balance) { - // seq->strip->color_balance->gui = 0; // XXX - peter, is this relevant in 2.5? - } + + /* need to load color balance to it could be converted to modifier */ + seq->strip->color_balance = newdataadr(fd, seq->strip->color_balance); } direct_link_sequence_modifiers(fd, &seq->modifiers); @@ -5825,7 +5760,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc) ScrArea *sa; ScrVert *sv; ScrEdge *se; - int a; link_list(fd, &(sc->vertbase)); link_list(fd, &(sc->edgebase)); @@ -5835,16 +5769,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc) sc->mainwin = sc->subwinactive= 0; /* indices */ sc->swap = 0; - - /* hacky patch... but people have been saving files with the verse-blender, - * causing the handler to keep running for ever, with no means to disable it */ - for (a = 0; a < SCREEN_MAXHANDLER; a+=2) { - if (sc->handler[a] == SCREEN_HANDLER_VERSE) { - sc->handler[a] = 0; - break; - } - } - + /* edges */ for (se = sc->edgebase.first; se; se = se->next) { se->v1 = newdataadr(fd, se->v1); @@ -6123,7 +6048,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) * it absolute. This can happen when appending an object with a relative * link into an unsaved blend file. See [#27405]. * The remap relative option will make it relative again on save - campbell */ - if (strncmp(lib->name, "//", 2) == 0) { + if (BLI_path_is_rel(lib->name)) { BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name)); } } @@ -6132,7 +6057,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) for (lib = main->library.first; lib; lib = lib->id.next) { /* Libraries store both relative and abs paths, recreate relative paths, * relative to the blend file since indirectly linked libs will be relative to their direct linked library */ - if (strncmp(lib->name, "//", 2) == 0) { /* if this is relative to begin with? */ + if (BLI_path_is_rel(lib->name)) { /* if this is relative to begin with? */ BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name)); BLI_path_rel(lib->name, basepath); } @@ -7275,8 +7200,8 @@ static void do_version_ntree_mask_264(void *UNUSED(data), ID *UNUSED(id), bNodeT if (node->storage == NULL) { NodeMask *data = MEM_callocN(sizeof(NodeMask), __func__); /* move settings into own struct */ - data->size_x = node->custom3; - data->size_y = node->custom4; + data->size_x = (int)node->custom3; + data->size_y = (int)node->custom4; node->custom3 = 0.5f; /* default shutter */ node->storage = data; } @@ -8134,6 +8059,42 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ntreetype->foreach_nodetree(main, NULL, do_version_ntree_mask_264); } + if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 18)) { + Scene *scene; + + for (scene = main->scene.first; scene; scene = scene->id.next) { + if (scene->ed) { + Sequence *seq; + + SEQ_BEGIN (scene->ed, seq) + { + Strip *strip = seq->strip; + + if (strip && strip->color_balance) { + SequenceModifierData *smd; + ColorBalanceModifierData *cbmd; + + smd = BKE_sequence_modifier_new(seq, NULL, seqModifierType_ColorBalance); + cbmd = (ColorBalanceModifierData *) smd; + + cbmd->color_balance = *strip->color_balance; + + /* multiplication with color balance used is handled differently, + * so we need to move multiplication to modifier so files would be + * compatible + */ + cbmd->color_multiply = seq->mul; + seq->mul = 1.0f; + + MEM_freeN(strip->color_balance); + strip->color_balance = NULL; + } + } + SEQ_END + } + } + } + /* default values in Freestyle settings */ { Scene *sce; @@ -9750,9 +9711,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) cleanup_path(G.main->name, mainptr->curlib->filepath); fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports); - fd->mainlist = mainlist; - + if (fd) { + fd->mainlist = mainlist; printf("found: '%s', party on macuno!\n", mainptr->curlib->filepath); } } diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c index a7dae22cda2..eaf725dda9e 100644 --- a/source/blender/blenloader/intern/runtime.c +++ b/source/blender/blenloader/intern/runtime.c @@ -50,7 +50,6 @@ #include "BKE_blender.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLI_blenlib.h" diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 1bad1bd80df..a4f190c8167 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -89,7 +89,6 @@ #include "BKE_screen.h" #include "BKE_sequencer.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" #include "NOD_socket.h" diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 8ace277b42d..1cc0d4180ab 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -95,7 +95,6 @@ #include "BKE_property.h" // for get_ob_property #include "BKE_scene.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "IMB_imbuf.h" // for proxy / timecode versioning stuff diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 769d33778ba..b2d4e905dc9 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -155,7 +155,6 @@ Any case: direct data is ALWAYS after the lib block #include "BKE_report.h" #include "BKE_sequencer.h" #include "BKE_subsurf.h" -#include "BKE_utildefines.h" #include "BKE_modifier.h" #include "BKE_fcurve.h" #include "BKE_pointcache.h" @@ -164,6 +163,7 @@ Any case: direct data is ALWAYS after the lib block #include "BLO_writefile.h" #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "readfile.h" @@ -2217,9 +2217,6 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->flag & SEQ_USE_PROXY && strip->proxy) { writestruct(wd, DATA, "StripProxy", 1, strip->proxy); } - if (seq->flag & SEQ_USE_COLOR_BALANCE && strip->color_balance) { - writestruct(wd, DATA, "StripColorBalance", 1, strip->color_balance); - } if (seq->type==SEQ_TYPE_IMAGE) writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata); else if (seq->type==SEQ_TYPE_MOVIE || seq->type==SEQ_TYPE_SOUND_RAM || seq->type == SEQ_TYPE_SOUND_HD) diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index ac002070484..955b1a729c5 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -196,6 +196,11 @@ * * There may be a better place for this section, but adding here for now. * + * \subsection bm_todo_api API + * + * - make crease and bevel weight optional, they come for free in meshes but are allocated layers + * in the bmesh data structure. + * * * \subsection bm_todo_tools Tools * diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 94d94cbec3e..f03ce9b8543 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -86,8 +86,9 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3], const BMVert *example) /* exception: don't copy the original shapekey index */ keyi = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_SHAPE_KEYINDEX); - if(keyi) + if (keyi) { *keyi = ORIGINDEX_NONE; + } } BM_CHECK_ELEMENT(v); @@ -339,6 +340,8 @@ BMFace *BM_face_create(BMesh *bm, BMVert **verts, BMEdge **edges, const int len, return f; } +#ifndef NDEBUG + /** * Check the element is valid. * @@ -357,14 +360,16 @@ int bmesh_elem_check(void *element, const char htype) return 2; switch (htype) { - case BM_VERT: { + case BM_VERT: + { BMVert *v = element; if (v->e && v->e->head.htype != BM_EDGE) { err |= 4; } break; } - case BM_EDGE: { + case BM_EDGE: + { BMEdge *e = element; if (e->l && e->l->head.htype != BM_LOOP) err |= 8; @@ -383,7 +388,8 @@ int bmesh_elem_check(void *element, const char htype) err |= 128; break; } - case BM_LOOP: { + case BM_LOOP: + { BMLoop *l = element, *l2; int i; @@ -423,7 +429,8 @@ int bmesh_elem_check(void *element, const char htype) break; } - case BM_FACE: { + case BM_FACE: + { BMFace *f = element; BMLoop *l_iter; BMLoop *l_first; @@ -471,6 +478,8 @@ int bmesh_elem_check(void *element, const char htype) return err; } +#endif /* NDEBUG */ + /** * low level function, only frees the vert, * doesn't change or adjust surrounding geometry @@ -1483,6 +1492,7 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **r_e) * and collapses the edge on that vertex. * * \par Examples: + * * <pre> * Before: OE KE * ------- ------- @@ -1792,18 +1802,21 @@ BMFace *bmesh_jfke(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e) int BM_vert_splice(BMesh *bm, BMVert *v, BMVert *vtarget) { BMEdge *e; - BMLoop *l; - BMIter liter; + + BMLoop **loops; + int i, loops_tot; /* verts already spliced */ if (v == vtarget) { return FALSE; } - /* retarget all the loops of v to vtarget */ - BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { - l->v = vtarget; + /* we can't modify the vert while iterating so first allocate an array of loops */ + loops = BM_iter_as_arrayN(bm, BM_LOOPS_OF_VERT, v, &loops_tot); + for (i = 0; i < loops_tot; i++) { + loops[i]->v = vtarget; } + MEM_freeN(loops); /* move all the edges from v's disk to vtarget's disk */ while ((e = v->e)) { diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c index 8103ae1ee11..726127fdcad 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.c +++ b/source/blender/bmesh/intern/bmesh_iterators.c @@ -28,6 +28,8 @@ * See: bmesh_iterators_inlin.c too, some functions are here for speed reasons. */ +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" #include "bmesh.h" @@ -105,6 +107,38 @@ int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, cons } /** + * \brief Iterator as Array + * + * Allocates a new array, has the advantage that you dont need to know the size ahead of time. + * + * Takes advantage of less common iterator usage to avoid counting twice, + * which you might end up doing when #BM_iter_as_array is used. + * + * Caller needs to free the array. + */ +void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len) +{ + BMIter iter; + + if (BM_iter_init(&iter, bm, itype, data) && iter.count > 0) { + BMElem *ele; + BMElem **array = MEM_mallocN(sizeof(ele) * iter.count, __func__); + int i = 0; + + *r_len = iter.count; /* set before iterating */ + + while ((ele = BM_iter_step(&iter))) { + array[i++] = ele; + } + return array; + } + else { + *r_len = 0; + return NULL; + } +} + +/** * \brief Elem Iter Flag Count * * Counts how many flagged / unflagged items are found in this element. diff --git a/source/blender/bmesh/intern/bmesh_iterators.h b/source/blender/bmesh/intern/bmesh_iterators.h index 1361a91a692..8d0eeca31ed 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.h +++ b/source/blender/bmesh/intern/bmesh_iterators.h @@ -115,10 +115,19 @@ typedef struct BMIter { char itype; } BMIter; -void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index); -int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len); -int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const short value); -int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const short value); +void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +#endif +; +int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len); +void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +#endif +; +int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const short value); +int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const short value); /* private for bmesh_iterators_inline.c */ void bmiter__vert_of_mesh_begin(struct BMIter *iter); diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index 58ccfa79a02..c0439311104 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -527,9 +527,9 @@ void BM_active_face_set(BMesh *bm, BMFace *efa) bm->act_face = efa; } -BMFace *BM_active_face_get(BMesh *bm, int sloppy) +BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected) { - if (bm->act_face) { + if (bm->act_face && (!selected || BM_elem_flag_test(bm->act_face, BM_ELEM_SELECT))) { return bm->act_face; } else if (sloppy) { @@ -546,6 +546,9 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy) if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { f = NULL; } + else if (selected && !BM_elem_flag_test(f, BM_ELEM_SELECT)) { + f = NULL; + } else { break; } @@ -768,7 +771,7 @@ void BM_select_history_validate(BMesh *bm) int BM_select_history_active_get(BMesh *bm, BMEditSelection *ese) { BMEditSelection *ese_last = bm->selected.last; - BMFace *efa = BM_active_face_get(bm, FALSE); + BMFace *efa = BM_active_face_get(bm, FALSE, FALSE); ese->next = ese->prev = NULL; diff --git a/source/blender/bmesh/intern/bmesh_marking.h b/source/blender/bmesh/intern/bmesh_marking.h index 9b73ed2c390..8d4397794d5 100644 --- a/source/blender/bmesh/intern/bmesh_marking.h +++ b/source/blender/bmesh/intern/bmesh_marking.h @@ -71,7 +71,7 @@ int BM_mesh_elem_hflag_count_disabled(BMesh *bm, const char htype, const char hf /* edit selection stuff */ void BM_active_face_set(BMesh *bm, BMFace *f); -BMFace *BM_active_face_get(BMesh *bm, int sloppy); +BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected); void BM_editselection_center(BMEditSelection *ese, float r_center[3]); void BM_editselection_normal(BMEditSelection *ese, float r_normal[3]); diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 0f2dc7041fa..53b95c97c8b 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -1417,7 +1417,8 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v case '=': case '%': break; - case 'm': { + case 'm': + { int size, c; c = NEXT_CHAR(fmt); @@ -1431,12 +1432,14 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v state = 1; break; } - case 'v': { + case 'v': + { BMO_slot_vec_set(op, slot_name, va_arg(vlist, float *)); state = 1; break; } - case 'e': { + case 'e': + { BMHeader *ele = va_arg(vlist, void *); BMOpSlot *slot = BMO_slot_get(op, slot_name); @@ -1447,7 +1450,8 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v state = 1; break; } - case 's': { + case 's': + { BMOperator *op2 = va_arg(vlist, void *); const char *slot_name2 = va_arg(vlist, char *); diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 807570f0d86..eb2b7721bdc 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -285,7 +285,7 @@ void calc_poly_plane(float (*verts)[3], const int nverts) * the list that bridges a concave region of the face or intersects * any of the faces's edges. */ -static void shrink_edgef(float v1[3], float v2[3], const float fac) +static void scale_edge_v3f(float v1[3], float v2[3], const float fac) { float mid[3]; @@ -502,7 +502,7 @@ void BM_face_normal_flip(BMesh *bm, BMFace *f) /* detects if two line segments cross each other (intersects). * note, there could be more winding cases then there needs to be. */ -static int linecrossesf(const float v1[2], const float v2[2], const float v3[2], const float v4[2]) +static int line_crosses_v2f(const float v1[2], const float v2[2], const float v3[2], const float v4[2]) { #define GETMIN2_AXIS(a, b, ma, mb, axis) \ @@ -606,13 +606,13 @@ int BM_face_point_inside_test(BMFace *f, const float co[3]) do { float v1[2], v2[2]; - v1[0] = (l_iter->prev->v->co[ax] - cent[ax]) * onepluseps + cent[ax]; - v1[1] = (l_iter->prev->v->co[ay] - cent[ay]) * onepluseps + cent[ay]; + v1[0] = (l_iter->prev->v->co[ax] - cent[0]) * onepluseps + cent[0]; + v1[1] = (l_iter->prev->v->co[ay] - cent[1]) * onepluseps + cent[1]; - v2[0] = (l_iter->v->co[ax] - cent[ax]) * onepluseps + cent[ax]; - v2[1] = (l_iter->v->co[ay] - cent[ay]) * onepluseps + cent[ay]; + v2[0] = (l_iter->v->co[ax] - cent[0]) * onepluseps + cent[0]; + v2[1] = (l_iter->v->co[ay] - cent[1]) * onepluseps + cent[1]; - crosses += linecrossesf(v1, v2, co2, out) != 0; + crosses += line_crosses_v2f(v1, v2, co2, out) != 0; } while ((l_iter = l_iter->next) != l_first); return crosses % 2 != 0; @@ -959,7 +959,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) BMIter iter; BMLoop *l; float v1[3], v2[3], v3[3] /*, v4[3 */, no[3], mid[3], *p1, *p2, *p3, *p4; - float out[3] = {-234324.0f, -234324.0f, 0.0f}; + float out[3] = {-FLT_MAX, -FLT_MAX, 0.0f}; float (*projverts)[3]; float (*edgeverts)[3]; float fac1 = 1.0000001f, fac2 = 0.9f; //9999f; //0.999f; @@ -980,7 +980,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) copy_v3_v3(v1, loops[i][0]->v->co); copy_v3_v3(v2, loops[i][1]->v->co); - shrink_edgef(v1, v2, fac2); + scale_edge_v3f(v1, v2, fac2); copy_v3_v3(edgeverts[a], v1); a++; @@ -994,14 +994,16 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) for (i = 0, l = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l = l->next) { p1 = projverts[i]; - out[0] = maxf(out[0], p1[0]) + 0.01f; - out[1] = maxf(out[1], p1[1]) + 0.01f; - out[2] = 0.0f; - p1[2] = 0.0f; + out[0] = maxf(out[0], p1[0]); + out[1] = maxf(out[1], p1[1]); + /* out[2] = 0.0f; */ /* keep at zero */ - //copy_v3_v3(l->v->co, p1); + p1[2] = 0.0f; } + /* ensure we are well outside the face bounds (value is arbitrary) */ + add_v2_fl(out, 1.0f); + for (i = 0; i < len; i++) { edgeverts[i * 2][2] = 0.0f; edgeverts[i * 2 + 1][2] = 0.0f; @@ -1019,19 +1021,26 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) p1 = projverts[j]; p2 = projverts[(j + 1) % f->len]; +#if 0 copy_v3_v3(v1, p1); copy_v3_v3(v2, p2); - shrink_edgef(v1, v2, fac1); - - if (linecrossesf(p1, p2, mid, out)) clen++; + scale_edge_v3f(v1, v2, fac1); + if (line_crosses_v2f(v1, v2, mid, out)) { + clen++; + } +#else + if (line_crosses_v2f(p1, p2, mid, out)) { + clen++; + } +#endif } - + if (clen % 2 == 0) { loops[i][0] = NULL; } } - + /* do line crossing test */ for (i = 0; i < f->len; i++) { p1 = projverts[i]; @@ -1040,7 +1049,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) copy_v3_v3(v1, p1); copy_v3_v3(v2, p2); - shrink_edgef(v1, v2, fac1); + scale_edge_v3f(v1, v2, fac1); for (j = 0; j < len; j++) { if (!loops[j][0]) { @@ -1050,7 +1059,7 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) p3 = edgeverts[j * 2]; p4 = edgeverts[j * 2 + 1]; - if (linecrossesf(v1, v2, p3, p4)) { + if (line_crosses_v2f(v1, v2, p3, p4)) { loops[j][0] = NULL; } } @@ -1067,9 +1076,9 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) copy_v3_v3(v1, p1); copy_v3_v3(v2, p2); - shrink_edgef(v1, v2, fac1); + scale_edge_v3f(v1, v2, fac1); - if (linecrossesf(v1, v2, p3, p4)) { + if (line_crosses_v2f(v1, v2, p3, p4)) { loops[i][0] = NULL; } } diff --git a/source/blender/bmesh/intern/bmesh_private.h b/source/blender/bmesh/intern/bmesh_private.h index 0827901f5c2..b3fe3676ab8 100644 --- a/source/blender/bmesh/intern/bmesh_private.h +++ b/source/blender/bmesh/intern/bmesh_private.h @@ -37,21 +37,21 @@ */ /* returns positive nonzero on error */ -int bmesh_elem_check(void *element, const char htype); -#define BM_CHECK_ELEMENT(el) \ +#ifdef NDEBUG + /* no error checking for release, + * it can take most of the CPU time when running some tools */ +# define BM_CHECK_ELEMENT(el) (void)(el) +#else +int bmesh_elem_check(void *element, const char htype); +# define BM_CHECK_ELEMENT(el) \ if (bmesh_elem_check(el, ((BMHeader *)el)->htype)) { \ printf("check_element failure, with code %i on line %i in file\n" \ " \"%s\"\n\n", \ - bmesh_elem_check(el, ((BMHeader *)el)->htype), \ + bmesh_elem_check(el, ((BMHeader *)el)->htype), \ __LINE__, __FILE__); \ - } - -#define BM_DISK_EDGE_LINK_GET(e, v) ( \ - ((v) == ((BMEdge *)(e))->v1) ? \ - &((e)->v1_disk_link) : \ - &((e)->v2_disk_link) \ - ) + } (void)0 +#endif int bmesh_radial_length(BMLoop *l); int bmesh_disk_count(BMVert *v); diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index a9f146e4962..d850eb34477 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -470,31 +470,12 @@ int BM_edge_face_count(BMEdge *e) } /** - * Returns the number of faces around this vert + * Returns the number of faces around this vert + * length matches #BM_LOOPS_OF_VERT iterator */ int BM_vert_face_count(BMVert *v) { - int count = 0; - BMLoop *l; - BMIter iter; - - BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) { - count++; - } - - return count; -#if 0 //this code isn't working - BMEdge *curedge = NULL; - - if (v->e) { - curedge = v->e; - do { - if (curedge->l) count += BM_edge_face_count(curedge); - curedge = bmesh_disk_edge_next(curedge, v); - } while (curedge != v->e); - } - return count; -#endif + return bmesh_disk_facevert_count(v); } /** @@ -503,22 +484,21 @@ int BM_vert_face_count(BMVert *v) */ int BM_vert_is_wire(BMVert *v) { - BMEdge *curedge; + if (v->e) { + BMEdge *e_first, *e_iter; - if (v->e == NULL) { + e_first = e_iter = v->e; + do { + if (e_iter->l) { + return FALSE; + } + } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first); + + return TRUE; + } + else { return FALSE; } - - curedge = v->e; - do { - if (curedge->l) { - return FALSE; - } - - curedge = bmesh_disk_edge_next(curedge, v); - } while (curedge != v->e); - - return TRUE; } /** diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index 2ff9e707b59..b58e61a3066 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -153,10 +153,22 @@ int bmesh_edge_swapverts(BMEdge *e, BMVert *orig, BMVert *newv) * advantage is that no intrinsic properties of the data structures are dependent upon the * cycle order and all non-manifold conditions are represented trivially. */ + +BLI_INLINE BMDiskLink *bmesh_disk_edge_link_from_vert(BMEdge *e, BMVert *v) +{ + if (v == e->v1) { + return &e->v1_disk_link; + } + else { + BLI_assert(v == e->v2); + return &e->v2_disk_link; + } +} + int bmesh_disk_edge_append(BMEdge *e, BMVert *v) { if (!v->e) { - BMDiskLink *dl1 = BM_DISK_EDGE_LINK_GET(e, v); + BMDiskLink *dl1 = bmesh_disk_edge_link_from_vert(e, v); v->e = e; dl1->next = dl1->prev = e; @@ -164,9 +176,9 @@ int bmesh_disk_edge_append(BMEdge *e, BMVert *v) else { BMDiskLink *dl1, *dl2, *dl3; - dl1 = BM_DISK_EDGE_LINK_GET(e, v); - dl2 = BM_DISK_EDGE_LINK_GET(v->e, v); - dl3 = dl2->prev ? BM_DISK_EDGE_LINK_GET(dl2->prev, v) : NULL; + dl1 = bmesh_disk_edge_link_from_vert(e, v); + dl2 = bmesh_disk_edge_link_from_vert(v->e, v); + dl3 = dl2->prev ? bmesh_disk_edge_link_from_vert(dl2->prev, v) : NULL; dl1->next = v->e; dl1->prev = dl2->prev; @@ -183,14 +195,14 @@ void bmesh_disk_edge_remove(BMEdge *e, BMVert *v) { BMDiskLink *dl1, *dl2; - dl1 = BM_DISK_EDGE_LINK_GET(e, v); + dl1 = bmesh_disk_edge_link_from_vert(e, v); if (dl1->prev) { - dl2 = BM_DISK_EDGE_LINK_GET(dl1->prev, v); + dl2 = bmesh_disk_edge_link_from_vert(dl1->prev, v); dl2->next = dl1->next; } if (dl1->next) { - dl2 = BM_DISK_EDGE_LINK_GET(dl1->next, v); + dl2 = bmesh_disk_edge_link_from_vert(dl1->next, v); dl2->prev = dl1->prev; } diff --git a/source/blender/bmesh/operators/bmo_connect.c b/source/blender/bmesh/operators/bmo_connect.c index 6943dcb3e5d..1987294fc42 100644 --- a/source/blender/bmesh/operators/bmo_connect.c +++ b/source/blender/bmesh/operators/bmo_connect.c @@ -45,18 +45,18 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) { BMIter iter, liter; BMFace *f, *nf; - BMLoop **loops = NULL, *lastl = NULL; - BLI_array_declare(loops); - BMLoop *l, *nl; - BMVert **verts = NULL; - BLI_array_declare(verts); + BMLoop *(*loops_split)[2] = NULL; + BLI_array_declare(loops_split); + BMLoop *l, *nl, *lastl = NULL; + BMVert *(*verts_pair)[2] = NULL; + BLI_array_declare(verts_pair); int i; BMO_slot_buffer_flag_enable(bm, op, "verts", BM_VERT, VERT_INPUT); for (f = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); f; f = BM_iter_step(&iter)) { - BLI_array_empty(loops); - BLI_array_empty(verts); + BLI_array_empty(loops_split); + BLI_array_empty(verts_pair); if (BMO_elem_flag_test(bm, f, FACE_NEW)) { continue; @@ -72,50 +72,44 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) } if (lastl != l->prev && lastl != l->next) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = lastl; - - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = l; + BLI_array_grow_one(loops_split); + loops_split[BLI_array_count(loops_split) - 1][0] = lastl; + loops_split[BLI_array_count(loops_split) - 1][1] = l; } lastl = l; } } - if (BLI_array_count(loops) == 0) { + if (BLI_array_count(loops_split) == 0) { continue; } - if (BLI_array_count(loops) > 2) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = loops[BLI_array_count(loops) - 2]; - - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = loops[0]; + if (BLI_array_count(loops_split) > 1) { + BLI_array_grow_one(loops_split); + loops_split[BLI_array_count(loops_split) - 1][0] = loops_split[BLI_array_count(loops_split) - 2][1]; + loops_split[BLI_array_count(loops_split) - 1][1] = loops_split[0][0]; } - BM_face_legal_splits(bm, f, (BMLoop *(*)[2])loops, BLI_array_count(loops) / 2); + BM_face_legal_splits(bm, f, loops_split, BLI_array_count(loops_split)); - for (i = 0; i < BLI_array_count(loops) / 2; i++) { - if (loops[i * 2] == NULL) { + for (i = 0; i < BLI_array_count(loops_split); i++) { + if (loops_split[i][0] == NULL) { continue; } - BLI_array_grow_one(verts); - verts[BLI_array_count(verts) - 1] = loops[i * 2]->v; - - BLI_array_grow_one(verts); - verts[BLI_array_count(verts) - 1] = loops[i * 2 + 1]->v; + BLI_array_grow_one(verts_pair); + verts_pair[BLI_array_count(verts_pair) - 1][0] = loops_split[i][0]->v; + verts_pair[BLI_array_count(verts_pair) - 1][1] = loops_split[i][1]->v; } - for (i = 0; i < BLI_array_count(verts) / 2; i++) { - nf = BM_face_split(bm, f, verts[i * 2], verts[i * 2 + 1], &nl, NULL, FALSE); + for (i = 0; i < BLI_array_count(verts_pair); i++) { + nf = BM_face_split(bm, f, verts_pair[i][0], verts_pair[i][1], &nl, NULL, FALSE); f = nf; if (!nl || !nf) { BMO_error_raise(bm, op, BMERR_CONNECTVERT_FAILED, NULL); - BLI_array_free(loops); + BLI_array_free(loops_split); return; } BMO_elem_flag_enable(bm, nf, FACE_NEW); @@ -125,8 +119,8 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op) BMO_slot_buffer_from_enabled_flag(bm, op, "edgeout", BM_EDGE, EDGE_OUT); - BLI_array_free(loops); - BLI_array_free(verts); + BLI_array_free(loops_split); + BLI_array_free(verts_pair); } static BMVert *get_outer_vert(BMesh *bm, BMEdge *e) @@ -345,7 +339,6 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op) goto cleanup; } - j = 0; if (vv1[0] == vv1[lenv1 - 1]) { lenv1--; } diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index 9ea8e631435..c8be7c9ce34 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -390,7 +390,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) if (!v1->e) BM_vert_kill(bm, v1); if (!v2->e) - BM_vert_kill(bm, v1); + BM_vert_kill(bm, v2); continue; } diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c index 3aa6e6dbe49..132d7050b31 100644 --- a/source/blender/bmesh/operators/bmo_inset.c +++ b/source/blender/bmesh/operators/bmo_inset.c @@ -283,7 +283,8 @@ void bmo_inset_exec(BMesh *bm, BMOperator *op) * cross product between both face normals */ add_v3_v3v3(tvec, e_info_a->no, e_info_b->no); - if ((f_a == f_b) || compare_v3v3(f_a->no, f_b->no, 0.00001f)) { + /* epsilon increased to fix [#32329] */ + if ((f_a == f_b) || compare_v3v3(f_a->no, f_b->no, 0.001f)) { normalize_v3(tvec); } else { diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 2af764060fb..b239be1c83b 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -308,7 +308,7 @@ static void quad_1edge_split(BMesh *bm, BMFace *UNUSED(face), } } -static SubDPattern quad_1edge = { +static const SubDPattern quad_1edge = { {1, 0, 0, 0}, quad_1edge_split, 4, @@ -337,7 +337,7 @@ static void quad_2edge_split_path(BMesh *bm, BMFace *UNUSED(face), BMVert **vert connect_smallest_face(bm, verts[numcuts * 2 + 3], verts[numcuts * 2 + 1], &nf); } -static SubDPattern quad_2edge_path = { +static const SubDPattern quad_2edge_path = { {1, 1, 0, 0}, quad_2edge_split_path, 4, @@ -379,7 +379,7 @@ static void quad_2edge_split_innervert(BMesh *bm, BMFace *UNUSED(face), BMVert * connect_smallest_face(bm, lastv, verts[numcuts * 2 + 2], &nf); } -static SubDPattern quad_2edge_innervert = { +static const SubDPattern quad_2edge_innervert = { {1, 1, 0, 0}, quad_2edge_split_innervert, 4, @@ -410,7 +410,7 @@ static void quad_2edge_split_fan(BMesh *bm, BMFace *UNUSED(face), BMVert **verts } } -static SubDPattern quad_2edge_fan = { +static const SubDPattern quad_2edge_fan = { {1, 1, 0, 0}, quad_2edge_split_fan, 4, @@ -449,7 +449,7 @@ static void quad_3edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, } } -static SubDPattern quad_3edge = { +static const SubDPattern quad_3edge = { {1, 1, 1, 0}, quad_3edge_split, 4, @@ -559,7 +559,7 @@ static void tri_1edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, } } -static SubDPattern tri_1edge = { +static const SubDPattern tri_1edge = { {1, 0, 0}, tri_1edge_split, 3, @@ -660,51 +660,55 @@ cleanup: MEM_freeN(lines); } -static SubDPattern tri_3edge = { +static const SubDPattern tri_3edge = { {1, 1, 1}, tri_3edge_subdivide, 3, }; -static SubDPattern quad_4edge = { +static const SubDPattern quad_4edge = { {1, 1, 1, 1}, quad_4edge_subdivide, 4, }; -static SubDPattern *patterns[] = { - NULL, //quad single edge pattern is inserted here - NULL, //quad corner vert pattern is inserted here - NULL, //tri single edge pattern is inserted here +static const SubDPattern *patterns[] = { + NULL, /* quad single edge pattern is inserted here */ + NULL, /* quad corner vert pattern is inserted here */ + NULL, /* tri single edge pattern is inserted here */ NULL, &quad_3edge, NULL, }; -#define PLEN (sizeof(patterns) / sizeof(void *)) +#define PATTERNS_TOT (sizeof(patterns) / sizeof(void *)) typedef struct SubDFaceData { - BMVert *start; SubDPattern *pat; - int totedgesel; //only used if pat was NULL, e.g. no pattern was found + BMVert *start; + const SubDPattern *pat; + int totedgesel; /* only used if pat was NULL, e.g. no pattern was found */ BMFace *face; } SubDFaceData; void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) { BMOpSlot *einput; - SubDPattern *pat; + const SubDPattern *pat; SubDParams params; SubDFaceData *facedata = NULL; + BLI_array_declare(facedata); BMIter viter, fiter, liter; BMVert *v, **verts = NULL; - BMEdge *edge, **edges = NULL; - BMLoop *nl, *l, **splits = NULL, **loops = NULL; - BMFace *face; - BLI_array_declare(splits); - BLI_array_declare(loops); - BLI_array_declare(facedata); + BMEdge *edge; + BMEdge **edges = NULL; BLI_array_declare(edges); + BMLoop *(*loops_split)[2] = NULL; + BLI_array_declare(loops_split); + BMLoop **loops = NULL; + BLI_array_declare(loops); + BMLoop *nl, *l; + BMFace *face; BLI_array_declare(verts); float smooth, fractal, along_normal; int use_sphere, cornertype, use_singleedge, use_gridfill; @@ -726,7 +730,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_srandom(seed); patterns[1] = NULL; - //straight cut is patterns[1] == NULL + /* straight cut is patterns[1] == NULL */ switch (cornertype) { case SUBD_PATH: patterns[1] = &quad_2edge_path; @@ -861,7 +865,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) continue; } - for (i = 0; i < PLEN; i++) { + for (i = 0; i < PATTERNS_TOT; i++) { pat = patterns[i]; if (!pat) { continue; @@ -935,12 +939,12 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) /* ok, no pattern. we still may be able to do something */ BLI_array_empty(loops); - BLI_array_empty(splits); + BLI_array_empty(loops_split); /* for case of two edges, connecting them shouldn't be too hard */ - BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = l; + BLI_array_grow_items(loops, face->len); + BM_ITER_ELEM_INDEX (l, &liter, face, BM_LOOPS_OF_FACE, a) { + loops[a] = l; } vlen = BLI_array_count(loops); @@ -971,23 +975,65 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) b += numcuts - 1; + BLI_array_grow_items(loops_split, numcuts); for (j = 0; j < numcuts; j++) { - BLI_array_grow_one(splits); - splits[BLI_array_count(splits) - 1] = loops[a]; - - BLI_array_grow_one(splits); - splits[BLI_array_count(splits) - 1] = loops[b]; + int ok = TRUE; + + /* Check for special case: [#32500] + * This edge pair could be used by more then one face, + * in this case it used to (2.63), split both faces along the same verts + * while it could be calculated which face should do the split, + * its ambigious, so in this case we're better off to skip them as exceptional cases + * and not try to be clever guessing which face to cut up. + * + * To avoid this case we need to check: + * Do the verts of each share a face besides the one we are subdividing, + * (but not connect to make an edge of that face). + */ + { + BMLoop *other_loop; + BMIter other_fiter; + BM_ITER_ELEM (other_loop, &other_fiter, loops[a]->v, BM_LOOPS_OF_VERT) { + if (other_loop->f != face) { + if (BM_vert_in_face(other_loop->f, loops[b]->v)) { + /* we assume that these verts are not making an edge in the face */ + BLI_assert(other_loop->prev->v != loops[a]->v); + BLI_assert(other_loop->next->v != loops[a]->v); + + ok = FALSE; + break; + } + } + } + } + + + if (ok == TRUE) { + loops_split[j][0] = loops[a]; + loops_split[j][1] = loops[b]; + } + else { + loops_split[j][0] = NULL; + loops_split[j][1] = NULL; + } b = (b - 1) % vlen; a = (a + 1) % vlen; } - //BM_face_legal_splits(bmesh, face, splits, BLI_array_count(splits) / 2); + /* Since these are newly created vertices, we don't need to worry about them being legal, + * ... though there are some cases we _should_ check for + * - concave corner of an ngon. + * - 2 edges being used in 2+ ngons. + */ +// BM_face_legal_splits(bm, face, loops_split, BLI_array_count(loops_split)); + + for (j = 0; j < BLI_array_count(loops_split); j++) { + if (loops_split[j][0]) { + BLI_assert(BM_edge_exists(loops_split[j][0]->v, loops_split[j][1]->v) == FALSE); - for (j = 0; j < BLI_array_count(splits) / 2; j++) { - if (splits[j * 2]) { /* BMFace *nf = */ /* UNUSED */ - BM_face_split(bm, face, splits[j * 2]->v, splits[j * 2 + 1]->v, &nl, NULL, FALSE); + BM_face_split(bm, face, loops_split[j][0]->v, loops_split[j][1]->v, &nl, NULL, FALSE); } } @@ -997,27 +1043,19 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) continue; } - j = a = 0; - for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); - nl; - nl = BM_iter_step(&liter)) - { + a = 0; + BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) { if (nl->v == facedata[i].start) { a = j + 1; break; } - j++; } - for (j = 0; j < face->len; j++) { - BLI_array_grow_one(verts); - } - - j = 0; - for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); nl; nl = BM_iter_step(&liter)) { + BLI_array_grow_items(verts, face->len); + + BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) { b = (j - a + face->len) % face->len; verts[b] = nl->v; - j += 1; } BM_CHECK_ELEMENT(face); @@ -1035,7 +1073,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) if (facedata) BLI_array_free(facedata); if (edges) BLI_array_free(edges); if (verts) BLI_array_free(verts); - BLI_array_free(splits); + BLI_array_free(loops_split); BLI_array_free(loops); BMO_slot_buffer_from_enabled_flag(bm, op, "outinner", BM_ALL, ELE_INNER); diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c index 85beb6d092b..91527313972 100644 --- a/source/blender/bmesh/tools/BME_bevel.c +++ b/source/blender/bmesh/tools/BME_bevel.c @@ -38,7 +38,6 @@ #include "BLI_ghash.h" #include "BLI_memarena.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_bmesh.h" diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index d241926c20c..b2748a55b6a 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -683,12 +683,11 @@ void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId& listid for (unsigned int i = 0; i < fcu->totvert; i++) { double input_fov = fcu->bezt[i].vec[1][1]; - double xfov = (fov_type == CAMERA_YFOV) ? aspect * input_fov : input_fov; - // fov is in degrees, cam->lens is in millimiters - double fov = fov_to_focallength(DEG2RADF(input_fov), cam->sensor_x); + // NOTE: Needs more testing (As we curretnly have no official test data for this) + double xfov = (fov_type == CAMERA_YFOV) ? (2.0f * atanf(aspect * tanf(DEG2RADF(input_fov) * 0.5f))) : DEG2RADF(input_fov); - fcu->bezt[i].vec[1][1] = fov; + fcu->bezt[i].vec[1][1] = fov_to_focallength(xfov, cam->sensor_x); } BLI_addtail(AnimCurves, fcu); diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index c47798ee804..7683ec1e9cd 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -99,7 +99,6 @@ extern char build_rev[]; #include "BKE_action.h" // pose functions #include "BKE_armature.h" #include "BKE_image.h" -#include "BKE_utildefines.h" #include "BKE_object.h" #include "BLI_math.h" @@ -164,6 +163,8 @@ void DocumentExporter::exportCurrentScene(Scene *sce) COLLADABU::NativeString(std::string(this->export_settings->filepath)); COLLADASW::StreamWriter sw(native_filename); + fprintf(stdout, "Collada export: %s\n", this->export_settings->filepath); + // open <collada> sw.startDocument(); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 60b03a211ba..f29933ea0c1 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -62,13 +62,13 @@ extern "C" { #include "BKE_texture.h" #include "BKE_fcurve.h" #include "BKE_depsgraph.h" -#include "BLI_path_util.h" #include "BKE_scene.h" #include "BKE_global.h" #include "BKE_material.h" -#include "BKE_utildefines.h" #include "BKE_image.h" +#include "BLI_path_util.h" + #include "DNA_camera_types.h" #include "DNA_lamp_types.h" @@ -867,9 +867,11 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) { double yfov = camera->getYFov().getValue(); double aspect = camera->getAspectRatio().getValue(); - double xfov = aspect * yfov; - // xfov is in degrees, cam->lens is in millimiters - cam->lens = fov_to_focallength(DEG2RADF(xfov), cam->sensor_x); + + // NOTE: Needs more testing (As we curretnly have no official test data for this) + + double xfov = 2.0f * atanf(aspect * tanf(DEG2RADF(yfov) * 0.5f)); + cam->lens = fov_to_focallength(xfov, cam->sensor_x); } break; } diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index c7ad2ff3975..27700444ba9 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -132,14 +132,17 @@ void GeometryExporter::operator()(Object *ob) createLooseEdgeList(ob, me, geom_id, norind); - // XXX slow - if (ob->totcol) { - for (int a = 0; a < ob->totcol; a++) { - createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); + // Only create Polylists if number of faces > 0 + if (me->totface > 0) { + // XXX slow + if (ob->totcol) { + for (int a = 0; a < ob->totcol; a++) { + createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); + } + } + else { + createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } - } - else { - createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } closeMesh(); @@ -248,7 +251,7 @@ void GeometryExporter::createPolylist(short material_index, // no faces using this material if (faces_in_polylist == 0) { - fprintf(stderr, "%s: no faces use material %d\n", id_name(ob).c_str(), material_index); + fprintf(stderr, "%s: material with index %d is not used.\n", id_name(ob).c_str(), material_index); return; } diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index 66dcec7d8e4..a15dadda8cf 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -39,7 +39,6 @@ extern "C" { #include "BKE_image.h" #include "BKE_main.h" #include "BKE_mesh.h" -#include "BKE_utildefines.h" #include "BLI_fileops.h" #include "BLI_path_util.h" #include "BLI_string.h" @@ -75,6 +74,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) short image_source = image->source; bool is_generated = image_source == IMA_SRC_GENERATED; + bool is_packed = image->packedfile != NULL; char export_path[FILE_MAX]; char source_path[FILE_MAX]; @@ -84,7 +84,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) // Destination folder for exported assets BLI_split_dir_part(this->export_settings->filepath, export_dir, sizeof(export_dir)); - if (is_generated || is_dirty || use_copies) { + if (is_generated || is_dirty || use_copies || is_packed) { // make absolute destination path @@ -97,7 +97,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) BLI_make_existing_file(export_path); } - if (is_generated || is_dirty) { + if (is_generated || is_dirty || is_packed) { // This image in its current state only exists in Blender memory. // So we have to export it. The export will keep the image state intact, @@ -120,12 +120,15 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) // This image is already located on the file system. // But we want to create copies here. - // To avoid overwroting images with same file name but - // differenet source locations - - if (BLI_copy(source_path, export_path) != 0) { - fprintf(stderr, "Collada export: Cannot copy image:\n source:%s\ndest :%s\n", source_path, export_path); - return; + // To move images into the same export directory. + // Note: If an image is already located in the export folder, + // then skip the copy (as it would result in a file copy error). + + if (BLI_path_cmp(source_path, export_path) != 0) { + if (BLI_copy(source_path, export_path) != 0) { + fprintf(stderr, "Collada export: Cannot copy image:\n source:%s\ndest :%s\n", source_path, export_path); + return; + } } BLI_strncpy(export_path, export_file, sizeof(export_path)); @@ -133,7 +136,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) } else { - // Do not make any vopies, but use the source path directly as reference + // Do not make any copies, but use the source path directly as reference // to the original image BLI_strncpy(export_path, source_path, sizeof(export_path)); diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 5593fe993f4..cf211e2fbb1 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -570,7 +570,7 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) if (loose_edge_count > 0) { unsigned int face_edge_count = me->totedge; - unsigned int total_edge_count = loose_edge_count + face_edge_count; + /* unsigned int total_edge_count = loose_edge_count + face_edge_count; */ /* UNUSED */ mesh_add_edges(me, loose_edge_count); MEdge *med = me->medge + face_edge_count; diff --git a/source/blender/compositor/COM_compositor.h b/source/blender/compositor/COM_compositor.h index d9cfae8edb9..f35bf71392c 100644 --- a/source/blender/compositor/COM_compositor.h +++ b/source/blender/compositor/COM_compositor.h @@ -277,6 +277,9 @@ extern "C" { * It can be executed during editing (blenkernel/node.c) or rendering * (renderer/pipeline.c) * + * @param rd [struct RenderData] + * Render data for this composite, this won't always belong to a scene. + * * @param editingtree [struct bNodeTree] * reference to the compositor editing tree * @@ -301,10 +304,17 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering); /** * @brief Deinitialize the compositor caches and allocated memory. + * Use COM_clearCaches to only free the caches. */ void COM_deinitialize(void); /** + * @brief Clear all compositor caches. (Compositor system will still remain available). + * To deinitialize the compositor use the COM_deinitialize method. + */ +// void COM_clearCaches(void); // NOT YET WRITTEN + +/** * @brief Return a list of highlighted bnodes pointers. * @return */ diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index d4fad80ed07..71067ac8f15 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -500,7 +500,8 @@ void Converter::convertResolution(SocketConnection *connection, ExecutionSystem system->addOperation(sxop); system->addOperation(syop); - unsigned int resolution[2] = {fromWidth, fromHeight}; + unsigned int resolution[2] = {fromOperation->getWidth(), + fromOperation->getHeight()}; scaleOperation->setResolution(resolution); sxop->setResolution(resolution); syop->setResolution(resolution); @@ -522,7 +523,8 @@ void Converter::convertResolution(SocketConnection *connection, ExecutionSystem system->addOperation(xop); system->addOperation(yop); - unsigned int resolution[2] = {toWidth, toHeight}; + unsigned int resolution[2] = {toOperation->getWidth(), + toOperation->getHeight()}; translateOperation->setResolution(resolution); xop->setResolution(resolution); yop->setResolution(resolution); diff --git a/source/blender/compositor/intern/COM_Device.h b/source/blender/compositor/intern/COM_Device.h index e33a2a4288f..dc39b2baca7 100644 --- a/source/blender/compositor/intern/COM_Device.h +++ b/source/blender/compositor/intern/COM_Device.h @@ -31,8 +31,15 @@ * work are packaged as a WorkPackage instance. */ class Device { + public: /** + * @brief Declaration of the virtual destructor + * @note resolve warning gcc 4.7 + */ + virtual ~Device() {} + + /** * @brief initialize the device */ virtual bool initialize() { return true; } diff --git a/source/blender/compositor/intern/COM_ExecutionSystemHelper.h b/source/blender/compositor/intern/COM_ExecutionSystemHelper.h index bd34fe8ab02..307e082ea80 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystemHelper.h +++ b/source/blender/compositor/intern/COM_ExecutionSystemHelper.h @@ -55,7 +55,7 @@ public: * this node is converted to a Node instance. * and the converted node is returned * - * @param bNode node to add + * @param b_node node to add * @return Node that represents the bNode or null when not able to convert. */ static Node *addNode(vector<Node *>& nodes, bNode *b_node, bool isInActiveGroup, bool fast); diff --git a/source/blender/compositor/intern/COM_Node.cpp b/source/blender/compositor/intern/COM_Node.cpp index 320baacb669..50393d14f35 100644 --- a/source/blender/compositor/intern/COM_Node.cpp +++ b/source/blender/compositor/intern/COM_Node.cpp @@ -137,6 +137,21 @@ void Node::addSetVectorOperation(ExecutionSystem *graph, InputSocket *inputsocke graph->addOperation(operation); } +/* when a node has no valid data (missing image or group pointer) */ +void Node::convertToOperations_invalid(ExecutionSystem *graph, CompositorContext *context) +{ + /* this is a really bad situation - bring on the pink! - so artists know this is bad */ + const float warning_color[4] = {1.0f, 0.0f, 1.0f, 1.0f}; + int index; + vector<OutputSocket *> &outputsockets = this->getOutputSockets(); + for (index = 0; index < outputsockets.size(); index++) { + SetColorOperation *operation = new SetColorOperation(); + this->getOutputSocket(index)->relinkConnections(operation->getOutputSocket()); + operation->setChannels(warning_color); + graph->addOperation(operation); + } +} + bNodeSocket *Node::getEditorInputSocket(int editorNodeInputSocketIndex) { bNodeSocket *bSock = (bNodeSocket *)this->getbNode()->inputs.first; diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h index e19b1d774c9..7ce40e3cb34 100644 --- a/source/blender/compositor/intern/COM_Node.h +++ b/source/blender/compositor/intern/COM_Node.h @@ -100,6 +100,13 @@ public: void addSetVectorOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex); /** + * when a node has no valid data (missing image or a group nodes ID pointer is NULL) + * call this function from #convertToOperations, this way the node sockets are converted + * into valid outputs, without this the compositor system gets confused and crashes, see [#32490] + */ + void convertToOperations_invalid(ExecutionSystem *graph, CompositorContext *context); + + /** * Creates a new link between an outputSocket and inputSocket and registrates the link to the graph * @return the new created link */ diff --git a/source/blender/compositor/intern/COM_NodeBase.h b/source/blender/compositor/intern/COM_NodeBase.h index 3c390f6bcdb..b55e444be80 100644 --- a/source/blender/compositor/intern/COM_NodeBase.h +++ b/source/blender/compositor/intern/COM_NodeBase.h @@ -71,13 +71,14 @@ protected: inline vector<OutputSocket *>& getOutputSockets() { return this->m_outputsockets; } -public: +protected: /** * @brief destructor * clean up memory related to this NodeBase. */ virtual ~NodeBase(); +public: /** * @brief get the reference to the SDNA bNode struct */ diff --git a/source/blender/compositor/intern/COM_NodeOperation.cpp b/source/blender/compositor/intern/COM_NodeOperation.cpp index bae884d713e..4ae114bd031 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cpp +++ b/source/blender/compositor/intern/COM_NodeOperation.cpp @@ -124,19 +124,26 @@ bool NodeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOper return false; } else { - unsigned int index; - vector<InputSocket *> &inputsockets = this->getInputSockets(); - - for (index = 0; index < inputsockets.size(); index++) { - InputSocket *inputsocket = inputsockets[index]; - if (inputsocket->isConnected()) { - NodeOperation *inputoperation = (NodeOperation *)inputsocket->getConnection()->getFromNode(); - bool result = inputoperation->determineDependingAreaOfInterest(input, readOperation, output); - if (result) { - return true; + rcti tempOutput; + bool first = true; + for (int i = 0 ; i < getNumberOfInputSockets() ; i ++) { + NodeOperation * inputOperation = this->getInputOperation(i); + if (inputOperation && inputOperation->determineDependingAreaOfInterest(input, readOperation, &tempOutput)) { + if (first) { + output->xmin = tempOutput.xmin; + output->ymin = tempOutput.ymin; + output->xmax = tempOutput.xmax; + output->ymax = tempOutput.ymax; + first = false; + } + else { + output->xmin = MIN2(output->xmin, tempOutput.xmin); + output->ymin = MIN2(output->ymin, tempOutput.ymin); + output->xmax = MAX2(output->xmax, tempOutput.xmax); + output->ymax = MAX2(output->ymax, tempOutput.ymax); } } } - return false; + return !first; } } diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cpp b/source/blender/compositor/intern/COM_OpenCLDevice.cpp index be5936b495e..d23ed245844 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.cpp +++ b/source/blender/compositor/intern/COM_OpenCLDevice.cpp @@ -110,7 +110,7 @@ void OpenCLDevice::COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offse { if (offsetIndex != -1) { cl_int error; - cl_int2 offset = {operation->getWidth(), operation->getHeight()}; + cl_int2 offset = {(cl_int)operation->getWidth(), (cl_int)operation->getHeight()}; error = clSetKernelArg(kernel, offsetIndex, sizeof(cl_int2), &offset); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } @@ -127,7 +127,7 @@ void OpenCLDevice::COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel ker void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer) { cl_int error; - const size_t size[] = {outputMemoryBuffer->getWidth(), outputMemoryBuffer->getHeight()}; + const size_t size[] = {(size_t)outputMemoryBuffer->getWidth(), (size_t)outputMemoryBuffer->getHeight()}; error = clEnqueueNDRangeKernel(this->m_queue, kernel, 2, NULL, size, 0, 0, 0, NULL); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } @@ -144,7 +144,10 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo size_t size[2]; cl_int2 offset; - if (this->m_vendorID == NVIDIA) {localSize = 32;} + if (this->m_vendorID == NVIDIA) { + localSize = 32; + } + bool breaked = false; for (offsety = 0; offsety < height && (!breaked); offsety += localSize) { offset[1] = offsety; @@ -154,6 +157,7 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo else { size[1] = height - offsety; } + for (offsetx = 0; offsetx < width && (!breaked); offsetx += localSize) { if (offsetx + localSize < width) { size[0] = localSize; diff --git a/source/blender/compositor/intern/COM_Socket.h b/source/blender/compositor/intern/COM_Socket.h index 2aebe262594..bad112d20c7 100644 --- a/source/blender/compositor/intern/COM_Socket.h +++ b/source/blender/compositor/intern/COM_Socket.h @@ -62,6 +62,14 @@ private: DataType m_datatype; bNodeSocket *m_editorSocket; + +protected: + /** + * @brief Declaration of the virtual destructor + * @note resolve warning gcc 4.7 + */ + virtual ~Socket() {} + public: Socket(DataType datatype); diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index 5f133fe071f..f732a40e768 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -54,6 +54,7 @@ static vector<CPUDevice *> g_cpudevices; #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE /// @brief list of all thread for every CPUDevice in cpudevices a thread exists static ListBase g_cputhreads; +static bool g_cpuInitialized = false; /// @brief all scheduled work for the cpu static ThreadQueue *g_cpuqueue; static ThreadQueue *g_gpuqueue; @@ -67,11 +68,13 @@ static ListBase g_gputhreads; /// @brief all scheduled work for the gpu #ifdef COM_OPENCL_ENABLED static bool g_openclActive = false; +static bool g_openclInitialized = false; #endif #endif #endif #define MAX_HIGHLIGHT 8 +static bool g_highlightInitialized = false; extern "C" { int g_highlightIndex; void **g_highlightedNodes; @@ -90,8 +93,10 @@ void **g_highlightedNodesRead; if (node->original) { \ node = node->original; \ } \ - if (g_highlightIndex < MAX_HIGHLIGHT) { \ - g_highlightedNodes[g_highlightIndex++] = node; \ + if (g_highlightInitialized && g_highlightedNodes) { \ + if (g_highlightIndex < MAX_HIGHLIGHT) { \ + g_highlightedNodes[g_highlightIndex++] = node; \ + } \ } \ } \ } \ @@ -100,7 +105,13 @@ void **g_highlightedNodesRead; void COM_startReadHighlights() { - if (g_highlightedNodesRead) { + if (!g_highlightInitialized) + { + return; + } + + if (g_highlightedNodesRead) + { MEM_freeN(g_highlightedNodesRead); } @@ -111,11 +122,15 @@ void COM_startReadHighlights() int COM_isHighlightedbNode(bNode *bnode) { + if (!g_highlightInitialized) { + return false; + } + if (!g_highlightedNodesRead) { return false; } - for (int i = 0 ; i < MAX_HIGHLIGHT; i++) { + for (int i = 0; i < MAX_HIGHLIGHT; i++) { void *p = g_highlightedNodesRead[i]; if (!p) return false; if (p == bnode) return true; @@ -255,40 +270,59 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t printf("OPENCL error: %s\n", errinfo); } -void WorkScheduler::initialize() +void WorkScheduler::initialize(bool use_opencl) { - if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead); - if (g_highlightedNodes) MEM_freeN(g_highlightedNodes); + /* initialize highlighting */ + if (!g_highlightInitialized) { + if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead); + if (g_highlightedNodes) MEM_freeN(g_highlightedNodes); + + g_highlightedNodesRead = NULL; + g_highlightedNodes = NULL; - g_highlightedNodesRead = NULL; - g_highlightedNodes = NULL; + COM_startReadHighlights(); + + g_highlightInitialized = true; + } - COM_startReadHighlights(); #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE - int numberOfCPUThreads = BLI_system_thread_count(); + /* initialize CPU threads */ + if (!g_cpuInitialized) { + int numberOfCPUThreads = BLI_system_thread_count(); - for (int index = 0; index < numberOfCPUThreads; index++) { - CPUDevice *device = new CPUDevice(); - device->initialize(); - g_cpudevices.push_back(device); + for (int index = 0; index < numberOfCPUThreads; index++) { + CPUDevice *device = new CPUDevice(); + device->initialize(); + g_cpudevices.push_back(device); + } + + g_cpuInitialized = true; } + #ifdef COM_OPENCL_ENABLED - g_context = NULL; - g_program = NULL; - if (clCreateContextFromType) { - cl_uint numberOfPlatforms = 0; - cl_int error; - error = clGetPlatformIDs(0, 0, &numberOfPlatforms); - if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } - if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms); - cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__); - error = clGetPlatformIDs(numberOfPlatforms, platforms, 0); - unsigned int indexPlatform; - for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) { - cl_platform_id platform = platforms[indexPlatform]; - cl_uint numberOfDevices = 0; - clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices); - if (numberOfDevices > 0) { + /* deinitialize OpenCL GPU's */ + if (use_opencl && !g_openclInitialized) { + g_context = NULL; + g_program = NULL; + + OCL_init(); /* this will check and skip if already initialized */ + + if (clCreateContextFromType) { + cl_uint numberOfPlatforms = 0; + cl_int error; + error = clGetPlatformIDs(0, 0, &numberOfPlatforms); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms); + cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__); + error = clGetPlatformIDs(numberOfPlatforms, platforms, 0); + unsigned int indexPlatform; + for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) { + cl_platform_id platform = platforms[indexPlatform]; + cl_uint numberOfDevices = 0; + clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices); + if (numberOfDevices <= 0) + continue; + cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__); clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0); @@ -324,8 +358,10 @@ void WorkScheduler::initialize() } MEM_freeN(cldevices); } + MEM_freeN(platforms); } - MEM_freeN(platforms); + + g_openclInitialized = true; } #endif #endif @@ -334,37 +370,55 @@ void WorkScheduler::initialize() void WorkScheduler::deinitialize() { #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE - Device *device; - while (g_cpudevices.size() > 0) { - device = g_cpudevices.back(); - g_cpudevices.pop_back(); - device->deinitialize(); - delete device; + /* deinitialize CPU threads */ + if (g_cpuInitialized) { + Device *device; + while (g_cpudevices.size() > 0) { + device = g_cpudevices.back(); + g_cpudevices.pop_back(); + device->deinitialize(); + delete device; + } + + g_cpuInitialized = false; } + #ifdef COM_OPENCL_ENABLED - while (g_gpudevices.size() > 0) { - device = g_gpudevices.back(); - g_gpudevices.pop_back(); - device->deinitialize(); - delete device; - } - if (g_program) { - clReleaseProgram(g_program); - g_program = NULL; - } - if (g_context) { - clReleaseContext(g_context); - g_context = NULL; + /* deinitialize OpenCL GPU's */ + if (g_openclInitialized) { + Device *device; + while (g_gpudevices.size() > 0) { + device = g_gpudevices.back(); + g_gpudevices.pop_back(); + device->deinitialize(); + delete device; + } + if (g_program) { + clReleaseProgram(g_program); + g_program = NULL; + } + if (g_context) { + clReleaseContext(g_context); + g_context = NULL; + } + + g_openclInitialized = false; } #endif #endif - if (g_highlightedNodes) { - MEM_freeN(g_highlightedNodes); - } + /* deinitialize highlighting */ + if (g_highlightInitialized) { + g_highlightInitialized = false; + if (g_highlightedNodes) { + MEM_freeN(g_highlightedNodes); + g_highlightedNodes = NULL; + } - if (g_highlightedNodesRead) { - MEM_freeN(g_highlightedNodesRead); + if (g_highlightedNodesRead) { + MEM_freeN(g_highlightedNodesRead); + g_highlightedNodesRead = NULL; + } } } diff --git a/source/blender/compositor/intern/COM_WorkScheduler.h b/source/blender/compositor/intern/COM_WorkScheduler.h index f56fe94201e..4ab23cf9ae4 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.h +++ b/source/blender/compositor/intern/COM_WorkScheduler.h @@ -74,8 +74,10 @@ public: * After mutex initialization the system is queried in order to count the number of CPUDevices and GPUDevices to be created. * For every hardware thread a CPUDevice and for every OpenCL GPU device a OpenCLDevice is created. * these devices are stored in a separate list (cpudevices & gpudevices) + * + * This function can be called multiple times to lazily initialize OpenCL. */ - static void initialize(); + static void initialize(bool use_opencl); /** * @brief deinitialize the WorkScheduler diff --git a/source/blender/compositor/intern/COM_compositor.cpp b/source/blender/compositor/intern/COM_compositor.cpp index 7dcb3572a14..cb9166c929d 100644 --- a/source/blender/compositor/intern/COM_compositor.cpp +++ b/source/blender/compositor/intern/COM_compositor.cpp @@ -36,29 +36,39 @@ extern "C" { static ThreadMutex s_compositorMutex; static char is_compositorMutex_init = FALSE; + +void intern_freeCompositorCaches() +{ + deintializeDistortionCache(); +} + void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) { - if (is_compositorMutex_init == FALSE) { /// TODO: move to blender startup phase - memset(&s_compositorMutex, 0, sizeof(s_compositorMutex)); + /* initialize mutex, TODO this mutex init is actually not thread safe and + * should be done somewhere as part of blender startup, all the other + * initializations can be done lazily */ + if (is_compositorMutex_init == FALSE) { BLI_mutex_init(&s_compositorMutex); - OCL_init(); - WorkScheduler::initialize(); ///TODO: call workscheduler.deinitialize somewhere is_compositorMutex_init = TRUE; } + BLI_mutex_lock(&s_compositorMutex); + if (editingtree->test_break(editingtree->tbh)) { // during editing multiple calls to this method can be triggered. // make sure one the last one will be doing the work. BLI_mutex_unlock(&s_compositorMutex); return; - } + /* initialize workscheduler, will check if already done. TODO deinitialize somewhere */ + bool use_opencl = (editingtree->flag & NTREE_COM_OPENCL); + WorkScheduler::initialize(use_opencl); /* set progress bar to 0% and status to init compositing */ editingtree->progress(editingtree->prh, 0.0); - bool twopass = (editingtree->flag&NTREE_TWO_PASS) > 0 && !rendering; + bool twopass = (editingtree->flag & NTREE_TWO_PASS) > 0 && !rendering; /* initialize execution system */ if (twopass) { ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass); @@ -81,12 +91,20 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) BLI_mutex_unlock(&s_compositorMutex); } +void COM_freeCaches() +{ + if (is_compositorMutex_init) { + BLI_mutex_lock(&s_compositorMutex); + intern_freeCompositorCaches(); + BLI_mutex_unlock(&s_compositorMutex); + } +} + void COM_deinitialize() { - if (is_compositorMutex_init) - { + if (is_compositorMutex_init) { BLI_mutex_lock(&s_compositorMutex); - deintializeDistortionCache(); + intern_freeCompositorCaches(); WorkScheduler::deinitialize(); is_compositorMutex_init = FALSE; BLI_mutex_unlock(&s_compositorMutex); diff --git a/source/blender/compositor/nodes/COM_GroupNode.cpp b/source/blender/compositor/nodes/COM_GroupNode.cpp index b1bc0966687..e10d7dbad2e 100644 --- a/source/blender/compositor/nodes/COM_GroupNode.cpp +++ b/source/blender/compositor/nodes/COM_GroupNode.cpp @@ -33,16 +33,7 @@ GroupNode::GroupNode(bNode *editorNode) : Node(editorNode) void GroupNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { if (this->getbNode()->id == NULL) { - /* this is a really bad situation - bring on the pink! - so artists know this is bad */ - const float warning_color[4] = {1.0f, 0.0f, 1.0f, 1.0f}; - int index; - vector<OutputSocket *> &outputsockets = this->getOutputSockets(); - for (index = 0; index < outputsockets.size(); index++) { - SetColorOperation *operation = new SetColorOperation(); - this->getOutputSocket(index)->relinkConnections(operation->getOutputSocket()); - operation->setChannels(warning_color); - graph->addOperation(operation); - } + convertToOperations_invalid(graph, context); } } diff --git a/source/blender/compositor/nodes/COM_ImageNode.cpp b/source/blender/compositor/nodes/COM_ImageNode.cpp index addde140b9f..2d13ffb82b6 100644 --- a/source/blender/compositor/nodes/COM_ImageNode.cpp +++ b/source/blender/compositor/nodes/COM_ImageNode.cpp @@ -72,12 +72,16 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type == IMA_TYPE_MULTILAYER) { + bool is_multilayer_ok = false; BKE_image_get_ibuf(image, imageuser); if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { OutputSocket *socket; int index; + + is_multilayer_ok = true; + for (index = 0; index < numberOfOutputs; index++) { socket = this->getOutputSocket(index); if (socket->isConnected() || index == 0) { @@ -114,6 +118,11 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c } } } + + /* without this, multilayer that fail to load will crash blender [#32490] */ + if (is_multilayer_ok == false) { + convertToOperations_invalid(graph, context); + } } else { if (numberOfOutputs > 0) { diff --git a/source/blender/compositor/nodes/COM_MovieClipNode.cpp b/source/blender/compositor/nodes/COM_MovieClipNode.cpp index a250841b160..6d5b9bba8aa 100644 --- a/source/blender/compositor/nodes/COM_MovieClipNode.cpp +++ b/source/blender/compositor/nodes/COM_MovieClipNode.cpp @@ -49,10 +49,14 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex bNode *editorNode = this->getbNode(); MovieClip *movieClip = (MovieClip *)editorNode->id; MovieClipUser *movieClipUser = (MovieClipUser *)editorNode->storage; - + bool cacheFrame = !context->isRendering(); + ImBuf *ibuf = NULL; if (movieClip) { - ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); + if (cacheFrame) + ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); + else + ibuf = BKE_movieclip_get_ibuf_flag(movieClip, movieClipUser, movieClip->flag, MOVIECLIP_CACHE_SKIP); } // always connect the output image @@ -78,10 +82,11 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex outputMovieClip->relinkConnections(operation->getOutputSocket()); } } + operation->setMovieClip(movieClip); operation->setMovieClipUser(movieClipUser); operation->setFramenumber(context->getFramenumber()); - operation->setCacheFrame(!context->isRendering()); + operation->setCacheFrame(cacheFrame); graph->addOperation(operation); MovieTrackingStabilization *stab = &movieClip->tracking.stabilization; diff --git a/source/blender/compositor/nodes/COM_OutputFileNode.cpp b/source/blender/compositor/nodes/COM_OutputFileNode.cpp index e85f521def0..b8cee29fee6 100644 --- a/source/blender/compositor/nodes/COM_OutputFileNode.cpp +++ b/source/blender/compositor/nodes/COM_OutputFileNode.cpp @@ -24,8 +24,8 @@ #include "COM_OutputFileNode.h" #include "COM_OutputFileOperation.h" #include "COM_ExecutionSystem.h" + #include "BLI_path_util.h" -#include "BKE_utildefines.h" OutputFileNode::OutputFileNode(bNode *editorNode) : Node(editorNode) { diff --git a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp index c37830a9d92..867053bf1d2 100644 --- a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp +++ b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp @@ -23,7 +23,6 @@ #include "COM_AntiAliasOperation.h" #include "BLI_math.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp b/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp index ded686bb5de..3ced0548bb8 100644 --- a/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp +++ b/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp @@ -37,31 +37,6 @@ CombineChannelsOperation::CombineChannelsOperation() : NodeOperation() this->m_inputChannel4Operation = NULL; } -bool CombineChannelsOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) -{ - rcti tempOutput; - bool first = true; - for (int i = 0 ; i < 4 ; i ++) { - NodeOperation * inputOperation = this->getInputOperation(i); - if (inputOperation->determineDependingAreaOfInterest(input, readOperation, &tempOutput)) { - if (first) { - output->xmin = tempOutput.xmin; - output->ymin = tempOutput.ymin; - output->xmax = tempOutput.xmax; - output->ymax = tempOutput.ymax; - first = false; - } - else { - output->xmin = MIN2(output->xmin, tempOutput.xmin); - output->ymin = MIN2(output->ymin, tempOutput.ymin); - output->xmax = MAX2(output->xmax, tempOutput.xmax); - output->ymax = MAX2(output->ymax, tempOutput.ymax); - } - } - } - return !first; -} - void CombineChannelsOperation::initExecution() { this->m_inputChannel1Operation = this->getInputSocketReader(0); @@ -82,7 +57,6 @@ void CombineChannelsOperation::deinitExecution() void CombineChannelsOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; - /// @todo: remove if statements if (this->m_inputChannel1Operation) { this->m_inputChannel1Operation->read(input, x, y, sampler); output[0] = input[0]; diff --git a/source/blender/compositor/operations/COM_CombineChannelsOperation.h b/source/blender/compositor/operations/COM_CombineChannelsOperation.h index 460eb9bdcb1..7c8742b1557 100644 --- a/source/blender/compositor/operations/COM_CombineChannelsOperation.h +++ b/source/blender/compositor/operations/COM_CombineChannelsOperation.h @@ -37,8 +37,6 @@ public: void initExecution(); void deinitExecution(); - - bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); }; #endif diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index ae94e974db0..c1d91c16a3c 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -31,6 +31,9 @@ */ class CompositorOperation : public NodeOperation { private: + /** + * @brief Scene name, used for getting the render output, includes 'SC' prefix. + */ char m_sceneName[MAX_ID_NAME]; /** diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp index a156dfc1d99..36b3f2023ae 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cpp +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -93,7 +93,7 @@ void MaskOperation::initExecution() frame_iter += frame_step; } - BKE_mask_free(mask_temp); + BKE_mask_free_nolib(mask_temp); MEM_freeN(mask_temp); } } diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cpp b/source/blender/compositor/operations/COM_MovieClipOperation.cpp index b73db74b061..709e4b7d4b0 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cpp @@ -48,14 +48,10 @@ void MovieClipOperation::initExecution() BKE_movieclip_user_set_frame(this->m_movieClipUser, this->m_framenumber); ImBuf *ibuf; - if (this->m_cacheFrame) { + if (this->m_cacheFrame) ibuf = BKE_movieclip_get_ibuf(this->m_movieClip, this->m_movieClipUser); - } - else { - int flag = this->m_movieClip->flag & MCLIP_TIMECODE_FLAGS; - - ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, flag, MOVIECLIP_CACHE_SKIP); - } + else + ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, this->m_movieClip->flag, MOVIECLIP_CACHE_SKIP); if (ibuf) { this->m_movieClipBuffer = ibuf; diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0d6e5bfa61a..532242c97ce 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -24,8 +24,9 @@ #ifndef _COM_OutputFileOperation_h #define _COM_OutputFileOperation_h #include "COM_NodeOperation.h" + #include "BLI_rect.h" -#include "BKE_utildefines.h" +#include "BLI_path_util.h" #include "intern/openexr/openexr_multi.h" diff --git a/source/blender/compositor/operations/COM_RenderLayersImageProg.h b/source/blender/compositor/operations/COM_RenderLayersImageProg.h index 2d63bad235b..5fa74c8b21f 100644 --- a/source/blender/compositor/operations/COM_RenderLayersImageProg.h +++ b/source/blender/compositor/operations/COM_RenderLayersImageProg.h @@ -25,7 +25,7 @@ #include "COM_RenderLayersBaseProg.h" -/// @TODO rename to image operation +/// @todo rename to image operation class RenderLayersColorProg : public RenderLayersBaseProg { public: RenderLayersColorProg(); diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index eb9889ce847..f220f0ee762 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -62,7 +62,6 @@ #include "BKE_curve.h" #include "BKE_key.h" #include "BKE_context.h" -#include "BKE_utildefines.h" /* FILE_MAX */ #include "UI_interface.h" #include "UI_interface_icons.h" diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index 3255bc47148..6ce9fc638be 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_node.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "RNA_access.h" diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index dd6778a79cd..7a80cab93e5 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -90,7 +90,6 @@ #include "BKE_node.h" #include "BKE_mask.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "ED_anim_api.h" #include "ED_markers.h" @@ -1409,13 +1408,13 @@ static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const i /* only if selected */ if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay)) ) { /* only if editable */ -// if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) { + if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) { /* active... */ if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) { /* add to list */ ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask); } -// } + } } } diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 95adaa01b94..445b684c261 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -1019,6 +1019,7 @@ static void select_timeline_marker_frame(ListBase *markers, int frame, unsigned static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera) { ListBase *markers = ED_context_get_markers(C); + ARegion *ar = CTX_wm_region(C); View2D *v2d = UI_view2d_fromcontext(C); float viewx; int x, y, cfra; @@ -1026,8 +1027,8 @@ static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera) if (markers == NULL) return OPERATOR_PASS_THROUGH; - x = evt->x - CTX_wm_region(C)->winrct.xmin; - y = evt->y - CTX_wm_region(C)->winrct.ymin; + x = evt->x - ar->winrct.xmin; + y = evt->y - ar->winrct.ymin; UI_view2d_region_to_view(v2d, x, y, &viewx, NULL); diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c index 46537674e59..6c9105dde69 100644 --- a/source/blender/editors/animation/keyframes_draw.c +++ b/source/blender/editors/animation/keyframes_draw.c @@ -412,7 +412,7 @@ static void add_bezt_to_keyblocks_list(DLRBT_Tree *blocks, DLRBT_Tree *beztTree, * -> firstly, handles must have same central value as each other * -> secondly, handles which control that section of the curve must be constant */ - if ((!prev) || (!beztn)) return; + if (prev == NULL) return; if (IS_EQF(beztn->vec[1][1], prev->vec[1][1]) == 0) return; if (IS_EQF(beztn->vec[1][1], beztn->vec[0][1]) == 0) return; if (IS_EQF(prev->vec[1][1], prev->vec[2][1]) == 0) return; diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 3883dce7671..b5c0555bf63 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -45,7 +45,6 @@ #include "BKE_fcurve.h" -#include "BKE_utildefines.h" #include "BKE_report.h" #include "BKE_library.h" #include "BKE_global.h" diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 3ef686910e6..8cd8cfaea51 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -164,10 +164,7 @@ FCurve *verify_fcurve(bAction *act, const char group[], PointerRNA *ptr, * - add if not found and allowed to add one * TODO: add auto-grouping support? how this works will need to be resolved */ - if (act) - fcu = list_find_fcurve(&act->curves, rna_path, array_index); - else - fcu = NULL; + fcu = list_find_fcurve(&act->curves, rna_path, array_index); if ((fcu == NULL) && (add)) { /* use default settings to make a F-Curve */ diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index 23c987c3536..eea7424c59a 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -1006,7 +1006,7 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) /* get search-string */ index = pld->search_cursor; - if (index >= 0 && index <= sizeof(tempstr) - 1) { + if (index >= 0 && index < sizeof(tempstr) - 1) { memcpy(&tempstr[0], &pld->searchstr[0], index); tempstr[index] = '|'; memcpy(&tempstr[index + 1], &pld->searchstr[index], (sizeof(tempstr) - 1) - index); diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index cd2ca16fec5..e9424a08b0c 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -274,7 +274,7 @@ void POSE_OT_paths_calculate(wmOperatorType *ot) /* api callbacks */ ot->invoke = pose_calculate_paths_invoke; ot->exec = pose_calculate_paths_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -319,7 +319,7 @@ void POSE_OT_paths_update(wmOperatorType *ot) /* api callbakcs */ ot->exec = pose_update_paths_exec; - ot->poll = ED_operator_posemode; /* TODO: this should probably check for active bone and/or existing paths */ + ot->poll = ED_operator_posemode_exclusive; /* TODO: this should probably check for active bone and/or existing paths */ /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -380,7 +380,7 @@ void POSE_OT_paths_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_clear_paths_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -2192,7 +2192,7 @@ void POSE_OT_bone_layers(wmOperatorType *ot) /* callbacks */ ot->invoke = pose_bone_layers_invoke; ot->exec = pose_bone_layers_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -2350,20 +2350,18 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { pose_bone_do_paste(ob, pchan, only_select, 0); } - + /* free temp data - free manually as was copied without constraints */ - if (dummyPose) { - for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->prop) { - IDP_FreeProperty(pchan->prop); - MEM_freeN(pchan->prop); - } + for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { + if (pchan->prop) { + IDP_FreeProperty(pchan->prop); + MEM_freeN(pchan->prop); } - - /* was copied without constraints */ - BLI_freelistN(&dummyPose->chanbase); - MEM_freeN(dummyPose); } + + /* was copied without constraints */ + BLI_freelistN(&dummyPose->chanbase); + MEM_freeN(dummyPose); } else { /* no animation, so just reset whole pose to rest pose diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index ce4e1db23b5..00f88a69fb6 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -3272,7 +3272,7 @@ ReebGraph *BIF_ReebGraphFromEditMesh(void) freeEdgeIndex(&indexed_edges); #ifdef DEBUG_REEB - weightToVCol(em, 1); +// weightToVCol(em, 1); #endif rg = generateReebGraph(em, G.scene->toolsettings->skgen_resolution); diff --git a/source/blender/editors/armature/reeb.h b/source/blender/editors/armature/reeb.h index d71e80ca0ca..bb8b3003baf 100644 --- a/source/blender/editors/armature/reeb.h +++ b/source/blender/editors/armature/reeb.h @@ -146,9 +146,9 @@ struct EdgeIndex; int weightToHarmonic(struct EditMesh *em, struct EdgeIndex *indexed_edges); int weightFromDistance(struct EditMesh *em, struct EdgeIndex *indexed_edges); int weightFromLoc(struct EditMesh *me, int axis); -void weightToVCol(struct EditMesh *em, int index); +//void weightToVCol(struct EditMesh *em, int index); void arcToVCol(struct ReebGraph *rg, struct EditMesh *em, int index); -void angleToVCol(struct EditMesh *em, int index); +//void angleToVCol(struct EditMesh *em, int index); void renormalizeWeight(struct EditMesh *em, float newmax); ReebGraph *generateReebGraph(struct EditMesh *me, int subdivisions); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index e2d15897233..d780429784f 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -107,7 +107,7 @@ void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatu static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short selstatus); /* still need to eradicate a few :( */ -#define callocstructN(x, y, name) (x *)MEM_callocN((y) * sizeof(x), name) +#define CALLOC_STRUCT_N(x, y, name) (x *)MEM_callocN((y) * sizeof(x), name) static float nurbcircle[8][2] = { {0.0, -1.0}, {-1.0, -1.0}, {-1.0, 0.0}, {-1.0, 1.0}, @@ -6265,7 +6265,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->pntsu = 4; nu->pntsv = 1; nu->orderu = 4; - nu->bp = callocstructN(BPoint, 4, "addNurbprim3"); + nu->bp = CALLOC_STRUCT_N(BPoint, 4, "addNurbprim3"); bp = nu->bp; for (a = 0; a < 4; a++, bp++) { @@ -6301,7 +6301,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->orderu = 5; nu->flagu = CU_NURB_ENDPOINT; /* endpoint */ nu->resolu = cu->resolu; - nu->bp = callocstructN(BPoint, 5, "addNurbprim3"); + nu->bp = CALLOC_STRUCT_N(BPoint, 5, "addNurbprim3"); bp = nu->bp; for (a = 0; a < 5; a++, bp++) { @@ -6334,7 +6334,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) if (cutype == CU_BEZIER) { if (!force_3d) nu->flag |= CU_2D; nu->pntsu = 4; - nu->bezt = callocstructN(BezTriple, 4, "addNurbprim1"); + nu->bezt = CALLOC_STRUCT_N(BezTriple, 4, "addNurbprim1"); nu->flagu = CU_NURB_CYCLIC; bezt = nu->bezt; @@ -6371,7 +6371,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->pntsu = 8; nu->pntsv = 1; nu->orderu = 4; - nu->bp = callocstructN(BPoint, 8, "addNurbprim6"); + nu->bp = CALLOC_STRUCT_N(BPoint, 8, "addNurbprim6"); nu->flagu = CU_NURB_CYCLIC; bp = nu->bp; @@ -6404,7 +6404,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->orderu = 4; nu->orderv = 4; nu->flag = CU_SMOOTH; - nu->bp = callocstructN(BPoint, 4 * 4, "addNurbprim6"); + nu->bp = CALLOC_STRUCT_N(BPoint, 4 * 4, "addNurbprim6"); nu->flagu = 0; nu->flagv = 0; bp = nu->bp; @@ -6471,7 +6471,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) nu->resolu = cu->resolu; nu->resolv = cu->resolv; nu->flag = CU_SMOOTH; - nu->bp = callocstructN(BPoint, 5, "addNurbprim6"); + nu->bp = CALLOC_STRUCT_N(BPoint, 5, "addNurbprim6"); nu->flagu = 0; bp = nu->bp; diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 7906d632f86..5a94d54f329 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -177,8 +177,8 @@ static void gp_draw_stroke_point(bGPDspoint *points, short thickness, short dfla /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok * - also mandatory in if Image Editor 'image-based' dot */ - if ( (thickness < GP_DRAWTHICKNESS_SPECIAL) || - ((dflag & GP_DRAWDATA_IEDITHACK) && (sflag & GP_STROKE_2DSPACE)) ) + if ((thickness < GP_DRAWTHICKNESS_SPECIAL) || + ((dflag & GP_DRAWDATA_IEDITHACK) && (sflag & GP_STROKE_2DSPACE))) { glBegin(GL_POINTS); glVertex2fv(co); @@ -253,8 +253,8 @@ static void gp_draw_stroke(bGPDspoint *points, int totpoints, short thickness_s, /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, 'smooth' opengl lines look better * - 'smooth' opengl lines are also required if Image Editor 'image-based' stroke */ - if ( (thickness < GP_DRAWTHICKNESS_SPECIAL) || - ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) ) + if ((thickness < GP_DRAWTHICKNESS_SPECIAL) || + ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D))) { bGPDspoint *pt; int i; diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index e4bfbea75b0..4e281b96fc3 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -27,7 +27,6 @@ * \ingroup edgpencil */ - #include <stdio.h> #include <stddef.h> #include <stdlib.h> @@ -778,7 +777,8 @@ static short gp_stroke_eraser_splitdel(bGPDframe *gpf, bGPDstroke *gps, int i) } /* eraser tool - check if part of stroke occurs within last segment drawn by eraser */ -static short gp_stroke_eraser_strokeinside(int mval[], int UNUSED(mvalo[]), short rad, short x0, short y0, short x1, short y1) +static short gp_stroke_eraser_strokeinside(const int mval[], const int UNUSED(mvalo[]), + int rad, int x0, int y0, int x1, int y1) { /* simple within-radius check for now */ if (edge_inside_circle(mval[0], mval[1], rad, x0, y0, x1, y1)) @@ -790,7 +790,9 @@ static short gp_stroke_eraser_strokeinside(int mval[], int UNUSED(mvalo[]), shor /* eraser tool - evaluation per stroke */ // TODO: this could really do with some optimization (KD-Tree/BVH?) -static void gp_stroke_eraser_dostroke(tGPsdata *p, int mval[], int mvalo[], short rad, rcti *rect, bGPDframe *gpf, bGPDstroke *gps) +static void gp_stroke_eraser_dostroke(tGPsdata *p, + const int mval[], const int mvalo[], + short rad, const rcti *rect, bGPDframe *gpf, bGPDstroke *gps) { bGPDspoint *pt1, *pt2; int x0 = 0, y0 = 0, x1 = 0, y1 = 0; @@ -827,7 +829,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, int mval[], int mvalo[], shor /* do boundbox check first */ if (BLI_rcti_isect_pt(rect, x0, y0)) { /* only check if point is inside */ - if ( ((x0 - mval[0]) * (x0 - mval[0]) + (y0 - mval[1]) * (y0 - mval[1])) <= rad * rad) { + if (((x0 - mval[0]) * (x0 - mval[0]) + (y0 - mval[1]) * (y0 - mval[1])) <= rad * rad) { /* free stroke */ MEM_freeN(gps->points); BLI_freelinkN(&gpf->strokes, gps); diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c index 61f7e1bb86f..fa9f5196866 100644 --- a/source/blender/editors/gpencil/gpencil_undo.c +++ b/source/blender/editors/gpencil/gpencil_undo.c @@ -25,6 +25,10 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/editors/gpencil/gpencil_undo.c + * \ingroup edgpencil + */ + #include <stdlib.h> #include <string.h> @@ -34,6 +38,7 @@ #include "DNA_listBase.h" #include "DNA_windowmanager_types.h" +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_gpencil.h" @@ -46,12 +51,10 @@ #include "gpencil_intern.h" -#define MAXUNDONAME 64 - typedef struct bGPundonode { struct bGPundonode *next, *prev; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; struct bGPdata *gpd; } bGPundonode; diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index 6f41bef81f4..87f12b8ac9c 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -60,9 +60,7 @@ void ED_space_image_get_uv_aspect(struct SpaceImage *sima, float *aspx, float *a void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings); void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings); -void ED_image_get_size(struct Image *ima, int *width, int *height); -void ED_image_get_aspect(struct Image *ima, float *aspx, float *aspy); -void ED_image_get_uv_aspect(struct Image *ima, float *aspx, float *aspy); +void ED_image_get_uv_aspect(struct Image *ima, struct ImageUser *iuser, float *aspx, float *aspy); void ED_image_mouse_pos(struct SpaceImage *sima, struct ARegion *ar, const int mval[2], float co[2]); void ED_image_point_pos(struct SpaceImage *sima, struct ARegion *ar, float x, float y, float *xr, float *yr); void ED_image_point_pos__reverse(struct SpaceImage *sima, struct ARegion *ar, const float co[2], float r_co[2]); diff --git a/source/blender/editors/include/ED_mask.h b/source/blender/editors/include/ED_mask.h index 88667729eee..8ebf932fd96 100644 --- a/source/blender/editors/include/ED_mask.h +++ b/source/blender/editors/include/ED_mask.h @@ -56,7 +56,8 @@ void ED_operatormacros_mask(void); void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type); void ED_mask_draw_region(struct Mask *mask, struct ARegion *ar, const char draw_flag, const char draw_type, - int width, int height, + const int width_i, const int height_i, + const float aspx, const float aspy, const short do_scale_applied, const short do_post_draw, float stabmat[4][4], const bContext *C); diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 35284b26d29..1d4fbe81e02 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -71,14 +71,8 @@ struct Material; struct Object; struct rcti; -intptr_t mesh_octree_table(struct Object *ob, struct BMEditMesh *em, const float co[3], char mode); -int mesh_mirrtopo_table(struct Object *ob, char mode); /* editmesh_utils.c */ - -/* retrieves mirrored cache vert, or NULL if there isn't one. - * note: calling this without ensuring the mirror cache state - * is bad.*/ void EDBM_verts_mirror_cache_begin(struct BMEditMesh *em, const short use_select); /* note, replaces EM_cache_x_mirror_vert in trunk */ void EDBM_verts_mirror_apply(struct BMEditMesh *em, const int sel_from, const int sel_to); struct BMVert *EDBM_verts_mirror_get(struct BMEditMesh *em, struct BMVert *v); @@ -86,7 +80,9 @@ void EDBM_verts_mirror_cache_clear(struct BMEditMesh *em, struct BMVer void EDBM_verts_mirror_cache_end(struct BMEditMesh *em); void EDBM_mesh_normals_update(struct BMEditMesh *em); +void EDBM_mesh_clear(struct BMEditMesh *em); +void EDBM_selectmode_to_scene(struct bContext *C); void EDBM_mesh_make(struct ToolSettings *ts, struct Scene *scene, struct Object *ob); void EDBM_mesh_free(struct BMEditMesh *tm); void EDBM_mesh_load(struct Object *ob); @@ -110,94 +106,105 @@ void EDBM_selectmode_flush(struct BMEditMesh *em); void EDBM_deselect_flush(struct BMEditMesh *em); void EDBM_select_flush(struct BMEditMesh *em); -void EDBM_selectmode_set(struct BMEditMesh *em); -void EDBM_selectmode_convert(struct BMEditMesh *em, short oldmode, const short selectmode); void undo_push_mesh(struct bContext *C, const char *name); int EDBM_vert_color_check(struct BMEditMesh *em); - void EDBM_mesh_hide(struct BMEditMesh *em, int swap); void EDBM_mesh_reveal(struct BMEditMesh *em); void EDBM_update_generic(struct bContext *C, struct BMEditMesh *em, const short do_tessface); -int EDBM_backbuf_check(unsigned int index); -int EDBM_backbuf_border_mask_init(struct ViewContext *vc, int mcords[][2], short tot, - short xmin, short ymin, short xmax, short ymax); -void EDBM_backbuf_free(void); -int EDBM_backbuf_border_init(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax); -int EDBM_backbuf_circle_init(struct ViewContext *vc, short xs, short ys, short rads); - -void EDBM_deselect_by_material(struct BMEditMesh *em, const short index, const short select); - struct UvElementMap *EDBM_uv_element_map_create(struct BMEditMesh *em, int selected, int doIslands); void EDBM_uv_element_map_free(struct UvElementMap *vmap); int EDBM_mtexpoly_check(struct BMEditMesh *em); -struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy); +struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy, int selected); void EDBM_uv_vert_map_free(struct UvVertMap *vmap); struct UvMapVert *EDBM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v); struct UvVertMap *EDBM_uv_vert_map_create(struct BMEditMesh *em, int selected, int do_face_idx_array, const float limit[2]); -void EDBM_data_layer_add(struct BMEditMesh *em, struct CustomData *data, int type, const char *name); -void EDBM_data_layer_free(struct BMEditMesh *em, struct CustomData *data, int type); - -void EDBM_select_toggle_all(struct BMEditMesh *em); -void EDBM_select_swap(struct BMEditMesh *em); /* exported for UV */ -int EDBM_select_interior_faces(struct BMEditMesh *em); - void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag); void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag); + + +/* editmesh_select.c */ void EDBM_select_mirrored(struct Object *obedit, struct BMEditMesh *em, int extend); void EDBM_automerge(struct Scene *scene, struct Object *ob, int update); -/* editmesh_mods.c */ -extern unsigned int bm_vertoffs, bm_solidoffs, bm_wireoffs; +int EDBM_backbuf_border_init(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax); +int EDBM_backbuf_check(unsigned int index); +void EDBM_backbuf_free(void); -int mouse_mesh(struct bContext *C, const int mval[2], short extend, short deselect, short toggle); +int EDBM_backbuf_border_mask_init(struct ViewContext *vc, int mcords[][2], short tot, + short xmin, short ymin, short xmax, short ymax); +int EDBM_backbuf_circle_init(struct ViewContext *vc, short xs, short ys, short rads); -struct BMVert *editbmesh_get_x_mirror_vert(struct Object *ob, struct BMEditMesh *em, struct BMVert *eve, const float co[3], int index); -int mesh_get_x_mirror_vert(struct Object *ob, int index); -int *mesh_get_x_mirror_faces(struct Object *ob, struct BMEditMesh *em); +struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, int *dist, short sel, short strict); +struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, int *dist); +struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, int *dist); + +int EDBM_select_pick(struct bContext *C, const int mval[2], short extend, short deselect, short toggle); + +void EDBM_selectmode_set(struct BMEditMesh *em); +void EDBM_selectmode_convert(struct BMEditMesh *em, short oldmode, const short selectmode); + +void EDBM_deselect_by_material(struct BMEditMesh *em, const short index, const short select); + +void EDBM_select_toggle_all(struct BMEditMesh *em); + +void EDBM_select_swap(struct BMEditMesh *em); /* exported for UV */ +int EDBM_select_interior_faces(struct BMEditMesh *em); +void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc); /* rename? */ + +extern unsigned int bm_vertoffs, bm_solidoffs, bm_wireoffs; -int join_mesh_exec(struct bContext *C, struct wmOperator *op); -int join_mesh_shapes_exec(struct bContext *C, struct wmOperator *op); /* mesh_ops.c */ void ED_operatortypes_mesh(void); void ED_operatormacros_mesh(void); void ED_keymap_mesh(struct wmKeyConfig *keyconf); +void ED_keymap_mesh(struct wmKeyConfig *keyconf); -/* editmesh.c */ - +/* spacetypes.c */ void ED_spacetypes_init(void); -void ED_keymap_mesh(struct wmKeyConfig *keyconf); -/* bmesh_mods.c */ -extern unsigned int bm_vertoffs, bm_solidoffs, bm_wireoffs; -/* bmesh_tools.c (could be moved) */ +/* editmesh_tools.c (could be moved) */ void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct Object *obedit, struct BMEditMesh *em); + /* editface.c */ void paintface_flush_flags(struct Object *ob); -int paintface_mouse_select(struct bContext *C, struct Object *ob, const int mval[2], int extend, int deselect, int toggle); -int do_paintface_box_select(struct ViewContext *vc, struct rcti *rect, int select, int extend); +int paintface_mouse_select(struct bContext *C, struct Object *ob, const int mval[2], int extend, int deselect, int toggle); +int do_paintface_box_select(struct ViewContext *vc, struct rcti *rect, int select, int extend); void paintface_deselect_all_visible(struct Object *ob, int action, short flush_flags); void paintface_select_linked(struct bContext *C, struct Object *ob, int mval[2], int mode); -int paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]); +int paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]); void paintface_hide(struct Object *ob, const int unselected); void paintface_reveal(struct Object *ob); void paintvert_deselect_all_visible(struct Object *ob, int action, short flush_flags); -void paintvert_flush_flags(struct Object *ob); +void paintvert_flush_flags(struct Object *ob); + +/* mirrtopo */ +typedef struct MirrTopoStore_t { + intptr_t *index_lookup; + int prev_vert_tot; + int prev_edge_tot; + int prev_ob_mode; +} MirrTopoStore_t; + +int ED_mesh_mirrtopo_recalc_check(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); +void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store, + const short skip_em_vert_array_init); +void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store); -/* object_vgroup.c */ +/* object_vgroup.c */ #define WEIGHT_REPLACE 1 #define WEIGHT_ADD 2 #define WEIGHT_SUBTRACT 3 @@ -218,9 +225,6 @@ void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup * void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum); float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum); -struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, int *dist, short sel, short strict); -struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, int *dist); -struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, int *dist); /* mesh_data.c */ // void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces); @@ -248,25 +252,6 @@ int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me); int ED_mesh_color_remove_named(struct bContext *C, struct Object *ob, struct Mesh *me, const char *name); -void EDBM_selectmode_to_scene(struct bContext *C); -void EDBM_mesh_clear(struct BMEditMesh *em); - -#include "../mesh/editmesh_bvh.h" - - -/* mirrtopo */ -typedef struct MirrTopoStore_t { - intptr_t *index_lookup; - int prev_vert_tot; - int prev_edge_tot; - int prev_ob_mode; -} MirrTopoStore_t; - -int ED_mesh_mirrtopo_recalc_check(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); -void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store, - const short skip_em_vert_array_init); -void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store); - /* mesh backup */ typedef struct BMBackup { struct BMesh *bmcopy; @@ -279,6 +264,30 @@ void EDBM_redo_state_restore(struct BMBackup, struct BMEditMesh *em, int recalct /* delete the backup, optionally flushing it to an editmesh */ void EDBM_redo_state_free(struct BMBackup *, struct BMEditMesh *em, int recalctess); + +/* meshtools.c */ +int join_mesh_exec(struct bContext *C, struct wmOperator *op); +int join_mesh_shapes_exec(struct bContext *C, struct wmOperator *op); + +intptr_t mesh_octree_table(struct Object *ob, struct BMEditMesh *em, const float co[3], char mode); +int mesh_mirrtopo_table(struct Object *ob, char mode); + +/* retrieves mirrored cache vert, or NULL if there isn't one. + * note: calling this without ensuring the mirror cache state + * is bad.*/ +int mesh_get_x_mirror_vert(struct Object *ob, int index); +struct BMVert *editbmesh_get_x_mirror_vert(struct Object *ob, struct BMEditMesh *em, struct BMVert *eve, const float co[3], int index); +int *mesh_get_x_mirror_faces(struct Object *ob, struct BMEditMesh *em); + +int ED_mesh_pick_vert(struct bContext *C, struct Mesh *me, const int mval[2], unsigned int *index, int size); +int ED_mesh_pick_face(struct bContext *C, struct Mesh *me, const int mval[2], unsigned int *index, int size); +int ED_mesh_pick_face_vert(struct bContext *C, struct Mesh *me, struct Object *ob, const int mval[2], unsigned int *index, int size); + +#define ED_MESH_PICK_DEFAULT_VERT_SIZE 50 +#define ED_MESH_PICK_DEFAULT_FACE_SIZE 3 + +#include "../mesh/editmesh_bvh.h" + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/include/ED_render.h b/source/blender/editors/include/ED_render.h index 7891315be9f..39e2c28a61a 100644 --- a/source/blender/editors/include/ED_render.h +++ b/source/blender/editors/include/ED_render.h @@ -56,18 +56,12 @@ void ED_render_scene_update(struct Main *bmain, struct Scene *scene, int updated typedef struct RenderInfo { int pr_rectx; int pr_recty; - short curtile, tottile, status; + short curtile, tottile; rcti disprect; /* storage for view3d preview rect */ unsigned int *rect; struct Render *re; /* persistent render */ } RenderInfo; -/* ri->status */ -#define PR_DBASE 1 -#define PR_DISPRECT 2 -#define PR_PROJECTED 4 -#define PR_ROTATED 8 - /* Render the preview * * pr_method: diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 4faf82eec36..fc20bdfb9c5 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -169,6 +169,7 @@ int ED_operator_editlattice(struct bContext *C); int ED_operator_editmball(struct bContext *C); int ED_operator_uvedit(struct bContext *C); int ED_operator_uvmap(struct bContext *C); +int ED_operator_posemode_exclusive(struct bContext *C); int ED_operator_posemode(struct bContext *C); int ED_operator_mask(struct bContext *C); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f055c89235d..c6f58fdd70b 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -187,70 +187,73 @@ typedef struct uiLayout uiLayout; * - bit 8: for 'bit' * - bit 9-15: button type (now 6 bits, 64 types) * */ - -#define CHA 32 -#define SHO 64 -#define INT 96 -#define FLO 128 -/*#define FUN 192*/ /*UNUSED*/ -#define BIT 256 - -/* button reqyires a pointer */ -#define BUTPOIN (FLO | SHO | CHA) +typedef enum { + UI_BUT_POIN_CHAR = 32, + UI_BUT_POIN_SHORT = 64, + UI_BUT_POIN_INT = 96, + UI_BUT_POIN_FLOAT = 128, +/* UI_BUT_POIN_FUNCTION = 192, */ /*UNUSED*/ + UI_BUT_POIN_BIT = 256 /* OR'd with a bit index*/ +} eButPointerType; + +/* requires (but->poin != NULL) */ +#define UI_BUT_POIN_TYPES (UI_BUT_POIN_FLOAT | UI_BUT_POIN_SHORT | UI_BUT_POIN_CHAR) /* assigned to but->type, OR'd with the flags above when passing args */ -#define BUT (1 << 9) -#define ROW (2 << 9) -#define TOG (3 << 9) -#define SLI (4 << 9) -#define NUM (5 << 9) -#define TEX (6 << 9) -#define TOG3 (7 << 9) -#define TOGR (8 << 9) -#define TOGN (9 << 9) -#define LABEL (10 << 9) -#define MENU (11 << 9) -#define ICONROW (12 << 9) -#define ICONTOG (13 << 9) -#define NUMSLI (14 << 9) -#define COL (15 << 9) -#define IDPOIN (16 << 9) -#define HSVSLI (17 << 9) -#define SCROLL (18 << 9) -#define BLOCK (19 << 9) -#define BUTM (20 << 9) -#define SEPR (21 << 9) -#define LINK (22 << 9) -#define INLINK (23 << 9) -#define KEYEVT (24 << 9) -#define ICONTEXTROW (25 << 9) -#define HSVCUBE (26 << 9) -#define PULLDOWN (27 << 9) -#define ROUNDBOX (28 << 9) -#define CHARTAB (29 << 9) -#define BUT_COLORBAND (30 << 9) -#define BUT_NORMAL (31 << 9) -#define BUT_CURVE (32 << 9) -#define BUT_TOGDUAL (33 << 9) -#define ICONTOGN (34 << 9) -#define FTPREVIEW (35 << 9) -#define NUMABS (36 << 9) -#define TOGBUT (37 << 9) -#define OPTION (38 << 9) -#define OPTIONN (39 << 9) -#define TRACKPREVIEW (40 << 9) -/* buttons with value >= SEARCH_MENU don't get undo pushes */ -#define SEARCH_MENU (41 << 9) -#define BUT_EXTRA (42 << 9) -#define HSVCIRCLE (43 << 9) -#define LISTBOX (44 << 9) -#define LISTROW (45 << 9) -#define HOTKEYEVT (46 << 9) -#define BUT_IMAGE (47 << 9) -#define HISTOGRAM (48 << 9) -#define WAVEFORM (49 << 9) -#define VECTORSCOPE (50 << 9) -#define PROGRESSBAR (51 << 9) +typedef enum { + BUT = (1 << 9), + ROW = (2 << 9), + TOG = (3 << 9), + SLI = (4 << 9), + NUM = (5 << 9), + TEX = (6 << 9), + TOG3 = (7 << 9), + TOGR = (8 << 9), + TOGN = (9 << 9), + LABEL = (10 << 9), + MENU = (11 << 9), + ICONROW = (12 << 9), + ICONTOG = (13 << 9), + NUMSLI = (14 << 9), + COLOR = (15 << 9), + IDPOIN = (16 << 9), + HSVSLI = (17 << 9), + SCROLL = (18 << 9), + BLOCK = (19 << 9), + BUTM = (20 << 9), + SEPR = (21 << 9), + LINK = (22 << 9), + INLINK = (23 << 9), + KEYEVT = (24 << 9), + ICONTEXTROW = (25 << 9), + HSVCUBE = (26 << 9), + PULLDOWN = (27 << 9), + ROUNDBOX = (28 << 9), + CHARTAB = (29 << 9), + BUT_COLORBAND = (30 << 9), + BUT_NORMAL = (31 << 9), + BUT_CURVE = (32 << 9), + BUT_TOGDUAL = (33 << 9), + ICONTOGN = (34 << 9), + /* FTPREVIEW = (35 << 9), */ /* UNUSED */ + NUMABS = (36 << 9), + TOGBUT = (37 << 9), + OPTION = (38 << 9), + OPTIONN = (39 << 9), + TRACKPREVIEW = (40 << 9), + /* buttons with value >= SEARCH_MENU don't get undo pushes */ + SEARCH_MENU = (41 << 9), + BUT_EXTRA = (42 << 9), + HSVCIRCLE = (43 << 9), + LISTBOX = (44 << 9), + LISTROW = (45 << 9), + HOTKEYEVT = (46 << 9), + BUT_IMAGE = (47 << 9), + HISTOGRAM = (48 << 9), + WAVEFORM = (49 << 9), + VECTORSCOPE = (50 << 9), + PROGRESSBAR = (51 << 9) +} eButType; #define BUTTYPE (63 << 9) @@ -395,7 +398,8 @@ void uiBlockBeginAlign(uiBlock *block); void uiBlockEndAlign(uiBlock *block); /* block bounds/position calculation */ -enum { +typedef enum { + UI_BLOCK_BOUNDS_NONE = 0, UI_BLOCK_BOUNDS = 1, UI_BLOCK_BOUNDS_TEXT, UI_BLOCK_BOUNDS_POPUP_MOUSE, @@ -527,7 +531,7 @@ enum { BUT_GET_TIP, BUT_GET_RNA_TIP, BUT_GET_RNAENUM_TIP, - BUT_GET_OP_KEYMAP, + BUT_GET_OP_KEYMAP }; typedef struct uiStringInfo { @@ -538,7 +542,7 @@ typedef struct uiStringInfo { /* Note: Expects pointers to uiStringInfo structs as parameters. * Will fill them with translated strings, when possible. * Strings in uiStringInfo must be MEM_freeN'ed by caller. */ -void uiButGetStrInfo(struct bContext *C, uiBut *but, const int nbr, ...); +void uiButGetStrInfo(struct bContext *C, uiBut *but, int nbr, ...); /* Edit i18n stuff. */ /* Name of the main py op from i18n addon. */ @@ -573,7 +577,7 @@ typedef void (*uiIDPoinFuncFP)(struct bContext *C, const char *str, struct ID ** typedef void (*uiIDPoinFunc)(struct bContext *C, struct ID *id, int event); uiBut *uiDefIDPoinBut(uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, const char *str, - int x, int y, short width, short height, void *idpp, const char *tip); + int x, int y, short width, short height, void *idpp, const char *tip); int uiIconFromID(struct ID *id); @@ -624,7 +628,9 @@ void uiButSetNFunc(uiBut *but, uiButHandleNFunc func, void *argN, void void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg); -void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), void *arg1, void *arg2); +void uiBlockSetDrawExtraFunc(uiBlock *block, + void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), + void *arg1, void *arg2); void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but); @@ -743,7 +749,9 @@ void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv); void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr); void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context); const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing -void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, struct wmOperator *op, int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align, const short flag); +void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, struct wmOperator *op, + int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), + const char label_align, const short flag); struct MenuType *uiButGetMenuType(uiBut *but); void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext); diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 3a8f05a76f0..792c96fe7c8 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -203,7 +203,7 @@ void UI_view2d_operatortypes(void); void UI_view2d_keymap(struct wmKeyConfig *keyconf); void UI_view2d_smooth_view(struct bContext *C, struct ARegion *ar, - const struct rctf *cur); + const struct rctf *cur); #endif /* __UI_VIEW2D_H__ */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index afbabaaa8d7..823f8d7be39 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -33,7 +33,8 @@ #include <math.h> #include <string.h> #include <ctype.h> - +#include <stddef.h> /* offsetof() */ + #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" @@ -41,7 +42,12 @@ #include "DNA_userdef_types.h" #include "BLI_math.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_string_utf8.h" +#include "BLI_path_util.h" +#include "BLI_rect.h" + #include "BLI_dynstr.h" #include "BLI_utildefines.h" @@ -50,7 +56,6 @@ #include "BKE_unit.h" #include "BKE_screen.h" #include "BKE_idprop.h" -#include "BKE_utildefines.h" /* FILE_MAX */ #include "BIF_gl.h" @@ -129,7 +134,7 @@ void ui_block_to_window(const ARegion *ar, uiBlock *block, int *x, int *y) *y = (int)(fy + 0.5f); } -void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, rctf *graph, rcti *winr) +void ui_block_to_window_rct(const ARegion *ar, uiBlock *block, const rctf *graph, rcti *winr) { rctf tmpr; @@ -312,7 +317,7 @@ static void ui_centered_bounds_block(const bContext *C, uiBlock *block) ui_bounds_block(block); } -static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_calc) +static void ui_popup_bounds_block(const bContext *C, uiBlock *block, eBlockBoundsCalc bounds_calc) { wmWindow *window = CTX_wm_window(C); int startx, starty, endx, endy, width, height, oldwidth, oldheight; @@ -383,21 +388,21 @@ void uiBoundsBlock(uiBlock *block, int addval) return; block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS; + block->bounds_type = UI_BLOCK_BOUNDS; } /* used for pulldowns */ void uiTextBoundsBlock(uiBlock *block, int addval) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_TEXT; + block->bounds_type = UI_BLOCK_BOUNDS_TEXT; } /* used for block popups */ void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_POPUP_MOUSE; + block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MOUSE; block->mx = mx; block->my = my; } @@ -406,7 +411,7 @@ void uiPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_POPUP_MENU; + block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MENU; block->mx = mx; block->my = my; } @@ -415,7 +420,7 @@ void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my) void uiCenteredBoundsBlock(uiBlock *block, int addval) { block->bounds = addval; - block->dobounds = UI_BLOCK_BOUNDS_POPUP_CENTER; + block->bounds_type = UI_BLOCK_BOUNDS_POPUP_CENTER; } void uiExplicitBoundsBlock(uiBlock *block, int minx, int miny, int maxx, int maxy) @@ -424,7 +429,7 @@ void uiExplicitBoundsBlock(uiBlock *block, int minx, int miny, int maxx, int max block->rect.ymin = miny; block->rect.xmax = maxx; block->rect.ymax = maxy; - block->dobounds = 0; + block->bounds_type = UI_BLOCK_BOUNDS_NONE; } /* ************** LINK LINE DRAWING ************* */ @@ -754,7 +759,7 @@ static void ui_menu_block_set_keyaccels(uiBlock *block) * fun first pass on all buttons so first word chars always get first priority */ for (but = block->buttons.first; but; but = but->next) { - if (!ELEM4(but->type, BUT, MENU, BLOCK, PULLDOWN) || (but->flag & UI_HIDDEN)) { + if (!ELEM5(but->type, BUT, BUTM, MENU, BLOCK, PULLDOWN) || (but->flag & UI_HIDDEN)) { /* pass */ } else if (but->menu_key == '\0') { @@ -929,21 +934,45 @@ void uiEndBlock(const bContext *C, uiBlock *block) } /* handle pending stuff */ - if (block->layouts.first) uiBlockLayoutResolve(block, NULL, NULL); + if (block->layouts.first) { + uiBlockLayoutResolve(block, NULL, NULL); + } ui_block_do_align(block); if ((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) { ui_menu_block_set_keyaccels(block); /* could use a different flag to check */ } - if (block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block); + + if (block->flag & UI_BLOCK_LOOP) { + ui_menu_block_set_keymaps(C, block); + } /* after keymaps! */ - if (block->dobounds == UI_BLOCK_BOUNDS) ui_bounds_block(block); - else if (block->dobounds == UI_BLOCK_BOUNDS_TEXT) ui_text_bounds_block(block, 0.0f); - else if (block->dobounds == UI_BLOCK_BOUNDS_POPUP_CENTER) ui_centered_bounds_block(C, block); - else if (block->dobounds) ui_popup_bounds_block(C, block, block->dobounds); + switch (block->bounds_type) { + case UI_BLOCK_BOUNDS_NONE: + break; + case UI_BLOCK_BOUNDS: + ui_bounds_block(block); + break; + case UI_BLOCK_BOUNDS_TEXT: + ui_text_bounds_block(block, 0.0f); + break; + case UI_BLOCK_BOUNDS_POPUP_CENTER: + ui_centered_bounds_block(C, block); + break; - if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) uiBoundsBlock(block, 0); - if (block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block); + /* fallback */ + case UI_BLOCK_BOUNDS_POPUP_MOUSE: + case UI_BLOCK_BOUNDS_POPUP_MENU: + ui_popup_bounds_block(C, block, block->bounds_type); + break; + } + + if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) { + uiBoundsBlock(block, 0); + } + if (block->flag & UI_BUT_ALIGN) { + uiBlockEndAlign(block); + } block->endblock = 1; } @@ -1077,8 +1106,12 @@ static void ui_is_but_sel(uiBut *but, double *value) int lvalue; UI_GET_BUT_VALUE_INIT(but, *value); lvalue = (int)*value; - if (BTST(lvalue, (but->bitnr)) ) is_push = is_true; - else is_push = !is_true; + if (UI_BITBUT_TEST(lvalue, (but->bitnr))) { + is_push = is_true; + } + else { + is_push = !is_true; + } } else { switch (but->type) { @@ -1116,7 +1149,7 @@ static void ui_is_but_sel(uiBut *but, double *value) if (*value == (double)but->hardmax) is_push = 1; } break; - case COL: + case COLOR: is_push = 2; break; default: @@ -1233,8 +1266,7 @@ void ui_delete_linkline(uiLinkLine *line, uiBut *but) else { b = 0; for (a = 0; a < (*(link->totlink)); a++) { - - if ( (*(link->ppoin))[a] != line->to->poin) { + if ((*(link->ppoin))[a] != line->to->poin) { (*(link->ppoin))[b] = (*(link->ppoin))[a]; b++; } @@ -1277,13 +1309,13 @@ void ui_get_but_vectorf(uiBut *but, float vec[3]) vec[a] = RNA_property_float_get_index(&but->rnapoin, prop, a); } } - else if (but->pointype == CHA) { + else if (but->pointype == UI_BUT_POIN_CHAR) { char *cp = (char *)but->poin; vec[0] = ((float)cp[0]) / 255.0f; vec[1] = ((float)cp[1]) / 255.0f; vec[2] = ((float)cp[2]) / 255.0f; } - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { float *fp = (float *)but->poin; copy_v3_v3(vec, fp); } @@ -1323,13 +1355,13 @@ void ui_set_but_vectorf(uiBut *but, const float vec[3]) } } } - else if (but->pointype == CHA) { + else if (but->pointype == UI_BUT_POIN_CHAR) { char *cp = (char *)but->poin; cp[0] = (char)(0.5f + vec[0] * 255.0f); cp[1] = (char)(0.5f + vec[1] * 255.0f); cp[2] = (char)(0.5f + vec[2] * 255.0f); } - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { float *fp = (float *)but->poin; copy_v3_v3(fp, vec); } @@ -1337,7 +1369,7 @@ void ui_set_but_vectorf(uiBut *but, const float vec[3]) int ui_is_but_float(uiBut *but) { - if (but->pointype == FLO && but->poin) + if (but->pointype == UI_BUT_POIN_FLOAT && but->poin) return 1; if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT) @@ -1433,16 +1465,16 @@ double ui_get_but_val(uiBut *but) case 'V': value = hsv[2]; break; } } - else if (but->pointype == CHA) { + else if (but->pointype == UI_BUT_POIN_CHAR) { value = *(char *)but->poin; } - else if (but->pointype == SHO) { + else if (but->pointype == UI_BUT_POIN_SHORT) { value = *(short *)but->poin; } - else if (but->pointype == INT) { + else if (but->pointype == UI_BUT_POIN_INT) { value = *(int *)but->poin; } - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { value = *(float *)but->poin; } @@ -1514,9 +1546,10 @@ void ui_set_but_val(uiBut *but, double value) } else { /* first do rounding */ - if (but->pointype == CHA) + if (but->pointype == UI_BUT_POIN_CHAR) { value = (char)floor(value + 0.5); - else if (but->pointype == SHO) { + } + else if (but->pointype == UI_BUT_POIN_SHORT) { /* gcc 3.2.1 seems to have problems * casting a double like 32772.0 to * a short so we cast to an int, then @@ -1530,9 +1563,9 @@ void ui_set_but_val(uiBut *but, double value) gcckludge = (int) floor(value + 0.5); value = (short)gcckludge; } - else if (but->pointype == INT) + else if (but->pointype == UI_BUT_POIN_INT) value = (int)floor(value + 0.5); - else if (but->pointype == FLO) { + else if (but->pointype == UI_BUT_POIN_FLOAT) { float fval = (float)value; if (fval >= -0.00001f && fval <= 0.00001f) fval = 0.0f; /* prevent negative zero */ value = fval; @@ -1541,13 +1574,13 @@ void ui_set_but_val(uiBut *but, double value) /* then set value with possible edit override */ if (but->editval) value = *but->editval = value; - else if (but->pointype == CHA) + else if (but->pointype == UI_BUT_POIN_CHAR) value = *((char *)but->poin) = (char)value; - else if (but->pointype == SHO) + else if (but->pointype == UI_BUT_POIN_SHORT) value = *((short *)but->poin) = (short)value; - else if (but->pointype == INT) + else if (but->pointype == UI_BUT_POIN_INT) value = *((int *)but->poin) = (int)value; - else if (but->pointype == FLO) + else if (but->pointype == UI_BUT_POIN_FLOAT) value = *((float *)but->poin) = (float)value; } @@ -2207,6 +2240,10 @@ void ui_check_but(uiBut *but) but->iconadd = (int)value - (int)(but->hardmin); } break; + + /* quiet warnings for unhandled types */ + default: + break; } @@ -2459,7 +2496,7 @@ static void ui_block_do_align_but(uiBut *first, short nr) flag |= UI_BUT_ALIGN_TOP; } - if ( (flag & UI_BUT_ALIGN_TOP) == 0) { /* stil top row */ + if ((flag & UI_BUT_ALIGN_TOP) == 0) { /* stil top row */ if (prev) { if (next && buts_are_horiz(but, next)) flag = UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_LEFT | UI_BUT_ALIGN_RIGHT; @@ -2528,11 +2565,13 @@ void ui_block_do_align(uiBlock *block) /* skip with same number */ for (; but && but->alignnr == nr; but = but->next) ; - if (!but) + if (!but) { break; + } } - else + else { but = but->next; + } } } @@ -2548,22 +2587,29 @@ void ui_block_do_align(uiBlock *block) * 1,2,3, and a maximum of 4, all greater values will be clamped to 4. */ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, - int x, int y, short width, short height, + int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip) { uiBut *but; int slen; - - if (type & BUTPOIN) { /* a pointer is required */ - if (poin == NULL) + + /* we could do some more error checks here */ + if ((type & BUTTYPE) == LABEL) { + BLI_assert((poin != NULL || min != 0.0f || max != 0.0f || (a1 == 0.0f && a2 != 0.0f) || (a1 != 0.0f && a1 != 1.0f)) == FALSE); + } + + if (type & UI_BUT_POIN_TYPES) { /* a pointer is required */ + if (poin == NULL) { + BLI_assert(0); return NULL; + } } but = MEM_callocN(sizeof(uiBut), "uiBut"); but->type = type & BUTTYPE; - but->pointype = type & BUTPOIN; - but->bit = type & BIT; + but->pointype = type & UI_BUT_POIN_TYPES; + but->bit = type & UI_BUT_POIN_BIT; but->bitnr = type & 31; but->icon = ICON_NONE; but->iconadd = 0; @@ -2640,7 +2686,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, /* keep track of UI_interface.h */ if (ELEM7(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, BUTM)) ; - else if (ELEM3(but->type, SCROLL, SEPR, FTPREVIEW)) ; + else if (ELEM(but->type, SCROLL, SEPR /* , FTPREVIEW */ )) ; else if (but->type >= SEARCH_MENU) ; else but->flag |= UI_BUT_UNDO; @@ -3036,40 +3082,40 @@ static uiBut *uiDefButBit(uiBlock *block, int type, int bit, int retval, const c return NULL; } else { - return uiDefBut(block, type | BIT | bitIdx, retval, str, x, y, width, height, poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_BIT | bitIdx, retval, str, x, y, width, height, poin, min, max, a1, a2, tip); } } uiBut *uiDefButF(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | FLO, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_FLOAT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitF(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | FLO, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_FLOAT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButI(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | INT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_INT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitI(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | INT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_INT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButS(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | SHO, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_SHORT, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitS(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | SHO, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_SHORT, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButC(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefBut(block, type | CHA, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefBut(block, type | UI_BUT_POIN_CHAR, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefButBit(block, type | CHA, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefButBit(block, type | UI_BUT_POIN_CHAR, bit, retval, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { @@ -3121,41 +3167,41 @@ static uiBut *uiDefIconButBit(uiBlock *block, int type, int bit, int retval, int return NULL; } else { - return uiDefIconBut(block, type | BIT | bitIdx, retval, icon, x, y, width, height, poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_BIT | bitIdx, retval, icon, x, y, width, height, poin, min, max, a1, a2, tip); } } uiBut *uiDefIconButF(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | FLO, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_FLOAT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitF(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | FLO, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_FLOAT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButI(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | INT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_INT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitI(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | INT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_INT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButS(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | SHO, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_SHORT, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | SHO, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_SHORT, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButC(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconBut(block, type | CHA, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconBut(block, type | UI_BUT_POIN_CHAR, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconButBit(block, type | CHA, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconButBit(block, type | UI_BUT_POIN_CHAR, bit, retval, icon, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { @@ -3200,41 +3246,41 @@ static uiBut *uiDefIconTextButBit(uiBlock *block, int type, int bit, int retval, return NULL; } else { - return uiDefIconTextBut(block, type | BIT | bitIdx, retval, icon, str, x, y, width, height, poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_BIT | bitIdx, retval, icon, str, x, y, width, height, poin, min, max, a1, a2, tip); } } uiBut *uiDefIconTextButF(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | FLO, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_FLOAT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitF(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, float *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | FLO, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_FLOAT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButI(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | INT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_INT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitI(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, int *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | INT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_INT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButS(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | SHO, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_SHORT, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitS(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | SHO, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_SHORT, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButC(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextBut(block, type | CHA, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextBut(block, type | UI_BUT_POIN_CHAR, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x, int y, short width, short height, char *poin, float min, float max, float a1, float a2, const char *tip) { - return uiDefIconTextButBit(block, type | CHA, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); + return uiDefIconTextButBit(block, type | UI_BUT_POIN_CHAR, bit, retval, icon, str, x, y, width, height, (void *) poin, min, max, a1, a2, tip); } uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const char *str, int x, int y, short width, short height, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { @@ -3632,7 +3678,7 @@ uiBut *uiDefIconBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, int uiBut *uiDefKeyevtButS(uiBlock *block, int retval, const char *str, int x, int y, short width, short height, short *spoin, const char *tip) { - uiBut *but = ui_def_but(block, KEYEVT | SHO, retval, str, x, y, width, height, spoin, 0.0, 0.0, 0.0, 0.0, tip); + uiBut *but = ui_def_but(block, KEYEVT | UI_BUT_POIN_SHORT, retval, str, x, y, width, height, spoin, 0.0, 0.0, 0.0, 0.0, tip); ui_check_but(but); return but; } @@ -3641,7 +3687,7 @@ uiBut *uiDefKeyevtButS(uiBlock *block, int retval, const char *str, int x, int y /* modkeypoin will be set to KM_SHIFT, KM_ALT, KM_CTRL, KM_OSKEY bits */ uiBut *uiDefHotKeyevtButS(uiBlock *block, int retval, const char *str, int x, int y, short width, short height, short *keypoin, short *modkeypoin, const char *tip) { - uiBut *but = ui_def_but(block, HOTKEYEVT | SHO, retval, str, x, y, width, height, keypoin, 0.0, 0.0, 0.0, 0.0, tip); + uiBut *but = ui_def_but(block, HOTKEYEVT | UI_BUT_POIN_SHORT, retval, str, x, y, width, height, keypoin, 0.0, 0.0, 0.0, 0.0, tip); but->modifier_key = *modkeypoin; ui_check_but(but); return but; @@ -3713,8 +3759,14 @@ void uiButGetStrInfo(bContext *C, uiBut *but, int nbr, ...) if (type == BUT_GET_LABEL) { if (but->str) { - /* Menu labels can have some complex formating stuff marked by pipes, we don't want those here! */ - char *tc = strchr(but->str, '|'); + /* Menu labels can have some complex formating stuff marked by pipes or %t, we don't want those here! */ + const char *tc; + + if (but->type == MENU) + tc = strstr(but->str, "%t"); + else + tc = strchr(but->str, '|'); + if (tc) tmp = BLI_strdupn(but->str, tc - but->str); else diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ca52daa8cd2..b8a84e1638a 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -54,6 +54,7 @@ #include "PIL_time.h" +#include "BKE_blender.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_idprop.h" @@ -120,8 +121,10 @@ typedef struct uiHandleButtonData { /* overall state */ uiHandleButtonState state; - int cancel, escapecancel, retval; - int applied, appliedinteractive; + int retval; + /* booleans (could be made into flags) */ + char cancel, escapecancel; + char applied, appliedinteractive; wmTimer *flashtimer; /* edited value */ @@ -193,7 +196,7 @@ typedef struct uiAfterFunc { bContextStore *context; - char undostr[512]; + char undostr[BKE_UNDO_STR_MAX]; int autokey; } uiAfterFunc; @@ -461,7 +464,7 @@ static void ui_apply_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -470,7 +473,7 @@ static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -481,7 +484,7 @@ static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data ui_check_but(but); ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -491,19 +494,21 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) /* local hack... */ if (but->type == BUT_TOGDUAL && data->togdual) { - if (but->pointype == SHO) + if (but->pointype == UI_BUT_POIN_SHORT) { but->poin += 2; - else if (but->pointype == INT) + } + else if (but->pointype == UI_BUT_POIN_INT) { but->poin += 4; + } } value = ui_get_but_val(but); lvalue = (int)value; if (but->bit) { - w = BTST(lvalue, but->bitnr); - if (w) lvalue = BCLR(lvalue, but->bitnr); - else lvalue = BSET(lvalue, but->bitnr); + w = UI_BITBUT_TEST(lvalue, but->bitnr); + if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr); + else lvalue = UI_BITBUT_SET(lvalue, but->bitnr); if (but->type == TOGR) { if (!data->togonly) { @@ -531,16 +536,18 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) /* end local hack... */ if (but->type == BUT_TOGDUAL && data->togdual) { - if (but->pointype == SHO) + if (but->pointype == UI_BUT_POIN_SHORT) { but->poin -= 2; - else if (but->pointype == INT) + } + else if (but->pointype == UI_BUT_POIN_INT) { but->poin -= 4; + } } ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data) @@ -557,7 +564,7 @@ static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleBu ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -576,7 +583,7 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -586,7 +593,7 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) data->value = ui_get_but_val(but); } else { - data->cancel = 1; + data->cancel = TRUE; return; } } @@ -597,42 +604,42 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TOG3(bContext *C, uiBut *but, uiHandleButtonData *data) { - if (but->pointype == SHO) { + if (but->pointype == UI_BUT_POIN_SHORT) { short *sp = (short *)but->poin; - if (BTST(sp[1], but->bitnr)) { - sp[1] = BCLR(sp[1], but->bitnr); - sp[0] = BCLR(sp[0], but->bitnr); + if (UI_BITBUT_TEST(sp[1], but->bitnr)) { + sp[1] = UI_BITBUT_CLR(sp[1], but->bitnr); + sp[0] = UI_BITBUT_CLR(sp[0], but->bitnr); } - else if (BTST(sp[0], but->bitnr)) { - sp[1] = BSET(sp[1], but->bitnr); + else if (UI_BITBUT_TEST(sp[0], but->bitnr)) { + sp[1] = UI_BITBUT_SET(sp[1], but->bitnr); } else { - sp[0] = BSET(sp[0], but->bitnr); + sp[0] = UI_BITBUT_SET(sp[0], but->bitnr); } } else { - if (BTST(*(but->poin + 2), but->bitnr)) { - *(but->poin + 2) = BCLR(*(but->poin + 2), but->bitnr); - *(but->poin) = BCLR(*(but->poin), but->bitnr); + if (UI_BITBUT_TEST(*(but->poin + 2), but->bitnr)) { + *(but->poin + 2) = UI_BITBUT_CLR(*(but->poin + 2), but->bitnr); + *(but->poin) = UI_BITBUT_CLR(*(but->poin), but->bitnr); } - else if (BTST(*(but->poin), but->bitnr)) { - *(but->poin + 2) = BSET(*(but->poin + 2), but->bitnr); + else if (UI_BITBUT_TEST(*(but->poin), but->bitnr)) { + *(but->poin + 2) = UI_BITBUT_SET(*(but->poin + 2), but->bitnr); } else { - *(but->poin) = BSET(*(but->poin), but->bitnr); + *(but->poin) = UI_BITBUT_SET(*(but->poin), but->bitnr); } } ui_check_but(but); ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -642,21 +649,21 @@ static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_COLORBAND(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_CURVE(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_IDPOIN(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -665,7 +672,7 @@ static void ui_apply_but_IDPOIN(bContext *C, uiBut *but, uiHandleButtonData *dat ui_check_but(but); ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } #ifdef WITH_INTERNATIONAL @@ -673,7 +680,7 @@ static void ui_apply_but_CHARTAB(bContext *C, uiBut *but, uiHandleButtonData *da { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } #endif @@ -710,7 +717,7 @@ static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data, wmDrag *drag; button_activate_state(C, but, BUTTON_STATE_EXIT); - data->cancel = 1; + data->cancel = TRUE; drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but)); if (but->imb) @@ -729,13 +736,10 @@ static void ui_delete_active_linkline(uiBlock *block) uiLink *link; uiLinkLine *line, *nline; int a, b; - - but = block->buttons.first; - while (but) { + + for (but = block->buttons.first; but; but = but->next) { if (but->type == LINK && but->link) { - line = but->link->lines.first; - while (line) { - + for (line = but->link->lines.first; line; line = nline) { nline = line->next; if (line->flag & UI_SELECT) { @@ -755,7 +759,7 @@ static void ui_delete_active_linkline(uiBlock *block) b = 0; for (a = 0; a < (*(link->totlink)); a++) { - if ( (*(link->ppoin))[a] != line->to->poin) { + if ((*(link->ppoin))[a] != line->to->poin) { (*(link->ppoin))[b] = (*(link->ppoin))[a]; b++; } @@ -769,10 +773,8 @@ static void ui_delete_active_linkline(uiBlock *block) MEM_freeN(line); } - line = nline; } } - but = but->next; } } @@ -784,10 +786,10 @@ static uiLinkLine *ui_is_a_link(uiBut *from, uiBut *to) link = from->link; if (link) { - line = link->lines.first; - while (line) { - if (line->from == from && line->to == to) return line; - line = line->next; + for (line = link->lines.first; line; line = line->next) { + if (line->from == from && line->to == to) { + return line; + } } } return NULL; @@ -866,7 +868,7 @@ static void ui_add_link(bContext *C, uiBut *from, uiBut *to) void **oldppoin; int a; - if ( (line = ui_is_a_link(from, to)) ) { + if ((line = ui_is_a_link(from, to))) { line->flag |= UI_SELECT; ui_delete_active_linkline(from->block); return; @@ -929,35 +931,35 @@ static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data) ui_apply_but_func(C, but); data->retval = but->retval; } - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_HISTOGRAM(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_WAVEFORM(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data) { ui_apply_but_func(C, but); data->retval = but->retval; - data->applied = 1; + data->applied = TRUE; } @@ -988,10 +990,12 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut else { /* we avoid applying interactive edits a second time * at the end with the appliedinteractive flag */ - if (interactive) - data->appliedinteractive = 1; - else if (data->appliedinteractive) + if (interactive) { + data->appliedinteractive = TRUE; + } + else if (data->appliedinteractive) { return; + } } /* ensures we are writing actual values */ @@ -1049,7 +1053,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut case PULLDOWN: ui_apply_but_BLOCK(C, but, data); break; - case COL: + case COLOR: if (data->cancel) ui_apply_but_VEC(C, but, data); else @@ -1180,19 +1184,27 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, } /* RGB triple */ - else if (but->type == COL) { + else if (but->type == COLOR) { float rgb[3]; if (but->poin == NULL && but->rnapoin.data == NULL) ; else if (mode == 'c') { ui_get_but_vectorf(but, rgb); + /* convert to linear color to do compatible copy between gamma and non-gamma */ + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) + srgb_to_linearrgb_v3_v3(rgb, rgb); + BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]); WM_clipboard_text_set(buf, 0); } else { if (sscanf(buf, "[%f, %f, %f]", &rgb[0], &rgb[1], &rgb[2]) == 3) { + /* assume linear colors in buffer */ + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) + linearrgb_to_srgb_v3_v3(rgb, rgb); + button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); ui_set_but_vectorf(but, rgb); button_activate_state(C, but, BUTTON_STATE_EXIT); @@ -1209,7 +1221,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); BLI_strncpy(buf, active_data->str, UI_MAX_DRAW_STR); WM_clipboard_text_set(active_data->str, 0); - active_data->cancel = 1; + active_data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else { @@ -1312,7 +1324,10 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho while (i > 0) { if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &i)) { - if (BLF_width(fstyle->uifont_id, origstr + i) > (startx - x) * 0.25f) break; // 0.25 == scale factor for less sensitivity + /* 0.25 == scale factor for less sensitivity */ + if (BLF_width(fstyle->uifont_id, origstr + i) > (startx - x) * 0.25f) { + break; + } } else { break; /* unlikely but possible */ @@ -1375,7 +1390,7 @@ static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, else if (x < data->selstartx) data->selextend = EXTEND_LEFT; ui_textedit_set_cursor_pos(but, data, x); - + if (data->selextend == EXTEND_RIGHT) but->selend = but->pos; if (data->selextend == EXTEND_LEFT) but->selsta = but->pos; @@ -1429,7 +1444,8 @@ static int ui_textedit_type_ascii(uiBut *but, uiHandleButtonData *data, char asc return ui_textedit_type_buf(but, data, buf, 1); } -static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJumpDirection direction, int select, strCursorJumpType jump) +static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJumpDirection direction, + int select, strCursorJumpType jump) { const char *str = data->str; const int len = strlen(str); @@ -1778,13 +1794,13 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle break; case RIGHTMOUSE: case ESCKEY: - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); retval = WM_UI_HANDLER_BREAK; break; - case LEFTMOUSE: { - + case LEFTMOUSE: + { /* exit on LMB only on RELEASE for searchbox, to mimic other popups, and allow multiple menu levels */ if (data->searchbox) inbox = ui_searchbox_inside(data->searchbox, event->x, event->y); @@ -1805,7 +1821,7 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle else if (inbox == 0) { /* if searchbox, click outside will cancel */ if (data->searchbox) - data->cancel = data->escapecancel = 1; + data->cancel = data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); retval = WM_UI_HANDLER_BREAK; } @@ -1835,11 +1851,13 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } break; case RIGHTARROWKEY: - ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + ui_textedit_move(but, data, STRCUR_DIR_NEXT, + event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case LEFTARROWKEY: - ui_textedit_move(but, data, STRCUR_DIR_PREV, event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + ui_textedit_move(but, data, STRCUR_DIR_PREV, + event->shift, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case DOWNARROWKEY: @@ -1849,7 +1867,8 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } /* pass on purposedly */ case ENDKEY: - ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->shift, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_NEXT, + event->shift, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case UPARROWKEY: @@ -1859,7 +1878,8 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } /* pass on purposedly */ case HOMEKEY: - ui_textedit_move(but, data, STRCUR_DIR_PREV, event->shift, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_PREV, + event->shift, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case PADENTER: @@ -1868,12 +1888,14 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle retval = WM_UI_HANDLER_BREAK; break; case DELKEY: - changed = ui_textedit_delete(but, data, 1, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + changed = ui_textedit_delete(but, data, 1, + event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case BACKSPACEKEY: - changed = ui_textedit_delete(but, data, 0, event->shift ? STRCUR_JUMP_ALL : (event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE)); + changed = ui_textedit_delete(but, data, 0, + event->shift ? STRCUR_JUMP_ALL : (event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE)); retval = WM_UI_HANDLER_BREAK; break; @@ -1950,7 +1972,8 @@ static void ui_do_but_textedit_select(bContext *C, uiBlock *block, uiBut *but, u int mx, my, retval = WM_UI_HANDLER_CONTINUE; switch (event->type) { - case MOUSEMOVE: { + case MOUSEMOVE: + { mx = event->x; my = event->y; ui_window_to_block(data->region, block, &mx, &my); @@ -2073,14 +2096,18 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data menufunc = ui_block_func_ICONTEXTROW; arg = but; break; - case COL: + case COLOR: ui_get_but_vectorf(but, data->origvec); copy_v3_v3(data->vec, data->origvec); but->editvec = data->vec; - handlefunc = ui_block_func_COL; + handlefunc = ui_block_func_COLOR; arg = but; break; + + /* quiet warnings for unhandled types */ + default: + break; } if (func || handlefunc) { @@ -2134,7 +2161,7 @@ static int ui_do_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data, wmEv else if (data->state == BUTTON_STATE_WAIT_RELEASE) { if (event->type == LEFTMOUSE && event->val != KM_PRESS) { if (!(but->flag & UI_SELECT)) - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } @@ -2165,7 +2192,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data if (but->flag & UI_BUT_IMMEDIATE) ui_set_but_val(but, 0); else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } @@ -2187,14 +2214,14 @@ static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data if (WM_key_event_string(event->type)[0]) ui_set_but_val(but, event->type); else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } else if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2220,7 +2247,7 @@ static int ui_do_but_KEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data, w if (WM_key_event_string(event->type)[0]) ui_set_but_val(but, event->type); else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2568,8 +2595,8 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { @@ -2619,7 +2646,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (temp >= softmin && temp <= softmax) data->value = (double)temp; else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2630,7 +2657,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (temp >= softmin && temp <= softmax) data->value = (double)temp; else - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -2790,8 +2817,8 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { @@ -2849,7 +2876,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (temp >= softmin && temp <= softmax) data->value = temp; else - data->cancel = 1; + data->cancel = TRUE; } else { if (f < tempf) tempf -= 0.01f; @@ -2858,7 +2885,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton if (tempf >= softmin && tempf <= softmax) data->value = tempf; else - data->cancel = 1; + data->cancel = TRUE; } button_activate_state(C, but, BUTTON_STATE_EXIT); @@ -2907,8 +2934,8 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { @@ -2978,7 +3005,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm return WM_UI_HANDLER_BREAK; } } - else if (but->type == COL) { + else if (but->type == COLOR) { if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { float *hsv = ui_block_hsv_get(but->block); float col[3]; @@ -3010,7 +3037,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm /* outside icon quit, not needed if drag activated */ if (0 == ui_but_mouse_inside_icon(but, data->region, event)) { button_activate_state(C, but, BUTTON_STATE_EXIT); - data->cancel = 1; + data->cancel = TRUE; return WM_UI_HANDLER_BREAK; } @@ -3321,8 +3348,8 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -3501,8 +3528,8 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } /* XXX hardcoded keymap check.... */ @@ -3794,7 +3821,7 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt } else { /* move the view */ - data->cancel = 1; + data->cancel = TRUE; } data->dragsel = sel; @@ -3916,8 +3943,8 @@ static int ui_do_but_HISTOGRAM(bContext *C, uiBlock *block, uiBut *but, uiHandle } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -3999,8 +4026,8 @@ static int ui_do_but_WAVEFORM(bContext *C, uiBlock *block, uiBut *but, uiHandleB } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -4066,8 +4093,8 @@ static int ui_do_but_VECTORSCOPE(bContext *C, uiBlock *block, uiBut *but, uiHand } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -4209,7 +4236,7 @@ static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmE if (event->type == LEFTMOUSE && event->val != KM_PRESS) { if (!(but->flag & UI_SELECT)) - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } @@ -4283,8 +4310,8 @@ static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHan } else if (data->state == BUTTON_STATE_NUM_EDITING) { if (event->type == ESCKEY) { - data->cancel = 1; - data->escapecancel = 1; + data->cancel = TRUE; + data->escapecancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->type == MOUSEMOVE) { @@ -4736,7 +4763,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) ui_but_drop(C, event, but, data); } /* handle keyframing */ - else if (event->type == IKEY && !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey) && event->val == KM_PRESS) { + else if ((event->type == IKEY) && + !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey) && + (event->val == KM_PRESS)) + { if (event->alt) { if (event->shift) { ui_but_anim_clear_keyframe(C); @@ -4754,7 +4784,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) return WM_UI_HANDLER_BREAK; } /* handle drivers */ - else if (event->type == DKEY && !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && event->val == KM_PRESS) { + else if ((event->type == DKEY) && + !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && + (event->val == KM_PRESS)) + { if (event->alt) ui_but_anim_remove_driver(C); else @@ -4765,7 +4798,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) return WM_UI_HANDLER_BREAK; } /* handle keyingsets */ - else if (event->type == KKEY && !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && event->val == KM_PRESS) { + else if ((event->type == KKEY) && + !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && + (event->val == KM_PRESS)) + { if (event->alt) ui_but_anim_remove_keyingset(C); else @@ -4876,7 +4912,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case BUTM: retval = ui_do_but_BUT(C, but, data, event); break; - case COL: + case COLOR: if (but->a1 == UI_GRAD_V_ALT) /* signal to prevent calling up color picker */ retval = ui_do_but_EXIT(C, but, data, event); else @@ -4901,6 +4937,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case CHARTAB: retval = ui_do_but_CHARTAB(C, block, but, data, event); break; +#else + /* do nothing */ + case CHARTAB: + break; #endif case LINK: @@ -4910,6 +4950,11 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case TRACKPREVIEW: retval = ui_do_but_TRACKPREVIEW(C, block, but, data, event); break; + + /* quiet warnings for unhandled types */ + case SEPR: + case BUT_EXTRA: + break; } return retval; @@ -5186,17 +5231,33 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s /* automatic open pulldown block timer */ if (ELEM3(but->type, BLOCK, PULLDOWN, ICONTEXTROW)) { - if (data->used_mouse && !data->autoopentimer) { + if ((data->used_mouse == TRUE) && + (data->autoopentimer == FALSE) && + /* don't popup the first time, + * see description on this member for info */ + (but->block->auto_is_first_event == FALSE)) + { int time; - if (but->block->auto_open == TRUE) time = 1; // test for toolbox - else if ((but->block->flag & UI_BLOCK_LOOP && but->type != BLOCK) || but->block->auto_open == TRUE) time = 5 * U.menuthreshold2; - else if (U.uiflag & USER_MENUOPENAUTO) time = 5 * U.menuthreshold1; - else time = -1; + if (but->block->auto_open == TRUE) { /* test for toolbox */ + time = 1; + } + else if ((but->block->flag & UI_BLOCK_LOOP && but->type != BLOCK) || but->block->auto_open == TRUE) { + time = 5 * U.menuthreshold2; + } + else if (U.uiflag & USER_MENUOPENAUTO) { + time = 5 * U.menuthreshold1; + } + else { + time = -1; /* do nothing */ + } - if (time >= 0) + if (time >= 0) { data->autoopentimer = WM_event_add_timer(data->wm, data->window, TIMER, 0.02 * (double)time); + } } + + but->block->auto_is_first_event = FALSE; } } else { @@ -5288,7 +5349,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA /* XXX curve is temp */ } else { - data->interactive = 1; + data->interactive = TRUE; } data->state = BUTTON_STATE_INIT; @@ -5417,7 +5478,7 @@ void ui_button_active_free(const bContext *C, uiBut *but) * case cleanly anyway in case it happens */ if (but->active) { data = but->active; - data->cancel = 1; + data->cancel = TRUE; button_activate_exit((bContext *)C, data, but, 0, 1); } } @@ -5647,7 +5708,7 @@ static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiBu oldbut = ui_but_find_activated(ar); if (oldbut) { data = oldbut->active; - data->cancel = 1; + data->cancel = TRUE; button_activate_exit(C, data, oldbut, 0, 0); } @@ -5675,18 +5736,18 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) switch (event->type) { case WINDEACTIVATE: case EVT_BUT_CANCEL: - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); retval = WM_UI_HANDLER_CONTINUE; break; case MOUSEMOVE: /* verify if we are still over the button, if not exit */ if (!ui_mouse_inside_button(ar, but, event->x, event->y)) { - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (ui_but_find_mouse_over(ar, event->x, event->y) != but) { - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); } else if (event->x != event->prevx || event->y != event->prevy) { @@ -5696,7 +5757,8 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) } break; - case TIMER: { + case TIMER: + { /* handle tooltip timer */ if (event->customdata == data->tooltiptimer) { WM_event_remove_timer(data->wm, data->window, data->tooltiptimer); @@ -5734,7 +5796,7 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) else if (data->state == BUTTON_STATE_WAIT_RELEASE) { switch (event->type) { case WINDEACTIVATE: - data->cancel = 1; + data->cancel = TRUE; button_activate_state(C, but, BUTTON_STATE_EXIT); break; @@ -5750,18 +5812,18 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) if (ui_mouse_inside_button(ar, but, event->x, event->y)) { if (!(but->flag & UI_SELECT)) { but->flag |= (UI_SELECT | UI_ACTIVE); - data->cancel = 0; + data->cancel = FALSE; ED_region_tag_redraw(data->region); } } else { if (but->flag & UI_SELECT) { but->flag &= ~(UI_SELECT | UI_ACTIVE); - data->cancel = 1; + data->cancel = TRUE; ED_region_tag_redraw(data->region); } } - } + } break; default: /* otherwise catch mouse release event */ @@ -5773,9 +5835,11 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) } else if (data->state == BUTTON_STATE_WAIT_FLASH) { switch (event->type) { - case TIMER: { - if (event->customdata == data->flashtimer) + case TIMER: + { + if (event->customdata == data->flashtimer) { button_activate_state(C, but, BUTTON_STATE_EXIT); + } } } @@ -5785,21 +5849,41 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but) /* check for exit because of mouse-over another button */ switch (event->type) { case MOUSEMOVE: - - if (data->menu && data->menu->region) - if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) + { + /* if the mouse is over the button, do nothing */ + if (ui_mouse_inside_button(data->region, but, event->x, event->y)) { + break; + } + + /* if the mouse is over the menu, also do nothing */ + if (data->menu && data->menu->region) { + if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) { break; - - { - uiBut *bt = ui_but_find_mouse_over(ar, event->x, event->y); + } + else { + /* make a rectangle between the menu and the button that opened it, + * this avoids any space between them exiting the popup. see [#29072] - campbell */ + rctf rct_all = but->rect; + rctf rct_win; + + ui_block_to_window_fl(ar, block, &rct_all.xmin, &rct_all.ymin); + ui_block_to_window_fl(ar, block, &rct_all.xmax, &rct_all.ymax); + + BLI_rctf_rcti_copy(&rct_win, &data->menu->region->winrct); + BLI_rctf_union(&rct_all, &rct_win); - if (bt && bt->active != data) { - if (but->type != COL) /* exception */ - data->cancel = 1; - button_activate_state(C, but, BUTTON_STATE_EXIT); + if (BLI_rctf_isect_pt(&rct_all, event->x, event->y)) { + break; + } } - break; } + + if (but->type != COLOR) { /* exception */ + data->cancel = TRUE; + } + button_activate_state(C, but, BUTTON_STATE_EXIT); + break; + } } ui_do_button(C, block, but, event); @@ -5904,15 +5988,19 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * /* copy over return values from the closing menu */ if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_UPDATE)) { - if (but->type == COL) + if (but->type == COLOR) copy_v3_v3(data->vec, menu->retvec); else if (ELEM3(but->type, MENU, ICONROW, ICONTEXTROW)) data->value = menu->retvalue; } if (menu->menuretval & UI_RETURN_UPDATE) { - if (data->interactive) ui_apply_button(C, but->block, but, data, 1); - else ui_check_but(but); + if (data->interactive) { + ui_apply_button(C, but->block, but, data, TRUE); + } + else { + ui_check_but(but); + } menu->menuretval = 0; } @@ -5920,7 +6008,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * /* now change button state or exit, which will close the submenu */ if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_CANCEL)) { if (menu->menuretval != UI_RETURN_OK) - data->cancel = 1; + data->cancel = TRUE; button_activate_exit(C, data, but, 1, 0); } @@ -5935,7 +6023,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); } else { - data->cancel = 1; + data->cancel = TRUE; button_activate_exit(C, data, but, 1, 0); } } @@ -5956,7 +6044,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut * static void ui_mouse_motion_towards_init(uiPopupBlockHandle *menu, int mx, int my, int force) { if (!menu->dotowards || force) { - menu->dotowards = 1; + menu->dotowards = TRUE; menu->towardsx = mx; menu->towardsy = my; @@ -5972,7 +6060,9 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men float p1[2], p2[2], p3[2], p4[2], oldp[2], newp[2]; int closer; - if (!menu->dotowards) return 0; + if (!menu->dotowards) { + return 0; + } /* verify that we are moving towards one of the edges of the * menu block, in other words, in the triangle formed by the @@ -6004,11 +6094,11 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men isect_point_tri_v2(newp, oldp, p4, p1)); if (!closer) - menu->dotowards = 0; + menu->dotowards = FALSE; /* 1 second timer */ if (PIL_check_seconds_timer() - menu->towardstime > BUTTON_MOUSE_TOWARDS_THRESH) - menu->dotowards = 0; + menu->dotowards = FALSE; return menu->dotowards; } @@ -6164,7 +6254,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle case WHEELUPMOUSE: case WHEELDOWNMOUSE: /* arrowkeys: only handle for block_loop blocks */ - if (event->alt || event->shift || event->ctrl || event->oskey) ; + if (event->alt || event->shift || event->ctrl || event->oskey) { + /* pass */ + } else if (inside || (block->flag & UI_BLOCK_LOOP)) { if (event->val == KM_PRESS) { but = ui_but_find_activated(ar); @@ -6213,8 +6305,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle } } - if (bt) + if (bt) { ui_handle_button_activate(C, ar, bt, BUTTON_ACTIVATE); + } } } @@ -6249,7 +6342,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle count = 0; for (but = block->buttons.first; but; but = but->next) { - int doit = 0; + int doit = FALSE; if (but->type != LABEL && but->type != SEPR) count++; @@ -6258,19 +6351,29 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle if (but->rnapoin.data && but->rnaprop) { if (ELEM(RNA_property_subtype(but->rnaprop), PROP_LAYER, PROP_LAYER_MEMBER)) { if (but->rnaindex == act - 1) - doit = 1; + doit = TRUE; } } /* exception for menus like layer buts, with button aligning they're not drawn in order */ else if (but->type == TOGR) { if (but->bitnr == act - 1) - doit = 1; + doit = TRUE; + } + else if (count == act) { + doit = TRUE; } - else if (count == act) - doit = 1; if (doit) { - ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_APPLY); + /* activate buttons but open menu's */ + uiButtonActivateType activate; + if (but->type == PULLDOWN) { + activate = BUTTON_ACTIVATE_OPEN; + } + else { + activate = BUTTON_ACTIVATE_APPLY; + } + + ui_handle_button_activate(C, ar, but, activate); break; } } @@ -6315,7 +6418,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle for (but = block->buttons.first; but; but = but->next) { if (but->menu_key == event->type) { - if (but->type == BUT) { + if (ELEM(but->type, BUT, BUTM)) { /* mainly for operator buttons */ ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_APPLY); } @@ -6408,7 +6511,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle * buttons inside this region. disabled inside check .. not sure * anymore why it was there? but it meant enter didn't work * for example when mouse was not over submenu */ - if ((/*inside &&*/ (!menu->menuretval || (menu->menuretval & UI_RETURN_UPDATE)) && retval == WM_UI_HANDLER_CONTINUE) || event->type == TIMER) { + if ((event->type == TIMER) || + (/*inside &&*/ (!menu->menuretval || (menu->menuretval & UI_RETURN_UPDATE)) && retval == WM_UI_HANDLER_CONTINUE)) + { but = ui_but_find_activated(ar); if (but) { diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index dd3c2e491a7..f6f12f98181 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -59,7 +59,6 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_icons.h" -#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -621,7 +620,7 @@ static void init_iconfile_list(struct ListBase *list) if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */ for (i = 0; i < totfile; i++) { - if ( (dir[i].type & S_IFREG) ) { + if ((dir[i].type & S_IFREG)) { char *filename = dir[i].relname; if (BLI_testextensie(filename, ".png")) { @@ -836,7 +835,7 @@ static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size) if (G.debug & G_DEBUG) printf("%s, error: requested preview image does not exist", __func__); } - if (!prv_img->rect[size]) { + else if (!prv_img->rect[size]) { prv_img->w[size] = render_size; prv_img->h[size] = render_size; prv_img->changed[size] = 1; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 567109e26d0..73e6427d1cb 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -94,8 +94,7 @@ typedef enum { UI_WTYPE_BOX, UI_WTYPE_SCROLL, UI_WTYPE_LISTITEM, - UI_WTYPE_PROGRESSBAR, - + UI_WTYPE_PROGRESSBAR } uiWidgetTypeEnum; /* panel limits */ @@ -131,6 +130,14 @@ typedef enum { /* for scope resize zone */ #define SCOPE_RESIZE_PAD 9 +/* bit button defines */ +/* Bit operations */ +#define UI_BITBUT_TEST(a, b) ( ( (a) & 1 << (b) ) != 0) +#define UI_BITBUT_SET(a, b) ( (a) | 1 << (b) ) +#define UI_BITBUT_CLR(a, b) ( (a) & ~(1 << (b)) ) +/* bit-row */ +#define UI_BITBUT_ROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) + typedef struct uiLinkLine { /* only for draw/edit */ struct uiLinkLine *next, *prev; struct uiBut *from, *to; @@ -151,8 +158,9 @@ typedef struct { struct uiBut { struct uiBut *next, *prev; int flag, drawflag; - short type, pointype, bit, bitnr, retval, strwidth, ofs, pos, selsta, selend, alignnr; - short pad1; + eButType type; + eButPointerType pointype; + short bit, bitnr, retval, strwidth, ofs, pos, selsta, selend, alignnr; char *str; char strdata[UI_MAX_NAME_STR]; @@ -297,7 +305,17 @@ struct uiBlock { char direction; char dt; /* drawtype: UI_EMBOSS, UI_EMBOSSN ... etc, copied to buttons */ char auto_open; - char _pad[7]; + + /* this setting is used so newly opened menu's dont popout the first item under the mouse, + * the reasoning behind this is because of muscle memory for opening menus. + * + * Without this, the first time opening a Submenu and activating an item in it will be 2 steps, + * but the second time the same item is accessed the menu memory would auto activate the + * last used menu and the key intended to select that submenu ends up being passed into the submenu. + * - Campbell + */ + char auto_is_first_event; + char _pad[6]; double auto_open_last; const char *lockstr; @@ -308,7 +326,8 @@ struct uiBlock { char endblock; /* uiEndBlock done? */ float xofs, yofs; /* offset to parent button */ - int dobounds, mx, my; /* for doing delayed */ + eBlockBoundsCalc bounds_type; /* for doing delayed */ + int mx, my; int bounds, minbounds; /* for doing delayed */ rctf safety; /* pulldowns, to detect outside, can differ per case how it is created */ @@ -340,7 +359,7 @@ void ui_fontscale(short *points, float aspect); extern void ui_block_to_window_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y); extern void ui_block_to_window(const struct ARegion *ar, uiBlock *block, int *x, int *y); -extern void ui_block_to_window_rct(const struct ARegion *ar, uiBlock *block, rctf *graph, rcti *winr); +extern void ui_block_to_window_rct(const struct ARegion *ar, uiBlock *block, const rctf *graph, rcti *winr); extern void ui_window_to_block_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y); extern void ui_window_to_block(const struct ARegion *ar, uiBlock *block, int *x, int *y); extern void ui_window_to_region(const ARegion *ar, int *x, int *y); @@ -402,7 +421,7 @@ struct uiPopupBlockHandle { float retvec[4]; }; -uiBlock *ui_block_func_COL(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); +uiBlock *ui_block_func_COLOR(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); void ui_block_func_ICONROW(struct bContext *C, uiLayout *layout, void *arg_but); void ui_block_func_ICONTEXTROW(struct bContext *C, uiLayout *layout, void *arg_but); @@ -521,4 +540,3 @@ int ui_but_anim_expression_create(uiBut *but, const char *str); void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra); #endif - diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index b68e14898d0..803fd928085 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2837,7 +2837,9 @@ static void ui_layout_operator_buts__reset_cb(bContext *UNUSED(C), void *op_pt, } /* this function does not initialize the layout, functions can be called on the layout before and after */ -void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op, int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align, const short flag) +void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op, + int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), + const char label_align, const short flag) { if (!op->properties) { IDPropertyTemplate val = {0}; diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 67c0d04a79f..e8b8959fd43 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -908,19 +908,19 @@ static void UI_OT_editsource(wmOperatorType *ot) void edittranslation_find_po_file(const char *root, const char *uilng, char *path, const size_t maxlen) { - char t[32]; /* Should be more than enough! */ + char tstr[32]; /* Should be more than enough! */ /* First, full lang code. */ - sprintf(t, "%s.po", uilng); + BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng); BLI_join_dirfile(path, maxlen, root, uilng); - BLI_join_dirfile(path, maxlen, path, t); + BLI_join_dirfile(path, maxlen, path, tstr); if (BLI_is_file(path)) return; /* Now try without the second iso code part (_ES in es_ES). */ - strncpy(t, uilng, 2); - strcpy(t + 2, uilng + 5); /* Because of some codes like sr_SR@latin... */ - BLI_join_dirfile(path, maxlen, root, t); - sprintf(t, "%s.po", t); - BLI_join_dirfile(path, maxlen, path, t); + strncpy(tstr, uilng, 2); + BLI_strncpy(tstr + 2, uilng + 5, sizeof(tstr) - 2); /* Because of some codes like sr_SR@latin... */ + BLI_join_dirfile(path, maxlen, root, tstr); + strcat(tstr, ".po"); + BLI_join_dirfile(path, maxlen, path, tstr); if (BLI_is_file(path)) return; path[0] = '\0'; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 96c1b00d46d..10a64d50887 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1648,6 +1648,18 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut ar->regiondata = handle; + /* set UI_BLOCK_NUMSELECT before uiEndBlock() so we get alphanumeric keys assigned */ + if (but) { + if (but->type == PULLDOWN) { + block->flag |= UI_BLOCK_NUMSELECT; + } + } + else { + block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; + } + + block->flag |= UI_BLOCK_LOOP; + if (!block->endblock) uiEndBlock(C, block); @@ -1665,7 +1677,6 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); saferct->safety = block->safety; BLI_addhead(&block->saferct, saferct); - block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; } /* clip block with window boundary */ @@ -1680,8 +1691,6 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut ar->winrct.ymax = block->rect.ymax + MENU_TOP; ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin); - - block->flag |= UI_BLOCK_LOOP; /* adds subwindow */ ED_region_init(C, ar); @@ -1797,11 +1806,11 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a bt->flag = UI_TEXT_LEFT; } else if (entry->icon) { - uiDefIconTextButF(block, BUTM | FLO, B_NOP, entry->icon, entry->str, 0, 0, + uiDefIconTextButF(block, BUTM, B_NOP, entry->icon, entry->str, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } else { - uiDefButF(block, BUTM | FLO, B_NOP, entry->str, 0, 0, + uiDefButF(block, BUTM, B_NOP, entry->str, 0, 0, UI_UNIT_X * 5, UI_UNIT_X, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } } @@ -1819,7 +1828,7 @@ void ui_block_func_ICONROW(bContext *UNUSED(C), uiLayout *layout, void *arg_but) uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT); for (a = (int)but->hardmin; a <= (int)but->hardmax; a++) - uiDefIconButF(block, BUTM | FLO, B_NOP, but->icon + (a - but->hardmin), 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, + uiDefIconButF(block, BUTM, B_NOP, but->icon + (a - but->hardmin), 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, &handle->retvalue, (float)a, 0.0, 0, 0, ""); } @@ -1849,7 +1858,7 @@ void ui_block_func_ICONTEXTROW(bContext *UNUSED(C), uiLayout *layout, void *arg_ if (entry->sepr) uiItemS(layout); else - uiDefIconTextButF(block, BUTM | FLO, B_NOP, (short)((but->icon) + (entry->retval - but->hardmin)), entry->str, + uiDefIconTextButF(block, BUTM, B_NOP, (short)((but->icon) + (entry->retval - but->hardmin)), entry->str, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } @@ -2021,27 +2030,20 @@ static void picker_new_hide_reveal(uiBlock *block, short colormode) /* tag buttons */ for (bt = block->buttons.first; bt; bt = bt->next) { - - if (bt->type == LABEL) { - if (bt->str[1] == 'G') { - if (colormode == 2) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } + if (bt->func == do_picker_rna_cb && bt->type == NUMSLI && bt->rnaindex != 3) { + /* RGB sliders (color circle and alpha are always shown) */ + if (colormode == 0) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; } - - if (bt->type == NUMSLI || bt->type == TEX) { - if (bt->str[1] == 'e') { - if (colormode == 2) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } - else if (ELEM3(bt->str[0], 'R', 'G', 'B')) { - if (colormode == 0) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } - else if (ELEM3(bt->str[0], 'H', 'S', 'V')) { - if (colormode == 1) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } + else if (bt->func == do_hsv_rna_cb) { + /* HSV sliders */ + if (colormode == 1) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; + } + else if (bt->func == do_hex_rna_cb || bt->type == LABEL) { + /* hex input or gamma correction status label */ + if (colormode == 2) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; } } } @@ -2235,7 +2237,7 @@ static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, w return 0; } -uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_but) +uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_but) { uiBut *but = arg_but; uiBlock *block; @@ -2434,6 +2436,7 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut uiPopupMenu *pup; pup = MEM_callocN(sizeof(uiPopupMenu), __func__); pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); + pup->block->flag |= UI_BLOCK_NUMSELECT; /* default menus to numselect */ pup->layout = uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style); pup->slideout = (but && (but->block->flag & UI_BLOCK_LOOP)); pup->but = but; @@ -2499,6 +2502,7 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); pup->block->flag |= UI_BLOCK_POPUP_MEMORY; pup->block->puphash = ui_popup_menu_hash(title); + pup->block->auto_is_first_event = TRUE; pup->layout = uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style); uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index ee0613ea0d0..b16250021d3 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -257,7 +257,7 @@ uiStyle *UI_GetStyle(void) { uiStyle *style = NULL; /* offset is two struct uiStyle pointers */ - /* style = BLI_findstring( &U.uistyles, "Unifont Style", sizeof(style)*2 ) */; + /* style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2) */; return (style != NULL) ? style : U.uistyles.first; } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 2137f4ec14c..9f0dc4af226 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1025,7 +1025,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco + 10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); if (con->flag & CONSTRAINT_DISABLE) - uiLayoutSetRedAlert(row, 1); + uiLayoutSetRedAlert(row, TRUE); if (proxy_protected == 0) { uiItemR(row, &ptr, "name", 0, "", ICON_NONE); @@ -1033,7 +1033,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) else uiItemL(row, con->name, ICON_NONE); - uiLayoutSetRedAlert(row, 0); + uiLayoutSetRedAlert(row, FALSE); /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */ if (proxy_protected) { @@ -1201,7 +1201,7 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M block = uiLayoutGetBlock(layout); row = uiLayoutRow(layout, FALSE); col = uiLayoutColumn(row, FALSE); - uiLayoutSetKeepAspect(col, 1); + uiLayoutSetKeepAspect(col, TRUE); /* add preview */ uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, pid, 0.0, 0.0, 0, 0, ""); @@ -1745,6 +1745,13 @@ static void curvemap_buttons_redraw(bContext *C, void *UNUSED(arg1), void *UNUSE ED_region_tag_redraw(CTX_wm_region(C)); } +static void curvemap_buttons_update(bContext *UNUSED(C), void *UNUSED(arg1), void *cumap_v) +{ + CurveMapping *cumap = cumap_v; + + curvemapping_changed(cumap, TRUE); +} + static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) { CurveMapping *cumap = cumap_v; @@ -1767,12 +1774,14 @@ static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels, int brush, RNAUpdateCb *cb) { CurveMapping *cumap = ptr->data; + CurveMap *cm = &cumap->cm[cumap->cur]; + CurveMapPoint *cmp = NULL; uiLayout *row, *sub, *split; uiBlock *block; uiBut *bt; float dx = UI_UNIT_X; int icon, size; - int bg = -1; + int bg = -1, i; block = uiLayoutGetBlock(layout); @@ -1877,6 +1886,21 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe row = uiLayoutRow(layout, FALSE); uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 200), cumap, 0.0f, 1.0f, bg, 0, ""); + /* sliders for selected point */ + for (i = 0; i < cm->totpoint; i++) { + if (cm->curve[i].flag & CUMA_SELECT) { + cmp = &cm->curve[i]; + break; + } + } + + if (cmp) { + uiLayoutRow(layout, TRUE); + uiBlockSetNFunc(block, curvemap_buttons_update, NULL, cumap); + uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, &cmp->x, 0.0f, 1.0f, 1, 5, ""); + uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, &cmp->y, 0.0f, 1.0f, 1, 5, ""); + } + /* black/white levels */ if (levels) { split = uiLayoutSplit(layout, 0.0f, FALSE); @@ -2182,7 +2206,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe row = uiLayoutRow(split, TRUE); if (i == 0 || (key->type != KEY_RELATIVE)) uiItemL(row, "", ICON_NONE); else uiItemR(row, itemptr, "value", 0, "", ICON_NONE); - uiItemR(row, itemptr, "mute", 0, "", 0); + uiItemR(row, itemptr, "mute", 0, "", ICON_NONE); if ((kb->flag & KEYBLOCK_MUTE) || (ob->mode == OB_MODE_EDIT && !((ob->shapeflag & OB_SHAPE_EDIT_MODE) && ob->type == OB_MESH))) @@ -2251,9 +2275,9 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe uiBlockSetEmboss(block, UI_EMBOSSN); row = uiLayoutRow(split, TRUE); uiItemR(row, itemptr, "alpha", 0, "", ICON_NONE); - uiItemR(row, itemptr, "hide", 0, "", 0); - uiItemR(row, itemptr, "hide_select", 0, "", 0); - uiItemR(row, itemptr, "hide_render", 0, "", 0); + uiItemR(row, itemptr, "hide", 0, "", ICON_NONE); + uiItemR(row, itemptr, "hide_select", 0, "", ICON_NONE); + uiItemR(row, itemptr, "hide_render", 0, "", ICON_NONE); uiBlockSetEmboss(block, UI_EMBOSS); } @@ -2298,7 +2322,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe while (id < prop_names_end) { if ((id_next = strchr(id, ':'))) *id_next++ = '\0'; else id_next = prop_names_end; - uiItemR(row, itemptr, id, 0, NULL, 0); + uiItemR(row, itemptr, id, 0, NULL, ICON_NONE); id = id_next; } MEM_freeN(prop_names); @@ -2558,6 +2582,7 @@ void uiTemplateOperatorSearch(uiLayout *layout) #define B_STOPCOMPO 4 #define B_STOPSEQ 5 #define B_STOPCLIP 6 +#define B_STOPOTHER 7 static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) { @@ -2580,6 +2605,9 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) case B_STOPCLIP: WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL); break; + case B_STOPOTHER: + G.is_break = TRUE; + break; } } @@ -2619,6 +2647,10 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) handle_event = B_STOPCOMPO; break; } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) { + handle_event = B_STOPOTHER; + break; + } } owner = scene; } diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 8ff8e0824d6..d363609fbd9 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -78,7 +78,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind if (arraylen && index == -1) { if (ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA)) - but = uiDefButR_prop(block, COL, 0, name, x1, y1, x2, y2, ptr, prop, 0, 0, 0, -1, -1, NULL); + but = uiDefButR_prop(block, COLOR, 0, name, x1, y1, x2, y2, ptr, prop, 0, 0, 0, -1, -1, NULL); } else if (RNA_property_subtype(prop) == PROP_PERCENTAGE || RNA_property_subtype(prop) == PROP_FACTOR) but = uiDefButR_prop(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); @@ -102,7 +102,8 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind else but = uiDefButR_prop(block, TEX, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; - case PROP_POINTER: { + case PROP_POINTER: + { PointerRNA pptr; pptr = RNA_property_pointer_get(ptr, prop); @@ -115,7 +116,8 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind but = uiDefIconTextButR_prop(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { char text[256]; BLI_snprintf(text, sizeof(text), IFACE_("%d items"), RNA_property_collection_length(ptr, prop)); but = uiDefBut(block, LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ef8d8302fa7..026f02d1089 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -46,7 +46,6 @@ #include "BKE_context.h" #include "BKE_curve.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -1256,10 +1255,12 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB if (but->type == BUT_TOGDUAL) { int dualset = 0; - if (but->pointype == SHO) - dualset = BTST(*(((short *)but->poin) + 1), but->bitnr); - else if (but->pointype == INT) - dualset = BTST(*(((int *)but->poin) + 1), but->bitnr); + if (but->pointype == UI_BUT_POIN_SHORT) { + dualset = UI_BITBUT_TEST(*(((short *)but->poin) + 1), but->bitnr); + } + else if (but->pointype == UI_BUT_POIN_INT) { + dualset = UI_BITBUT_TEST(*(((int *)but->poin) + 1), but->bitnr); + } widget_draw_icon(but, ICON_DOT, dualset ? 1.0f : 0.25f, rect); } @@ -3155,7 +3156,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct wt = widget_type(UI_WTYPE_MENU_ITEM); break; - case COL: + case COLOR: wt = widget_type(UI_WTYPE_SWATCH); break; diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 3926fe291c7..1d0cd2707ac 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -950,7 +950,7 @@ void UI_SetTheme(int spacetype, int regionid) } } -bTheme *UI_GetTheme() +bTheme *UI_GetTheme(void) { return U.themes.first; } diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index c3059b8d575..0f1d1a24dcb 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -544,7 +544,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) curheight = BLI_RCT_SIZE_Y(cur); /* width */ - if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_X | V2D_LIMITZOOM)) ) { + if ((curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_X | V2D_LIMITZOOM))) { /* if zoom doesn't have to be maintained, just clamp edges */ if (cur->xmin < tot->xmin) cur->xmin = tot->xmin; if (cur->xmax > tot->xmax) cur->xmax = tot->xmax; @@ -627,7 +627,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) } /* height */ - if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_Y | V2D_LIMITZOOM)) ) { + if ((curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_Y | V2D_LIMITZOOM))) { /* if zoom doesn't have to be maintained, just clamp edges */ if (cur->ymin < tot->ymin) cur->ymin = tot->ymin; if (cur->ymax > tot->ymax) cur->ymax = tot->ymax; @@ -1874,7 +1874,7 @@ void UI_view2d_listview_view_to_cell(View2D *v2d, short columnwidth, short rowhe const int y = (int)(floorf(fabsf(viewy) + 0.5f) - starty); /* sizes must not be negative */ - if ( (v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0)) ) { + if ((v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0))) { if (column) *column = 0; if (row) *row = 0; diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 5b19bb2d3c9..99313edc289 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1719,8 +1719,8 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) * NOTE: see view2d.c for latest conditions, and keep this in sync with that */ if (ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { - if ( ((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0) || - ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0) ) + if (((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0) || + ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0)) { /* switch to bar (i.e. no scaling gets handled) */ vsm->zone = SCROLLHANDLE_BAR; @@ -1729,8 +1729,8 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) /* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */ if (vsm->zone == SCROLLHANDLE_BAR) { - if ( ((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) || - ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y)) ) + if (((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) || + ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y))) { /* free customdata initialized */ scroller_activate_exit(C, op); @@ -1741,8 +1741,8 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) } /* zone is also inappropriate if scroller is not visible... */ - if ( ((vsm->scroller == 'h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_HIDE | V2D_SCROLL_HORIZONTAL_FULLR))) || - ((vsm->scroller == 'v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE | V2D_SCROLL_VERTICAL_FULLR))) ) + if (((vsm->scroller == 'h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_HIDE | V2D_SCROLL_HORIZONTAL_FULLR))) || + ((vsm->scroller == 'v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE | V2D_SCROLL_VERTICAL_FULLR))) ) { /* free customdata initialized */ scroller_activate_exit(C, op); diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index d0ce3f0cace..0e6b8f77528 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -152,10 +152,10 @@ void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr) /* Export Options: */ box = uiLayoutBox(layout); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(box, FALSE); uiItemL(row, IFACE_("Export Data Options:"), ICON_MESH_DATA); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(box, FALSE); split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT); col = uiLayoutColumn(split, FALSE); uiItemR(col, imfptr, "apply_modifiers", 0, NULL, ICON_NONE); diff --git a/source/blender/editors/io/io_collada.h b/source/blender/editors/io/io_collada.h index 5cb255e1b7c..4bb1475a3b2 100644 --- a/source/blender/editors/io/io_collada.h +++ b/source/blender/editors/io/io_collada.h @@ -24,7 +24,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/editor/io/io_collada.h +/** \file blender/editors/io/io_collada.h * \ingroup editor/io */ diff --git a/source/blender/editors/io/io_ops.h b/source/blender/editors/io/io_ops.h index 4c04b349655..4fffca4607c 100644 --- a/source/blender/editors/io/io_ops.h +++ b/source/blender/editors/io/io_ops.h @@ -24,7 +24,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/editor/io/io_ops.h +/** \file blender/editors/io/io_ops.h * \ingroup editor/io */ diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index b37f758596b..7fe1ac09df6 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -556,6 +556,7 @@ static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, con static int add_vertex_exec(bContext *C, wmOperator *op) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; @@ -595,7 +596,7 @@ static int add_vertex_exec(bContext *C, wmOperator *op) BKE_mask_calc_handle_point_auto(spline, point_other, FALSE); /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); return OPERATOR_FINISHED; @@ -617,7 +618,7 @@ static int add_vertex_exec(bContext *C, wmOperator *op) } /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 00bbfcf3188..655458bd4cb 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -496,7 +496,8 @@ void ED_mask_draw(const bContext *C, * width, height are to match the values from ED_mask_get_size() */ void ED_mask_draw_region(Mask *mask, ARegion *ar, const char draw_flag, const char draw_type, - int width, int height, + const int width_i, const int height_i, /* convert directly into aspect corrected vars */ + const float aspx, const float aspy, const short do_scale_applied, const short do_post_draw, float stabmat[4][4], /* optional - only used by clip */ const bContext *C /* optional - only used when do_post_draw is set */ @@ -504,6 +505,9 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar, { struct View2D *v2d = &ar->v2d; + /* aspect always scales vertically in movie and image spaces */ + const float width = width_i, height = (float)height_i * (aspy / aspx); + int x, y; /* int w, h; */ float zoomx, zoomy; diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 85a8ae11111..39a19bdaa5f 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -109,11 +109,9 @@ void ED_mask_mouse_pos(ScrArea *sa, ARegion *ar, const int mval[2], float co[2]) } case SPACE_IMAGE: { - float frame_size[2]; SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_size_fl(sima, frame_size); ED_image_mouse_pos(sima, ar, mval, co); - BKE_mask_coord_from_frame(co, co, frame_size); + BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); break; } default: @@ -149,11 +147,9 @@ void ED_mask_point_pos(ScrArea *sa, ARegion *ar, float x, float y, float *xr, fl break; case SPACE_IMAGE: { - float frame_size[2]; SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_size_fl(sima, frame_size); ED_image_point_pos(sima, ar, x, y, &co[0], &co[1]); - BKE_mask_coord_from_frame(co, co, frame_size); + BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); break; } default: @@ -192,13 +188,10 @@ void ED_mask_point_pos__reverse(ScrArea *sa, ARegion *ar, float x, float y, floa break; case SPACE_IMAGE: { - float frame_size[2]; SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_size_fl(sima, frame_size); - co[0] = x; co[1] = y; - BKE_mask_coord_to_frame(co, co, frame_size); + BKE_mask_coord_to_image(sima->image, &sima->iuser, co, co); ED_image_point_pos__reverse(sima, ar, co, co); break; } diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 1df1e5a66fe..88fbb91edfb 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -915,6 +915,7 @@ static void delete_feather_points(MaskSplinePoint *point) static int delete_exec(bContext *C, wmOperator *UNUSED(op)) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; @@ -1002,7 +1003,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) } /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); @@ -1060,7 +1061,7 @@ static int mask_switch_direction_exec(bContext *C, wmOperator *UNUSED(op)) if (change) { /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); @@ -1126,7 +1127,7 @@ static int mask_normals_make_consistent_exec(bContext *C, wmOperator *UNUSED(op) if (change) { /* TODO: only update this spline */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); @@ -1324,6 +1325,7 @@ void MASK_OT_hide_view_set(wmOperatorType *ot) static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; int changed = FALSE; @@ -1351,7 +1353,7 @@ static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) if (changed) { /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + BKE_mask_update_display(mask, CFRA); WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask); DAG_id_tag_update(&mask->id, 0); diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 3431bea18ea..94e10b53b29 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -123,43 +123,6 @@ void paintface_flush_flags(Object *ob) } } -/* returns 0 if not found, otherwise 1 */ -static int facesel_face_pick(struct bContext *C, Mesh *me, Object *ob, const int mval[2], unsigned int *index, short rect) -{ - Scene *scene = CTX_data_scene(C); - ViewContext vc; - view3d_set_viewcontext(C, &vc); - - if (!me || me->totpoly == 0) - return 0; - - makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0); - - // XXX if (v3d->flag & V3D_INVALID_BACKBUF) { -// XXX drawview.c! check_backbuf(); -// XXX persp(PERSP_VIEW); -// XXX } - - if (rect) { - /* sample rect to increase changes of selecting, so that when clicking - * on an edge in the backbuf, we can still select a face */ - - int dist; - *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totpoly + 1, &dist, 0, NULL, NULL); - } - else { - /* sample only on the exact position */ - *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); - } - - if ((*index) <= 0 || (*index) > (unsigned int)me->totpoly) - return 0; - - (*index)--; - - return 1; -} - void paintface_hide(Object *ob, const int unselected) { Mesh *me; @@ -174,10 +137,10 @@ void paintface_hide(Object *ob, const int unselected) while (a--) { if ((mpoly->flag & ME_HIDE) == 0) { if (unselected) { - if ( (mpoly->flag & ME_FACE_SEL) == 0) mpoly->flag |= ME_HIDE; + if ((mpoly->flag & ME_FACE_SEL) == 0) mpoly->flag |= ME_HIDE; } else { - if ( (mpoly->flag & ME_FACE_SEL)) mpoly->flag |= ME_HIDE; + if ((mpoly->flag & ME_FACE_SEL)) mpoly->flag |= ME_HIDE; } } if (mpoly->flag & ME_HIDE) mpoly->flag &= ~ME_FACE_SEL; @@ -331,7 +294,7 @@ void paintface_select_linked(bContext *UNUSED(C), Object *ob, int UNUSED(mval[2] if (mode == 0 || mode == 1) { /* XXX - Causes glitches, not sure why */ #if 0 - if (!facesel_face_pick(C, me, mval, &index, 1)) + if (!ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) return; #endif } @@ -518,7 +481,7 @@ int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], in /* Get the face under the cursor */ me = BKE_mesh_from_object(ob); - if (!facesel_face_pick(C, me, ob, mval, &index, 1)) + if (!ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) return 0; if (index >= me->totpoly) diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 9cbd9e0b7da..8b032bb1a3d 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -97,7 +97,6 @@ static void make_prim_finish(bContext *C, int *state, int enter_editmode) static int add_primitive_plane_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -108,8 +107,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) make_prim_init(C, "Plane", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat)) @@ -143,7 +141,6 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) static int add_primitive_cube_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -154,8 +151,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op) make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) { return OPERATOR_CANCELLED; @@ -194,7 +190,6 @@ static const EnumPropertyItem fill_type_items[] = { static int add_primitive_circle_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -208,8 +203,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op) make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4", @@ -253,7 +247,6 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -267,8 +260,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf( em, op, "vertout", @@ -318,7 +310,6 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) static int add_primitive_cone_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -332,8 +323,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op) make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf( em, op, "vertout", @@ -382,7 +372,6 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) static int add_primitive_grid_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -393,8 +382,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) make_prim_init(C, "Grid", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", @@ -438,7 +426,6 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) static int add_primitive_monkey_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -452,8 +439,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op) make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) { return OPERATOR_CANCELLED; @@ -484,7 +470,6 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -495,8 +480,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) make_prim_init(C, "Sphere", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4", @@ -540,7 +524,6 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) { Object *obedit; - Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; @@ -551,8 +534,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) make_prim_init(C, "Icosphere", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + em = BMEdit_FromObject(obedit); if (!EDBM_op_call_and_selectf( em, op, "vertout", diff --git a/source/blender/editors/mesh/editmesh_bvh.c b/source/blender/editors/mesh/editmesh_bvh.c index 549032f7286..0b7d396b696 100644 --- a/source/blender/editors/mesh/editmesh_bvh.c +++ b/source/blender/editors/mesh/editmesh_bvh.c @@ -49,6 +49,7 @@ #include "ED_mesh.h" #include "ED_view3d.h" +#include "editmesh_bvh.h" /* own include */ typedef struct BMBVHTree { BMEditMesh *em; @@ -394,15 +395,10 @@ int BMBVH_EdgeVisible(BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Obje float co1[3], co2[3], co3[3], dir1[4], dir2[4], dir3[4]; float origin[3], invmat[4][4]; float epsilon = 0.01f; - float mval_f[2], end[3]; - - if (!ar) { - printf("error in BMBVH_EdgeVisible!\n"); - return 0; - } - - mval_f[0] = ar->winx / 2.0f; - mval_f[1] = ar->winy / 2.0f; + float end[3]; + const float mval_f[2] = {ar->winx / 2.0f, + ar->winy / 2.0f}; + ED_view3d_win_to_segment_clip(ar, v3d, mval_f, origin, end); invert_m4_m4(invmat, obedit->obmat); diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 229bbdbefb7..7ecfb712c18 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -160,7 +160,7 @@ typedef struct KnifeTool_OpData { int totlinehit; /* Data for mouse-position-derived data (cur) and previous click (prev) */ - KnifePosData cur, prev; + KnifePosData curr, prev; int totkedge, totkvert; @@ -290,7 +290,7 @@ static void knife_add_edge_faces_to_vert(KnifeTool_OpData *kcd, KnifeVert *kfv, } /* Find a face in common in the two faces lists. - If more than one, return the first; if none, return NULL */ + * If more than one, return the first; if none, return NULL */ static BMFace *knife_find_common_face(ListBase *faces1, ListBase *faces2) { Ref *ref1, *ref2; @@ -368,22 +368,22 @@ static KnifeEdge *get_bm_knife_edge(KnifeTool_OpData *kcd, BMEdge *e) * Copy the current position data into prev. */ static void knife_start_cut(KnifeTool_OpData *kcd) { - kcd->prev = kcd->cur; - kcd->cur.is_space = 0; /*TODO: why do we do this? */ + kcd->prev = kcd->curr; + kcd->curr.is_space = 0; /*TODO: why do we do this? */ if (kcd->prev.vert == NULL && kcd->prev.edge == NULL && is_zero_v3(kcd->prev.cage)) { /* Make prevcage a point on the view ray to mouse closest to a point on model: choose vertex 0 */ float origin[3], ray[3], co[3]; BMVert *v0; - knife_input_ray_cast(kcd, kcd->cur.mval, origin, ray); + knife_input_ray_cast(kcd, kcd->curr.mval, origin, ray); add_v3_v3v3(co, origin, ray); v0 = BM_vert_at_index(kcd->em->bm, 0); if (v0) { closest_to_line_v3(kcd->prev.cage, v0->co, co, origin); copy_v3_v3(kcd->prev.co, kcd->prev.cage); /*TODO: do we need this? */ - copy_v3_v3(kcd->cur.cage, kcd->prev.cage); - copy_v3_v3(kcd->cur.co, kcd->prev.co); + copy_v3_v3(kcd->curr.cage, kcd->prev.cage); + copy_v3_v3(kcd->curr.co, kcd->prev.co); } } } @@ -471,15 +471,15 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, KnifeEdge *kfe, float return newkfe->v2; } -/* Make a single KnifeEdge for cut from kcd->prev to kcd->cur. +/* Make a single KnifeEdge for cut from kcd->prev to kcd->curr. * and move cur data to prev. */ static void knife_add_single_cut(KnifeTool_OpData *kcd) { KnifeEdge *kfe = new_knife_edge(kcd), *kfe2 = NULL, *kfe3 = NULL; - if (kcd->prev.vert && kcd->prev.vert == kcd->cur.vert) + if (kcd->prev.vert && kcd->prev.vert == kcd->curr.vert) return; - if (kcd->prev.edge && kcd->prev.edge == kcd->cur.edge) + if (kcd->prev.edge && kcd->prev.edge == kcd->curr.edge) return; kfe->draw = 1; @@ -500,25 +500,25 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) knife_append_list(kcd, &kfe->v1->faces, kcd->prev.bmface); } - if (kcd->cur.vert) { - kfe->v2 = kcd->cur.vert; + if (kcd->curr.vert) { + kfe->v2 = kcd->curr.vert; } - else if (kcd->cur.edge) { - kfe->v2 = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); - kcd->cur.vert = kfe->v2; + else if (kcd->curr.edge) { + kfe->v2 = knife_split_edge(kcd, kcd->curr.edge, kcd->curr.co, &kfe3); + kcd->curr.vert = kfe->v2; } else { - kfe->v2 = new_knife_vert(kcd, kcd->cur.co, kcd->cur.co); - kfe->v2->draw = !kcd->cur.is_space; + kfe->v2 = new_knife_vert(kcd, kcd->curr.co, kcd->curr.co); + kfe->v2->draw = !kcd->curr.is_space; kfe->v2->isface = 1; - kfe->v2->inspace = kcd->cur.is_space; - if (kfe->v2->draw && kcd->cur.bmface) - knife_append_list(kcd, &kfe->v2->faces, kcd->cur.bmface); + kfe->v2->inspace = kcd->curr.is_space; + if (kfe->v2->draw && kcd->curr.bmface) + knife_append_list(kcd, &kfe->v2->faces, kcd->curr.bmface); - if (kcd->cur.is_space) + if (kcd->curr.is_space) kfe->draw = 0; - kcd->cur.vert = kfe->v2; + kcd->curr.vert = kfe->v2; } knife_find_basef(kfe); @@ -529,12 +529,12 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) knife_edge_append_face(kcd, kfe, kfe->basef); /* sanity check to make sure we're in the right edge/face lists */ - if (kcd->cur.bmface) { - if (!find_ref(&kfe->faces, kcd->cur.bmface)) { - knife_edge_append_face(kcd, kfe, kcd->cur.bmface); + if (kcd->curr.bmface) { + if (!find_ref(&kfe->faces, kcd->curr.bmface)) { + knife_edge_append_face(kcd, kfe, kcd->curr.bmface); } - if (kcd->prev.bmface && kcd->prev.bmface != kcd->cur.bmface) { + if (kcd->prev.bmface && kcd->prev.bmface != kcd->curr.bmface) { if (!find_ref(&kfe->faces, kcd->prev.bmface)) { knife_edge_append_face(kcd, kfe, kcd->prev.bmface); } @@ -542,7 +542,7 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) } /* set up for next cut */ - kcd->prev = kcd->cur; + kcd->prev = kcd->curr; } static int verge_linehit(const void *vlh1, const void *vlh2) @@ -554,6 +554,65 @@ static int verge_linehit(const void *vlh1, const void *vlh2) else return 0; } +/* If there's a linehit connected (same face) as testi in range [firsti, lasti], return the first such, else -1. + * If testi is out of range, look for connection to f instead, if f is non-NULL */ +static int find_connected_linehit(KnifeTool_OpData *kcd, int testi, BMFace *f, int firsti, int lasti) +{ + int i; + + for (i = firsti; i <= lasti; i++) { + if (testi >= 0 && testi < kcd->totlinehit) { + if (knife_find_common_face(&kcd->linehits[testi].kfe->faces, + &kcd->linehits[i].kfe->faces)) + return i; + } + else if (f) { + if (find_ref(&kcd->linehits[i].kfe->faces, f)) + return i; + } + } + return -1; +} + +/* Sort in order of distance along cut line, but take care when distances are equal */ +static void knife_sort_linehits(KnifeTool_OpData *kcd) +{ + int i, j, k, nexti, nsame; + + qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); + + /* for ranges of equal "l", swap if neccesary to make predecessor and + * successor faces connected to the linehits at either end of the range */ + for (i = 0; i < kcd->totlinehit - 1; i = nexti) { + for (j = i + 1; j < kcd->totlinehit; j++) { + if (fabsf(kcd->linehits[j].l - kcd->linehits[i].l) > 80 * FLT_EPSILON) + break; + } + nexti = j; + j--; + nsame = j - i; + if (nsame > 0) { + /* find something connected to predecessor of equal range */ + k = find_connected_linehit(kcd, i - 1, kcd->prev.bmface, i, j); + if (k != -1) { + if (k != i) { + SWAP(BMEdgeHit, kcd->linehits[i], kcd->linehits[k]); + } + i++; + nsame--; + } + if (nsame > 0) { + /* find something connected to successor of equal range */ + k = find_connected_linehit(kcd, j + 1, kcd->curr.bmface, i, j); + if (k != -1 && k != j) { + SWAP(BMEdgeHit, kcd->linehits[j], kcd->linehits[k]); + } + } + /* rest of same range doesn't matter because we won't connect them */ + } + } +} + static void knife_add_single_cut_through(KnifeTool_OpData *kcd, KnifeVert *v1, KnifeVert *v2, BMFace *f) { KnifeEdge *kfenew; @@ -618,29 +677,30 @@ static void knife_cut_through(KnifeTool_OpData *kcd) return; } + /* TODO: probably don't need to sort at all */ qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); splitkfe = MEM_callocN(kcd->totlinehit * sizeof(KnifeEdge *), "knife_cut_through"); if (kcd->prev.vert) { - if (kcd->prev.vert == kcd->cur.vert) + if (kcd->prev.vert == kcd->curr.vert) return; firstv = kcd->prev.vert; knife_get_vert_faces(kcd, firstv, kcd->prev.bmface, &firstfaces); } else if (kcd->prev.edge) { - if (kcd->prev.edge == kcd->cur.edge) + if (kcd->prev.edge == kcd->curr.edge) return; firstv = knife_split_edge(kcd, kcd->prev.edge, kcd->prev.co, &kfe3); knife_get_edge_faces(kcd, kcd->prev.edge, &firstfaces); } - if (kcd->cur.vert) { - lastv = kcd->cur.vert; - knife_get_vert_faces(kcd, lastv, kcd->cur.bmface, &lastfaces); + if (kcd->curr.vert) { + lastv = kcd->curr.vert; + knife_get_vert_faces(kcd, lastv, kcd->curr.bmface, &lastfaces); } - else if (kcd->cur.edge) { - lastv = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); - knife_get_edge_faces(kcd, kcd->cur.edge, &lastfaces); + else if (kcd->curr.edge) { + lastv = knife_split_edge(kcd, kcd->curr.edge, kcd->curr.co, &kfe3); + knife_get_edge_faces(kcd, kcd->curr.edge, &lastfaces); } if (firstv) { @@ -709,15 +769,15 @@ static void knife_cut_through(KnifeTool_OpData *kcd) kcd->totlinehit = 0; /* set up for next cut */ - kcd->prev = kcd->cur; + kcd->prev = kcd->curr; } /* User has just left-clicked after the first time. - * Add all knife cuts implied by line from prev to cur. + * Add all knife cuts implied by line from prev to curr. * If that line crossed edges then kcd->linehits will be non-NULL. */ static void knife_add_cut(KnifeTool_OpData *kcd) { - KnifePosData savcur = kcd->cur; + KnifePosData savcur = kcd->curr; if (kcd->cut_through) { knife_cut_through(kcd); @@ -726,8 +786,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) BMEdgeHit *lh, *lastlh, *firstlh; int i; - /* TODO: not a stable sort! need to figure out what to do for equal lambdas */ - qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); + knife_sort_linehits(kcd); lh = kcd->linehits; lastlh = firstlh = NULL; @@ -755,7 +814,11 @@ static void knife_add_cut(KnifeTool_OpData *kcd) if (len_v3v3(kcd->prev.cage, lh->realhit) < FLT_EPSILON * 80) continue; - if (len_v3v3(kcd->cur.cage, lh->realhit) < FLT_EPSILON * 80) + if (len_v3v3(kcd->curr.cage, lh->realhit) < FLT_EPSILON * 80) + continue; + + /* first linehit may be down face parallel to view */ + if (!lastlh && fabsf(lh->l) < FLT_EPSILON * 80) continue; if (kcd->prev.is_space) { @@ -768,12 +831,18 @@ static void knife_add_cut(KnifeTool_OpData *kcd) continue; } - kcd->cur.is_space = 0; - kcd->cur.edge = lh->kfe; - kcd->cur.bmface = lh->f; - kcd->cur.vert = lh->v; - copy_v3_v3(kcd->cur.co, lh->hit); - copy_v3_v3(kcd->cur.cage, lh->cagehit); + kcd->curr.is_space = 0; + kcd->curr.edge = lh->kfe; + kcd->curr.bmface = lh->f; + kcd->curr.vert = lh->v; + copy_v3_v3(kcd->curr.co, lh->hit); + copy_v3_v3(kcd->curr.cage, lh->cagehit); + + /* don't draw edges down faces parallel to view */ + if (lastlh && fabsf(lastlh->l - lh->l) < FLT_EPSILON * 80) { + kcd->prev = kcd->curr; + continue; + } knife_add_single_cut(kcd); } @@ -782,7 +851,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) kcd->prev = savcur; } else { - kcd->cur = savcur; + kcd->curr = savcur; knife_add_single_cut(kcd); } @@ -935,38 +1004,38 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg) glBegin(GL_LINES); glVertex3fv(kcd->prev.cage); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); glLineWidth(1.0); } - if (kcd->cur.edge) { + if (kcd->curr.edge) { glColor3ubv(kcd->colors.edge); glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->cur.edge->v1->cageco); - glVertex3fv(kcd->cur.edge->v2->cageco); + glVertex3fv(kcd->curr.edge->v1->cageco); + glVertex3fv(kcd->curr.edge->v2->cageco); glEnd(); glLineWidth(1.0); } - else if (kcd->cur.vert) { + else if (kcd->curr.vert) { glColor3ubv(kcd->colors.point); glPointSize(11); glBegin(GL_POINTS); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); } - if (kcd->cur.bmface) { + if (kcd->curr.bmface) { glColor3ubv(kcd->colors.curpoint); glPointSize(9); glBegin(GL_POINTS); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); } @@ -1113,7 +1182,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, KnifeEdge *kfe = ref->ref; if (BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { - continue; // We already found a hit on this knife edge + continue; /* We already found a hit on this knife edge */ } if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, NULL)) { @@ -1121,13 +1190,17 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); - if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) + if (kcd->curr.vert && len_squared_v3v3(kcd->curr.vert->cageco, p) < depsilon_squared) { continue; - if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) + } + if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) { continue; + } if (len_squared_v3v3(kcd->prev.cage, p) < depsilon_squared || - len_squared_v3v3(kcd->cur.cage, p) < depsilon_squared) + len_squared_v3v3(kcd->curr.cage, p) < depsilon_squared) + { continue; + } knife_project_v3(kcd, p, sp); view3d_unproject(mats, view, sp[0], sp[1], 0.0f); @@ -1135,15 +1208,17 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, if (kcd->cut_through) { hitf = FALSE; - } else { + } + else { /* check if this point is visible in the viewport */ float p1[3], lambda1; /* if face isn't planer, p may be behind the current tesselated tri, - so move it onto that and then a little towards eye */ + * so move it onto that and then a little towards eye */ if (isect_line_tri_v3(p, view, ls[0]->v->co, ls[1]->v->co, ls[2]->v->co, &lambda1, NULL)) { interp_v3_v3v3(p1, p, view, lambda1); - } else { + } + else { copy_v3_v3(p1, p); } sub_v3_v3(view, p1); @@ -1163,9 +1238,11 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { BMEdgeHit hit; - if (len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || + if (len_squared_v3v3(p, kcd->curr.co) < depsilon_squared || len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) + { continue; + } hit.kfe = kfe; hit.v = NULL; @@ -1185,15 +1262,18 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, /* select the closest from the edge endpoints or the midpoint */ if (perc < 0.25f) { perc = 0.0f; - } else if (perc < 0.75f) { + } + else if (perc < 0.75f) { perc = 0.5f; - } else { + } + else { perc = 1.0f; } interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); - } else { + } + else { copy_v3_v3(hit.hit, p); } knife_project_v3(kcd, hit.cagehit, hit.schit); @@ -1239,7 +1319,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) } copy_v3_v3(v1, kcd->prev.cage); - copy_v3_v3(v2, kcd->cur.cage); + copy_v3_v3(v2, kcd->curr.cage); /* project screen line's 3d coordinates back into 2d */ knife_project_v3(kcd, v1, s1); @@ -1435,7 +1515,7 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo copy_v3_v3(p, co); copy_v3_v3(cagep, cageco); - kcd->cur.bmface = f; + kcd->curr.bmface = f; if (f) { KnifeEdge *cure = NULL; @@ -1499,8 +1579,8 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo /* update mouse coordinates to the snapped-to edge's screen coordinates * this is important for angle snap, which uses the previous mouse position */ edgesnap = new_knife_vert(kcd, p, cagep); - kcd->cur.mval[0] = (int)edgesnap->sco[0]; - kcd->cur.mval[1] = (int)edgesnap->sco[1]; + kcd->curr.mval[0] = (int)edgesnap->sco[0]; + kcd->curr.mval[1] = (int)edgesnap->sco[1]; } else { @@ -1532,7 +1612,7 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, p); - kcd->cur.bmface = f; + kcd->curr.bmface = f; if (f) { ListBase *lst; @@ -1583,8 +1663,8 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo /* update mouse coordinates to the snapped-to vertex's screen coordinates * this is important for angle snap, which uses the previous mouse position */ - kcd->cur.mval[0] = (int)curv->sco[0]; - kcd->cur.mval[1] = (int)curv->sco[1]; + kcd->curr.mval[0] = (int)curv->sco[0]; + kcd->curr.mval[1] = (int)curv->sco[1]; } return curv; @@ -1641,30 +1721,30 @@ static int knife_update_active(KnifeTool_OpData *kcd) if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING) knife_snap_angle(kcd); - knife_pos_data_clear(&kcd->cur); - kcd->cur.mval[0] = kcd->vc.mval[0]; - kcd->cur.mval[1] = kcd->vc.mval[1]; + knife_pos_data_clear(&kcd->curr); + kcd->curr.mval[0] = kcd->vc.mval[0]; + kcd->curr.mval[1] = kcd->vc.mval[1]; /* XXX knife_snap_angle updates the view coordinate mouse values to constrained angles, * which current mouse values are set to current mouse values are then used * for vertex and edge snap detection, without regard to the exact angle constraint */ - kcd->cur.vert = knife_find_closest_vert(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + kcd->curr.vert = knife_find_closest_vert(kcd, kcd->curr.co, kcd->curr.cage, &kcd->curr.bmface, &kcd->curr.is_space); - if (!kcd->cur.vert) { - kcd->cur.edge = knife_find_closest_edge(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + if (!kcd->curr.vert) { + kcd->curr.edge = knife_find_closest_edge(kcd, kcd->curr.co, kcd->curr.cage, &kcd->curr.bmface, &kcd->curr.is_space); } /* if no hits are found this would normally default to (0, 0, 0) so instead * get a point at the mouse ray closest to the previous point. * Note that drawing lines in `free-space` isn't properly supported * but theres no guarantee (0, 0, 0) has any geometry either - campbell */ - if (kcd->cur.vert == NULL && kcd->cur.edge == NULL) { + if (kcd->curr.vert == NULL && kcd->curr.edge == NULL) { float origin[3], ray[3], co[3]; knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); add_v3_v3v3(co, origin, ray); - closest_to_line_v3(kcd->cur.cage, kcd->prev.cage, co, origin); + closest_to_line_v3(kcd->curr.cage, kcd->prev.cage, co, origin); } if (kcd->mode == MODE_DRAGGING) { @@ -2872,7 +2952,7 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) /* can't usefully select resulting edges in face mode */ kcd->select_result = (kcd->em->selectmode != SCE_SELECT_FACE); - knife_pos_data_clear(&kcd->cur); + knife_pos_data_clear(&kcd->curr); knife_pos_data_clear(&kcd->prev); knife_init_colors(&kcd->colors); diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 8325e0a50d4..4d4a890300f 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -380,6 +380,7 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) float projectMat[4][4], fmval[3] = {event->mval[0], event->mval[1]}; float dist = FLT_MAX; float d; + int is_wire; BMEditSelection ese; int totboundary_edge = 0; @@ -403,6 +404,8 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) if (!v) return OPERATOR_CANCELLED; + is_wire = BM_vert_is_wire(v); + e2 = NULL; if (v->e) { @@ -430,8 +433,11 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) * - we cant find an edge - this means we are ripping a faces vert that is connected to other * geometry only at the vertex. * - the boundary edge total is greater then 2, - * in this case edge split _can_ work but we get far nicer results if we use this special case. */ - if (totboundary_edge > 2) { + * in this case edge split _can_ work but we get far nicer results if we use this special case. + * - there are only 2 edges but we are a wire vert. */ + if ((is_wire == FALSE && totboundary_edge > 2) || + (is_wire == TRUE && totboundary_edge > 1)) + { BMVert **vout; int vout_len; @@ -458,21 +464,44 @@ static int edbm_rip_invoke__vert(bContext *C, wmOperator *op, wmEvent *event) dist = FLT_MAX; + /* in the loop below we find the best vertex to drag based on its connected geometry, + * either by its face corner, or connected edge (when no faces are attached) */ for (i = 0; i < vout_len; i++) { - BM_ITER_ELEM (l, &iter, vout[i], BM_LOOPS_OF_VERT) { - if (!BM_elem_flag_test(l->f, BM_ELEM_HIDDEN)) { - float l_mid_co[3]; - BM_loop_calc_face_tangent(l, l_mid_co); - /* scale to average of surrounding edge size, only needs to be approx */ - mul_v3_fl(l_mid_co, (BM_edge_calc_length(l->e) + BM_edge_calc_length(l->prev->e)) / 2.0f); - add_v3_v3(l_mid_co, v->co); + if (BM_vert_is_wire(vout[i]) == FALSE) { + /* find the best face corner */ + BM_ITER_ELEM (l, &iter, vout[i], BM_LOOPS_OF_VERT) { + if (!BM_elem_flag_test(l->f, BM_ELEM_HIDDEN)) { + float l_mid_co[3]; + BM_loop_calc_face_tangent(l, l_mid_co); + + /* scale to average of surrounding edge size, only needs to be approx, but should + * be roughly equivalent to the check below which uses the middle of the edge. */ + mul_v3_fl(l_mid_co, (BM_edge_calc_length(l->e) + BM_edge_calc_length(l->prev->e)) / 2.0f); + add_v3_v3(l_mid_co, v->co); - d = edbm_rip_rip_edgedist(ar, projectMat, v->co, l_mid_co, fmval); + d = edbm_rip_rip_edgedist(ar, projectMat, v->co, l_mid_co, fmval); - if (d < dist) { - dist = d; - vi_best = i; + if (d < dist) { + dist = d; + vi_best = i; + } + } + } + } + else { + /* a wire vert, find the best edge */ + BM_ITER_ELEM (e, &iter, vout[i], BM_EDGES_OF_VERT) { + if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { + float e_mid_co[3]; + mid_v3_v3v3(e_mid_co, e->v1->co, e->v2->co); + + d = edbm_rip_rip_edgedist(ar, projectMat, v->co, e_mid_co, fmval); + + if (d < dist) { + dist = d; + vi_best = i; + } } } } diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index c50726ca9c2..de9b3c5ba05 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -268,11 +268,14 @@ int EDBM_backbuf_border_mask_init(ViewContext *vc, int mcords[][2], short tot, s /* grab mask */ bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); - drm = bufmask->rect; + if (bufmask == NULL) { return 0; /* only when mem alloc fails, go crash somewhere else! */ } - + else { + drm = bufmask->rect; + } + /* build selection lookup */ selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); @@ -1504,7 +1507,7 @@ void MESH_OT_select_shortest_path(wmOperatorType *ot) /* ************************************************** */ /* here actual select happens */ /* gets called via generic mouse select operator */ -int mouse_mesh(bContext *C, const int mval[2], short extend, short deselect, short toggle) +int EDBM_select_pick(bContext *C, const int mval[2], short extend, short deselect, short toggle) { ViewContext vc; BMVert *eve = NULL; @@ -2231,7 +2234,7 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed, } } else if (em->selectmode & SCE_SELECT_FACE) { - f = BM_active_face_get(em->bm, TRUE); + f = BM_active_face_get(em->bm, TRUE, FALSE); if (f) { *r_efa = f; return; @@ -2306,8 +2309,7 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) view3d_set_viewcontext(C, vc); if (vc->obedit) { - Mesh *me = vc->obedit->data; - vc->em = me->edit_btmesh; + vc->em = BMEdit_FromObject(vc->obedit); } } @@ -2332,25 +2334,19 @@ static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op) BMIter iter; BMEdge *e; BMLoop *l1, *l2; - float sharp = RNA_float_get(op->ptr, "sharpness"), angle; + const float sharp = RNA_float_get(op->ptr, "sharpness"); BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) || !e->l) - continue; - - l1 = e->l; - l2 = l1->radial_next; - - if (l1 == l2) - continue; - - /* edge has exactly two neighboring faces, check angle */ - angle = angle_normalized_v3v3(l1->f->no, l2->f->no); + if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) == FALSE && + BM_edge_loop_pair(e, &l1, &l2)) + { + /* edge has exactly two neighboring faces, check angle */ + const float angle = angle_normalized_v3v3(l1->f->no, l2->f->no); - if (fabsf(angle) < sharp) { - BM_edge_select_set(em->bm, e, TRUE); + if (fabsf(angle) > sharp) { + BM_edge_select_set(em->bm, e, TRUE); + } } - } WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); @@ -2377,7 +2373,7 @@ void MESH_OT_edges_select_sharp(wmOperatorType *ot) /* props */ prop = RNA_def_float_rotation(ot->srna, "sharpness", 0, NULL, DEG2RADF(0.01f), DEG2RADF(180.0f), "Sharpness", "", DEG2RADF(1.0f), DEG2RADF(180.0f)); - RNA_def_property_float_default(prop, DEG2RADF(1.0f)); + RNA_def_property_float_default(prop, DEG2RADF(30.0f)); } static int edbm_select_linked_flat_faces_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/mesh/editmesh_slide.c b/source/blender/editors/mesh/editmesh_slide.c index f08c229d38a..86ea5bc8651 100644 --- a/source/blender/editors/mesh/editmesh_slide.c +++ b/source/blender/editors/mesh/editmesh_slide.c @@ -27,6 +27,7 @@ /* Takes heavily from editmesh_loopcut.c */ #include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "MEM_guardedalloc.h" @@ -99,7 +100,7 @@ typedef struct VertexSlideOp { } VertexSlideOp; static void vtx_slide_draw(const bContext *C, ARegion *ar, void *arg); -static int edbm_vertex_slide_exec(bContext *C, wmOperator *op); +static int edbm_vertex_slide_exec_ex(bContext *C, wmOperator *op, const int do_update); static void vtx_slide_exit(const bContext *C, wmOperator *op); static int vtx_slide_set_frame(VertexSlideOp *vso); @@ -195,16 +196,38 @@ static void vtx_slide_confirm(bContext *C, wmOperator *op) VertexSlideOp *vso = op->customdata; BMEditMesh *em = BMEdit_FromObject(vso->obj); BMesh *bm = em->bm; + BMVert *other = NULL; + + BMVert *mirr_vtx = NULL; + BMVert *mirr_vtx_other = NULL; /* Select new edge */ BM_edge_select_set(bm, vso->sel_edge, TRUE); - /* Invoke operator */ - edbm_vertex_slide_exec(C, op); + if (vso->snap_n_merge) { + other = BM_edge_other_vert(vso->sel_edge, vso->start_vtx); + } + + if (((Mesh *)em->ob->data)->editflag & ME_EDIT_MIRROR_X) { + EDBM_verts_mirror_cache_begin(em, TRUE); + + mirr_vtx = EDBM_verts_mirror_get(em, vso->start_vtx); + if (vso->snap_n_merge) { + mirr_vtx_other = EDBM_verts_mirror_get(em, other); + } + } + + /* Invoke operator - warning */ + edbm_vertex_slide_exec_ex(C, op, FALSE); + + if (mirr_vtx) { + mirr_vtx->co[0] = -vso->start_vtx->co[0]; + mirr_vtx->co[1] = vso->start_vtx->co[1]; + mirr_vtx->co[2] = vso->start_vtx->co[2]; + } if (vso->snap_n_merge) { float other_d; - BMVert *other = BM_edge_other_vert(vso->sel_edge, vso->start_vtx); other_d = len_v3v3(vso->interp, other->co); /* Only snap if within threshold */ @@ -213,6 +236,13 @@ static void vtx_slide_confirm(bContext *C, wmOperator *op) BM_vert_select_set(bm, vso->start_vtx, TRUE); EDBM_op_callf(em, op, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, other->co); EDBM_flag_disable_all(em, BM_ELEM_SELECT); + + if (mirr_vtx_other) { + BM_vert_select_set(bm, mirr_vtx, TRUE); + BM_vert_select_set(bm, mirr_vtx_other, TRUE); + EDBM_op_callf(em, op, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, mirr_vtx_other->co); + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + } } else { /* Store in historty if not merging */ @@ -225,6 +255,10 @@ static void vtx_slide_confirm(bContext *C, wmOperator *op) BM_select_history_store(em->bm, vso->start_vtx); } + if (((Mesh *)em->ob->data)->editflag & ME_EDIT_MIRROR_X) { + EDBM_verts_mirror_cache_end(em); + } + EDBM_selectmode_flush(em); /* NC_GEOM | ND_DATA & Retess */ @@ -644,7 +678,7 @@ static int edbm_vertex_slide_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED } /* Vertex Slide */ -static int edbm_vertex_slide_exec(bContext *C, wmOperator *op) +static int edbm_vertex_slide_exec_ex(bContext *C, wmOperator *op, const int do_update) { Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); @@ -708,12 +742,21 @@ static int edbm_vertex_slide_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* Update Geometry */ - EDBM_update_generic(C, em, TRUE); + if (do_update) { + /* Update Geometry */ + EDBM_update_generic(C, em, TRUE); + } return OPERATOR_FINISHED; } +#if 0 +static int edbm_vertex_slide_exec(bContext *C, wmOperator *op) +{ + return edbm_vertex_slide_exec_ex(C, op, TRUE); +} +#endif + void MESH_OT_vert_slide(wmOperatorType *ot) { PropertyRNA *prop; diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 91c76ffd6fd..9e83742a909 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -751,10 +751,8 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent float nor[3] = {0.0, 0.0, 0.0}; /* 2D normal calc */ - float mval_f[2]; - - mval_f[0] = (float)event->mval[0]; - mval_f[1] = (float)event->mval[1]; + const float mval_f[2] = {(float)event->mval[0], + (float)event->mval[1]}; /* check for edges that are half selected, use for rotation */ done = FALSE; diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 6b7409cd031..03e2f2691a8 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -345,7 +345,6 @@ void EDBM_mesh_make(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) me->edit_btmesh->selectmode = me->edit_btmesh->bm->selectmode = ts->selectmode; me->edit_btmesh->mat_nr = (ob->actcol > 0) ? ob->actcol - 1 : 0; - me->edit_btmesh->me = me; me->edit_btmesh->ob = ob; } @@ -580,6 +579,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *em_v, void *UNUSED(obdata)) *em = *em_tmp; em->selectmode = um->selectmode; + bm->selectmode = um->selectmode; em->ob = ob; MEM_freeN(em_tmp); @@ -991,15 +991,15 @@ void EDBM_uv_element_map_free(UvElementMap *element_map) /* last_sel, use em->act_face otherwise get the last selected face in the editselections * at the moment, last_sel is mainly useful for making sure the space image dosnt flicker */ -MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy) +MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy, int selected) { BMFace *efa = NULL; if (!EDBM_mtexpoly_check(em)) return NULL; - efa = BM_active_face_get(em->bm, sloppy); - + efa = BM_active_face_get(em->bm, sloppy, selected); + if (efa) { if (r_act_efa) *r_act_efa = efa; return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); @@ -1055,14 +1055,14 @@ static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index) #define BM_CD_LAYER_ID "__mirror_index" void EDBM_verts_mirror_cache_begin(BMEditMesh *em, const short use_select) { - Mesh *me = em->me; + Mesh *me = (Mesh *)em->ob->data; BMesh *bm = em->bm; BMIter iter; BMVert *v; int li, topo = 0; /* one or the other is used depending if topo is enabled */ - BMBVHTree *tree = NULL; + struct BMBVHTree *tree = NULL; MirrTopoStore_t mesh_topo_store = {NULL, -1, -1, -1}; if (me && (me->editflag & ME_EDIT_MIRROR_TOPO)) { diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 19ca30b9c45..09d89a961e4 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -43,10 +43,10 @@ #include "DNA_view3d_types.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "BLI_array.h" #include "BLI_math.h" #include "BLI_edgehash.h" -#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_depsgraph.h" diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index ee74cea48af..aed57141c2a 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -85,8 +85,6 @@ float labda_PdistVL2Dfl(const float v1[3], const float v2[3], const float v3[3]) /* ******************** editface.c */ -void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc); - void MESH_OT_separate(struct wmOperatorType *ot); /* ******************* editmesh_add.c */ diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index 14d20d68455..88b1f191e3a 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -491,7 +491,7 @@ static int navmesh_face_copy_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); /* do work here */ - BMFace *efa_act = BM_active_face_get(em->bm, FALSE); + BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); if (efa_act) { if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) { diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 2e75a779fed..a7467ee4c79 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -42,6 +42,7 @@ #include "MEM_guardedalloc.h" #include "DNA_mesh_types.h" +#include "DNA_view3d_types.h" #include "DNA_key_types.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" @@ -441,18 +442,20 @@ int join_mesh_exec(bContext *C, wmOperator *op) } if (me->totpoly) { - /* make mapping for materials */ - for (a = 1; a <= base->object->totcol; a++) { - ma = give_current_material(base->object, a); + if (totmat) { + /* make mapping for materials */ + for (a = 1; a <= base->object->totcol; a++) { + ma = give_current_material(base->object, a); - for (b = 0; b < totcol; b++) { - if (ma == matar[b]) { - matmap[a - 1] = b; - break; + for (b = 0; b < totcol; b++) { + if (ma == matar[b]) { + matmap[a - 1] = b; + break; + } } } } - + CustomData_merge(&me->pdata, &pdata, CD_MASK_MESH, CD_DEFAULT, totpoly); CustomData_copy_data(&me->pdata, &pdata, 0, polyofs, me->totpoly); @@ -877,7 +880,7 @@ intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, const float co[3], char m return 0; } -MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; +static MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; /* mode is 's' start, or 'e' end, or 'u' use */ /* if end, ob can be NULL */ @@ -1146,3 +1149,125 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em) return mirrorfaces; } + +/* selection, vertex and face */ +/* returns 0 if not found, otherwise 1 */ + +/** + * Face selection in object mode, + * currently only weight-paint and vertex-paint use this. + * + * \return boolean TRUE == Found + */ +int ED_mesh_pick_face(bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) +{ + ViewContext vc; + + if (!me || me->totpoly == 0) + return 0; + + view3d_set_viewcontext(C, &vc); + + if (size) { + /* sample rect to increase chances of selecting, so that when clicking + * on an edge in the backbuf, we can still select a face */ + + int dummy_dist; + *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totpoly + 1, &dummy_dist, 0, NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index) <= 0 || (*index) > (unsigned int)me->totpoly) + return 0; + + (*index)--; + + return 1; +} +/** + * Use when the back buffer stores face index values. but we want a vert. + * This gets the face then finds the closest vertex to mval. + */ +int ED_mesh_pick_face_vert(bContext *C, Mesh *me, Object *ob, const int mval[2], unsigned int *index, int size) +{ + unsigned int poly_index; + + if (ED_mesh_pick_face(C, me, mval, &poly_index, size)) { + Scene *scene = CTX_data_scene(C); + struct ARegion *ar = CTX_wm_region(C); + + /* derived mesh to find deformed locations */ + DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + int v_idx_best = -1; + + if (dm->getVertCo) { + /* find the vert closest to 'mval' */ + const float mval_f[2] = {(float)mval[0], + (float)mval[1]}; + MPoly *mp = &me->mpoly[poly_index]; + int fidx; + float len_best = FLT_MAX; + + fidx = mp->totloop - 1; + do { + float co[3], sco[2], len; + const int v_idx = me->mloop[mp->loopstart + fidx].v; + dm->getVertCo(dm, v_idx, co); + mul_m4_v3(ob->obmat, co); + project_float_noclip(ar, co, sco); + len = len_squared_v2v2(mval_f, sco); + if (len < len_best) { + len_best = len; + v_idx_best = v_idx; + } + } while (fidx--); + } + + dm->release(dm); + + if (v_idx_best != -1) { + *index = v_idx_best; + return 1; + } + } + + return 0; +} + +/** + * Vertex selection in object mode, + * currently only weight paint uses this. + * + * \return boolean TRUE == Found + */ +int ED_mesh_pick_vert(bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) +{ + ViewContext vc; + + if (!me || me->totvert == 0) + return 0; + + view3d_set_viewcontext(C, &vc); + + if (size > 0) { + /* sample rect to increase chances of selecting, so that when clicking + * on an face in the backbuf, we can still select a vert */ + + int dummy_dist; + *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totvert + 1, &dummy_dist, 0, NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index) <= 0 || (*index) > (unsigned int)me->totvert) + return 0; + + (*index)--; + + return 1; +} diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index 59cc782f3eb..f9b73a56403 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -1347,6 +1347,8 @@ static void init_bake_internal(BakeRender *bkr, bContext *C) static void finish_bake_internal(BakeRender *bkr) { + Image *ima; + RE_Database_Free(bkr->re); /* restore raytrace and AO */ @@ -1358,26 +1360,29 @@ static void finish_bake_internal(BakeRender *bkr) if (bkr->prev_r_raytrace == 0) bkr->scene->r.mode &= ~R_RAYTRACE; - if (bkr->result == BAKE_RESULT_OK) { - Image *ima; - /* force OpenGL reload and mipmap recalc */ - for (ima = G.main->image.first; ima; ima = ima->id.next) { + + /* force OpenGL reload and mipmap recalc */ + for (ima = G.main->image.first; ima; ima = ima->id.next) { + ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL); + + if (bkr->result == BAKE_RESULT_OK) { if (ima->ok == IMA_OK_LOADED) { - ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL); if (ibuf) { if (ibuf->userflags & IB_BITMAPDIRTY) { GPU_free_image(ima); imb_freemipmapImBuf(ibuf); } - - /* freed when baking is done, but if its canceled we need to free here */ - if (ibuf->userdata) { - MEM_freeN(ibuf->userdata); - ibuf->userdata = NULL; - } } } } + + /* freed when baking is done, but if its canceled we need to free here */ + if (ibuf) { + if (ibuf->userdata) { + MEM_freeN(ibuf->userdata); + ibuf->userdata = NULL; + } + } } } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index be25c79ba25..1ef7c12b409 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -1185,7 +1185,7 @@ void POSE_OT_constraints_clear(wmOperatorType *ot) /* callbacks */ ot->exec = pose_constraints_clear_exec; - ot->poll = ED_operator_posemode; // XXX - do we want to ensure there are selected bones too? + ot->poll = ED_operator_posemode_exclusive; // XXX - do we want to ensure there are selected bones too? } @@ -1266,7 +1266,7 @@ void POSE_OT_constraints_copy(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_constraint_copy_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1392,9 +1392,9 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o /* just use the first object we encounter (that isn't the active object) * and which fulfills the criteria for the object-target that we've got */ - if ( (ob != obact) && - ((!only_curve) || (ob->type == OB_CURVE)) && - ((!only_mesh) || (ob->type == OB_MESH)) ) + if ((ob != obact) && + ((!only_curve) || (ob->type == OB_CURVE)) && + ((!only_mesh) || (ob->type == OB_MESH))) { /* set target */ *tar_ob = ob; @@ -1478,15 +1478,15 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase if (type == CONSTRAINT_TYPE_NULL) { return OPERATOR_CANCELLED; } - if ( (type == CONSTRAINT_TYPE_RIGIDBODYJOINT) && (list != &ob->constraints) ) { + if ((type == CONSTRAINT_TYPE_RIGIDBODYJOINT) && (list != &ob->constraints)) { BKE_report(op->reports, RPT_ERROR, "Rigid Body Joint Constraint can only be added to Objects"); return OPERATOR_CANCELLED; } - if ( (type == CONSTRAINT_TYPE_KINEMATIC) && ((!pchan) || (list != &pchan->constraints)) ) { + if ((type == CONSTRAINT_TYPE_KINEMATIC) && ((!pchan) || (list != &pchan->constraints))) { BKE_report(op->reports, RPT_ERROR, "IK Constraint can only be added to Bones"); return OPERATOR_CANCELLED; } - if ( (type == CONSTRAINT_TYPE_SPLINEIK) && ((!pchan) || (list != &pchan->constraints)) ) { + if ((type == CONSTRAINT_TYPE_SPLINEIK) && ((!pchan) || (list != &pchan->constraints))) { BKE_report(op->reports, RPT_ERROR, "Spline IK Constraint can only be added to Bones"); return OPERATOR_CANCELLED; } @@ -1661,7 +1661,7 @@ void POSE_OT_constraint_add(wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_menu_invoke; ot->exec = pose_constraint_add_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1680,7 +1680,7 @@ void POSE_OT_constraint_add_with_targets(wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_menu_invoke; ot->exec = pose_constraint_add_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1766,7 +1766,7 @@ void POSE_OT_ik_add(wmOperatorType *ot) /* api callbacks */ ot->invoke = pose_ik_add_invoke; ot->exec = pose_ik_add_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1816,7 +1816,7 @@ void POSE_OT_ik_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_ik_clear_exec; - ot->poll = ED_operator_posemode; + ot->poll = ED_operator_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 2b1492aa732..4858fdf1c35 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -1658,7 +1658,7 @@ static int skin_radii_equalize_exec(bContext *C, wmOperator *UNUSED(op)) void OBJECT_OT_skin_radii_equalize(wmOperatorType *ot) { ot->name = "Skin Radii Equalize"; - ot->description = "Make skin radii of selected vertices equal"; + ot->description = "Make skin radii of selected vertices equal on each axis"; ot->idname = "OBJECT_OT_skin_radii_equalize"; ot->poll = skin_edit_poll; diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index d8c964ff2df..cafc7ce9300 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1518,7 +1518,7 @@ static void single_object_users(Scene *scene, View3D *v3d, int flag) */ ob->id.newid = NULL; - if ( (base->flag & flag) == flag) { + if ((base->flag & flag) == flag) { if (ob->id.lib == NULL && ob->id.us > 1) { /* base gets copy of object */ obn = BKE_object_copy(ob); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c4616fc39c6..b31d2b8b076 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -62,6 +62,7 @@ #include "BKE_tessmesh.h" #include "BKE_report.h" #include "BKE_DerivedMesh.h" +#include "BKE_object_deform.h" #include "RNA_access.h" #include "RNA_define.h" @@ -1136,7 +1137,6 @@ static void vgroup_levels(Object *ob, float offset, float gain) } } -/* TODO - select between groups */ static void vgroup_normalize_all(Object *ob, int lock_active) { MDeformVert *dv, **dvert_array = NULL; @@ -1152,29 +1152,35 @@ static void vgroup_normalize_all(Object *ob, int lock_active) ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, use_vert_sel); if (dvert_array) { - if (lock_active) { + const int defbase_tot = BLI_countlist(&ob->defbase); + char *lock_flags = BKE_objdef_lock_flags_get(ob, defbase_tot); - for (i = 0; i < dvert_tot; i++) { - /* in case its not selected */ - if (!(dv = dvert_array[i])) { - continue; - } - - defvert_normalize_lock(dv, def_nr); - } + if ((lock_active == TRUE) && + (lock_flags != NULL) && + (def_nr < defbase_tot)) + { + lock_flags[def_nr] = TRUE; } - else { - for (i = 0; i < dvert_tot; i++) { - /* in case its not selected */ - if (!(dv = dvert_array[i])) { - continue; + for (i = 0; i < dvert_tot; i++) { + /* in case its not selected */ + if ((dv = dvert_array[i])) { + if (lock_flags) { + defvert_normalize_lock_map(dv, lock_flags, defbase_tot); + } + else if (lock_active) { + defvert_normalize_lock_single(dv, def_nr); + } + else { + defvert_normalize(dv); } - - defvert_normalize(dv); } } + if (lock_flags) { + MEM_freeN(lock_flags); + } + MEM_freeN(dvert_array); } } @@ -1536,8 +1542,8 @@ void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_v int *flip_map, flip_map_len; const int def_nr = ob->actdef - 1; - if ( (mirror_weights == 0 && flip_vgroups == 0) || - (BLI_findlink(&ob->defbase, def_nr) == NULL) ) + if ((mirror_weights == 0 && flip_vgroups == 0) || + (BLI_findlink(&ob->defbase, def_nr) == NULL)) { return; } @@ -1682,6 +1688,10 @@ void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_v } } + /* flip active group index */ + if (flip_vgroups && flip_map[def_nr] >= 0) + ob->actdef = flip_map[def_nr] + 1; + cleanup: if (flip_map) MEM_freeN(flip_map); @@ -1782,6 +1792,21 @@ static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg) if (ob->actdef < 1 && ob->defbase.first) ob->actdef = 1; + /* remove all dverts */ + if (ob->defbase.first == NULL) { + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert); + me->dvert = NULL; + } + else if (ob->type == OB_LATTICE) { + Lattice *lt = ob->data; + if (lt->dvert) { + MEM_freeN(lt->dvert); + lt->dvert = NULL; + } + } + } } /* only in editmode */ @@ -2674,7 +2699,7 @@ void OBJECT_OT_vertex_group_mirror(wmOperatorType *ot) /* properties */ RNA_def_boolean(ot->srna, "mirror_weights", TRUE, "Mirror Weights", "Mirror weights"); - RNA_def_boolean(ot->srna, "flip_group_names", TRUE, "Flip Groups", "Flip vertex group names"); + RNA_def_boolean(ot->srna, "flip_group_names", TRUE, "Flip Group Names", "Flip vertex group names"); RNA_def_boolean(ot->srna, "all_groups", FALSE, "All Groups", "Mirror all vertex groups weights"); } diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 72d2d67e081..b7ce32aa10a 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3540,7 +3540,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) switch (pset->brushtype) { case PE_BRUSH_COMB: { - float mval_f[2]; + const float mval_f[2] = {dx, dy}; data.mval= mval; data.rad= (float)brush->size; @@ -3552,8 +3552,6 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) invert_m4_m4(ob->imat, ob->obmat); - mval_f[0]= dx; - mval_f[1]= dy; ED_view3d_win_to_delta(ar, mval_f, vec); data.dvec= vec; @@ -4137,7 +4135,7 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, if (cache && cache->flag & PTCACHE_DISK_CACHE) return; - if (psys == NULL && cache->mem_cache.first == NULL) + if (psys == NULL && (cache && cache->mem_cache.first == NULL)) return; if (!edit) { diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index b57500df719..a17d84af128 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -98,12 +98,14 @@ void OBJECT_OT_particle_system_add(wmOperatorType *ot) static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob= ED_object_context(C); + Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); - int mode_orig = ob->mode; + int mode_orig; + if (!scene || !ob) return OPERATOR_CANCELLED; + mode_orig = ob->mode; object_remove_particle_system(scene, ob); /* possible this isn't the active object diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index add2cbd566b..068a7aaa50a 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -788,7 +788,7 @@ static void shader_preview_free(void *customdata) /* get rid of copied world */ BLI_remlink(&pr_main->world, sp->worldcopy); - BKE_world_free(sp->worldcopy); + BKE_world_free_ex(sp->worldcopy, FALSE); properties = IDP_GetProperties((ID *)sp->worldcopy, FALSE); if (properties) { diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 967c6e85590..c93f4156eeb 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -298,13 +298,13 @@ void setlinestyle(int nr) /* Invert line handling */ -#define gl_toggle(mode, onoff) (((onoff) ? glEnable : glDisable)(mode)) +#define GL_TOGGLE(mode, onoff) (((onoff) ? glEnable : glDisable)(mode)) void set_inverted_drawing(int enable) { glLogicOp(enable ? GL_INVERT : GL_COPY); - gl_toggle(GL_COLOR_LOGIC_OP, enable); - gl_toggle(GL_DITHER, !enable); + GL_TOGGLE(GL_COLOR_LOGIC_OP, enable); + GL_TOGGLE(GL_DITHER, !enable); } void sdrawXORline(int x0, int y0, int x1, int y1) diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index adffb97c16f..11d32e11cd0 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1471,7 +1471,7 @@ void ED_screen_set_scene(bContext *C, bScreen *screen, Scene *scene) /* are there cameras in the views that are not in the scene? */ for (sc = CTX_data_main(C)->screen.first; sc; sc = sc->id.next) { - if ( (U.flag & USER_SCENEGLOBAL) || sc == screen) { + if ((U.flag & USER_SCENEGLOBAL) || sc == screen) { ScrArea *sa = sc->areabase.first; while (sa) { SpaceLink *sl = sa->spacedata.first; @@ -1767,12 +1767,22 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, sad->ar = CTX_wm_region(C); /* if startframe is larger than current frame, we put currentframe on startframe. * note: first frame then is not drawn! (ton) */ - if (scene->r.sfra > scene->r.cfra) { - sad->sfra = scene->r.cfra; - scene->r.cfra = scene->r.sfra; + if (PRVRANGEON) { + if (scene->r.psfra > scene->r.cfra) { + sad->sfra = scene->r.cfra; + scene->r.cfra = scene->r.psfra; + } + else + sad->sfra = scene->r.cfra; + } + else { + if (scene->r.sfra > scene->r.cfra) { + sad->sfra = scene->r.cfra; + scene->r.cfra = scene->r.sfra; + } + else + sad->sfra = scene->r.cfra; } - else - sad->sfra = scene->r.cfra; sad->redraws = redraws; sad->refresh = refresh; sad->flag |= (enable < 0) ? ANIMPLAY_FLAG_REVERSE : 0; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 823037a7903..50a210e5d7c 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -349,6 +349,29 @@ int ED_operator_editarmature(bContext *C) return 0; } +/** + * \brief check for pose mode (no mixed modes) + * + * We wan't to enable most pose operations in weight paint mode, + * when it comes to transforming bones, but managing bomes layers/groups + * can be left for pose mode only. (not weight paint mode) + */ +int ED_operator_posemode_exclusive(bContext *C) +{ + Object *obact = CTX_data_active_object(C); + + if (obact && !(obact->mode & OB_MODE_EDIT)) { + Object *obpose; + if ((obpose = BKE_object_pose_armature_get(obact))) { + if (obact == obpose) { + return 1; + } + } + } + + return 0; +} + int ED_operator_posemode(bContext *C) { Object *obact = CTX_data_active_object(C); @@ -1347,12 +1370,12 @@ static int area_split_invoke(bContext *C, wmOperator *op, wmEvent *event) if (event->type == EVT_ACTIONZONE_AREA) { sActionzoneData *sad = event->customdata; - if (sad->modifier > 0) { + if (sad == NULL || sad->modifier > 0) { return OPERATOR_PASS_THROUGH; } /* verify *sad itself */ - if (sad == NULL || sad->sa1 == NULL || sad->az == NULL) + if (sad->sa1 == NULL || sad->az == NULL) return OPERATOR_PASS_THROUGH; /* is this our *sad? if areas not equal it should be passed on */ @@ -2261,12 +2284,12 @@ static int area_join_invoke(bContext *C, wmOperator *op, wmEvent *event) if (event->type == EVT_ACTIONZONE_AREA) { sActionzoneData *sad = event->customdata; - if (sad->modifier > 0) { + if (sad == NULL || sad->modifier > 0) { return OPERATOR_PASS_THROUGH; } /* verify *sad itself */ - if (sad == NULL || sad->sa1 == NULL || sad->sa2 == NULL) + if (sad->sa1 == NULL || sad->sa2 == NULL) return OPERATOR_PASS_THROUGH; /* is this our *sad? if areas equal it should be passed on */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 953215b83aa..7c3f376df91 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1410,24 +1410,46 @@ static float project_paint_uvpixel_mask( /* calculate mask */ if (ps->do_mask_normal) { - MFace *mf = ps->dm_mface + face_index; - short *no1, *no2, *no3; + MFace *mf = &ps->dm_mface[face_index]; float no[3], angle; - no1 = ps->dm_mvert[mf->v1].no; - if (side == 1) { - no2 = ps->dm_mvert[mf->v3].no; - no3 = ps->dm_mvert[mf->v4].no; + if (mf->flag & ME_SMOOTH) { + short *no1, *no2, *no3; + no1 = ps->dm_mvert[mf->v1].no; + if (side == 1) { + no2 = ps->dm_mvert[mf->v3].no; + no3 = ps->dm_mvert[mf->v4].no; + } + else { + no2 = ps->dm_mvert[mf->v2].no; + no3 = ps->dm_mvert[mf->v3].no; + } + + no[0] = w[0] * no1[0] + w[1] * no2[0] + w[2] * no3[0]; + no[1] = w[0] * no1[1] + w[1] * no2[1] + w[2] * no3[1]; + no[2] = w[0] * no1[2] + w[1] * no2[2] + w[2] * no3[2]; + normalize_v3(no); } else { - no2 = ps->dm_mvert[mf->v2].no; - no3 = ps->dm_mvert[mf->v3].no; + /* incase the */ +#if 1 + /* normalizing per pixel isn't optimal, we could cache or check ps->*/ + if (mf->v4) + normal_quad_v3(no, + ps->dm_mvert[mf->v1].co, + ps->dm_mvert[mf->v2].co, + ps->dm_mvert[mf->v3].co, + ps->dm_mvert[mf->v4].co); + else + normal_tri_v3(no, + ps->dm_mvert[mf->v1].co, + ps->dm_mvert[mf->v2].co, + ps->dm_mvert[mf->v3].co); +#else + /* don't use because some modifiers dont have normal data (subsurf for eg) */ + copy_v3_v3(no, (float *)ps->dm->getTessFaceData(ps->dm, face_index, CD_NORMAL)); +#endif } - no[0] = w[0] * no1[0] + w[1] * no2[0] + w[2] * no3[0]; - no[1] = w[0] * no1[1] + w[1] * no2[1] + w[2] * no3[1]; - no[2] = w[0] * no1[2] + w[1] * no2[2] + w[2] * no3[2]; - normalize_v3(no); - /* now we can use the normal as a mask */ if (ps->is_ortho) { angle = angle_normalized_v3v3((float *)ps->viewDir, no); @@ -3695,7 +3717,7 @@ typedef struct ProjectHandle { int thread_index; } ProjectHandle; -static void blend_color_mix(unsigned char *cp, const unsigned char *cp1, const unsigned char *cp2, const int fac) +static void blend_color_mix(unsigned char cp[4], const unsigned char cp1[4], const unsigned char cp2[4], const int fac) { /* this and other blending modes previously used >>8 instead of /255. both * are not equivalent (>>8 is /256), and the former results in rounding @@ -3708,7 +3730,7 @@ static void blend_color_mix(unsigned char *cp, const unsigned char *cp1, const u cp[3] = (mfac * cp1[3] + fac * cp2[3]) / 255; } -static void blend_color_mix_float(float *cp, const float *cp1, const float *cp2, const float fac) +static void blend_color_mix_float(float cp[4], const float cp1[4], const float cp2[4], const float fac) { const float mfac = 1.0f - fac; cp[0] = mfac * cp1[0] + fac * cp2[0]; @@ -5334,12 +5356,25 @@ static void toggle_paint_cursor(bContext *C, int enable) * ensure that the cursor is hidden when not in paint mode */ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings) { + wmWindow *win; + ScrArea *sa; ImagePaintSettings *imapaint = &settings->imapaint; + int enabled = FALSE; - if (!imapaint->paintcursor) { - imapaint->paintcursor = - WM_paint_cursor_activate(wm, image_paint_poll, - brush_drawcursor, NULL); + for (win = wm->windows.first; win; win = win->next) + for (sa = win->screen->areabase.first; sa; sa = sa->next) + if (sa->spacetype == SPACE_IMAGE) + if (((SpaceImage*)sa->spacedata.first)->mode == SI_MODE_PAINT) + enabled = TRUE; + + if (enabled) { + BKE_paint_init(&imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT); + + if (!imapaint->paintcursor) { + imapaint->paintcursor = + WM_paint_cursor_activate(wm, image_paint_poll, + brush_drawcursor, NULL); + } } } diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 104f727c603..cc71be4938e 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -584,19 +584,21 @@ static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *p RCFlags flags) { wmKeyMapItem *kmi; + /* only size needs to follow zoom, strength shows fixed size circle */ + int flags_nozoom = flags & (~RC_ZOOM); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0); set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0); - set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags); + set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags_nozoom); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", WKEY, KM_PRESS, 0, 0); - set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags); + set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags_nozoom); if (flags & RC_ROTATION) { kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0); - set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags); + set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags_nozoom); } } diff --git a/source/blender/editors/sculpt_paint/paint_undo.c b/source/blender/editors/sculpt_paint/paint_undo.c index 8e6c87c1510..f5b9aa742c6 100644 --- a/source/blender/editors/sculpt_paint/paint_undo.c +++ b/source/blender/editors/sculpt_paint/paint_undo.c @@ -23,7 +23,6 @@ * \brief Undo system for painting and sculpting. */ - #include <stdlib.h> #include <string.h> @@ -35,7 +34,7 @@ #include "DNA_userdef_types.h" - +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_global.h" @@ -43,11 +42,9 @@ #include "paint_intern.h" -#define MAXUNDONAME 64 - typedef struct UndoElem { struct UndoElem *next, *prev; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; uintptr_t undosize; ListBase elems; @@ -272,4 +269,3 @@ void ED_undo_paint_free(void) undo_stack_free(&ImageUndoStack); undo_stack_free(&MeshUndoStack); } - diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 99bc192042c..df64e1c9d90 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -159,14 +159,12 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3], { Object *ob = vc->obact; float delta[3], scale, loc[3]; - float mval_f[2]; + const float mval_f[2] = {pixel_radius, 0.0f}; mul_v3_m4v3(loc, ob->obmat, center); initgrabz(vc->rv3d, loc[0], loc[1], loc[2]); - mval_f[0] = pixel_radius; - mval_f[1] = 0.0f; ED_view3d_win_to_delta(vc->ar, mval_f, delta); scale = fabsf(mat4_to_scale(ob->obmat)); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 3c389f97b34..ba440e98290 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -72,6 +72,7 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_object.h" +#include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_report.h" @@ -1008,52 +1009,34 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, wmEvent *event) me = BKE_mesh_from_object(vc.obact); if (me && me->dvert && vc.v3d && vc.rv3d) { - int index; + const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + int v_idx_best = -1; + unsigned int index; view3d_operator_needs_opengl(C); - index = view3d_sample_backbuf(&vc, event->mval[0], event->mval[1]); - - if (index && index <= me->totpoly) { - DerivedMesh *dm = mesh_get_derived_final(vc.scene, vc.obact, CD_MASK_BAREMESH); - - if (dm->getVertCo == NULL) { + if (use_vert_sel) { + if (ED_mesh_pick_vert(C, me, event->mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE)) { + v_idx_best = index; + } + } + else { + if (ED_mesh_pick_face_vert(C, me, vc.obact, event->mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + v_idx_best = index; + } + else if (ED_mesh_pick_face(C, me, event->mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + /* this relies on knowning the internal worksings of ED_mesh_pick_face_vert() */ BKE_report(op->reports, RPT_WARNING, "The modifier used does not support deformed locations"); } - else { - MPoly *mp = ((MPoly *)me->mpoly) + (index - 1); - const int vgroup_active = vc.obact->actdef - 1; - Scene *scene = vc.scene; - ToolSettings *ts = vc.scene->toolsettings; - Brush *brush = paint_brush(&ts->wpaint->paint); - float mval_f[2]; - int v_idx_best = -1; - int fidx; - float len_best = FLT_MAX; - - mval_f[0] = (float)event->mval[0]; - mval_f[1] = (float)event->mval[1]; - - fidx = mp->totloop - 1; - do { - float co[3], sco[3], len; - const int v_idx = me->mloop[mp->loopstart + fidx].v; - dm->getVertCo(dm, v_idx, co); - project_float_noclip(vc.ar, co, sco); - len = len_squared_v2v2(mval_f, sco); - if (len < len_best) { - len_best = len; - v_idx_best = v_idx; - } - } while (fidx--); + } - if (v_idx_best != -1) { /* should always be valid */ - float vgroup_weight = defvert_find_weight(&me->dvert[v_idx_best], vgroup_active); - BKE_brush_weight_set(scene, brush, vgroup_weight); - change = TRUE; - } - } - dm->release(dm); + if (v_idx_best != -1) { /* should always be valid */ + ToolSettings *ts = vc.scene->toolsettings; + Brush *brush = paint_brush(&ts->wpaint->paint); + const int vgroup_active = vc.obact->actdef - 1; + float vgroup_weight = defvert_find_weight(&me->dvert[v_idx_best], vgroup_active); + BKE_brush_weight_set(vc.scene, brush, vgroup_weight); + change = TRUE; } } @@ -1084,6 +1067,20 @@ void PAINT_OT_weight_sample(wmOperatorType *ot) } /* samples cursor location, and gives menu with vertex groups to activate */ +static int weight_paint_sample_enum_itemf__helper(const MDeformVert *dvert, const int defbase_tot, int *groups) +{ + /* this func fills in used vgroup's */ + int found = FALSE; + int i = dvert->totweight; + MDeformWeight *dw; + for (dw = dvert->dw; i > 0; dw++, i--) { + if (dw->def_nr < defbase_tot) { + groups[dw->def_nr] = TRUE; + found = TRUE; + } + } + return found; +} static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { if (C) { @@ -1095,56 +1092,57 @@ static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA view3d_set_viewcontext(C, &vc); me = BKE_mesh_from_object(vc.obact); - if (me && me->dvert && vc.v3d && vc.rv3d) { - int index; + if (me && me->dvert && vc.v3d && vc.rv3d && vc.obact->defbase.first) { + const int defbase_tot = BLI_countlist(&vc.obact->defbase); + const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + int *groups = MEM_callocN(defbase_tot * sizeof(int), "groups"); + int found = FALSE; + unsigned int index; - view3d_operator_needs_opengl(C); + int mval[2] = {win->eventstate->x - vc.ar->winrct.xmin, + win->eventstate->y - vc.ar->winrct.ymin}; - index = view3d_sample_backbuf(&vc, win->eventstate->x - vc.ar->winrct.xmin, win->eventstate->y - vc.ar->winrct.ymin); + view3d_operator_needs_opengl(C); - if (index && index <= me->totpoly) { - const int defbase_tot = BLI_countlist(&vc.obact->defbase); - if (defbase_tot) { - MPoly *mp = ((MPoly *)me->mpoly) + (index - 1); + if (use_vert_sel) { + if (ED_mesh_pick_vert(C, me, mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE)) { + MDeformVert *dvert = &me->dvert[index]; + found |= weight_paint_sample_enum_itemf__helper(dvert, defbase_tot, groups); + } + } + else { + if (ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + MPoly *mp = &me->mpoly[index]; unsigned int fidx = mp->totloop - 1; - int *groups = MEM_callocN(defbase_tot * sizeof(int), "groups"); - int found = FALSE; do { - MDeformVert *dvert = me->dvert + me->mloop[mp->loopstart + fidx].v; - int i = dvert->totweight; - MDeformWeight *dw; - for (dw = dvert->dw; i > 0; dw++, i--) { - if (dw->def_nr < defbase_tot) { - groups[dw->def_nr] = TRUE; - found = TRUE; - } - } + MDeformVert *dvert = &me->dvert[me->mloop[mp->loopstart + fidx].v]; + found |= weight_paint_sample_enum_itemf__helper(dvert, defbase_tot, groups); } while (fidx--); + } + } - if (found == FALSE) { - MEM_freeN(groups); + if (found == FALSE) { + MEM_freeN(groups); + } + else { + EnumPropertyItem *item = NULL, item_tmp = {0}; + int totitem = 0; + int i = 0; + bDeformGroup *dg; + for (dg = vc.obact->defbase.first; dg && i < defbase_tot; i++, dg = dg->next) { + if (groups[i]) { + item_tmp.identifier = item_tmp.name = dg->name; + item_tmp.value = i; + RNA_enum_item_add(&item, &totitem, &item_tmp); } - else { - EnumPropertyItem *item = NULL, item_tmp = {0}; - int totitem = 0; - int i = 0; - bDeformGroup *dg; - for (dg = vc.obact->defbase.first; dg && i < defbase_tot; i++, dg = dg->next) { - if (groups[i]) { - item_tmp.identifier = item_tmp.name = dg->name; - item_tmp.value = i; - RNA_enum_item_add(&item, &totitem, &item_tmp); - } - } + } - RNA_enum_item_end(&item, &totitem); - *free = 1; + RNA_enum_item_end(&item, &totitem); + *free = 1; - MEM_freeN(groups); - return item; - } - } + MEM_freeN(groups); + return item; } } } @@ -1308,29 +1306,6 @@ static char has_locked_group(MDeformVert *dvert, const int defbase_tot, } return FALSE; } -/* - * gen_lck_flags gets the status of "flag" for each bDeformGroup - * in ob->defbase and returns an array containing them - */ -static char *gen_lock_flags(Object *ob, int defbase_tot) -{ - char is_locked = FALSE; - int i; - //int defbase_tot = BLI_countlist(&ob->defbase); - char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags"); - bDeformGroup *defgroup; - - for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { - lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); - is_locked |= lock_flags[i]; - } - if (is_locked) { - return lock_flags; - } - - MEM_freeN(lock_flags); - return NULL; -} static int has_locked_group_selected(int defbase_tot, const char *defbase_sel, const char *lock_flags) { @@ -1664,9 +1639,9 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi, dv_test.totweight = dv->totweight; /* do not multi-paint if a locked group is selected or the active group is locked * !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */ - if ( (wpi->lock_flags == NULL) || - ((wpi->lock_flags[dw->def_nr] == FALSE) && /* def_nr range has to be checked for by caller */ - has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == FALSE)) + if ((wpi->lock_flags == NULL) || + ((wpi->lock_flags[dw->def_nr] == FALSE) && /* def_nr range has to be checked for by caller */ + has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == FALSE)) { if (wpi->do_multipaint && wpi->defbase_tot_sel > 1) { if (change && change != 1) { @@ -1722,10 +1697,6 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, const int defba return -1; } - -static char *wpaint_make_validmap(Object *ob); - - static void do_weight_paint_vertex( /* vars which remain the same for every vert */ VPaint *wp, Object *ob, const WeightPaintInfo *wpi, @@ -1816,8 +1787,8 @@ static void do_weight_paint_vertex( /* If there are no locks or multipaint, * then there is no need to run the more complicated checks */ - if ( (do_multipaint_totsel == FALSE) && - (wpi->lock_flags == NULL || has_locked_group(dv, wpi->defbase_tot, wpi->vgroup_validmap, wpi->lock_flags) == FALSE)) + if ((do_multipaint_totsel == FALSE) && + (wpi->lock_flags == NULL || has_locked_group(dv, wpi->defbase_tot, wpi->vgroup_validmap, wpi->lock_flags) == FALSE)) { dw->weight = wpaint_blend(wp, dw->weight, dw_prev->weight, alpha, paintweight, wpi->brush_alpha_value, wpi->do_flip, FALSE); @@ -2067,63 +2038,6 @@ struct WPaintData { int defbase_tot; }; -static char *wpaint_make_validmap(Object *ob) -{ - bDeformGroup *dg; - ModifierData *md; - char *vgroup_validmap; - GHash *gh; - int i, step1 = 1; - - if (ob->defbase.first == NULL) { - return NULL; - } - - gh = BLI_ghash_str_new("wpaint_make_validmap gh"); - - /* add all names to a hash table */ - for (dg = ob->defbase.first; dg; dg = dg->next) { - BLI_ghash_insert(gh, dg->name, NULL); - } - - /* now loop through the armature modifiers and identify deform bones */ - for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) { - if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual))) - continue; - - if (md->type == eModifierType_Armature) { - ArmatureModifierData *amd = (ArmatureModifierData *) md; - - if (amd->object && amd->object->pose) { - bPose *pose = amd->object->pose; - bPoseChannel *chan; - - for (chan = pose->chanbase.first; chan; chan = chan->next) { - if (chan->bone->flag & BONE_NO_DEFORM) - continue; - - if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) { - BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1)); - } - } - } - } - } - - vgroup_validmap = MEM_mallocN(BLI_ghash_size(gh), "wpaint valid map"); - - /* add all names to a hash table */ - for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) { - vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL); - } - - BLI_assert(i == BLI_ghash_size(gh)); - - BLI_ghash_free(gh, NULL, NULL); - - return vgroup_validmap; -} - static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2])) { Scene *scene = CTX_data_scene(C); @@ -2202,9 +2116,9 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNU /* set up auto-normalize, and generate map for detecting which * vgroups affect deform bones */ wpd->defbase_tot = BLI_countlist(&ob->defbase); - wpd->lock_flags = gen_lock_flags(ob, wpd->defbase_tot); + wpd->lock_flags = BKE_objdef_lock_flags_get(ob, wpd->defbase_tot); if (ts->auto_normalize || ts->multipaint || wpd->lock_flags) { - wpd->vgroup_validmap = wpaint_make_validmap(ob); + wpd->vgroup_validmap = BKE_objdef_validmap_get(ob, wpd->defbase_tot); } /* painting on subsurfs should give correct points too, this returns me->totvert amount */ @@ -2243,7 +2157,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float alpha; float mval[2]; int use_vert_sel; - char *defbase_sel; const float pressure = RNA_float_get(itemptr, "pressure"); const float brush_size_pressure = BKE_brush_size_get(scene, brush) * (BKE_brush_use_size_pressure(scene, brush) ? pressure : 1.0f); @@ -2277,12 +2190,13 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P + /* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */ wpi.defbase_tot = wpd->defbase_tot; - defbase_sel = MEM_mallocN(wpi.defbase_tot * sizeof(char), "wpi.defbase_sel"); - wpi.defbase_tot_sel = get_selected_defgroups(ob, defbase_sel, wpi.defbase_tot); - wpi.defbase_sel = defbase_sel; /* so we can stay const */ - if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) wpi.defbase_tot_sel = 1; + wpi.defbase_sel = BKE_objdef_selected_get(ob, wpi.defbase_tot, &wpi.defbase_tot_sel); + if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) { + wpi.defbase_tot_sel = 1; + } wpi.defbase_tot_unsel = wpi.defbase_tot - wpi.defbase_tot_sel; wpi.vgroup_active = wpd->vgroup_active; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index e2289bc9cfc..210477e3e5a 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -3074,12 +3074,12 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_ /* BMESH ONLY --- at some point we should move sculpt code to use polygons only - but for now it needs tessfaces */ BKE_mesh_tessface_ensure(me); - /* needs to be called after we ensure tessface */ - dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); - if (!mmd) ss->kb = ob_get_keyblock(ob); else ss->kb = NULL; + /* needs to be called after we ensure tessface */ + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + if (mmd) { ss->multires = mmd; ss->totvert = dm->getNumVerts(dm); diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index c9f765ac3db..9ab79d73e76 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -255,8 +255,8 @@ static void borderselect_action(bAnimContext *ac, rcti rect, short mode, short s } /* perform vertical suitability check (if applicable) */ - if ( (mode == ACTKEYS_BORDERSEL_FRAMERANGE) || - !((ymax < rectf.ymin) || (ymin > rectf.ymax)) ) + if ((mode == ACTKEYS_BORDERSEL_FRAMERANGE) || + !((ymax < rectf.ymin) || (ymin > rectf.ymax))) { /* loop over data selecting */ if (ale->type == ANIMTYPE_GPLAYER) @@ -802,8 +802,8 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se TimeMarker *marker; for (marker = markers->first; marker; marker = marker->next) { - if ( ((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) || - ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA)) ) + if (((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) || + ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA))) { marker->flag |= SELECT; } diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index cdecda63432..0e82d8651f3 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -341,7 +341,7 @@ static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUS { /* callback when opening texture user selection menu, to create buttons. */ SpaceButs *sbuts = CTX_wm_space_buts(C); - ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; + ButsContextTexture *ct = sbuts->texuser; ButsTextureUser *user; uiBlock *block = uiLayoutGetBlock(layout); const char *last_category = NULL; diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 7a54a39ee48..08ad6aac970 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -158,7 +158,7 @@ void ED_space_clip_get_aspect(SpaceClip *sc, float *aspx, float *aspy) MovieClip *clip = ED_space_clip_get_clip(sc); if (clip) - BKE_movieclip_aspect(clip, aspx, aspy); + BKE_movieclip_get_aspect(clip, aspx, aspy); else *aspx = *aspy = 1.0f; diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c index d8c7bf3f809..1bdf5214192 100644 --- a/source/blender/editors/space_clip/clip_toolbar.c +++ b/source/blender/editors/space_clip/clip_toolbar.c @@ -230,7 +230,7 @@ static void clip_panel_operator_redo(const bContext *C, Panel *pa) block = uiLayoutGetBlock(pa->layout); if (!WM_operator_check_ui_enabled(C, op->type->name)) - uiLayoutSetEnabled(pa->layout, 0); + uiLayoutSetEnabled(pa->layout, FALSE); /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */ uiBlockSetHandleFunc(block, ED_undo_operator_repeat_cb_evt, op); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index bb06104d442..7f43c404095 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -1131,10 +1131,13 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) if (mask) { ScrArea *sa = CTX_wm_area(C); int width, height; + float aspx, aspy; ED_mask_get_size(sa, &width, &height); + ED_space_clip_get_aspect(sc, &aspx, &aspy); ED_mask_draw_region(mask, ar, sc->mask_info.draw_flag, sc->mask_info.draw_type, width, height, + aspx, aspy, TRUE, TRUE, sc->stabmat, C); } diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index ff7a71af8c2..040f276940d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -156,7 +156,7 @@ static FileSelection file_selection_get(bContext *C, const rcti *rect, short fil return sel; } -static FileSelect file_select_do(bContext *C, int selected_idx) +static FileSelect file_select_do(bContext *C, int selected_idx, short do_diropen) { FileSelect retval = FILE_SELECT_NOTHING; SpaceFile *sfile = CTX_wm_space_file(C); @@ -172,8 +172,12 @@ static FileSelect file_select_do(bContext *C, int selected_idx) params->active_file = selected_idx; if (S_ISDIR(file->type)) { + if (do_diropen == FALSE) { + params->file[0] = '\0'; + retval = FILE_SELECT_DIR; + } /* the path is too long and we are not going up! */ - if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) { + else if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) { // XXX error("Path too long, cannot enter this directory"); } else { @@ -202,7 +206,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx) } -static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, short fill) +static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, short fill, short do_diropen) { SpaceFile *sfile = CTX_wm_space_file(C); FileSelect retval = FILE_SELECT_NOTHING; @@ -219,7 +223,7 @@ static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, if ((sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE))) { /* Check last selection, if selected, act on the file or dir */ if (filelist_is_selected(sfile->files, sel.last, check_type)) { - retval = file_select_do(C, sel.last); + retval = file_select_do(C, sel.last, do_diropen); } } @@ -284,7 +288,7 @@ static int file_border_select_exec(bContext *C, wmOperator *op) BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect); - ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, 0); + ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, FALSE, FALSE); if (FILE_SELECT_DIR == ret) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } @@ -320,6 +324,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) rcti rect; int extend = RNA_boolean_get(op->ptr, "extend"); int fill = RNA_boolean_get(op->ptr, "fill"); + int do_diropen = RNA_boolean_get(op->ptr, "open"); if (ar->regiontype != RGN_TYPE_WINDOW) return OPERATOR_CANCELLED; @@ -333,7 +338,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) /* single select, deselect all selected first */ if (!extend) file_deselect_all(sfile, SELECTED_FILE); - ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill); + ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen); if (FILE_SELECT_DIR == ret) WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); else if (FILE_SELECT_FILE == ret) @@ -357,8 +362,9 @@ void FILE_OT_select(wmOperatorType *ot) ot->poll = ED_operator_file_active; /* rna */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first"); - RNA_def_boolean(ot->srna, "fill", 0, "Fill", "Select everything beginning with the last selection"); + RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first"); + RNA_def_boolean(ot->srna, "fill", FALSE, "Fill", "Select everything beginning with the last selection"); + RNA_def_boolean(ot->srna, "open", TRUE, "Open", "Open a directory when selecting it"); } static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op)) @@ -1113,7 +1119,7 @@ static void file_expand_directory(bContext *C) if (sfile->params) { /* TODO, what about // when relbase isn't valid? */ - if (G.relbase_valid && strncmp(sfile->params->dir, "//", 2) == 0) { + if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) { BLI_path_abs(sfile->params->dir, G.main->name); } else if (sfile->params->dir[0] == '~') { diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index fcf6f28b406..4b568b43695 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -284,8 +284,6 @@ static void file_main_area_init(wmWindowManager *wm, ARegion *ar) keymap = WM_keymap_find(wm->defaultconf, "File Browser Main", SPACE_FILE, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); - - } static void file_main_area_listener(ARegion *ar, wmNotifier *wmn) @@ -418,12 +416,26 @@ static void file_keymap(struct wmKeyConfig *keyconf) keymap = WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0); kmi = WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0); RNA_boolean_set(kmi->ptr, "need_active", TRUE); + + /* left mouse selects and opens */ WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0); kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0); RNA_boolean_set(kmi->ptr, "extend", TRUE); kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0); RNA_boolean_set(kmi->ptr, "extend", TRUE); RNA_boolean_set(kmi->ptr, "fill", TRUE); + + /* right mouse selects without opening */ + kmi = WM_keymap_add_item(keymap, "FILE_OT_select", RIGHTMOUSE, KM_CLICK, 0, 0); + RNA_boolean_set(kmi->ptr, "open", FALSE); + kmi = WM_keymap_add_item(keymap, "FILE_OT_select", RIGHTMOUSE, KM_CLICK, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "extend", TRUE); + RNA_boolean_set(kmi->ptr, "open", FALSE); + kmi = WM_keymap_add_item(keymap, "FILE_OT_select", RIGHTMOUSE, KM_CLICK, KM_ALT, 0); + RNA_boolean_set(kmi->ptr, "extend", TRUE); + RNA_boolean_set(kmi->ptr, "fill", TRUE); + RNA_boolean_set(kmi->ptr, "open", FALSE); + WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0); diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index ad97b7853c4..e4bda15bc7d 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -235,7 +235,7 @@ static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2 * if a Graph Editor option to only show handles of selected keys is on. */ if (!sel_handle_only || BEZSELECTED(bezt) ) { - if ( (!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)) ) { + if ((!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { if ((bezt->f1 & SELECT) == sel) /* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/ draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize); } @@ -378,8 +378,8 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu) } else { /* only draw first handle if previous segment was had handles, and selection is ok */ - if ( ((bezt->f1 & SELECT) == sel) && - ( (!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)) ) ) + if (((bezt->f1 & SELECT) == sel) && + ((!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)))) { fp = bezt->vec[0]; UI_GetThemeColor3ubv(basecol + bezt->h1, col); @@ -390,8 +390,8 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu) } /* only draw second handle if this segment is bezier, and selection is ok */ - if ( ((bezt->f3 & SELECT) == sel) && - (bezt->ipo == BEZT_IPO_BEZ) ) + if (((bezt->f3 & SELECT) == sel) && + (bezt->ipo == BEZT_IPO_BEZ)) { fp = bezt->vec[1]; UI_GetThemeColor3ubv(basecol + bezt->h2, col); @@ -846,11 +846,11 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid /* 1) draw curve line */ { /* set color/drawing style for curve itself */ - if ( ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || (fcu->flag & FCURVE_PROTECTED) ) { + if (((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || (fcu->flag & FCURVE_PROTECTED)) { /* protected curves (non editable) are drawn with dotted lines */ setlinestyle(2); } - if ( ((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED) ) { + if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) { /* muted curves are drawn in a grayish hue */ // XXX should we have some variations? UI_ThemeColorShade(TH_HEADER, 50); @@ -878,7 +878,7 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid */ draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid); } - else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { + else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { /* just draw curve based on defined data (i.e. no modifiers) */ if (fcu->bezt) draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d); @@ -908,7 +908,7 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid } } } - else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { + else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { /* apply unit mapping */ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0); diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index 32abad86828..633f2b72cf6 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -942,7 +942,7 @@ static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fc /* if there is already a point for the F-Curve, check if this point is closer than that was */ if ((nvi) && (nvi->fcu == fcu)) { /* replace if we are closer, or if equal and that one wasn't selected but we are... */ - if ( (nvi->dist > dist) || ((nvi->sel == 0) && BEZSELECTED(bezt)) ) + if ((nvi->dist > dist) || ((nvi->sel == 0) && BEZSELECTED(bezt))) replace = 1; } /* add new if not replacing... */ diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index ac9883b411d..79d01491df7 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -143,27 +143,6 @@ int ED_space_image_has_buffer(SpaceImage *sima) return has_buffer; } -void ED_image_get_size(Image *ima, int *width, int *height) -{ - ImBuf *ibuf = NULL; - void *lock; - - if (ima) - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf && ibuf->x > 0 && ibuf->y > 0) { - *width = ibuf->x; - *height = ibuf->y; - } - else { - *width = IMG_SIZE_FALLBACK; - *height = IMG_SIZE_FALLBACK; - } - - if (ima) - BKE_image_release_ibuf(ima, lock); -} - void ED_space_image_get_size(SpaceImage *sima, int *width, int *height) { Scene *scene = sima->iuser.scene; @@ -205,23 +184,18 @@ void ED_space_image_get_size_fl(SpaceImage *sima, float size[2]) size[1] = size_i[1]; } -void ED_image_get_aspect(Image *ima, float *aspx, float *aspy) -{ - *aspx = *aspy = 1.0; +void ED_space_image_get_aspect(SpaceImage *sima, float *aspx, float *aspy) +{ + Image *ima = sima->image; if ((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) || (ima->aspx == 0.0f || ima->aspy == 0.0f)) { - return; + *aspx = *aspy = 1.0; + } + else { + BKE_image_get_aspect(ima, aspx, aspy); } - - /* x is always 1 */ - *aspy = ima->aspy / ima->aspx; -} - -void ED_space_image_get_aspect(SpaceImage *sima, float *aspx, float *aspy) -{ - ED_image_get_aspect(ED_space_image(sima), aspx, aspy); } void ED_space_image_get_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy) @@ -254,15 +228,21 @@ void ED_space_image_get_uv_aspect(SpaceImage *sima, float *aspx, float *aspy) } } -void ED_image_get_uv_aspect(Image *ima, float *aspx, float *aspy) +void ED_image_get_uv_aspect(Image *ima, ImageUser *iuser, float *aspx, float *aspy) { - int w, h; + if (ima) { + int w, h; - ED_image_get_aspect(ima, aspx, aspy); - ED_image_get_size(ima, &w, &h); + BKE_image_get_aspect(ima, aspx, aspy); + BKE_image_get_size(ima, iuser, &w, &h); - *aspx *= (float)w; - *aspy *= (float)h; + *aspx *= (float)w; + *aspy *= (float)h; + } + else { + *aspx = 1.0f; + *aspy = 1.0f; + } } /* takes event->mval */ diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 3d6b316b743..86722c5158e 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -632,7 +632,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) ima = ED_space_image(sima); ED_space_image_get_size(sima, &width, &height); - ED_image_get_aspect(ima, &aspx, &aspy); + ED_space_image_get_aspect(sima, &aspx, &aspy); width = width * aspx; height = height * aspy; @@ -1051,7 +1051,7 @@ static int image_replace_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(eve return image_replace_exec(C, op); if (!RNA_struct_property_is_set(op->ptr, "relative_path")) - RNA_boolean_set(op->ptr, "relative_path", (strncmp(sima->image->name, "//", 2)) == 0); + RNA_boolean_set(op->ptr, "relative_path", BLI_path_is_rel(sima->image->name)); image_filesel(C, op, sima->image->name); @@ -1160,7 +1160,7 @@ static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima, /* check for empty path */ if (guess_path && simopts->filepath[0] == 0) { - if ( (G.ima[0] == '/') && (G.ima[1] == '/') && (G.ima[2] == '\0') ) { + if ((G.ima[0] == '/') && (G.ima[1] == '/') && (G.ima[2] == '\0')) { BLI_strncpy(simopts->filepath, "//untitled", FILE_MAX); } else { @@ -1586,7 +1586,7 @@ static int image_new_exec(bContext *C, wmOperator *op) PropertyRNA *prop; char name[MAX_ID_NAME - 2]; float color[4]; - int width, height, floatbuf, uvtestgrid, alpha; + int width, height, floatbuf, gen_type, alpha; /* retrieve state */ sima = CTX_wm_space_image(C); @@ -1597,7 +1597,7 @@ static int image_new_exec(bContext *C, wmOperator *op) width = RNA_int_get(op->ptr, "width"); height = RNA_int_get(op->ptr, "height"); floatbuf = RNA_boolean_get(op->ptr, "float"); - uvtestgrid = RNA_boolean_get(op->ptr, "uv_test_grid"); + gen_type = RNA_enum_get(op->ptr, "generated_type"); RNA_float_get_array(op->ptr, "color", color); alpha = RNA_boolean_get(op->ptr, "alpha"); @@ -1607,7 +1607,7 @@ static int image_new_exec(bContext *C, wmOperator *op) if (!alpha) color[3] = 1.0f; - ima = BKE_image_add_generated(width, height, name, alpha ? 32 : 24, floatbuf, uvtestgrid, color); + ima = BKE_image_add_generated(width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color); if (!ima) return OPERATOR_CANCELLED; @@ -1664,7 +1664,8 @@ void IMAGE_OT_new(wmOperatorType *ot) prop = RNA_def_float_color(ot->srna, "color", 4, NULL, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f); RNA_def_property_float_array_default(prop, default_color); RNA_def_boolean(ot->srna, "alpha", 1, "Alpha", "Create an image with an alpha channel"); - RNA_def_boolean(ot->srna, "uv_test_grid", 0, "UV Test Grid", "Fill the image with a grid for UV map testing"); + RNA_def_enum(ot->srna, "generated_type", image_generated_type_items, IMA_GENTYPE_BLANK, + "Generated Type", "Fill the image with a grid for UV map testing"); RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth"); } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index d2639edb276..91a0cba2555 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -392,11 +392,12 @@ static void image_refresh(const bContext *C, ScrArea *sa) else if (obedit && obedit->type == OB_MESH) { Mesh *me = (Mesh *)obedit->data; struct BMEditMesh *em = me->edit_btmesh; - int sloppy = 1; /* partially selected face is ok */ + int sloppy = TRUE; /* partially selected face is ok */ + int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */ if (BKE_scene_use_new_shading_nodes(scene)) { /* new shading system, get image from material */ - BMFace *efa = BM_active_face_get(em->bm, sloppy); + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) { Image *node_ima; @@ -413,8 +414,8 @@ static void image_refresh(const bContext *C, ScrArea *sa) if (em && EDBM_mtexpoly_check(em)) { sima->image = NULL; - tf = EDBM_mtexpoly_active_get(em, NULL, TRUE); /* partially selected face is ok */ - + tf = EDBM_mtexpoly_active_get(em, NULL, sloppy, selected); + if (tf) { /* don't need to check for pin here, see above */ sima->image = tf->tpage; @@ -681,10 +682,13 @@ static void image_main_area_draw(const bContext *C, ARegion *ar) if (mask) { int width, height; + float aspx, aspy; ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_aspect(sima, &aspx, &aspy); ED_mask_draw_region(mask, ar, sima->mask_info.draw_flag, sima->mask_info.draw_type, width, height, + aspx, aspy, TRUE, FALSE, NULL, C); diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 7870e64228a..4ffa99319c4 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -70,7 +70,8 @@ typedef struct SceneStats { static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) { switch (ob->type) { - case OB_MESH: { + case OB_MESH: + { /* we assume derivedmesh is already built, this strictly does stats now. */ DerivedMesh *dm = ob->derivedFinal; int totvert, totedge, totface; @@ -101,7 +102,8 @@ static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) break; case OB_SURF: case OB_CURVE: - case OB_FONT: { + case OB_FONT: + { int tot = 0, totf = 0; stats->totcurve += totob; @@ -121,7 +123,8 @@ static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) } break; } - case OB_MBALL: { + case OB_MBALL: + { int tot = 0, totf = 0; BKE_displist_count(&ob->disp, &tot, &totf); diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 08e0934e8ae..6ffac1dcd34 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -878,7 +878,7 @@ static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisf } /* 4th case: select actuator when controller selected */ - if ( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE)) && (ob->scavisflag & OB_VIS_CONT)) { + if ((scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE)) && (ob->scavisflag & OB_VIS_CONT)) { cont= ob->controllers.first; while (cont) { for (a=0; a<cont->totlinks; a++) { @@ -921,7 +921,7 @@ static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisf } while (ob) { - if ( (ob->scavisflag) && (ob != obact)) { + if ((ob->scavisflag) && (ob != obact)) { idar[nr]= (ID *)ob; nr++; } @@ -2162,7 +2162,7 @@ static short draw_actuatorbuttons(Main *bmain, Object *ob, bActuator *act, uiBlo 0.0, 1.0, 0, 0, "Sets the volume of this sound"); uiDefButF(block, NUM, 0, "Pitch:", xco+wval+10, yco-66, wval, 19, &sa->pitch, -12.0, 12.0, 0, 0, "Sets the pitch of this sound"); - uiDefButS(block, TOG | BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, + uiDefButS(block, TOG | UI_BUT_POIN_BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, &sa->flag, 0.0, 1.0, 0.0, 0.0, "Plays the sound positioned in 3D space"); if (sa->flag & ACT_SND_3D_SOUND) { uiDefButF(block, NUM, 0, "Minimum Gain: ", xco+10, yco-110, wval, 19, @@ -3398,7 +3398,13 @@ static void draw_sensor_message(uiLayout *layout, PointerRNA *ptr) static void draw_sensor_mouse(uiLayout *layout, PointerRNA *ptr) { - uiItemR(layout, ptr, "mouse_event", 0, NULL, ICON_NONE); + uiLayout *split; + + split = uiLayoutSplit(layout, 0.8f, FALSE); + uiItemR(split, ptr, "mouse_event", 0, NULL, ICON_NONE); + + if (RNA_enum_get(ptr, "mouse_event") == BL_SENS_MOUSE_MOUSEOVER_ANY) + uiItemR(split, ptr, "use_pulse", UI_ITEM_R_TOGGLE, NULL, ICON_NONE); } static void draw_sensor_near(uiLayout *layout, PointerRNA *ptr) @@ -4352,38 +4358,38 @@ static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr) uiLayout *row; uiLayout *col; - uiItemR(layout, ptr, "mode", 0, NULL, 0); - uiItemR(layout, ptr, "target", 0, NULL, 0); - uiItemR(layout, ptr, "navmesh", 0, NULL, 0); + uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "target", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "navmesh", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemR(row, ptr, "distance", 0, NULL, 0); - uiItemR(row, ptr, "velocity", 0, NULL, 0); + uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "velocity", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemR(row, ptr, "acceleration", 0, NULL, 0); - uiItemR(row, ptr, "turn_speed", 0, NULL, 0); + uiItemR(row, ptr, "acceleration", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "turn_speed", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); col = uiLayoutColumn(row, FALSE); - uiItemR(col, ptr, "facing", 0, NULL, 0); + uiItemR(col, ptr, "facing", 0, NULL, ICON_NONE); col = uiLayoutColumn(row, FALSE); - uiItemR(col, ptr, "facing_axis", 0, NULL, 0); + uiItemR(col, ptr, "facing_axis", 0, NULL, ICON_NONE); if (!RNA_boolean_get(ptr, "facing")) { uiLayoutSetActive(col, FALSE); } col = uiLayoutColumn(row, FALSE); - uiItemR(col, ptr, "normal_up", 0, NULL, 0); + uiItemR(col, ptr, "normal_up", 0, NULL, ICON_NONE); if (!RNA_pointer_get(ptr, "navmesh").data) { uiLayoutSetActive(col, FALSE); } row = uiLayoutRow(layout, FALSE); - uiItemR(row, ptr, "self_terminated", 0, NULL, 0); + uiItemR(row, ptr, "self_terminated", 0, NULL, ICON_NONE); if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING) { - uiItemR(row, ptr, "update_period", 0, NULL, 0); + uiItemR(row, ptr, "update_period", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); } - uiItemR(row, ptr, "show_visualization", 0, NULL, 0); + uiItemR(row, ptr, "show_visualization", 0, NULL, ICON_NONE); } static void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C) @@ -4539,7 +4545,9 @@ static void logic_buttons_new(bContext *C, ARegion *ar) ob= (Object *)idar[a]; /* only draw the controller common header if "use_visible" */ - if ( (ob->scavisflag & OB_VIS_CONT) == 0) continue; + if ( (ob->scavisflag & OB_VIS_CONT) == 0) { + continue; + } /* Drawing the Controller Header common to all Selected Objects */ @@ -4707,7 +4715,9 @@ static void logic_buttons_new(bContext *C, ARegion *ar) ob= (Object *)idar[a]; /* only draw the actuator common header if "use_visible" */ - if ( (ob->scavisflag & OB_VIS_ACT) == 0) continue; + if ((ob->scavisflag & OB_VIS_ACT) == 0) { + continue; + } row = uiLayoutRow(layout, TRUE); uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2, (short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators"); @@ -4834,7 +4844,9 @@ void logic_buttons(bContext *C, ARegion *ar) ob= (Object *)idar[a]; // uiClearButLock(); // uiSetButLock(BKE_object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - if ( (ob->scavisflag & OB_VIS_CONT) == 0) continue; + if ((ob->scavisflag & OB_VIS_CONT) == 0) { + continue; + } /* presume it is only objects for now */ uiBlockBeginAlign(block); @@ -4972,7 +4984,9 @@ void logic_buttons(bContext *C, ARegion *ar) // uiClearButLock(); // uiSetButLock(BKE_object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - if ( (ob->scavisflag & OB_VIS_SENS) == 0) continue; + if ((ob->scavisflag & OB_VIS_SENS) == 0) { + continue; + } /* presume it is only objects for now */ uiBlockBeginAlign(block); @@ -5052,7 +5066,9 @@ void logic_buttons(bContext *C, ARegion *ar) ob= (Object *)idar[a]; // uiClearButLock(); // uiSetButLock(BKE_object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - if ( (ob->scavisflag & OB_VIS_ACT) == 0) continue; + if ((ob->scavisflag & OB_VIS_ACT) == 0) { + continue; + } /* presume it is only objects for now */ uiBlockBeginAlign(block); diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index e7610210881..222c2414fcb 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -245,8 +245,8 @@ static void borderselect_nla_strips(bAnimContext *ac, rcti rect, short mode, sho ymin = ymax - NLACHANNEL_STEP(snla); /* perform vertical suitability check (if applicable) */ - if ( (mode == NLA_BORDERSEL_FRAMERANGE) || - !((ymax < rectf.ymin) || (ymin > rectf.ymax)) ) + if ((mode == NLA_BORDERSEL_FRAMERANGE) || + !((ymax < rectf.ymin) || (ymin > rectf.ymax))) { /* loop over data selecting (only if NLA-Track) */ if (ale->type == ANIMTYPE_NLATRACK) { @@ -255,8 +255,8 @@ static void borderselect_nla_strips(bAnimContext *ac, rcti rect, short mode, sho /* only select strips if they fall within the required ranges (if applicable) */ for (strip = nlt->strips.first; strip; strip = strip->next) { - if ( (mode == NLA_BORDERSEL_CHANNELS) || - BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax)) + if ((mode == NLA_BORDERSEL_CHANNELS) || + BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax)) { /* set selection */ ACHANNEL_SET_FLAG(strip, selectmode, NLASTRIP_FLAG_SELECT); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 8a1f0e5b611..5ebcef1d9a7 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -171,7 +171,7 @@ static void node_socket_button_color(const bContext *C, uiBlock *block, int labelw = width - 40; RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr); - bt = uiDefButR(block, COL, B_NODE_EXEC, "", + bt = uiDefButR(block, COLOR, B_NODE_EXEC, "", x, y + 2, (labelw > 0 ? 40 : width), NODE_DY - 2, &ptr, "default_value", 0, 0, 0, -1, -1, NULL); if (node) @@ -647,23 +647,22 @@ static void update_group_output_cb(bContext *UNUSED(C), void *UNUSED(snode_v), v static void draw_group_socket_name(SpaceNode *snode, bNode *gnode, bNodeSocket *sock, int in_out, float xoffset, float yoffset) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - uiBut *bt; - const char *ui_name = IFACE_(sock->name); - if (sock->flag & SOCK_DYNAMIC) { - bt = uiDefBut(gnode->block, TEX, 0, "", - sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY, - sock->name, 0, sizeof(sock->name), 0, 0, ""); + bNodeTree *ngroup = (bNodeTree *)gnode->id; + uiBut *but; + but = uiDefBut(gnode->block, TEX, 0, "", + sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY, + sock->name, 0, sizeof(sock->name), 0, 0, ""); if (in_out == SOCK_IN) - uiButSetFunc(bt, update_group_input_cb, snode, ngroup); + uiButSetFunc(but, update_group_input_cb, snode, ngroup); else - uiButSetFunc(bt, update_group_output_cb, snode, ngroup); + uiButSetFunc(but, update_group_output_cb, snode, ngroup); } else { + const char *ui_name = IFACE_(sock->name); uiDefBut(gnode->block, LABEL, 0, ui_name, sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY, - NULL, 0, sizeof(ui_name), 0, 0, ""); + NULL, 0, 0, 0, 0, ""); } } @@ -900,7 +899,7 @@ void node_uifunc_group(uiLayout *layout, bContext *C, PointerRNA *ptr) static void node_common_buts_whileloop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "max_iterations", 0, NULL, 0); + uiItemR(layout, ptr, "max_iterations", 0, NULL, ICON_NONE); } /* XXX Does a bounding box update by iterating over all children. @@ -1324,6 +1323,11 @@ static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); + uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); + + if (RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX) { + uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE); + } /* note: image user properties used directly here, unlike compositor image node, * which redefines them in the node struct RNA to get proper updates. @@ -1359,6 +1363,19 @@ static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), Po uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE); } +static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiLayout *col; + + col = uiLayoutColumn(layout, TRUE); + uiItemR(col, ptr, "offset", 0, IFACE_("Offset"), ICON_NONE); + uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE); + + col = uiLayoutColumn(layout, TRUE); + uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE); + uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE); +} + static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE); @@ -1443,6 +1460,9 @@ static void node_shader_set_butfunc(bNodeType *ntype) case SH_NODE_TEX_MAGIC: ntype->uifunc = node_shader_buts_tex_magic; break; + case SH_NODE_TEX_BRICK: + ntype->uifunc = node_shader_buts_tex_brick; + break; case SH_NODE_TEX_WAVE: ntype->uifunc = node_shader_buts_tex_wave; break; @@ -1534,9 +1554,9 @@ static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), Point uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE); if (RNA_boolean_get(ptr, "use_relative")) { - uiItemL(col, IFACE_("Aspect Correction"), 0); + uiItemL(col, IFACE_("Aspect Correction"), ICON_NONE); row = uiLayoutRow(layout, TRUE); - uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0); + uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, ICON_NONE); col = uiLayoutColumn(layout, TRUE); uiItemR(col, ptr, "factor_x", 0, IFACE_("X"), ICON_NONE); @@ -1960,7 +1980,7 @@ static void node_draw_input_file_output(const bContext *C, uiBlock *block, NodeImageMultiFileSocket *input = sock->storage; RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotLayer, input, &inputptr); - uiItemL(row, input->layer, 0); + uiItemL(row, input->layer, ICON_NONE); } else { NodeImageMultiFileSocket *input = sock->storage; @@ -1968,7 +1988,7 @@ static void node_draw_input_file_output(const bContext *C, uiBlock *block, const char *imtype_name; RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotFile, input, &inputptr); - uiItemL(row, input->path, 0); + uiItemL(row, input->path, ICON_NONE); if (!RNA_boolean_get(&inputptr, "use_node_format")) imfptr = RNA_pointer_get(&inputptr, "format"); @@ -1977,7 +1997,7 @@ static void node_draw_input_file_output(const bContext *C, uiBlock *block, RNA_property_enum_name((bContext *)C, &imfptr, imtype_prop, RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name); uiBlockSetEmboss(block, UI_EMBOSSP); - uiItemL(row, imtype_name, 0); + uiItemL(row, imtype_name, ICON_NONE); uiBlockSetEmboss(block, UI_EMBOSSN); } @@ -1989,9 +2009,9 @@ static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C) int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER); if (multilayer) - uiItemL(layout, IFACE_("Path:"), 0); + uiItemL(layout, IFACE_("Path:"), ICON_NONE); else - uiItemL(layout, IFACE_("Base Path:"), 0); + uiItemL(layout, IFACE_("Base Path:"), ICON_NONE); uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE); } static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -2037,9 +2057,9 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C uiLayout *row, *col; col = uiLayoutColumn(layout, TRUE); - uiItemL(col, IFACE_("Layer:"), 0); + uiItemL(col, IFACE_("Layer:"), ICON_NONE); row = uiLayoutRow(col, FALSE); - uiItemR(row, &active_input_ptr, "name", 0, "", 0); + uiItemR(row, &active_input_ptr, "name", 0, "", ICON_NONE); uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY); } @@ -2047,9 +2067,9 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C uiLayout *row, *col; col = uiLayoutColumn(layout, TRUE); - uiItemL(col, IFACE_("File Path:"), 0); + uiItemL(col, IFACE_("File Path:"), ICON_NONE); row = uiLayoutRow(col, FALSE); - uiItemR(row, &active_input_ptr, "path", 0, "", 0); + uiItemR(row, &active_input_ptr, "path", 0, "", ICON_NONE); uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY); @@ -2057,8 +2077,8 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C imfptr = RNA_pointer_get(&active_input_ptr, "format"); col = uiLayoutColumn(layout, TRUE); - uiItemL(col, IFACE_("Format:"), 0); - uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, 0); + uiItemL(col, IFACE_("Format:"), ICON_NONE); + uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, ICON_NONE); col = uiLayoutColumn(layout, FALSE); uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == FALSE); @@ -2212,12 +2232,12 @@ static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, Pointe if (!node->id) return; - uiItemR(layout, ptr, "filter_type", 0, "", 0); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "filter_type", 0, "", 0); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -2229,7 +2249,7 @@ static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, Po if (!node->id) return; - uiItemR(layout, ptr, "distortion_type", 0, "", 0); + uiItemR(layout, ptr, "distortion_type", 0, "", ICON_NONE); } static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) @@ -2242,15 +2262,15 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, "", 0); - uiItemL(row, IFACE_("Saturation"), 0); - uiItemL(row, IFACE_("Contrast"), 0); - uiItemL(row, IFACE_("Gamma"), 0); - uiItemL(row, IFACE_("Gain"), 0); - uiItemL(row, IFACE_("Lift"), 0); + uiItemL(row, "", ICON_NONE); + uiItemL(row, IFACE_("Saturation"), ICON_NONE); + uiItemL(row, IFACE_("Contrast"), ICON_NONE); + uiItemL(row, IFACE_("Gamma"), ICON_NONE); + uiItemL(row, IFACE_("Gain"), ICON_NONE); + uiItemL(row, IFACE_("Lift"), ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Master"), 0); + uiItemL(row, IFACE_("Master"), ICON_NONE); uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2258,7 +2278,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Highlights"), 0); + uiItemL(row, IFACE_("Highlights"), ICON_NONE); uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2266,7 +2286,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Midtones"), 0); + uiItemL(row, IFACE_("Midtones"), ICON_NONE); uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2274,7 +2294,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSE uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); row = uiLayoutRow(layout, FALSE); - uiItemL(row, IFACE_("Shadows"), 0); + uiItemL(row, IFACE_("Shadows"), ICON_NONE); uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2295,31 +2315,31 @@ static void node_composit_buts_colorcorrection_but(uiLayout *layout, bContext *U uiItemR(row, ptr, "green", 0, NULL, ICON_NONE); uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); row = layout; - uiItemL(row, IFACE_("Saturation"), 0); + uiItemL(row, IFACE_("Saturation"), ICON_NONE); uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Contrast"), 0); + uiItemL(row, IFACE_("Contrast"), ICON_NONE); uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Gamma"), 0); + uiItemL(row, IFACE_("Gamma"), ICON_NONE); uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Gain"), 0); + uiItemL(row, IFACE_("Gain"), ICON_NONE); uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemL(row, IFACE_("Lift"), 0); + uiItemL(row, IFACE_("Lift"), ICON_NONE); uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); @@ -2570,7 +2590,7 @@ static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRN RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr); - col = uiLayoutColumn(layout, 0); + col = uiLayoutColumn(layout, FALSE); uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); object = BKE_tracking_object_get_named(tracking, data->tracking_object); diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index e50b1dc4ba6..da077d93641 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -110,8 +110,8 @@ static void active_node_panel(const bContext *C, Panel *pa) uiItemR(col, &ptr, "use_custom_color", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE); sub = uiLayoutRow(col, FALSE); if (!(node->flag & NODE_CUSTOM_COLOR)) - uiLayoutSetEnabled(sub, 0); - uiItemR(sub, &ptr, "color", 0, "", 0); + uiLayoutSetEnabled(sub, FALSE); + uiItemR(sub, &ptr, "color", 0, "", ICON_NONE); col = uiLayoutColumn(row, TRUE); uiItemO(col, "", ICON_ZOOMIN, "node.node_color_preset_add"); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index fbae8b17ebf..9e04bd36a1f 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -309,7 +309,8 @@ void ED_node_shader_default(Scene *scene, ID *id) ntree = ntreeAddTree("Shader Nodetree", NTREE_SHADER, 0); switch (GS(id->name)) { - case ID_MA: { + case ID_MA: + { Material *ma = (Material *)id; ma->nodetree = ntree; @@ -326,7 +327,8 @@ void ED_node_shader_default(Scene *scene, ID *id) strength = 0.0f; break; } - case ID_WO: { + case ID_WO: + { World *wo = (World *)id; wo->nodetree = ntree; @@ -337,7 +339,8 @@ void ED_node_shader_default(Scene *scene, ID *id) strength = 1.0f; break; } - case ID_LA: { + case ID_LA: + { Lamp *la = (Lamp *)id; la->nodetree = ntree; @@ -1456,7 +1459,7 @@ static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag) if (toggle_flag == NODE_OPTIONS && (node->typeinfo->flag & NODE_OPTIONS) == 0) continue; - if ( (tot_eq && tot_neq) || tot_eq == 0) + if ((tot_eq && tot_neq) || tot_eq == 0) node->flag |= toggle_flag; else node->flag &= ~toggle_flag; diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index 77583ae1325..b76cc05af5c 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -950,7 +950,7 @@ static int node_group_make_insert_selected(bNodeTree *ntree, bNode *gnode) int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT) && link->tonode != gnode); linkn = link->next; - if (gnode && ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode))) { + if ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode)) { /* remove all links to/from the gnode. * this can remove link information, but there's no general way to preserve it. */ diff --git a/source/blender/editors/space_node/node_header.c b/source/blender/editors/space_node/node_header.c index f461174d74f..e17961b6c7c 100644 --- a/source/blender/editors/space_node/node_header.c +++ b/source/blender/editors/space_node/node_header.c @@ -41,6 +41,7 @@ #include "BLF_translation.h" +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" @@ -64,7 +65,7 @@ static void do_node_add(bContext *C, bNodeTemplate *ntemp) SpaceNode *snode = CTX_wm_space_node(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar; - bNode *node; + bNode *node, *node_new; /* get location to add node at mouse */ for (ar = sa->regionbase.first; ar; ar = ar->next) { @@ -84,7 +85,7 @@ static void do_node_add(bContext *C, bNodeTemplate *ntemp) else node->flag &= ~NODE_TEST; } - /* node= */ node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]); + node_new = node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]); /* select previous selection before autoconnect */ for (node = snode->edittree->nodes.first; node; node = node->next) { @@ -95,7 +96,14 @@ static void do_node_add(bContext *C, bNodeTemplate *ntemp) for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TEST) node->flag &= ~NODE_SELECT; } - + + /* once this is called from an operator, this should be removed */ + if (node_new) { + char undostr[BKE_UNDO_STR_MAX]; + BLI_snprintf(undostr, sizeof(BKE_UNDO_STR_MAX), "Add Node %s", nodeLabel(node_new)); + BKE_write_undo(C, undostr); + } + snode_notify(C, snode); snode_dag_update(C, snode); } diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index 12c221b9273..fec7366ee73 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -560,7 +560,8 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) case LEFTMOUSE: case RIGHTMOUSE: - case MIDDLEMOUSE: { + case MIDDLEMOUSE: + { for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { link = linkdata->data; diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index 989b3999018..7881014ed54 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -627,11 +627,11 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, row = uiLayoutRow(split, FALSE); col = uiLayoutColumn(row, FALSE); - uiItemR(col, &inputptr, "default_value", 0, "", 0); + uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE); } else { row = uiLayoutRow(split, TRUE); - uiItemR(row, &inputptr, "default_value", 0, "", 0); + uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE); } } else diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 42fdd5173d4..21e06f00d8e 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -1273,8 +1273,8 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene * we don't expand items when searching in the datablocks but we * still want to highlight any filter matches. */ - if ( (SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) && - (tselem->flag & TSE_SEARCHMATCH)) + if ((SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) && + (tselem->flag & TSE_SEARCHMATCH)) { char col[4]; UI_GetThemeColorType4ubv(TH_MATCH, SPACE_OUTLINER, col); diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 63907f530eb..3e1ce1fea6e 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -1216,8 +1216,8 @@ static int treesort_obtype_alpha(const void *v1, const void *v2) else { /* 2nd we check ob type */ if (x1->idcode == ID_OB && x2->idcode == ID_OB) { - if ( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1; - else if ( ((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1; + if (((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1; + else if (((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1; else return 0; } else { @@ -1243,7 +1243,7 @@ static void outliner_sort(SpaceOops *soops, ListBase *lb) tselem = TREESTORE(te); /* sorting rules; only object lists or deformgroups */ - if ( (tselem->type == TSE_DEFGROUP) || (tselem->type == 0 && te->idcode == ID_OB)) { + if ((tselem->type == TSE_DEFGROUP) || (tselem->type == 0 && te->idcode == ID_OB)) { /* count first */ for (te = lb->first; te; te = te->next) totelem++; diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index d6a2b0a001e..0c316450c29 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -852,7 +852,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq struct ImBuf *ibuf = NULL; struct ImBuf *scope = NULL; struct View2D *v2d = &ar->v2d; - int rectx, recty; + /* int rectx, recty; */ /* UNUSED */ float viewrectx, viewrecty; float render_size = 0.0; float proxy_size = 100.0; @@ -874,8 +874,8 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq viewrectx = (render_size * (float)scene->r.xsch) / 100.0f; viewrecty = (render_size * (float)scene->r.ysch) / 100.0f; - rectx = viewrectx + 0.5f; - recty = viewrecty + 0.5f; + /* rectx = viewrectx + 0.5f; */ /* UNUSED */ + /* recty = viewrecty + 0.5f; */ /* UNUSED */ if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { viewrectx *= scene->r.xasp / scene->r.yasp; @@ -1049,6 +1049,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq if (mask) { int width, height; + float aspx = 1.0f, aspy = 1.0f; // ED_mask_get_size(C, &width, &height); //Scene *scene = CTX_data_scene(C); @@ -1058,6 +1059,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq ED_mask_draw_region(mask, ar, 0, 0, /* TODO */ width, height, + aspx, aspy, FALSE, TRUE, NULL, C); } diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 5a40c2ce4e7..f47eb339878 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -170,7 +170,7 @@ static void proxy_endjob(void *pjv) BKE_sequencer_proxy_rebuild_finish(link->data, pj->stop); } - BKE_sequencer_free_imbuf(pj->scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(pj->scene, &ed->seqbase, FALSE); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, pj->scene); } @@ -381,8 +381,8 @@ Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, const int mval[ while (seq) { if (seq->machine == (int)y) { /* check for both normal strips, and strips that have been flipped horizontally */ - if ( ((seq->startdisp < seq->enddisp) && (seq->startdisp <= x && seq->enddisp >= x)) || - ((seq->startdisp > seq->enddisp) && (seq->startdisp >= x && seq->enddisp <= x)) ) + if (((seq->startdisp < seq->enddisp) && (seq->startdisp <= x && seq->enddisp >= x)) || + ((seq->startdisp > seq->enddisp) && (seq->startdisp >= x && seq->enddisp <= x)) ) { if (BKE_sequence_tx_test(seq)) { @@ -1141,12 +1141,16 @@ static int sequencer_mute_exec(bContext *C, wmOperator *op) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if ((seq->flag & SEQ_LOCK) == 0) { if (selected) { /* mute unselected */ - if (seq->flag & SELECT) + if (seq->flag & SELECT) { seq->flag |= SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } else { - if ((seq->flag & SELECT) == 0) + if ((seq->flag & SELECT) == 0) { seq->flag |= SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } } } @@ -1188,12 +1192,16 @@ static int sequencer_unmute_exec(bContext *C, wmOperator *op) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if ((seq->flag & SEQ_LOCK) == 0) { if (selected) { /* unmute unselected */ - if (seq->flag & SELECT) + if (seq->flag & SELECT) { seq->flag &= ~SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } else { - if ((seq->flag & SELECT) == 0) + if ((seq->flag & SELECT) == 0) { seq->flag &= ~SEQ_MUTE; + BKE_sequence_invalidate_deendent(scene, seq); + } } } } @@ -1340,7 +1348,7 @@ static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2447,7 +2455,7 @@ static Sequence *sequence_find_parent(Scene *scene, Sequence *child) if (ed == NULL) return NULL; for (seq = ed->seqbasep->first; seq; seq = seq->next) { - if ( (seq != child) && seq_is_parent(seq, child) ) { + if ((seq != child) && seq_is_parent(seq, child)) { parent = seq; break; } @@ -2563,7 +2571,7 @@ static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op)) if (se) { // prevent setting the render size if sequence values aren't initialized - if ( (se->orig_width > 0) && (se->orig_height > 0) ) { + if ((se->orig_width > 0) && (se->orig_height > 0)) { scene->r.xsch = se->orig_width; scene->r.ysch = se->orig_height; WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene); @@ -2903,7 +2911,7 @@ static int sequencer_change_effect_input_exec(bContext *C, wmOperator *op) BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); /* important else we don't get the imbuf cache flushed */ - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2963,7 +2971,7 @@ static int sequencer_change_effect_type_exec(bContext *C, wmOperator *op) BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); /* important else we don't get the imbuf cache flushed */ - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -3036,7 +3044,7 @@ static int sequencer_change_path_exec(bContext *C, wmOperator *op) BKE_sequence_calc(scene, seq); /* important else we don't get the imbuf cache flushed */ - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); } else { /* lame, set rna filepath */ diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index f5c3a4c4d89..935bd13fcfc 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -118,8 +118,6 @@ void SEQUENCER_OT_paste(struct wmOperatorType *ot); void SEQUENCER_OT_rebuild_proxy(struct wmOperatorType *ot); -void SEQUENCER_OT_update_strip_length(struct wmOperatorType *ot); - /* preview specific operators */ void SEQUENCER_OT_view_all_preview(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_sequencer/sequencer_view.c b/source/blender/editors/space_sequencer/sequencer_view.c index fa39003bd55..d500bef4f02 100644 --- a/source/blender/editors/space_sequencer/sequencer_view.c +++ b/source/blender/editors/space_sequencer/sequencer_view.c @@ -162,8 +162,12 @@ static void sample_exit(bContext *C, wmOperator *op) static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event) { ARegion *ar = CTX_wm_region(C); + SpaceSeq *sseq = CTX_wm_space_seq(C); ImageSampleInfo *info; + if (sseq->mainb != SEQ_DRAW_IMG_IMBUF) + return OPERATOR_CANCELLED; + info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); info->art = ar->type; info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL); diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index a05bc5eddc7..ecce12b8cba 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -272,7 +272,7 @@ static short set_pchan_glColor(short colCode, int boneflag, short constflag) case PCHAN_COLOR_LINEBONE: { /* inner part in background color or constraint */ - if ( (constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) { + if ((constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS))) { if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0); else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0); else if (constflag & PCHAN_HAS_SPLINEIK) glColor3ub(200, 255, 0); @@ -1540,7 +1540,7 @@ static void draw_pose_dofs(Object *ob) for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { bone = pchan->bone; - if ( (bone) && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { + if ((bone != NULL) && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { if (bone->flag & BONE_SELECTED) { if (bone->layer & arm->layer) { if (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT)) { @@ -1701,8 +1701,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] * NOTE: this is the only case with (NO_DEFORM == 0) flag, as this is for envelope influence drawing */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_NO_DEFORM | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_NO_DEFORM | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0)) { if (bone->flag & (BONE_SELECTED)) { if (bone->layer & arm->layer) @@ -1732,8 +1732,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, arm->layer_used |= bone->layer; /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0)) { if (bone->layer & arm->layer) { int use_custom = (pchan->custom) && !(arm->flag & ARM_NO_CUSTOM); @@ -1748,8 +1748,9 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* catch exception for bone with hidden parent */ flag = bone->flag; - if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) ) + if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { flag &= ~BONE_CONNECTED; + } /* set temporary flag for drawing bone as active, but only if selected */ if (bone == arm->act_bone) @@ -1819,8 +1820,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, bone = pchan->bone; /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) { if (bone->layer & arm->layer) { if (pchan->custom) { @@ -1895,8 +1896,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, arm->layer_used |= bone->layer; /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */ - if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 && - ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) ) + if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) && + ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0)) { if (bone->layer & arm->layer) { const short constflag = pchan->constflag; @@ -1904,7 +1905,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* Draw a line from our root to the parent's tip * - only if V3D_HIDE_HELPLINES is enabled... */ - if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED) == 0) ) { + if ((do_dashed & 2) && ((bone->flag & BONE_CONNECTED) == 0)) { if (arm->flag & ARM_POSEMODE) { glLoadName(index & 0xFFFF); /* object tag, for bordersel optim */ UI_ThemeColor(TH_WIRE); @@ -2047,7 +2048,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, } /* Draw additional axes on the bone tail */ - if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) { + if ((arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE)) { glPushMatrix(); copy_m4_m4(bmat, pchan->pose_mat); bone_matrix_translate_y(bmat, pchan->bone->length); @@ -2134,8 +2135,9 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) /* catch exception for bone with hidden parent */ flag = eBone->flag; - if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) + if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) { flag &= ~BONE_CONNECTED; + } /* set temporary flag for drawing bone as active, but only if selected */ if (eBone == arm->act_edbone) @@ -2176,8 +2178,9 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) /* catch exception for bone with hidden parent */ flag = eBone->flag; - if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) + if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) { flag &= ~BONE_CONNECTED; + } /* set temporary flag for drawing bone as active, but only if selected */ if (eBone == arm->act_edbone) @@ -2378,7 +2381,11 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BKE_pose_free(posen); @@ -2386,7 +2393,6 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; ob->ipoflag = ipoflago; } @@ -2457,7 +2463,11 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base * } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BLI_dlrbTree_free(&keys); BKE_pose_free(posen); @@ -2466,7 +2476,6 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base * CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; } @@ -2544,7 +2553,11 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base) } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BKE_pose_free(posen); @@ -2552,7 +2565,6 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base) CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 5069c4219c3..da93e07748a 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -772,7 +772,8 @@ static int compareDrawOptionsEm(void *userData, int cur_index, int next_index) return 1; } -void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { Mesh *me = ob->data; @@ -871,7 +872,7 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) { /* get openl texture */ int mipmap = 1; - int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap) : 0; + int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, FALSE) : 0; float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; if (bindcode) { @@ -941,7 +942,8 @@ static int tex_mat_set_face_editmesh_cb(void *userData, int index) return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN); } -void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, const int draw_flags) +void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { if ((!BKE_scene_use_new_shading_nodes(scene)) || (draw_flags & DRAW_MODIFIERS_PREVIEW)) { draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, draw_flags); @@ -1017,7 +1019,8 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o /* Vertex Paint and Weight Paint */ -void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { DMSetDrawOptions facemask = NULL; Mesh *me = ob->data; @@ -1027,7 +1030,7 @@ void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *d if (draw_flags & DRAW_FACE_SELECT) facemask = wpaint__setSolidDrawOptions_facemask; - if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) { + if (ob->mode & OB_MODE_WEIGHT_PAINT) { if (do_light) { const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f}; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index f63171789a0..83bc094270b 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2904,7 +2904,7 @@ static void draw_em_fancy_edges(BMEditMesh *em, Scene *scene, View3D *v3d, if (ts->selectmode == SCE_SELECT_FACE) { draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act); } - else if ( (me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE) ) { + else if ((me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE)) { if (cageDM->drawMappedEdgesInterp && (ts->selectmode & SCE_SELECT_VERTEX)) { glShadeModel(GL_SMOOTH); draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol); @@ -3180,7 +3180,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, { Mesh *me = ob->data; - BMFace *efa_act = BM_active_face_get(em->bm, FALSE); /* annoying but active faces is stored differently */ + BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); /* annoying but active faces is stored differently */ BMEdge *eed_act = NULL; BMVert *eve_act = NULL; @@ -3347,8 +3347,8 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, draw_dm_vert_normals(em, scene, ob, cageDM); } - if ( (me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_FACEAREA | ME_DRAWEXTRA_FACEANG)) && - !(v3d->flag2 & V3D_RENDER_OVERRIDE)) + if ((me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_FACEAREA | ME_DRAWEXTRA_FACEANG)) && + !(v3d->flag2 & V3D_RENDER_OVERRIDE)) { draw_em_measure_stats(v3d, ob, em, &scene->unit); } @@ -3445,14 +3445,14 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D else if (dt == OB_WIRE || totface == 0) { draw_wire = OBDRAW_WIRE_ON; /* draw wire only, no depth buffer stuff */ } - else if ( ((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) || - check_object_draw_texture(scene, v3d, dt)) + else if (((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) || + check_object_draw_texture(scene, v3d, dt)) { - if ( (v3d->flag & V3D_SELECT_OUTLINE) && - ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - (base->flag & SELECT) && - !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) && - (draw_wire == OBDRAW_WIRE_OFF)) + if ((v3d->flag & V3D_SELECT_OUTLINE) && + ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && + (base->flag & SELECT) && + !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) && + (draw_wire == OBDRAW_WIRE_OFF)) { draw_mesh_object_outline(v3d, ob, dm); } @@ -3490,11 +3490,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f}; /* draw outline */ - if ( (v3d->flag & V3D_SELECT_OUTLINE) && - ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - (base->flag & SELECT) && - (draw_wire == OBDRAW_WIRE_OFF) && - (ob->sculpt == NULL)) + if ((v3d->flag & V3D_SELECT_OUTLINE) && + ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && + (base->flag & SELECT) && + (draw_wire == OBDRAW_WIRE_OFF) && + (ob->sculpt == NULL)) { draw_mesh_object_outline(v3d, ob, dm); } @@ -3522,11 +3522,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D else { Paint *p; - if ( (v3d->flag & V3D_SELECT_OUTLINE) && - ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - (base->flag & SELECT) && - (draw_wire == OBDRAW_WIRE_OFF) && - (ob->sculpt == NULL)) + if ((v3d->flag & V3D_SELECT_OUTLINE) && + ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && + (base->flag & SELECT) && + (draw_wire == OBDRAW_WIRE_OFF) && + (ob->sculpt == NULL)) { draw_mesh_object_outline(v3d, ob, dm); } @@ -3791,12 +3791,14 @@ static int drawDispListwire(ListBase *dlbase) } glEnd(); -/* (ton) this code crashes for me when resolv is 86 or higher... no clue */ -// glVertexPointer(3, GL_FLOAT, sizeof(float)*3*dl->nr, data + 3*nr); -// if (dl->flag & DL_CYCL_V) -// glDrawArrays(GL_LINE_LOOP, 0, dl->parts); -// else -// glDrawArrays(GL_LINE_STRIP, 0, dl->parts); +#if 0 + /* (ton) this code crashes for me when resolv is 86 or higher... no clue */ + glVertexPointer(3, GL_FLOAT, sizeof(float) * 3 * dl->nr, data + 3*nr); + if (dl->flag & DL_CYCL_V) + glDrawArrays(GL_LINE_LOOP, 0, dl->parts); + else + glDrawArrays(GL_LINE_STRIP, 0, dl->parts); +#endif } break; @@ -4375,7 +4377,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv timestep = psys_get_timestep(&sim); - if ( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) { + if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) { float mat[4][4]; mult_m4_m4m4(mat, ob->obmat, psys->imat); glMultMatrixf(mat); @@ -4921,7 +4923,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv pdd->ma_col = NULL; } - if ( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) { + if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) { glLoadMatrixf(rv3d->viewmat); } } @@ -5281,7 +5283,7 @@ static void tekenhandlesN(Nurb *nu, short sel, short hide_handles) a = nu->pntsu; while (a--) { if (bezt->hide == 0) { - if ( (bezt->f2 & SELECT) == sel) { + if ((bezt->f2 & SELECT) == sel) { fp = bezt->vec[0]; glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]); @@ -5292,14 +5294,14 @@ static void tekenhandlesN(Nurb *nu, short sel, short hide_handles) glVertex3fv(fp + 3); glVertex3fv(fp + 6); } - else if ( (bezt->f1 & SELECT) == sel) { + else if ((bezt->f1 & SELECT) == sel) { fp = bezt->vec[0]; glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]); glVertex3fv(fp); glVertex3fv(fp + 3); } - else if ( (bezt->f3 & SELECT) == sel) { + else if ((bezt->f3 & SELECT) == sel) { fp = bezt->vec[1]; glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]); @@ -5534,7 +5536,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel) for (a = nu->pntsu - 1; a > 0; a--, bp++) { if (bp->hide == 0 && bp1->hide == 0) { if (sel) { - if ( (bp->f1 & SELECT) && (bp1->f1 & SELECT) ) { + if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) { UI_ThemeColor(TH_NURB_SEL_ULINE); glBegin(GL_LINE_STRIP); @@ -5569,7 +5571,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel) for (a = nu->pntsv - 1; a > 0; a--, bp += ofs) { if (bp->hide == 0 && bp1->hide == 0) { if (sel) { - if ( (bp->f1 & SELECT) && (bp1->f1 & SELECT) ) { + if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) { UI_ThemeColor(TH_NURB_SEL_VLINE); glBegin(GL_LINE_STRIP); @@ -6958,9 +6960,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short } /* draw edit particles last so that they can draw over child particles */ - if ( (warning_recursive == 0) && - (dflag & DRAW_PICKING) == 0 && - (!scene->obedit)) + if ((warning_recursive == 0) && + (dflag & DRAW_PICKING) == 0 && + (!scene->obedit)) { if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) { @@ -7260,7 +7262,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short setlinestyle(0); } } - else if ((curcon->flag & CONSTRAINT_EXPAND) && (cti) && (cti->get_constraint_targets)) { + else if ((curcon->flag & CONSTRAINT_EXPAND) && (cti->get_constraint_targets)) { cti->get_constraint_targets(curcon, &targets); for (ct = targets.first; ct; ct = ct->next) { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 24395865a5e..8a334423ab0 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -48,6 +48,7 @@ #include "BLI_math.h" #include "BLI_rand.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BKE_anim.h" #include "BKE_camera.h" @@ -1388,16 +1389,21 @@ unsigned int view3d_sample_backbuf(ViewContext *vc, int x, int y) { unsigned int col; - if (x >= vc->ar->winx || y >= vc->ar->winy) return 0; + if (x >= vc->ar->winx || y >= vc->ar->winy) { + return 0; + } + x += vc->ar->winrct.xmin; y += vc->ar->winrct.ymin; view3d_validate_backbuf(vc); - glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); - glReadBuffer(GL_BACK); + glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); + glReadBuffer(GL_BACK); - if (ENDIAN_ORDER == B_ENDIAN) SWITCH_INT(col); + if (ENDIAN_ORDER == B_ENDIAN) { + BLI_endian_switch_uint32(&col); + } return WM_framebuffer_to_index(col); } @@ -2824,13 +2830,21 @@ static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar, int draw /* create render engine */ if (!rv3d->render_engine) { + RenderEngine *engine; + type = RE_engines_find(scene->r.engine); if (!(type->view_update && type->view_draw)) return 0; - rv3d->render_engine = RE_engine_create(type); - type->view_update(rv3d->render_engine, C); + engine = RE_engine_create(type); + + engine->tile_x = ceil(ar->winx/(float)scene->r.xparts); + engine->tile_y = ceil(ar->winy/(float)scene->r.yparts); + + type->view_update(engine, C); + + rv3d->render_engine = engine; } /* setup view matrices */ diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 5169d823bd8..7accdb0c0e4 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -475,8 +475,8 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event) { /* for dolly */ - float mval_f[2]; - VECCOPY2D(mval_f, event->mval); + const float mval_f[2] = {(float)event->mval[0], + (float)event->mval[1]}; ED_view3d_win_to_vector(vod->ar, mval_f, vod->mousevec); } @@ -2733,12 +2733,12 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } /* convert border to 3d coordinates */ - if ( (!gluUnProject(cent[0], cent[1], depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p[0], &p[1], &p[2])) || - (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p_corner[0], &p_corner[1], &p_corner[2]))) + if ((!gluUnProject(cent[0], cent[1], depth_close, + mats.modelview, mats.projection, (GLint *)mats.viewport, + &p[0], &p[1], &p[2])) || + (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, + mats.modelview, mats.projection, (GLint *)mats.viewport, + &p_corner[0], &p_corner[1], &p_corner[2]))) { return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 465279ee6ed..fd43333acfe 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -370,7 +370,7 @@ static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) case B_SEL_EDGE: if (em) { if (shift == 0 || em->selectmode == 0) { - if ( (em->selectmode ^ SCE_SELECT_EDGE) == SCE_SELECT_VERTEX) { + if ((em->selectmode ^ SCE_SELECT_EDGE) == SCE_SELECT_VERTEX) { if (ctrl) EDBM_selectmode_convert(em, SCE_SELECT_VERTEX, SCE_SELECT_EDGE); } em->selectmode = SCE_SELECT_EDGE; @@ -384,7 +384,9 @@ static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) case B_SEL_FACE: if (em) { if (shift == 0 || em->selectmode == 0) { - if ( ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)) { + if (((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || + ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)) + { if (ctrl) EDBM_selectmode_convert(em, (ts->selectmode ^ SCE_SELECT_FACE), SCE_SELECT_FACE); } em->selectmode = SCE_SELECT_FACE; diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 71e87e73747..5bfabf4fc4a 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -175,7 +175,7 @@ void VIEW3D_OT_game_start(struct wmOperatorType *ot); int ED_view3d_boundbox_clip(RegionView3D * rv3d, float obmat[][4], struct BoundBox *bb); void view3d_smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *, - float *ofs, float *quat, float *dist, float *lens); + float *ofs, float *quat, float *dist, float *lens); void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 6f3cc744537..5712144caf1 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -119,8 +119,8 @@ int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const int m initgrabz(vc->rv3d, fp[0], fp[1], fp[2]); if (mval_cpy[0] != IS_CLIPPED) { - float mval_f[2]; - VECSUB2D(mval_f, mval_cpy, mval); + const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), + (float)(mval_cpy[1] - mval[1])}; ED_view3d_win_to_delta(vc->ar, mval_f, dvec); sub_v3_v3(fp, dvec); @@ -1527,10 +1527,10 @@ int edge_inside_circle(int centx, int centy, int rad, int x1, int y1, int x2, in int radsq = rad * rad; /* check points in circle itself */ - if ( (x1 - centx) * (x1 - centx) + (y1 - centy) * (y1 - centy) <= radsq) { + if ((x1 - centx) * (x1 - centx) + (y1 - centy) * (y1 - centy) <= radsq) { return TRUE; } - else if ( (x2 - centx) * (x2 - centx) + (y2 - centy) * (y2 - centy) <= radsq) { + else if ((x2 - centx) * (x2 - centx) + (y2 - centy) * (y2 - centy) <= radsq) { return TRUE; } else { @@ -2027,36 +2027,6 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) WM_operator_properties_gesture_border(ot, TRUE); } -/* much like facesel_face_pick()*/ -/* returns 0 if not found, otherwise 1 */ -static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size) -{ - ViewContext vc; - view3d_set_viewcontext(C, &vc); - - if (!me || me->totvert == 0) - return 0; - - if (size > 0) { - /* sample rect to increase changes of selecting, so that when clicking - * on an face in the backbuf, we can still select a vert */ - - int dist; - *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totvert + 1, &dist, 0, NULL, NULL); - } - else { - /* sample only on the exact position */ - *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); - } - - if ((*index) <= 0 || (*index) > (unsigned int)me->totvert) - return 0; - - (*index)--; - - return 1; -} - /* mouse selection in weight paint */ /* gets called via generic mouse select operator */ static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], short extend, short deselect, short toggle, Object *obact) @@ -2065,8 +2035,8 @@ static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], shor unsigned int index = 0; MVert *mv; - if (vertsel_vert_pick(C, me, mval, &index, 50)) { - mv = me->mvert + index; + if (ED_mesh_pick_vert(C, me, mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE)) { + mv = &me->mvert[index]; if (extend) { mv->flag |= SELECT; } @@ -2116,7 +2086,7 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) if (obedit && object == FALSE) { if (obedit->type == OB_MESH) - retval = mouse_mesh(C, event->mval, extend, deselect, toggle); + retval = EDBM_select_pick(C, event->mval, extend, deselect, toggle); else if (obedit->type == OB_ARMATURE) retval = mouse_armature(C, event->mval, extend, deselect, toggle); else if (obedit->type == OB_LATTICE) @@ -2268,6 +2238,7 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m /* bbsel= */ /* UNUSED */ EDBM_backbuf_circle_init(vc, mval[0], mval[1], (short)(rad + 1.0f)); edbm_backbuf_check_and_select_tfaces(me, select == LEFTMOUSE); EDBM_backbuf_free(); + paintface_flush_flags(ob); } } @@ -2496,7 +2467,7 @@ static void armature_circle_select(ViewContext *vc, int select, const int mval[2 /* only if the endpoints didn't get selected, deal with the middle of the bone too */ /* XXX should we just do this always? */ - if ( (didpoint == 0) && edge_inside_circle(mval[0], mval[1], rad, sco1[0], sco1[1], sco2[0], sco2[1]) ) { + if ((didpoint == 0) && edge_inside_circle(mval[0], mval[1], rad, sco1[0], sco1[1], sco2[0], sco2[1])) { if (select) ebone->flag |= BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED; else diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index fc97b9bbb36..4ca9bd95485 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -101,8 +101,8 @@ static void special_transvert_update(Object *obedit) DAG_id_tag_update(obedit->data, 0); if (obedit->type == OB_MESH) { - Mesh *me = obedit->data; - BM_mesh_normals_update(me->edit_btmesh->bm, TRUE); /* does face centers too */ + BMEditMesh *em = BMEdit_FromObject(obedit); + BM_mesh_normals_update(em->bm, TRUE); /* does face centers too */ } else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { Curve *cu = obedit->data; @@ -229,8 +229,7 @@ static void make_trans_verts(Object *obedit, float min[3], float max[3], int mod zero_v3(centroid); if (obedit->type == OB_MESH) { - Mesh *me = obedit->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(obedit); BMesh *bm = em->bm; BMIter iter; void *userdata[2] = {em, NULL}; @@ -992,11 +991,11 @@ static int snap_curs_to_active(bContext *C, wmOperator *UNUSED(op)) if (obedit) { if (obedit->type == OB_MESH) { + BMEditMesh *em = BMEdit_FromObject(obedit); /* check active */ - Mesh *me = obedit->data; BMEditSelection ese; - if (BM_select_history_active_get(me->edit_btmesh->bm, &ese)) { + if (BM_select_history_active_get(em->bm, &ese)) { BM_editselection_center(&ese, curs); } diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index ee1ead76f7c..b40e880591a 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -111,7 +111,7 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa) block = uiLayoutGetBlock(pa->layout); if (!WM_operator_check_ui_enabled(C, op->type->name)) - uiLayoutSetEnabled(pa->layout, 0); + uiLayoutSetEnabled(pa->layout, FALSE); /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */ uiBlockSetHandleFunc(block, ED_undo_operator_repeat_cb_evt, op); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index fbbf23beca4..c25bb80bfde 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -87,8 +87,9 @@ void view3d_operator_needs_opengl(const bContext *C) void view3d_region_operator_needs_opengl(wmWindow *win, ARegion *ar) { /* for debugging purpose, context should always be OK */ - if ((ar == NULL) || (ar->regiontype != RGN_TYPE_WINDOW)) + if ((ar == NULL) || (ar->regiontype != RGN_TYPE_WINDOW)) { printf("view3d_region_operator_needs_opengl error, wrong region\n"); + } else { RegionView3D *rv3d = ar->regiondata; @@ -1652,7 +1653,7 @@ static void game_set_commmandline_options(GameData *gm) SYS_SystemHandle syshandle; int test; - if ( (syshandle = SYS_GetSystem()) ) { + if ((syshandle = SYS_GetSystem())) { /* User defined settings */ test = (U.gameflags & USER_DISABLE_MIPMAP); GPU_set_mipmap(!test); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index c5f9546e467..dccd0c27234 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -65,6 +65,7 @@ #include "BKE_particle.h" #include "BKE_pointcache.h" #include "BKE_unit.h" +#include "BKE_mask.h" #include "ED_image.h" #include "ED_keyframing.h" @@ -164,9 +165,7 @@ static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy) void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) { if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) { - float mval_f[2]; - mval_f[0] = dx; - mval_f[1] = dy; + const float mval_f[2] = {(float)dx, (float)dy}; ED_view3d_win_to_delta(t->ar, mval_f, r_vec); } else if (t->spacetype == SPACE_IMAGE) { @@ -230,9 +229,27 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) project_int_noclip(t->ar, vec, adr); } else if (t->spacetype == SPACE_IMAGE) { + SpaceImage *sima = t->sa->spacedata.first; + if (t->options & CTX_MASK) { + /* not working quite right, TODO (see below too) */ + float aspx, aspy; float v[2]; - ED_mask_point_pos__reverse(t->sa, t->ar, vec[0], vec[1], &v[0], &v[1]); + + ED_space_image_get_aspect(sima, &aspx, &aspy); + + copy_v2_v2(v, vec); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + BKE_mask_coord_to_image(sima->image, &sima->iuser, v, v); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + ED_image_point_pos__reverse(sima, t->ar, v, v); + adr[0] = v[0]; adr[1] = v[1]; } @@ -280,23 +297,41 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) adr[1] = out[1]; } else if (t->spacetype == SPACE_CLIP) { - float v[2]; - float aspx = 1.0f, aspy = 1.0f; + SpaceClip *sc = t->sa->spacedata.first; - copy_v2_v2(v, vec); + if (t->options & CTX_MASK) { + /* not working quite right, TODO (see above too) */ + float aspx, aspy; + float v[2]; - if (t->options & CTX_MOVIECLIP) { - ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); - } - else if (t->options & CTX_MASK) { - /* MASKTODO - not working as expected */ - ED_space_clip_get_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); + + copy_v2_v2(v, vec); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v); + + v[0] = v[0] / aspx; + v[1] = v[1] / aspy; + + ED_clip_point_stable_pos__reverse(sc, t->ar, v, v); + + adr[0] = v[0]; + adr[1] = v[1]; } + else if (t->options & CTX_MOVIECLIP) { + float v[2], aspx, aspy; + + copy_v2_v2(v, vec); + ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); - v[0] /= aspx; - v[1] /= aspy; + v[0] /= aspx; + v[1] /= aspy; - UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + } } else if (t->spacetype == SPACE_NODE) { UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], adr, adr + 1); @@ -2431,8 +2466,9 @@ void initWarp(TransInfo *t) mul_m3_v3(t->data[i].mtx, center); mul_m4_v3(t->viewmat, center); sub_v3_v3(center, t->viewmat[3]); - if (i) + if (i) { minmax_v3v3_v3(min, max, center); + } else { copy_v3_v3(max, center); copy_v3_v3(min, center); @@ -2739,12 +2775,14 @@ static void headerResize(TransInfo *t, float vec[3], char *str) } } else { - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); - else + } + else { spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + } } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { @@ -3647,9 +3685,10 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) { int i, do_split = t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1 : 0; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { bUnit_AsString(&tvec[i * NUM_STR_REP_LEN], NUM_STR_REP_LEN, dvec[i] * t->scene->unit.scale_length, 4, t->scene->unit.system, B_UNIT_LENGTH, do_split, 1); + } } else { sprintf(&tvec[0], "%.4f", dvec[0]); @@ -3691,12 +3730,14 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) } } else { - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { spos += sprintf(spos, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext); - else + } + else { spos += sprintf(spos, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, &autoik[0]); + } } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { @@ -4749,11 +4790,10 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo static int createSlideVerts(TransInfo *t) { - Mesh *me = t->obedit->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(t->obedit); BMesh *bm = em->bm; BMIter iter, iter2; - BMEdge *e, *e1 /*, *ee, *le */ /* UNUSED */; + BMEdge *e, *e1; BMVert *v, *v2, *first; BMLoop *l, *l1, *l2; TransDataSlideVert *sv_array; @@ -4765,9 +4805,10 @@ static int createSlideVerts(TransInfo *t) ARegion *ar = t->ar; float projectMat[4][4]; float mval[2] = {(float)t->mval[0], (float)t->mval[1]}; - float start[3] = {0.0f, 0.0f, 0.0f}, dir[3], end[3] = {0.0f, 0.0f, 0.0f}; + float start[3] = {0.0f, 0.0f, 0.0f}, end[3] = {0.0f, 0.0f, 0.0f}; float vec[3], vec2[3] /*, lastvec[3], size, dis=0.0, z */ /* UNUSED */; - int numsel, i, j; + float dir[3], maxdist, (*loop_dir)[3], *loop_maxdist; + int numsel, i, j, loop_nr, l_nr; if (t->spacetype == SPACE_VIEW3D) { /* background mode support */ @@ -4842,6 +4883,7 @@ static int createSlideVerts(TransInfo *t) } sv_array = MEM_callocN(sizeof(TransDataSlideVert) * j, "sv_array"); + loop_nr = 0; j = 0; while (1) { @@ -4904,6 +4946,8 @@ static int createSlideVerts(TransInfo *t) sv->v = v; sv->origvert = *v; + sv->loop_nr = loop_nr; + copy_v3_v3(sv->upvec, vec); if (l2) copy_v3_v3(sv->downvec, vec2); @@ -4926,6 +4970,7 @@ static int createSlideVerts(TransInfo *t) sv = sv_array + j + 1; sv->v = v; sv->origvert = *v; + sv->loop_nr = loop_nr; l = BM_face_other_edge_loop(l1->f, l1->e, v); sv->up = BM_edge_other_vert(l->e, v); @@ -4952,6 +4997,8 @@ static int createSlideVerts(TransInfo *t) BM_elem_flag_disable(v, BM_ELEM_TAG); BM_elem_flag_disable(v2, BM_ELEM_TAG); } while (e != first->e && l1); + + loop_nr++; } /* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */ @@ -4959,21 +5006,24 @@ static int createSlideVerts(TransInfo *t) sld->sv = sv_array; sld->totsv = j; - /*find mouse vector*/ - /* dis = z = -1.0f; */ /* UNUSED */ - /* size = 50.0; */ /* UNUSED */ - /* zero_v3(lastvec); */ /* UNUSED */ + /* find mouse vectors, the global one, and one per loop in case we have + * multiple loops selected, in case they are oriented different */ zero_v3(dir); - /* ee = le = NULL; */ /* UNUSED */ + maxdist = -1.0f; + + loop_dir = MEM_callocN(sizeof(float) * 3 * loop_nr, "sv loop_dir"); + loop_maxdist = MEM_callocN(sizeof(float) * loop_nr, "sv loop_maxdist"); + for (j = 0; j < loop_nr; j++) + loop_maxdist[j] = -1.0f; + BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { BMIter iter2; BMEdge *e2; - float vec1[3], dis2, mval[2] = {t->mval[0], t->mval[1]}, d; + float vec1[3], mval[2] = {t->mval[0], t->mval[1]}, d; /* search cross edges for visible edge to the mouse cursor, * then use the shared vertex to calculate screen vector*/ - dis2 = -1.0f; for (i = 0; i < 2; i++) { v = i ? e->v1 : e->v2; BM_ITER_ELEM (e2, &iter2, v, BM_EDGES_OF_VERT) { @@ -5001,17 +5051,23 @@ static int createSlideVerts(TransInfo *t) ED_view3d_project_float_v3(ar, sv_array[j].up->co, vec2, projectMat); } else { - add_v3_v3v3(vec1, v->co, sv_array[j].upvec); + add_v3_v3v3(vec2, v->co, sv_array[j].upvec); ED_view3d_project_float_v3(ar, vec2, vec2, projectMat); } - + + /* global direction */ d = dist_to_line_segment_v2(mval, vec1, vec2); - if (dis2 == -1.0f || d < dis2) { - dis2 = d; - /* ee = e2; */ /* UNUSED */ - /* size = len_v3v3(vec1, vec2); */ /* UNUSED */ + if (maxdist == -1.0f || d < maxdist) { + maxdist = d; sub_v3_v3v3(dir, vec1, vec2); } + + /* per loop direction */ + l_nr = sv_array[j].loop_nr; + if (loop_maxdist[l_nr] == -1.0f || d < loop_maxdist[l_nr]) { + loop_maxdist[l_nr] = d; + sub_v3_v3v3(loop_dir[l_nr], vec1, vec2); + } } } } @@ -5045,6 +5101,14 @@ static int createSlideVerts(TransInfo *t) } BLI_smallhash_insert(&sld->vhash, (uintptr_t)sv_array->v, sv_array); + + /* switch up/down if loop direction is different from global direction */ + l_nr = sv_array->loop_nr; + if (dot_v3v3(loop_dir[l_nr], dir) < 0.0f) { + swap_v3_v3(sv_array->upvec, sv_array->downvec); + SWAP(BMVert, sv_array->vup, sv_array->vdown); + SWAP(BMVert*, sv_array->up, sv_array->down); + } } if (rv3d) @@ -5055,7 +5119,7 @@ static int createSlideVerts(TransInfo *t) /*zero out start*/ zero_v3(start); - + /*dir holds a vector along edge loop*/ copy_v3_v3(end, dir); mul_v3_fl(end, 0.5f); @@ -5072,6 +5136,8 @@ static int createSlideVerts(TransInfo *t) BLI_smallhash_release(&table); BMBVH_FreeBVH(btree); + MEM_freeN(loop_dir); + MEM_freeN(loop_maxdist); return 1; } @@ -5333,7 +5399,8 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event) return 1; } break; - case FKEY: { + case FKEY: + { if (event->val == KM_PRESS) { if (sld->is_proportional == FALSE) { sld->flipped_vtx = !sld->flipped_vtx; @@ -5342,13 +5409,16 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event) } break; } - case EVT_MODAL_MAP: { + case EVT_MODAL_MAP: + { switch (event->val) { - case TFM_MODAL_EDGESLIDE_DOWN: { + case TFM_MODAL_EDGESLIDE_DOWN: + { sld->curr_sv_index = ((sld->curr_sv_index - 1) + sld->totsv) % sld->totsv; break; } - case TFM_MODAL_EDGESLIDE_UP: { + case TFM_MODAL_EDGESLIDE_UP: + { sld->curr_sv_index = (sld->curr_sv_index + 1) % sld->totsv; break; } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 8a7148aad95..e645cb2fed6 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -198,6 +198,8 @@ typedef struct TransDataSlideVert { float edge_len; float upvec[3], downvec[3]; + + int loop_nr; } TransDataSlideVert; typedef struct SlideData { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 7f77341447d..181f9fe6036 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -861,7 +861,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) data->rootbone = 0; /* watch-it! has to be 0 here, since we're still on the same bone for the first time through the loop [#25885] */ /* we only include bones that are part of a continual connected chain */ - while (pchan) { + do { /* here, we set ik-settings for bone from pchan->protectflag */ // XXX: careful with quats/axis-angle rotations where we're locking 4d components if (pchan->protectflag & OB_LOCK_ROTX) pchan->ikflag |= BONE_IK_NO_XDOF_TEMP; @@ -876,7 +876,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) pchan = pchan->parent; else pchan = NULL; - } + } while (pchan); /* make a copy of maximum chain-length */ data->max_rootbone = data->rootbone; @@ -992,6 +992,9 @@ static void createTransPose(TransInfo *t, Object *ob) t->flag |= T_POSE; t->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */ + /* disable PET, its not usable in pose mode yet [#32444] */ + t->flag &= ~(T_PROP_EDIT | T_PROP_CONNECTED); + /* init trans data */ td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransPoseBone"); tdx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "TransPoseBoneExt"); @@ -4990,7 +4993,7 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o static void special_aftertrans_update__mask(bContext *C, TransInfo *t) { - Mask *mask; + Mask *mask = NULL; if (t->spacetype == SPACE_CLIP) { SpaceClip *sc = t->sa->spacedata.first; @@ -5606,6 +5609,9 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t) return; } + /* nodes dont support PET and probably never will */ + t->flag &= ~(T_PROP_EDIT | T_PROP_CONNECTED); + /* set transform flags on nodes */ for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_SELECT && is_node_parent_select(node) == FALSE) { diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index bcebca52ce8..325dbe639b4 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -40,6 +40,7 @@ #include "DNA_armature_types.h" #include "DNA_lattice_types.h" #include "DNA_screen_types.h" +#include "DNA_sequence_types.h" #include "DNA_space_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -894,6 +895,17 @@ static void recalcData_view3d(TransInfo *t) /* helper for recalcData() - for sequencer transforms */ static void recalcData_sequencer(TransInfo *t) { + Editing *ed = BKE_sequencer_editing_get(t->scene, FALSE); + Sequence *seq; + + SEQ_BEGIN(ed, seq) + { + if (seq->flag & SELECT) { + BKE_sequence_invalidate_deendent(t->scene, seq); + } + } + SEQ_END + BKE_sequencer_preprocessed_cache_cleanup(); flushTransSeq(t); diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 237f6b35eb0..a155ff7786a 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -565,8 +565,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], ob = obedit; if (ob->type == OB_MESH) { - Mesh *me = ob->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(ob); BMVert *eve; BMEditSelection ese; float vec[3] = {0, 0, 0}; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 89cb83e3661..b88ae68e00b 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -410,9 +410,8 @@ static void initSnappingMode(TransInfo *t) } else { /* force project off when not supported */ - if (ts->snap_mode != SCE_SNAP_MODE_FACE) { + if (t->spacetype == SPACE_IMAGE || ts->snap_mode != SCE_SNAP_MODE_FACE) t->tsnap.project = 0; - } t->tsnap.mode = ts->snap_mode; } diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index c13e6c16413..e0991c48fa6 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -62,6 +62,7 @@ set(SRC ../include/ED_lattice.h ../include/ED_logic.h ../include/ED_markers.h + ../include/ED_mask.h ../include/ED_mball.h ../include/ED_mesh.h ../include/ED_node.h diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 6d9f2732d8a..23d6b0a075e 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -45,10 +45,10 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "ED_armature.h" +#include "ED_image.h" #include "ED_mesh.h" #include "ED_object.h" #include "ED_sculpt.h" @@ -67,6 +67,7 @@ void ED_editors_init(bContext *C) { + wmWindowManager *wm = CTX_wm_manager(C); Main *bmain = CTX_data_main(C); Scene *sce = CTX_data_scene(C); Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL; @@ -86,6 +87,11 @@ void ED_editors_init(bContext *C) ED_object_toggle_modes(C, mode); } } + + /* image editor paint mode */ + if (sce) { + ED_space_image_paint_update(wm, sce->toolsettings); + } } /* frees all editmode stuff */ diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index 18610d57bbd..9a3b0476205 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -29,8 +29,6 @@ * \ingroup edutil */ - - #include <stdlib.h> #include <string.h> #include <math.h> @@ -44,7 +42,7 @@ #include "BLI_dynstr.h" #include "BLI_utildefines.h" - +#include "BKE_blender.h" #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_global.h" @@ -82,8 +80,6 @@ static void error(const char *UNUSED(arg)) {} /* ****** XXX ***** */ - -#define MAXUNDONAME 64 typedef struct UndoElem { struct UndoElem *next, *prev; ID id; // copy of editmode object ID @@ -91,7 +87,7 @@ typedef struct UndoElem { int type; // type of edited object void *undodata; uintptr_t undosize; - char name[MAXUNDONAME]; + char name[BKE_UNDO_STR_MAX]; void * (*getdata)(bContext * C); void (*freedata)(void *); void (*to_editmode)(void *, void *, void *); diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index 4213ff68cf2..5eafc3e65a9 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -74,8 +74,6 @@ #include "util_intern.h" -#define MAXUNDONAME 64 /* XXX, make common define */ - /* ***************** generic undo system ********************* */ void ED_undo_push(bContext *C, const char *str) @@ -109,8 +107,7 @@ void ED_undo_push(bContext *C, const char *str) PE_undo_push(CTX_data_scene(C), str); } else { - if (U.uiflag & USER_GLOBALUNDO) - BKE_write_undo(C, str); + BKE_write_undo(C, str); } if (wm->file_saved) { @@ -283,7 +280,7 @@ static int ed_undo_exec(bContext *C, wmOperator *UNUSED(op)) static int ed_undo_push_exec(bContext *C, wmOperator *op) { - char str[MAXUNDONAME]; + char str[BKE_UNDO_STR_MAX]; RNA_string_get(op->ptr, "message", str); ED_undo_push(C, str); return OPERATOR_FINISHED; @@ -321,7 +318,7 @@ void ED_OT_undo_push(wmOperatorType *ot) ot->flag = OPTYPE_INTERNAL; - RNA_def_string(ot->srna, "message", "Add an undo step *function may be moved*", MAXUNDONAME, "Undo Message", ""); + RNA_def_string(ot->srna, "message", "Add an undo step *function may be moved*", BKE_UNDO_STR_MAX, "Undo Message", ""); } void ED_OT_redo(wmOperatorType *ot) diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 1f78bc6bddf..d6794912043 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -415,7 +415,7 @@ static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob) glColor3ub(112, 112, 112); - if (me->mtface) { + if (me->mtpoly) { MPoly *mpoly = me->mpoly; MTexPoly *tface = me->mtpoly; MLoopUV *mloopuv; @@ -455,8 +455,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) StitchPreviewer *stitch_preview = uv_get_stitch_previewer(); - activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */ - activef = BM_active_face_get(bm, FALSE); + activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE, FALSE); /* will be set to NULL if hidden */ + activef = BM_active_face_get(bm, FALSE, FALSE); ts = scene->toolsettings; drawfaces = draw_uvs_face_check(scene); diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h index d258d271833..f0ff79ae25e 100644 --- a/source/blender/editors/uvedit/uvedit_intern.h +++ b/source/blender/editors/uvedit/uvedit_intern.h @@ -46,10 +46,6 @@ struct BMLoop; struct BMEdge; struct BMVert; -/* id can be from 0 to 3 */ -#define TF_PIN_MASK(id) (TF_PIN1 << id) -#define TF_SEL_MASK(id) (TF_SEL1 << id) - /* visibility and selection */ int uvedit_face_visible_nolocal(struct Scene *scene, struct BMFace *efa); diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 6f3e6bee850..5008c35e46a 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -174,6 +174,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im BMIter iter; MTexPoly *tf; int update = 0; + int sloppy = TRUE; + int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* skip assigning these procedural images... */ if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)) @@ -190,8 +192,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (BKE_scene_use_new_shading_nodes(scene)) { /* new shading system, assign image in material */ - int sloppy = 1; - BMFace *efa = BM_active_face_get(em->bm, sloppy); + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) ED_object_assign_active_image(bmain, obedit, efa->mat_nr + 1, ima); @@ -2056,7 +2057,7 @@ static void UV_OT_select(wmOperatorType *ot) ot->name = "Select"; ot->description = "Select UV vertices"; ot->idname = "UV_OT_select"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->exec = select_exec; @@ -2101,7 +2102,7 @@ static void UV_OT_select_loop(wmOperatorType *ot) ot->name = "Loop Select"; ot->description = "Select a loop of connected UV vertices"; ot->idname = "UV_OT_select_loop"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->exec = select_loop_exec; @@ -2203,7 +2204,7 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) ot->name = "Select Linked Pick"; ot->description = "Select all UV vertices linked under the mouse"; ot->idname = "UV_OT_select_linked_pick"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->invoke = select_linked_pick_invoke; diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index b4903390408..c95b2e85248 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -192,13 +192,16 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, handle = param_construct_begin(); if (correct_aspect) { - efa = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + + efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) { float aspx, aspy; tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); - ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, NULL, &aspx, &aspy); if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); @@ -380,14 +383,17 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e handle = param_construct_begin(); if (correct_aspect) { - editFace = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + + editFace = BM_active_face_get(em->bm, sloppy, selected); if (editFace) { MTexPoly *tf; float aspx, aspy; tf = CustomData_bmesh_get(&em->bm->pdata, editFace->head.data, CD_MTEXPOLY); - ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, NULL, &aspx, &aspy); if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); @@ -1003,7 +1009,9 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) static void correct_uv_aspect(BMEditMesh *em) { - BMFace *efa = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); BMLoop *l; BMIter iter, liter; MLoopUV *luv; @@ -1013,7 +1021,7 @@ static void correct_uv_aspect(BMEditMesh *em) MTexPoly *tf; tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); - ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, NULL, &aspx, &aspy); } if (aspx == aspy) diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 629283ce50d..1729ac06f5a 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -159,18 +159,18 @@ int GPU_buffer_legacy(struct DerivedMesh *dm ); typedef struct GPU_Buffers GPU_Buffers; GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4], - struct MFace *mface, struct MVert *mvert, - int *face_indices, int totface); + struct MFace *mface, struct MVert *mvert, + int *face_indices, int totface); void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert, - int *vert_indices, int totvert, const float *vmask); + int *vert_indices, int totvert, const float *vmask); GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid, - unsigned int **grid_hidden, int gridsize); + unsigned int **grid_hidden, int gridsize); void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids, - const struct DMFlagMat *grid_flag_mats, - int *grid_indices, int totgrid, const struct CCGKey *key); + const struct DMFlagMat *grid_flag_mats, + int *grid_indices, int totgrid, const struct CCGKey *key); void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial); diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 7a71f33d3d0..467adbe10b8 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -122,7 +122,7 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap); void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h, int mipmap); void GPU_update_images_framechange(void); int GPU_update_image_time(struct Image *ima, double time); -int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap); +int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap, int ncd); void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int rectw, int recth, int mipmap, int use_hight_bit_depth, struct Image *ima); void GPU_create_gl_tex_compressed(unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, struct Image *ima, struct ImBuf *ibuf); int GPU_upload_dxt_texture(struct ImBuf *ibuf); diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index b04da04258e..198d002ff0d 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -111,7 +111,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels); GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]); GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]); GPUTexture *GPU_texture_from_blender(struct Image *ima, - struct ImageUser *iuser, double time, int mipmap); + struct ImageUser *iuser, int ncd, double time, int mipmap); void GPU_texture_free(GPUTexture *tex); void GPU_texture_ref(GPUTexture *tex); diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index a725ff4385d..baa557c3484 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -107,7 +107,7 @@ typedef struct GPUNodeStack { GPUNodeLink *GPU_attribute(int type, const char *name); GPUNodeLink *GPU_uniform(float *num); GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data); -GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser); +GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, int ncd); GPUNodeLink *GPU_texture(int size, float *pixels); GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data); GPUNodeLink *GPU_socket(GPUNodeStack *sock); @@ -135,6 +135,8 @@ int GPU_material_bound(GPUMaterial *material); void GPU_material_vertex_attributes(GPUMaterial *material, struct GPUVertexAttribs *attrib); +int GPU_material_do_color_management(GPUMaterial *mat); + /* Exported shading */ typedef struct GPUShadeInput { diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index a88a075383d..25990e8fc6e 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -761,7 +761,7 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap) /* now bind the textures */ for (input=inputs->first; input; input=input->next) { if (input->ima) - input->tex = GPU_texture_from_blender(input->ima, input->iuser, time, mipmap); + input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->imagencd, time, mipmap); if (input->tex && input->bindtex) { GPU_texture_bind(input->tex, input->texid); @@ -917,6 +917,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->ima = link->ptr1; input->iuser = link->ptr2; + input->imagencd = link->imagencd; input->textarget = GL_TEXTURE_2D; input->textype = GPU_TEX2D; MEM_freeN(link); @@ -1109,13 +1110,14 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data) return link; } -GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser) +GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int ncd) { GPUNodeLink *link = GPU_node_link_create(0); link->image= 1; link->ptr1= ima; link->ptr2= iuser; + link->imagencd= ncd; return link; } diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h index db334b8bf19..3010937a2f3 100644 --- a/source/blender/gpu/intern/gpu_codegen.h +++ b/source/blender/gpu/intern/gpu_codegen.h @@ -91,6 +91,7 @@ struct GPUNodeLink { const char *attribname; int image; + int imagencd; int texture; int texturesize; @@ -137,6 +138,7 @@ typedef struct GPUInput { struct Image *ima; /* image */ struct ImageUser *iuser;/* image user */ + int imagencd; /* image does not contain color data */ float *dynamicvec; /* vector data in case it is dynamic */ int dynamictype; /* origin of the dynamic uniform (GPUDynamicType) */ void *dynamicdata; /* data source of the dynamic uniform */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index d03913af417..4314a784511 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -422,7 +422,7 @@ static void gpu_verify_reflection(Image *ima) } } -int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap) +int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap, int ncd) { ImBuf *ibuf = NULL; unsigned int *bind = NULL; @@ -492,7 +492,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int } /* TODO unneeded when float images are correctly treated as linear always */ - if (ibuf->profile == IB_PROFILE_LINEAR_RGB) + if (!ncd && ibuf->profile == IB_PROFILE_LINEAR_RGB) do_color_management = TRUE; if (ibuf->rect==NULL) @@ -807,7 +807,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend) gpu_verify_alpha_blend(alphablend); gpu_verify_reflection(ima); - if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) { + if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap, FALSE)) { GTS.curtile= GTS.tile; GTS.curima= GTS.ima; GTS.curtilemode= GTS.tilemode; diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 4974d57d64c..c5f427fbcab 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -522,7 +522,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels) return tex; } -GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap) +GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int ncd, double time, int mipmap) { GPUTexture *tex; GLint w, h, border, lastbindcode, bindcode; @@ -530,7 +530,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode); GPU_update_image_time(ima, time); - bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap); + bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, ncd); if (ima->gputexture) { ima->gputexture->bindcode = bindcode; diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index efb24375729..61be4057843 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -387,7 +387,7 @@ void gpu_material_add_node(GPUMaterial *material, GPUNode *node) /* Code generation */ -static int gpu_do_color_management(GPUMaterial *mat) +int GPU_material_do_color_management(GPUMaterial *mat) { return ((mat->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) && !((mat->scene->gm.flag & GAME_GLSL_NO_COLOR_MANAGEMENT))); @@ -645,7 +645,7 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink ** GPU_link(mat, "shade_light_texture", GPU_builtin(GPU_VIEW_POSITION), - GPU_image(mtex->tex->ima, &mtex->tex->iuser), + GPU_image(mtex->tex->ima, &mtex->tex->iuser, FALSE), GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob), &tex_rgb); texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb); @@ -1028,7 +1028,7 @@ static void do_material_tex(GPUShadeInput *shi) talpha = 0; if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb); + GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb); rgbnor= TEX_RGB; if (tex->imaflag & TEX_USEALPHA) @@ -1076,7 +1076,7 @@ static void do_material_tex(GPUShadeInput *shi) } if (tex->type==TEX_IMAGE) - if (gpu_do_color_management(mat)) + if (GPU_material_do_color_management(mat)) GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol); if (mtex->mapto & MAP_COL) { @@ -1104,7 +1104,7 @@ static void do_material_tex(GPUShadeInput *shi) if (tex->imaflag & TEX_NORMALMAP) { /* normalmap image */ - GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor); + GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser, TRUE), &tnor); if (mtex->norfac < 0.0f) GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor); @@ -1234,26 +1234,26 @@ static void do_material_tex(GPUShadeInput *shi) if (found_deriv_map) { GPU_link(mat, "mtex_bump_deriv", - texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, &dBs, &dBt ); } else if ( mtex->texflag & MTEX_3TAP_BUMP) GPU_link(mat, "mtex_bump_tap3", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt ); else if ( mtex->texflag & MTEX_5TAP_BUMP) GPU_link(mat, "mtex_bump_tap5", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt ); else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) { if (GPU_bicubic_bump_support()) { GPU_link(mat, "mtex_bump_bicubic", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt); } else { GPU_link(mat, "mtex_bump_tap5", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt); } } @@ -1263,7 +1263,7 @@ static void do_material_tex(GPUShadeInput *shi) float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; GPU_link(mat, "mtex_bump_apply_texspace", fDet, dBs, dBt, vR1, vR2, - GPU_image(tex->ima, &tex->iuser), texco, + GPU_image(tex->ima, &tex->iuser, TRUE), texco, GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc, &vNacc, &shi->vn ); } @@ -1372,7 +1372,7 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) GPU_link(mat, "set_value", GPU_uniform(&ma->amb), &shi->amb); GPU_link(mat, "shade_view", GPU_builtin(GPU_VIEW_POSITION), &shi->view); GPU_link(mat, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol); - if (gpu_do_color_management(mat)) + if (GPU_material_do_color_management(mat)) GPU_link(mat, "srgb_to_linearrgb", shi->vcol, &shi->vcol); GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); } @@ -1396,10 +1396,10 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) GPU_material_enable_alpha(mat); if ((mat->scene->gm.flag & GAME_GLSL_NO_LIGHTS) || (ma->mode & MA_SHLESS)) { - shr->combined = shi->rgb; - shr->alpha = shi->alpha; GPU_link(mat, "set_rgb", shi->rgb, &shr->diff); GPU_link(mat, "set_rgb_zero", &shr->spec); + GPU_link(mat, "set_value", shi->alpha, &shr->alpha); + shr->combined = shr->diff; } else { if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) { @@ -1418,7 +1418,8 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) material_lights(shi, shr); shr->combined = shr->diff; - shr->alpha = shi->alpha; + + GPU_link(mat, "set_value", shi->alpha, &shr->alpha); if (world) { /* exposure correction */ @@ -1515,12 +1516,9 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma) GPU_material_output_link(mat, outlink); } - if (!BKE_scene_use_new_shading_nodes(scene)) { - if (gpu_do_color_management(mat)) - if (mat->outlink) - GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); - } - + if (GPU_material_do_color_management(mat)) + if (mat->outlink) + GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); GPU_material_construct_end(mat); diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index fb248f1b016..81c3cab97d4 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2114,6 +2114,12 @@ void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 c fac = 1.0; } +void node_tex_brick(vec3 co, vec4 color1, vec4 color2, vec4 mortar, float scale, float mortar_size, float bias, float brick_width, float row_height, out vec4 color, out float fac) +{ + color = vec4(1.0); + fac = 1.0; +} + void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac) { color = vec4(1.0); diff --git a/source/blender/ikplugin/BIK_api.h b/source/blender/ikplugin/BIK_api.h index cbc6485cb54..e1d5f50edfb 100644 --- a/source/blender/ikplugin/BIK_api.h +++ b/source/blender/ikplugin/BIK_api.h @@ -70,9 +70,9 @@ void BIK_clear_cache(struct bPose *pose); void BIK_update_param(struct bPose *pose); void BIK_test_constraint(struct Object *ob, struct bConstraint *cons); // not yet implemented -int BIK_get_constraint_param(struct bPose *pose, struct bConstraint *cons, int id, BIK_ParamValue *value); -int BIK_get_channel_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); -int BIK_get_solver_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); +// int BIK_get_constraint_param(struct bPose *pose, struct bConstraint *cons, int id, BIK_ParamValue *value); +// int BIK_get_channel_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); +// int BIK_get_solver_param(struct bPose *pose, struct bPoseChannel *pchan, int id, BIK_ParamValue *value); // number of solver available // 0 = iksolver diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 7a53fe247fe..c5722995d32 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -57,7 +57,6 @@ extern "C" { #include "BKE_global.h" #include "BKE_armature.h" #include "BKE_action.h" -#include "BKE_utildefines.h" #include "BKE_constraint.h" #include "DNA_object_types.h" #include "DNA_action_types.h" diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index a04affd4891..d23d42ddd0c 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -483,8 +483,8 @@ void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value); /* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, - const float col[4], const int do_color_management, - int x1, int y1, int x2, int y2); + const float col[4], const int do_color_management, + int x1, int y1, int x2, int y2); /* defined in metadata.c */ int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field); diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h index 16d10a5c41c..18816924a9b 100644 --- a/source/blender/imbuf/intern/IMB_indexer.h +++ b/source/blender/imbuf/intern/IMB_indexer.h @@ -31,7 +31,6 @@ #include <stdlib.h> #include <stdio.h> -#include "BKE_utildefines.h" #include "IMB_anim.h" /* * separate animation index files to solve the following problems: diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 9092d59c351..16dbd0823da 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -801,6 +801,34 @@ static int ffmpeg_decode_video_frame(struct anim *anim) anim->next_packet.stream_index = -1; } + if (rval == AVERROR_EOF) { + anim->next_packet.size = 0; + anim->next_packet.data = 0; + + anim->pFrameComplete = 0; + + avcodec_decode_video2( + anim->pCodecCtx, + anim->pFrame, &anim->pFrameComplete, + &anim->next_packet); + + if (anim->pFrameComplete) { + anim->next_pts = av_get_pts_from_frame( + anim->pFormatCtx, anim->pFrame); + + av_log(anim->pFormatCtx, + AV_LOG_DEBUG, + " FRAME DONE (after EOF): next_pts=%lld " + "pkt_pts=%lld, guessed_pts=%lld\n", + (anim->pFrame->pts == AV_NOPTS_VALUE) ? + -1 : (long long int)anim->pFrame->pts, + (anim->pFrame->pkt_pts == AV_NOPTS_VALUE) ? + -1 : (long long int)anim->pFrame->pkt_pts, + (long long int)anim->next_pts); + rval = 0; + } + } + if (rval < 0) { anim->next_packet.stream_index = -1; diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 60dd4f65594..8fa468949e7 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -69,7 +69,7 @@ typedef struct BMPHEADER { static int checkbmp(unsigned char *mem) { -#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[0])) +#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[1])) int ret_val = 0; BMPINFOHEADER bmi; diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c index 900bc7756f0..d67de3be68b 100644 --- a/source/blender/imbuf/intern/filetype.c +++ b/source/blender/imbuf/intern/filetype.c @@ -48,12 +48,6 @@ static int imb_ftype_default(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype & type->filetype); } -#if defined(__APPLE__) && defined(IMBUF_COCOA) -static int imb_ftype_cocoa(ImFileType *type, ImBuf *ibuf) -{ - return (ibuf->ftype & TIF); -} -#endif static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf) { (void)type; @@ -83,8 +77,6 @@ ImFileType IMB_FILE_TYPES[] = { #endif #ifdef WITH_TIFF {imb_inittiff, NULL, imb_is_a_tiff, imb_ftype_default, imb_loadtiff, imb_savetiff, imb_loadtiletiff, 0, TIF}, -#elif defined(__APPLE__) && defined(IMBUF_COCOA) - {NULL, NULL, imb_is_a_cocoa, imb_ftype_cocoa, imb_imb_cocoaLoadImage, imb_savecocoa, NULL, 0, TIF}, #endif #ifdef WITH_HDR {NULL, NULL, imb_is_a_hdr, imb_ftype_default, imb_loadhdr, imb_savehdr, NULL, IM_FTYPE_FLOAT, RADHDR}, diff --git a/source/blender/imbuf/intern/imbuf_cocoa.m b/source/blender/imbuf/intern/imbuf_cocoa.m deleted file mode 100644 index 10381e9d1c3..00000000000 --- a/source/blender/imbuf/intern/imbuf_cocoa.m +++ /dev/null @@ -1,384 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Contributor(s): Damien Plisson 10/2009 - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/imbuf/intern/imbuf_coca.m - * \ingroup imbuf - * - * Provides image file loading and saving for Blender, via Cocoa. - */ - -#include <stdint.h> -#include <string.h> -#import <Cocoa/Cocoa.h> - -#include "imbuf.h" - -#include "IMB_cocoa.h" - -#include "BKE_global.h" -#include "BKE_colortools.h" - -#include "IMB_imbuf_types.h" -#include "IMB_imbuf.h" - -#include "IMB_allocimbuf.h" - - - -#pragma mark load/save functions - -/** - * Loads an image from the supplied buffer - * - * Loads any Core Graphics supported type - * Currently is : TIFF, BMP, JPEG, GIF, PNG, DIB, ICO, and various RAW formats - * - * \param mem: Memory containing the bitmap image - * \param size: Size of the mem buffer. - * \param flags: If flags has IB_test set then the file is not actually loaded, - * but all other operations take place. - * - * \return: A newly allocated ImBuf structure if successful, otherwise NULL. - */ -struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags) -{ - struct ImBuf *ibuf = NULL; - NSSize bitmapSize; - uchar *rasterRGB = NULL; - uchar *rasterRGBA = NULL; - uchar *toIBuf = NULL; - int x, y, to_i, from_i; - NSData *data; - NSBitmapImageRep *bitmapImage; - NSBitmapImageRep *blBitmapFormatImageRGB,*blBitmapFormatImageRGBA; - NSAutoreleasePool *pool; - - pool = [[NSAutoreleasePool alloc] init]; - - data = [NSData dataWithBytes:mem length:size]; - bitmapImage = [[NSBitmapImageRep alloc] initWithData:data]; - - if (!bitmapImage) { - fprintf(stderr, "imb_cocoaLoadImage: error loading image\n"); - [pool drain]; - return NULL; - } - - bitmapSize.width = [bitmapImage pixelsWide]; - bitmapSize.height = [bitmapImage pixelsHigh]; - - /* Tell cocoa image resolution is same as current system one */ - [bitmapImage setSize:bitmapSize]; - - /* allocate the image buffer */ - ibuf = IMB_allocImBuf(bitmapSize.width, bitmapSize.height, 32/*RGBA*/, 0); - if (!ibuf) { - fprintf(stderr, - "imb_cocoaLoadImage: could not allocate memory for the image.\n"); - [bitmapImage release]; - [pool drain]; - return NULL; - } - - /* read in the image data */ - if (!(flags & IB_test)) { - - /* allocate memory for the ibuf->rect */ - imb_addrectImBuf(ibuf); - - /* Convert the image in a RGBA 32bit format */ - /* As Core Graphics does not support contextes with non premutliplied alpha, - we need to get alpha key values in a separate batch */ - - /* First get RGB values w/o Alpha to avoid pre-multiplication, 32bit but last byte is unused */ - blBitmapFormatImageRGB = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:bitmapSize.width - pixelsHigh:bitmapSize.height - bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:0 - bytesPerRow:4*bitmapSize.width - bitsPerPixel:32/*RGB format padded to 32bits*/]; - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGB]]; - [bitmapImage draw]; - [NSGraphicsContext restoreGraphicsState]; - - rasterRGB = (uchar*)[blBitmapFormatImageRGB bitmapData]; - if (rasterRGB == NULL) { - [bitmapImage release]; - [blBitmapFormatImageRGB release]; - [pool drain]; - return NULL; - } - - /* Then get Alpha values by getting the RGBA image (that is premultiplied btw) */ - blBitmapFormatImageRGBA = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:bitmapSize.width - pixelsHigh:bitmapSize.height - bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:0 - bytesPerRow:4*bitmapSize.width - bitsPerPixel:32/* RGBA */]; - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGBA]]; - [bitmapImage draw]; - [NSGraphicsContext restoreGraphicsState]; - - rasterRGBA = (uchar*)[blBitmapFormatImageRGBA bitmapData]; - if (rasterRGBA == NULL) { - [bitmapImage release]; - [blBitmapFormatImageRGB release]; - [blBitmapFormatImageRGBA release]; - [pool drain]; - return NULL; - } - - /*Copy the image to ibuf, flipping it vertically*/ - toIBuf = (uchar*)ibuf->rect; - for (x = 0; x < bitmapSize.width; x++) { - for (y = 0; y < bitmapSize.height; y++) { - to_i = (bitmapSize.height-y-1)*bitmapSize.width + x; - from_i = y*bitmapSize.width + x; - - toIBuf[4*to_i] = rasterRGB[4*from_i]; /* R */ - toIBuf[4*to_i+1] = rasterRGB[4*from_i+1]; /* G */ - toIBuf[4*to_i+2] = rasterRGB[4*from_i+2]; /* B */ - toIBuf[4*to_i+3] = rasterRGBA[4*from_i+3]; /* A */ - } - } - - [blBitmapFormatImageRGB release]; - [blBitmapFormatImageRGBA release]; - } - - /* release the cocoa objects */ - [bitmapImage release]; - [pool drain]; - - if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); - - ibuf->ftype = TIF; - ibuf->profile = IB_PROFILE_SRGB; - - /* return successfully */ - return (ibuf); -} - -/** - * Saves an image to a file. - * - * ImBuf structures with 1, 3 or 4 bytes per pixel (GRAY, RGB, RGBA - * respectively) are accepted, and interpreted correctly. - * - * Accepted formats: TIFF, GIF, BMP, PNG, JPEG, JPEG2000 - * - * \param ibuf: Image buffer. - * \param name: Name of the image file to create. - * \param flags: Currently largely ignored. - * - * \return: 1 if the function is successful, 0 on failure. - */ - -#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f)) - -short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags) -{ - uint16_t samplesperpixel, bitspersample; - unsigned char *from = NULL, *to = NULL; - unsigned short *to16 = NULL; - float *fromf = NULL; - int x, y, from_i, to_i, i; - int success; - BOOL hasAlpha; - NSString* colorSpace; - NSBitmapImageRep *blBitmapFormatImage; - NSData *dataToWrite; - NSDictionary *imageProperties; - - NSAutoreleasePool *pool; - - if (!ibuf) return FALSE; - if (!name) return FALSE; - - /* check for a valid number of bytes per pixel. Like the PNG writer, - * the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding - * to gray, RGB, RGBA respectively. */ - samplesperpixel = (uint16_t)((ibuf->planes + 7) >> 3); - switch (samplesperpixel) { - case 4: /*RGBA type*/ - hasAlpha = YES; - colorSpace = NSCalibratedRGBColorSpace; - break; - case 3: /*RGB type*/ - hasAlpha = NO; - colorSpace = NSCalibratedRGBColorSpace; - break; - case 1: - hasAlpha = NO; - colorSpace = NSCalibratedWhiteColorSpace; - break; - default: - fprintf(stderr, - "imb_cocoaSaveImage: unsupported number of bytes per " - "pixel: %d\n", samplesperpixel); - return (0); - } - - if((ibuf->ftype & TIF_16BIT) && ibuf->rect_float) - bitspersample = 16; - else - bitspersample = 8; - - pool = [[NSAutoreleasePool alloc] init]; - - /* Create bitmap image rep in blender format */ - blBitmapFormatImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:ibuf->x - pixelsHigh:ibuf->y - bitsPerSample:bitspersample samplesPerPixel:samplesperpixel hasAlpha:hasAlpha isPlanar:NO - colorSpaceName:colorSpace - bitmapFormat:NSAlphaNonpremultipliedBitmapFormat - bytesPerRow:(ibuf->x*bitspersample*samplesperpixel/8) - bitsPerPixel:(bitspersample*samplesperpixel)]; - if (!blBitmapFormatImage) { - [pool drain]; - return FALSE; - } - - /* setup pointers */ - if(bitspersample == 16) { - fromf = ibuf->rect_float; - to16 = (unsigned short*)[blBitmapFormatImage bitmapData]; - } - else { - from = (unsigned char*)ibuf->rect; - to = (unsigned char*)[blBitmapFormatImage bitmapData]; - } - - /* copy pixel data. While copying, we flip the image vertically. */ - for (x = 0; x < ibuf->x; x++) { - for (y = 0; y < ibuf->y; y++) { - from_i = 4*(y*ibuf->x+x); - to_i = samplesperpixel*((ibuf->y-y-1)*ibuf->x+x); - - if(bitspersample == 16) { - if (ibuf->profile == IB_PROFILE_SRGB) { - switch (samplesperpixel) { - case 4 /*RGBA*/: - to16[to_i] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i])); - to16[to_i+1] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+1])); - to16[to_i+2] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+2])); - to16[to_i+3] = FTOUSHORT(fromf[from_i+3]); - break; - case 3 /*RGB*/: - to16[to_i] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i])); - to16[to_i+1] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+1])); - to16[to_i+2] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i+2])); - break; - case 1 /*BW*/: - to16[to_i] = FTOUSHORT(linearrgb_to_srgb(fromf[from_i])); - break; - } - } - else { - for (i = 0; i < samplesperpixel; i++, to_i++, from_i++) - to16[to_i] = FTOUSHORT(fromf[from_i]); - } - } - else { - /* 8bits per sample*/ - for (i = 0; i < samplesperpixel; i++, to_i++, from_i++) - to[to_i] = from[from_i]; - } - } - } - - /* generate file data */ - if (IS_tiff(ibuf)) { - dataToWrite = [blBitmapFormatImage TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0]; - } - else if (IS_png(ibuf)) { - imageProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:false], NSImageInterlaced, - nil]; - dataToWrite = [blBitmapFormatImage representationUsingType:NSPNGFileType properties:imageProperties]; - } - else if (IS_bmp(ibuf)) { - dataToWrite = [blBitmapFormatImage representationUsingType:NSBMPFileType properties:nil]; - } - else {/* JPEG by default */ - int quality; - - quality = ibuf->ftype & 0xff; - if (quality <= 0) quality = 90; /* Standard quality if wrong supplied*/ - if (quality > 100) quality = 100; - - imageProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:quality], NSImageCompressionFactor, - [NSNumber numberWithBool:true], NSImageProgressive, - nil]; - dataToWrite = [blBitmapFormatImage representationUsingType:NSJPEGFileType properties:imageProperties]; - } - - /* Write the file */ - success = [dataToWrite writeToFile:[NSString stringWithCString:name encoding:NSISOLatin1StringEncoding] - atomically:YES]; - - [blBitmapFormatImage release]; - [pool drain]; - - return success; -} - -#pragma mark format checking functions - -/* Currently, only tiff format is handled, so need to include here function that was previously in tiff.c */ - -/** - * Checks whether a given memory buffer contains a TIFF file. - * - * FIXME: Possible memory leak if mem is less than IMB_TIFF_NCB bytes long. - * However, changing this will require up-stream modifications. - * - * This method uses the format identifiers from: - * http://www.faqs.org/faqs/graphics/fileformats-faq/part4/section-9.html - * The first four bytes of big-endian and little-endian TIFF files - * respectively are (hex): - * 4d 4d 00 2a - * 49 49 2a 00 - * Note that TIFF files on *any* platform can be either big- or little-endian; - * it's not platform-specific. - * - * AFAICT, libtiff doesn't provide a method to do this automatically, and - * hence my manual comparison. - Jonathan Merritt (lancelet) 4th Sept 2005. - */ -#define IMB_TIFF_NCB 4 /* number of comparison bytes used */ -int imb_is_a_tiff(void *mem) -{ - char big_endian[IMB_TIFF_NCB] = { 0x4d, 0x4d, 0x00, 0x2a }; - char lil_endian[IMB_TIFF_NCB] = { 0x49, 0x49, 0x2a, 0x00 }; - - return ( (memcmp(big_endian, mem, IMB_TIFF_NCB) == 0) || - (memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0) ); -} diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 4108f0d89d7..ea493e277f3 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -24,18 +24,21 @@ #include <stdlib.h> -#include "IMB_indexer.h" -#include "IMB_anim.h" -#include "AVI_avi.h" -#include "imbuf.h" #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" +#include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_math_base.h" +#include "IMB_indexer.h" +#include "IMB_anim.h" +#include "AVI_avi.h" +#include "imbuf.h" + #include "MEM_guardedalloc.h" #include "DNA_userdef_types.h" #include "BKE_global.h" @@ -208,10 +211,10 @@ struct anim_index *IMB_indexer_open(const char *name) if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) { for (i = 0; i < idx->num_entries; i++) { - SWITCH_INT(idx->entries[i].frameno); - SWITCH_INT64(idx->entries[i].seek_pos); - SWITCH_INT64(idx->entries[i].seek_pos_dts); - SWITCH_INT64(idx->entries[i].pts); + BLI_endian_switch_int32(&idx->entries[i].frameno); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos_dts); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].pts); } } @@ -720,6 +723,17 @@ typedef struct FFmpegIndexBuilderContext { IMB_Timecode_Type tcs_in_use; IMB_Proxy_Size proxy_sizes_in_use; + + unsigned long long seek_pos; + unsigned long long last_seek_pos; + unsigned long long seek_pos_dts; + unsigned long long seek_pos_pts; + unsigned long long last_seek_pos_dts; + unsigned long long start_pts; + double frame_rate; + double pts_time_base; + int frameno, frameno_gapless; + int start_pts_set; } FFmpegIndexBuilderContext; static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, IMB_Timecode_Type tcs_in_use, @@ -836,20 +850,63 @@ static void index_rebuild_ffmpeg_finish(FFmpegIndexBuilderContext *context, int MEM_freeN(context); } +static void index_rebuild_ffmpeg_proc_decoded_frame( + FFmpegIndexBuilderContext *context, + AVPacket * curr_packet, + AVFrame *in_frame) +{ + int i; + unsigned long long s_pos = context->seek_pos; + unsigned long long s_dts = context->seek_pos_dts; + unsigned long long pts = av_get_pts_from_frame(context->iFormatCtx, in_frame); + + for (i = 0; i < context->num_proxy_sizes; i++) { + add_to_proxy_output_ffmpeg(context->proxy_ctx[i], in_frame); + } + + if (!context->start_pts_set) { + context->start_pts = pts; + context->start_pts_set = TRUE; + } + + context->frameno = floor((pts - context->start_pts) + * context->pts_time_base + * context->frame_rate + 0.5f); + + /* decoding starts *always* on I-Frames, + * so: P-Frames won't work, even if all the + * information is in place, when we seek + * to the I-Frame presented *after* the P-Frame, + * but located before the P-Frame within + * the stream */ + + if (pts < context->seek_pos_pts) { + s_pos = context->last_seek_pos; + s_dts = context->last_seek_pos_dts; + } + + for (i = 0; i < context->num_indexers; i++) { + if (context->tcs_in_use & tc_types[i]) { + int tc_frameno = context->frameno; + + if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) + tc_frameno = context->frameno_gapless; + + IMB_index_builder_proc_frame( + context->indexer[i], + curr_packet->data, + curr_packet->size, + tc_frameno, + s_pos, s_dts, pts); + } + } + + context->frameno_gapless++; +} + static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, short *stop, short *do_update, float *progress) { - int i; - unsigned long long seek_pos = 0; - unsigned long long last_seek_pos = 0; - unsigned long long seek_pos_dts = 0; - unsigned long long seek_pos_pts = 0; - unsigned long long last_seek_pos_dts = 0; - unsigned long long start_pts = 0; - double frame_rate; - double pts_time_base; - int frameno = 0, frameno_gapless = 0; - int start_pts_set = FALSE; AVFrame *in_frame = 0; AVPacket next_packet; uint64_t stream_size; @@ -858,8 +915,8 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, stream_size = avio_size(context->iFormatCtx->pb); - frame_rate = av_q2d(context->iStream->r_frame_rate); - pts_time_base = av_q2d(context->iStream->time_base); + context->frame_rate = av_q2d(context->iStream->r_frame_rate); + context->pts_time_base = av_q2d(context->iStream->time_base); while (av_read_frame(context->iFormatCtx, &next_packet) >= 0) { int frame_finished = 0; @@ -878,11 +935,11 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, if (next_packet.stream_index == context->videoStream) { if (next_packet.flags & AV_PKT_FLAG_KEY) { - last_seek_pos = seek_pos; - last_seek_pos_dts = seek_pos_dts; - seek_pos = next_packet.pos; - seek_pos_dts = next_packet.dts; - seek_pos_pts = next_packet.pts; + context->last_seek_pos = context->seek_pos; + context->last_seek_pos_dts = context->seek_pos_dts; + context->seek_pos = next_packet.pos; + context->seek_pos_dts = next_packet.dts; + context->seek_pos_pts = next_packet.pts; } avcodec_decode_video2( @@ -891,54 +948,34 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, } if (frame_finished) { - unsigned long long s_pos = seek_pos; - unsigned long long s_dts = seek_pos_dts; - unsigned long long pts = av_get_pts_from_frame(context->iFormatCtx, in_frame); - - for (i = 0; i < context->num_proxy_sizes; i++) { - add_to_proxy_output_ffmpeg( - context->proxy_ctx[i], in_frame); - } - - if (!start_pts_set) { - start_pts = pts; - start_pts_set = TRUE; - } + index_rebuild_ffmpeg_proc_decoded_frame( + context, &next_packet, in_frame); + } + av_free_packet(&next_packet); + } - frameno = floor((pts - start_pts) * - pts_time_base * frame_rate + 0.5f); + /* process pictures still stuck in decoder engine after EOF + according to ffmpeg docs using 0-size packets. - /* decoding starts *always* on I-Frames, - * so: P-Frames won't work, even if all the - * information is in place, when we seek - * to the I-Frame presented *after* the P-Frame, - * but located before the P-Frame within - * the stream */ + At least, if we haven't already stopped... */ + if (!*stop) { + int frame_finished; - if (pts < seek_pos_pts) { - s_pos = last_seek_pos; - s_dts = last_seek_pos_dts; - } + next_packet.size = 0; + next_packet.data = 0; - for (i = 0; i < context->num_indexers; i++) { - if (context->tcs_in_use & tc_types[i]) { - int tc_frameno = frameno; + do { + frame_finished = 0; - if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) - tc_frameno = frameno_gapless; + avcodec_decode_video2( + context->iCodecCtx, in_frame, &frame_finished, + &next_packet); - IMB_index_builder_proc_frame( - context->indexer[i], - next_packet.data, - next_packet.size, - tc_frameno, - s_pos, s_dts, pts); - } + if (frame_finished) { + index_rebuild_ffmpeg_proc_decoded_frame( + context, &next_packet, in_frame); } - - frameno_gapless++; - } - av_free_packet(&next_packet); + } while (frame_finished); } av_free(in_frame); diff --git a/source/blender/imbuf/intern/indexer_dv.c b/source/blender/imbuf/intern/indexer_dv.c index 4c6b750aa41..6b960a18277 100644 --- a/source/blender/imbuf/intern/indexer_dv.c +++ b/source/blender/imbuf/intern/indexer_dv.c @@ -22,9 +22,12 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "IMB_indexer.h" #include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_path_util.h" + +#include "IMB_indexer.h" #include <time.h> typedef struct indexer_dv_bitstream { diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index e76a59905cb..13b0fc1b55a 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -522,15 +522,13 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } - if (ibuf) { - ibuf->ftype = IMAGIC; - ibuf->profile = IB_PROFILE_SRGB; + ibuf->ftype = IMAGIC; + ibuf->profile = IB_PROFILE_SRGB; - test_endian_zbuf(ibuf); + test_endian_zbuf(ibuf); - if (ibuf->rect) { - IMB_convert_rgba_to_abgr(ibuf); - } + if (ibuf->rect) { + IMB_convert_rgba_to_abgr(ibuf); } return(ibuf); diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 71eae6c6c21..78a989ad48f 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -41,6 +41,7 @@ #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLI_mempool.h" +#include "BLI_threads.h" #include "IMB_moviecache.h" @@ -58,6 +59,7 @@ #endif static MEM_CacheLimiterC *limitor = NULL; +static pthread_mutex_t limitor_lock = BLI_MUTEX_INITIALIZER; typedef struct MovieCache { char name[64]; @@ -172,12 +174,13 @@ static int compare_int(const void *av, const void *bv) static void IMB_moviecache_destructor(void *p) { - MovieCacheItem *item = (MovieCacheItem *) p; - MovieCache *cache = item->cache_owner; - - PRINT("%s: cache '%s' destroy item %p buffer %p\n", __func__, cache->name, item, item->ibuf); + MovieCacheItem *item = (MovieCacheItem *)p; if (item && item->ibuf) { + MovieCache *cache = item->cache_owner; + + PRINT("%s: cache '%s' destroy item %p buffer %p\n", __func__, cache->name, item, item->ibuf); + IMB_freeImBuf(item->ibuf); item->ibuf = NULL; @@ -334,16 +337,20 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf) BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree); BLI_ghash_insert(cache->hash, key, item); - item->c_handle = MEM_CacheLimiter_insert(limitor, item); - if (cache->last_userkey) { memcpy(cache->last_userkey, userkey, cache->keysize); } + BLI_mutex_lock(&limitor_lock); + + item->c_handle = MEM_CacheLimiter_insert(limitor, item); + MEM_CacheLimiter_ref(item->c_handle); MEM_CacheLimiter_enforce_limits(limitor); MEM_CacheLimiter_unref(item->c_handle); + BLI_mutex_unlock(&limitor_lock); + /* cache limiter can't remove unused keys which points to destoryed values */ check_unused_keys(cache); @@ -364,7 +371,10 @@ ImBuf *IMB_moviecache_get(MovieCache *cache, void *userkey) if (item) { if (item->ibuf) { + BLI_mutex_lock(&limitor_lock); MEM_CacheLimiter_touch(item->c_handle); + BLI_mutex_unlock(&limitor_lock); + IMB_refImBuf(item->ibuf); return item->ibuf; diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index ab805ea6666..c3e23246638 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -46,19 +46,19 @@ /* blend modes */ -static void blend_color_mix(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_mix(char cp[3], const char cp1[3], const char cp2[3], const int fac) { /* this and other blending modes previously used >>8 instead of /255. both * are not equivalent (>>8 is /256), and the former results in rounding * errors that can turn colors black fast after repeated blending */ - int mfac = 255 - fac; + const int mfac = 255 - fac; cp[0] = (mfac * cp1[0] + fac * cp2[0]) / 255; cp[1] = (mfac * cp1[1] + fac * cp2[1]) / 255; cp[2] = (mfac * cp1[2] + fac * cp2[2]) / 255; } -static void blend_color_add(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_add(char cp[3], const char cp1[3], const char cp2[3], const int fac) { int temp; @@ -70,7 +70,7 @@ static void blend_color_add(char *cp, char *cp1, char *cp2, int fac) if (temp > 254) cp[2] = 255; else cp[2] = temp; } -static void blend_color_sub(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_sub(char cp[3], const char cp1[3], const char cp2[3], const int fac) { int temp; @@ -82,7 +82,7 @@ static void blend_color_sub(char *cp, char *cp1, char *cp2, int fac) if (temp < 0) cp[2] = 0; else cp[2] = temp; } -static void blend_color_mul(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_mul(char cp[3], const char cp1[3], const char cp2[3], const int fac) { int mfac = 255 - fac; @@ -92,7 +92,7 @@ static void blend_color_mul(char *cp, char *cp1, char *cp2, int fac) cp[2] = (mfac * cp1[2] + fac * ((cp1[2] * cp2[2]) / 255)) / 255; } -static void blend_color_lighten(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_lighten(char cp[3], const char cp1[3], const char cp2[3], const int fac) { /* See if are lighter, if so mix, else don't do anything. * if the paint col is darker then the original, then ignore */ @@ -101,11 +101,12 @@ static void blend_color_lighten(char *cp, char *cp1, char *cp2, int fac) cp[1] = cp1[1]; cp[2] = cp1[2]; } - else + else { blend_color_mix(cp, cp1, cp2, fac); + } } -static void blend_color_darken(char *cp, char *cp1, char *cp2, int fac) +static void blend_color_darken(char cp[3], const char cp1[3], const char cp2[3], const int fac) { /* See if were darker, if so mix, else don't do anything. * if the paint col is brighter then the original, then ignore */ @@ -114,8 +115,9 @@ static void blend_color_darken(char *cp, char *cp1, char *cp2, int fac) cp[1] = cp1[1]; cp[2] = cp1[2]; } - else + else { blend_color_mix(cp, cp1, cp2, fac); + } } unsigned int IMB_blend_color(unsigned int src1, unsigned int src2, int fac, IMB_BlendMode mode) @@ -162,7 +164,7 @@ unsigned int IMB_blend_color(unsigned int src1, unsigned int src2, int fac, IMB_ return dst; } -static void blend_color_mix_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_mix_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { float mfac = 1.0f - fac; cp[0] = mfac * cp1[0] + fac * cp2[0]; @@ -170,7 +172,7 @@ static void blend_color_mix_float(float *cp, float *cp1, float *cp2, float fac) cp[2] = mfac * cp1[2] + fac * cp2[2]; } -static void blend_color_add_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_add_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { cp[0] = cp1[0] + fac * cp2[0]; cp[1] = cp1[1] + fac * cp2[1]; @@ -181,7 +183,7 @@ static void blend_color_add_float(float *cp, float *cp1, float *cp2, float fac) if (cp[2] > 1.0f) cp[2] = 1.0f; } -static void blend_color_sub_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_sub_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { cp[0] = cp1[0] - fac * cp2[0]; cp[1] = cp1[1] - fac * cp2[1]; @@ -192,7 +194,7 @@ static void blend_color_sub_float(float *cp, float *cp1, float *cp2, float fac) if (cp[2] < 0.0f) cp[2] = 0.0f; } -static void blend_color_mul_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_mul_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { float mfac = 1.0f - fac; @@ -201,7 +203,7 @@ static void blend_color_mul_float(float *cp, float *cp1, float *cp2, float fac) cp[2] = mfac * cp1[2] + fac * (cp1[2] * cp2[2]); } -static void blend_color_lighten_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_lighten_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { /* See if are lighter, if so mix, else don't do anything. * if the pafloat col is darker then the original, then ignore */ @@ -214,7 +216,7 @@ static void blend_color_lighten_float(float *cp, float *cp1, float *cp2, float f blend_color_mix_float(cp, cp1, cp2, fac); } -static void blend_color_darken_float(float *cp, float *cp1, float *cp2, float fac) +static void blend_color_darken_float(float cp[3], const float cp1[3], const float cp2[3], const float fac) { /* See if were darker, if so mix, else don't do anything. * if the pafloat col is brighter then the original, then ignore */ diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 6a234b8e29a..2a2aedb49ff 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -39,8 +39,6 @@ #include "BLI_fileops.h" #include "BLI_md5.h" -#include "BKE_utildefines.h" - #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index afef2365de4..cfc49d8cef5 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -29,18 +29,20 @@ #include "zlib.h" +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BLI_fileops.h" -#include "BKE_utildefines.h" +#include "BLO_blend_defs.h" + #include "BKE_global.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" -#include "MEM_guardedalloc.h" - /* extracts the thumbnail from between the 'REND' and the 'GLOB' * chunks of the header, don't use typical blend loader because its too slow */ @@ -78,7 +80,7 @@ static ImBuf *loadblend_thumb(gzFile gzfile) while (gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) { if (endian_switch) - SWITCH_INT(bhead[1]); /* length */ + BLI_endian_switch_int32(&bhead[1]); /* length */ if (bhead[0] == REND) { gzseek(gzfile, bhead[1], SEEK_CUR); /* skip to the next */ @@ -97,8 +99,8 @@ static ImBuf *loadblend_thumb(gzFile gzfile) return NULL; if (endian_switch) { - SWITCH_INT(size[0]); - SWITCH_INT(size[1]); + BLI_endian_switch_int32(&size[0]); + BLI_endian_switch_int32(&size[1]); } /* length */ bhead[1] -= sizeof(int) * 2; diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index a765ac5c3b4..6d1e3c16631 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -225,16 +225,6 @@ static int isqtime(const char *name) static char ffmpeg_last_error[1024]; -void silence_log_ffmpeg(int quiet) -{ - if (quiet) { - av_log_set_level(AV_LOG_QUIET); - } - else { - av_log_set_level(AV_LOG_DEBUG); - } -} - void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) { if (ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) { @@ -244,8 +234,10 @@ void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) ffmpeg_last_error[n - 1] = '\0'; } - /* call default logger to print all message to console */ - av_log_default_callback(ptr, level, format, arg); + if (G.debug & G_DEBUG_FFMPEG) { + /* call default logger to print all message to console */ + av_log_default_callback(ptr, level, format, arg); + } } void IMB_ffmpeg_init(void) @@ -253,13 +245,6 @@ void IMB_ffmpeg_init(void) av_register_all(); avdevice_register_all(); - if ((G.debug & G_DEBUG_FFMPEG) == 0) { - silence_log_ffmpeg(1); - } - else { - silence_log_ffmpeg(0); - } - ffmpeg_last_error[0] = '\0'; /* set own callback which could store last error to report to UI */ diff --git a/source/blender/makesdna/DNA_ipo_types.h b/source/blender/makesdna/DNA_ipo_types.h index e3ab6b4a7db..6bf8dbbe73a 100644 --- a/source/blender/makesdna/DNA_ipo_types.h +++ b/source/blender/makesdna/DNA_ipo_types.h @@ -65,8 +65,8 @@ typedef struct IpoDriver { typedef struct IpoCurve { struct IpoCurve *next, *prev; - struct BPoint *bp; /* array of BPoints (sizeof(BPoint)*totvert) - i.e. baked/imported data */ - struct BezTriple *bezt; /* array of BezTriples (sizeof(BezTriple)*totvert) - i.e. user-editable keyframes */ + struct BPoint *bp; /* array of BPoints (sizeof(BPoint) * totvert) - i.e. baked/imported data */ + struct BezTriple *bezt; /* array of BezTriples (sizeof(BezTriple) * totvert) - i.e. user-editable keyframes */ rctf maxrct, totrct; /* bounding boxes */ diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 316b90b69de..5408e865ab2 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -92,7 +92,8 @@ typedef struct Mesh { struct MCol *mcol; struct MSticky *msticky; struct Mesh *texcomesh; - + + /* When the object is available, the preferred access method is: BMEdit_FromObject(ob) */ struct BMEditMesh *edit_btmesh; /* not saved in file! */ struct CustomData vdata, edata, fdata; diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index c3b11fed613..3c89e069ea0 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -328,7 +328,6 @@ typedef struct MVertSkin { #define TF_SEL2 8 #define TF_SEL3 16 #define TF_SEL4 32 -#define TF_HIDE 64 /* unused, same as TF_SELECT */ /* mtface->mode */ #define TF_DYNAMIC 1 diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index ffb16b96b55..3f1f4933585 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -614,17 +614,27 @@ typedef struct NodeTexSky { typedef struct NodeTexImage { NodeTexBase base; ImageUser iuser; - int color_space, pad; + int color_space; + int projection; + float projection_blend; + int pad; } NodeTexImage; typedef struct NodeTexChecker { NodeTexBase base; } NodeTexChecker; +typedef struct NodeTexBrick { + NodeTexBase base; + int offset_freq, squash_freq; + float offset, squash; +} NodeTexBrick; + typedef struct NodeTexEnvironment { NodeTexBase base; ImageUser iuser; - int color_space, projection; + int color_space; + int projection; } NodeTexEnvironment; typedef struct NodeTexGradient { @@ -764,6 +774,10 @@ typedef struct NodeTrackPosData { #define SHD_PROJ_EQUIRECTANGULAR 0 #define SHD_PROJ_MIRROR_BALL 1 +/* image texture */ +#define SHD_PROJ_FLAT 0 +#define SHD_PROJ_BOX 1 + /* blur node */ #define CMP_NODE_BLUR_ASPECT_NONE 0 #define CMP_NODE_BLUR_ASPECT_Y 1 diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 4c7273b914d..9b347a71140 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1160,7 +1160,7 @@ typedef struct Scene { #define R_EDGE 0x0020 #define R_FIELDS 0x0040 #define R_FIELDSTILL 0x0080 -#define R_RADIO 0x0100 +/*#define R_RADIO 0x0100 */ /* deprecated */ #define R_BORDER 0x0200 #define R_PANORAMA 0x0400 /* deprecated as scene option, still used in renderer */ #define R_CROP 0x0800 @@ -1363,9 +1363,6 @@ typedef struct Scene { #define TIME2FRA(a) ((((double) scene->r.frs_sec) * (double)(a)) / (double)scene->r.frs_sec_base) #define FPS (((double) scene->r.frs_sec) / (double)scene->r.frs_sec_base) -#define RAD_PHASE_PATCHES 1 -#define RAD_PHASE_FACES 2 - /* base->flag is in DNA_object_types.h */ /* toolsettings->snap_flag */ diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h index 34fb7ce60be..b1cd54950e6 100644 --- a/source/blender/makesdna/DNA_screen_types.h +++ b/source/blender/makesdna/DNA_screen_types.h @@ -77,8 +77,6 @@ typedef struct bScreen { struct wmTimer *animtimer; /* if set, screen has timer handler added in window */ void *context; /* context callback */ - - short handler[8]; /* similar to space handler */ } bScreen; typedef struct ScrVert { @@ -214,13 +212,6 @@ typedef struct ARegion { #define PNL_DEFAULT_CLOSED 1 #define PNL_NO_HEADER 2 -/* screen handlers */ -#define SCREEN_MAXHANDLER 8 - -#define SCREEN_HANDLER_ANIM 1 -#define SCREEN_HANDLER_PYTHON 2 -#define SCREEN_HANDLER_VERSE 3 - /* regiontype, first two are the default set */ /* Do NOT change order, append on end. Types are hardcoded needed */ enum { diff --git a/source/blender/makesdna/DNA_sdna_types.h b/source/blender/makesdna/DNA_sdna_types.h index ec02db192fd..8b2e7645823 100644 --- a/source/blender/makesdna/DNA_sdna_types.h +++ b/source/blender/makesdna/DNA_sdna_types.h @@ -81,12 +81,7 @@ typedef struct BHead4 { # typedef struct BHead8 { int code, len; -#if defined(WIN32) && !defined(FREE_WINDOWS) - /* This is a compiler type! */ - __int64 old; -#else - long long old; -#endif + int64_t old; int SDNAnr, nr; } BHead8; diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h index c83bddbfc64..d094c1d6255 100644 --- a/source/blender/makesdna/DNA_sequence_types.h +++ b/source/blender/makesdna/DNA_sequence_types.h @@ -99,7 +99,7 @@ typedef struct Strip { StripProxy *proxy; StripCrop *crop; StripTransform *transform; - StripColorBalance *color_balance; + StripColorBalance *color_balance DNA_DEPRECATED; } Strip; /** @@ -150,9 +150,6 @@ typedef struct Sequence { /* pointers for effects: */ struct Sequence *seq1, *seq2, *seq3; - /* maks input for effects */ - struct Sequence *mask_sequence; - ListBase seqbase; /* list of strips for metastrips */ struct bSound *sound; /* the linked "bSound" object */ @@ -315,7 +312,7 @@ typedef struct BrightContrastModifierData { #define SEQ_USE_PROXY (1 << 15) #define SEQ_USE_TRANSFORM (1 << 16) #define SEQ_USE_CROP (1 << 17) -#define SEQ_USE_COLOR_BALANCE (1 << 18) +/* #define SEQ_USE_COLOR_BALANCE (1 << 18) */ /* DEPRECATED */ #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) @@ -384,11 +381,6 @@ enum { SEQ_TYPE_EFFECT_MAX = 31 }; -#define STRIPELEM_FAILED 0 -#define STRIPELEM_OK 1 - -#define STRIPELEM_PREVIEW_DONE 1 - #define SEQ_MOVIECLIP_RENDER_UNDISTORTED (1 << 0) #define SEQ_MOVIECLIP_RENDER_STABILIZED (1 << 1) diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 833cb267185..96f0c0e7a9a 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -47,7 +47,6 @@ struct ColorBand; /* ************************ style definitions ******************** */ #define MAX_STYLE_NAME 64 -#define MAX_FONT_NAME 256 /* default uifont_id offered by Blender */ #define UIFONT_DEFAULT 0 diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index d730c7d9019..9da10381af0 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -133,11 +133,11 @@ typedef struct RegionView3D { short rflag; - /* last view */ + /* last view (use when switching out of camera view) */ float lviewquat[4]; short lpersp, lview; /* lpersp can never be set to 'RV3D_CAMOB' */ + float gridview; - float twangle[3]; diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index bd1266bba81..d55810deeac 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -146,8 +146,8 @@ static int nr_types = 0; static int nr_structs = 0; static char **names, *namedata; /* at address names[a] is string a */ static char **types, *typedata; /* at address types[a] is string a */ -static short *typelens; /* at typelens[a] is de length of type a */ -static short *alphalens; /* contains sizes as they are calculated on the DEC Alpha (64 bits), in fact any 64bit system */ +static short *typelens_native; /* at typelens[a] is the length of type 'a' on this systems bitness (32 or 64) */ +static short *typelens_64; /* contains sizes as they are calculated on 64 bit systems */ static short **structs, *structdata; /* at sp = structs[a] is the first address of a struct definition * sp[0] is type number * sp[1] is amount of elements @@ -244,8 +244,8 @@ static int add_type(const char *str, int len) for (nr = 0; nr < nr_types; nr++) { if (strcmp(str, types[nr]) == 0) { if (len) { - typelens[nr] = len; - alphalens[nr] = len; + typelens_native[nr] = len; + typelens_64[nr] = len; } return nr; } @@ -258,8 +258,8 @@ static int add_type(const char *str, int len) } strcpy(cp, str); types[nr_types] = cp; - typelens[nr_types] = len; - alphalens[nr_types] = len; + typelens_native[nr_types] = len; + typelens_64[nr_types] = len; if (nr_types >= maxnr) { printf("too many types\n"); @@ -714,7 +714,7 @@ static int arraysize(char *astr, int len) static int calculate_structlens(int firststruct) { - int a, b, len, alphalen, unknown = nr_structs, lastunknown, structtype, type, mul, namelen; + int a, b, len_native, len_64, unknown = nr_structs, lastunknown, structtype, type, mul, namelen; short *sp, *structpoin; char *cp; int has_pointer, dna_error = 0; @@ -729,11 +729,11 @@ static int calculate_structlens(int firststruct) structtype = structpoin[0]; /* when length is not known... */ - if (typelens[structtype] == 0) { + if (typelens_native[structtype] == 0) { sp = structpoin + 2; - len = 0; - alphalen = 0; + len_native = 0; + len_64 = 0; has_pointer = 0; /* check all elements in struct */ @@ -756,25 +756,25 @@ static int calculate_structlens(int firststruct) /* 4-8 aligned/ */ if (sizeof(void *) == 4) { - if (len % 4) { - printf("Align pointer error in struct (len4): %s %s\n", types[structtype], cp); + if (len_native % 4) { + printf("Align pointer error in struct (len_native 4): %s %s\n", types[structtype], cp); dna_error = 1; } } else { - if (len % 8) { - printf("Align pointer error in struct (len8): %s %s\n", types[structtype], cp); + if (len_native % 8) { + printf("Align pointer error in struct (len_native 8): %s %s\n", types[structtype], cp); dna_error = 1; } } - if (alphalen % 8) { - printf("Align pointer error in struct (alphalen8): %s %s\n", types[structtype], cp); + if (len_64 % 8) { + printf("Align pointer error in struct (len_64 8): %s %s\n", types[structtype], cp); dna_error = 1; } - len += sizeof(void *) * mul; - alphalen += 8 * mul; + len_native += sizeof(void *) * mul; + len_64 += 8 * mul; } else if (cp[0] == '[') { @@ -782,7 +782,7 @@ static int calculate_structlens(int firststruct) printf("Parse error in struct, invalid member name: %s %s\n", types[structtype], cp); dna_error = 1; } - else if (typelens[type]) { + else if (typelens_native[type]) { /* has the name an extra length? (array) */ mul = 1; if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen); @@ -794,54 +794,54 @@ static int calculate_structlens(int firststruct) /* struct alignment */ if (type >= firststruct) { - if (sizeof(void *) == 8 && (len % 8) ) { + if (sizeof(void *) == 8 && (len_native % 8) ) { printf("Align struct error: %s %s\n", types[structtype], cp); dna_error = 1; } } /* 2-4-8 aligned/ */ - if (type < firststruct && typelens[type] > 4 && (len % 8)) { - printf("Align 8 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 8); + if (type < firststruct && typelens_native[type] > 4 && (len_native % 8)) { + printf("Align 8 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 8); dna_error = 1; } - if (typelens[type] > 3 && (len % 4) ) { - printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 4); + if (typelens_native[type] > 3 && (len_native % 4) ) { + printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 4); dna_error = 1; } - else if (typelens[type] == 2 && (len % 2) ) { - printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 2); + else if (typelens_native[type] == 2 && (len_native % 2) ) { + printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 2); dna_error = 1; } - len += mul * typelens[type]; - alphalen += mul * alphalens[type]; + len_native += mul * typelens_native[type]; + len_64 += mul * typelens_64[type]; } else { - len = 0; - alphalen = 0; + len_native = 0; + len_64 = 0; break; } } - if (len == 0) { + if (len_native == 0) { unknown++; } else { - typelens[structtype] = len; - alphalens[structtype] = alphalen; + typelens_native[structtype] = len_native; + typelens_64[structtype] = len_64; /* two ways to detect if a struct contains a pointer: - * has_pointer is set or alphalen != len */ - if (has_pointer || alphalen != len) { - if (alphalen % 8) { - printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], alphalen % 8); + * has_pointer is set or len_64 != len_native */ + if (has_pointer || len_64 != len_native) { + if (len_64 % 8) { + printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], len_64 % 8); dna_error = 1; } } - if (len % 4) { - printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len % 4); + if (len_native % 4) { + printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len_native % 4); dna_error = 1; } @@ -863,7 +863,7 @@ static int calculate_structlens(int firststruct) structtype = structpoin[0]; /* length unknown */ - if (typelens[structtype] != 0) { + if (typelens_native[structtype] != 0) { printf(" %s\n", types[structtype]); } } @@ -877,7 +877,7 @@ static int calculate_structlens(int firststruct) structtype = structpoin[0]; /* length unknown yet */ - if (typelens[structtype] == 0) { + if (typelens_native[structtype] == 0) { printf(" %s\n", types[structtype]); } } @@ -923,7 +923,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[structtype]); + printf("\t%s\t:%d\n", types[structtype], typelens_native[structtype]); } } @@ -954,8 +954,8 @@ static int make_structDNA(char *baseDirectory, FILE *file) /* a maximum of 5000 variables, must be sufficient? */ names = MEM_callocN(sizeof(char *) * maxnr, "names"); types = MEM_callocN(sizeof(char *) * maxnr, "types"); - typelens = MEM_callocN(sizeof(short) * maxnr, "typelens"); - alphalens = MEM_callocN(sizeof(short) * maxnr, "alphalens"); + typelens_native = MEM_callocN(sizeof(short) * maxnr, "typelens_native"); + typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64"); structs = MEM_callocN(sizeof(short) * maxnr, "structs"); /* insertion of all known types */ @@ -1008,7 +1008,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) } printf("\n"); - sp = typelens; + sp = typelens_native; for (a = 0; a < nr_types; a++, sp++) { printf(" %s %d\n", types[a], *sp); } @@ -1016,7 +1016,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) for (a = 0; a < nr_structs; a++) { sp = structs[a]; - printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens[sp[0]]); + printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens_native[sp[0]]); num_types = sp[1]; sp += 2; /* ? num_types was elem? */ @@ -1068,7 +1068,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) len = 2 * nr_types; if (nr_types & 1) len += 2; - dna_write(file, typelens, len); + dna_write(file, typelens_native, len); /* WRITE STRUCTS */ strcpy(str, "STRC"); @@ -1099,7 +1099,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) } fprintf(fp, "main() {\n"); - sp = typelens; + sp = typelens_native; sp += firststruct; for (a = firststruct; a < nr_types; a++, sp++) { if (*sp) { @@ -1121,8 +1121,8 @@ static int make_structDNA(char *baseDirectory, FILE *file) MEM_freeN(structdata); MEM_freeN(names); MEM_freeN(types); - MEM_freeN(typelens); - MEM_freeN(alphalens); + MEM_freeN(typelens_native); + MEM_freeN(typelens_64); MEM_freeN(structs); if (debugSDNA > -1) printf("done.\n"); diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 240ad95bcee..1c41c67b39c 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -57,6 +57,7 @@ extern EnumPropertyItem sequence_modifier_type_items[]; extern EnumPropertyItem image_type_items[]; extern EnumPropertyItem image_color_mode_items[]; extern EnumPropertyItem image_depth_mode_items[]; +extern EnumPropertyItem image_generated_type_items[]; extern EnumPropertyItem color_sets_items[]; diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index ca579dde033..4b65d7e0185 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -51,7 +51,7 @@ # define __func__ __FUNCTION__ #endif -/* copied from BKE_utildefines.h ugh */ +/* copied from BLI_utildefines.h ugh */ #ifdef __GNUC__ # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) #else @@ -532,7 +532,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get"); switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func); fprintf(f, "{\n"); @@ -565,7 +566,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "}\n\n"); break; } - case PROP_POINTER: { + case PROP_POINTER: + { fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func); fprintf(f, "{\n"); if (manualfunc) { @@ -584,7 +586,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "}\n\n"); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func); @@ -785,7 +788,8 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set"); switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func); fprintf(f, "{\n"); @@ -817,7 +821,8 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, "}\n\n"); break; } - case PROP_POINTER: { + case PROP_POINTER: + { fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func); fprintf(f, "{\n"); if (manualfunc) { @@ -1275,7 +1280,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) prop = dp->prop; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (!prop->arraydimension) { @@ -1291,7 +1297,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (!prop->arraydimension) { @@ -1310,7 +1317,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (!prop->arraydimension) { @@ -1329,14 +1337,16 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; eprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)eprop->get); eprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)eprop->set); break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)sprop->get); @@ -1344,7 +1354,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) sprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)sprop->set); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; pprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get); @@ -1356,7 +1367,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) } break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; const char *nextfunc = (const char *)cprop->next; @@ -1421,7 +1433,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR switch (prop->type) { case PROP_BOOLEAN: - case PROP_INT: { + case PROP_INT: + { if (!prop->arraydimension) { fprintf(f, "int %sget(PointerRNA *ptr);\n", func); /*fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func); */ @@ -1436,7 +1449,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { if (!prop->arraydimension) { fprintf(f, "float %sget(PointerRNA *ptr);\n", func); /*fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func); */ @@ -1451,7 +1465,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR } break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; int i; @@ -1471,7 +1486,8 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (sprop->maxlength) { @@ -1484,12 +1500,14 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR break; } - case PROP_POINTER: { + case PROP_POINTER: + { fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func); /*fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func); */ break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func); fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func); fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func); @@ -1520,28 +1538,32 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property fprintf(f, "\t/* */\n"); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { if (!prop->arraydimension) fprintf(f, "\tinline bool %s(void);", rna_safe_id(prop->identifier)); else if (prop->totarraylength) fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } - case PROP_INT: { + case PROP_INT: + { if (!prop->arraydimension) fprintf(f, "\tinline int %s(void);", rna_safe_id(prop->identifier)); else if (prop->totarraylength) fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { if (!prop->arraydimension) fprintf(f, "\tinline float %s(void);", rna_safe_id(prop->identifier)); else if (prop->totarraylength) fprintf(f, "\tinline Array<float, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; int i; @@ -1559,11 +1581,13 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property fprintf(f, "\tinline %s_enum %s(void);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier)); break; } - case PROP_STRING: { + case PROP_STRING: + { fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier)); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop; if (pprop->type) @@ -1572,7 +1596,8 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier)); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop; if (cprop->item_type) @@ -1598,7 +1623,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe return; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { if (!prop->arraydimension) fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); else if (prop->totarraylength) @@ -1606,7 +1632,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_INT: { + case PROP_INT: + { if (!prop->arraydimension) fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); else if (prop->totarraylength) @@ -1614,7 +1641,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { if (!prop->arraydimension) fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); else if (prop->totarraylength) @@ -1622,17 +1650,20 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_ENUM: { + case PROP_ENUM: + { fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", rna_safe_id(prop->identifier), srna->identifier, rna_safe_id(prop->identifier)); break; } - case PROP_STRING: { + case PROP_STRING: + { fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier)); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop; if (pprop->type) @@ -1643,7 +1674,8 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe rna_safe_id(prop->identifier)); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { #if 0 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop; @@ -2218,7 +2250,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; int i, defaultfound = 0, totflag = 0; @@ -2270,7 +2303,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } break; } - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; unsigned int i; @@ -2291,7 +2325,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; unsigned int i; @@ -2312,7 +2347,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; unsigned int i; @@ -2380,7 +2416,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "},\n"); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), @@ -2393,7 +2430,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), @@ -2412,7 +2450,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), @@ -2432,7 +2471,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), @@ -2442,7 +2482,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n"); break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, NULL, ", rna_function_string(eprop->get), @@ -2455,7 +2496,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue); break; } - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s,", rna_function_string(pprop->get), rna_function_string(pprop->set), @@ -2465,7 +2507,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr else fprintf(f, "NULL\n"); break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), @@ -2882,8 +2925,8 @@ static const char *cpp_classes = "" " T data[Tsize];\n" "\n" " Array() {}\n" -" Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); }\n" -" const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); " +" Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); }\n" +" const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); " "return *this; }\n" "\n" " operator T*() { return data; }\n" diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index ec4da311686..4c1c377cb9f 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1659,8 +1659,9 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value) IDP_Int(idprop) = value; rna_idproperty_touch(idprop); } - else if (bprop->set) + else if (bprop->set) { bprop->set(ptr, value); + } else if (prop->flag & PROP_EDITABLE) { IDPropertyTemplate val = {0}; IDProperty *group; @@ -3192,19 +3193,22 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro /* handle conversions */ if (set) { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { int b; RAW_GET(int, b, in, a); RNA_property_boolean_set(&itemptr, iprop, b); break; } - case PROP_INT: { + case PROP_INT: + { int i; RAW_GET(int, i, in, a); RNA_property_int_set(&itemptr, iprop, i); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { float f; RAW_GET(float, f, in, a); RNA_property_float_set(&itemptr, iprop, f); @@ -3216,17 +3220,20 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } else { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { int b = RNA_property_boolean_get(&itemptr, iprop); RAW_SET(int, in, a, b); break; } - case PROP_INT: { + case PROP_INT: + { int i = RNA_property_int_get(&itemptr, iprop); RAW_SET(int, in, a, i); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { float f = RNA_property_float_get(&itemptr, iprop); RAW_SET(float, in, a, f); break; @@ -3251,19 +3258,22 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro /* handle conversions */ if (set) { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { for (j = 0; j < itemlen; j++, a++) RAW_GET(int, ((int *)tmparray)[j], in, a); RNA_property_boolean_set_array(&itemptr, iprop, tmparray); break; } - case PROP_INT: { + case PROP_INT: + { for (j = 0; j < itemlen; j++, a++) RAW_GET(int, ((int *)tmparray)[j], in, a); RNA_property_int_set_array(&itemptr, iprop, tmparray); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { for (j = 0; j < itemlen; j++, a++) RAW_GET(float, ((float *)tmparray)[j], in, a); RNA_property_float_set_array(&itemptr, iprop, tmparray); @@ -3275,19 +3285,22 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } else { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { RNA_property_boolean_get_array(&itemptr, iprop, tmparray); for (j = 0; j < itemlen; j++, a++) RAW_SET(int, in, a, ((int *)tmparray)[j]); break; } - case PROP_INT: { + case PROP_INT: + { RNA_property_int_get_array(&itemptr, iprop, tmparray); for (j = 0; j < itemlen; j++, a++) RAW_SET(int, in, a, ((int *)tmparray)[j]); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { RNA_property_float_get_array(&itemptr, iprop, tmparray); for (j = 0; j < itemlen; j++, a++) RAW_SET(float, in, a, ((float *)tmparray)[j]); @@ -3301,17 +3314,20 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro else { if (set) { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { RNA_property_boolean_set_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_INT: { + case PROP_INT: + { RNA_property_int_set_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { RNA_property_float_set_array(&itemptr, iprop, &((float *)in.array)[a]); a += itemlen; break; @@ -3322,17 +3338,20 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } else { switch (itemtype) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { RNA_property_boolean_get_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_INT: { + case PROP_INT: + { RNA_property_int_get_array(&itemptr, iprop, &((int *)in.array)[a]); a += itemlen; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { RNA_property_float_get_array(&itemptr, iprop, &((float *)in.array)[a]); a += itemlen; break; @@ -4924,7 +4943,8 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSE case PROP_ENUM: memcpy(data, &((EnumPropertyRNA *)parm)->defaultvalue, size); break; - case PROP_STRING: { + case PROP_STRING: + { const char *defvalue = ((StringPropertyRNA *)parm)->defaultvalue; if (defvalue && defvalue[0]) { /* causes bug [#29988], possibly this is only correct for thick wrapped diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 738e7ad2219..be70405d165 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -146,6 +146,18 @@ static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene), WM_main_add_notifier(NC_GEOM | ND_DATA, id); } +/* called whenever a bone is renamed */ +static void rna_Bone_update_renamed(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +{ + ID *id = ptr->id.data; + + /* redraw view */ + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + /* update animation channels */ + WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN, id); +} + static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { ID *id = ptr->id.data; @@ -470,7 +482,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone) RNA_def_struct_name_property(srna, prop); if (editbone) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_EditBone_name_set"); else RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Bone_name_set"); - RNA_def_property_update(prop, 0, "rna_Armature_redraw_data"); + RNA_def_property_update(prop, 0, "rna_Bone_update_renamed"); /* flags */ prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER); diff --git a/source/blender/makesrna/intern/rna_camera_api.c b/source/blender/makesrna/intern/rna_camera_api.c index 2d19047ef89..75941fa224f 100644 --- a/source/blender/makesrna/intern/rna_camera_api.c +++ b/source/blender/makesrna/intern/rna_camera_api.c @@ -29,9 +29,7 @@ #include <stdio.h> #include <string.h> - #include "RNA_define.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 0320c0d7142..45092d09ce1 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -926,7 +926,8 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier } } break; - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->hardmin = (subtype == PROP_UNSIGNED) ? 0 : INT_MIN; @@ -937,7 +938,8 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier iprop->step = 1; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->hardmin = (subtype == PROP_UNSIGNED) ? 0.0f : -FLT_MAX; @@ -959,7 +961,8 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier fprop->precision = 3; break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->defaultvalue = ""; @@ -1009,19 +1012,22 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier RNA_def_property_boolean_sdna(prop, NULL, identifier, 0); DefRNA.silent = 0; break; - case PROP_INT: { + case PROP_INT: + { DefRNA.silent = 1; RNA_def_property_int_sdna(prop, NULL, identifier); DefRNA.silent = 0; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { DefRNA.silent = 1; RNA_def_property_float_sdna(prop, NULL, identifier); DefRNA.silent = 0; break; } - case PROP_STRING: { + case PROP_STRING: + { DefRNA.silent = 1; RNA_def_property_string_sdna(prop, NULL, identifier); DefRNA.silent = 0; @@ -1173,14 +1179,16 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->softmin = (int)min; iprop->softmax = (int)max; iprop->step = (int)step; break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->softmin = (float)min; fprop->softmax = (float)max; @@ -1201,7 +1209,8 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->hardmin = (int)min; iprop->hardmax = (int)max; @@ -1209,7 +1218,8 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max) iprop->softmax = MIN2((int)max, iprop->hardmax); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->hardmin = (float)min; fprop->hardmax = (float)max; @@ -1234,12 +1244,14 @@ void RNA_def_property_struct_type(PropertyRNA *prop, const char *type) } switch (prop->type) { - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; pprop->type = (StructRNA *)type; break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; cprop->item_type = (StructRNA *)type; break; @@ -1262,7 +1274,8 @@ void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type) } switch (prop->type) { - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; pprop->type = type; @@ -1271,7 +1284,8 @@ void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type) break; } - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; cprop->item_type = type; break; @@ -1290,7 +1304,8 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item int i, defaultfound = 0; switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; eprop->item = (EnumPropertyItem *)item; eprop->totitem = 0; @@ -1325,7 +1340,8 @@ void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->maxlength = maxlength; break; @@ -1342,7 +1358,8 @@ void RNA_def_property_boolean_default(PropertyRNA *prop, int value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; bprop->defaultvalue = value; break; @@ -1359,7 +1376,8 @@ void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; bprop->defaultarray = array; break; @@ -1376,7 +1394,8 @@ void RNA_def_property_int_default(PropertyRNA *prop, int value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->defaultvalue = value; break; @@ -1393,7 +1412,8 @@ void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; iprop->defaultarray = array; break; @@ -1410,7 +1430,8 @@ void RNA_def_property_float_default(PropertyRNA *prop, float value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->defaultvalue = value; break; @@ -1427,7 +1448,8 @@ void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; fprop->defaultarray = array; /* WARNING, this array must not come from the stack and lost */ break; @@ -1444,7 +1466,8 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value) StructRNA *srna = DefRNA.laststruct; switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; sprop->defaultvalue = value; break; @@ -1462,7 +1485,8 @@ void RNA_def_property_enum_default(PropertyRNA *prop, int value) int i, defaultfound = 0; switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; eprop->defaultvalue = value; @@ -1945,7 +1969,8 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch } switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (prop->arraydimension) { @@ -1975,7 +2000,8 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char * } switch (prop->type) { - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (prop->arraydimension) { @@ -2006,7 +2032,8 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char } switch (prop->type) { - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (prop->arraydimension) { @@ -2037,7 +2064,8 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char } switch (prop->type) { - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; if (get) eprop->get = (PropEnumGetFunc)get; @@ -2062,7 +2090,8 @@ void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const cha } switch (prop->type) { - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (get) sprop->get = (PropStringGetFunc)get; @@ -2088,7 +2117,8 @@ void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const ch } switch (prop->type) { - case PROP_POINTER: { + case PROP_POINTER: + { PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; if (get) pprop->get = (PropPointerGetFunc)get; @@ -2116,7 +2146,8 @@ void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, con } switch (prop->type) { - case PROP_COLLECTION: { + case PROP_COLLECTION: + { CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; if (begin) cprop->begin = (PropCollectionBeginFunc)begin; @@ -2742,7 +2773,8 @@ int rna_parameter_size(PropertyRNA *parm) } else return sizeof(char *); - case PROP_POINTER: { + case PROP_POINTER: + { #ifdef RNA_RUNTIME if (parm->flag & PROP_RNAPTR) return sizeof(PointerRNA); @@ -2889,7 +2921,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA if (prop->description) prop->description = BLI_strdup(prop->description); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (bprop->defaultarray) { @@ -2899,7 +2932,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (iprop->defaultarray) { @@ -2909,7 +2943,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; if (eprop->item) { @@ -2928,7 +2963,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (fprop->defaultarray) { @@ -2938,7 +2974,8 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA } break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (sprop->defaultvalue) sprop->defaultvalue = BLI_strdup(sprop->defaultvalue); @@ -2966,25 +3003,29 @@ void RNA_def_property_free_pointers(PropertyRNA *prop) MEM_freeN(prop->py_data); switch (prop->type) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; if (bprop->defaultarray) MEM_freeN((void *)bprop->defaultarray); break; } - case PROP_INT: { + case PROP_INT: + { IntPropertyRNA *iprop = (IntPropertyRNA *)prop; if (iprop->defaultarray) MEM_freeN((void *)iprop->defaultarray); break; } - case PROP_FLOAT: { + case PROP_FLOAT: + { FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; if (fprop->defaultarray) MEM_freeN((void *)fprop->defaultarray); break; } - case PROP_ENUM: { + case PROP_ENUM: + { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; for (a = 0; a < eprop->totitem; a++) { @@ -2999,7 +3040,8 @@ void RNA_def_property_free_pointers(PropertyRNA *prop) if (eprop->item) MEM_freeN((void *)eprop->item); break; } - case PROP_STRING: { + case PROP_STRING: + { StringPropertyRNA *sprop = (StringPropertyRNA *)prop; if (sprop->defaultvalue) MEM_freeN((void *)sprop->defaultvalue); diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index e84a290acb8..daa661175a1 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -24,15 +24,16 @@ * \ingroup RNA */ - #include <stdlib.h> +#include "DNA_object_fluidsim.h" + +#include "BLI_path_util.h" + #include "RNA_define.h" #include "rna_internal.h" -#include "DNA_object_fluidsim.h" - #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c index e246c6975b5..eb12a02aa99 100644 --- a/source/blender/makesrna/intern/rna_gpencil.c +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -203,7 +203,7 @@ static void rna_def_gpencil_layer(BlenderRNA *brna) RNA_def_property_editable_func(prop, "rna_GPencilLayer_active_frame_editable"); /* Drawing Color */ - prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_array(prop, 3); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Color", "Color for all strokes in this layer"); diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 03e446c9d91..62a06888613 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -42,6 +42,13 @@ #include "WM_types.h" #include "WM_api.h" +EnumPropertyItem image_generated_type_items[] = { + {IMA_GENTYPE_BLANK, "BLANK", 0, "Blank", "Generate a blank image"}, + {IMA_GENTYPE_GRID, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"}, + {IMA_GENTYPE_GRID_COLOR, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"}, + {0, NULL, 0, NULL, NULL} +}; + static EnumPropertyItem image_source_items[] = { {IMA_SRC_FILE, "FILE", 0, "Single Image", "Single image file"}, {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"}, @@ -436,12 +443,6 @@ static void rna_def_image(BlenderRNA *brna) {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""}, {0, NULL, 0, NULL, NULL} }; - static const EnumPropertyItem prop_generated_type_items[] = { - {0, "BLANK", 0, "Blank", "Generate a blank image"}, - {1, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"}, - {2, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"}, - {0, NULL, 0, NULL, NULL} - }; static const EnumPropertyItem prop_mapping_items[] = { {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"}, {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"}, @@ -520,7 +521,7 @@ static void rna_def_image(BlenderRNA *brna) /* generated image (image_generated_change_cb) */ prop = RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "gen_type"); - RNA_def_property_enum_items(prop, prop_generated_type_items); + RNA_def_property_enum_items(prop, image_generated_type_items); RNA_def_property_ui_text(prop, "Generated Type", "Generated image type"); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 17261c2c909..78e0fde5715 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -24,16 +24,15 @@ * \ingroup RNA */ - #include <stdlib.h> #include <string.h> +#include "BLI_path_util.h" + #include "RNA_define.h" #include "rna_internal.h" -#include "BKE_utildefines.h" - #ifdef RNA_RUNTIME #include "BKE_main.h" diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index ae1e8b5548b..2d26fec0d50 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -35,12 +35,13 @@ #include "DNA_ID.h" +#include "BLI_path_util.h" + #include "RNA_define.h" #include "RNA_access.h" #include "RNA_enum_types.h" -#include "rna_internal.h" -#include "BKE_utildefines.h" +#include "rna_internal.h" #ifdef RNA_RUNTIME @@ -556,7 +557,7 @@ Mask *rna_Main_mask_new(Main *UNUSED(bmain), const char *name) void rna_Main_masks_remove(Main *bmain, Mask *mask) { - BKE_mask_unlink(bmain, mask); + BKE_mask_free(bmain, mask); BKE_libblock_free(&bmain->mask, mask); /* XXX python now has invalid pointer? */ } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 2f763a6ed0e..55dda3fc315 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1526,6 +1526,15 @@ static void def_sh_tex_image(StructRNA *srna) {0, NULL, 0, NULL, NULL} }; + static const EnumPropertyItem prop_projection_items[] = { + {SHD_PROJ_FLAT, "FLAT", 0, "Flat", + "Image is projected flat using the X and Y coordinates of the texture vector"}, + {SHD_PROJ_BOX, "BOX", 0, "Box", + "Image is projected using different components for each side of the object space bounding box"}, + {0, NULL, 0, NULL, NULL} + }; + + PropertyRNA *prop; prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); @@ -1543,6 +1552,15 @@ static void def_sh_tex_image(StructRNA *srna) RNA_def_property_ui_text(prop, "Color Space", "Image file color space"); RNA_def_property_update(prop, 0, "rna_Node_update"); + prop = RNA_def_property(srna, "projection", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, prop_projection_items); + RNA_def_property_ui_text(prop, "Projection", "Method to project 2D image on object with a 3D texture vector"); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "projection_blend", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_ui_text(prop, "Projection Blend", "For box projection, amount of blend to use between sides"); + RNA_def_property_update(prop, 0, "rna_Node_update"); + prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_NEVER_NULL); RNA_def_property_pointer_sdna(prop, NULL, "iuser"); @@ -1588,6 +1606,43 @@ static void def_sh_tex_checker(StructRNA *srna) def_sh_tex(srna); } +static void def_sh_tex_brick(StructRNA *srna) +{ + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeTexBrick", "storage"); + def_sh_tex(srna); + + prop = RNA_def_property(srna, "offset_frequency", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "offset_freq"); + RNA_def_property_int_default(prop, 2); + RNA_def_property_range(prop, 1, 99); + RNA_def_property_ui_text(prop, "Offset Frequency", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "squash_frequency", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "squash_freq"); + RNA_def_property_int_default(prop, 2); + RNA_def_property_range(prop, 1, 99); + RNA_def_property_ui_text(prop, "Squash Frequency", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "offset"); + RNA_def_property_float_default(prop, 0.5f); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Offset Amount", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "squash", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "squash"); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_range(prop, 0.0f, 99.0f); + RNA_def_property_ui_text(prop, "Squash Amount", ""); + RNA_def_property_update(prop, 0, "rna_Node_update"); + +} + static void def_sh_tex_magic(StructRNA *srna) { PropertyRNA *prop; diff --git a/source/blender/makesrna/intern/rna_nodetree_types.h b/source/blender/makesrna/intern/rna_nodetree_types.h index 15ad1c557a5..0baa4cc0838 100644 --- a/source/blender/makesrna/intern/rna_nodetree_types.h +++ b/source/blender/makesrna/intern/rna_nodetree_types.h @@ -91,6 +91,7 @@ DefNode( ShaderNode, SH_NODE_TEX_WAVE, def_sh_tex_wave, "TE DefNode( ShaderNode, SH_NODE_TEX_MUSGRAVE, def_sh_tex_musgrave, "TEX_MUSGRAVE", TexMusgrave, "Musgrave Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_VORONOI, def_sh_tex_voronoi, "TEX_VORONOI", TexVoronoi, "Voronoi Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_CHECKER, def_sh_tex_checker, "TEX_CHECKER", TexChecker, "Checker Texture", "" ) +DefNode( ShaderNode, SH_NODE_TEX_BRICK, def_sh_tex_brick, "TEX_BRICK", TexBrick, "Brick Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_COORD, 0, "TEX_COORD", TexCoord, "Texture Coordinate","" ) DefNode( CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" ) diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 7ab359661c5..5bf1cc281ad 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -84,7 +84,8 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ switch (ob->type) { case OB_FONT: case OB_CURVE: - case OB_SURF: { + case OB_SURF: + { ListBase dispbase = {NULL, NULL}; DerivedMesh *derivedFinal = NULL; int uv_from_orco; @@ -163,7 +164,8 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ break; } - case OB_MBALL: { + case OB_MBALL: + { /* metaballs don't have modifiers, so just convert to mesh */ Object *basis_ob = BKE_mball_basis_find(sce, ob); /* todo, re-generatre for render-res */ diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index fff16650a93..d2e4e8edbfb 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -24,11 +24,12 @@ * \ingroup RNA */ - #include <stdlib.h> #include "DNA_scene_types.h" +#include "BLI_path_util.h" + #include "RNA_define.h" #include "RNA_enum_types.h" @@ -37,7 +38,6 @@ #include "RE_engine.h" #include "RE_pipeline.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME @@ -317,6 +317,7 @@ static void rna_def_render_engine(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REQUIRED); prop = RNA_def_int(func, "h", 0, 0, INT_MAX, "Height", "", 0, INT_MAX); RNA_def_property_flag(prop, PROP_REQUIRED); + RNA_def_string(func, "layer", "", 0, "Layer", "Single layer to get render result for"); /* NULL ok here */ prop = RNA_def_pointer(func, "result", "RenderResult", "Result", ""); RNA_def_function_return(func, prop); @@ -327,6 +328,8 @@ static void rna_def_render_engine(BlenderRNA *brna) func = RNA_def_function(srna, "end_result", "RE_engine_end_result"); prop = RNA_def_pointer(func, "result", "RenderResult", "Result", ""); RNA_def_property_flag(prop, PROP_REQUIRED); + prop = RNA_def_boolean(func, "cancel", 0, "Cancel", "Don't merge back results"); + RNA_def_property_flag(prop, PROP_REQUIRED); func = RNA_def_function(srna, "test_break", "RE_engine_test_break"); prop = RNA_def_boolean(func, "do_break", 0, "Break", ""); @@ -360,6 +363,19 @@ static void rna_def_render_engine(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "camera_override"); RNA_def_property_struct_type(prop, "Object"); + prop = RNA_def_property(srna, "tile_x", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "tile_x"); + prop = RNA_def_property(srna, "tile_y", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "tile_y"); + + prop = RNA_def_property(srna, "resolution_x", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "resolution_x"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + prop = RNA_def_property(srna, "resolution_y", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "resolution_y"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + /* registration */ prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 62631e60e2b..bd4d3e84883 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -3990,11 +3990,13 @@ static void rna_def_scene_render_data(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "mode", R_ENVMAP); RNA_def_property_ui_text(prop, "Environment Maps", "Calculate environment maps while rendering"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); - + +#if 0 prop = RNA_def_property(srna, "use_radiosity", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", R_RADIO); RNA_def_property_ui_text(prop, "Radiosity", "Calculate radiosity in a pre-process before rendering"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); +#endif prop = RNA_def_property(srna, "use_sss", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SSS); diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 61be48f3f02..69b61b47d8a 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -32,13 +32,13 @@ #include <stdlib.h> #include <stdio.h> +#include "BLI_path_util.h" + #include "RNA_define.h" #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BKE_utildefines.h" - #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c index 00e8ed5289f..314082dfd02 100644 --- a/source/blender/makesrna/intern/rna_sensor.c +++ b/source/blender/makesrna/intern/rna_sensor.c @@ -417,6 +417,11 @@ static void rna_def_mouse_sensor(BlenderRNA *brna) RNA_def_property_enum_items(prop, mouse_event_items); RNA_def_property_ui_text(prop, "Mouse Event", "Type of event this mouse sensor should trigger on"); RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_MOUSE_FOCUS_PULSE); + RNA_def_property_ui_text(prop, "Pulse", "Moving the mouse over a different object generates a pulse"); + RNA_def_property_update(prop, NC_LOGIC, NULL); } static void rna_def_touch_sensor(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index a3884b62ec1..e3e467a9abb 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -56,7 +56,6 @@ typedef struct EffectInfo { const char *ui_desc; void (*func)(StructRNA *); int inputs; - int supports_mask; } EffectInfo; EnumPropertyItem sequence_modifier_type_items[] = { @@ -244,28 +243,6 @@ static void rna_Sequence_channel_set(PointerRNA *ptr, int value) BKE_sequencer_sort(scene); } -/* properties that need to allocate structs */ -static void rna_Sequence_use_color_balance_set(PointerRNA *ptr, int value) -{ - Sequence *seq = (Sequence *)ptr->data; - int c; - - if (value) { - seq->flag |= SEQ_USE_COLOR_BALANCE; - if (seq->strip->color_balance == NULL) { - seq->strip->color_balance = MEM_callocN(sizeof(struct StripColorBalance), "StripColorBalance"); - for (c = 0; c < 3; c++) { - seq->strip->color_balance->lift[c] = 1.0f; - seq->strip->color_balance->gamma[c] = 1.0f; - seq->strip->color_balance->gain[c] = 1.0f; - } - } - } - else { - seq->flag ^= SEQ_USE_COLOR_BALANCE; - } -} - static void rna_Sequence_use_proxy_set(PointerRNA *ptr, int value) { Sequence *seq = (Sequence *)ptr->data; @@ -608,13 +585,6 @@ static int rna_Sequence_input_count_get(PointerRNA *ptr) return BKE_sequence_effect_get_num_inputs(seq->type); } -static int rna_Sequence_supports_mask_get(PointerRNA *ptr) -{ - Sequence *seq = (Sequence *)(ptr->data); - - return BKE_sequence_effect_get_supports_mask(seq->type); -} - #if 0 static void rna_SoundSequence_filename_set(PointerRNA *ptr, const char *value) { @@ -642,26 +612,12 @@ static void rna_Sequence_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Point } } -static int rna_Sequence_otherSequence_poll(PointerRNA *ptr, PointerRNA value) -{ - Sequence *seq = (Sequence *) ptr->data; - Sequence *cur = (Sequence *) value.data; - - if (seq == cur) - return FALSE; - - if (BKE_sequence_check_depend(seq, cur)) - return FALSE; - - return TRUE; -} - static void rna_Sequence_update_reopen_files(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { Scene *scene = (Scene *) ptr->id.data; Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE); if (RNA_struct_is_a(ptr->type, &RNA_SoundSequence)) BKE_sequencer_update_sound_bounds(scene, ptr->data); @@ -1631,16 +1587,6 @@ static void rna_def_filter_video(StructRNA *srna) RNA_def_property_ui_text(prop, "Strobe", "Only display every nth frame"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); - prop = RNA_def_property(srna, "use_color_balance", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_USE_COLOR_BALANCE); - RNA_def_property_ui_text(prop, "Use Color Balance", "(3-Way color correction) on input"); - RNA_def_property_boolean_funcs(prop, NULL, "rna_Sequence_use_color_balance_set"); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); - - prop = RNA_def_property(srna, "color_balance", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "strip->color_balance"); - RNA_def_property_ui_text(prop, "Color Balance", ""); - prop = RNA_def_property(srna, "use_translation", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_USE_TRANSFORM); RNA_def_property_ui_text(prop, "Use Translation", "Translate image before processing"); @@ -1706,7 +1652,7 @@ static void rna_def_input(StructRNA *srna) RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); } -static void rna_def_effect_inputs(StructRNA *srna, int count, int supports_mask) +static void rna_def_effect_inputs(StructRNA *srna, int count) { PropertyRNA *prop; @@ -1714,10 +1660,6 @@ static void rna_def_effect_inputs(StructRNA *srna, int count, int supports_mask) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_int_funcs(prop, "rna_Sequence_input_count_get", NULL, NULL); - prop = RNA_def_property(srna, "is_supports_mask", PROP_INT, PROP_UNSIGNED); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_int_funcs(prop, "rna_Sequence_supports_mask_get", NULL, NULL); - if (count >= 1) { prop = RNA_def_property(srna, "input_1", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "seq1"); @@ -1740,15 +1682,6 @@ static void rna_def_effect_inputs(StructRNA *srna, int count, int supports_mask) RNA_def_property_ui_text(prop, "Input 3", "Third input for the effect strip"); } */ - - if (supports_mask) { - prop = RNA_def_property(srna, "input_mask_strip", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "mask_sequence"); - RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Sequence_otherSequence_poll"); - RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Mask", "Mask input for the effect strip"); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); - } } static void rna_def_image(BlenderRNA *brna) @@ -2189,28 +2122,28 @@ static void rna_def_speed_control(StructRNA *srna) } static EffectInfo def_effects[] = { - {"AddSequence", "Add Sequence", "Add Sequence", NULL, 2, FALSE}, + {"AddSequence", "Add Sequence", "Add Sequence", NULL, 2}, {"AdjustmentSequence", "Adjustment Layer Sequence", - "Sequence strip to perform filter adjustments to layers below", rna_def_input, 0, TRUE}, - {"AlphaOverSequence", "Alpha Over Sequence", "Alpha Over Sequence", NULL, 2, FALSE}, - {"AlphaUnderSequence", "Alpha Under Sequence", "Alpha Under Sequence", NULL, 2, FALSE}, + "Sequence strip to perform filter adjustments to layers below", rna_def_input, 0}, + {"AlphaOverSequence", "Alpha Over Sequence", "Alpha Over Sequence", NULL, 2}, + {"AlphaUnderSequence", "Alpha Under Sequence", "Alpha Under Sequence", NULL, 2}, {"ColorSequence", "Color Sequence", - "Sequence strip creating an image filled with a single color", rna_def_solid_color, 0, FALSE}, - {"CrossSequence", "Cross Sequence", "Cross Sequence", NULL, 2, FALSE}, - {"GammaCrossSequence", "Gamma Cross Sequence", "Gamma Cross Sequence", NULL, 2, FALSE}, - {"GlowSequence", "Glow Sequence", "Sequence strip creating a glow effect", rna_def_glow, 1, FALSE}, + "Sequence strip creating an image filled with a single color", rna_def_solid_color, 0}, + {"CrossSequence", "Cross Sequence", "Cross Sequence", NULL, 2}, + {"GammaCrossSequence", "Gamma Cross Sequence", "Gamma Cross Sequence", NULL, 2}, + {"GlowSequence", "Glow Sequence", "Sequence strip creating a glow effect", rna_def_glow, 1}, {"MulticamSequence", "Multicam Select Sequence", "Sequence strip to perform multicam editing", - rna_def_multicam, 0, FALSE}, - {"MultiplySequence", "Multiply Sequence", "Multiply Sequence", NULL, 2, FALSE}, - {"OverDropSequence", "Over Drop Sequence", "Over Drop Sequence", NULL, 2, FALSE}, + rna_def_multicam, 0}, + {"MultiplySequence", "Multiply Sequence", "Multiply Sequence", NULL, 2}, + {"OverDropSequence", "Over Drop Sequence", "Over Drop Sequence", NULL, 2}, {"SpeedControlSequence", "SpeedControl Sequence", - "Sequence strip to control the speed of other strips", rna_def_speed_control, 1, FALSE}, - {"SubtractSequence", "Subtract Sequence", "Subtract Sequence", NULL, 2, FALSE}, + "Sequence strip to control the speed of other strips", rna_def_speed_control, 1}, + {"SubtractSequence", "Subtract Sequence", "Subtract Sequence", NULL, 2}, {"TransformSequence", "Transform Sequence", - "Sequence strip applying affine transformations to other strips", rna_def_transform, 1, FALSE}, + "Sequence strip applying affine transformations to other strips", rna_def_transform, 1}, {"WipeSequence", "Wipe Sequence", "Sequence strip creating a wipe transition", - rna_def_wipe, 1, FALSE}, - {"", "", "", NULL, 0, FALSE} + rna_def_wipe, 1}, + {"", "", "", NULL, 0} }; static void rna_def_effects(BlenderRNA *brna) @@ -2223,7 +2156,7 @@ static void rna_def_effects(BlenderRNA *brna) RNA_def_struct_ui_text(srna, effect->ui_name, effect->ui_desc); RNA_def_struct_sdna(srna, "Sequence"); - rna_def_effect_inputs(srna, effect->inputs, effect->supports_mask); + rna_def_effect_inputs(srna, effect->inputs); if (effect->func) effect->func(srna); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index ad14c60e532..a00e8bfea2d 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -531,12 +531,7 @@ static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr) static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr) { - SpaceImage *sima = (SpaceImage *)(ptr->data); - if (sima->mode == SI_MODE_PAINT) { - BKE_paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); - - ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); - } + ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); } static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr) @@ -1560,7 +1555,7 @@ static void rna_def_space_view3d(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "near"); RNA_def_property_range(prop, 0.001f, FLT_MAX); RNA_def_property_float_default(prop, 0.1f); - RNA_def_property_ui_text(prop, "Clip Start", "3D View near clipping distance"); + RNA_def_property_ui_text(prop, "Clip Start", "3D View near clipping distance (perspective view only)"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE); diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c index ff8940129a1..e62b3ecd804 100644 --- a/source/blender/makesrna/intern/rna_texture_api.c +++ b/source/blender/makesrna/intern/rna_texture_api.c @@ -24,14 +24,13 @@ * \ingroup RNA */ - #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "BLI_path_util.h" #include "RNA_define.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index ed057235f0d..018022fdde9 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2992,11 +2992,12 @@ static void rna_def_userdef_system(BlenderRNA *brna) /* locale according to http://www.roseindia.net/tutorials/I18N/locales-list.shtml */ /* if you edit here, please also edit the source/blender/blenfont/intern/blf_lang.c 's locales */ /* Note: As this list is in alphabetical order, and not defined order, - * here is the highest define currently in use: 31 (Hungarian). */ + * here is the highest define currently in use: 33 (Hebrew). */ static EnumPropertyItem language_items[] = { { 0, "", 0, N_("Nearly done"), ""}, { 0, "DEFAULT", 0, "Default (Default)", ""}, {21, "ARABIC", 0, "Arabic (ﺔﻴﺑﺮﻌﻟﺍ)", "ar_EG"}, + {32, "BRAZILIANPORTUGUESE", 0, "Brazilian Portuguese (Português do Brasil)", "pt_BR"}, { 1, "ENGLISH", 0, "English (English)", "en_US"}, { 8, "FRENCH", 0, "French (Français)", "fr_FR"}, { 4, "ITALIAN", 0, "Italian (Italiano)", "it_IT"}, @@ -3017,6 +3018,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) { 6, "FINNISH", 0, "Finnish (Suomi)", "fi_FI"}, { 5, "GERMAN", 0, "German (Deutsch)", "de_DE"}, {23, "GREEK", 0, "Greek (Ελληνικά)", "el_GR"}, + {33, "HEBREW", 0, "Hebrew (עִבְרִית)", "he_IL"}, {31, "HUNGARIAN", 0, "Hungarian (magyar)", "hu_HU"}, {27, "INDONESIAN", 0, "Indonesian (Bahasa indonesia)", "id_ID"}, {29, "KYRGYZ", 0, "Kyrgyz (Кыргыз тили)", "ky_KG"}, @@ -3273,6 +3275,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_enum_items(prop, compute_device_type_items); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_userdef_compute_device_type_itemf"); RNA_def_property_ui_text(prop, "Compute Device Type", "Device to use for computation (rendering with Cycles)"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL); prop = RNA_def_property(srna, "compute_device", PROP_ENUM, PROP_NONE); RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index d910ed7900c..ae4d5dc493e 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -83,9 +83,10 @@ void rna_event_timer_remove(struct wmWindowManager *wm, wmTimer *timer) } static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, const char *idname, int type, int value, - int any, int shift, int ctrl, int alt, int oskey, int keymodifier) + int any, int shift, int ctrl, int alt, int oskey, int keymodifier, int head) { /* wmWindowManager *wm = CTX_wm_manager(C); */ + wmKeyMapItem *kmi = NULL; char idname_bl[OP_MAX_TYPENAME]; int modifier = 0; @@ -103,8 +104,19 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, cons if (oskey) modifier |= KM_OSKEY; if (any) modifier = KM_ANY; - - return WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); + + /* create keymap item */ + kmi = WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); + + /* [#32437] allow scripts to define hotkeys that get added to start of keymap + * so that they stand a chance against catch-all defines later on + */ + if (head) { + BLI_remlink(&km->items, kmi); + BLI_addhead(&km->items, kmi); + } + + return kmi; } static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km, ReportList *reports, const char *propvalue_str, @@ -425,6 +437,9 @@ void RNA_api_keymapitems(StructRNA *srna) RNA_def_boolean(func, "alt", 0, "Alt", ""); RNA_def_boolean(func, "oskey", 0, "OS Key", ""); RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); + RNA_def_boolean(func, "head", 0, "At Head", + "Force item to be added at start (not end) of key map so that " + "it doesn't get blocked by an existing key map item"); parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item"); RNA_def_function_return(func, parm); diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner.py b/source/blender/makesrna/rna_cleanup/rna_cleaner.py index b75d177d809..e3359fbae59 100755 --- a/source/blender/makesrna/rna_cleanup/rna_cleaner.py +++ b/source/blender/makesrna/rna_cleanup/rna_cleaner.py @@ -60,7 +60,7 @@ def check_commandline(): usage() if sys.argv[1] == '-h': help() - elif not (sys.argv[1].endswith(".txt") or sys.argv[1].endswith(".py")): + elif not sys.argv[1].endswith((".txt", ".py")): print ('\nBad input file extension... exiting.') usage() else: diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 1c98880c3db..9acac6d00cd 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -51,7 +51,6 @@ #include "BKE_fluidsim.h" /* ensure definitions here match */ #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" -#include "BKE_utildefines.h" #include "BKE_global.h" /* G.main->name only */ #include "MOD_fluidsim_util.h" diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 6f3d47b3426..febc4190fdf 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -43,7 +43,6 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_deform.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 21836453eed..3bf8b9ffacc 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -37,7 +37,6 @@ #include "BKE_global.h" #include "BKE_modifier.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" #include "BLI_blenlib.h" #include "BLI_math.h" diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index c034832bfb4..e64e80efde3 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -105,6 +105,41 @@ static void foreachObjectLink(ModifierData *md, Object *ob, walk(userData, ob, &pimd->ob); } +static int particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psys, int p) +{ + ParticleData *pa; + + if (pimd->flag & eParticleInstanceFlag_Parents) { + if (p >= psys->totpart) { + if (psys->part->childtype == PART_CHILD_PARTICLES) { + pa = psys->particles + (psys->child + p - psys->totpart)->parent; + } + else { + pa = NULL; + } + } + else { + pa = psys->particles + p; + } + } + else { + if (psys->part->childtype == PART_CHILD_PARTICLES) { + pa = psys->particles + (psys->child + p)->parent; + } + else { + pa = NULL; + } + } + + if (pa) { + if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) return 1; + if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) return 1; + if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) return 1; + } + + return 0; +} + static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) @@ -113,11 +148,13 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md; ParticleSimulationData sim; ParticleSystem *psys = NULL; - ParticleData *pa = NULL, *pars = NULL; + ParticleData *pa = NULL; MPoly *mpoly, *orig_mpoly; MLoop *mloop, *orig_mloop; MVert *mvert, *orig_mvert; - int i, totvert, totpoly, totloop, maxvert, maxpoly, maxloop, totpart = 0, first_particle = 0; + int totvert, totpoly, totloop /* , totedge */; + int maxvert, maxpoly, maxloop, totpart = 0, first_particle = 0; + int k, p, p_skip; short track = ob->trackflag % 3, trackneg, axis = pimd->axis; float max_co = 0.0, min_co = 0.0, temp_co[3], cross[3]; float *size = NULL; @@ -153,7 +190,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, sim.psmd = psys_get_modifier(pimd->ob, psys); if (pimd->flag & eParticleInstanceFlag_UseSize) { - int p; float *si; si = size = MEM_callocN(totpart * sizeof(float), "particle size array"); @@ -171,15 +207,24 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } } - pars = psys->particles; - totvert = dm->getNumVerts(dm); totpoly = dm->getNumPolys(dm); totloop = dm->getNumLoops(dm); + /* totedge = dm->getNumEdges(dm); */ /* UNUSED */ - maxvert = totvert * totpart; - maxpoly = totpoly * totpart; - maxloop = totloop * totpart; + /* count particles */ + maxvert = 0; + maxpoly = 0; + maxloop = 0; + + for (p = 0; p < totpart; p++) { + if (particle_skip(pimd, psys, p)) + continue; + + maxvert += totvert; + maxpoly += totpoly; + maxloop += totloop; + } psys->lattice = psys_get_lattice(&sim); @@ -191,127 +236,110 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, max_co = max_r[track]; } - result = CDDM_from_template(dm, maxvert, dm->getNumEdges(dm) * totpart, 0, maxloop, maxpoly); + result = CDDM_from_template(dm, maxvert, 0, 0, maxloop, maxpoly); mvert = result->getVertArray(result); orig_mvert = dm->getVertArray(dm); - for (i = 0; i < maxvert; i++) { - MVert *inMV; - MVert *mv = mvert + i; - ParticleKey state; - - inMV = orig_mvert + i % totvert; - DM_copy_vert_data(dm, result, i % totvert, i, 1); - *mv = *inMV; - - /*change orientation based on object trackflag*/ - copy_v3_v3(temp_co, mv->co); - mv->co[axis] = temp_co[track]; - mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3]; - mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3]; - - if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) && - (pimd->flag & eParticleInstanceFlag_Path)) - { - float ran = 0.0f; - if (pimd->random_position != 0.0f) { - BLI_srandom(psys->seed + (i / totvert) % totpart); - ran = pimd->random_position * BLI_frand(); - } - - if (pimd->flag & eParticleInstanceFlag_KeepShape) { - state.time = pimd->position * (1.0f - ran); - } - else { - state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran); - - if (trackneg) - state.time = 1.0f - state.time; - - mv->co[axis] = 0.0; - } - - psys_get_particle_on_path(&sim, first_particle + i / totvert, &state, 1); - - normalize_v3(state.vel); + mpoly = result->getPolyArray(result); + orig_mpoly = dm->getPolyArray(dm); + mloop = result->getLoopArray(result); + orig_mloop = dm->getLoopArray(dm); - /* TODO: incremental rotations somehow */ - if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) { - unit_qt(state.rot); - } - else { - float temp[3] = {0.0f, 0.0f, 0.0f}; - temp[axis] = 1.0f; + for (p = 0, p_skip = 0; p < totpart; p++) { + /* skip particle? */ + if (particle_skip(pimd, psys, p)) + continue; + + /* set vertices coordinates */ + for (k = 0; k < totvert; k++) { + ParticleKey state; + MVert *inMV; + MVert *mv = mvert + p_skip * totvert + k; + + inMV = orig_mvert + k; + DM_copy_vert_data(dm, result, k, p_skip * totvert + k, 1); + *mv = *inMV; + + /*change orientation based on object trackflag*/ + copy_v3_v3(temp_co, mv->co); + mv->co[axis] = temp_co[track]; + mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3]; + mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3]; + + /* get particle state */ + if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) && + (pimd->flag & eParticleInstanceFlag_Path)) + { + float ran = 0.0f; + if (pimd->random_position != 0.0f) { + BLI_srandom(psys->seed + p); + ran = pimd->random_position * BLI_frand(); + } - cross_v3_v3v3(cross, temp, state.vel); + if (pimd->flag & eParticleInstanceFlag_KeepShape) { + state.time = pimd->position * (1.0f - ran); + } + else { + state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran); - /* state.vel[axis] is the only component surviving from a dot product with the axis */ - axis_angle_to_quat(state.rot, cross, saacos(state.vel[axis])); - } - } - else { - state.time = -1.0; - psys_get_particle_state(&sim, first_particle + i / totvert, &state, 1); - } + if (trackneg) + state.time = 1.0f - state.time; - mul_qt_v3(state.rot, mv->co); - if (pimd->flag & eParticleInstanceFlag_UseSize) - mul_v3_fl(mv->co, size[i / totvert]); - add_v3_v3(mv->co, state.co); - } + mv->co[axis] = 0.0; + } - mpoly = result->getPolyArray(result); - orig_mpoly = dm->getPolyArray(dm); - mloop = result->getLoopArray(result); - orig_mloop = dm->getLoopArray(dm); + psys_get_particle_on_path(&sim, first_particle + p, &state, 1); - for (i = 0; i < maxpoly; i++) { - MPoly *inMP = orig_mpoly + i % totpoly; - MPoly *mp = mpoly + i; + normalize_v3(state.vel); - if (pimd->flag & eParticleInstanceFlag_Parents) { - if (i / totpoly >= psys->totpart) { - if (psys->part->childtype == PART_CHILD_PARTICLES) { - pa = psys->particles + (psys->child + i / totpoly - psys->totpart)->parent; + /* TODO: incremental rotations somehow */ + if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) { + unit_qt(state.rot); } else { - pa = NULL; + float temp[3] = {0.0f, 0.0f, 0.0f}; + temp[axis] = 1.0f; + + cross_v3_v3v3(cross, temp, state.vel); + + /* state.vel[axis] is the only component surviving from a dot product with the axis */ + axis_angle_to_quat(state.rot, cross, saacos(state.vel[axis])); } } else { - pa = pars + i / totpoly; - } - } - else { - if (psys->part->childtype == PART_CHILD_PARTICLES) { - pa = psys->particles + (psys->child + i / totpoly)->parent; - } - else { - pa = NULL; + state.time = -1.0; + psys_get_particle_state(&sim, first_particle + p, &state, 1); } - } - if (pa) { - if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) continue; - if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) continue; - if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) continue; + mul_qt_v3(state.rot, mv->co); + if (pimd->flag & eParticleInstanceFlag_UseSize) + mul_v3_fl(mv->co, size[p]); + add_v3_v3(mv->co, state.co); } - DM_copy_poly_data(dm, result, i % totpoly, i, 1); - *mp = *inMP; - mp->loopstart += (i / totpoly) * totloop; + /* create polys and loops */ + for (k = 0; k < totpoly; k++) { + MPoly *inMP = orig_mpoly + k; + MPoly *mp = mpoly + p_skip * totpoly + k; + + DM_copy_poly_data(dm, result, k, p_skip * totpoly + k, 1); + *mp = *inMP; + mp->loopstart += p_skip * totloop; - { - MLoop *inML = orig_mloop + inMP->loopstart; - MLoop *ml = mloop + mp->loopstart; - int j = mp->totloop; + { + MLoop *inML = orig_mloop + inMP->loopstart; + MLoop *ml = mloop + mp->loopstart; + int j = mp->totloop; - DM_copy_loop_data(dm, result, inMP->loopstart, mp->loopstart, j); - for (; j; j--, ml++, inML++) { - ml->v = inML->v + ((i / totpoly) * totvert); + DM_copy_loop_data(dm, result, inMP->loopstart, mp->loopstart, j); + for (; j; j--, ml++, inML++) { + ml->v = inML->v + (p_skip * totvert); + } } } + + p_skip++; } CDDM_calc_edges(result); diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index aed8a70a805..4fd2c658380 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -857,7 +857,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, mp_new->loopstart = mpoly_index * 4; mp_new->totloop = 4; - mp_new->flag = ME_SMOOTH; + mp_new->flag = mpoly_flag; origindex[mpoly_index] = ORIGINDEX_NONE; mp_new++; ml_new += 4; diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index d5deb50e1f9..22b1e33e2a6 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -474,7 +474,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der float *dists_e = use_trgt_edges ? MEM_mallocN(sizeof(float) * numIdx, "dists_e") : NULL; float *dists_f = use_trgt_faces ? MEM_mallocN(sizeof(float) * numIdx, "dists_f") : NULL; - space_transform_setup(&loc2trgt, ob, obr); + SPACE_TRANSFORM_SETUP(&loc2trgt, ob, obr); get_vert2geom_distance(numIdx, v_cos, dists_v, dists_e, dists_f, target_dm, &loc2trgt); for (i = 0; i < numIdx; i++) { diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index e1adb419a8a..08e0e7b0f93 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -180,6 +180,7 @@ set(SRC shader/nodes/node_shader_tex_voronoi.c shader/nodes/node_shader_tex_wave.c shader/nodes/node_shader_tex_checker.c + shader/nodes/node_shader_tex_brick.c shader/node_shader_tree.c shader/node_shader_util.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 6b000181953..49428c06e5f 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -69,6 +69,7 @@ void register_node_type_sh_invert(struct bNodeTreeType *ttype); void register_node_type_sh_seprgb(struct bNodeTreeType *ttype); void register_node_type_sh_combrgb(struct bNodeTreeType *ttype); void register_node_type_sh_hue_sat(struct bNodeTreeType *ttype); +void register_node_type_sh_tex_brick(struct bNodeTreeType *ttype); void register_node_type_sh_attribute(struct bNodeTreeType *ttype); void register_node_type_sh_geometry(struct bNodeTreeType *ttype); diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 37444b6da92..e1510f9f813 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -48,7 +48,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_tracking.h" -#include "BKE_utildefines.h" #include "node_common.h" #include "node_exec.h" @@ -607,11 +606,9 @@ static void ntreeCompositExecTreeOld(bNodeTree *ntree, RenderData *rd, int do_pr bNode *node; ListBase threads; ThreadData thdata; - int totnode, curnode, rendering= 1, n; - bNodeTreeExec *exec= ntree->execdata; - - if (ntree == NULL) return; - + int totnode, curnode, rendering = TRUE, n; + bNodeTreeExec *exec = ntree->execdata; + if (do_preview) ntreeInitPreview(ntree, 0, 0); @@ -788,7 +785,6 @@ static void force_hidden_passes(bNode *node, int passflag) if (!(passflag & SCE_PASS_TRANSM_INDIRECT)) sock->flag |= SOCK_UNAVAIL; sock= BLI_findlink(&node->outputs, RRES_OUT_TRANSM_COLOR); if (!(passflag & SCE_PASS_TRANSM_COLOR)) sock->flag |= SOCK_UNAVAIL; - sock= BLI_findlink(&node->outputs, RRES_OUT_TRANSM_COLOR); } /* based on rules, force sockets hidden always */ diff --git a/source/blender/nodes/composite/nodes/node_composite_channelMatte.c b/source/blender/nodes/composite/nodes/node_composite_channelMatte.c index cda6fa85d74..06b77de463b 100644 --- a/source/blender/nodes/composite/nodes/node_composite_channelMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_channelMatte.c @@ -82,15 +82,18 @@ static void do_channel_matte(bNode *node, float *out, float *in) } case 1: { /* Alpha=G-MAX(R, B) */ switch (node->custom2) { - case 1: { + case 1: + { alpha=in[0]-MAX2(in[1], in[2]); break; } - case 2: { + case 2: + { alpha=in[1]-MAX2(in[0], in[2]); break; } - case 3: { + case 3: + { alpha=in[2]-MAX2(in[0], in[1]); break; } diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index 399cb1d1557..2d9b9348668 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -33,8 +33,6 @@ #include <string.h> #include "BLI_path_util.h" -#include "BKE_utildefines.h" - #include "node_composite_util.h" #include "IMB_imbuf.h" diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index ffa636fa952..fdbe82efeda 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -45,7 +45,6 @@ #include "BKE_main.h" #include "BLI_math.h" #include "BKE_node.h" -#include "BKE_utildefines.h" #include "RNA_access.h" #include "RNA_types.h" diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 8f9214fa1b2..27258c45fe5 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -73,6 +73,12 @@ void node_copy_standard_storage(bNode *orig_node, bNode *new_node) new_node->storage= MEM_dupallocN(orig_node->storage); } +void *node_initexec_curves(bNode *node) +{ + curvemapping_initialize(node->storage); + return NULL; /* unused return */ +} + /**** Labels ****/ const char *node_blend_label(bNode *node) diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h index 6f167e35262..9f9caef14e2 100644 --- a/source/blender/nodes/intern/node_util.h +++ b/source/blender/nodes/intern/node_util.h @@ -53,6 +53,7 @@ extern void node_free_standard_storage(struct bNode *node); extern void node_copy_curves(struct bNode *orig_node, struct bNode *new_node); extern void node_copy_standard_storage(struct bNode *orig_node, struct bNode *new_node); +extern void *node_initexec_curves(struct bNode *node); /**** Labels ****/ diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index fa623eaad3d..ad907c317f8 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -49,7 +49,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_scene.h" -#include "BKE_utildefines.h" #include "GPU_material.h" @@ -66,15 +65,15 @@ static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func) Lamp *la; World *wo; - for (ma= main->mat.first; ma; ma= ma->id.next) + for (ma = main->mat.first; ma; ma = ma->id.next) if (ma->nodetree) func(calldata, &ma->id, ma->nodetree); - for (la= main->lamp.first; la; la= la->id.next) + for (la = main->lamp.first; la; la = la->id.next) if (la->nodetree) func(calldata, &la->id, la->nodetree); - for (wo= main->world.first; wo; wo= wo->id.next) + for (wo = main->world.first; wo; wo = wo->id.next) if (wo->nodetree) func(calldata, &wo->id, wo->nodetree); } @@ -101,7 +100,7 @@ static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) bNode *node, *node_next; /* replace muted nodes and reroute nodes by internal links */ - for (node= localtree->nodes.first; node; node= node_next) { + for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { @@ -116,15 +115,15 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) bNode *lnode; /* copy over contents of previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { - bNode *node= lnode->new_node; + bNode *node = lnode->new_node; if (node->preview && node->preview->rect) { if (lnode->preview && lnode->preview->rect) { - int xsize= node->preview->xsize; - int ysize= node->preview->ysize; - memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4); + int xsize = node->preview->xsize; + int ysize = node->preview->ysize; + memcpy(node->preview->rect, lnode->preview->rect, 4 * xsize + xsize * ysize * sizeof(char) * 4); } } } @@ -176,7 +175,7 @@ void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *); void set_node_shader_lamp_loop(void (*lamp_loop_func)(ShadeInput *, ShadeResult *)) { - node_shader_lamp_loop= lamp_loop_func; + node_shader_lamp_loop = lamp_loop_func; } @@ -203,10 +202,10 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree, int use_tree_data) exec = ntree_exec_begin(ntree); /* allocate the thread stack listbase array */ - exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array"); + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node= exec->nodetree->nodes.first; node; node= node->next) - node->need_exec= 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; if (use_tree_data) { /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, @@ -224,19 +223,19 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree, int use_tree_data) void ntreeShaderEndExecTree(bNodeTreeExec *exec, int use_tree_data) { if (exec) { - bNodeTree *ntree= exec->nodetree; + bNodeTree *ntree = exec->nodetree; bNodeThreadStack *nts; int a; if (exec->threadstack) { - for (a=0; a<BLENDER_MAX_THREADS; a++) { - for (nts=exec->threadstack[a].first; nts; nts=nts->next) + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } MEM_freeN(exec->threadstack); - exec->threadstack= NULL; + exec->threadstack = NULL; } ntree_exec_end(exec); @@ -260,8 +259,8 @@ void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) bNodeTreeExec *exec = ntree->execdata; /* convert caller data to struct */ - scd.shi= shi; - scd.shr= shr; + scd.shi = shi; + scd.shr = shr; /* each material node has own local shaderesult, with optional copying */ memset(shr, 0, sizeof(ShadeResult)); @@ -276,14 +275,14 @@ void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) exec = ntree->execdata; } - nts= ntreeGetThreadStack(exec, shi->thread); + nts = ntreeGetThreadStack(exec, shi->thread); ntreeExecThreadNodes(exec, nts, &scd, shi->thread); ntreeReleaseThreadStack(nts); // \note: set material back to preserved material shi->mat = mat; /* better not allow negative for now */ - if (shr->combined[0]<0.0f) shr->combined[0]= 0.0f; - if (shr->combined[1]<0.0f) shr->combined[1]= 0.0f; - if (shr->combined[2]<0.0f) shr->combined[2]= 0.0f; + if (shr->combined[0] < 0.0f) shr->combined[0] = 0.0f; + if (shr->combined[1] < 0.0f) shr->combined[1] = 0.0f; + if (shr->combined[2] < 0.0f) shr->combined[2] = 0.0f; } diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c index 8831b07d8a0..83cb1d33628 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.c +++ b/source/blender/nodes/shader/nodes/node_shader_curves.c @@ -45,12 +45,6 @@ static bNodeSocketTemplate sh_node_curve_vec_out[]= { { -1, 0, "" } }; -static void *node_shader_initexec_curve(bNode *node) -{ - curvemapping_initialize(node->storage); - return NULL; /* unused return */ -} - static void node_shader_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { float vec[3]; @@ -86,7 +80,7 @@ void register_node_type_sh_curve_vec(bNodeTreeType *ttype) node_type_init(&ntype, node_shader_init_curve_vec); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, node_shader_exec_curve_vec); - node_type_exec_new(&ntype, node_shader_initexec_curve, NULL, NULL); /* only for its initexec func */ + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ node_type_gpu(&ntype, gpu_shader_curve_vec); nodeRegisterType(ttype, &ntype); @@ -144,7 +138,7 @@ void register_node_type_sh_curve_rgb(bNodeTreeType *ttype) node_type_init(&ntype, node_shader_init_curve_rgb); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, node_shader_exec_curve_rgb); - node_type_exec_new(&ntype, node_shader_initexec_curve, NULL, NULL); /* only for its initexec func */ + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ node_type_gpu(&ntype, gpu_shader_curve_rgb); nodeRegisterType(ttype, &ntype); diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c index 5be8925b556..ddfcb9476f4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -31,6 +31,13 @@ static bNodeSocketTemplate outputs[] = { { SOCK_FLOAT, 0, "Index" }, { SOCK_FLOAT, 0, "Age" }, { SOCK_FLOAT, 0, "Lifetime" }, + { SOCK_VECTOR, 0, "Location" }, + #if 0 /* quaternion sockets not yet supported */ + { SOCK_QUATERNION, 0, "Rotation" }, + #endif + { SOCK_FLOAT, 0, "Size" }, + { SOCK_VECTOR, 0, "Velocity" }, + { SOCK_VECTOR, 0, "Angular Velocity" }, { -1, 0, "" } }; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c new file mode 100644 index 00000000000..11f7fb94ae0 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c @@ -0,0 +1,90 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_tex_brick_in[]= { + { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, N_("Mortar Size"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 0.125f}, + { SOCK_FLOAT, 1, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f}, + { SOCK_FLOAT, 1, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate sh_node_tex_brick_out[]= { + { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick"); + default_tex_mapping(&tex->base.tex_mapping); + default_color_mapping(&tex->base.color_mapping); + + tex->offset = 0.5f; + tex->squash = 1.0f; + tex->offset_freq = 2; + tex->squash_freq = 2; + + node->storage = tex; +} + +static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) +{ + if (!in[0].link) + in[0].link = GPU_attribute(CD_ORCO, ""); + + node_shader_gpu_tex_mapping(mat, node, in, out); + + return GPU_stack_link(mat, "node_tex_brick", in, out); +} + +/* node type definition */ +void register_node_type_sh_tex_brick(bNodeTreeType *ttype) +{ + static bNodeType ntype; + + node_type_base(ttype, &ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, NODE_OPTIONS); + node_type_compatibility(&ntype, NODE_NEW_SHADING); + node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out); + node_type_size(&ntype, 150, 60, 200); + node_type_init(&ntype, node_shader_init_tex_brick); + node_type_storage(&ntype, "NodeTexBrick", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL); + node_type_gpu(&ntype, node_shader_gpu_tex_brick); + + nodeRegisterType(ttype, &ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index 572f06e007b..ace0f0c8774 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -58,6 +58,8 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; + NodeTexImage *tex = node->storage; + int ncd = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); @@ -67,7 +69,10 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser)); + if (out[0].link && GPU_material_do_color_management(mat)) + GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); + + return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, ncd)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index 176c50bcabb..d6c757222b9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -58,6 +58,8 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; + NodeTexImage *tex = node->storage; + int ncd = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_image_empty", in, out); @@ -67,7 +69,10 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser)); + if (out[0].link && GPU_material_do_color_management(mat)) + GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); + + return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, ncd)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c index 3f90d4fbcd5..73c3b846fe3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ b/source/blender/nodes/shader/nodes/node_shader_texture.c @@ -122,7 +122,7 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, GPUNodeStack *in, G Tex *tex = (Tex*)node->id; if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPUNodeLink *texlink = GPU_image(tex->ima, NULL); + GPUNodeLink *texlink = GPU_image(tex->ima, NULL, FALSE); return GPU_stack_link(mat, "texture_image", in, out, texlink); } else diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index 063cc31e6f6..9656d93f1b0 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -58,7 +58,7 @@ static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func) { Tex *tx; - for (tx= main->tex.first; tx; tx= tx->id.next) { + for (tx = main->tex.first; tx; tx = tx->id.next) { if (tx->nodetree) { func(calldata, &tx->id, tx->nodetree); } @@ -83,7 +83,7 @@ static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) bNode *node, *node_next; /* replace muted nodes and reroute nodes by internal links */ - for (node= localtree->nodes.first; node; node= node_next) { + for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { @@ -98,15 +98,15 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) bNode *lnode; /* copy over contents of previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { - bNode *node= lnode->new_node; + bNode *node = lnode->new_node; if (node->preview && node->preview->rect) { if (lnode->preview && lnode->preview->rect) { - int xsize= node->preview->xsize; - int ysize= node->preview->ysize; - memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4); + int xsize = node->preview->xsize; + int ysize = node->preview->ysize; + memcpy(node->preview->rect, lnode->preview->rect, 4 * xsize + xsize * ysize * sizeof(char) * 4); } } } @@ -141,15 +141,15 @@ int ntreeTexTagAnimated(bNodeTree *ntree) { bNode *node; - if (ntree==NULL) return 0; + if (ntree == NULL) return 0; - for (node= ntree->nodes.first; node; node= node->next) { - if (node->type==TEX_NODE_CURVE_TIME) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == TEX_NODE_CURVE_TIME) { nodeUpdate(ntree, node); return 1; } - else if (node->type==NODE_GROUP) { - if ( ntreeTexTagAnimated((bNodeTree *)node->id) ) { + else if (node->type == NODE_GROUP) { + if (ntreeTexTagAnimated((bNodeTree *)node->id) ) { return 1; } } @@ -178,10 +178,10 @@ bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree, int use_tree_data) exec = ntree_exec_begin(ntree); /* allocate the thread stack listbase array */ - exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array"); + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node= exec->nodetree->nodes.first; node; node= node->next) - node->need_exec= 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; if (use_tree_data) { /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, @@ -200,9 +200,9 @@ static void tex_free_delegates(bNodeTreeExec *exec) bNodeStack *ns; int th, a; - for (th=0; th<BLENDER_MAX_THREADS; th++) - for (nts=exec->threadstack[th].first; nts; nts=nts->next) - for (ns= nts->stack, a=0; a<exec->stacksize; a++, ns++) + for (th = 0; th < BLENDER_MAX_THREADS; th++) + for (nts = exec->threadstack[th].first; nts; nts = nts->next) + for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) if (ns->data && !ns->is_copy) MEM_freeN(ns->data); } @@ -213,21 +213,21 @@ static void tex_free_delegates(bNodeTreeExec *exec) void ntreeTexEndExecTree(bNodeTreeExec *exec, int use_tree_data) { if (exec) { - bNodeTree *ntree= exec->nodetree; + bNodeTree *ntree = exec->nodetree; bNodeThreadStack *nts; int a; if (exec->threadstack) { tex_free_delegates(exec); - for (a=0; a<BLENDER_MAX_THREADS; a++) { - for (nts=exec->threadstack[a].first; nts; nts=nts->next) + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } MEM_freeN(exec->threadstack); - exec->threadstack= NULL; + exec->threadstack = NULL; } ntree_exec_end(exec); @@ -254,10 +254,10 @@ int ntreeTexExecTree( MTex *mtex ) { TexCallData data; - float *nor= texres->nor; + float *nor = texres->nor; int retval = TEX_INT; bNodeThreadStack *nts = NULL; - bNodeTreeExec *exec= nodes->execdata; + bNodeTreeExec *exec = nodes->execdata; data.co = co; data.dxt = dxt; @@ -267,9 +267,9 @@ int ntreeTexExecTree( data.do_preview = preview; data.thread = thread; data.which_output = which_output; - data.cfra= cfra; - data.mtex= mtex; - data.shi= shi; + data.cfra = cfra; + data.mtex = mtex; + data.shi = shi; /* ensure execdata is only initialized once */ if (!exec) { @@ -278,10 +278,10 @@ int ntreeTexExecTree( ntreeTexBeginExecTree(nodes, 1); BLI_unlock_thread(LOCK_NODES); - exec= nodes->execdata; + exec = nodes->execdata; } - nts= ntreeGetThreadStack(exec, thread); + nts = ntreeGetThreadStack(exec, thread); ntreeExecThreadNodes(exec, nts, &data, thread); ntreeReleaseThreadStack(nts); @@ -289,7 +289,7 @@ int ntreeTexExecTree( retval |= TEX_RGB; /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set * however, the texture code checks this for other reasons (namely, a normal is required for material) */ - texres->nor= nor; + texres->nor = nor; return retval; } diff --git a/source/blender/nodes/texture/nodes/node_texture_curves.c b/source/blender/nodes/texture/nodes/node_texture_curves.c index 543b39ec75e..6ccb5e1e83f 100644 --- a/source/blender/nodes/texture/nodes/node_texture_curves.c +++ b/source/blender/nodes/texture/nodes/node_texture_curves.c @@ -77,6 +77,7 @@ void register_node_type_tex_curve_time(bNodeTreeType *ttype) node_type_init(&ntype, time_init); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, time_exec); + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ nodeRegisterType(ttype, &ntype); } @@ -121,6 +122,7 @@ void register_node_type_tex_curve_rgb(bNodeTreeType *ttype) node_type_init(&ntype, rgb_init); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, rgb_exec); + node_type_exec_new(&ntype, node_initexec_curves, NULL, NULL); /* only for its initexec func */ nodeRegisterType(ttype, &ntype); } diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index ce11545c90d..45b767c6eda 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -44,7 +44,7 @@ #include "BLI_utildefines.h" static PyObject *Buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds); -static PyObject *Method_ShaderSource (PyObject *self, PyObject *args); +static PyObject *Method_ShaderSource(PyObject *self, PyObject *args); /* Buffer sequence methods */ diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 520773c1ddf..2e4d4e870b8 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -402,6 +402,15 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) if (PyBytes_Check(py_str)) { return PyBytes_AS_STRING(py_str); } +#ifdef WIN32 + /* bug [#31856] oddly enough, Python3.2 --> 3.3 on Windows will throw an + * exception here this needs to be fixed in python: + * see: bugs.python.org/issue15859 */ + else if (!PyUnicode_Check(py_str)) { + PyErr_BadArgument(); + return NULL; + } +#endif else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { return PyBytes_AS_STRING(*coerce); } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index aa9d81389da..9cd0bdd090a 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -163,8 +163,17 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) void BPY_text_free_code(Text *text) { if (text->compiled) { + PyGILState_STATE gilstate; + int use_gil = !PYC_INTERPRETER_ACTIVE; + + if (use_gil) + gilstate = PyGILState_Ensure(); + Py_DECREF((PyObject *)text->compiled); text->compiled = NULL; + + if (use_gil) + PyGILState_Release(gilstate); } } @@ -254,6 +263,15 @@ void BPY_python_start(int argc, const char **argv) Py_Initialize(); +#ifdef WIN32 + /* this is disappointing, its likely a bug in python? + * for some reason 'PYTHONIOENCODING' is ignored in windows + * see: [#31555] for details. */ + PyRun_SimpleString("import sys, io\n" + "sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='surrogateescape', line_buffering=True)\n" + "sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='surrogateescape', line_buffering=True)\n"); +#endif /* WIN32 */ + // PySys_SetArgv(argc, argv); // broken in py3, not a huge deal /* sigh, why do python guys not have a (char **) version anymore? */ { diff --git a/source/blender/quicktime/apple/qtkit_export.m b/source/blender/quicktime/apple/qtkit_export.m index 47df4c7363f..bb87fe21c49 100644 --- a/source/blender/quicktime/apple/qtkit_export.m +++ b/source/blender/quicktime/apple/qtkit_export.m @@ -318,7 +318,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport"); - [QTMovie enterQTKitOnThread]; + [QTMovie enterQTKitOnThread]; /* Check first if the QuickTime 7.2.1 initToWritableFile: method is available */ if ([[[[QTMovie alloc] init] autorelease] respondsToSelector:@selector(initToWritableFile:error:)] != YES) { @@ -328,7 +328,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R else { makeqtstring(rd, name); qtexport->filename = [[NSString alloc] initWithCString:name - encoding:[NSString defaultCStringEncoding]]; + encoding:[NSString defaultCStringEncoding]]; qtexport->movie = nil; qtexport->audioFile = NULL; @@ -354,7 +354,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R strcpy(extension,".aiff"); break; } - + tmpnam(name); strcat(name, extension); outputFileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,(UInt8*) name, strlen(name), false); @@ -362,7 +362,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R if (outputFileURL) { qtexport->audioFileName = [[NSString alloc] initWithCString:name - encoding:[NSString defaultCStringEncoding]]; + encoding:[NSString defaultCStringEncoding]]; qtexport->audioInputFormat.mSampleRate = U.audiorate; qtexport->audioInputFormat.mFormatID = kAudioFormatLinearPCM; @@ -471,7 +471,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R qtexport->audioOutputFormat.mBytesPerFrame = qtexport->audioOutputFormat.mBytesPerPacket; break; } - + err = AudioFileCreateWithURL(outputFileURL, audioFileType, &qtexport->audioOutputFormat, kAudioFileFlags_EraseFile, &qtexport->audioFile); CFRelease(outputFileURL); @@ -489,27 +489,27 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R else { UInt32 prop,propSize; /* Set up codec properties */ - if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /*Lossy compressed format*/ + if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /* Lossy compressed format */ prop = rd->qtcodecsettings.audioBitRate; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterEncodeBitRate, - sizeof(prop), &prop); + sizeof(prop), &prop); if (rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_CODEC_ISCBR) prop = kAudioCodecBitRateControlMode_Constant; else prop = kAudioCodecBitRateControlMode_LongTermAverage; AudioConverterSetProperty(qtexport->audioConverter, kAudioCodecPropertyBitRateControlMode, - sizeof(prop), &prop); + sizeof(prop), &prop); } /* Conversion quality : if performance impact then offer degraded option */ - if ((rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_RESAMPLE_NOHQ) == 0) { + if ((rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_RESAMPLE_NOHQ) == 0) { prop = kAudioConverterSampleRateConverterComplexity_Mastering; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterSampleRateConverterComplexity, - sizeof(prop), &prop); + sizeof(prop), &prop); prop = kAudioConverterQuality_Max; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterSampleRateConverterQuality, - sizeof(prop), &prop); + sizeof(prop), &prop); } write_cookie(qtexport->audioConverter, qtexport->audioFile); @@ -517,29 +517,30 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R /* Allocate output buffer */ if (qtexport->audioOutputFormat.mBytesPerPacket ==0) /* VBR */ AudioConverterGetProperty(qtexport->audioConverter, kAudioConverterPropertyMaximumOutputPacketSize, - &propSize, &qtexport->audioCodecMaxOutputPacketSize); + &propSize, &qtexport->audioCodecMaxOutputPacketSize); else qtexport->audioCodecMaxOutputPacketSize = qtexport->audioOutputFormat.mBytesPerPacket; qtexport->audioInputBuffer = MEM_mallocN(AUDIOOUTPUTBUFFERSIZE, "qt_audio_inputPacket"); qtexport->audioOutputBuffer = MEM_mallocN(AUDIOOUTPUTBUFFERSIZE, "qt_audio_outputPacket"); - qtexport->audioOutputPktDesc = MEM_mallocN(sizeof(AudioStreamPacketDescription)*AUDIOOUTPUTBUFFERSIZE/qtexport->audioCodecMaxOutputPacketSize, - "qt_audio_pktdesc"); + qtexport->audioOutputPktDesc = MEM_mallocN(sizeof(AudioStreamPacketDescription) * AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize, + "qt_audio_pktdesc"); } } } - + if (err == noErr) { - qtexport->videoTempFileName = [[NSString alloc] initWithCString:tmpnam(nil) - encoding:[NSString defaultCStringEncoding]]; - if (qtexport->videoTempFileName) + qtexport->videoTempFileName = [[NSString alloc] initWithCString:tmpnam(nil) + encoding:[NSString defaultCStringEncoding]]; + if (qtexport->videoTempFileName) { qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->videoTempFileName error:&error]; + } } } else qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error]; - + if(qtexport->movie == nil) { BKE_report(reports, RPT_ERROR, "Unable to create quicktime movie."); success= 0; @@ -585,7 +586,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R specs.rate = U.audiorate; qtexport->audioInputDevice = AUD_openReadDevice(specs); AUD_playDevice(qtexport->audioInputDevice, scene->sound_scene, rd->sfra * rd->frs_sec_base / rd->frs_sec); - + qtexport->audioOutputPktPos = 0; qtexport->audioTotalExportedFrames = 0; qtexport->audioTotalSavedFrames = 0; @@ -655,13 +656,13 @@ int append_qt(struct RenderData *rd, int start_frame, int frame, int *pixels, in audioPacketsConverted = AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize; err = AudioConverterFillComplexBuffer(qtexport->audioConverter, AudioConverterInputCallback, - NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc); + NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc); if (audioPacketsConverted) { AudioFileWritePackets(qtexport->audioFile, false, qtexport->audioBufferList.mBuffers[0].mDataByteSize, - qtexport->audioOutputPktDesc, qtexport->audioOutputPktPos, &audioPacketsConverted, qtexport->audioOutputBuffer); + qtexport->audioOutputPktDesc, qtexport->audioOutputPktPos, &audioPacketsConverted, qtexport->audioOutputBuffer); qtexport->audioOutputPktPos += audioPacketsConverted; - if (qtexport->audioOutputFormat.mFramesPerPacket) { + if (qtexport->audioOutputFormat.mFramesPerPacket) { // this is the common case: format has constant frames per packet qtexport->audioTotalSavedFrames += (audioPacketsConverted * qtexport->audioOutputFormat.mFramesPerPacket); } @@ -751,8 +752,8 @@ void end_qt(void) } /* Save file */ - dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] - forKey:QTMovieFlatten]; + dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] + forKey:QTMovieFlatten]; if (dict) { [qtexport->movie writeToFile:qtexport->filename withAttributes:dict]; diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h index 5afdb2a29ce..2376aeca55e 100644 --- a/source/blender/render/extern/include/RE_engine.h +++ b/source/blender/render/extern/include/RE_engine.h @@ -86,9 +86,14 @@ typedef struct RenderEngine { int flag; struct Object *camera_override; + int tile_x; + int tile_y; + struct Render *re; ListBase fullresult; char *text; + + int resolution_x, resolution_y; } RenderEngine; RenderEngine *RE_engine_create(RenderEngineType *type); @@ -97,9 +102,9 @@ void RE_engine_free(RenderEngine *engine); void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y); void RE_result_load_from_file(struct RenderResult *result, struct ReportList *reports, const char *filename); -struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h); +struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername); void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result); -void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result); +void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result, int cancel); int RE_engine_test_break(RenderEngine *engine); void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info); diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 4695f2ba44f..1510d9adb10 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -92,6 +92,9 @@ typedef struct RenderLayer { float *acolrect; /* 4 float, optional transparent buffer, needs storage for display updates */ float *scolrect; /* 4 float, optional strand buffer, needs storage for display updates */ int rectx, recty; + + /* optional saved endresult on disk */ + void *exrhandle; ListBase passes; @@ -124,7 +127,7 @@ typedef struct RenderResult { volatile RenderLayer *renlay; /* optional saved endresult on disk */ - void *exrhandle; + int do_exr_tile; /* for render results in Image, verify validity for sequences */ int framenr; diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 604cd940fab..c07ed42332f 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -65,7 +65,7 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove); struct Material *RE_init_sample_material(struct Material *orig_mat, struct Scene *scene); void RE_free_sample_material(struct Material *mat); void RE_sample_material_color(struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3], - int face_index, short hit_quad, struct DerivedMesh *orcoDm, struct Object *ob); + int face_index, short hit_quad, struct DerivedMesh *orcoDm, struct Object *ob); #endif /* __RE_RENDER_EXT_H__ */ diff --git a/source/blender/render/intern/include/initrender.h b/source/blender/render/intern/include/initrender.h index 7917fd66cfa..43ab9552194 100644 --- a/source/blender/render/intern/include/initrender.h +++ b/source/blender/render/intern/include/initrender.h @@ -40,7 +40,7 @@ struct Object; void free_sample_tables(Render *re); void make_sample_tables(Render *re); -void initparts(Render *re); +void initparts(Render *re, int do_crop); void freeparts(Render *re); diff --git a/source/blender/render/intern/include/pixelshading.h b/source/blender/render/intern/include/pixelshading.h index 00d731912b6..30d574694b2 100644 --- a/source/blender/render/intern/include/pixelshading.h +++ b/source/blender/render/intern/include/pixelshading.h @@ -44,9 +44,9 @@ * \return pointer to the object */ int shadeHaloFloat(HaloRen *har, - float *col, int zz, - float dist, float xn, - float yn, short flarec); + float *col, int zz, + float dist, float xn, + float yn, short flarec); /** * Render the sky at pixel (x, y). diff --git a/source/blender/render/intern/include/render_result.h b/source/blender/render/intern/include/render_result.h index 3d73ee1e912..303d4094f8e 100644 --- a/source/blender/render/intern/include/render_result.h +++ b/source/blender/render/intern/include/render_result.h @@ -37,6 +37,8 @@ #define RR_USE_MEM 0 #define RR_USE_EXR 1 +#define RR_ALL_LAYERS NULL + struct ImBuf; struct ListBase; struct Render; @@ -49,7 +51,7 @@ struct rcti; /* New */ struct RenderResult *render_result_new(struct Render *re, - struct rcti *partrct, int crop, int savebuffers); + struct rcti *partrct, int crop, int savebuffers, const char *layername); struct RenderResult *render_result_new_full_sample(struct Render *re, struct ListBase *lb, struct rcti *partrct, int crop, int savebuffers); @@ -76,9 +78,9 @@ void render_result_exr_file_end(struct Render *re); void render_result_exr_file_merge(struct RenderResult *rr, struct RenderResult *rrpart); -void render_result_exr_file_path(struct Scene *scene, int sample, char *filepath); +void render_result_exr_file_path(struct Scene *scene, const char *layname, int sample, char *filepath); int render_result_exr_file_read(struct Render *re, int sample); -int render_result_exr_file_read_path(struct RenderResult *rr, const char *filepath); +int render_result_exr_file_read_path(struct RenderResult *rr, struct RenderLayer *rl_single, const char *filepath); /* Combined Pixel Rect */ diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index c8c8eb1fc06..60f3ced5652 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -63,7 +63,6 @@ struct ReportList; struct Main; #define TABLEINITSIZE 1024 -#define LAMPINITSIZE 256 typedef struct SampleTables { float centLut[16]; diff --git a/source/blender/render/intern/include/sunsky.h b/source/blender/render/intern/include/sunsky.h index 4bb7d99ba16..74e42109be5 100644 --- a/source/blender/render/intern/include/sunsky.h +++ b/source/blender/render/intern/include/sunsky.h @@ -27,9 +27,7 @@ #ifndef __SUNSKY_H__ #define __SUNSKY_H__ -#define SPECTRUM_MAX_COMPONENTS 100 -#define SPECTRUM_START 350.0 -#define SPECTRUM_END 800.0 +// #define SPECTRUM_MAX_COMPONENTS 100 typedef struct SunSky { short effect_type, skyblendtype, sky_colorspace; diff --git a/source/blender/render/intern/include/volumetric.h b/source/blender/render/intern/include/volumetric.h index 7f63bcbbecc..3805478fed0 100644 --- a/source/blender/render/intern/include/volumetric.h +++ b/source/blender/render/intern/include/volumetric.h @@ -41,9 +41,6 @@ void shade_volume_outside(ShadeInput *shi, ShadeResult *shr); void shade_volume_inside(ShadeInput *shi, ShadeResult *shr); void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct Isect *last_is); -#define STEPSIZE_VIEW 0 -#define STEPSIZE_SHADE 1 - #define VOL_IS_BACKFACE 1 #define VOL_IS_SAMEMATERIAL 2 diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 03f00418af9..e0864533fed 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -247,32 +247,24 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), done++; } else { - mul_m4_v3(re->viewmat, vec); + if (re) + mul_m4_v3(re->viewmat, vec); /* in vec are global coordinates * calculate distance to camera * and using that, define the alpha */ - - { - float tx, ty, tz; - - tx = vec[0]; - ty = vec[1]; - tz = vec[2]; - - alpha = sqrt(tx * tx + ty * ty + tz * tz); - - if (alpha >= clipend) alpha = 0.0; - else if (alpha <= starmindist) alpha = 0.0; - else if (alpha <= 2.0f * starmindist) { - alpha = (alpha - starmindist) / starmindist; - } - else { - alpha -= 2.0f * starmindist; - alpha /= (clipend - 2.0f * starmindist); - alpha = 1.0f - alpha; - } + alpha = len_v3(vec); + + if (alpha >= clipend) alpha = 0.0; + else if (alpha <= starmindist) alpha = 0.0; + else if (alpha <= 2.0f * starmindist) { + alpha = (alpha - starmindist) / starmindist; + } + else { + alpha -= 2.0f * starmindist; + alpha /= (clipend - 2.0f * starmindist); + alpha = 1.0f - alpha; } diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 487271ea1f7..636b3205b23 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -55,6 +55,7 @@ #include "RE_engine.h" #include "RE_pipeline.h" +#include "initrender.h" #include "render_types.h" #include "render_result.h" @@ -149,7 +150,7 @@ void RE_engine_free(RenderEngine *engine) /* Render Results */ -RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h) +RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername) { Render *re = engine->re; RenderResult *result; @@ -172,7 +173,9 @@ RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, disprect.ymin = y; disprect.ymax = y + h; - result = render_result_new(re, &disprect, 0, RR_USE_MEM); + result = render_result_new(re, &disprect, 0, RR_USE_MEM, layername); + + /* todo: make this thread safe */ /* can be NULL if we CLAMP the width or height to 0 */ if (result) { @@ -197,25 +200,43 @@ void RE_engine_update_result(RenderEngine *engine, RenderResult *result) } } -void RE_engine_end_result(RenderEngine *engine, RenderResult *result) +void RE_engine_end_result(RenderEngine *engine, RenderResult *result, int cancel) { Render *re = engine->re; + RenderPart *pa; - if (!result) + if (!result) { return; + } /* merge. on break, don't merge in result for preview renders, looks nicer */ - if (!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) - render_result_merge(re->result, result); + if (!cancel) { + /* for exr tile render, detect tiles that are done */ + for (pa = re->parts.first; pa; pa = pa->next) { + if (result->tilerect.xmin == pa->disprect.xmin && + result->tilerect.ymin == pa->disprect.ymin && + result->tilerect.xmax == pa->disprect.xmax && + result->tilerect.ymax == pa->disprect.ymax) + { + pa->ready = 1; + } + } - /* draw */ - if (!re->test_break(re->tbh)) { - result->renlay = result->layers.first; /* weak, draws first layer always */ - re->display_draw(re->ddh, result, NULL); + if (re->result->do_exr_tile) + render_result_exr_file_merge(re->result, result); + else if (!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) + render_result_merge(re->result, result); + + /* draw */ + if (!re->test_break(re->tbh)) { + result->renlay = result->layers.first; /* weak, draws first layer always */ + re->display_draw(re->ddh, result, NULL); + } } /* free */ - render_result_free_list(&engine->fullresult, result); + BLI_remlink(&engine->fullresult, result); + render_result_free(result); } /* Cancel */ @@ -294,12 +315,16 @@ int RE_engine_render(Render *re, int do_all) /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result == NULL || !(re->r.scemode & R_PREVIEWBUTS)) { + int savebuffers; + if (re->result) render_result_free(re->result); - re->result = render_result_new(re, &re->disprect, 0, 0); + + savebuffers = (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM; + re->result = render_result_new(re, &re->disprect, 0, savebuffers, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); - + if (re->result == NULL) return 1; @@ -318,14 +343,35 @@ int RE_engine_render(Render *re, int do_all) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; + engine->resolution_x = re->winx; + engine->resolution_y = re->winy; + if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_PREVIEWBUTS)) == 0) BKE_scene_update_for_newframe(re->main, re->scene, re->lay); + initparts(re, FALSE); + engine->tile_x = re->partx; + engine->tile_y = re->party; + + if (re->result->do_exr_tile) + render_result_exr_file_begin(re); + if (type->update) type->update(engine, re->main, re->scene); + if (type->render) type->render(engine, re->scene); + if (re->result->do_exr_tile) { + BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); + render_result_exr_file_end(re); + BLI_rw_mutex_unlock(&re->resultmutex); + } + + engine->tile_x = 0; + engine->tile_y = 0; + freeparts(re); + render_result_free_list(&engine->fullresult, engine->fullresult.first); RE_engine_free(engine); diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index e4fb87e8e4f..7f0484c8ee6 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -1054,6 +1054,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if ((ibuf == NULL) || ((ibuf->rect == NULL) && (ibuf->rect_float == NULL))) return retval; + ima->flag |= IMA_USED_FOR_RENDER; + /* mipmap test */ image_mipmap_test(tex, ibuf); diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index 7efdba77943..66f230a40f5 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -537,7 +537,7 @@ void freeparts(Render *re) BLI_freelistN(&re->parts); } -void initparts(Render *re) +void initparts(Render *re, int do_crop) { int nr, xd, yd, partx, party, xparts, yparts; int xminb, xmaxb, yminb, ymaxb; @@ -618,7 +618,7 @@ void initparts(Render *re) RenderPart *pa = MEM_callocN(sizeof(RenderPart), "new part"); /* Non-box filters need 2 pixels extra to work */ - if ((re->r.filtertype || (re->r.mode & R_EDGE))) { + if (do_crop && (re->r.filtertype || (re->r.mode & R_EDGE))) { pa->crop = 2; disprect.xmin -= pa->crop; disprect.ymin -= pa->crop; diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 14c9df2da4e..720287510d0 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -56,7 +56,6 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "BKE_writeavi.h" /* <------ should be replaced once with generic movie module */ #include "BLI_math.h" @@ -198,14 +197,12 @@ float *RE_RenderLayerGetPass(RenderLayer *rl, int passtype) RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name) { - RenderLayer *rl; - - if (rr == NULL) return NULL; - - for (rl = rr->layers.first; rl; rl = rl->next) - if (strncmp(rl->name, name, RE_MAXNAME) == 0) - return rl; - return NULL; + if (rr == NULL) { + return NULL; + } + else { + return BLI_findstring(&rr->layers, name, offsetof(RenderLayer, name)); + } } RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty) @@ -644,7 +641,7 @@ static void *do_part_thread(void *pa_v) if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE)) pa->result = render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM); else - pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM); + pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM, RR_ALL_LAYERS); if (R.sss_points) zbufshade_sss_tile(pa); @@ -654,7 +651,7 @@ static void *do_part_thread(void *pa_v) zbufshade_tile(pa); /* merge too on break! */ - if (R.result->exrhandle) { + if (R.result->do_exr_tile) { render_result_exr_file_merge(R.result, pa->result); } else if (render_display_draw_enabled(&R)) { @@ -798,12 +795,12 @@ static void threaded_tile_processor(Render *re) render_result_free(re->result); if (re->sss_points && render_display_draw_enabled(re)) - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); else if (re->r.scemode & R_FULL_SAMPLE) re->result = render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR); else re->result = render_result_new(re, &re->disprect, 0, - (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM); + (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); @@ -813,9 +810,9 @@ static void threaded_tile_processor(Render *re) /* warning; no return here without closing exr file */ - initparts(re); + initparts(re, TRUE); - if (re->result->exrhandle) + if (re->result->do_exr_tile) render_result_exr_file_begin(re); BLI_init_threads(&threads, do_part_thread, re->r.threads); @@ -895,7 +892,7 @@ static void threaded_tile_processor(Render *re) } - if (re->result->exrhandle) { + if (re->result->do_exr_tile) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); @@ -1055,7 +1052,7 @@ static void do_render_blur_3d(Render *re) int blur = re->r.mblur_samples; /* create accumulation render result */ - rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); /* do the blur steps */ while (blur--) { @@ -1119,7 +1116,10 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende /* passes are allocated in sync */ rpass1 = rl1->passes.first; rpass2 = rl2->passes.first; - for (rpass = rl->passes.first; rpass && rpass1 && rpass2; rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next) { + for (rpass = rl->passes.first; + rpass && rpass1 && rpass2; + rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next) + { interleave_rect(rr, rpass->rect, rpass1->rect, rpass2->rect, rpass->channels); } } @@ -1180,7 +1180,7 @@ static void do_render_fields_3d(Render *re) re->disprect.ymax *= 2; BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); if (rr2) { if (re->r.mode & R_ODDFIELD) @@ -1243,7 +1243,7 @@ static void do_render_fields_blur_3d(Render *re) re->rectx = re->winx; re->recty = re->winy; - rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); render_result_merge(rres, re->result); render_result_free(re->result); @@ -1632,7 +1632,7 @@ static void do_render_composite_fields_blur_3d(Render *re) BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_free(re->result); - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); BLI_rw_mutex_unlock(&re->resultmutex); @@ -1770,7 +1770,7 @@ static void do_render_seq(Render *re) if (recurs_depth == 0) { /* with nested scenes, only free on toplevel... */ Editing *ed = re->scene->ed; if (ed) - BKE_sequencer_free_imbuf(re->scene, &ed->seqbase, TRUE, TRUE); + BKE_sequencer_free_imbuf(re->scene, &ed->seqbase, TRUE); } IMB_freeImBuf(ibuf); } @@ -1929,7 +1929,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r if (scene->r.scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) { char str[FILE_MAX]; - render_result_exr_file_path(scene, 0, str); + render_result_exr_file_path(scene, "", 0, str); if (BLI_file_is_writable(str) == 0) { BKE_report(reports, RPT_ERROR, "Can not save render buffers, check the temp default path"); @@ -2013,7 +2013,7 @@ static void validate_render_settings(Render *re) if (RE_engine_is_external(re)) { /* not supported yet */ - re->r.scemode &= ~(R_EXR_TILE_FILE | R_FULL_SAMPLE); + re->r.scemode &= ~(R_FULL_SAMPLE); re->r.mode &= ~(R_FIELDS | R_MBLUR); } } @@ -2512,7 +2512,7 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename) { - if (!render_result_exr_file_read_path(result, filename)) { + if (!render_result_exr_file_read_path(result, NULL, filename)) { BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename); return; } diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 83bbaa7edbe..fb1a7885390 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -30,6 +30,7 @@ */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "MEM_guardedalloc.h" @@ -38,7 +39,6 @@ #include "BKE_global.h" #include "BKE_main.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLI_fileops.h" #include "BLI_listbase.h" @@ -387,10 +387,10 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel rpass->recty = rl->recty; BLI_strncpy(rpass->name, get_pass_name(rpass->passtype, -1), sizeof(rpass->name)); - if (rr->exrhandle) { + if (rl->exrhandle) { int a; for (a = 0; a < channels; a++) - IMB_exr_add_channel(rr->exrhandle, rl->name, get_pass_name(passtype, a), 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, get_pass_name(passtype, a), 0, 0, NULL); } else { float *rect; @@ -416,7 +416,7 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel /* will read info from Render *re to define layers */ /* called in threads */ /* re->winx,winy is coordinate space of entire image, partrct the part within */ -RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuffers) +RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuffers, const char *layername) { RenderResult *rr; RenderLayer *rl; @@ -438,17 +438,21 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf /* tilerect is relative coordinates within render disprect. do not subtract crop yet */ rr->tilerect.xmin = partrct->xmin - re->disprect.xmin; - rr->tilerect.xmax = partrct->xmax - re->disprect.xmax; + rr->tilerect.xmax = partrct->xmax - re->disprect.xmin; rr->tilerect.ymin = partrct->ymin - re->disprect.ymin; - rr->tilerect.ymax = partrct->ymax - re->disprect.ymax; + rr->tilerect.ymax = partrct->ymax - re->disprect.ymin; if (savebuffers) { - rr->exrhandle = IMB_exr_get_handle(); + rr->do_exr_tile = TRUE; } - + /* check renderdata for amount of layers */ for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) { - + + if (layername && layername[0]) + if (strcmp(srl->name, layername) != 0) + continue; + if ((re->r.scemode & R_SINGLE_LAYER) && nr != re->r.actlay) continue; if (srl->layflag & SCE_LAY_DISABLE) @@ -469,11 +473,13 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->rectx = rectx; rl->recty = recty; - if (rr->exrhandle) { - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.R", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.G", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.B", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.A", 0, 0, NULL); + if (rr->do_exr_tile) { + rl->exrhandle = IMB_exr_get_handle(); + + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.R", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.G", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.B", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.A", 0, 0, NULL); } else rl->rectf = MEM_mapallocN(rectx * recty * sizeof(float) * 4, "Combined rgba"); @@ -535,7 +541,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf } /* sss, previewrender and envmap don't do layers, so we make a default one */ - if (rr->layers.first == NULL) { + if (rr->layers.first == NULL && !(layername && layername[0])) { rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); BLI_addtail(&rr->layers, rl); @@ -543,14 +549,17 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->recty = recty; /* duplicate code... */ - if (rr->exrhandle) { - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.R", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.G", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.B", 0, 0, NULL); - IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.A", 0, 0, NULL); + if (rr->do_exr_tile) { + rl->exrhandle = IMB_exr_get_handle(); + + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.R", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.G", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.B", 0, 0, NULL); + IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.A", 0, 0, NULL); } - else + else { rl->rectf = MEM_mapallocN(rectx * recty * sizeof(float) * 4, "Combined rgba"); + } /* note, this has to be in sync with scene.c */ rl->lay = (1 << 20) - 1; @@ -574,10 +583,10 @@ RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *part int a; if (re->osa == 0) - return render_result_new(re, partrct, crop, savebuffers); + return render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS); for (a = 0; a < re->osa; a++) { - RenderResult *rr = render_result_new(re, partrct, crop, savebuffers); + RenderResult *rr = render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS); BLI_addtail(lb, rr); rr->sample_nr = a; } @@ -686,15 +695,20 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart) RenderLayer *rl, *rlp; RenderPass *rpass, *rpassp; - for (rl = rr->layers.first, rlp = rrpart->layers.first; rl && rlp; rl = rl->next, rlp = rlp->next) { - - /* combined */ - if (rl->rectf && rlp->rectf) - do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4); - - /* passes are allocated in sync */ - for (rpass = rl->passes.first, rpassp = rlp->passes.first; rpass && rpassp; rpass = rpass->next, rpassp = rpassp->next) { - do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels); + for (rl = rr->layers.first; rl; rl = rl->next) { + rlp = RE_GetRenderLayer(rrpart, rl->name); + if (rlp) { + /* combined */ + if (rl->rectf && rlp->rectf) + do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4); + + /* passes are allocated in sync */ + for (rpass = rl->passes.first, rpassp = rlp->passes.first; + rpass && rpassp; + rpass = rpass->next, rpassp = rpassp->next) + { + do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels); + } } } } @@ -739,21 +753,24 @@ int RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *file /* combined */ if (rl->rectf) { int a, xstride = 4; - for (a = 0; a < xstride; a++) - IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), + for (a = 0; a < xstride; a++) { + IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride * rr->rectx, rl->rectf + a); + } } /* passes are allocated in sync */ for (rpass = rl->passes.first; rpass; rpass = rpass->next) { int a, xstride = rpass->channels; for (a = 0; a < xstride; a++) { - if (rpass->passtype) - IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), + if (rpass->passtype) { + IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), xstride, xstride * rr->rectx, rpass->rect + a); - else - IMB_exr_add_channel(exrhandle, rl->name, make_pass_name(rpass, a), + } + else { + IMB_exr_add_channel(exrhandle, rl->name, make_pass_name(rpass, a), xstride, xstride * rr->rectx, rpass->rect + a); + } } } } @@ -811,8 +828,9 @@ void render_result_single_layer_end(Render *re) /* reconstruct render result layers */ for (nr = 0, srl = re->scene->r.layers.first; srl; srl = srl->next, nr++) { - if (nr == re->r.actlay) + if (nr == re->r.actlay) { BLI_addtail(&re->result->layers, rl); + } else { rlpush = RE_GetRenderLayer(re->pushedresult, srl->name); if (rlpush) { @@ -831,14 +849,21 @@ void render_result_single_layer_end(Render *re) static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart) { - RenderLayer *rlp; + RenderLayer *rlp, *rl; RenderPass *rpassp; int offs, partx, party; BLI_lock_thread(LOCK_IMAGE); for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) { - + rl = RE_GetRenderLayer(rr, rlp->name); + + /* should never happen but prevents crash if it does */ + BLI_assert(rl); + if (UNLIKELY(rl == NULL)) { + continue; + } + if (rrpart->crop) { /* filters add pixel extra */ offs = (rrpart->crop + rrpart->crop * rrpart->rectx); } @@ -849,24 +874,37 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart) /* combined */ if (rlp->rectf) { int a, xstride = 4; - for (a = 0; a < xstride; a++) - IMB_exr_set_channel(rr->exrhandle, rlp->name, get_pass_name(SCE_PASS_COMBINED, a), + for (a = 0; a < xstride; a++) { + IMB_exr_set_channel(rl->exrhandle, rlp->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride * rrpart->rectx, rlp->rectf + a + xstride * offs); + } } /* passes are allocated in sync */ for (rpassp = rlp->passes.first; rpassp; rpassp = rpassp->next) { int a, xstride = rpassp->channels; - for (a = 0; a < xstride; a++) - IMB_exr_set_channel(rr->exrhandle, rlp->name, get_pass_name(rpassp->passtype, a), + for (a = 0; a < xstride; a++) { + IMB_exr_set_channel(rl->exrhandle, rlp->name, get_pass_name(rpassp->passtype, a), xstride, xstride * rrpart->rectx, rpassp->rect + a + xstride * offs); + } } } party = rrpart->tilerect.ymin + rrpart->crop; partx = rrpart->tilerect.xmin + rrpart->crop; - IMB_exrtile_write_channels(rr->exrhandle, partx, party, 0); + + for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) { + rl = RE_GetRenderLayer(rr, rlp->name); + + /* should never happen but prevents crash if it does */ + BLI_assert(rl); + if (UNLIKELY(rl == NULL)) { + continue; + } + + IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0); + } BLI_unlock_thread(LOCK_IMAGE); } @@ -875,15 +913,18 @@ static void save_empty_result_tiles(Render *re) { RenderPart *pa; RenderResult *rr; + RenderLayer *rl; for (rr = re->result; rr; rr = rr->next) { - IMB_exrtile_clear_channels(rr->exrhandle); + for (rl = rr->layers.first; rl; rl = rl->next) { + IMB_exrtile_clear_channels(rl->exrhandle); - for (pa = re->parts.first; pa; pa = pa->next) { - if (pa->ready == 0) { - int party = pa->disprect.ymin - re->disprect.ymin + pa->crop; - int partx = pa->disprect.xmin - re->disprect.xmin + pa->crop; - IMB_exrtile_write_channels(rr->exrhandle, partx, party, 0); + for (pa = re->parts.first; pa; pa = pa->next) { + if (pa->ready == 0) { + int party = pa->disprect.ymin - re->disprect.ymin + pa->crop; + int partx = pa->disprect.xmin - re->disprect.xmin + pa->crop; + IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0); + } } } } @@ -893,13 +934,15 @@ static void save_empty_result_tiles(Render *re) void render_result_exr_file_begin(Render *re) { RenderResult *rr; + RenderLayer *rl; char str[FILE_MAX]; - + for (rr = re->result; rr; rr = rr->next) { - render_result_exr_file_path(re->scene, rr->sample_nr, str); - - printf("write exr tmp file, %dx%d, %s\n", rr->rectx, rr->recty, str); - IMB_exrtile_begin_write(rr->exrhandle, str, 0, rr->rectx, rr->recty, re->partx, re->party); + for (rl = rr->layers.first; rl; rl = rl->next) { + render_result_exr_file_path(re->scene, rl->name, rr->sample_nr, str); + printf("write exr tmp file, %dx%d, %s\n", rr->rectx, rr->recty, str); + IMB_exrtile_begin_write(rl->exrhandle, str, 0, rr->rectx, rr->recty, re->partx, re->party); + } } } @@ -907,12 +950,17 @@ void render_result_exr_file_begin(Render *re) void render_result_exr_file_end(Render *re) { RenderResult *rr; + RenderLayer *rl; save_empty_result_tiles(re); for (rr = re->result; rr; rr = rr->next) { - IMB_exr_close(rr->exrhandle); - rr->exrhandle = NULL; + for (rl = rr->layers.first; rl; rl = rl->next) { + IMB_exr_close(rl->exrhandle); + rl->exrhandle = NULL; + } + + rr->do_exr_tile = FALSE; } render_result_free_list(&re->fullresult, re->result); @@ -929,17 +977,17 @@ void render_result_exr_file_merge(RenderResult *rr, RenderResult *rrpart) } /* path to temporary exr file */ -void render_result_exr_file_path(Scene *scene, int sample, char *filepath) +void render_result_exr_file_path(Scene *scene, const char *layname, int sample, char *filepath) { - char di[FILE_MAX], name[FILE_MAXFILE + MAX_ID_NAME + 100], fi[FILE_MAXFILE]; + char di[FILE_MAX], name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100], fi[FILE_MAXFILE]; BLI_strncpy(di, G.main->name, FILE_MAX); BLI_splitdirstring(di, fi); if (sample == 0) - BLI_snprintf(name, sizeof(name), "%s_%s.exr", fi, scene->id.name + 2); + BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname); else - BLI_snprintf(name, sizeof(name), "%s_%s%d.exr", fi, scene->id.name + 2, sample); + BLI_snprintf(name, sizeof(name), "%s_%s_%s%d.exr", fi, scene->id.name + 2, layname, sample); BLI_make_file_string("/", filepath, BLI_temporary_dir(), name); } @@ -947,29 +995,30 @@ void render_result_exr_file_path(Scene *scene, int sample, char *filepath) /* only for temp buffer files, makes exact copy of render result */ int render_result_exr_file_read(Render *re, int sample) { + RenderLayer *rl; char str[FILE_MAX]; - int success; + int success = TRUE; RE_FreeRenderResult(re->result); - re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM); + re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS); - render_result_exr_file_path(re->scene, sample, str); - printf("read exr tmp file: %s\n", str); + for (rl = re->result->layers.first; rl; rl = rl->next) { - if (render_result_exr_file_read_path(re->result, str)) { - success = TRUE; - } - else { - printf("cannot read: %s\n", str); - success = FALSE; + render_result_exr_file_path(re->scene, rl->name, sample, str); + printf("read exr tmp file: %s\n", str); + + if (!render_result_exr_file_read_path(re->result, rl, str)) { + printf("cannot read: %s\n", str); + success = FALSE; + } } return success; } /* called for reading temp files, and for external engines */ -int render_result_exr_file_read_path(RenderResult *rr, const char *filepath) +int render_result_exr_file_read_path(RenderResult *rr, RenderLayer *rl_single, const char *filepath) { RenderLayer *rl; RenderPass *rpass; @@ -992,6 +1041,9 @@ int render_result_exr_file_read_path(RenderResult *rr, const char *filepath) } for (rl = rr->layers.first; rl; rl = rl->next) { + if (rl_single && rl_single != rl) + continue; + /* combined */ if (rl->rectf) { int a, xstride = 4; diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 14c178c10f9..cbe8cc81451 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -93,13 +93,9 @@ extern struct Render R; static void init_render_texture(Render *re, Tex *tex) { - int cfra= re->scene->r.cfra; - - if (re) cfra= re->r.cfra; - /* imap test */ if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { - BKE_image_user_frame_calc(&tex->iuser, cfra, re?re->flag & R_SEC_FIELD:0); + BKE_image_user_frame_calc(&tex->iuser, re->r.cfra, re?re->flag & R_SEC_FIELD:0); } else if (tex->type==TEX_ENVMAP) { diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index b842cab1d29..8c9df496dd6 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -36,7 +36,6 @@ #include "BKE_modifier.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" #include "render_types.h" #include "RE_shader_ext.h" diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 78dbd253cd6..5c88babfb47 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -57,11 +57,11 @@ void WM_keymap_init (struct bContext *C); void WM_keymap_free (struct wmKeyMap *keymap); wmKeyMapItem *WM_keymap_verify_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 1f0a0d87cf4..4ec3d8ea755 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -115,7 +115,6 @@ struct ImBuf; #include "RNA_types.h" #include "DNA_listBase.h" -#include "BKE_utildefines.h" /* FILE_MAX */ /* exported types for WM */ #include "wm_cursors.h" diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 60c61dbe88c..17f17baba0e 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1444,14 +1444,15 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand } else { - printf("%s: error - missing modal\n", __func__); + printf("%s: error '%s' missing modal\n", __func__, op->idname); } } else { wmOperatorType *ot = WM_operatortype_find(event->keymap_idname, 0); - if (ot) + if (ot) { retval = wm_operator_invoke(C, ot, event, properties, NULL, FALSE); + } } /* Finished and pass through flag as handled */ @@ -2707,7 +2708,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U switch (type) { /* mouse move */ - case GHOST_kEventCursorMove: { + case GHOST_kEventCursorMove: + { if (win->active) { GHOST_TEventCursorData *cd = customdata; wmEvent *lastevent = win->queue.last; @@ -2750,7 +2752,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } break; } - case GHOST_kEventTrackpad: { + case GHOST_kEventTrackpad: + { GHOST_TEventTrackpadData *pd = customdata; switch (pd->subtype) { case GHOST_kTrackpadEventMagnify: @@ -2782,7 +2785,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } /* mouse button */ case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { + case GHOST_kEventButtonUp: + { GHOST_TEventButtonData *bd = customdata; event.val = (type == GHOST_kEventButtonDown) ? KM_PRESS : KM_RELEASE; @@ -2830,7 +2834,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } /* keyboard */ case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { + case GHOST_kEventKeyUp: + { GHOST_TEventKeyData *kd = customdata; event.type = convert_key(kd->key); event.ascii = kd->ascii; @@ -2914,7 +2919,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventWheel: { + case GHOST_kEventWheel: + { GHOST_TEventWheelData *wheelData = customdata; if (wheelData->z > 0) @@ -2927,7 +2933,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventTimer: { + case GHOST_kEventTimer: + { event.type = TIMER; event.custom = EVT_DATA_TIMER; event.customdata = customdata; @@ -2936,7 +2943,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventNDOFMotion: { + case GHOST_kEventNDOFMotion: + { event.type = NDOF_MOTION; attach_ndof_data(&event, customdata); wm_event_add(win, &event); @@ -2946,7 +2954,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } - case GHOST_kEventNDOFButton: { + case GHOST_kEventNDOFButton: + { GHOST_TEventNDOFButtonData *e = customdata; event.type = NDOF_BUTTON_NONE + e->button; @@ -2972,12 +2981,12 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U case GHOST_kNumEventTypes: break; - case GHOST_kEventWindowDeactivate: { + case GHOST_kEventWindowDeactivate: + { event.type = WINDEACTIVATE; wm_event_add(win, &event); break; - } } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index f01ca9f566e..dca28c63557 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -492,6 +492,8 @@ int WM_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory char tstr[FILE_MAX]; int success = 0; + BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE); + G.relbase_valid = 0; if (!from_memory) { char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL); @@ -569,6 +571,9 @@ int WM_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory } #endif + /* important to do before NULL'ing the context */ + BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); + WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL); /* in background mode the scene will stay NULL */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 67cd202591d..0259146a9d3 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1002,7 +1002,7 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op) layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, UI_UNIT_Y, style); if (!WM_operator_check_ui_enabled(C, op->type->name)) - uiLayoutSetEnabled(layout, 0); + uiLayoutSetEnabled(layout, FALSE); if (op->type->flag & OPTYPE_MACRO) { for (op = op->macro.first; op; op = op->next) { diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 0074d6236db..e3867c0a32a 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -61,7 +61,6 @@ #include "BKE_blender.h" #include "BKE_global.h" -#include "BKE_utildefines.h" #include "BIF_gl.h" #include "BIF_glutil.h" @@ -327,7 +326,11 @@ static void build_pict_list(char *first, int totframes, int fstep, int fontid) int file; file = open(filepath, O_BINARY | O_RDONLY, 0); - if (file < 0) return; + if (file < 0) { + /* print errno? */ + return; + } + picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture"); if (picture == NULL) { printf("Not enough memory for pict struct '%s'\n", filepath); @@ -701,11 +704,11 @@ void playanim_window_open(const char *title, int posx, int posy, int sizex, int inital_state = start_maximized ? GHOST_kWindowStateMaximized : GHOST_kWindowStateNormal; g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system, - title, - posx, posy, sizex, sizey, - inital_state, - GHOST_kDrawingContextTypeOpenGL, - FALSE /* no stereo */, FALSE); + title, + posx, posy, sizex, sizey, + inital_state, + GHOST_kDrawingContextTypeOpenGL, + FALSE /* no stereo */, FALSE); //if (ghostwin) { //if (win) { diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index b83b93454e6..59c8235faf0 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -724,11 +724,13 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr break; } - case GHOST_kEventWindowClose: { + case GHOST_kEventWindowClose: + { wm_window_close(C, wm, win); break; } - case GHOST_kEventWindowUpdate: { + case GHOST_kEventWindowUpdate: + { if (G.debug & G_DEBUG_EVENTS) { printf("%s: ghost redraw %d\n", __func__, win->winid); } @@ -739,7 +741,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr break; } case GHOST_kEventWindowSize: - case GHOST_kEventWindowMove: { + case GHOST_kEventWindowMove: + { GHOST_TWindowState state; state = GHOST_GetWindowState(win->ghostwin); win->windowstate = state; diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 38b87824cfb..b6228849ec8 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -791,6 +791,9 @@ if(WITH_CYCLES) cycles_kernel cycles_util cycles_subd) + if(WITH_CYCLES_OSL) + list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl) + endif() endif() #if(UNIX) @@ -955,6 +958,10 @@ endif() list(APPEND BLENDER_SORTED_LIBS extern_xdnd) endif() + if(WITH_CYCLES_OSL) + list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl") + endif() + foreach(SORTLIB ${BLENDER_SORTED_LIBS}) set(REMLIB ${SORTLIB}) foreach(SEARCHLIB ${BLENDER_LINK_LIBS}) diff --git a/source/creator/creator.c b/source/creator/creator.c index e0e82679645..e1dc2b5df4c 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -68,7 +68,6 @@ #include "BLI_blenlib.h" -#include "BKE_utildefines.h" #include "BKE_blender.h" #include "BKE_context.h" #include "BKE_depsgraph.h" /* for DAG_on_visible_update */ diff --git a/source/darwin/blender.app/Contents/Info.plist b/source/darwin/blender.app/Contents/Info.plist index 37920dc8181..064ffe5bc3f 100644 --- a/source/darwin/blender.app/Contents/Info.plist +++ b/source/darwin/blender.app/Contents/Info.plist @@ -48,5 +48,7 @@ <key>OMP_NUM_THREADS</key> <string>4</string> </dict> + <key>NSPrincipalClass</key> + <string>NSApplication</string> </dict> </plist> diff --git a/source/darwin/blenderplayer.app/Contents/Info.plist b/source/darwin/blenderplayer.app/Contents/Info.plist index 54364d18866..c7b9ceb568e 100644 --- a/source/darwin/blenderplayer.app/Contents/Info.plist +++ b/source/darwin/blenderplayer.app/Contents/Info.plist @@ -1,33 +1,27 @@ <?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> -<plist version="0.9"> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> <dict> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> - <key>CFBundleExecutable</key> <string>blenderplayer</string> - <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> - <key>CFBundleIconFile</key> <string>blender player icon.icns</string> - <key>CFBundleName</key> <string>BlenderPlayer</string> <key>CFBundleIdentifier</key> <string>org.blenderfoundation.blenderplayer</string> - <key>CFBundleVersion</key> <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}, Blender Foundation</string> <key>CFBundleShortVersionString</key> <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> <key>CFBundleGetInfoString</key> <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}, Blender Foundation</string> - <key>CFBundleDocumentTypes</key> <array> <dict> @@ -49,5 +43,7 @@ <false/> </dict> </array> + <key>NSPrincipalClass</key> + <string>NSApplication</string> </dict> </plist> diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 1b8f857c2cb..3a06fe979e1 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -54,6 +54,7 @@ #include "KX_BlenderSceneConverter.h" #include "KX_PythonInit.h" #include "KX_PyConstraintBinding.h" +#include "KX_PythonMain.h" #include "RAS_GLExtensionManager.h" #include "RAS_OpenGLRasterizer.h" @@ -79,6 +80,9 @@ extern "C" { #include "DNA_windowmanager_types.h" #include "BKE_global.h" #include "BKE_report.h" + +#include "MEM_guardedalloc.h" + /* #include "BKE_screen.h" */ /* cant include this because of 'new' function name */ extern float BKE_screen_view3d_zoom_to_fac(float camzoom); @@ -121,6 +125,93 @@ static BlendFileData *load_game_data(char *filename) return bfd; } +int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWindow *win, Scene *scene, ARegion *ar, + KX_BlenderKeyboardDevice* keyboarddevice, KX_BlenderMouseDevice* mousedevice, int draw_letterbox) +{ + int exitrequested; + + // first check if we want to exit + exitrequested = ketsjiengine->GetExitCode(); + + // kick the engine + bool render = ketsjiengine->NextFrame(); + + if (render) { + if (draw_letterbox) { + // Clear screen to border color + // We do this here since we set the canvas to be within the frames. This means the engine + // itself is unaware of the extra space, so we clear the whole region for it. + glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f); + glViewport(ar->winrct.xmin, ar->winrct.ymin, + BLI_RCT_SIZE_X(&ar->winrct), BLI_RCT_SIZE_Y(&ar->winrct)); + glClear(GL_COLOR_BUFFER_BIT); + } + + // render the frame + ketsjiengine->Render(); + } + + wm_window_process_events_nosleep(); + + // test for the ESC key + //XXX while (qtest()) + while (wmEvent *event= (wmEvent *)win->queue.first) { + short val = 0; + //unsigned short event = 0; //XXX extern_qread(&val); + + if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) + exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; + + /* Coordinate conversion... where + * should this really be? + */ + if (event->type == MOUSEMOVE) { + /* Note, not nice! XXX 2.5 event hack */ + val = event->x - ar->winrct.xmin; + mousedevice->ConvertBlenderEvent(MOUSEX, val); + + val = ar->winy - (event->y - ar->winrct.ymin) - 1; + mousedevice->ConvertBlenderEvent(MOUSEY, val); + } + else { + mousedevice->ConvertBlenderEvent(event->type,event->val); + } + + BLI_remlink(&win->queue, event); + wm_event_free(event); + } + + if (win != CTX_wm_window(C)) { + exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */ + } + return exitrequested; +} + +struct BL_KetsjiNextFrameState { + struct KX_KetsjiEngine* ketsjiengine; + struct bContext *C; + struct wmWindow* win; + struct Scene* scene; + struct ARegion *ar; + KX_BlenderKeyboardDevice* keyboarddevice; + KX_BlenderMouseDevice* mousedevice; + int draw_letterbox; +} ketsjinextframestate; + +int BL_KetsjiPyNextFrame(void *state0) +{ + BL_KetsjiNextFrameState *state = (BL_KetsjiNextFrameState *) state0; + return BL_KetsjiNextFrame( + state->ketsjiengine, + state->C, + state->win, + state->scene, + state->ar, + state->keyboarddevice, + state->mousedevice, + state->draw_letterbox); +} + extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing) { /* context values */ @@ -440,71 +531,49 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c // Could be in StartEngine set the framerate, we need the scene to do this ketsjiengine->SetAnimFrameRate(FPS); +#ifdef WITH_PYTHON + char *python_main = NULL; + pynextframestate.state = NULL; + pynextframestate.func = NULL; + python_main = KX_GetPythonMain(scene); + // the mainloop printf("\nBlender Game Engine Started\n"); - while (!exitrequested) - { - // first check if we want to exit - exitrequested = ketsjiengine->GetExitCode(); - - // kick the engine - bool render = ketsjiengine->NextFrame(); - - if (render) - { - if (draw_letterbox) { - // Clear screen to border color - // We do this here since we set the canvas to be within the frames. This means the engine - // itself is unaware of the extra space, so we clear the whole region for it. - glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f); - glViewport(ar->winrct.xmin, ar->winrct.ymin, - BLI_RCT_SIZE_X(&ar->winrct), BLI_RCT_SIZE_Y(&ar->winrct)); - glClear(GL_COLOR_BUFFER_BIT); - } - - // render the frame - ketsjiengine->Render(); + if (python_main) { + char *python_code = KX_GetPythonCode(blenderdata, python_main); + if (python_code) { + ketsjinextframestate.ketsjiengine = ketsjiengine; + ketsjinextframestate.C = C; + ketsjinextframestate.win = win; + ketsjinextframestate.scene = scene; + ketsjinextframestate.ar = ar; + ketsjinextframestate.keyboarddevice = keyboarddevice; + ketsjinextframestate.mousedevice = mousedevice; + ketsjinextframestate.draw_letterbox = draw_letterbox; + + pynextframestate.state = &ketsjinextframestate; + pynextframestate.func = &BL_KetsjiPyNextFrame; + printf("Yielding control to Python script '%s'...\n", python_main); + PyRun_SimpleString(python_code); + printf("Exit Python script '%s'\n", python_main); + MEM_freeN(python_code); } - - wm_window_process_events_nosleep(); - - // test for the ESC key - //XXX while (qtest()) - while(wmEvent *event= (wmEvent *)win->queue.first) + } + else +#endif /* WITH_PYTHON */ + { + while (!exitrequested) { - short val = 0; - //unsigned short event = 0; //XXX extern_qread(&val); - - if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) - exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; - - /* Coordinate conversion... where - * should this really be? - */ - if (event->type==MOUSEMOVE) { - /* Note, not nice! XXX 2.5 event hack */ - val = event->x - ar->winrct.xmin; - mousedevice->ConvertBlenderEvent(MOUSEX, val); - - val = ar->winy - (event->y - ar->winrct.ymin) - 1; - mousedevice->ConvertBlenderEvent(MOUSEY, val); - } - else { - mousedevice->ConvertBlenderEvent(event->type,event->val); - } - - BLI_remlink(&win->queue, event); - wm_event_free(event); - } - - if (win != CTX_wm_window(C)) { - exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */ + exitrequested = BL_KetsjiNextFrame(ketsjiengine, C, win, scene, ar, keyboarddevice, mousedevice, draw_letterbox); } } printf("Blender Game Engine Finished\n"); exitstring = ketsjiengine->GetExitString(); - gs = *(ketsjiengine->GetGlobalSettings()); +#ifdef WITH_PYTHON + if (python_main) MEM_freeN(python_main); +#endif /* WITH_PYTHON */ + gs = *(ketsjiengine->GetGlobalSettings()); // when exiting the mainloop #ifdef WITH_PYTHON diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 89a3f365140..9caa6bbf579 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -82,8 +82,7 @@ #include "BKE_text.h" #include "BLI_blenlib.h" #include "BLI_math_base.h" - -#define FILE_MAX 1024 // repeated here to avoid dependency from BKE_utildefines.h +#include "BLI_path_util.h" #include "KX_NetworkMessageActuator.h" diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 5347aaafc65..a35cb4f9f69 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -262,7 +262,7 @@ PyMethodDef PyObjectPlus::Methods[] = { {NULL, NULL} /* Sentinel */ }; -#define attr_invalid (&(PyObjectPlus::Attributes[0])) +#define BGE_PY_ATTR_INVALID (&(PyObjectPlus::Attributes[0])) PyAttributeDef PyObjectPlus::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("invalid", PyObjectPlus, pyattr_get_invalid), {NULL} //Sentinel @@ -281,7 +281,7 @@ PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef * PyObjectPlus *ref= (BGE_PROXY_REF(self_py)); char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref; if (ptr == NULL || (BGE_PROXY_PYREF(self_py) && (ref==NULL || !ref->py_is_valid()))) { - if (attrdef == attr_invalid) + if (attrdef == BGE_PY_ATTR_INVALID) Py_RETURN_TRUE; // don't bother running the function PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG); diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index ea4ac1e150b..48fa3257d20 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -81,7 +81,7 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex ) return NULL; #else /* WITH_SDL */ if (joyindex < 0 || joyindex >= JOYINDEX_MAX) { - echo("Error-invalid joystick index: " << joyindex); + ECHO("Error-invalid joystick index: " << joyindex); return NULL; } @@ -96,7 +96,7 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex ) # else if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) == -1 ) { # endif - echo("Error-Initializing-SDL: " << SDL_GetError()); + ECHO("Error-Initializing-SDL: " << SDL_GetError()); return NULL; } @@ -242,7 +242,7 @@ bool SCA_Joystick::CreateJoystickDevice(void) if (m_isinit == false) { if (m_joyindex>=m_joynum) { // don't print a message, because this is done anyway - //echo("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)"); + //ECHO("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)"); // Need this so python args can return empty lists m_axismax = m_buttonmax = m_hatmax = 0; @@ -253,7 +253,7 @@ bool SCA_Joystick::CreateJoystickDevice(void) SDL_JoystickEventState(SDL_ENABLE); m_isinit = true; - echo("Joystick " << m_joyindex << " initialized"); + ECHO("Joystick " << m_joyindex << " initialized"); /* must run after being initialized */ m_axismax = SDL_JoystickNumAxes(m_private->m_joystick); @@ -279,7 +279,7 @@ void SCA_Joystick::DestroyJoystickDevice(void) #ifdef WITH_SDL if (m_isinit) { if (SDL_JoystickOpened(m_joyindex)) { - echo("Closing-joystick " << m_joyindex); + ECHO("Closing-joystick " << m_joyindex); SDL_JoystickClose(m_private->m_joystick); } m_isinit = false; diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h index 45766eb9057..148bdd0962e 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h @@ -37,10 +37,10 @@ #endif #ifndef _DEBUG -#define echo(x) +# define ECHO(x) #else -#include <iostream> -#define echo(x) std::cout << x << std::endl; +# include <iostream> +# define ECHO(x) std::cout << x << std::endl; #endif #define JOYINDEX_MAX 8 diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 41f641b4368..d8b07fd50d9 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -47,6 +47,7 @@ #endif // __APPLE__ #include "KX_KetsjiEngine.h" #include "KX_PythonInit.h" +#include "KX_PythonMain.h" /********************************** * Begin Blender include block @@ -97,7 +98,6 @@ extern char datatoc_bfont_ttf[]; #include "RAS_IRasterizer.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "RNA_define.h" @@ -332,6 +332,40 @@ static BlendFileData *load_game_data(const char *progname, char *filename = NULL return bfd; } +bool GPG_NextFrame(GHOST_ISystem* system, GPG_Application *app, int &exitcode, STR_String &exitstring, GlobalSettings *gs) +{ + bool run = true; + system->processEvents(false); + system->dispatchEvents(); + app->EngineNextFrame(); + if ((exitcode = app->getExitRequested())) { + run = false; + exitstring = app->getExitString(); + *gs = *app->getGlobalSettings(); + } + return run; +} + +struct GPG_NextFrameState { + GHOST_ISystem* system; + GPG_Application *app; + GlobalSettings *gs; +} gpg_nextframestate; + +int GPG_PyNextFrame(void *state0) +{ + GPG_NextFrameState *state = (GPG_NextFrameState *) state0; + int exitcode; + STR_String exitstring; + bool run = GPG_NextFrame(state->system, state->app, exitcode, exitstring, state->gs); + if (run) return 0; + else { + if (exitcode) + fprintf(stderr, "Exit code %d: %s\n", exitcode, exitstring.ReadPtr()); + return 1; + } +} + int main(int argc, char** argv) { int i; @@ -966,17 +1000,39 @@ int main(int argc, char** argv) // Enter main loop bool run = true; - while (run) + char *python_main = NULL; + pynextframestate.state = NULL; + pynextframestate.func = NULL; +#ifdef WITH_PYTHON + python_main = KX_GetPythonMain(scene); +#endif // WITH_PYTHON + if (python_main) { - system->processEvents(false); - system->dispatchEvents(); - app.EngineNextFrame(); - - if ((exitcode = app.getExitRequested())) + char *python_code = KX_GetPythonCode(maggie, python_main); + if (python_code) + { +#ifdef WITH_PYTHON + gpg_nextframestate.system = system; + gpg_nextframestate.app = &app; + gpg_nextframestate.gs = &gs; + pynextframestate.state = &gpg_nextframestate; + pynextframestate.func = &GPG_PyNextFrame; + + printf("Yielding control to Python script '%s'...\n", python_main); + PyRun_SimpleString(python_code); + printf("Exit Python script '%s'\n", python_main); +#endif // WITH_PYTHON + MEM_freeN(python_code); + } + else { + fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data block named '%s'\n", python_main); + } + } + else + { + while (run) { - run = false; - exitstring = app.getExitString(); - gs = *app.getGlobalSettings(); + run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs); } } app.StopGameEngine(); @@ -986,6 +1042,7 @@ int main(int argc, char** argv) system->removeEventConsumer(&app); BLO_blendfiledata_free(bfd); + if (python_main) MEM_freeN(python_main); } } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME); } diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 4b3426e0784..269311b7e00 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -107,6 +107,7 @@ set(SRC KX_PyMath.cpp KX_PythonInit.cpp KX_PythonInitTypes.cpp + KX_PythonMain.cpp KX_PythonSeq.cpp KX_RadarSensor.cpp KX_RayCast.cpp @@ -189,6 +190,7 @@ set(SRC KX_PyMath.h KX_PythonInit.h KX_PythonInitTypes.h + KX_PythonMain.h KX_PythonSeq.h KX_RadarSensor.h KX_RayCast.h diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 581b3712f97..7d29a20d1a2 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -133,7 +133,6 @@ extern "C" { #include "PHY_IPhysicsEnvironment.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BLI_blenlib.h" #include "GPU_material.h" @@ -811,6 +810,23 @@ static PyObject *gLibList(PyObject*, PyObject* args) return list; } +struct PyNextFrameState pynextframestate; +static PyObject *gPyNextFrame(PyObject *) +{ + if (pynextframestate.func == NULL) Py_RETURN_NONE; + if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead? + + if (pynextframestate.func(pynextframestate.state)) //nonzero = stop + { + Py_RETURN_TRUE; + } + else // 0 = go on + { + Py_RETURN_FALSE; + } +} + + static struct PyMethodDef game_methods[] = { {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc}, {"startGame", (PyCFunction)gPyStartGame, METH_VARARGS, (const char *)gPyStartGame_doc}, @@ -840,7 +856,7 @@ static struct PyMethodDef game_methods[] = { {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"}, {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"}, {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"}, - + {"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"}, /* library functions */ {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""}, diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 866681b9da7..1500dd97ae1 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -70,6 +70,16 @@ class KX_Scene; void KX_SetActiveScene(class KX_Scene* scene); class KX_Scene* KX_GetActiveScene(); class KX_KetsjiEngine* KX_GetActiveEngine(); + +typedef int (*PyNextFrameFunc)(void *); +struct PyNextFrameState { + //state: can be either a GPG_NextFrameState or a BL_KetsjiNextFrameState + void *state; + //func: can be either GPG_PyNextFrame or BL_KetsjiPyNextFrame + PyNextFrameFunc func; +}; +extern struct PyNextFrameState pynextframestate; + #include "MT_Vector3.h" void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color); diff --git a/source/gameengine/Ketsji/KX_PythonMain.cpp b/source/gameengine/Ketsji/KX_PythonMain.cpp new file mode 100644 index 00000000000..d926dff0bf5 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.cpp @@ -0,0 +1,77 @@ +/* + * $Id: KX_PythonMain.cpp 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +/** \file gameengine/Ketsji/KX_PythonMain.cpp + * \ingroup ketsji + */ + +#include "KX_PythonMain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stddef.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_string.h" +#include "BLI_listbase.h" + +#include "BKE_text.h" +#include "BKE_main.h" +#include "BKE_idprop.h" + + +#ifdef __cplusplus +} +#endif + +extern "C" char *KX_GetPythonMain(struct Scene *scene) +{ + /* examine custom scene properties */ + if (scene->id.properties) { + IDProperty *item = IDP_GetPropertyTypeFromGroup(scene->id.properties, "__main__", IDP_STRING); + if (item) { + return BLI_strdup(IDP_String(item)); + } + } + + return NULL; +} + +extern "C" char *KX_GetPythonCode(Main *bmain, char *python_main) +{ + Text *text; + + if ((text = (Text *)BLI_findstring(&bmain->text, python_main, offsetof(ID, name) + 2))) { + return txt_to_buf(text); + } + + return NULL; +} diff --git a/source/gameengine/Ketsji/KX_PythonMain.h b/source/gameengine/Ketsji/KX_PythonMain.h new file mode 100644 index 00000000000..1460ea2ca96 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.h @@ -0,0 +1,41 @@ +/* + * $Id: KX_PythonMain.h 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file KX_PythonMain.h + * \ingroup ketsji + */ + +#ifndef __KX_PYTHON_MAIN +#define __KX_PYTHON_MAIN + +#include "BKE_main.h" +#include "DNA_scene_types.h" +extern "C" char *KX_GetPythonMain(struct Scene* scene); +extern "C" char *KX_GetPythonCode(struct Main *main, char *python_main); +#endif diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index f9fa0ae65f1..c1afed82b02 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1727,11 +1727,6 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to) brick->Replace_IScene(to); brick->Replace_NetworkScene(to->GetNetworkScene()); - SCA_ISensor *sensor= dynamic_cast<class SCA_ISensor *>(brick); - if (sensor) { - sensor->Replace_EventManager(logicmgr); - } - /* near sensors have physics controllers */ #ifdef USE_BULLET KX_TouchSensor *touch_sensor = dynamic_cast<class KX_TouchSensor *>(brick); @@ -1739,6 +1734,14 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to) touch_sensor->GetPhysicsController()->SetPhysicsEnvironment(to->GetPhysicsEnvironment()); } #endif + + // If we end up replacing a KX_TouchEventManager, we need to make sure + // physics controllers are properly in place. In other words, do this + // after merging physics controllers! + SCA_ISensor *sensor= dynamic_cast<class SCA_ISensor *>(brick); + if (sensor) { + sensor->Replace_EventManager(logicmgr); + } } #ifdef USE_BULLET diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 92c390efd39..06251cd2282 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -431,7 +431,7 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) // reverting to texunit 0, without this we get bug [#28462] glActiveTextureARB(GL_TEXTURE0); - glViewport(rect.GetLeft(), rect.GetBottom(), rect_width, rect.GetHeight()+1); + glViewport(rect.GetLeft(), rect.GetBottom(), rect_width, rect_height); glDisable(GL_DEPTH_TEST); // in case the previous material was wire diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 7da0be3a506..25afefbcc5a 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -536,18 +536,18 @@ void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transfor const MT_Vector3 pnorm(transform.getBasis()[2]); // unneeded: const MT_Scalar pval = transform.getOrigin()[2]; - vector<polygonSlot> slots(totpoly); + vector<polygonSlot> poly_slots(totpoly); /* get indices and z into temporary array */ for (j=0; j<totpoly; j++) - slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm); + poly_slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm); /* sort (stable_sort might be better, if flickering happens?) */ - std::sort(slots.begin(), slots.end(), backtofront()); + std::sort(poly_slots.begin(), poly_slots.end(), backtofront()); /* get indices from temporary array again */ for (j=0; j<totpoly; j++) - slots[j].set(it.index, j*nvert, nvert); + poly_slots[j].set(it.index, j*nvert, nvert); } } diff --git a/source/tests/bl_rna_wiki_reference.py b/source/tests/bl_rna_wiki_reference.py new file mode 100644 index 00000000000..2018c4327a3 --- /dev/null +++ b/source/tests/bl_rna_wiki_reference.py @@ -0,0 +1,70 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8 compliant> + +# Use for validating our wiki interlinking. +# ./blender.bin --background -noaudio --python source/tests/bl_rna_wiki_reference.py +# +# 1) test_lookup_coverage() -- ensure that we have lookups for _every_ RNA path +# 2) test_urls() -- ensure all the URL's are correct +# 3) test_language_coverage() -- ensure language lookup table is complete +# + +import bpy + +# a stripped down version of api_dump() in rna_info_dump.py + + +def test_lookup_coverage(): + + def rna_ids(): + + import rna_info + struct = rna_info.BuildRNAInfo()[0] + for struct_id, v in sorted(struct.items()): + props = [(prop.identifier, prop) for prop in v.properties] + for prop_id, prop in props: + yield "bpy.types.%s.%s" % (struct_id[1], prop_id) + + for submod_id in dir(bpy.ops): + for op_id in dir(getattr(bpy.ops, submod_id)): + yield "bpy.ops.%s.%s" % (submod_id, op_id) + + # check coverage + from bl_operators import wm + + for rna_id in rna_ids(): + url = wm.WM_OT_doc_view_manual._lookup_rna_url(rna_id, verbose=False) + print(rna_id, "->", url) + + +def test_urls(): + pass # TODO + + +def test_language_coverage(): + pass # TODO + + +def main(): + test_lookup_coverage() + test_language_coverage() + +if __name__ == "__main__": + main() diff --git a/source/tests/pep8.py b/source/tests/pep8.py index d12397ea81d..ccaaeb7c0cd 100644 --- a/source/tests/pep8.py +++ b/source/tests/pep8.py @@ -43,7 +43,7 @@ FORCE_PEP8_ALL = False def file_list_py(path): for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: - if filename.endswith(".py") or filename.endswith(".cfg"): + if filename.endswith((".py", ".cfg")): yield os.path.join(dirpath, filename) diff --git a/source/tests/rna_info_dump.py b/source/tests/rna_info_dump.py index 293c02dfb84..615c3b035ce 100644 --- a/source/tests/rna_info_dump.py +++ b/source/tests/rna_info_dump.py @@ -19,7 +19,7 @@ # <pep8 compliant> # Used for generating API diff's between releases -# ./blender.bin --background -noaudio --python release/test/rna_info_dump.py +# ./blender.bin --background -noaudio --python source/tests/rna_info_dump.py import bpy |