Mango request: option to clamp result of Mix RGB and Color Math nodes
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 10 Jul 2012 10:36:18 +0000 (10:36 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 10 Jul 2012 10:36:18 +0000 (10:36 +0000)
---
Merging r48792 from soc-2011-tomato into trunk

218 files changed:
CMakeLists.txt
SConstruct
build_files/cmake/Modules/FindOpenColorIO.cmake [deleted file]
build_files/cmake/macros.cmake
build_files/scons/config/darwin-config.py
build_files/scons/config/linux-config.py
build_files/scons/config/win32-mingw-config.py
build_files/scons/config/win32-vc-config.py
build_files/scons/config/win64-mingw-config.py
build_files/scons/config/win64-vc-config.py
build_files/scons/tools/Blender.py
build_files/scons/tools/btools.py
intern/CMakeLists.txt
intern/SConscript
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_session.h
intern/cycles/blender/blender_sync.cpp
intern/cycles/blender/blender_sync.h
intern/cycles/blender/blender_util.h
intern/cycles/device/CMakeLists.txt
intern/cycles/device/device.cpp
intern/cycles/device/device.h
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_multi.cpp
intern/cycles/device/device_opencl.cpp
intern/cycles/device/device_task.cpp [deleted file]
intern/cycles/device/device_task.h [deleted file]
intern/cycles/render/buffers.cpp
intern/cycles/render/buffers.h
intern/cycles/render/session.cpp
intern/cycles/render/session.h
intern/cycles/render/tile.cpp
intern/cycles/render/tile.h
intern/cycles/util/util_math.h
intern/memutil/MEM_CacheLimiter.h
intern/memutil/MEM_CacheLimiterC-Api.h
intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
intern/opencolorio/CMakeLists.txt [deleted file]
intern/opencolorio/SConscript [deleted file]
intern/opencolorio/ocio_capi.cpp [deleted file]
intern/opencolorio/ocio_capi.h [deleted file]
intern/raskter/CMakeLists.txt
intern/raskter/raskter.c
intern/raskter/raskter.h
intern/raskter/raskter_kdtree.c [new file with mode: 0644]
intern/raskter/raskter_kdtree.h [new file with mode: 0644]
intern/raskter/raskter_mt.c [new file with mode: 0644]
release/datafiles/colormanagement/config.ocio [deleted file]
release/datafiles/colormanagement/luts/adx_adx10_to_cdd.spimtx [deleted file]
release/datafiles/colormanagement/luts/adx_adx16_to_cdd.spimtx [deleted file]
release/datafiles/colormanagement/luts/adx_cdd_to_cid.spimtx [deleted file]
release/datafiles/colormanagement/luts/adx_cid_to_rle.py [deleted file]
release/datafiles/colormanagement/luts/adx_cid_to_rle.spi1d [deleted file]
release/datafiles/colormanagement/luts/adx_exp_to_aces.spimtx [deleted file]
release/datafiles/colormanagement/luts/lg10.spi1d [deleted file]
release/datafiles/colormanagement/luts/logc800.py [deleted file]
release/datafiles/colormanagement/luts/logc800.spi1d [deleted file]
release/datafiles/colormanagement/luts/logc_to_aces.spimtx [deleted file]
release/datafiles/colormanagement/luts/rec709.spi1d [deleted file]
release/datafiles/colormanagement/luts/rec709_to_aces.spimtx [deleted file]
release/datafiles/colormanagement/luts/rrt_ut33_dcdm.spi3d [deleted file]
release/datafiles/colormanagement/luts/rrt_ut33_p3d60.spi3d [deleted file]
release/datafiles/colormanagement/luts/rrt_ut33_p3dci.spi3d [deleted file]
release/datafiles/colormanagement/luts/rrt_ut33_rec709.spi3d [deleted file]
release/datafiles/colormanagement/luts/rrt_ut33_sRGB.spi3d [deleted file]
release/datafiles/colormanagement/luts/slog.py [deleted file]
release/datafiles/colormanagement/luts/slog.spi1d [deleted file]
release/datafiles/colormanagement/luts/slog10.spi1d [deleted file]
release/datafiles/colormanagement/luts/slog2.py [deleted file]
release/datafiles/colormanagement/luts/slogf35_to_aces.spimtx [deleted file]
release/datafiles/colormanagement/luts/slogf65_to_aces_3200.spimtx [deleted file]
release/datafiles/colormanagement/luts/slogf65_to_aces_5500.spimtx [deleted file]
release/datafiles/colormanagement/luts/spi_ocio_srgb_test.spi3d [deleted file]
release/datafiles/colormanagement/luts/ten_bit_scale.spimtx [deleted file]
release/datafiles/splash.png
release/scripts/modules/bl_i18n_utils/bl_process_msg.py
release/scripts/startup/bl_operators/screen_play_rendered_anim.py
release/scripts/startup/bl_ui/properties_color_management.py [deleted file]
release/scripts/startup/bl_ui/properties_render.py
release/scripts/startup/bl_ui/space_clip.py
release/scripts/startup/bl_ui/space_image.py
release/scripts/startup/bl_ui/space_info.py
release/scripts/startup/bl_ui/space_node.py
release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenfont/BLF_translation.h
source/blender/blenfont/intern/blf_lang.c
source/blender/blenkernel/BKE_colortools.h
source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/BKE_mask.h
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/colortools.c
source/blender/blenkernel/intern/fcurve.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/mask.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/seqcache.c
source/blender/blenlib/BLI_string.h
source/blender/blenlib/BLI_threads.h
source/blender/blenlib/intern/string.c
source/blender/blenloader/intern/readblenentry.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/readfile.h
source/blender/collada/ImageExporter.cpp
source/blender/compositor/CMakeLists.txt
source/blender/compositor/intern/COM_Converter.cpp
source/blender/compositor/intern/COM_MemoryBuffer.cpp
source/blender/compositor/intern/COM_MemoryBuffer.h
source/blender/compositor/nodes/COM_DefocusNode.cpp
source/blender/compositor/nodes/COM_KeyingNode.cpp
source/blender/compositor/nodes/COM_KeyingNode.h
source/blender/compositor/nodes/COM_MovieClipNode.cpp
source/blender/compositor/nodes/COM_TrackPositionNode.cpp [deleted file]
source/blender/compositor/nodes/COM_TrackPositionNode.h [deleted file]
source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp
source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h
source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
source/blender/compositor/operations/COM_FastGaussianBlurOperation.h
source/blender/compositor/operations/COM_KeyingDespillOperation.cpp
source/blender/compositor/operations/COM_KeyingDespillOperation.h
source/blender/compositor/operations/COM_KeyingOperation.cpp
source/blender/compositor/operations/COM_MaskOperation.cpp
source/blender/compositor/operations/COM_MaskOperation.h
source/blender/compositor/operations/COM_MovieClipOperation.cpp
source/blender/compositor/operations/COM_MovieClipOperation.h
source/blender/compositor/operations/COM_OpenCLKernels.cl
source/blender/compositor/operations/COM_OpenCLKernels.cl.h
source/blender/compositor/operations/COM_TrackPositionOperation.cpp [deleted file]
source/blender/compositor/operations/COM_TrackPositionOperation.h [deleted file]
source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h
source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
source/blender/compositor/operations/COM_ViewerBaseOperation.h
source/blender/editors/animation/anim_deps.c
source/blender/editors/animation/anim_filter.c
source/blender/editors/animation/anim_ipo_utils.c
source/blender/editors/armature/poseobject.c
source/blender/editors/datafiles/splash.png.c
source/blender/editors/include/ED_clip.h
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_ops.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/resources.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_clip/clip_editor.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_image/image_intern.h
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_draw.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/space_node.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/editors/uvedit/uvedit_parametrizer.c
source/blender/editors/uvedit/uvedit_parametrizer.h
source/blender/editors/uvedit/uvedit_unwrap_ops.c
source/blender/imbuf/CMakeLists.txt
source/blender/imbuf/IMB_colormanagement.h [deleted file]
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/IMB_moviecache.h
source/blender/imbuf/SConscript
source/blender/imbuf/intern/IMB_colormanagement_intern.h [deleted file]
source/blender/imbuf/intern/IMB_filter.h
source/blender/imbuf/intern/allocimbuf.c
source/blender/imbuf/intern/colormanagement.c [deleted file]
source/blender/imbuf/intern/divers.c
source/blender/imbuf/intern/filter.c
source/blender/imbuf/intern/moviecache.c
source/blender/makesdna/DNA_color_types.h
source/blender/makesdna/DNA_mask_types.h
source/blender/makesdna/DNA_meshdata_types.h
source/blender/makesdna/DNA_node_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_nodetree_types.h
source/blender/makesrna/intern/rna_render.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/makesrna/intern/rna_wm.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_composite.h
source/blender/nodes/composite/nodes/node_composite_keying.c
source/blender/nodes/composite/nodes/node_composite_trackpos.c [deleted file]
source/blender/render/extern/include/RE_engine.h
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/include/initrender.h
source/blender/render/intern/include/render_result.h
source/blender/render/intern/source/external_engine.c
source/blender/render/intern/source/initrender.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_result.c
source/blender/windowmanager/CMakeLists.txt
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_playanim.c [deleted file]
source/blender/windowmanager/intern/wm_window.c
source/blenderplayer/CMakeLists.txt
source/creator/CMakeLists.txt
source/creator/creator.c
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

index c98f7d8d88344946f5b4a50ff966d3e2e67fdb96..75cefd0c2198c20ab9f02ce336763d9bcfe6cec6 100644 (file)
@@ -130,7 +130,6 @@ option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effect
 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
 option(WITH_PLAYER        "Build Player" OFF)
-option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
 
 # GHOST Windowing Library Options
@@ -366,7 +365,7 @@ if(WITH_CYCLES)
 endif()
 
 # auto enable boost for cycles and carve
-if(WITH_CYCLES OR WITH_CARVE OR WITH_OPENCOLORIO)
+if(WITH_CYCLES OR WITH_CARVE)
        set(WITH_BOOST ON)
 endif()
 
@@ -672,24 +671,6 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
-       if(WITH_OPENCOLORIO)
-               # use lib dir if available and nothing else specified
-               if(LIBDIR AND NOT OPENCOLORIO_ROOT_DIR)
-                       set(OPENCOLORIO_ROOT_DIR ${LIBDIR}/ocio)
-               endif()
-
-               find_package(OpenColorIO)
-
-               set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
-               set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
-               set(OPENCOLORIO_DEFINITIONS)
-
-               if(NOT OPENCOLORIO_FOUND)
-                       set(WITH_OPENCOLORIO OFF)
-                       message(STATUS "OpenColorIO not found")
-               endif()
-       endif()
-
        # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
        set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
 
@@ -1033,14 +1014,6 @@ elseif(WIN32)
                        set(OPENIMAGEIO_DEFINITIONS)
                endif()
 
-               if(WITH_OPENCOLORIO)
-                       set(OPENCOLORIO ${LIBDIR}/opencolorio)
-                       set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
-                       set(OPENCOLORIO_LIBRARIES OpenColorIO)
-                       set_lib_path(OPENCOLORIO_LIBPATH "opencolorio/lib")
-                       set(OPENCOLORIO_DEFINITIONS)
-               endif()
-
                set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
 
                # MSVC only, Mingw doesnt need
@@ -1210,14 +1183,6 @@ elseif(WIN32)
                        set(OPENIMAGEIO_DEFINITIONS)
                endif()
                
-               if(WITH_OPENCOLORIO)
-                       set(OPENCOLORIO ${LIBDIR}/opencolorio)
-                       set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
-                       set(OPENCOLORIO_LIBRARIES OpenColorIO)
-                       set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
-                       set(OPENCOLORIO_DEFINITIONS)
-               endif()
-
                set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
 
                ## DISABLE - causes linking errors 
@@ -1464,14 +1429,6 @@ elseif(APPLE)
                set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
        endif()
 
-       if(WITH_OPENCOLORIO)
-               set(OPENCOLORIO ${LIBDIR}/opencolorio)
-               set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
-               set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
-               set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
-               set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
-       endif()
-
        set(EXETYPE MACOSX_BUNDLE)
 
        set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
@@ -1838,7 +1795,6 @@ if(FIRST_RUN)
        info_cfg_option(WITH_INTERNATIONAL)
        info_cfg_option(WITH_INPUT_NDOF)
        info_cfg_option(WITH_CYCLES)
-       info_cfg_option(WITH_OPENCOLORIO)
 
        info_cfg_text("Compiler Options:")
        info_cfg_option(WITH_BUILDINFO)
index f0250808faf198c54183dd811b5c925200122e95..993167acfe97af3f8307999465c60e8ca6fca43b 100644 (file)
@@ -609,27 +609,7 @@ if env['OURPLATFORM']!='darwin':
                     kernel_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel')
                     cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch)
                     scriptinstall.append(env.Install(dir=dir,source=cubin_file))
-
-    if env['WITH_BF_OCIO']:
-        colormanagement = os.path.join('release', 'datafiles', 'colormanagement')
-
-        for dp, dn, df in os.walk(colormanagement):
-            if '.svn' in dn:
-                dn.remove('.svn')
-            if '_svn' in dn:
-                dn.remove('_svn')
-
-            dir = os.path.join(env['BF_INSTALLDIR'], VERSION, 'datafiles')
-            dir += os.sep + os.path.basename(colormanagement) + dp[len(colormanagement):]
-
-            source = [os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
-
-            # To ensure empty dirs are created too
-            if len(source) == 0:
-                env.Execute(Mkdir(dir))
-
-            scriptinstall.append(env.Install(dir=dir,source=source))
-
+    
     if env['WITH_BF_INTERNATIONAL']:
         internationalpaths=['release' + os.sep + 'datafiles']
         
@@ -762,9 +742,6 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
     if env['WITH_BF_OIIO'] and env['OURPLATFORM'] != 'win32-mingw':
         dllsources.append('${LCGDIR}/openimageio/bin/OpenImageIO.dll')
 
-    if env['WITH_BF_OCIO'] and env['OURPLATFORM'] != 'win32-mingw':
-        dllsources.append('${LCGDIR}/opencolorio/bin/OpenColorIO.dll')
-
     dllsources.append('#source/icons/blender.exe.manifest')
 
     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
diff --git a/build_files/cmake/Modules/FindOpenColorIO.cmake b/build_files/cmake/Modules/FindOpenColorIO.cmake
deleted file mode 100644 (file)
index 78539ae..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-# - Find OpenColorIO library
-# Find the native OpenColorIO includes and library
-# This module defines
-#  OPENCOLORIO_INCLUDE_DIRS, where to find OpenColorIO.h, Set when
-#                            OPENCOLORIO_INCLUDE_DIR is found.
-#  OPENCOLORIO_LIBRARIES, libraries to link against to use OpenColorIO.
-#  OPENCOLORIO_ROOT_DIR, The base directory to search for OpenColorIO.
-#                        This can also be an environment variable.
-#  OPENCOLORIO_FOUND, If false, do not try to use OpenColorIO.
-#
-# also defined, but not for general use are
-#  OPENCOLORIO_LIBRARY, where to find the OpenColorIO library.
-
-#=============================================================================
-# Copyright 2012 Blender Foundation.
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-
-# If OPENCOLORIO_ROOT_DIR was defined in the environment, use it.
-IF(NOT OPENCOLORIO_ROOT_DIR AND NOT $ENV{OPENCOLORIO_ROOT_DIR} STREQUAL "")
-  SET(OPENCOLORIO_ROOT_DIR $ENV{OPENCOLORIO_ROOT_DIR})
-ENDIF()
-
-SET(_opencolorio_SEARCH_DIRS
-  ${OPENCOLORIO_ROOT_DIR}
-  /usr/local
-  /sw # Fink
-  /opt/local # DarwinPorts
-  /opt/csw # Blastwave
-)
-
-FIND_PATH(OPENCOLORIO_INCLUDE_DIR
-  NAMES
-    OpenColorIO/OpenColorIO.h
-  HINTS
-    ${_opencolorio_SEARCH_DIRS}
-  PATH_SUFFIXES
-    include
-)
-
-FIND_LIBRARY(OPENCOLORIO_LIBRARY
-  NAMES
-    OCIO OpenColorIO
-  HINTS
-    ${_opencolorio_SEARCH_DIRS}
-  PATH_SUFFIXES
-    lib64 lib
-  )
-
-# handle the QUIETLY and REQUIRED arguments and set OPENCOLORIO_FOUND to TRUE if 
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenColorIO DEFAULT_MSG
-    OPENCOLORIO_LIBRARY OPENCOLORIO_INCLUDE_DIR)
-
-IF(OPENCOLORIO_FOUND)
-  SET(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARY})
-  SET(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO_INCLUDE_DIR})
-ENDIF(OPENCOLORIO_FOUND)
-
-MARK_AS_ADVANCED(
-  OPENCOLORIO_INCLUDE_DIR
-  OPENCOLORIO_LIBRARY
-)
-
index f34c88214a9487a3394a947c923721e064096aff..3608f41e369e9b751351f0c6c5db95e5d8444a42 100644 (file)
@@ -193,9 +193,6 @@ macro(SETUP_LIBDIRS)
        if(WITH_OPENIMAGEIO)
                link_directories(${OPENIMAGEIO_LIBPATH})
        endif()
-       if(WITH_OPENCOLORIO)
-               link_directories(${OPENCOLORIO_LIBPATH})
-       endif()
        if(WITH_IMAGE_OPENJPEG AND WITH_SYSTEM_OPENJPEG)
                link_directories(${OPENJPEG_LIBPATH})
        endif()
@@ -291,9 +288,6 @@ macro(setup_liblinks
        if(WITH_OPENIMAGEIO)
                target_link_libraries(${target} ${OPENIMAGEIO_LIBRARIES})
        endif()
-       if(WITH_OPENCOLORIO)
-               target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
-       endif()
        if(WITH_BOOST)
                target_link_libraries(${target} ${BOOST_LIBRARIES})
        endif()
index 4ffc0aaf6f523828c76240f90fc4c8ef5db4c859..e5bce90e50d44999927ec807f490dbe755a1c6b3 100644 (file)
@@ -277,12 +277,6 @@ BF_OIIO_INC = BF_OIIO + '/include'
 BF_OIIO_LIB = 'OpenImageIO'
 BF_OIIO_LIBPATH = BF_OIIO + '/lib'
 
-WITH_BF_OCIO = True
-BF_OCIO = LIBDIR + '/opencolorio'
-BF_OCIO_INC = BF_OCIO + '/include'
-BF_OCIO_LIB = 'OpenColorIO tinyxml yaml-cpp'
-BF_OCIO_LIBPATH = BF_OCIO + '/lib'
-
 WITH_BF_BOOST = True
 BF_BOOST = LIBDIR + '/boost'
 BF_BOOST_INC = BF_BOOST + '/include'
index a63000d7d7d3f041c33ea6cdb99243b2a8f92672..cd97ffe8b56e100f67a1f9549a00c6a6fd98244d 100644 (file)
@@ -210,16 +210,6 @@ BF_OIIO_INC = BF_OIIO + '/include'
 BF_OIIO_LIB = 'OpenImageIO'
 BF_OIIO_LIBPATH = BF_OIIO + '/lib'
 
-WITH_BF_OCIO = True
-WITH_BF_STATICOCIO = False
-BF_OCIO = LIBDIR + '/ocio'
-if not os.path.exists(LCGDIR + '/ocio'):
-    WITH_BF_OCIO = False
-    BF_OCIO = '/usr'
-BF_OCIO_INC = BF_OCIO + '/include'
-BF_OCIO_LIB = 'OpenColorIO yaml-cpp tinyxml'
-BF_OCIO_LIBPATH = BF_OCIO + '/lib'
-
 WITH_BF_BOOST = True
 WITH_BF_STATICBOOST = False
 BF_BOOST = LIBDIR + '/boost'
index f61b128fe9fb469b3e2af829ff27d3e024b8cbb6..723651971d04f7f6833ee0a6327a2f5e5bb9b377 100644 (file)
@@ -159,12 +159,6 @@ BF_OIIO_INC = BF_OIIO + '/include'
 BF_OIIO_LIB = 'OpenImageIO'
 BF_OIIO_LIBPATH = BF_OIIO + '/lib'
 
-WITH_BF_OCIO = False
-BF_OCIO = LIBDIR + '/opencolorio'
-BF_OCIO_INC = BF_OCIO + '/include'
-BF_OCIO_LIB = 'OpenColorIO'
-BF_OCIO_LIBPATH = BF_OCIO + '/lib'
-
 WITH_BF_BOOST = True
 BF_BOOST = LIBDIR + '/boost'
 BF_BOOST_INC = BF_BOOST + '/include'
index 1e1084a9d40d4170592740e775dfa34567d18dd7..609ee867eec6d981e189afc8b076f500280cfc2c 100644 (file)
@@ -156,12 +156,6 @@ BF_OIIO_INC = '${BF_OIIO}/include'
 BF_OIIO_LIB = 'OpenImageIO'
 BF_OIIO_LIBPATH = '${BF_OIIO}/lib'
 
-WITH_BF_OCIO = True
-BF_OCIO = '${LIBDIR}/opencolorio'
-BF_OCIO_INC = '${BF_OCIO}/include'
-BF_OCIO_LIB = 'OpenColorIO'
-BF_OCIO_LIBPATH = '${BF_OCIO}/lib'
-
 WITH_BF_BOOST = True
 BF_BOOST = '${LIBDIR}/boost'
 BF_BOOST_INC = '${BF_BOOST}/include'
index 3eb9803c785a5cd891dc2a41d0102f2489cd5df5..272864392974f7746693404aacf0818ebe581e22 100644 (file)
@@ -159,12 +159,6 @@ BF_OIIO_INC = '${BF_OIIO}/include'
 BF_OIIO_LIB = 'OpenImageIO'
 BF_OIIO_LIBPATH = '${BF_OIIO}/lib'
 
-WITH_BF_OCIO = False
-BF_OCIO = LIBDIR + '/opencolorio'
-BF_OCIO_INC = '${BF_OCIO}/include'
-BF_OCIO_LIB = 'OpenColorIO'
-BF_OCIO_LIBPATH = '${BF_OCIO}/lib'
-
 WITH_BF_BOOST = True
 BF_BOOST = LIBDIR + '/boost'
 BF_BOOST_INC = BF_BOOST + '/include'
index 64c741e4bdf22f6b6c45ad4f12f718e69f330b29..681e058f5bec41bb6d371b03d18684d44ddad396 100644 (file)
@@ -153,13 +153,6 @@ BF_OIIO_LIB = 'OpenImageIO'
 BF_OIIO_LIBPATH = '${BF_OIIO}/lib'
 BF_OIIO_LIBPATH = '${BF_OIIO}/lib'
 
-WITH_BF_OCIO = True
-BF_OCIO = '${LIBDIR}/opencolorio'
-BF_OCIO_INC = '${BF_OCIO}/include'
-BF_OCIO_LIB = 'OpenColorIO'
-BF_OCIO_LIBPATH = '${BF_OCIO}/lib'
-BF_OCIO_LIBPATH = '${BF_OCIO}/lib'
-
 WITH_BF_BOOST = True
 BF_BOOST = '${LIBDIR}/boost'
 BF_BOOST_INC = '${BF_BOOST}/include'
index 3566da34570ed7cac16f8ae9c71b3b76b22ca767..0c5d37f77fed03823efcf1bb89251749e1e4ec83 100644 (file)
@@ -200,11 +200,6 @@ def setup_staticlibs(lenv):
         if lenv['WITH_BF_STATICOIIO']:
             statlibs += Split(lenv['BF_OIIO_LIB_STATIC'])
 
-    if lenv['WITH_BF_OCIO']:
-        libincs += Split(lenv['BF_OCIO_LIBPATH'])
-        if lenv['WITH_BF_STATICOCIO']:
-            statlibs += Split(lenv['BF_OCIO_LIB_STATIC'])
-
     if lenv['WITH_BF_BOOST']:
         libincs += Split(lenv['BF_BOOST_LIBPATH'])
         if lenv['WITH_BF_STATICBOOST']:
@@ -253,10 +248,6 @@ def setup_syslibs(lenv):
         if not lenv['WITH_BF_STATICOIIO']:
             syslibs += Split(lenv['BF_OIIO_LIB'])
 
-    if lenv['WITH_BF_OCIO']:
-        if not lenv['WITH_BF_STATICOCIO']:
-            syslibs += Split(lenv['BF_OCIO_LIB'])
-
     if lenv['WITH_BF_OPENEXR'] and not lenv['WITH_BF_STATICOPENEXR']:
         syslibs += Split(lenv['BF_OPENEXR_LIB'])
     if lenv['WITH_BF_TIFF'] and not lenv['WITH_BF_STATICTIFF']:
@@ -587,9 +578,6 @@ def AppIt(target=None, source=None, env=None):
         commands.getoutput(cmd)
         cmd = 'cp -R %s/release/datafiles/fonts %s/%s.app/Contents/MacOS/%s/datafiles/'%(bldroot,installdir,binary,VERSION)
         commands.getoutput(cmd)
-       if env['WITH_BF_OCIO']:
-            cmd = 'cp -R %s/release/datafiles/colormanagement %s/%s.app/Contents/MacOS/%s/datafiles/'%(bldroot,installdir,binary,VERSION)
-            commands.getoutput(cmd)
         cmd = 'cp -R %s/release/scripts %s/%s.app/Contents/MacOS/%s/'%(bldroot,installdir,binary,VERSION)
         commands.getoutput(cmd)
 
index a7d4aa0d3e1ea67002c3c61ef82011a86499c41b..af484ed382e17e3847ba4750c7a196f6e93aae05 100644 (file)
@@ -163,7 +163,6 @@ def validate_arguments(args, bc):
             'WITH_BF_3DMOUSE', 'WITH_BF_STATIC3DMOUSE', 'BF_3DMOUSE', 'BF_3DMOUSE_INC', 'BF_3DMOUSE_LIB', 'BF_3DMOUSE_LIBPATH', 'BF_3DMOUSE_LIB_STATIC',
             'WITH_BF_CYCLES', 'WITH_BF_CYCLES_CUDA_BINARIES', 'BF_CYCLES_CUDA_NVCC', 'BF_CYCLES_CUDA_NVCC', 'WITH_BF_CYCLES_CUDA_THREADED_COMPILE',
             'WITH_BF_OIIO', 'WITH_BF_STATICOIIO', 'BF_OIIO', 'BF_OIIO_INC', 'BF_OIIO_LIB', 'BF_OIIO_LIB_STATIC', 'BF_OIIO_LIBPATH',
-            'WITH_BF_OCIO', 'WITH_BF_STATICOCIO', 'BF_OCIO', 'BF_OCIO_INC', 'BF_OCIO_LIB', 'BF_OCIO_LIB_STATIC', 'BF_OCIO_LIBPATH',
             'WITH_BF_BOOST', 'WITH_BF_STATICBOOST', 'BF_BOOST', 'BF_BOOST_INC', 'BF_BOOST_LIB', 'BF_BOOST_LIB_STATIC', 'BF_BOOST_LIBPATH',
             'WITH_BF_LIBMV', 'WITH_BF_CARVE'
             ]
@@ -570,14 +569,6 @@ def read_opts(env, cfg, args):
         ('BF_OIIO_LIBPATH', 'OIIO library path', ''),
         ('BF_OIIO_LIB_STATIC', 'OIIO static library', ''),
 
-        (BoolVariable('WITH_BF_OCIO', 'Build with OpenColorIO', False)),
-        (BoolVariable('WITH_BF_STATICOCIO', 'Staticly link to OpenColorIO', False)),
-        ('BF_OCIO', 'OCIO root path', ''),
-        ('BF_OCIO_INC', 'OCIO include path', ''),
-        ('BF_OCIO_LIB', 'OCIO library', ''),
-        ('BF_OCIO_LIBPATH', 'OCIO library path', ''),
-        ('BF_OCIO_LIB_STATIC', 'OCIO static library', ''),
-
         (BoolVariable('WITH_BF_BOOST', 'Build with Boost', False)),
         (BoolVariable('WITH_BF_STATICBOOST', 'Staticly link to boost', False)),
         ('BF_BOOST', 'Boost root path', ''),
index 878101d33113e0d5cdef6f3b93951b5d41654673..71d2ef5e410f45f79533ef017b55353b943d2782 100644 (file)
@@ -71,7 +71,3 @@ endif()
 if(WIN32)
        add_subdirectory(utfconv)
 endif()
-
-if(WITH_OPENCOLORIO)
-       add_subdirectory(opencolorio)
-endif()
index 72137349d822cfce8cb18dc60217d3829a546b8c..3bfdc2c4ca7d5e0976ee6b219653906a3ed19a9a 100644 (file)
@@ -30,6 +30,3 @@ SConscript(['bsp/SConscript'])
 
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-mingw', 'linuxcross', 'win64-vc'):
     SConscript(['utfconv/SConscript'])
-
-if env['WITH_BF_OCIO']:
-    SConscript(['opencolorio/SConscript'])
index 1191d1b8c2552ec08762484fb8f1f3452642bad9..5234db5255ef5327d4dcd3cc47bc593f5d24d0db 100644 (file)
@@ -197,16 +197,8 @@ class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
 
         sub = col.column(align=True)
         sub.label(text="Tiles:")
-
-        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")
-
-        #sub.prop(cscene, "debug_tile_size")
-        #sub.prop(cscene, "debug_min_size")
+        sub.prop(cscene, "debug_tile_size")
+        sub.prop(cscene, "debug_min_size")
 
         col = split.column()
 
index 3cc07a186cbd7d88f0e8089ea80a49a0a07782df..d09e43bd76d2a5f85bb32dad52855ca604c56db3 100644 (file)
@@ -42,7 +42,8 @@ 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_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL),
+  b_rr(PointerRNA_NULL), b_rlay(PointerRNA_NULL)
 {
        /* offline render */
        BL::RenderSettings r = b_scene.render();
@@ -59,7 +60,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_v3d(b_v3d_), b_rv3d(b_rv3d_), b_rr(PointerRNA_NULL), b_rlay(PointerRNA_NULL)
 {
        /* 3d view render */
        width = width_;
@@ -79,7 +80,7 @@ BlenderSession::~BlenderSession()
 void BlenderSession::create_session()
 {
        SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background);
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
+       SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background);
 
        /* reset status/progress */
        last_status = "";
@@ -89,7 +90,7 @@ void BlenderSession::create_session()
        scene = new Scene(scene_params);
 
        /* create sync */
-       sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background);
+       sync = new BlenderSync(b_data, b_scene, scene, !background);
        sync->sync_data(b_v3d, b_engine.camera_override());
 
        if(b_rv3d)
@@ -176,82 +177,35 @@ 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::write_render_buffers(RenderBuffers *buffers)
-{
-       BufferParams& params = 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;
-
-       /* write result */
-       write_render_result(b_rr, b_rlay, buffers);
-       end_render_result(b_engine, b_rr);
-}
-
 void BlenderSession::render()
 {
-       /* set callback to write out render results */
-       session->write_render_buffers_cb = function_bind(&BlenderSession::write_render_buffers, this, _1);
-
        /* get buffer parameters */
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
+       SessionParams session_params = BlenderSync::get_session_params(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::RenderSettings::layers_iterator b_iter;
+       BL::RenderResult::layers_iterator b_iter;
+       BL::RenderLayers b_rr_layers(r.ptr);
        
-       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;
+       /* render each layer */
+       for(b_rr.layers.begin(b_iter); b_iter != b_rr.layers.end(); ++b_iter) {
+               /* set layer */
+               b_rlay = *b_iter;
 
                /* 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);
@@ -263,16 +217,13 @@ 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_rlay_name.c_str());
+               sync->sync_data(b_v3d, b_engine.camera_override(), b_iter->name().c_str());
 
                /* update session */
                int samples = sync->get_layer_samples();
@@ -284,14 +235,20 @@ void BlenderSession::render()
 
                if(session->progress.get_cancel())
                        break;
+
+               /* write result */
+               write_render_result();
        }
 
-       /* clear callback */
-       session->write_render_buffers_cb = NULL;
+       /* delete render result */
+       RE_engine_end_result((RenderEngine*)b_engine.ptr.data, (RenderResult*)b_rr.ptr.data);
 }
 
-void BlenderSession::write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderBuffers *buffers)
+void BlenderSession::write_render_result()
 {
+       /* get state */
+       RenderBuffers *buffers = session->buffers;
+
        /* copy data from device */
        if(!buffers->copy_from_device())
                return;
@@ -332,7 +289,7 @@ 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_engine, b_userpref, b_scene, background);
+       SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background);
 
        if(session->params.modified(session_params) ||
           scene->params.modified(scene_params))
@@ -407,7 +364,7 @@ bool BlenderSession::draw(int w, int h)
 
                /* reset if requested */
                if(reset) {
-                       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
+                       SessionParams session_params = BlenderSync::get_session_params(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);
@@ -478,6 +435,7 @@ 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();
                }
index 0eda2a1944e5bb79da1abae4c8675b6b3080c518..b98e3ffed54fc3c618fef57765364d2158b2189d 100644 (file)
@@ -29,7 +29,6 @@ CCL_NAMESPACE_BEGIN
 
 class Scene;
 class Session;
-class RenderBuffers;
 
 class BlenderSession {
 public:
@@ -47,8 +46,7 @@ public:
 
        /* offline render */
        void render();
-       void write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderBuffers *buffers);
-       void write_render_buffers(RenderBuffers *buffers);
+       void write_render_result();
 
        /* interactive updates */
        void synchronize();
@@ -74,7 +72,8 @@ public:
        BL::Scene b_scene;
        BL::SpaceView3D b_v3d;
        BL::RegionView3D b_rv3d;
-       string b_rlay_name;
+       BL::RenderResult b_rr;
+       BL::RenderLayer b_rlay;
 
        string last_status;
        float last_progress;
index bc35e6dc5c94e37755aa36ba8971da58469499ce..c9d2d68da0ab604d2c2bed8a82345641676a112d 100644 (file)
@@ -40,9 +40,8 @@ CCL_NAMESPACE_BEGIN
 
 /* Constructor */
 
-BlenderSync::BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data_, BL::Scene b_scene_, Scene *scene_, bool preview_)
-: b_engine(b_engine_),
-  b_data(b_data_), b_scene(b_scene_),
+BlenderSync::BlenderSync(BL::BlendData b_data_, BL::Scene b_scene_, Scene *scene_, bool preview_)
+: b_data(b_data_), b_scene(b_scene_),
   shader_map(&scene_->shaders),
   object_map(&scene_->objects),
   mesh_map(&scene_->meshes),
@@ -285,7 +284,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::RenderEngine b_engine, BL::UserPreferences b_userpref, BL::Scene b_scene, bool background)
+SessionParams BlenderSync::get_session_params(BL::UserPreferences b_userpref, BL::Scene b_scene, bool background)
 {
        SessionParams params;
        PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
@@ -339,36 +338,25 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine, BL::Use
                }
        }
 
-       /* tiles */
-       int tile_x = b_engine.tile_x();
-       int tile_y = b_engine.tile_y();
-
-       if(tile_x == 0 || tile_y == 0) {
-               tile_x = get_int(cscene, "debug_tile_size");
-               tile_y = tile_x;
-
-               params.tile_size = make_int2(tile_x, tile_y);
-               params.min_size = get_int(cscene, "debug_min_size");
-       }
-       else {
-               params.tile_size = make_int2(tile_x, tile_y);
-               params.min_size = min(tile_x, tile_y);
-       }
-
        /* 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 = false;
+               params.progressive = true;
                params.min_size = INT_MAX;
        }
        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;
 }
 
index dcfb7c6d6227e56412866cd8d103701cc1b4607c..8c31c4b86baa62419e51137e10cfe316fb7963b6 100644 (file)
@@ -49,7 +49,7 @@ class ShaderNode;
 
 class BlenderSync {
 public:
-       BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data, BL::Scene b_scene, Scene *scene_, bool preview_);
+       BlenderSync(BL::BlendData b_data, BL::Scene b_scene, Scene *scene_, bool preview_);
        ~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::RenderEngine b_engine, BL::UserPreferences b_userpref, BL::Scene b_scene, bool background);
+       static SessionParams get_session_params(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);
 
@@ -96,7 +96,6 @@ private:
        int object_count_particles(BL::Object b_ob);
 
        /* variables */
-       BL::RenderEngine b_engine;
        BL::BlendData b_data;
        BL::Scene b_scene;
 
index ab1f7cf79073ddcfee007ccf8055ee993e58c7fb..ebbd4e1221cf941bd4d9c7d091f44fd86cd04ef6 100644 (file)
@@ -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, const char *layername);
+struct RenderResult *RE_engine_begin_result(struct RenderEngine *engine, int x, int y, int w, int h);
 void RE_engine_update_result(struct RenderEngine *engine, struct RenderResult *result);
-void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result, int cancel);
+void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result);
 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);
index 6038abd815ef7c6079e3f95ac55d9428030248c0..17072d230bb14defd7384513244c97c0592b27d5 100644 (file)
@@ -17,7 +17,6 @@ set(SRC
        device_multi.cpp
        device_network.cpp
        device_opencl.cpp
-       device_task.cpp
 )
 
 set(SRC_HEADERS
@@ -25,7 +24,6 @@ set(SRC_HEADERS
        device_memory.h
        device_intern.h
        device_network.h
-       device_task.h
 )
 
 add_definitions(-DGLEW_STATIC)
index 9a4d364a9b8e42133a2145f112c85cffe2b398de..33040f287d10e85dd2572b8fc37fc1b3bb07660f 100644 (file)
 
 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)
index 2ee2e044618a03927518083a09ed3e4a370db948..b17abac2a1bf6434d684d36bf47a65f9abc4f339 100644 (file)
 #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,7 +33,6 @@
 CCL_NAMESPACE_BEGIN
 
 class Progress;
-class RenderTile;
 
 /* Device Types */
 
@@ -68,6 +67,32 @@ 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 {
@@ -125,10 +150,6 @@ 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);
 
index ebd486b0e0a594d630809f5528b1411b8ab1bfd9..070b20aec49d457427f5e753adecd130652e34fd 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "osl_shader.h"
 
-#include "buffers.h"
-
 #include "util_debug.h"
 #include "util_foreach.h"
 #include "util_function.h"
@@ -143,44 +141,28 @@ public:
                        OSLShader::thread_init(kg);
 #endif
 
-               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;
-
 #ifdef WITH_OPTIMIZED_KERNEL
-                       if(system_cpu_support_optimized()) {
-                               for(int y = tile.y; y < tile.y + tile.h; y++) {
-                                       for(int x = tile.x; x < tile.x + tile.w; x++)
-                                               for(int sample = start_sample; sample < end_sample; sample++)
-                                                       kernel_cpu_optimized_path_trace(kg, render_buffer, rng_state,
-                                                               sample, x, y, tile.offset, tile.stride);
-
-                                       if(task_pool.cancelled())
-                                               break;
-                               }
+               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);
+
+                               if(task_pool.cancelled())
+                                       break;
                        }
-                       else
+               }
+               else
 #endif
-                       {
-                               for(int y = tile.y; y < tile.y + tile.h; y++) {
-                                       for(int x = tile.x; x < tile.x + tile.w; x++)
-                                               for(int sample = start_sample; sample < end_sample; sample++)
-                                                       kernel_cpu_path_trace(kg, render_buffer, rng_state,
-                                                               sample, x, y, tile.offset, tile.stride);
-
-                                       if(task_pool.cancelled())
-                                               break;
-                               }
-                       }
-
-                       task.release_tile(tile);
+               {
+                       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;
+                               if(task_pool.cancelled())
+                                       break;
+                       }
                }
 
 #ifdef WITH_OSL
@@ -246,7 +228,8 @@ 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()+1);
+
+               task.split(tasks, TaskScheduler::num_threads()*10);
 
                foreach(DeviceTask& task, tasks)
                        task_pool.push(new CPUDeviceTask(this, task));
index c297d120b692ab005bb7ec9f2fec45dde3dce5c6..357f99145b218c4b4bdada8b5710fba42936d722 100644 (file)
@@ -23,8 +23,6 @@
 #include "device.h"
 #include "device_intern.h"
 
-#include "buffers.h"
-
 #include "util_cuda.h"
 #include "util_debug.h"
 #include "util_map.h"
@@ -39,7 +37,6 @@ CCL_NAMESPACE_BEGIN
 class CUDADevice : public Device
 {
 public:
-       TaskPool task_pool;
        CUdevice cuDevice;
        CUcontext cuContext;
        CUmodule cuModule;
@@ -195,8 +192,6 @@ public:
 
        ~CUDADevice()
        {
-               task_pool.stop();
-
                cuda_push_context();
                cuda_assert(cuCtxDetach(cuContext))
        }
@@ -471,13 +466,13 @@ public:
                }
        }
 
-       void path_trace(RenderTile& rtile, int sample)
+       void path_trace(DeviceTask& task)
        {
                cuda_push_context();
 
                CUfunction cuPathTrace;
-               CUdeviceptr d_buffer = cuda_device_ptr(rtile.buffer);
-               CUdeviceptr d_rng_state = cuda_device_ptr(rtile.rng_state);
+               CUdeviceptr d_buffer = cuda_device_ptr(task.buffer);
+               CUdeviceptr d_rng_state = cuda_device_ptr(task.rng_state);
 
                /* get kernel function */
                cuda_assert(cuModuleGetFunction(&cuPathTrace, cuModule, "kernel_cuda_path_trace"))
@@ -491,28 +486,29 @@ 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, sample))
-               offset += sizeof(sample);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.sample))
+               offset += sizeof(task.sample);
 
-               cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.x))
-               offset += sizeof(rtile.x);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.x))
+               offset += sizeof(task.x);
 
-               cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.y))
-               offset += sizeof(rtile.y);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.y))
+               offset += sizeof(task.y);
 
-               cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.w))
-               offset += sizeof(rtile.w);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.w))
+               offset += sizeof(task.w);
 
-               cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.h))
-               offset += sizeof(rtile.h);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.h))
+               offset += sizeof(task.h);
 
-               cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.offset))
-               offset += sizeof(rtile.offset);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.offset))
+               offset += sizeof(task.offset);
 
-               cuda_assert(cuParamSeti(cuPathTrace, offset, rtile.stride))
-               offset += sizeof(rtile.stride);
+               cuda_assert(cuParamSeti(cuPathTrace, offset, task.stride))
+               offset += sizeof(task.stride);
 
                cuda_assert(cuParamSetSize(cuPathTrace, offset))
 
@@ -524,8 +520,8 @@ public:
                int xthreads = 8;
                int ythreads = 8;
 #endif
-               int xblocks = (rtile.w + xthreads - 1)/xthreads;
-               int yblocks = (rtile.h + ythreads - 1)/ythreads;
+               int xblocks = (task.w + xthreads - 1)/xthreads;
+               int yblocks = (task.h + ythreads - 1)/ythreads;
 
                cuda_assert(cuFuncSetCacheConfig(cuPathTrace, CU_FUNC_CACHE_PREFER_L1))
                cuda_assert(cuFuncSetBlockShape(cuPathTrace, xthreads, ythreads, 1))
@@ -534,13 +530,13 @@ public:
                cuda_pop_context();
        }
 
-       void tonemap(DeviceTask& task, device_ptr buffer, device_ptr rgba)
+       void tonemap(DeviceTask& task)
        {
                cuda_push_context();
 
                CUfunction cuFilmConvert;
-               CUdeviceptr d_rgba = map_pixels(rgba);
-               CUdeviceptr d_buffer = cuda_device_ptr(buffer);
+               CUdeviceptr d_rgba = map_pixels(task.rgba);
+               CUdeviceptr d_buffer = cuda_device_ptr(task.buffer);
 
                /* get kernel function */
                cuda_assert(cuModuleGetFunction(&cuFilmConvert, cuModule, "kernel_cuda_tonemap"))
@@ -824,67 +820,27 @@ public:
                Device::draw_pixels(mem, y, w, h, dy, width, height, transparent);
        }
 
-       void thread_run(DeviceTask *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++)
-                                       path_trace(tile, sample);
-
-                               cuda_push_context();
-                               cuda_assert(cuCtxSynchronize())
-                               cuda_pop_context();
-
-                               task->release_tile(tile);
-                       }
-               }
-               else if(task->type == DeviceTask::SHADER) {
-                       shader(*task);
-
-                       cuda_push_context();
-                       cuda_assert(cuCtxSynchronize())
-                       cuda_pop_context();
-               }
-       }
-
-       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)
        {
-               if(task.type == DeviceTask::TONEMAP) {
-                       /* must be done in main thread due to opengl access */
-                       tonemap(task, task.buffer, task.rgba);
-
-                       cuda_push_context();
-                       cuda_assert(cuCtxSynchronize())
-                       cuda_pop_context();
-               }
-               else {
-                       task_pool.push(new CUDADeviceTask(this, 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);
        }
 
        void task_wait()
        {
-               task_pool.wait_work();
+               cuda_push_context();
+
+               cuda_assert(cuCtxSynchronize())
+
+               cuda_pop_context();
        }
 
        void task_cancel()
        {
-               task_pool.cancel();
        }
 };
 
index 546ffe5e4b9651aac25310428db02d85a234affe..83e69b98f5d41e9ca1886851552fc77d14921d88 100644 (file)
@@ -23,8 +23,6 @@
 #include "device_intern.h"
 #include "device_network.h"
 
-#include "buffers.h"
-
 #include "util_foreach.h"
 #include "util_list.h"
 #include "util_map.h"
@@ -257,30 +255,6 @@ 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;
@@ -292,6 +266,7 @@ 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];
index e2877530add49a579adfa082c9148d823f82df04..13ebeff70d22d0709f32ea7d4bab92b67b53f746 100644 (file)
@@ -25,8 +25,6 @@
 #include "device.h"
 #include "device_intern.h"
 
-#include "buffers.h"
-
 #include "util_foreach.h"
 #include "util_map.h"
 #include "util_math.h"
@@ -43,7 +41,6 @@ CCL_NAMESPACE_BEGIN
 class OpenCLDevice : public Device
 {
 public:
-       TaskPool task_pool;
        cl_context cxContext;
        cl_command_queue cqCommandQueue;
        cl_platform_id cpPlatform;
@@ -441,8 +438,6 @@ public:
 
        ~OpenCLDevice()
        {
-               task_pool.stop();
-
                if(null_mem)
                        clReleaseMemObject(CL_MEM_PTR(null_mem));
 
@@ -548,19 +543,19 @@ public:
                return global_size + ((r == 0)? 0: group_size - r);
        }
 
-       void path_trace(RenderTile& rtile, int sample)
+       void path_trace(DeviceTask& task)
        {
                /* 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(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;
+               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;
 
                /* sample arguments */
                int narg = 0;
@@ -621,12 +616,12 @@ public:
                return err;
        }
 
-       void tonemap(DeviceTask& task, device_ptr buffer, device_ptr rgba)
+       void tonemap(DeviceTask& task)
        {
                /* 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(rgba);
-               cl_mem d_buffer = CL_MEM_PTR(buffer);
+               cl_mem d_rgba = CL_MEM_PTR(task.rgba);
+               cl_mem d_buffer = CL_MEM_PTR(task.buffer);
                cl_int d_x = task.x;
                cl_int d_y = task.y;
                cl_int d_w = task.w;
@@ -675,49 +670,30 @@ public:
                opencl_assert(clFinish(cqCommandQueue));
        }
 
-       void thread_run(DeviceTask *task)
+       void task_add(DeviceTask& maintask)
        {
-               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;
+               list<DeviceTask> tasks;
 
-                               for(int sample = start_sample; sample < end_sample; sample++)
-                                       path_trace(tile, sample);
-
-                               task->release_tile(tile);
-                       }
-               }
-       }
+               /* arbitrary limit to work around apple ATI opencl issue */
+               if(platform_name == "Apple")
+                       maintask.split_max_size(tasks, 76800);
+               else
+                       tasks.push_back(maintask);
 
-       class OpenCLDeviceTask : public DeviceTask {
-       public:
-               OpenCLDeviceTask(OpenCLDevice *device, DeviceTask& task)
-               : DeviceTask(task)
-               {
-                       run = function_bind(&OpenCLDevice::thread_run, device, this);
+               foreach(DeviceTask& task, tasks) {
+                       if(task.type == DeviceTask::TONEMAP)
+                               tonemap(task);
+                       else if(task.type == DeviceTask::PATH_TRACE)
+                               path_trace(task);
                }
-       };
-
-       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();
        }
 };
 
diff --git a/intern/cycles/device/device_task.cpp b/intern/cycles/device/device_task.cpp
deleted file mode 100644 (file)
index fe872bc..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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"
-
-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)
-{
-}
-
-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);
-               }
-       }
-}
-
-CCL_NAMESPACE_END
-
diff --git a/intern/cycles/device/device_task.h b/intern/cycles/device/device_task.h
deleted file mode 100644 (file)
index e0433e5..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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);
-
-       boost::function<bool(Device *device, RenderTile&)> acquire_tile;
-       boost::function<void(RenderTile&)> release_tile;
-};
-
-CCL_NAMESPACE_END
-
-#endif /* __DEVICE_TASK_H__ */
-
index bd8c6cd22dd40be9719dfae452ada30146cc73cc..a79a3591e0f4fa584de00d38ff5147a323cb2a56 100644 (file)
@@ -74,29 +74,6 @@ 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_)
index f8df2b3587ea57508bec858e317016c0e543f75e..78712ed89ef1318fa3c979400920bfb96b899350 100644 (file)
@@ -67,11 +67,12 @@ 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();
@@ -104,6 +105,8 @@ 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();
@@ -121,27 +124,6 @@ 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 resolution;
-       int offset;
-       int stride;
-
-       device_ptr buffer;
-       device_ptr rng_state;
-       device_ptr rgba;
-
-       RenderBuffers *buffers;
-
-       RenderTile();
-};
-
 CCL_NAMESPACE_END
 
 #endif /* __BUFFERS_H__ */
index eddb288a60034507530a9641a1b7c925821ba8db..a9f7e5beb567fc73466b9f097fcd2a93d9dc6485 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "util_foreach.h"
 #include "util_function.h"
-#include "util_math.h"
 #include "util_opengl.h"
 #include "util_task.h"
 #include "util_time.h"
@@ -36,23 +35,15 @@ CCL_NAMESPACE_BEGIN
 
 Session::Session(const SessionParams& params_)
 : params(params_),
-  tile_manager(params.progressive, params.samples, params.tile_size, params.min_size,
-       (params.background)? 1: max(params.device.multi_devices.size(), 1))
+  tile_manager(params.progressive, params.samples, params.tile_size, params.min_size)
 {
        device_use_gl = ((params.device.type != DEVICE_CPU) && !params.background);
 
        TaskScheduler::init(params.threads);
 
        device = Device::create(params.device, params.background, params.threads);
-
-       if(params.background) {
-               buffers = NULL;
-               display = NULL;
-       }
-       else {
-               buffers = new RenderBuffers(device);
-               display = new DisplayBuffer(device);
-       }
+       buffers = new RenderBuffers(device);
+       display = new DisplayBuffer(device);
 
        session_thread = NULL;
        scene = NULL;
@@ -90,7 +81,7 @@ Session::~Session()
                wait();
        }
 
-       if(display && params.output_path != "") {
+       if(params.output_path != "") {
                tonemap();
 
                progress.set_status("Writing Image", params.output_path);
@@ -127,8 +118,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();
@@ -144,7 +135,7 @@ void Session::reset_gpu(BufferParams& buffer_params, int samples)
 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) {
@@ -154,7 +145,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();
@@ -235,18 +226,23 @@ 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 */
-                       path_trace();
+                       foreach(Tile& tile, tile_manager.state.tiles) {
+                               path_trace(tile);
 
-                       device->task_wait();
+                               device->task_wait();
 
-                       if(device->error_message() != "")
-                               progress.set_cancel(device->error_message());
+                               if(device->error_message() != "")
+                                       progress.set_cancel(device->error_message());
+
+                               if(progress.get_cancel())
+                                       break;
+                       }
 
                        /* update status and timing */
                        update_status_time();
@@ -293,7 +289,7 @@ void Session::reset_cpu(BufferParams& buffer_params, int samples)
 
 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()) {
@@ -312,88 +308,13 @@ 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 = 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_buffers_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::release_tile(RenderTile& rtile)
-{
-       thread_scoped_lock tile_lock(tile_mutex);
-
-       if(write_render_buffers_cb) {
-               /* todo: optimize this by making it thread safe and removing lock */
-               if(!progress.get_cancel())
-                       write_render_buffers_cb(rtile.buffers);
-               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;
@@ -443,7 +364,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();
@@ -458,7 +379,8 @@ void Session::run_cpu()
                        update_status_time();
 
                        /* path trace */
-                       path_trace();
+                       foreach(Tile& tile, tile_manager.state.tiles)
+                               path_trace(tile);
 
                        /* update status and timing */
                        update_status_time();
@@ -474,8 +396,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 */
@@ -543,12 +465,10 @@ bool Session::draw(BufferParams& buffer_params)
 
 void Session::reset_(BufferParams& buffer_params, int samples)
 {
-       if(buffers) {
-               if(buffer_params.modified(buffers->params)) {
-                       gpu_draw_ready = false;
-                       buffers->reset(device, buffer_params);
-                       display->reset(device, buffer_params);
-               }
+       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);
@@ -612,6 +532,8 @@ 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 */
@@ -626,25 +548,20 @@ void Session::update_scene()
        }
 
        /* update scene */
-       if(scene->need_update()) {
-               progress.set_status("Updating Scene");
+       if(scene->need_update())
                scene->device_update(device, progress);
-       }
 }
 
 void Session::update_status_time(bool show_pause, bool show_done)
 {
        int sample = tile_manager.state.sample;
-       int num_samples = tile_manager.state.num_samples;
        int resolution = tile_manager.state.resolution;
-       int num_tiles = tile_manager.state.num_tiles;
-       int tile = num_tiles - tile_manager.state.tiles.size();
 
        /* update status */
        string status, substatus;
 
        if(!params.progressive)
-               substatus = string_printf("Path Tracing Tile %d/%d", tile, num_tiles);
+               substatus = "Path Tracing";
        else if(params.samples == INT_MAX)
                substatus = string_printf("Path Tracing Sample %d", sample+1);
        else
@@ -668,16 +585,23 @@ void Session::update_status_time(bool show_pause, bool show_done)
        /* 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 + num_samples, sample_time);
+       progress.set_sample(sample + 1, sample_time);
 }
 
-void Session::path_trace()
+void Session::path_trace(Tile& tile)
 {
        /* add path trace task */
        DeviceTask task(DeviceTask::PATH_TRACE);
-       
-       task.acquire_tile = function_bind(&Session::acquire_tile, this, _1, _2);
-       task.release_tile = function_bind(&Session::release_tile, this, _1);
+
+       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);
 
        device->task_add(task);
 }
index d06f5b823fbb2a579f0ed250c7b2a09c15a1914e..90616f011ea3af64d6e90f621a1717ce76539004 100644 (file)
@@ -47,7 +47,7 @@ public:
        bool progressive;
        bool experimental;
        int samples;
-       int2 tile_size;
+       int tile_size;
        int min_size;
        int threads;
 
@@ -63,7 +63,7 @@ public:
                progressive = false;
                experimental = false;
                samples = INT_MAX;
-               tile_size = make_int2(64, 64);
+               tile_size = 64;
                min_size = 64;
                threads = 0;
 
@@ -102,11 +102,8 @@ public:
        DisplayBuffer *display;
        Progress progress;
        SessionParams params;
-       TileManager tile_manager;
        int sample;
 
-       boost::function<void(RenderBuffers*)> write_render_buffers_cb;
-
        Session(const SessionParams& params);
        ~Session();
 
@@ -133,7 +130,7 @@ protected:
        void update_status_time(bool show_pause = false, bool show_done = false);
 
        void tonemap();
-       void path_trace();
+       void path_trace(Tile& tile);
        void reset_(BufferParams& params, int samples);
 
        void run_cpu();
@@ -144,9 +141,7 @@ protected:
        bool draw_gpu(BufferParams& params);
        void reset_gpu(BufferParams& params, int samples);
 
-       bool acquire_tile(Device *tile_device, RenderTile& tile);
-       void release_tile(RenderTile& tile);
-
+       TileManager tile_manager;
        bool device_use_gl;
 
        thread *session_thread;
@@ -160,9 +155,6 @@ 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;
 
index 0898edf18dd0413b80c467d98a2e1b0d15e70959..04e48d44029e3973813c595a02e77f94ff2af41b 100644 (file)
 
 CCL_NAMESPACE_BEGIN
 
-TileManager::TileManager(bool progressive_, int num_samples_, int2 tile_size_, int min_size_, int num_devices_)
+TileManager::TileManager(bool progressive_, int samples_, int tile_size_, int min_size_)
 {
        progressive = progressive_;
        tile_size = tile_size_;
        min_size = min_size_;
-       num_devices = num_devices_;
 
        BufferParams buffer_params;
        reset(buffer_params, 0);
@@ -37,7 +36,7 @@ TileManager::~TileManager()
 {
 }
 
-void TileManager::reset(BufferParams& params_, int num_samples_)
+void TileManager::reset(BufferParams& params_, int samples_)
 {
        params = params_;
 
@@ -54,19 +53,17 @@ void TileManager::reset(BufferParams& params_, int num_samples_)
                }
        }
 
-       num_samples = num_samples_;
+       samples = samples_;
 
        state.buffer = BufferParams();
        state.sample = -1;
-       state.num_tiles = 0;
-       state.num_samples = 0;
        state.resolution = start_resolution;
        state.tiles.clear();
 }
 
-void TileManager::set_samples(int num_samples_)
+void TileManager::set_samples(int samples_)
 {
-       num_samples = num_samples_;
+       samples = samples_;
 }
 
 void TileManager::set_tiles()
@@ -74,34 +71,24 @@ 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();
 
-       int num = min(image_h, num_devices);
+       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;
 
-       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;
-
-               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.tiles.push_back(Tile(x, y, w, h));
                }
        }
 
-       state.num_tiles = state.tiles.size();
-
        state.buffer.width = image_w;
        state.buffer.height = image_h;
 
@@ -111,24 +98,9 @@ void TileManager::set_tiles()
        state.buffer.full_height = max(1, params.full_height/resolution);
 }
 
-bool TileManager::next_tile(Tile& tile, int device)
-{
-       list<Tile>::iterator iter;
-
-       for(iter = state.tiles.begin(); iter != state.tiles.end(); iter++) {
-               if(iter->device == device) {
-                       tile = *iter;
-                       state.tiles.erase(iter);
-                       return true;
-               }
-       }
-
-       return false;
-}
-
 bool TileManager::done()
 {
-       return (state.sample+state.num_samples >= num_samples && state.resolution == 1);
+       return (state.sample+1 >= samples && state.resolution == 1);
 }
 
 bool TileManager::next()
@@ -139,17 +111,10 @@ 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();
        }
index b9d1fb26c00011d3dd0d0de1b7dd5ea4fd6763e0..b6e610c8d90247976fa658b7a33aff2cee18bd55 100644 (file)
@@ -31,13 +31,9 @@ CCL_NAMESPACE_BEGIN
 class Tile {
 public:
        int x, y, w, h;
-       int device;
 
-       Tile()
-       {}
-
-       Tile(int x_, int y_, int w_, int h_, int device_)
-       : x(x_), y(y_), w(w_), h(h_), device(device_) {}
+       Tile(int x_, int y_, int w_, int h_)
+       : x(x_), y(y_), w(w_), h(h_) {}
 };
 
 /* Tile Manager */
@@ -49,29 +45,25 @@ public:
        struct State {
                BufferParams buffer;
                int sample;
-               int num_samples;
                int resolution;
-               int num_tiles;
                list<Tile> tiles;
        } state;
 
-       TileManager(bool progressive, int num_samples, int2 tile_size, int min_size, int num_devices = 1);
+       TileManager(bool progressive, int samples, int tile_size, int min_size);
        ~TileManager();
 
-       void reset(BufferParams& params, int num_samples);
-       void set_samples(int num_samples);
+       void reset(BufferParams& params, int samples);
+       void set_samples(int samples);
        bool next();
-       bool next_tile(Tile& tile, int device = 0);
        bool done();
 
 protected:
        void set_tiles();
 
        bool progressive;
-       int num_samples;
-       int2 tile_size;
+       int samples;
+       int tile_size;
        int min_size;
-       int num_devices;
 
        int start_resolution;
 };
index 71a5dedeaa45f0e426b5a8c3cbcc80986cdd1b14..a6bc478ee64d79dbddafde7ae8ce0927be461a94 100644 (file)
@@ -277,11 +277,6 @@ __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));
index 801ee154d401c9395264a26c71f2a0cfe0193103..9a36b67aa2f8c11ae1f9bd197edec89f295da6bf 100644 (file)
@@ -32,7 +32,7 @@
  * @section MEM_CacheLimiter
  * This class defines a generic memory cache management system
  * to limit memory usage to a fixed global maximum.
- *
+ * 
  * Please use the C-API in MEM_CacheLimiterC-Api.h for code written in C.
  *
  * Usage example:
  * public:
  *       ~BigFatImage() { tell_everyone_we_are_gone(this); }
  * };
- *
+ * 
  * void doit() {
  *     MEM_Cache<BigFatImage> BigFatImages;
  *
  *     MEM_Cache_Handle<BigFatImage>* h = BigFatImages.insert(new BigFatImage);
- *
+ * 
  *     BigFatImages.enforce_limits();
  *     h->ref();
  *
@@ -58,8 +58,6 @@
  */
 
 #include <list>
-#include <queue>
-#include <vector>
 #include "MEM_Allocator.h"
 
 template<class T>
@@ -67,44 +65,36 @@ class MEM_CacheLimiter;
 
 #ifndef __MEM_CACHELIMITERC_API_H__
 extern "C" {
-       void MEM_CacheLimiter_set_maximum(size_t m);
-       size_t MEM_CacheLimiter_get_maximum();
+       extern void MEM_CacheLimiter_set_maximum(size_t m);
+       extern size_t MEM_CacheLimiter_get_maximum();
 };
 #endif
 
 template<class T>
 class MEM_CacheLimiterHandle {
 public:
-       explicit MEM_CacheLimiterHandle(T * data_,MEM_CacheLimiter<T> *parent_) :
-               data(data_),
-               refcount(0),
-               parent(parent_)
-       { }
+       explicit MEM_CacheLimiterHandle(T * data_, 
+                                        MEM_CacheLimiter<T> * parent_) 
+               : data(data_), refcount(0), parent(parent_) { }
 
-       void ref() {
-               refcount++;
+       void ref() { 
+               refcount++; 
        }
-
-       void unref() {
-               refcount--;
+       void unref() { 
+               refcount--; 
        }
-
-       T *get() {
-               return data;
+       T * get() { 
+               return data; 
        }
-
-       const T *get() const {
-               return data;
+       const T * get() const { 
+               return data; 
        }
-
-       int get_refcount() const {
-               return refcount;
+       int get_refcount() const { 
+               return refcount; 
        }
-
-       bool can_destroy() const {
-               return !data || !refcount;
+       bool can_destroy() const { 
+               return !data || !refcount; 
        }
-
        bool destroy_if_possible() {
                if (can_destroy()) {
                        delete data;
@@ -114,64 +104,48 @@ public:
                }
                return false;
        }
-
        void unmanage() {
                parent->unmanage(this);
        }
-
        void touch() {
                parent->touch(this);
        }
-
-       void set_priority(int priority) {
-               this->priority = priority;
-       }
-
-       int get_priority(void) {
-               return this->priority;
-       }
-
 private:
        friend class MEM_CacheLimiter<T>;
 
        T * data;
        int refcount;
-       int priority;
-       typename std::list<MEM_CacheLimiterHandle<T> *, MEM_Allocator<MEM_CacheLimiterHandle<T> *> >::iterator me;
+       typename std::list<MEM_CacheLimiterHandle<T> *,
+         MEM_Allocator<MEM_CacheLimiterHandle<T> *> >::iterator me;
        MEM_CacheLimiter<T> * parent;
 };
 
 template<class T>
 class MEM_CacheLimiter {
 public:
+       typedef typename std::list<MEM_CacheLimiterHandle<T> *,
+         MEM_Allocator<MEM_CacheLimiterHandle<T> *> >::iterator iterator;
        typedef size_t (*MEM_CacheLimiter_DataSize_Func) (void *data);
-       typedef int    (*MEM_CacheLimiter_ItemPriority_Func) (void *item, int default_priority);
-
        MEM_CacheLimiter(MEM_CacheLimiter_DataSize_Func getDataSize_)
                : getDataSize(getDataSize_) {
        }
-
        ~MEM_CacheLimiter() {
                for (iterator it = queue.begin(); it != queue.end(); it++) {
                        delete *it;
                }
        }
-
-       MEM_CacheLimiterHandle<T> *insert(T * elem) {
+       MEM_CacheLimiterHandle<T> * insert(T * elem) {
                queue.push_back(new MEM_CacheLimiterHandle<T>(elem, this));
                iterator it = queue.end();
                --it;
                queue.back()->me = it;
                return queue.back();
        }
-
-       void unmanage(MEM_CacheLimiterHandle<T> *handle) {
+       void unmanage(MEM_CacheLimiterHandle<T> * handle) {
                queue.erase(handle->me);
                delete handle;
        }
-
        void enforce_limits() {
-               MEM_CachePriorityQueue priority_queue;
                size_t max = MEM_CacheLimiter_get_maximum();
                size_t mem_in_use, cur_size;
 
@@ -185,33 +159,27 @@ public:
                        mem_in_use = MEM_get_memory_in_use();
                }
 
-               if (mem_in_use <= max) {
-                       return;
-               }
-
-               priority_queue = get_priority_queue();
-
-               while (!priority_queue.empty() && mem_in_use > max) {
-                       MEM_CacheElementPtr elem = priority_queue.top();
-
-                       priority_queue.pop();
+               for (iterator it = queue.begin(); 
+                    it != queue.end() && mem_in_use > max;)
+               {
+                       iterator jt = it;
+                       ++it;
 
                        if(getDataSize) {
-                               cur_size = getDataSize(elem->get()->get_data());
+                               cur_size= getDataSize((*jt)->get()->get_data());
                        } else {
-                               cur_size = mem_in_use;
+                               cur_size= mem_in_use;
                        }
 
-                       if (elem->destroy_if_possible()) {
-                               if (getDataSize) {
-                                       mem_in_use -= cur_size;
-                               } else {
-                                       mem_in_use -= cur_size - MEM_get_memory_in_use();
-                               }
+                       (*jt)->destroy_if_possible();
+
+                       if(getDataSize) {
+                               mem_in_use-= cur_size;
+                       } else {
+                               mem_in_use-= cur_size - MEM_get_memory_in_use();
                        }
                }
        }
-
        void touch(MEM_CacheLimiterHandle<T> * handle) {
                queue.push_back(handle);
                queue.erase(handle->me);
@@ -219,24 +187,7 @@ public:
                --it;
                handle->me = it;
        }
-
-       void set_item_priority_func(MEM_CacheLimiter_ItemPriority_Func item_priority_func) {
-               getItemPriority = item_priority_func;
-       }
-
 private:
-       typedef MEM_CacheLimiterHandle<T> *MEM_CacheElementPtr;
-       typedef std::list<MEM_CacheElementPtr, MEM_Allocator<MEM_CacheElementPtr> > MEM_CacheQueue;
-       typedef typename MEM_CacheQueue::iterator iterator;
-
-       struct compare_element_priority : public std::binary_function<MEM_CacheElementPtr, MEM_CacheElementPtr, bool> {
-               bool operator()(const MEM_CacheElementPtr left_elem, const MEM_CacheElementPtr right_elem) const {
-                       return left_elem->get_priority() > right_elem->get_priority();
-               }
-       };
-
-       typedef std::priority_queue<MEM_CacheElementPtr, std::vector<MEM_CacheElementPtr>, compare_element_priority > MEM_CachePriorityQueue;
-
        size_t total_size() {
                size_t size = 0;
                for (iterator it = queue.begin(); it != queue.end(); it++) {
@@ -245,33 +196,9 @@ private:
                return size;
        }
 
-       MEM_CachePriorityQueue get_priority_queue(void) {
-               MEM_CachePriorityQueue priority_queue;
-               iterator it;
-               int i;
-
-               for (it = queue.begin(), i = 0; it != queue.end(); it++, i++) {
-                       MEM_CacheElementPtr elem = *it;
-                       int priority;
-
-                       /* by default 0 means higherst priority element */
-                       priority = -(queue.size() - i - 1);
-
-                       if (getItemPriority) {
-                               priority = getItemPriority(elem->get()->get_data(), priority);
-                       }
-
-                       elem->set_priority(priority);
-
-                       priority_queue.push(elem);
-               }
-
-               return priority_queue;
-       }
-
-       MEM_CacheQueue queue;
+       std::list<MEM_CacheLimiterHandle<T>*,
+         MEM_Allocator<MEM_CacheLimiterHandle<T> *> > queue;
        MEM_CacheLimiter_DataSize_Func getDataSize;
-       MEM_CacheLimiter_ItemPriority_Func getItemPriority;
 };
 
 #endif // __MEM_CACHELIMITER_H__
index 1ae5e9df1c6e65a377a4be95345343c2f8d01927..4ed692fb55f503c3a428c164a2ac7996b06f60a6 100644 (file)
@@ -31,7 +31,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-
+       
 struct MEM_CacheLimiter_s;
 struct MEM_CacheLimiterHandle_s;
 
@@ -39,111 +39,106 @@ typedef struct MEM_CacheLimiter_s MEM_CacheLimiterC;
 typedef struct MEM_CacheLimiterHandle_s MEM_CacheLimiterHandleC;
 
 /* function used to remove data from memory */
-typedef void (*MEM_CacheLimiter_Destruct_Func)(void*);
+typedef void(*MEM_CacheLimiter_Destruct_Func)(void*);
 
 /* function used to measure stored data element size */
-typedef size_t (*MEM_CacheLimiter_DataSize_Func) (void*);
-
-/* function used to measure priority of item when freeing memory */
-typedef int (*MEM_CacheLimiter_ItemPriority_Func) (void*, int);
+typedef size_t(*MEM_CacheLimiter_DataSize_Func) (void*);
 
 #ifndef __MEM_CACHELIMITER_H__
-void MEM_CacheLimiter_set_maximum(size_t m);
-int MEM_CacheLimiter_get_maximum(void);
+extern void MEM_CacheLimiter_set_maximum(size_t m);
+extern int MEM_CacheLimiter_get_maximum(void);
 #endif /* __MEM_CACHELIMITER_H__ */
-
-/**
- * Create new MEM_CacheLimiter object
+/** 
+ * Create new MEM_CacheLimiter object 
  * managed objects are destructed with the data_destructor
  *
  * @param data_destructor
  * @return A new MEM_CacheLimter object
  */
 
-MEM_CacheLimiterC *new_MEM_CacheLimiter(MEM_CacheLimiter_Destruct_Func data_destructor,
-                                         MEM_CacheLimiter_DataSize_Func data_size);
+extern MEM_CacheLimiterC * new_MEM_CacheLimiter(
+       MEM_CacheLimiter_Destruct_Func data_destructor,
+       MEM_CacheLimiter_DataSize_Func data_size);
 
-/**
+/** 
  * Delete MEM_CacheLimiter
- *
+ * 
  * Frees the memory of the CacheLimiter but does not touch managed objects!
  *
  * @param This "This" pointer
  */
 
-void delete_MEM_CacheLimiter(MEM_CacheLimiterC *This);
+extern void delete_MEM_CacheLimiter(MEM_CacheLimiterC * This);
 
-/**
+/** 
  * Manage object
- *
+ * 
  * @param This "This" pointer, data data object to manage
  * @return CacheLimiterHandle to ref, unref, touch the managed object
  */
+       
+extern MEM_CacheLimiterHandleC * MEM_CacheLimiter_insert(
+       MEM_CacheLimiterC * This, void * data);
 
-MEM_CacheLimiterHandleC *MEM_CacheLimiter_insert(MEM_CacheLimiterC * This, void * data);
-
-/**
+/** 
  * Free objects until memory constraints are satisfied
- *
+ * 
  * @param This "This" pointer
  */
 
-void MEM_CacheLimiter_enforce_limits(MEM_CacheLimiterC *This);
+extern void MEM_CacheLimiter_enforce_limits(MEM_CacheLimiterC * This);
 
-/**
- * Unmanage object previously inserted object.
+/** 
+ * Unmanage object previously inserted object. 
  * Does _not_ delete managed object!
- *
+ * 
  * @param This "This" pointer, handle of object
  */
+       
+extern void MEM_CacheLimiter_unmanage(MEM_CacheLimiterHandleC * handle);
 
-void MEM_CacheLimiter_unmanage(MEM_CacheLimiterHandleC *handle);
 
-
-/**
+/** 
  * Raise priority of object (put it at the tail of the deletion chain)
- *
+ * 
  * @param handle of object
  */
+       
+extern void MEM_CacheLimiter_touch(MEM_CacheLimiterHandleC * handle);
 
-void MEM_CacheLimiter_touch(MEM_CacheLimiterHandleC *handle);
-
-/**
+/** 
  * Increment reference counter. Objects with reference counter != 0 are _not_
  * deleted.
- *
+ * 
  * @param handle of object
  */
+       
+extern void MEM_CacheLimiter_ref(MEM_CacheLimiterHandleC * handle);
 
-void MEM_CacheLimiter_ref(MEM_CacheLimiterHandleC *handle);
-
-/**
+/** 
  * Decrement reference counter. Objects with reference counter != 0 are _not_
  * deleted.
- *
+ * 
  * @param handle of object
  */
+       
+extern void MEM_CacheLimiter_unref(MEM_CacheLimiterHandleC * handle);
 
-void MEM_CacheLimiter_unref(MEM_CacheLimiterHandleC *handle);
-
-/**
+/** 
  * Get reference counter.
- *
+ * 
  * @param This "This" pointer, handle of object
  */
+       
+extern int MEM_CacheLimiter_get_refcount(MEM_CacheLimiterHandleC * handle);
 
-int MEM_CacheLimiter_get_refcount(MEM_CacheLimiterHandleC *handle);
-
-/**
+/** 
  * Get pointer to managed object
- *
+ * 
  * @param handle of object
  */
-
-void * MEM_CacheLimiter_get(MEM_CacheLimiterHandleC *handle);
-
-void MEM_CacheLimiter_ItemPriority_Func_set(MEM_CacheLimiterC *This,
-                                            MEM_CacheLimiter_ItemPriority_Func item_priority_func);
+       
+extern void * MEM_CacheLimiter_get(MEM_CacheLimiterHandleC * handle);
 
 #ifdef __cplusplus
 }
index 81a1ce670aeecbbaa1842d983ef728ac2b91a8b7..cfa6a207e1cf6613172fd8ac7caeaab4c635d4f9 100644 (file)
@@ -31,7 +31,7 @@
 
 static size_t & get_max()
 {
-       static size_t m = 32 * 1024 * 1024;
+       static size_t m = 32*1024*1024;
        return m;
 }
 
@@ -50,7 +50,8 @@ class MEM_CacheLimiterCClass;
 
 typedef MEM_CacheLimiterHandle<MEM_CacheLimiterHandleCClass> handle_t;
 typedef MEM_CacheLimiter<MEM_CacheLimiterHandleCClass> cache_t;
-typedef std::list<MEM_CacheLimiterHandleCClass*, MEM_Allocator<MEM_CacheLimiterHandleCClass* > > list_t;
+typedef std::list<MEM_CacheLimiterHandleCClass*,
+                 MEM_Allocator<MEM_CacheLimiterHandleCClass* > > list_t;
 
 class MEM_CacheLimiterCClass {
 public:
@@ -58,10 +59,11 @@ public:
                : data_destructor(data_destructor_), cache(data_size) {
        }
        ~MEM_CacheLimiterCClass();
-
+       
        handle_t * insert(void * data);
 
-       void destruct(void * data, list_t::iterator it);
+       void destruct(void * data,
+                     list_t::iterator it);
 
        cache_t * get_cache() {
                return &cache;
@@ -70,48 +72,42 @@ private:
        MEM_CacheLimiter_Destruct_Func data_destructor;
 
        MEM_CacheLimiter<MEM_CacheLimiterHandleCClass> cache;
-
+       
        list_t cclass_list;
 };
 
 class MEM_CacheLimiterHandleCClass {
 public:
-       MEM_CacheLimiterHandleCClass(void * data_, MEM_CacheLimiterCClass * parent_) :
-               data(data_),
-               parent(parent_)
-       { }
-
+       MEM_CacheLimiterHandleCClass(void * data_,
+                                    MEM_CacheLimiterCClass * parent_)
+           : data(data_), parent(parent_) { }
        ~MEM_CacheLimiterHandleCClass();
-
        void set_iter(list_t::iterator it_) {
                it = it_;
        }
-
        void set_data(void * data_) {
                data = data_;
        }
-
-       void *get_data() const {
+       void * get_data() const {
                return data;
        }
-
 private:
-       void *data;
-       MEM_CacheLimiterCClass *parent;
+       void * data;
+       MEM_CacheLimiterCClass * parent;
        list_t::iterator it;
 };
 
-handle_t *MEM_CacheLimiterCClass::insert(void * data)
+handle_t * MEM_CacheLimiterCClass::insert(void * data) 
 {
        cclass_list.push_back(new MEM_CacheLimiterHandleCClass(data, this));
        list_t::iterator it = cclass_list.end();
        --it;
        cclass_list.back()->set_iter(it);
-
+       
        return cache.insert(cclass_list.back());
 }
 
-void MEM_CacheLimiterCClass::destruct(void * data, list_t::iterator it)
+void MEM_CacheLimiterCClass::destruct(void * data, list_t::iterator it) 
 {
        data_destructor(data);
        cclass_list.erase(it);
@@ -127,78 +123,77 @@ MEM_CacheLimiterHandleCClass::~MEM_CacheLimiterHandleCClass()
 MEM_CacheLimiterCClass::~MEM_CacheLimiterCClass()
 {
        // should not happen, but don't leak memory in this case...
-       for (list_t::iterator it = cclass_list.begin(); it != cclass_list.end(); it++) {
+       for (list_t::iterator it = cclass_list.begin();
+            it != cclass_list.end(); it++) {
                (*it)->set_data(0);
-
                delete *it;
        }
 }
 
 // ----------------------------------------------------------------------
 
-static inline MEM_CacheLimiterCClass *cast(MEM_CacheLimiterC *l)
+static inline MEM_CacheLimiterCClass* cast(MEM_CacheLimiterC * l)
 {
-       return (MEM_CacheLimiterCClass *) l;
+       return (MEM_CacheLimiterCClass*) l;
 }
 
-static inline handle_t *cast(MEM_CacheLimiterHandleC *l)
+static inline handle_t* cast(MEM_CacheLimiterHandleC * l)
 {
-       return (handle_t *) l;
+       return (handle_t*) l;
 }
 
-MEM_CacheLimiterC *new_MEM_CacheLimiter(MEM_CacheLimiter_Destruct_Func data_destructor,
-                                        MEM_CacheLimiter_DataSize_Func data_size)
+MEM_CacheLimiterC * new_MEM_CacheLimiter(
+       MEM_CacheLimiter_Destruct_Func data_destructor,
+       MEM_CacheLimiter_DataSize_Func data_size)
 {
-       return (MEM_CacheLimiterC *) new MEM_CacheLimiterCClass(data_destructor, data_size);
+       return (MEM_CacheLimiterC*) new MEM_CacheLimiterCClass(
+               data_destructor,
+               data_size);
 }
 
-void delete_MEM_CacheLimiter(MEM_CacheLimiterC *This)
+void delete_MEM_CacheLimiter(MEM_CacheLimiterC * This)
 {
        delete cast(This);
 }
 
-MEM_CacheLimiterHandleC *MEM_CacheLimiter_insert(MEM_CacheLimiterC *This, void *data)
+MEM_CacheLimiterHandleC * MEM_CacheLimiter_insert(
+       MEM_CacheLimiterC * This, void * data)
 {
        return (MEM_CacheLimiterHandleC *) cast(This)->insert(data);
 }
 
-void MEM_CacheLimiter_enforce_limits(MEM_CacheLimiterC *This)
+void MEM_CacheLimiter_enforce_limits(MEM_CacheLimiterC * This)
 {
        cast(This)->get_cache()->enforce_limits();
 }
-
-void MEM_CacheLimiter_unmanage(MEM_CacheLimiterHandleC *handle)
+       
+void MEM_CacheLimiter_unmanage(MEM_CacheLimiterHandleC * handle)
 {
        cast(handle)->unmanage();
 }
-
-void MEM_CacheLimiter_touch(MEM_CacheLimiterHandleC *handle)
+       
+void MEM_CacheLimiter_touch(MEM_CacheLimiterHandleC * handle)
 {
        cast(handle)->touch();
 }
-
-void MEM_CacheLimiter_ref(MEM_CacheLimiterHandleC *handle)
+       
+void MEM_CacheLimiter_ref(MEM_CacheLimiterHandleC * handle)
 {
        cast(handle)->ref();
 }
-
-void MEM_CacheLimiter_unref(MEM_CacheLimiterHandleC *handle)
+       
+void MEM_CacheLimiter_unref(MEM_CacheLimiterHandleC * handle)
 {
        cast(handle)->unref();
 }
 
-int MEM_CacheLimiter_get_refcount(MEM_CacheLimiterHandleC *handle)
+int MEM_CacheLimiter_get_refcount(MEM_CacheLimiterHandleC * handle)
 {
        return cast(handle)->get_refcount();
 }
 
-void *MEM_CacheLimiter_get(MEM_CacheLimiterHandleC *handle)
+       
+void * MEM_CacheLimiter_get(MEM_CacheLimiterHandleC * handle)
 {
        return cast(handle)->get()->get_data();
 }
-
-void MEM_CacheLimiter_ItemPriority_Func_set(MEM_CacheLimiterC *This,
-                                            MEM_CacheLimiter_ItemPriority_Func item_priority_func)
-{
-       cast(This)->get_cache()->set_item_priority_func(item_priority_func);
-}
diff --git a/intern/opencolorio/CMakeLists.txt b/intern/opencolorio/CMakeLists.txt
deleted file mode 100644 (file)
index 3ad2e91..0000000
+++ /dev/null
@@ -1,49 +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.
-#
-# The Original Code is Copyright (C) 2012, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Sergey Sharybin.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
-       .
-       ${OPENCOLORIO_INCLUDE_DIRS}
-)
-
-set(INC_SYS
-
-)
-
-set(SRC
-       ocio_capi.cpp
-       ocio_capi.h
-)
-
-add_definitions(
-)
-
-if(WIN32 AND NOT MINGW)
-       list(APPEND INC
-               ${BOOST_INCLUDE_DIR}
-       )
-endif()
-
-blender_add_lib(bf_intern_opencolorio "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/opencolorio/SConscript b/intern/opencolorio/SConscript
deleted file mode 100644 (file)
index ef814ed..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/python
-
-Import('env')
-
-sources = env.Glob('*.cpp')
-
-incs = '.'
-incs += ' ' + env['BF_OCIO_INC']
-
-if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
-    incs += ' ' + env['BF_BOOST_INC']
-
-env.BlenderLib( 'bf_intern_opencolorio', sources, Split(incs), [], libtype=['extern','player'], priority=[10, 185])
diff --git a/intern/opencolorio/ocio_capi.cpp b/intern/opencolorio/ocio_capi.cpp
deleted file mode 100644 (file)
index 8a14a7e..0000000
+++ /dev/null
@@ -1,415 +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.
- *
- * The Original Code is Copyright (C) 2012 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): Xavier Thomas
- *                 Lukas Toene
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include <iostream>
-
-#include <OpenColorIO/OpenColorIO.h>
-
-
-#define OCIO_CAPI_IMPLEMENTATION
-#include "ocio_capi.h"
-
-ConstConfigRcPtr *OCIO_getCurrentConfig(void)
-{
-       ConstConfigRcPtr *config =  new ConstConfigRcPtr();
-       try {
-               *config = GetCurrentConfig();
-
-               if(*config)
-                       return config;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-void OCIO_setCurrentConfig(const ConstConfigRcPtr *config)
-{
-       try {
-               SetCurrentConfig(*config);
-       }
-       catch (Exception & exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-}
-
-ConstConfigRcPtr *OCIO_configCreateFromEnv(void)
-{
-       ConstConfigRcPtr *config =  new ConstConfigRcPtr();
-
-       try {
-               *config = Config::CreateFromEnv();
-
-               if (*config)
-                       return config;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-
-ConstConfigRcPtr *OCIO_configCreateFromFile(const char *filename)
-{
-       ConstConfigRcPtr *config =  new ConstConfigRcPtr();
-
-       try {
-               *config = Config::CreateFromFile(filename);
-
-               if (*config)
-                       return config;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-void OCIO_configRelease(ConstConfigRcPtr *config)
-{
-       delete config;
-}
-
-int OCIO_configGetNumColorSpaces(ConstConfigRcPtr *config)
-{
-       try {
-               return (*config)->getNumColorSpaces();
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return 0;
-}
-
-const char *OCIO_configGetColorSpaceNameByIndex(ConstConfigRcPtr *config, int index)
-{
-       try {
-               return (*config)->getColorSpaceNameByIndex(index);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-ConstColorSpaceRcPtr *OCIO_configGetColorSpace(ConstConfigRcPtr *config, const char *name)
-{
-       ConstColorSpaceRcPtr *cs =  new ConstColorSpaceRcPtr();
-
-       try {
-               *cs = (*config)->getColorSpace(name);
-
-               if (*cs)
-                       return cs;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-               delete cs;
-       }
-
-       return NULL;
-}
-
-int OCIO_configGetIndexForColorSpace(ConstConfigRcPtr *config, const char *name)
-{
-       try {
-               return (*config)->getIndexForColorSpace(name);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return -1;
-}
-
-const char *OCIO_configGetDefaultDisplay(ConstConfigRcPtr *config)
-{
-       try {
-               return (*config)->getDefaultDisplay();
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-int OCIO_configGetNumDisplays(ConstConfigRcPtr* config)
-{
-       try {
-               return (*config)->getNumDisplays();
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return 0;
-}
-
-const char *OCIO_configGetDisplay(ConstConfigRcPtr *config, int index)
-{
-       try {
-               return (*config)->getDisplay(index);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-const char *OCIO_configGetDefaultView(ConstConfigRcPtr *config, const char *display)
-{
-       try {
-               return (*config)->getDefaultView(display);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-int OCIO_configGetNumViews(ConstConfigRcPtr *config, const char *display)
-{
-       try {
-               return (*config)->getNumViews(display);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return 0;
-}
-
-const char *OCIO_configGetView(ConstConfigRcPtr *config, const char *display, int index)
-{
-       try {
-               return (*config)->getView(display, index);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-const char *OCIO_configGetDisplayColorSpaceName(ConstConfigRcPtr *config, const char *display, const char *view)
-{
-       try {
-               return (*config)->getDisplayColorSpaceName(display, view);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr *cs)
-{
-       delete cs;
-}
-
-ConstProcessorRcPtr *OCIO_configGetProcessorWithNames(ConstConfigRcPtr *config, const char *srcName, const char *dstName)
-{
-       ConstProcessorRcPtr *p =  new ConstProcessorRcPtr();
-
-       try {
-               *p = (*config)->getProcessor(srcName, dstName);
-
-               if (*p)
-                       return p;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return 0;
-}
-
-ConstProcessorRcPtr *OCIO_configGetProcessor(ConstConfigRcPtr *config, ConstTransformRcPtr *transform)
-{
-       ConstProcessorRcPtr *p =  new ConstProcessorRcPtr();
-
-       try {
-               *p = (*config)->getProcessor(*transform);
-
-               if (*p)
-                       return p;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-void OCIO_processorApply(ConstProcessorRcPtr *processor, PackedImageDesc *img)
-{
-       try {
-               (*processor)->apply(*img);
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-}
-
-void OCIO_processorApplyRGB(ConstProcessorRcPtr *processor, float *pixel)
-{
-       (*processor)->applyRGB(pixel);
-}
-
-void OCIO_processorApplyRGBA(ConstProcessorRcPtr *processor, float *pixel)
-{
-       (*processor)->applyRGBA(pixel);
-}
-
-void OCIO_processorRelease(ConstProcessorRcPtr *p)
-{
-       delete p;
-}
-
-const char *OCIO_colorSpaceGetName(ConstColorSpaceRcPtr *cs)
-{
-       return (*cs)->getName();
-}
-
-const char *OCIO_colorSpaceGetFamily(ConstColorSpaceRcPtr *cs)
-{
-       return (*cs)->getFamily();
-}
-
-DisplayTransformRcPtr *OCIO_createDisplayTransform(void)
-{
-       DisplayTransformRcPtr *dt =  new DisplayTransformRcPtr();
-
-       *dt = DisplayTransform::Create();
-
-       return dt;
-}
-
-void OCIO_displayTransformSetInputColorSpaceName(DisplayTransformRcPtr *dt, const char *name)
-{
-       (*dt)->setInputColorSpaceName(name);
-}
-
-void OCIO_displayTransformSetDisplay(DisplayTransformRcPtr *dt, const char *name)
-{
-       (*dt)->setDisplay(name);
-}
-
-void OCIO_displayTransformSetView(DisplayTransformRcPtr *dt, const char *name)
-{
-       (*dt)->setView(name);
-}
-
-void OCIO_displayTransformSetDisplayCC(DisplayTransformRcPtr *dt, ConstTransformRcPtr *t)
-{
-       (*dt)->setDisplayCC(*t);
-}
-
-void OCIO_displayTransformSetLinearCC(DisplayTransformRcPtr *dt, ConstTransformRcPtr *t)
-{
-       (*dt)->setLinearCC(*t);
-}
-
-void OCIO_displayTransformRelease(DisplayTransformRcPtr *dt)
-{
-       delete dt;
-       dt = NULL;
-}
-
-PackedImageDesc *OCIO_createPackedImageDesc(float *data, long width, long height, long numChannels,
-                                                                                       long chanStrideBytes, long xStrideBytes, long yStrideBytes)
-{
-       try {
-               PackedImageDesc *id = new PackedImageDesc(data, width, height, numChannels, chanStrideBytes, xStrideBytes, yStrideBytes);
-
-               return id;
-       }
-       catch (Exception &exception) {
-               std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
-       }
-
-       return NULL;
-}
-
-void OCIO_packedImageDescRelease(PackedImageDesc* id)
-{
-       delete id;
-       id = NULL;
-}
-
-ExponentTransformRcPtr *OCIO_createExponentTransform(void)
-{
-       ExponentTransformRcPtr *et =  new ExponentTransformRcPtr();
-
-       *et = ExponentTransform::Create();
-
-       return et;
-}
-
-void OCIO_exponentTransformSetValue(ExponentTransformRcPtr *et, const float *exponent)
-{
-       (*et)->setValue(exponent);
-}
-
-void OCIO_exponentTransformRelease(ExponentTransformRcPtr *et)
-{
-       delete et;
-}
-
-MatrixTransformRcPtr *OCIO_createMatrixTransform(void)
-{
-       MatrixTransformRcPtr *mt = new MatrixTransformRcPtr();
-
-       *mt = MatrixTransform::Create();
-
-       return mt;
-}
-
-void OCIO_matrixTransformSetValue(MatrixTransformRcPtr *mt, const float *m44, const float *offset4)
-{
-       (*mt)->setValue(m44, offset4);
-}
-
-void OCIO_matrixTransformRelease(MatrixTransformRcPtr *mt)
-{
-       delete mt;
-}
-
-void OCIO_matrixTransformScale(float * m44, float * offset4, const float *scale4f)
-{
-       MatrixTransform::Scale(m44, offset4, scale4f);
-}
diff --git a/intern/opencolorio/ocio_capi.h b/intern/opencolorio/ocio_capi.h
deleted file mode 100644 (file)
index 0f10593..0000000
+++ /dev/null
@@ -1,121 +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.
- *
- * The Original Code is Copyright (C) 2012 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): Xavier Thomas
- *                 Lukas Toene
- *                 Sergey Sharybin
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __OCIO_CAPI_H__
-#define __OCIO_CAPI_H__
-
-
-
-#ifdef __cplusplus
-using namespace OCIO_NAMESPACE;
-extern "C" {
-#endif
-
-#define OCIO_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
-
-
-#ifndef OCIO_CAPI_IMPLEMENTATION
-       #define OCIO_ROLE_SCENE_LINEAR  "scene_linear"
-       #define OCIO_ROLE_COLOR_PICKING "color_picking"
-       #define OCIO_ROLE_TEXTURE_PAINT "texture_paint"
-
-       OCIO_DECLARE_HANDLE(ConstConfigRcPtr);
-       OCIO_DECLARE_HANDLE(ConstColorSpaceRcPtr);
-       OCIO_DECLARE_HANDLE(ConstProcessorRcPtr);
-       OCIO_DECLARE_HANDLE(ConstContextRcPtr);
-       OCIO_DECLARE_HANDLE(PackedImageDesc);
-       OCIO_DECLARE_HANDLE(DisplayTransformRcPtr);
-       OCIO_DECLARE_HANDLE(ConstTransformRcPtr);
-       OCIO_DECLARE_HANDLE(ExponentTransformRcPtr);
-       OCIO_DECLARE_HANDLE(MatrixTransformRcPtr);
-#endif
-
-
-ConstConfigRcPtr *OCIO_getCurrentConfig(void);
-void OCIO_setCurrentConfig(const ConstConfigRcPtr *config);
-
-ConstConfigRcPtr *OCIO_configCreateFromEnv(void);
-ConstConfigRcPtr *OCIO_configCreateFromFile(const char* filename);
-
-void OCIO_configRelease(ConstConfigRcPtr *config);
-
-int OCIO_configGetNumColorSpaces(ConstConfigRcPtr *config);
-const char *OCIO_configGetColorSpaceNameByIndex(ConstConfigRcPtr *config, int index);
-ConstColorSpaceRcPtr *OCIO_configGetColorSpace(ConstConfigRcPtr *config, const char *name);
-int OCIO_configGetIndexForColorSpace(ConstConfigRcPtr *config, const char *name);
-
-void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr *cs);
-
-const char *OCIO_configGetDefaultDisplay(ConstConfigRcPtr *config);
-int         OCIO_configGetNumDisplays(ConstConfigRcPtr *config);
-const char *OCIO_configGetDisplay(ConstConfigRcPtr *config, int index);
-const char *OCIO_configGetDefaultView(ConstConfigRcPtr *config, const char *display);
-int         OCIO_configGetNumViews(ConstConfigRcPtr *config, const char *display);
-const char *OCIO_configGetView(ConstConfigRcPtr *config, const char *display, int index);
-const char *OCIO_configGetDisplayColorSpaceName(ConstConfigRcPtr *config, const char *display, const char *view);
-
-ConstProcessorRcPtr *OCIO_configGetProcessorWithNames(ConstConfigRcPtr *config, const char *srcName, const char *dstName);
-ConstProcessorRcPtr *OCIO_configGetProcessor(ConstConfigRcPtr *config, ConstTransformRcPtr *transform);
-
-void OCIO_processorApply(ConstProcessorRcPtr *processor, PackedImageDesc *img);
-void OCIO_processorApplyRGB(ConstProcessorRcPtr *processor, float *pixel);
-void OCIO_processorApplyRGBA(ConstProcessorRcPtr *processor, float *pixel);
-
-void OCIO_processorRelease(ConstProcessorRcPtr *p);
-
-
-const char *OCIO_colorSpaceGetName(ConstColorSpaceRcPtr *cs);
-const char *OCIO_colorSpaceGetFamily(ConstColorSpaceRcPtr *cs);
-
-DisplayTransformRcPtr *OCIO_createDisplayTransform(void);
-void OCIO_displayTransformSetInputColorSpaceName(DisplayTransformRcPtr *dt, const char *name);
-void OCIO_displayTransformSetDisplay(DisplayTransformRcPtr *dt, const char *name);
-void OCIO_displayTransformSetView(DisplayTransformRcPtr *dt, const char *name);
-void OCIO_displayTransformSetDisplayCC(DisplayTransformRcPtr *dt, ConstTransformRcPtr *et);
-void OCIO_displayTransformSetLinearCC(DisplayTransformRcPtr *dt, ConstTransformRcPtr *et);
-void OCIO_displayTransformRelease(DisplayTransformRcPtr *dt);
-
-PackedImageDesc *OCIO_createPackedImageDesc(float *data, long width, long height, long numChannels,
-                                                                                       long chanStrideBytes, long xStrideBytes, long yStrideBytes);
-
-void OCIO_packedImageDescRelease(PackedImageDesc *p);
-
-ExponentTransformRcPtr *OCIO_createExponentTransform(void);
-void OCIO_exponentTransformSetValue(ExponentTransformRcPtr *et, const float *exponent);
-void OCIO_exponentTransformRelease(ExponentTransformRcPtr *et);
-
-MatrixTransformRcPtr *OCIO_createMatrixTransform(void);
-void OCIO_matrixTransformSetValue(MatrixTransformRcPtr *et, const float *m44, const float *offset4);
-void OCIO_matrixTransformRelease(MatrixTransformRcPtr *mt);
-
-void OCIO_matrixTransformScale(float * m44, float * offset4, const float * scale4);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //OCIO_CAPI_H
index 3e1368d8eb0624276a44393aecee3fb8c04c8882..de6d2c33b7f94a28b07eaab1861ab000c1503486 100644 (file)
@@ -33,8 +33,11 @@ set(INC_SYS
 
 set(SRC
        raskter.c
+       raskter_mt.c
+       raskter_kdtree.c
 
        raskter.h
+       raskter_kdtree.h
 )
 
 blender_add_lib(bf_intern_raskter "${SRC}" "${INC}" "${INC_SYS}")
index b405fde82e8fe25bce69bb593e3d3d540f90981e..7049f7d0ebe499d2947bcb5a24d617f507527074 100644 (file)
 
 #include <stdlib.h>
 #include "raskter.h"
+//#define __PLX__FAKE_AA__
+//#define __PLX_KD_TREE__
+#ifdef __PLX_KD_TREE__
+#include "kdtree.h"
+#endif
+
 
-#define __PLX__FAKE_AA__
-
-/* from BLI_utildefines.h */
-#define MIN2(x, y)      ( (x) < (y) ? (x) : (y) )
-#define MAX2(x, y)      ( (x) > (y) ? (x) : (y) )
-#define ABS(a)          ( (a) < 0 ? (-(a)) : (a) )
-
-struct e_status {
-       int x;
-       int ybeg;
-       int xshift;
-       int xdir;
-       int drift;
-       int drift_inc;
-       int drift_dec;
-       int num;
-       struct e_status *e_next;
-};
-
-struct r_buffer_stats {
-       float *buf;
-       int sizex;
-       int sizey;
-};
-
-struct r_fill_context {
-       struct e_status *all_edges, *possible_edges;
-       struct r_buffer_stats rb;
-};
 
 /*
  * Sort all the edges of the input polygon by Y, then by X, of the "first" vertex encountered.
@@ -69,102 +46,113 @@ struct r_fill_context {
  * just the poly. Since the DEM code could end up being coupled with this, we'll keep it separate
  * for now.
  */
-static void preprocess_all_edges(struct r_fill_context *ctx, struct poly_vert *verts, int num_verts, struct e_status *open_edge)
-{
-       int i;
-       int xbeg;
-       int ybeg;
-       int xend;
-       int yend;
-       int dx;
-       int dy;
-       int temp_pos;
-       int xdist;
-       struct e_status *e_new;
-       struct e_status *next_edge;
-       struct e_status **next_edge_ref;
-       struct poly_vert *v;
-       /* set up pointers */
-       v = verts;
-       ctx->all_edges = NULL;
-       /* loop all verts */
-       for (i = 0; i < num_verts; i++) {
-               /* determine beginnings and endings of edges, linking last vertex to first vertex */
-               xbeg = v[i].x;
-               ybeg = v[i].y;
-               if (i) {
-                       /* we're not at the last vert, so end of the edge is the previous vertex */
-                       xend = v[i - 1].x;
-                       yend = v[i - 1].y;
-               }
-               else {
-                       /* we're at the first vertex, so the "end" of this edge is the last vertex */
-                       xend = v[num_verts - 1].x;
-                       yend = v[num_verts - 1].y;
-               }
-               /* make sure our edges are facing the correct direction */
-               if (ybeg > yend) {
-                       /* flip the Xs */
-                       temp_pos = xbeg;
-                       xbeg = xend;
-                       xend = temp_pos;
-                       /* flip the Ys */
-                       temp_pos = ybeg;
-                       ybeg = yend;
-                       yend = temp_pos;
-               }
-
-               /* calculate y delta */
-               dy = yend - ybeg;
-               /* dont draw horizontal lines directly, they are scanned as part of the edges they connect, so skip em. :) */
-               if (dy) {
-                       /* create the edge and determine it's slope (for incremental line drawing) */
-                       e_new = open_edge++;
-
-                       /* calculate x delta */
-                       dx = xend - xbeg;
-                       if (dx > 0) {
-                               e_new->xdir = 1;
-                               xdist = dx;
-                       }
-                       else {
-                               e_new->xdir = -1;
-                               xdist = -dx;
-                       }
-
-                       e_new->x = xbeg;
-                       e_new->ybeg = ybeg;
-                       e_new->num = dy;
-                       e_new->drift_dec = dy;
-
-                       /* calculate deltas for incremental drawing */
-                       if (dx >= 0) {
-                               e_new->drift = 0;
-                       }
-                       else {
-                               e_new->drift = -dy + 1;
-                       }
-                       if (dy >= xdist) {
-                               e_new->drift_inc = xdist;
-                               e_new->xshift = 0;
-                       }
-                       else {
-                               e_new->drift_inc = xdist % dy;
-                               e_new->xshift = (xdist / dy) * e_new->xdir;
-                       }
-                       next_edge_ref = &ctx->all_edges;
-                       /* link in all the edges, in sorted order */
-                       for (;; ) {
-                               next_edge = *next_edge_ref;
-                               if (!next_edge || (next_edge->ybeg > ybeg) || ((next_edge->ybeg == ybeg) && (next_edge->x >= xbeg))) {
-                                       e_new->e_next = next_edge;
-                                       *next_edge_ref = e_new;
-                                       break;
-                               }
-                               next_edge_ref = &next_edge->e_next;
-                       }
-               }
-       }
+void preprocess_all_edges(struct r_fill_context *ctx, struct poly_vert *verts, int num_verts, struct e_status *open_edge) {
+    int i;
+    int xbeg;
+    int ybeg;
+    int xend;
+    int yend;
+    int dx;
+    int dy;
+    int temp_pos;
+    int xdist;
+    struct e_status *e_new;
+    struct e_status *next_edge;
+    struct e_status **next_edge_ref;
+    struct poly_vert *v;
+    /* set up pointers */
+    v = verts;
+    ctx->all_edges = NULL;
+    /* initialize some boundaries */
+    ctx->rb.xmax = v[0].x;
+    ctx->rb.xmin = v[0].x;
+    ctx->rb.ymax = v[0].y;
+    ctx->rb.ymin = v[0].y;
+    /* loop all verts */
+    for(i = 0; i < num_verts; i++) {
+        /* determine beginnings and endings of edges, linking last vertex to first vertex */
+        xbeg = v[i].x;
+        ybeg = v[i].y;
+        /* keep track of our x and y bounds */
+        if(xbeg >= ctx->rb.xmax) {
+            ctx->rb.xmax = xbeg;
+        } else if(xbeg <= ctx->rb.xmin) {
+            ctx->rb.xmin = xbeg;
+        }
+        if(ybeg >= ctx->rb.ymax) {
+            ctx->rb.ymax= ybeg;
+        } else if(ybeg <= ctx->rb.ymin) {
+            ctx->rb.ymin=ybeg;
+        }
+        if(i) {
+            /* we're not at the last vert, so end of the edge is the previous vertex */
+            xend = v[i - 1].x;
+            yend = v[i - 1].y;
+        } else {
+            /* we're at the first vertex, so the "end" of this edge is the last vertex */
+            xend = v[num_verts - 1].x;
+            yend = v[num_verts - 1].y;
+        }
+        /* make sure our edges are facing the correct direction */
+        if(ybeg > yend) {
+            /* flip the Xs */
+            temp_pos = xbeg;
+            xbeg = xend;
+            xend = temp_pos;
+            /* flip the Ys */
+            temp_pos = ybeg;
+            ybeg = yend;
+            yend = temp_pos;
+        }
+
+        /* calculate y delta */
+        dy = yend - ybeg;
+        /* dont draw horizontal lines directly, they are scanned as part of the edges they connect, so skip em. :) */
+        if(dy) {
+            /* create the edge and determine it's slope (for incremental line drawing) */
+            e_new = open_edge++;
+
+            /* calculate x delta */
+            dx = xend - xbeg;
+            if(dx > 0) {
+                e_new->xdir = 1;
+                xdist = dx;
+            } else {
+                e_new->xdir = -1;
+                xdist = -dx;
+            }
+
+            e_new->x = xbeg;
+            e_new->ybeg = ybeg;
+            e_new->num = dy;
+            e_new->drift_dec = dy;
+
+            /* calculate deltas for incremental drawing */
+            if(dx >= 0) {
+                e_new->drift = 0;
+            } else {
+                e_new->drift = -dy + 1;
+            }
+            if(dy >= xdist) {
+                e_new->drift_inc = xdist;
+                e_new->xshift = 0;
+            } else {
+                e_new->drift_inc = xdist % dy;
+                e_new->xshift = (xdist / dy) * e_new->xdir;
+            }
+            next_edge_ref = &ctx->all_edges;
+            /* link in all the edges, in sorted order */
+            for(;;) {
+                next_edge = *next_edge_ref;
+                if(!next_edge || (next_edge->ybeg > ybeg) || ((next_edge->ybeg == ybeg) && (next_edge->x >= xbeg))) {
+                    e_new->e_next = next_edge;
+                    *next_edge_ref = e_new;
+                    break;
+                }
+                next_edge_ref = &next_edge->e_next;
+            }
+        }
+    }
 }
 
 /*
@@ -172,281 +160,275 @@ static void preprocess_all_edges(struct r_fill_context *ctx, struct poly_vert *v
  * for speed, but waiting on final design choices for curve-data before eliminating data the DEM code will need
  * if it ends up being coupled with this function.
  */
-static int rast_scan_fill(struct r_fill_context *ctx, struct poly_vert *verts, int num_verts, float intensity)
-{
-       int x_curr;                 /* current pixel position in X */
-       int y_curr;                 /* current scan line being drawn */
-       int yp;                     /* y-pixel's position in frame buffer */
-       int swixd = 0;              /* whether or not edges switched position in X */
-       float *cpxl;                /* pixel pointers... */
-       float *mpxl;
-       float *spxl;
-       struct e_status *e_curr;    /* edge pointers... */
-       struct e_status *e_temp;
-       struct e_status *edgbuf;
-       struct e_status **edgec;
-
-
-       /*
-        * If the number of verts specified to render as a polygon is less than 3,
-        * return immediately. Obviously we cant render a poly with sides < 3. The
-        * return for this we set to 1, simply so it can be distinguished from the
-        * next place we could return.
-        * which is a failure to allocate memory.
-        */
-       if (num_verts < 3) {
-               return(1);
-       }
-
-       /*
-        * Try to allocate an edge buffer in memory. needs to be the size of the edge tracking data
-        * multiplied by the number of edges, which is always equal to the number of verts in
-        * a 2D polygon. Here we return 0 to indicate a memory allocation failure, as opposed to a 1 for
-        * the preceeding error, which was a rasterization request on a 2D poly with less than
-        * 3 sides.
-        */
-       if ((edgbuf = (struct e_status *)(malloc(sizeof(struct e_status) * num_verts))) == NULL) {
-               return(0);
-       }
-
-       /*
-        * Do some preprocessing on all edges. This constructs a table structure in memory of all
-        * the edge properties and can "flip" some edges so sorting works correctly.
-        */
-       preprocess_all_edges(ctx, verts, num_verts, edgbuf);
-
-       /* can happen with a zero area mask */
-       if (ctx->all_edges == NULL) {
-               free(edgbuf);
-               return(1);
-       }
-
-       /*
-        * Set the pointer for tracking the edges currently in processing to NULL to make sure
-        * we don't get some crazy value after initialization.
-        */
-       ctx->possible_edges = NULL;
-
-       /*
-        * Loop through all scan lines to be drawn. Since we sorted by Y values during
-        * preprocess_all_edges(), we can already exact values for the lowest and
-        * highest Y values we could possibly need by induction. The preprocessing sorted
-        * out edges by Y position, we can cycle the current edge being processed once
-        * it runs out of Y pixels. When we have no more edges, meaning the current edge
-        * is NULL after setting the "current" edge to be the previous current edge's
-        * "next" edge in the Y sorted edge connection chain, we can stop looping Y values,
-        * since we can't possibly have more scan lines if we ran out of edges. :)
-        *
-        * TODO: This clips Y to the frame buffer, which should be done in the preprocessor, but for now is done here.
-        *       Will get changed once DEM code gets in.
-        */
-       for (y_curr = ctx->all_edges->ybeg; (ctx->all_edges || ctx->possible_edges); y_curr++) {
-
-               /*
-                * Link any edges that start on the current scan line into the list of
-                * edges currently needed to draw at least this, if not several, scan lines.
-                */
-
-               /*
-                * Set the current edge to the beginning of the list of edges to be rasterized
-                * into this scan line.
-                *
-                * We could have lots of edge here, so iterate over all the edges needed. The
-                * preprocess_all_edges() function sorted edges by X within each chunk of Y sorting
-                * so we safely cycle edges to thier own "next" edges in order.
-                *
-                * At each iteration, make sure we still have a non-NULL edge.
-                */
-               for (edgec = &ctx->possible_edges; ctx->all_edges && (ctx->all_edges->ybeg == y_curr); ) {
-                       x_curr = ctx->all_edges->x;                  /* Set current X position. */
-                       for (;; ) {                                  /* Start looping edges. Will break when edges run out. */
-                               e_curr = *edgec;                         /* Set up a current edge pointer. */
-                               if (!e_curr || (e_curr->x >= x_curr)) {  /* If we have an no edge, or we need to skip some X-span, */
-                                       e_temp = ctx->all_edges->e_next;     /* set a temp "next" edge to test. */
-                                       *edgec = ctx->all_edges;             /* Add this edge to the list to be scanned. */
-                                       ctx->all_edges->e_next = e_curr;     /* Set up the next edge. */
-                                       edgec = &ctx->all_edges->e_next;     /* Set our list to the next edge's location in memory. */
-                                       ctx->all_edges = e_temp;             /* Skip the NULL or bad X edge, set pointer to next edge. */
-                                       break;                               /* Stop looping edges (since we ran out or hit empty X span. */
-                               }
-                               else {
-                                       edgec = &e_curr->e_next;             /* Set the pointer to the edge list the "next" edge. */
-                               }
-                       }
-               }
-
-               /*
-                * Determine the current scan line's offset in the pixel buffer based on its Y position.
-                * Basically we just multiply the current scan line's Y value by the number of pixels in each line.
-                */
-               yp = y_curr * ctx->rb.sizex;
-               /*
-                * Set a "scan line pointer" in memory. The location of the buffer plus the row offset.
-                */
-               spxl = ctx->rb.buf + (yp);
-               /*
-                * Set up the current edge to the first (in X) edge. The edges which could possibly be in this
-                * list were determined in the preceeding edge loop above. They were already sorted in X by the
-                * initial processing function.
-                *
-                * At each iteration, test for a NULL edge. Since we'll keep cycling edge's to their own "next" edge
-                * we will eventually hit a NULL when the list runs out.
-                */
-               for (e_curr = ctx->possible_edges; e_curr; e_curr = e_curr->e_next) {
-                       /*
-                        * Calculate a span of pixels to fill on the current scan line.
-                        *
-                        * Set the current pixel pointer by adding the X offset to the scan line's start offset.
-                        * Cycle the current edge the next edge.
-                        * Set the max X value to draw to be one less than the next edge's first pixel. This way we are
-                        * sure not to ever get into a situation where we have overdraw. (drawing the same pixel more than
-                        * one time because it's on a vertex connecting two edges)
-                        *
-                        * Then blast through all the pixels in the span, advancing the pointer and setting the color to white.
-                        *
-                        * TODO: Here we clip to the scan line, this is not efficient, and should be done in the preprocessor,
-                        *       but for now it is done here until the DEM code comes in.
-                        */
-
-                       /* set up xmin and xmax bounds on this scan line */
-                       cpxl = spxl + MAX2(e_curr->x, 0);
-                       e_curr = e_curr->e_next;
-                       mpxl = spxl + MIN2(e_curr->x, ctx->rb.sizex) - 1;
-
-                       if ((y_curr >= 0) && (y_curr < ctx->rb.sizey)) {
-                               /* draw the pixels. */
-                               for(; cpxl <= mpxl; *cpxl++ += intensity);
-                       }
-               }
-
-               /*
-                * Loop through all edges of polygon that could be hit by this scan line,
-                * and figure out their x-intersections with the next scan line.
-                *
-                * Either A.) we wont have any more edges to test, or B.) we just add on the
-                * slope delta computed in preprocessing step. Since this draws non-antialiased
-                * polygons, we dont have fractional positions, so we only move in x-direction
-                * when needed to get all the way to the next pixel over...
-                */
-               for (edgec = &ctx->possible_edges; (e_curr = *edgec); ) {
-                       if (!(--(e_curr->num))) {
-                               *edgec = e_curr->e_next;
-                       }
-                       else {
-                               e_curr->x += e_curr->xshift;
-                               if ((e_curr->drift += e_curr->drift_inc) > 0) {
-                                       e_curr->x += e_curr->xdir;
-                                       e_curr->drift -= e_curr->drift_dec;
-                               }
-                               edgec = &e_curr->e_next;
-                       }
-               }
-               /*
-                * It's possible that some edges may have crossed during the last step, so we'll be sure
-                * that we ALWAYS intersect scan lines in order by shuffling if needed to make all edges
-                * sorted by x-intersection coordinate. We'll always scan through at least once to see if
-                * edges crossed, and if so, we set the 'swixd' flag. If 'swixd' gets set on the initial
-                * pass, then we know we need to sort by x, so then cycle through edges again and perform
-                * the sort.-
-                */
-               if (ctx->possible_edges) {
-                       for (edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
-                               /* if the current edge hits scan line at greater X than the next edge, we need to exchange the edges */
-                               if (e_curr->x > e_curr->e_next->x) {
-                                       *edgec = e_curr->e_next;
-                                       /* exchange the pointers */
-                                       e_temp = e_curr->e_next->e_next;
-                                       e_curr->e_next->e_next = e_curr;
-                                       e_curr->e_next = e_temp;
-                                       /* set flag that we had at least one switch */
-                                       swixd = 1;
-                               }
-                       }
-                       /* if we did have a switch, look for more (there will more if there was one) */
-                       for (;; ) {
-                               /* reset exchange flag so it's only set if we encounter another one */
-                               swixd = 0;
-                               for (edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
-                                       /* again, if current edge hits scan line at higher X than next edge, exchange the edges and set flag */
-                                       if (e_curr->x > e_curr->e_next->x) {
-                                               *edgec = e_curr->e_next;
-                                               /* exchange the pointers */
-                                               e_temp = e_curr->e_next->e_next;
-                                               e_curr->e_next->e_next = e_curr;
-                                               e_curr->e_next = e_temp;
-                                               /* flip the exchanged flag */
-                                               swixd = 1;
-                                       }
-                               }
-                               /* if we had no exchanges, we're done reshuffling the pointers */
-                               if (!swixd) {
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       free(edgbuf);
-       return 1;
+static int rast_scan_fill(struct r_fill_context *ctx, struct poly_vert *verts, int num_verts, float intensity) {
+    int x_curr;                 /* current pixel position in X */
+    int y_curr;                 /* current scan line being drawn */
+    int yp;                     /* y-pixel's position in frame buffer */
+    int swixd = 0;              /* whether or not edges switched position in X */
+    float *cpxl;                /* pixel pointers... */
+    float *mpxl;
+    float *spxl;
+    struct e_status *e_curr;    /* edge pointers... */
+    struct e_status *e_temp;
+    struct e_status *edgbuf;
+    struct e_status **edgec;
+
+
+    /*
+     * If the number of verts specified to render as a polygon is less than 3,
+     * return immediately. Obviously we cant render a poly with sides < 3. The
+     * return for this we set to 1, simply so it can be distinguished from the
+     * next place we could return, /home/guest/blender-svn/soc-2011-tomato/intern/raskter/raskter.
+     * which is a failure to allocate memory.
+     */
+    if(num_verts < 3) {
+        return(1);
+    }
+
+    /*
+     * Try to allocate an edge buffer in memory. needs to be the size of the edge tracking data
+     * multiplied by the number of edges, which is always equal to the number of verts in
+     * a 2D polygon. Here we return 0 to indicate a memory allocation failure, as opposed to a 1 for
+     * the preceeding error, which was a rasterization request on a 2D poly with less than
+     * 3 sides.
+     */
+    if((edgbuf = (struct e_status *)(malloc(sizeof(struct e_status) * num_verts))) == NULL) {
+        return(0);
+    }
+
+    /*
+     * Do some preprocessing on all edges. This constructs a table structure in memory of all
+     * the edge properties and can "flip" some edges so sorting works correctly.
+     */
+    preprocess_all_edges(ctx, verts, num_verts, edgbuf);
+
+    /* can happen with a zero area mask */
+    if (ctx->all_edges == NULL) {
+        free(edgbuf);
+        return(1);
+    }
+    /*
+     * Set the pointer for tracking the edges currently in processing to NULL to make sure
+     * we don't get some crazy value after initialization.
+     */
+    ctx->possible_edges = NULL;
+
+    /*
+     * Loop through all scan lines to be drawn. Since we sorted by Y values during
+     * preprocess_all_edges(), we can already exact values for the lowest and
+     * highest Y values we could possibly need by induction. The preprocessing sorted
+     * out edges by Y position, we can cycle the current edge being processed once
+     * it runs out of Y pixels. When we have no more edges, meaning the current edge
+     * is NULL after setting the "current" edge to be the previous current edge's
+     * "next" edge in the Y sorted edge connection chain, we can stop looping Y values,
+     * since we can't possibly have more scan lines if we ran out of edges. :)
+     *
+     * TODO: This clips Y to the frame buffer, which should be done in the preprocessor, but for now is done here.
+     *       Will get changed once DEM code gets in.
+     */
+    for(y_curr = ctx->all_edges->ybeg; (ctx->all_edges || ctx->possible_edges); y_curr++) {
+
+        /*
+         * Link any edges that start on the current scan line into the list of
+         * edges currently needed to draw at least this, if not several, scan lines.
+         */
+
+        /*
+         * Set the current edge to the beginning of the list of edges to be rasterized
+         * into this scan line.
+         *
+         * We could have lots of edge here, so iterate over all the edges needed. The
+         * preprocess_all_edges() function sorted edges by X within each chunk of Y sorting
+         * so we safely cycle edges to thier own "next" edges in order.
+         *
+         * At each iteration, make sure we still have a non-NULL edge.
+         */
+        for(edgec = &ctx->possible_edges; ctx->all_edges && (ctx->all_edges->ybeg == y_curr);) {
+            x_curr = ctx->all_edges->x;                  /* Set current X position. */
+            for(;;) {                                    /* Start looping edges. Will break when edges run out. */
+                e_curr = *edgec;                         /* Set up a current edge pointer. */
+                if(!e_curr || (e_curr->x >= x_curr)) {   /* If we have an no edge, or we need to skip some X-span, */
+                    e_temp = ctx->all_edges->e_next;     /* set a temp "next" edge to test. */
+                    *edgec = ctx->all_edges;             /* Add this edge to the list to be scanned. */
+                    ctx->all_edges->e_next = e_curr;     /* Set up the next edge. */
+                    edgec = &ctx->all_edges->e_next;     /* Set our list to the next edge's location in memory. */
+                    ctx->all_edges = e_temp;             /* Skip the NULL or bad X edge, set pointer to next edge. */
+                    break;                               /* Stop looping edges (since we ran out or hit empty X span. */
+                } else {
+                    edgec = &e_curr->e_next;             /* Set the pointer to the edge list the "next" edge. */
+                }
+            }
+        }
+
+        /*
+         * Determine the current scan line's offset in the pixel buffer based on its Y position.
+         * Basically we just multiply the current scan line's Y value by the number of pixels in each line.
+         */
+        yp = y_curr * ctx->rb.sizex;
+        /*
+         * Set a "scan line pointer" in memory. The location of the buffer plus the row offset.
+         */
+        spxl = ctx->rb.buf + (yp);
+        /*
+         * Set up the current edge to the first (in X) edge. The edges which could possibly be in this
+         * list were determined in the preceeding edge loop above. They were already sorted in X by the
+         * initial processing function.
+         *
+         * At each iteration, test for a NULL edge. Since we'll keep cycling edge's to their own "next" edge
+         * we will eventually hit a NULL when the list runs out.
+         */
+        for(e_curr = ctx->possible_edges; e_curr; e_curr = e_curr->e_next) {
+            /*
+             * Calculate a span of pixels to fill on the current scan line.
+             *
+             * Set the current pixel pointer by adding the X offset to the scan line's start offset.
+             * Cycle the current edge the next edge.
+             * Set the max X value to draw to be one less than the next edge's first pixel. This way we are
+             * sure not to ever get into a situation where we have overdraw. (drawing the same pixel more than
+             * one time because it's on a vertex connecting two edges)
+             *
+             * Then blast through all the pixels in the span, advancing the pointer and setting the color to white.
+             *
+             * TODO: Here we clip to the scan line, this is not efficient, and should be done in the preprocessor,
+             *       but for now it is done here until the DEM code comes in.
+             */
+
+            /* set up xmin and xmax bounds on this scan line */
+            cpxl = spxl + MAX2(e_curr->x, 0);
+            e_curr = e_curr->e_next;
+            mpxl = spxl + MIN2(e_curr->x, ctx->rb.sizex) - 1;
+
+            if((y_curr >= 0) && (y_curr < ctx->rb.sizey)) {
+                /* draw the pixels. */
+                for(; cpxl <= mpxl; *cpxl++ += intensity);
+            }
+        }
+
+        /*
+         * Loop through all edges of polygon that could be hit by this scan line,
+         * and figure out their x-intersections with the next scan line.
+         *
+         * Either A.) we wont have any more edges to test, or B.) we just add on the
+         * slope delta computed in preprocessing step. Since this draws non-antialiased
+         * polygons, we dont have fractional positions, so we only move in x-direction
+         * when needed to get all the way to the next pixel over...
+         */
+        for(edgec = &ctx->possible_edges; (e_curr = *edgec);) {
+            if(!(--(e_curr->num))) {
+                *edgec = e_curr->e_next;
+            } else {
+                e_curr->x += e_curr->xshift;
+                if((e_curr->drift += e_curr->drift_inc) > 0) {
+                    e_curr->x += e_curr->xdir;
+                    e_curr->drift -= e_curr->drift_dec;
+                }
+                edgec = &e_curr->e_next;
+            }
+        }
+        /*
+         * It's possible that some edges may have crossed during the last step, so we'll be sure
+         * that we ALWAYS intersect scan lines in order by shuffling if needed to make all edges
+         * sorted by x-intersection coordinate. We'll always scan through at least once to see if
+         * edges crossed, and if so, we set the 'swixd' flag. If 'swixd' gets set on the initial
+         * pass, then we know we need to sort by x, so then cycle through edges again and perform
+         * the sort.-
+         */
+        if(ctx->possible_edges) {
+            for(edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
+                /* if the current edge hits scan line at greater X than the next edge, we need to exchange the edges */
+                if(e_curr->x > e_curr->e_next->x) {
+                    *edgec = e_curr->e_next;
+                    /* exchange the pointers */
+                    e_temp = e_curr->e_next->e_next;
+                    e_curr->e_next->e_next = e_curr;
+                    e_curr->e_next = e_temp;
+                    /* set flag that we had at least one switch */
+                    swixd = 1;
+                }
+            }
+            /* if we did have a switch, look for more (there will more if there was one) */
+            for(;;) {
+                /* reset exchange flag so it's only set if we encounter another one */
+                swixd = 0;
+                for(edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
+                    /* again, if current edge hits scan line at higher X than next edge, exchange the edges and set flag */
+                    if(e_curr->x > e_curr->e_next->x) {
+                        *edgec = e_curr->e_next;
+                        /* exchange the pointers */
+                        e_temp = e_curr->e_next->e_next;
+                        e_curr->e_next->e_next = e_curr;
+                        e_curr->e_next = e_temp;
+                        /* flip the exchanged flag */
+                        swixd = 1;
+                    }
+                }
+                /* if we had no exchanges, we're done reshuffling the pointers */
+                if(!swixd) {
+                    break;
+                }
+            }
+        }
+    }
+
+    free(edgbuf);
+    return 1;
 }
 
-int PLX_raskterize(float (*base_verts)[2], int num_base_verts,
-                   float *buf, int buf_x, int buf_y, int do_mask_AA)
-{
-       int subdiv_AA = (do_mask_AA != 0) ? 8 : 0;
-       int i;                                   /* i: Loop counter. */
-       int sAx;
-       int sAy;
-       struct poly_vert *ply;                   /* ply: Pointer to a list of integer buffer-space vertex coordinates. */
-       struct r_fill_context ctx = {0};
-       const float buf_x_f = (float)(buf_x);
-       const float buf_y_f = (float)(buf_y);
-       float div_offset = (1.0f / (float)(subdiv_AA));
-       float div_offset_static = 0.5f * (float)(subdiv_AA) * div_offset;
-       /*
-        * Allocate enough memory for our poly_vert list. It'll be the size of the poly_vert
-        * data structure multiplied by the number of base_verts.
-        *
-        * In the event of a failure to allocate the memory, return 0, so this error can
-        * be distinguished as a memory allocation error.
-        */
-       if ((ply = (struct poly_vert *)(malloc(sizeof(struct poly_vert) * num_base_verts))) == NULL) {
-               return(0);
-       }
-
-       ctx.rb.buf = buf;                            /* Set the output buffer pointer. */
-       ctx.rb.sizex = buf_x;                        /* Set the output buffer size in X. (width) */
-       ctx.rb.sizey = buf_y;                        /* Set the output buffer size in Y. (height) */
-       /*
-        * Loop over all verts passed in to be rasterized. Each vertex's X and Y coordinates are
-        * then converted from normalized screen space (0.0 <= POS <= 1.0) to integer coordinates
-        * in the buffer-space coordinates passed in inside buf_x and buf_y.
-        *
-        * It's worth noting that this function ONLY outputs fully white pixels in a mask. Every pixel
-        * drawn will be 1.0f in value, there is no anti-aliasing.
-        */
-
-       if (!subdiv_AA) {
-               for (i = 0; i < num_base_verts; i++) {                     /* Loop over all base_verts. */
-                       ply[i].x = (int)((base_verts[i][0] * buf_x_f) + 0.5f); /* Range expand normalized X to integer buffer-space X. */
-                       ply[i].y = (int)((base_verts[i][1] * buf_y_f) + 0.5f); /* Range expand normalized Y to integer buffer-space Y. */
-               }
-
-               i = rast_scan_fill(&ctx, ply, num_base_verts, 1.0f);  /* Call our rasterizer, passing in the integer coords for each vert. */
-       }
-       else {
-               for (sAx = 0; sAx < subdiv_AA; sAx++) {
-                       for (sAy = 0; sAy < subdiv_AA; sAy++) {
-                               for (i = 0; i < num_base_verts; i++) {
-                                       ply[i].x = (int)((base_verts[i][0] * buf_x_f) + 0.5f - div_offset_static + (div_offset * (float)(sAx)));
-                                       ply[i].y = (int)((base_verts[i][1] * buf_y_f) + 0.5f - div_offset_static + (div_offset * (float)(sAy)));
-                               }
-                               i = rast_scan_fill(&ctx, ply, num_base_verts, (1.0f / (float)(subdiv_AA * subdiv_AA)));
-                       }
-               }
-       }
-       free(ply);                                      /* Free the memory allocated for the integer coordinate table. */
-       return(i);                                      /* Return the value returned by the rasterizer. */
+int PLX_raskterize(float(*base_verts)[2], int num_base_verts,
+                   float *buf, int buf_x, int buf_y, int do_mask_AA) {
+    int subdiv_AA = (do_mask_AA != 0)? 0:0;
+    int i;                                   /* i: Loop counter. */
+    int sAx;
+    int sAy;
+    struct poly_vert *ply;                   /* ply: Pointer to a list of integer buffer-space vertex coordinates. */
+    struct r_fill_context ctx = {0};
+    const float buf_x_f = (float)(buf_x);
+    const float buf_y_f = (float)(buf_y);
+    float div_offset=(1.0f / (float)(subdiv_AA));
+    float div_offset_static = 0.5f * (float)(subdiv_AA) * div_offset;
+    /*
+     * Allocate enough memory for our poly_vert list. It'll be the size of the poly_vert
+     * data structure multiplied by the number of base_verts.
+     *
+     * In the event of a failure to allocate the memory, return 0, so this error can
+     * be distinguished as a memory allocation error.
+     */
+    if((ply = (struct poly_vert *)(malloc(sizeof(struct poly_vert) * num_base_verts))) == NULL) {
+        return(0);
+    }
+
+    ctx.rb.buf = buf;                            /* Set the output buffer pointer. */
+    ctx.rb.sizex = buf_x;                        /* Set the output buffer size in X. (width) */
+    ctx.rb.sizey = buf_y;                        /* Set the output buffer size in Y. (height) */
+    /*
+     * Loop over all verts passed in to be rasterized. Each vertex's X and Y coordinates are
+     * then converted from normalized screen space (0.0 <= POS <= 1.0) to integer coordinates
+     * in the buffer-space coordinates passed in inside buf_x and buf_y.
+     *
+     * It's worth noting that this function ONLY outputs fully white pixels in a mask. Every pixel
+     * drawn will be 1.0f in value, there is no anti-aliasing.
+     */
+
+    if(!subdiv_AA) {
+        for(i = 0; i < num_base_verts; i++) {                           /* Loop over all base_verts. */
+            ply[i].x = (int)((base_verts[i][0] * buf_x_f) + 0.5f);       /* Range expand normalized X to integer buffer-space X. */
+            ply[i].y = (int)((base_verts[i][1] * buf_y_f) + 0.5f); /* Range expand normalized Y to integer buffer-space Y. */
+        }
+
+        i = rast_scan_fill(&ctx, ply, num_base_verts,1.0f);  /* Call our rasterizer, passing in the integer coords for each vert. */
+    } else {
+        for(sAx=0; sAx < subdiv_AA; sAx++) {
+            for(sAy=0; sAy < subdiv_AA; sAy++) {
+                for(i=0; i < num_base_verts; i++) {
+                    ply[i].x = (int)((base_verts[i][0]*buf_x_f)+0.5f - div_offset_static + (div_offset*(float)(sAx)));
+                    ply[i].y = (int)((base_verts[i][1]*buf_y_f)+0.5f - div_offset_static + (div_offset*(float)(sAy)));
+                }
+                i = rast_scan_fill(&ctx, ply, num_base_verts,(1.0f / (float)(subdiv_AA*subdiv_AA)));
+            }
+        }
+    }
+    free(ply);                                      /* Free the memory allocated for the integer coordinate table. */
+    return(i);                                      /* Return the value returned by the rasterizer. */
 }
 
 /*
@@ -455,911 +437,1087 @@ int PLX_raskterize(float (*base_verts)[2], int num_base_verts,
  * if it ends up being coupled with this function.
  */
 static int rast_scan_feather(struct r_fill_context *ctx,
-                             float (*base_verts_f)[2], int num_base_verts,
-                             struct poly_vert *feather_verts, float(*feather_verts_f)[2], int num_feather_verts)
-{
-       int x_curr;                 /* current pixel position in X */
-       int y_curr;                 /* current scan line being drawn */
-       int yp;                     /* y-pixel's position in frame buffer */
-       int swixd = 0;              /* whether or not edges switched position in X */
-       float *cpxl;                /* pixel pointers... */
-       float *mpxl;
-       float *spxl;
-       struct e_status *e_curr;    /* edge pointers... */
-       struct e_status *e_temp;
-       struct e_status *edgbuf;
-       struct e_status **edgec;
-
-       /* from dem */
-       int a;                          // a = temporary pixel index buffer loop counter
-       float fsz;                        // size of the frame
-       unsigned int rsl;               // long used for finding fast 1.0/sqrt
-       float rsf;                      // float used for finding fast 1.0/sqrt
-       const float rsopf = 1.5f;       // constant float used for finding fast 1.0/sqrt
-
-       //unsigned int gradientFillOffset;
-       float t;
-       float ud;                // ud = unscaled edge distance
-       float dmin;              // dmin = minimun edge distance
-       float odist;                    // odist = current outer edge distance
-       float idist;                    // idist = current inner edge distance
-       float dx;                         // dx = X-delta (used for distance proportion calculation)
-       float dy;                         // dy = Y-delta (used for distance proportion calculation)
-       float xpxw = (1.0f / (float)(ctx->rb.sizex));  // xpxw = normalized pixel width
-       float ypxh = (1.0f / (float)(ctx->rb.sizey));  // ypxh = normalized pixel height
-
-       /*
-        * If the number of verts specified to render as a polygon is less than 3,
-        * return immediately. Obviously we cant render a poly with sides < 3. The
-        * return for this we set to 1, simply so it can be distinguished from the
-        * next place we could return,
-        * which is a failure to allocate memory.
-        */
-       if (num_feather_verts < 3) {
-               return(1);
-       }
-
-       /*
-        * Try to allocate an edge buffer in memory. needs to be the size of the edge tracking data
-        * multiplied by the number of edges, which is always equal to the number of verts in
-        * a 2D polygon. Here we return 0 to indicate a memory allocation failure, as opposed to a 1 for
-        * the preceeding error, which was a rasterization request on a 2D poly with less than
-        * 3 sides.
-        */
-       if ((edgbuf = (struct e_status *)(malloc(sizeof(struct e_status) * num_feather_verts))) == NULL) {
-               return(0);
-       }
-
-       /*
-        * Do some preprocessing on all edges. This constructs a table structure in memory of all
-        * the edge properties and can "flip" some edges so sorting works correctly.
-        */
-       preprocess_all_edges(ctx, feather_verts, num_feather_verts, edgbuf);
-
-       /* can happen with a zero area mask */
-       if (ctx->all_edges == NULL) {
-               free(edgbuf);
-               return(1);
-       }
-
-       /*
-        * Set the pointer for tracking the edges currently in processing to NULL to make sure
-        * we don't get some crazy value after initialization.
-        */
-       ctx->possible_edges = NULL;
-
-       /*
-        * Loop through all scan lines to be drawn. Since we sorted by Y values during
-        * preprocess_all_edges(), we can already exact values for the lowest and
-        * highest Y values we could possibly need by induction. The preprocessing sorted
-        * out edges by Y position, we can cycle the current edge being processed once
-        * it runs out of Y pixels. When we have no more edges, meaning the current edge
-        * is NULL after setting the "current" edge to be the previous current edge's
-        * "next" edge in the Y sorted edge connection chain, we can stop looping Y values,
-        * since we can't possibly have more scan lines if we ran out of edges. :)
-        *
-        * TODO: This clips Y to the frame buffer, which should be done in the preprocessor, but for now is done here.
-        *       Will get changed once DEM code gets in.
-        */
-       for (y_curr = ctx->all_edges->ybeg; (ctx->all_edges || ctx->possible_edges); y_curr++) {
-
-               /*
-                * Link any edges that start on the current scan line into the list of
-                * edges currently needed to draw at least this, if not several, scan lines.
-                */
-
-               /*
-                * Set the current edge to the beginning of the list of edges to be rasterized
-                * into this scan line.
-                *
-                * We could have lots of edge here, so iterate over all the edges needed. The
-                * preprocess_all_edges() function sorted edges by X within each chunk of Y sorting
-                * so we safely cycle edges to thier own "next" edges in order.
-                *
-                * At each iteration, make sure we still have a non-NULL edge.
-                */
-               for (edgec = &ctx->possible_edges; ctx->all_edges && (ctx->all_edges->ybeg == y_curr); ) {
-                       x_curr = ctx->all_edges->x;                  /* Set current X position. */
-                       for (;; ) {                                  /* Start looping edges. Will break when edges run out. */
-                               e_curr = *edgec;                         /* Set up a current edge pointer. */
-                               if (!e_curr || (e_curr->x >= x_curr)) {  /* If we have an no edge, or we need to skip some X-span, */
-                                       e_temp = ctx->all_edges->e_next;     /* set a temp "next" edge to test. */
-                                       *edgec = ctx->all_edges;             /* Add this edge to the list to be scanned. */
-                                       ctx->all_edges->e_next = e_curr;     /* Set up the next edge. */
-                                       edgec = &ctx->all_edges->e_next;     /* Set our list to the next edge's location in memory. */
-                                       ctx->all_edges = e_temp;             /* Skip the NULL or bad X edge, set pointer to next edge. */
-                                       break;                               /* Stop looping edges (since we ran out or hit empty X span. */
-                               }
-                               else {
-                                       edgec = &e_curr->e_next;             /* Set the pointer to the edge list the "next" edge. */
-                               }
-                       }
-               }
-
-               /*
-                * Determine the current scan line's offset in the pixel buffer based on its Y position.
-                * Basically we just multiply the current scan line's Y value by the number of pixels in each line.
-                */
-               yp = y_curr * ctx->rb.sizex;
-               /*
-                * Set a "scan line pointer" in memory. The location of the buffer plus the row offset.
-                */
-               spxl = ctx->rb.buf + (yp);
-               /*
-                * Set up the current edge to the first (in X) edge. The edges which could possibly be in this
-                * list were determined in the preceeding edge loop above. They were already sorted in X by the
-                * initial processing function.
-                *
-                * At each iteration, test for a NULL edge. Since we'll keep cycling edge's to their own "next" edge
-                * we will eventually hit a NULL when the list runs out.
-                */
-               for (e_curr = ctx->possible_edges; e_curr; e_curr = e_curr->e_next) {
-                       /*
-                        * Calculate a span of pixels to fill on the current scan line.
-                        *
-                        * Set the current pixel pointer by adding the X offset to the scan line's start offset.
-                        * Cycle the current edge the next edge.
-                        * Set the max X value to draw to be one less than the next edge's first pixel. This way we are
-                        * sure not to ever get into a situation where we have overdraw. (drawing the same pixel more than
-                        * one time because it's on a vertex connecting two edges)
-                        *
-                        * Then blast through all the pixels in the span, advancing the pointer and setting the color to white.
-                        *
-                        * TODO: Here we clip to the scan line, this is not efficient, and should be done in the preprocessor,
-                        *       but for now it is done here until the DEM code comes in.
-                        */
-
-                       /* set up xmin and xmax bounds on this scan line */
-                       cpxl = spxl + MAX2(e_curr->x, 0);
-                       e_curr = e_curr->e_next;
-                       mpxl = spxl + MIN2(e_curr->x, ctx->rb.sizex) - 1;
-
-                       if ((y_curr >= 0) && (y_curr < ctx->rb.sizey)) {
-                               t = ((float)((cpxl - spxl) % ctx->rb.sizex) + 0.5f) * xpxw;
-                               fsz = ((float)(y_curr) + 0.5f) * ypxh;
-                               /* draw the pixels. */
-                               for (; cpxl <= mpxl; cpxl++, t += xpxw) {
-                                       //do feather check
-                                       // first check that pixel isn't already full, and only operate if it is not
-                                       if (*cpxl < 0.9999f) {
-
-                                               dmin = 2.0f;                        // reset min distance to edge pixel
-                                               for (a = 0; a < num_feather_verts; a++) { // loop through all outer edge buffer pixels
-                                                       dy = t - feather_verts_f[a][0];          // set dx to gradient pixel column - outer edge pixel row
-                                                       dx = fsz - feather_verts_f[a][1];        // set dy to gradient pixel row - outer edge pixel column
-                                                       ud = dx * dx + dy * dy;               // compute sum of squares
-                                                       if (ud < dmin) {                      // if our new sum of squares is less than the current minimum
-                                                               dmin = ud;                        // set a new minimum equal to the new lower value
-                                                       }
-                                               }
-                                               odist = dmin;                    // cast outer min to a float
-                                               rsf = odist * 0.5f;                       //
-                                               rsl = *(unsigned int *)&odist;            // use some peculiar properties of the way bits are stored
-                                               rsl = 0x5f3759df - (rsl >> 1);            // in floats vs. unsigned ints to compute an approximate
-                                               odist = *(float *)&rsl;                   // reciprocal square root
-                                               odist = odist * (rsopf - (rsf * odist * odist));  // -- ** this line can be iterated for more accuracy ** --
-                                               odist = odist * (rsopf - (rsf * odist * odist));
-                                               dmin = 2.0f;                        // reset min distance to edge pixel
-                                               for (a = 0; a < num_base_verts; a++) {    // loop through all inside edge pixels
-                                                       dy = t - base_verts_f[a][0];             // compute delta in Y from gradient pixel to inside edge pixel
-                                                       dx = fsz - base_verts_f[a][1];           // compute delta in X from gradient pixel to inside edge pixel
-                                                       ud = dx * dx + dy * dy;   // compute sum of squares
-                                                       if (ud < dmin) {          // if our new sum of squares is less than the current minimum we've found
-                                                               dmin = ud;            // set a new minimum equal to the new lower value
-                                                       }
-                                               }
-                                               idist = dmin;                    // cast inner min to a float
-                                               rsf = idist * 0.5f;                       //
-                                               rsl = *(unsigned int *)&idist;            //
-                                               rsl = 0x5f3759df - (rsl >> 1);            // see notes above
-                                               idist = *(float *)&rsl;                   //
-                                               idist = idist * (rsopf - (rsf * idist * idist));  //
-                                               idist = idist * (rsopf - (rsf * idist * idist));
-                                               /*
-                                                * Note once again that since we are using reciprocals of distance values our
-                                                * proportion is already the correct intensity, and does not need to be
-                                                * subracted from 1.0 like it would have if we used real distances.
-                                                */
-
-                                               /* set intensity, do the += so overlapping gradients are additive */
-                                               *cpxl = (idist / (idist + odist));
-                                       }
-                               }
-                       }
-               }
-
-               /*
-                * Loop through all edges of polygon that could be hit by this scan line,
-                * and figure out their x-intersections with the next scan line.
-                *
-                * Either A.) we wont have any more edges to test, or B.) we just add on the
-                * slope delta computed in preprocessing step. Since this draws non-antialiased
-                * polygons, we dont have fractional positions, so we only move in x-direction
-                * when needed to get all the way to the next pixel over...
-                */
-               for (edgec = &ctx->possible_edges; (e_curr = *edgec); ) {
-                       if (!(--(e_curr->num))) {
-                               *edgec = e_curr->e_next;
-                       }
-                       else {
-                               e_curr->x += e_curr->xshift;
-                               if ((e_curr->drift += e_curr->drift_inc) > 0) {
-                                       e_curr->x += e_curr->xdir;
-                                       e_curr->drift -= e_curr->drift_dec;
-                               }
-                               edgec = &e_curr->e_next;
-                       }
-               }
-               /*
-                * It's possible that some edges may have crossed during the last step, so we'll be sure
-                * that we ALWAYS intersect scan lines in order by shuffling if needed to make all edges
-                * sorted by x-intersection coordinate. We'll always scan through at least once to see if
-                * edges crossed, and if so, we set the 'swixd' flag. If 'swixd' gets set on the initial
-                * pass, then we know we need to sort by x, so then cycle through edges again and perform
-                * the sort.-
-                */
-               if (ctx->possible_edges) {
-                       for (edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
-                               /* if the current edge hits scan line at greater X than the next edge, we need to exchange the edges */
-                               if (e_curr->x > e_curr->e_next->x) {
-                                       *edgec = e_curr->e_next;
-                                       /* exchange the pointers */
-                                       e_temp = e_curr->e_next->e_next;
-                                       e_curr->e_next->e_next = e_curr;
-                                       e_curr->e_next = e_temp;
-                                       /* set flag that we had at least one switch */
-                                       swixd = 1;
-                               }
-                       }
-                       /* if we did have a switch, look for more (there will more if there was one) */
-                       for (;; ) {
-                               /* reset exchange flag so it's only set if we encounter another one */
-                               swixd = 0;
-                               for (edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
-                                       /* again, if current edge hits scan line at higher X than next edge,
-                                        * exchange the edges and set flag */
-                                       if (e_curr->x > e_curr->e_next->x) {
-                                               *edgec = e_curr->e_next;
-                                               /* exchange the pointers */
-                                               e_temp = e_curr->e_next->e_next;
-                                               e_curr->e_next->e_next = e_curr;
-                                               e_curr->e_next = e_temp;
-                                               /* flip the exchanged flag */
-                                               swixd = 1;
-                                       }
-                               }
-                               /* if we had no exchanges, we're done reshuffling the pointers */
-                               if (!swixd) {
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       free(edgbuf);
-       return 1;
+                             float(*base_verts_f)[2], int num_base_verts,
+                             struct poly_vert *feather_verts, float(*feather_verts_f)[2], int num_feather_verts) {
+    int x_curr;                 /* current pixel position in X */
+    int y_curr;                 /* current scan line being drawn */
+    int yp;                     /* y-pixel's position in frame buffer */
+    int swixd = 0;              /* whether or not edges switched position in X */
+    float *cpxl;                /* pixel pointers... */
+    float *mpxl;
+    float *spxl;
+    struct e_status *e_curr;    /* edge pointers... */
+    struct e_status *e_temp;
+    struct e_status *edgbuf;
+    struct e_status **edgec;
+
+    /* from dem */
+    int a;                          // a = temporary pixel index buffer loop counter
+    float fsz;                        // size of the frame
+    unsigned int rsl;               // long used for finding fast 1.0/sqrt
+    float rsf;                      // float used for finding fast 1.0/sqrt
+    const float rsopf = 1.5f;       // constant float used for finding fast 1.0/sqrt
+
+    //unsigned int gradientFillOffset;
+    float t;
+    float ud;                // ud = unscaled edge distance
+    float dmin;              // dmin = minimun edge distance
+    float odist;                    // odist = current outer edge distance
+    float idist;                    // idist = current inner edge distance
+    float dx;                         // dx = X-delta (used for distance proportion calculation)
+    float dy;                         // dy = Y-delta (used for distance proportion calculation)
+    float xpxw = (1.0f / (float)(ctx->rb.sizex));  // xpxw = normalized pixel width
+    float ypxh = (1.0f / (float)(ctx->rb.sizey));  // ypxh = normalized pixel height
+#ifdef __PLX_KD_TREE__
+    void *res_kdi;
+    void *res_kdo;
+    float clup[2];
+#endif
+
+    /*
+     * If the number of verts specified to render as a polygon is less than 3,
+     * return immediately. Obviously we cant render a poly with sides < 3. The
+     * return for this we set to 1, simply so it can be distinguished from the
+     * next place we could return,
+     * which is a failure to allocate memory.
+     */
+    if(num_feather_verts < 3) {
+        return(1);
+    }
+
+    /*
+     * Try to allocate an edge buffer in memory. needs to be the size of the edge tracking data
+     * multiplied by the number of edges, which is always equal to the number of verts in
+     * a 2D polygon. Here we return 0 to indicate a memory allocation failure, as opposed to a 1 for
+     * the preceeding error, which was a rasterization request on a 2D poly with less than
+     * 3 sides.
+     */
+    if((edgbuf = (struct e_status *)(malloc(sizeof(struct e_status) * num_feather_verts))) == NULL) {
+        return(0);
+    }
+
+    /*
+     * Do some preprocessing on all edges. This constructs a table structure in memory of all
+     * the edge properties and can "flip" some edges so sorting works correctly.
+     */
+    preprocess_all_edges(ctx, feather_verts, num_feather_verts, edgbuf);
+
+    /* can happen with a zero area mask */
+    if (ctx->all_edges == NULL) {
+        free(edgbuf);
+        return(1);
+    }
+
+    /*
+     * Set the pointer for tracking the edges currently in processing to NULL to make sure
+     * we don't get some crazy value after initialization.
+     */
+    ctx->possible_edges = NULL;
+
+    /*
+     * Loop through all scan lines to be drawn. Since we sorted by Y values during
+     * preprocess_all_edges(), we can already exact values for the lowest and
+     * highest Y values we could possibly need by induction. The preprocessing sorted
+     * out edges by Y position, we can cycle the current edge being processed once
+     * it runs out of Y pixels. When we have no more edges, meaning the current edge
+     * is NULL after setting the "current" edge to be the previous current edge's
+     * "next" edge in the Y sorted edge connection chain, we can stop looping Y values,
+     * since we can't possibly have more scan lines if we ran out of edges. :)
+     *
+     * TODO: This clips Y to the frame buffer, which should be done in the preprocessor, but for now is done here.
+     *       Will get changed once DEM code gets in.
+     */
+    for(y_curr = ctx->all_edges->ybeg; (ctx->all_edges || ctx->possible_edges); y_curr++) {
+
+        /*
+         * Link any edges that start on the current scan line into the list of
+         * edges currently needed to draw at least this, if not several, scan lines.
+         */
+
+        /*
+         * Set the current edge to the beginning of the list of edges to be rasterized
+         * into this scan line.
+         *
+         * We could have lots of edge here, so iterate over all the edges needed. The
+         * preprocess_all_edges() function sorted edges by X within each chunk of Y sorting
+         * so we safely cycle edges to thier own "next" edges in order.
+         *
+         * At each iteration, make sure we still have a non-NULL edge.
+         */
+        for(edgec = &ctx->possible_edges; ctx->all_edges && (ctx->all_edges->ybeg == y_curr);) {
+            x_curr = ctx->all_edges->x;                  /* Set current X position. */
+            for(;;) {                                    /* Start looping edges. Will break when edges run out. */
+                e_curr = *edgec;                         /* Set up a current edge pointer. */
+                if(!e_curr || (e_curr->x >= x_curr)) {   /* If we have an no edge, or we need to skip some X-span, */
+                    e_temp = ctx->all_edges->e_next;     /* set a temp "next" edge to test. */
+                    *edgec = ctx->all_edges;             /* Add this edge to the list to be scanned. */
+                    ctx->all_edges->e_next = e_curr;     /* Set up the next edge. */
+                    edgec = &ctx->all_edges->e_next;     /* Set our list to the next edge's location in memory. */
+                    ctx->all_edges = e_temp;             /* Skip the NULL or bad X edge, set pointer to next edge. */
+                    break;                               /* Stop looping edges (since we ran out or hit empty X span. */
+                } else {
+                    edgec = &e_curr->e_next;             /* Set the pointer to the edge list the "next" edge. */
+                }
+            }
+        }
+
+        /*
+         * Determine the current scan line's offset in the pixel buffer based on its Y position.
+         * Basically we just multiply the current scan line's Y value by the number of pixels in each line.
+         */
+        yp = y_curr * ctx->rb.sizex;
+        /*
+         * Set a "scan line pointer" in memory. The location of the buffer plus the row offset.
+         */
+        spxl = ctx->rb.buf + (yp);
+        /*
+         * Set up the current edge to the first (in X) edge. The edges which could possibly be in this
+         * list were determined in the preceeding edge loop above. They were already sorted in X by the
+         * initial processing function.
+         *
+         * At each iteration, test for a NULL edge. Since we'll keep cycling edge's to their own "next" edge
+         * we will eventually hit a NULL when the list runs out.
+         */
+        for(e_curr = ctx->possible_edges; e_curr; e_curr = e_curr->e_next) {
+            /*
+             * Calculate a span of pixels to fill on the current scan line.
+             *
+             * Set the current pixel pointer by adding the X offset to the scan line's start offset.
+             * Cycle the current edge the next edge.
+             * Set the max X value to draw to be one less than the next edge's first pixel. This way we are
+             * sure not to ever get into a situation where we have overdraw. (drawing the same pixel more than
+             * one time because it's on a vertex connecting two edges)
+             *
+             * Then blast through all the pixels in the span, advancing the pointer and setting the color to white.
+             *
+             * TODO: Here we clip to the scan line, this is not efficient, and should be done in the preprocessor,
+             *       but for now it is done here until the DEM code comes in.
+             */
+
+            /* set up xmin and xmax bounds on this scan line */
+            cpxl = spxl + MAX2(e_curr->x, 0);
+            e_curr = e_curr->e_next;
+            mpxl = spxl + MIN2(e_curr->x, ctx->rb.sizex) - 1;
+
+            if((y_curr >= 0) && (y_curr < ctx->rb.sizey)) {
+                t = ((float)((cpxl - spxl) % ctx->rb.sizex) + 0.5f) * xpxw;
+                fsz = ((float)(y_curr) + 0.5f) * ypxh;
+                /* draw the pixels. */
+                for(; cpxl <= mpxl; cpxl++, t += xpxw) {
+                    //do feather check
+                    // first check that pixel isn't already full, and only operate if it is not
+                    if(*cpxl < 0.9999f) {
+#ifndef __PLX_KD_TREE__
+                        dmin = 2.0f;                        // reset min distance to edge pixel
+                        for(a = 0; a < num_feather_verts; a++) {  // loop through all outer edge buffer pixels
+                            dx = t - feather_verts_f[a][0];          // set dx to gradient pixel column - outer edge pixel row
+                            dy = fsz - feather_verts_f[a][1];        // set dy to gradient pixel row - outer edge pixel column
+                            ud = dx * dx + dy * dy;               // compute sum of squares
+                            if(ud < dmin) {                       // if our new sum of squares is less than the current minimum
+                                dmin = ud;                        // set a new minimum equal to the new lower value
+                            }
+                        }
+                        odist = dmin;                    // cast outer min to a float
+                        rsf = odist * 0.5f;                       //
+                        rsl = *(unsigned int *)&odist;            // use some peculiar properties of the way bits are stored
+                        rsl = 0x5f3759df - (rsl >> 1);            // in floats vs. unsigned ints to compute an approximate
+                        odist = *(float *)&rsl;                   // reciprocal square root
+                        odist = odist * (rsopf - (rsf * odist * odist));  // -- ** this line can be iterated for more accuracy ** --
+                        odist = odist * (rsopf - (rsf * odist * odist));
+                        dmin = 2.0f;                        // reset min distance to edge pixel
+                        for(a = 0; a < num_base_verts; a++) {     // loop through all inside edge pixels
+                            dx = t - base_verts_f[a][0];             // compute delta in Y from gradient pixel to inside edge pixel
+                            dy = fsz - base_verts_f[a][1];           // compute delta in X from gradient pixel to inside edge pixel
+                            ud = dx * dx + dy * dy;   // compute sum of squares
+                            if(ud < dmin) {           // if our new sum of squares is less than the current minimum we've found
+                                dmin = ud;            // set a new minimum equal to the new lower value
+                            }
+                        }
+                        idist = dmin;                    // cast inner min to a float
+                        rsf = idist * 0.5f;                       //
+                        rsl = *(unsigned int *)&idist;            //
+                        rsl = 0x5f3759df - (rsl >> 1);            // see notes above
+                        idist = *(float *)&rsl;                   //
+                        idist = idist * (rsopf - (rsf * idist * idist));  //
+                        idist = idist * (rsopf - (rsf * idist * idist));
+                        /*
+                         * Note once again that since we are using reciprocals of distance values our
+                         * proportion is already the correct intensity, and does not need to be
+                         * subracted from 1.0 like it would have if we used real distances.
+                         */
+#else
+                        clup[0]=t;
+                        clup[1]=fsz;
+                        res_kdi=kd_nearestf(ctx->kdi,clup);
+                        res_kdo=kd_nearestf(ctx->kdo,clup);
+                        kd_res_itemf(res_kdi,clup);
+                        dx=t-clup[0];
+                        dy=fsz-clup[1];
+                        idist=dx*dx+dy*dy;
+                        rsf = idist * 0.5f;                       //
+                        rsl = *(unsigned int *)&idist;            //
+                        rsl = 0x5f3759df - (rsl >> 1);            // see notes above
+                        idist = *(float *)&rsl;                   //
+                        idist = idist * (rsopf - (rsf * idist * idist));  //
+                        idist = idist * (rsopf - (rsf * idist * idist));
+                        kd_res_itemf(res_kdo,clup);
+                        dx=t-clup[0];
+                        dy=fsz-clup[1];
+                        odist=dx*dx+dy*dy;
+                        rsf = odist * 0.5f;                       //
+                        rsl = *(unsigned int *)&odist;            // use some peculiar properties of the way bits are stored
+                        rsl = 0x5f3759df - (rsl >> 1);            // in floats vs. unsigned ints to compute an approximate
+                        odist = *(float *)&rsl;                   // reciprocal square root
+                        odist = odist * (rsopf - (rsf * odist * odist));  // -- ** this line can be iterated for more accuracy ** --
+                        odist = odist * (rsopf - (rsf * odist * odist));
+
+#endif
+                        /* set intensity, do the += so overlapping gradients are additive */
+                        *cpxl = (idist / (idist+odist));
+                    }
+                }
+            }
+        }
+
+        /*
+         * Loop through all edges of polygon that could be hit by this scan line,
+         * and figure out their x-intersections with the next scan line.
+         *
+         * Either A.) we wont have any more edges to test, or B.) we just add on the
+         * slope delta computed in preprocessing step. Since this draws non-antialiased
+         * polygons, we dont have fractional positions, so we only move in x-direction
+         * when needed to get all the way to the next pixel over...
+         */
+        for(edgec = &ctx->possible_edges; (e_curr = *edgec);) {
+            if(!(--(e_curr->num))) {
+                *edgec = e_curr->e_next;
+            } else {
+                e_curr->x += e_curr->xshift;
+                if((e_curr->drift += e_curr->drift_inc) > 0) {
+                    e_curr->x += e_curr->xdir;
+                    e_curr->drift -= e_curr->drift_dec;
+                }
+                edgec = &e_curr->e_next;
+            }
+        }
+        /*
+         * It's possible that some edges may have crossed during the last step, so we'll be sure
+         * that we ALWAYS intersect scan lines in order by shuffling if needed to make all edges
+         * sorted by x-intersection coordinate. We'll always scan through at least once to see if
+         * edges crossed, and if so, we set the 'swixd' flag. If 'swixd' gets set on the initial
+         * pass, then we know we need to sort by x, so then cycle through edges again and perform
+         * the sort.-
+         */
+        if(ctx->possible_edges) {
+            for(edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
+                /* if the current edge hits scan line at greater X than the next edge, we need to exchange the edges */
+                if(e_curr->x > e_curr->e_next->x) {
+                    *edgec = e_curr->e_next;
+                    /* exchange the pointers */
+                    e_temp = e_curr->e_next->e_next;
+                    e_curr->e_next->e_next = e_curr;
+                    e_curr->e_next = e_temp;
+                    /* set flag that we had at least one switch */
+                    swixd = 1;
+                }
+            }
+            /* if we did have a switch, look for more (there will more if there was one) */
+            for(;;) {
+                /* reset exchange flag so it's only set if we encounter another one */
+                swixd = 0;
+                for(edgec = &ctx->possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
+                    /* again, if current edge hits scan line at higher X than next edge,
+                     * exchange the edges and set flag */
+                    if(e_curr->x > e_curr->e_next->x) {
+                        *edgec = e_curr->e_next;
+                        /* exchange the pointers */
+                        e_temp = e_curr->e_next->e_next;
+                        e_curr->e_next->e_next = e_curr;
+                        e_curr->e_next = e_temp;
+                        /* flip the exchanged flag */
+                        swixd = 1;
+                    }
+                }
+                /* if we had no exchanges, we're done reshuffling the pointers */
+                if(!swixd) {
+                    break;
+                }
+            }
+        }
+    }
+
+    free(edgbuf);
+    return 1;
 }
 
-int PLX_raskterize_feather(float (*base_verts)[2], int num_base_verts, float (*feather_verts)[2], int num_feather_verts,
-                                                  float *buf, int buf_x, int buf_y) {
-       int i;                            /* i: Loop counter. */
-       struct poly_vert *fe;             /* fe: Pointer to a list of integer buffer-space feather vertex coords. */
-       struct r_fill_context ctx = {0};
-
-       /* for faster multiply */
-       const float buf_x_f = (float)buf_x;
-       const float buf_y_f = (float)buf_y;
-
-       /*
-        * Allocate enough memory for our poly_vert list. It'll be the size of the poly_vert
-        * data structure multiplied by the number of verts.
-        *
-        * In the event of a failure to allocate the memory, return 0, so this error can
-        * be distinguished as a memory allocation error.
-        */
-       if ((fe = (struct poly_vert *)(malloc(sizeof(struct poly_vert) * num_feather_verts))) == NULL) {
-               return(0);
-       }
-
-       /*
-        * Loop over all verts passed in to be rasterized. Each vertex's X and Y coordinates are
-        * then converted from normalized screen space (0.0 <= POS <= 1.0) to integer coordinates
-        * in the buffer-space coordinates passed in inside buf_x and buf_y.
-        *
-        * It's worth noting that this function ONLY outputs fully white pixels in a mask. Every pixel
-        * drawn will be 1.0f in value, there is no anti-aliasing.
-        */
-       for (i = 0; i < num_feather_verts; i++) {            /* Loop over all verts. */
-               fe[i].x = (int)((feather_verts[i][0] * buf_x_f) + 0.5f);  /* Range expand normalized X to integer buffer-space X. */
-               fe[i].y = (int)((feather_verts[i][1] * buf_y_f) + 0.5f);  /* Range expand normalized Y to integer buffer-space Y. */
-       }
-
-       ctx.rb.buf = buf;                            /* Set the output buffer pointer. */
-       ctx.rb.sizex = buf_x;                        /* Set the output buffer size in X. (width) */
-       ctx.rb.sizey = buf_y;                        /* Set the output buffer size in Y. (height) */
-
-       /* Call our rasterizer, passing in the integer coords for each vert. */
-       i = rast_scan_feather(&ctx, base_verts, num_base_verts, fe, feather_verts, num_feather_verts);
-       free(fe);
-       return i;                                   /* Return the value returned by the rasterizer. */
+int PLX_raskterize_feather(float(*base_verts)[2], int num_base_verts, float(*feather_verts)[2], int num_feather_verts,
+                           float *buf, int buf_x, int buf_y) {
+    //void plx_floatsort(float(*f)[2], unsigned int n, int sortby);
+    int i;                            /* i: Loop counter. */
+    struct poly_vert *fe;             /* fe: Pointer to a list of integer buffer-space feather vertex coords. */
+    struct r_fill_context ctx = {0};
+
+    /* for faster multiply */
+    const float buf_x_f = (float)buf_x;
+    const float buf_y_f = (float)buf_y;
+#ifdef __PLX_KD_TREE__
+    ctx.kdi = kd_create(2);
+    ctx.kdo = kd_create(2);
+#endif
+    /*
+     * Allocate enough memory for our poly_vert list. It'll be the size of the poly_vert
+     * data structure multiplied by the number of verts.
+     *
+     * In the event of a failure to allocate the memory, return 0, so this error can
+     * be distinguished as a memory allocation error.
+     */
+    if((fe = (struct poly_vert *)(malloc(sizeof(struct poly_vert) * num_feather_verts))) == NULL) {
+        return(0);
+    }
+
+    /*
+     * Loop over all verts passed in to be rasterized. Each vertex's X and Y coordinates are
+     * then converted from normalized screen space (0.0 <= POS <= 1.0) to integer coordinates
+     * in the buffer-space coordinates passed in inside buf_x and buf_y.
+     *
+     * It's worth noting that this function ONLY outputs fully white pixels in a mask. Every pixel
+     * drawn will be 1.0f in value, there is no anti-aliasing.
+     */
+    for(i = 0; i < num_feather_verts; i++) {             /* Loop over all verts. */
+        fe[i].x = (int)((feather_verts[i][0] * buf_x_f) + 0.5f);  /* Range expand normalized X to integer buffer-space X. */
+        fe[i].y = (int)((feather_verts[i][1] * buf_y_f) + 0.5f);  /* Range expand normalized Y to integer buffer-space Y. */
+#ifdef __PLX_KD_TREE__
+        kd_insertf(ctx.kdo,feather_verts[i],NULL);
+    }
+    for(i=0;i<num_base_verts;i++){
+        kd_insertf(ctx.kdi,base_verts[i],NULL);
+#endif
+    }
+
+    ctx.rb.buf = buf;                            /* Set the output buffer pointer. */
+    ctx.rb.sizex = buf_x;                        /* Set the output buffer size in X. (width) */
+    ctx.rb.sizey = buf_y;                        /* Set the output buffer size in Y. (height) */
+    /* pre-sort the sets of edge verts on y */
+    //plx_floatsort(base_verts,num_base_verts,0);
+    //plx_floatsort(base_verts,num_base_verts,1);
+    //plx_floatsort(feather_verts,num_feather_verts,0);
+    //plx_floatsort(feather_verts,num_feather_verts,1);
+    /* Call our rasterizer, passing in the integer coords for each vert. */
+    i = rast_scan_feather(&ctx, base_verts, num_base_verts, fe, feather_verts, num_feather_verts);
+    free(fe);
+    return i;                                   /* Return the value returned by the rasterizer. */
 }
 
 #ifndef __PLX__FAKE_AA__
 
-static int get_range_expanded_pixel_coord(float normalized_value, int max_value)
-{
-       return (int)((normalized_value * (float)(max_value)) + 0.5f);
+int get_range_expanded_pixel_coord(float normalized_value, int max_value) {
+    return (int)((normalized_value * (float)(max_value)) + 0.5f);
 }
 
-static float get_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y)
-{
-       if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) {
-               return 0.0f;
-       }
-       return buf[(pos_y * buf_y) + buf_x];
+__inline float get_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y) {
+    if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) {
+        return 0.0f;
+    }
+    return buf[(pos_y * buf_x) + pos_x];
 }
 
-static float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, float u, float v)
-{
-       int a;
-       int b;
-       int a_plus_1;
-       int b_plus_1;
-       float prop_u;
-       float prop_v;
-       float inv_prop_u;
-       float inv_prop_v;
-       if(u<0.0f || u>1.0f || v<0.0f || v>1.0f) {
-               return 0.0f;
-       }
-       u = u * (float)(buf_x) - 0.5f;
-       v = v * (float)(buf_y) - 0.5f;
-       a = (int)(u);
-       b = (int)(v);
-       prop_u = u - (float)(a);
-       prop_v = v - (float)(b);
-       inv_prop_u = 1.0f - prop_u;
-       inv_prop_v = 1.0f - prop_v;
-       a_plus_1 = MIN2((buf_x-1),a+1);
-       b_plus_1 = MIN2((buf_y-1),b+1);
-       return (buf[(b * buf_y) + a] * inv_prop_u + buf[(b*buf_y)+(a_plus_1)] * prop_u)*inv_prop_v+(buf[((b_plus_1) * buf_y)+a] * inv_prop_u + buf[((b_plus_1)*buf_y)+(a_plus_1)] * prop_u) * prop_v;
+__inline float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, float u, float v) {
+    int a;
+    int b;
+    int a_plus_1;
+    int b_plus_1;
+    float prop_u;
+    float prop_v;
+    float inv_prop_u;
+    float inv_prop_v;
+    if(u<0.0f || u>1.0f || v<0.0f || v>1.0f) {
+        return 0.0f;
+    }
+    u = u * (float)(buf_x) - 0.5f;
+    v = v * (float)(buf_y) - 0.5f;
+    a = (int)(u);
+    b = (int)(v);
+    prop_u = u - (float)(a);
+    prop_v = v - (float)(b);
+    inv_prop_u = 1.0f - prop_u;
+    inv_prop_v = 1.0f - prop_v;
+    a_plus_1 = MIN2((buf_x-1),a+1);
+    b_plus_1 = MIN2((buf_y-1),b+1);
+    return (buf[(b * buf_x) + a] * inv_prop_u + buf[(b*buf_x)+(a_plus_1)] * prop_u)*inv_prop_v+(buf[((b_plus_1) * buf_x)+a] * inv_prop_u + buf[((b_plus_1)*buf_x)+(a_plus_1)] * prop_u) * prop_v;
 
 }
 
-static void set_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y, float intensity)
-{
-       if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) {
-               return;
-       }
-       buf[(pos_y * buf_y) + buf_x] = intensity;
+__inline void set_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y, float intensity) {
+    if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) {
+        return;
+    }
+    buf[(pos_y * buf_x) + pos_x] = intensity;
 }
 #endif
 
-int PLX_antialias_buffer(float *buf, int buf_x, int buf_y)
-{
+int PLX_antialias_buffer(float *buf, int buf_x, int buf_y) {
 #ifdef __PLX__FAKE_AA__
 #ifdef __PLX_GREY_AA__
-       int i=0;
-       int sz = buf_x * buf_y;
-       for(i=0; i<sz; i++) {
-               buf[i] *= 0.5f;
-       }
+    int i=0;
+    int sz = buf_x * buf_y;
+    for(i=0; i<sz; i++) {
+        buf[i] *= 0.5f;
+    }
 #endif
-       (void)buf_x;
-       (void)buf_y;
-       (void)buf;
-       return 1;
+    (void)buf_x;
+    (void)buf_y;
+    (void)buf;
+    return 1;
 #else
-       /*XXX - TODO: THIS IS NOT FINAL CODE - IT DOES NOT WORK - DO NOT ENABLE IT */
-       const float p0 = 1.0f;
-       const float p1 = 1.0f;
-       const float p2 = 1.0f;
-       const float p3 = 1.0f;
-       const float p4 = 1.0f;
-       const float p5 = 1.5f;
-       const float p6 = 2.0f;
-       const float p7 = 2.0f;
-       const float p8 = 2.0f;
-       const float p9 = 2.0f;
-       const float p10 = 4.0f;
-       const float p11 = 8.0f;
-
-       const float edge_threshold = 0.063f;
-       const float edge_threshold_min = 0.0312f;
-       const float quality_subpix = 1.0f;
-//     int px_x;
-//     int px_y;
-
-       float posM_x,posM_y;
-       float posB_x,posB_y;
-       float posN_x,posN_y;
-       float posP_x,posP_y;
-       float offNP_x,offNP_y;
-       float lumaM;
-       float lumaS;
-       float lumaE;
-       float lumaN;
-       float lumaW;
-       float lumaNW;
-       float lumaSE;
-       float lumaNE;
-       float lumaSW;
-       float lumaNS;
-       float lumaWE;
-       float lumaNESE;
-       float lumaNWNE;
-       float lumaNWSW;
-       float lumaSWSE;
-       float lumaNN;
-       float lumaSS;
-       float lumaEndN;
-       float lumaEndP;
-       float lumaMM;
-       float lumaMLTZero;
-       float subpixNWSWNESE;
-       float subpixRcpRange;
-       float subpixNSWE;
-       float maxSM;
-       float minSM;
-       float maxESM;
-       float minESM;
-       float maxWN;
-       float minWN;
-       float rangeMax;
-       float rangeMin;
-       float rangeMaxScaled;
-       float range;
-       float rangeMaxClamped;
-       float edgeHorz;
-       float edgeVert;
-       float edgeHorz1;
-       float edgeVert1;
-       float edgeHorz2;
-       float edgeVert2;
-       float edgeHorz3;
-       float edgeVert3;
-       float edgeHorz4;
-       float edgeVert4;
-       float lengthSign;
-       float subpixA;
-       float subpixB;
-       float subpixC;
-       float subpixD;
-       float subpixE;
-       float subpixF;
-       float subpixG;
-       float subpixH;
-       float gradientN;
-       float gradientS;
-       float gradient;
-       float gradientScaled;
-       float dstN;
-       float dstP;
-       float dst;
-       float spanLength;
-       float spanLengthRcp;
-       float pixelOffset;
-       float pixelOffsetGood;
-       float pixelOffsetSubpix;
-       int directionN;
-       int goodSpan;
-       int goodSpanN;
-       int goodSpanP;
-       int horzSpan;
-       int earlyExit;
-       int pairN;
-       int doneN;
-       int doneP;
-       int doneNP;
-       int curr_x=0;
-       int curr_y=0;
-       for(curr_y=0; curr_y < buf_y; curr_y++) {
-               for(curr_x=0; curr_x < buf_x; curr_x++) {
-                       posM_x = ((float)(curr_x) + 0.5f) * (1.0f/(float)(buf_x));
-                       posM_y = ((float)(curr_y) + 0.5f) * (1.0f/(float)(buf_y));
-
-                       lumaM = get_pixel_intensity(buf, buf_x, buf_y, curr_x, curr_y);
-                       lumaS = get_pixel_intensity(buf, buf_x, buf_y, curr_x, curr_y - 1);
-                       lumaE = get_pixel_intensity(buf, buf_x, buf_y, curr_x + 1, curr_y);
-                       lumaN = get_pixel_intensity(buf, buf_x, buf_y, curr_x, curr_y + 1);
-                       lumaW = get_pixel_intensity(buf, buf_x, buf_y, curr_x - 1, curr_y);
-
-                       maxSM = MAX2(lumaS, lumaM);
-                       minSM = MIN2(lumaS, lumaM);
-                       maxESM = MAX2(lumaE, maxSM);
-                       minESM = MIN2(lumaE, minSM);
-                       maxWN = MAX2(lumaN, lumaW);
-                       minWN = MIN2(lumaN, lumaW);
-                       rangeMax = MAX2(maxWN, maxESM);
-                       rangeMin = MIN2(minWN, minESM);
-                       rangeMaxScaled = rangeMax * edge_threshold;
-                       range = rangeMax - rangeMin;
-                       rangeMaxClamped = MAX2(edge_threshold_min, rangeMaxScaled);
-
-                       earlyExit = range < rangeMaxClamped ? 1:0;
-                       if(earlyExit) {
-                               set_pixel_intensity(buf, buf_x, buf_y, curr_x, curr_y, lumaM);
-                       }
-
-                       lumaNW = get_pixel_intensity(buf, buf_x, buf_y, curr_x + 1, curr_y - 1);
-                       lumaSE = get_pixel_intensity(buf, buf_x, buf_y, curr_x - 1, curr_y + 1);
-                       lumaNE = get_pixel_intensity(buf, buf_x, buf_y, curr_x + 1, curr_y + 1);
-                       lumaSW = get_pixel_intensity(buf, buf_x, buf_y, curr_x - 1, curr_y - 1);
-
-                       lumaNS = lumaN + lumaS;
-                       lumaWE = lumaW + lumaE;
-                       subpixRcpRange = 1.0f/range;
-                       subpixNSWE = lumaNS + lumaWE;
-                       edgeHorz1 = (-2.0f * lumaM) + lumaNS;
-                       edgeVert1 = (-2.0f * lumaM) + lumaWE;
-
-                       lumaNESE = lumaNE + lumaSE;
-                       lumaNWNE = lumaNW + lumaNE;
-                       edgeHorz2 = (-2.0f * lumaE) + lumaNESE;
-                       edgeVert2 = (-2.0f * lumaN) + lumaNWNE;
-
-                       lumaNWSW = lumaNW + lumaSW;
-                       lumaSWSE = lumaSW + lumaSE;
-                       edgeHorz4 = (ABS(edgeHorz1) * 2.0f) + ABS(edgeHorz2);
-                       edgeVert4 = (ABS(edgeVert1) * 2.0f) + ABS(edgeVert2);
-                       edgeHorz3 = (-2.0f * lumaW) + lumaNWSW;
-                       edgeVert3 = (-2.0f * lumaS) + lumaSWSE;
-                       edgeHorz = ABS(edgeHorz3) + edgeHorz4;
-                       edgeVert = ABS(edgeVert3) + edgeVert4;
-
-                       subpixNWSWNESE = lumaNWSW + lumaNESE;
-                       lengthSign = 1.0f / (float)(buf_x);
-                       horzSpan = edgeHorz >= edgeVert ? 1:0;
-                       subpixA = subpixNSWE * 2.0f + subpixNWSWNESE;
-
-                       if(!horzSpan) {
-                               lumaN = lumaW;
-                               lumaS = lumaE;
-                       }
-                       else {
-                               lengthSign = 1.0f / (float)(buf_y);
-                       }
-                       subpixB = (subpixA * (1.0f/12.0f)) - lumaM;
-
-                       gradientN = lumaN - lumaM;
-                       gradientS = lumaS - lumaM;
-                       lumaNN = lumaN + lumaM;
-                       lumaSS = lumaS + lumaM;
-                       pairN = (ABS(gradientN)) >= (ABS(gradientS)) ? 1:0;
-                       gradient = MAX2(ABS(gradientN), ABS(gradientS));
-                       if(pairN) {
-                               lengthSign = -lengthSign;
-                       }
-                       subpixC = MAX2(MIN2(ABS(subpixB) * subpixRcpRange,1.0f),0.0f);
-
-                       posB_x = posM_x;
-                       posB_y = posM_y;
-                       offNP_x = (!horzSpan) ? 0.0f:(1.0f / (float)(buf_x));
-                       offNP_y = (horzSpan) ? 0.0f:(1.0f / (float)(buf_y));
-                       if(!horzSpan) {
-                               posB_x += lengthSign * 0.5f;
-                       }
-                       else {
-                               posB_y += lengthSign * 0.5f;
-                       }
-
-                       posN_x = posB_x - offNP_x * p0;
-                       posN_y = posB_y - offNP_y * p0;
-                       posP_x = posB_x + offNP_x * p0;
-                       posP_y = posB_y + offNP_y * p0;
-                       subpixD = ((-2.0f)*subpixC) + 3.0f;
-                       //may need bilinear filtered get_pixel_intensity() here...done
-                       lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                       subpixE = subpixC * subpixC;
-                       //may need bilinear filtered get_pixel_intensity() here...done
-                       lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-
-                       if(!pairN) {
-                               lumaNN = lumaSS;
-                       }
-                       gradientScaled = gradient * 1.0f/4.0f;
-                       lumaMM =lumaM - lumaNN * 0.5f;
-                       subpixF = subpixD * subpixE;
-                       lumaMLTZero = lumaMM < 0.0f ? 1:0;
-
-                       lumaEndN -= lumaNN * 0.5f;
-                       lumaEndP -= lumaNN * 0.5f;
-                       doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                       doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                       if(!doneN) {
-                               posN_x -= offNP_x * p1;
-                               posN_y -= offNP_y * p1;
-                       }
-                       doneNP = (!doneN) || (!doneP) ? 1:0;
-                       if(!doneP) {
-                               posP_x += offNP_x * p1;
-                               posP_y += offNP_y * p1;
-                       }
-
-                       if(doneNP) {
-                               if(!doneN) {
-                                       lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posN_x,posN_y);
-                               }
-                               if(!doneP) {
-                                       lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x, posP_y);
-                               }
-                               if(!doneN) {
-                                       lumaEndN = lumaEndN - lumaNN * 0.5;
-                               }
-                               if(!doneP) {
-                                       lumaEndP = lumaEndP - lumaNN * 0.5;
-                               }
-                               doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                               doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                               if(!doneN) {
-                                       posN_x -= offNP_x * p2;
-                                       posN_y -= offNP_y * p2;
-                               }
-                               doneNP = (!doneN) || (!doneP) ? 1:0;
-                               if(!doneP) {
-                                       posP_x += offNP_x * p2;
-                                       posP_y += offNP_y * p2;
-                               }
-                               if(doneNP) {
-                                       if(!doneN) {
-                                               lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                                       }
-                                       if(!doneP) {
-                                               lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-                                       }
-                                       if(!doneN) {
-                                               lumaEndN = lumaEndN - lumaNN * 0.5;
-                                       }
-                                       if(!doneP) {
-                                               lumaEndP = lumaEndP - lumaNN * 0.5;
-                                       }
-                                       doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                                       doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                                       if(!doneN) {
-                                               posN_x -= offNP_x * p3;
-                                               posN_y -= offNP_y * p3;
-                                       }
-                                       doneNP = (!doneN) || (!doneP) ? 1:0;
-                                       if(!doneP) {
-                                               posP_x += offNP_x * p3;
-                                               posP_y += offNP_y * p3;
-                                       }
-                                       if(doneNP) {
-                                               if(!doneN) {
-                                                       lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                                               }
-                                               if(!doneP) {
-                                                       lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-                                               }
-                                               if(!doneN) {
-                                                       lumaEndN = lumaEndN - lumaNN * 0.5;
-                                               }
-                                               if(!doneP) {
-                                                       lumaEndP = lumaEndP - lumaNN * 0.5;
-                                               }
-                                               doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                                               doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                                               if(!doneN) {
-                                                       posN_x -= offNP_x * p4;
-                                                       posN_y -= offNP_y * p4;
-                                               }
-                                               doneNP = (!doneN) || (!doneP) ? 1:0;
-                                               if(!doneP) {
-                                                       posP_x += offNP_x * p4;
-                                                       posP_y += offNP_y * p4;
-                                               }
-                                               if(doneNP) {
-                                                       if(!doneN) {
-                                                               lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                                                       }
-                                                       if(!doneP) {
-                                                               lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-                                                       }
-                                                       if(!doneN) {
-                                                               lumaEndN = lumaEndN - lumaNN * 0.5;
-                                                       }
-                                                       if(!doneP) {
-                                                               lumaEndP = lumaEndP - lumaNN * 0.5;
-                                                       }
-                                                       doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                                                       doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                                                       if(!doneN) {
-                                                               posN_x -= offNP_x * p5;
-                                                               posN_y -= offNP_y * p5;
-                                                       }
-                                                       doneNP = (!doneN) || (!doneP) ? 1:0;
-                                                       if(!doneP) {
-                                                               posP_x += offNP_x * p5;
-                                                               posP_y += offNP_y * p5;
-                                                       }
-                                                       if(doneNP) {
-                                                               if(!doneN) {
-                                                                       lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                                                               }
-                                                               if(!doneP) {
-                                                                       lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-                                                               }
-                                                               if(!doneN) {
-                                                                       lumaEndN = lumaEndN - lumaNN * 0.5;
-                                                               }
-                                                               if(!doneP) {
-                                                                       lumaEndP = lumaEndP - lumaNN * 0.5;
-                                                               }
-                                                               doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                                                               doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                                                               if(!doneN) {
-                                                                       posN_x -= offNP_x * p6;
-                                                                       posN_y -= offNP_y * p6;
-                                                               }
-                                                               doneNP = (!doneN) || (!doneP) ? 1:0;
-                                                               if(!doneP) {
-                                                                       posP_x += offNP_x * p6;
-                                                                       posP_y += offNP_y * p6;
-                                                               }
-                                                               if(doneNP) {
-                                                                       if(!doneN) {
-                                                                               lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                                                                       }
-                                                                       if(!doneP) {
-                                                                               lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-                                                                       }
-                                                                       if(!doneN) {
-                                                                               lumaEndN = lumaEndN - lumaNN * 0.5;
-                                                                       }
-                                                                       if(!doneP) {
-                                                                               lumaEndP = lumaEndP - lumaNN * 0.5;
-                                                                       }
-                                                                       doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                                                                       doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                                                                       if(!doneN) {
-                                                                               posN_x -= offNP_x * p7;
-                                                                               posN_y -= offNP_y * p7;
-                                                                       }
-                                                                       doneNP = (!doneN) || (!doneP) ? 1:0;
-                                                                       if(!doneP) {
-                                                                               posP_x += offNP_x * p7;
-                                                                               posP_y += offNP_y * p7;
-                                                                       }
-                                                                       if(doneNP) {
-                                                                               if(!doneN) {
-                                                                                       lumaEndN = get_pixel_intensity_bilinear(buf, buf_x, buf_y,posN_x,posN_y);
-                                                                               }
-                                                                               if(!doneP) {
-                                                                                       lumaEndP = get_pixel_intensity_bilinear(buf, buf_x, buf_y, posP_x,posP_y);
-                                                                               }
-                                                                               if(!doneN) {
-                                                                                       lumaEndN = lumaEndN - lumaNN * 0.5;
-                                                                               }
-                                                                               if(!doneP) {
-                                                                                       lumaEndP = lumaEndP - lumaNN * 0.5;
-                                                                               }
-                                                                               doneN = (ABS(lumaEndN)) >= gradientScaled ? 1:0;
-                                                                               doneP = (ABS(lumaEndP)) >= gradientScaled ? 1:0;
-                                                                         &nb