Cycles: some small code refactoring related to buffer parameters.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Dec 2011 13:48:35 +0000 (13:48 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Dec 2011 13:48:35 +0000 (13:48 +0000)
intern/cycles/render/buffers.h
intern/cycles/render/session.cpp
intern/cycles/render/tile.cpp
intern/cycles/render/tile.h

index 66bd03c889317f1c1f79b9035c8bf24d23d6df53..f4a9b37c09ba4f1133bb1604fce79b657470c4ba 100644 (file)
@@ -56,6 +56,12 @@ public:
                full_height = 0;
        }
 
+       void get_offset_stride(int& offset, int& stride)
+       {
+               offset = -(full_x + full_y*width);
+               stride = width;
+       }
+
        bool modified(const BufferParams& params)
        {
                return !(full_x == params.full_x
index 26c4dbfbb7a7066e2819ff1b6b9970561a0f2409..be2e493dc7f405860d59c94b3a8a8620e2a2e4c4 100644 (file)
@@ -515,10 +515,8 @@ void Session::update_scene()
           knows nothing about progressive or cropped rendering, it just gets the
           image dimensions passed in */
        Camera *cam = scene->camera;
-       float progressive_x = tile_manager.state.width/(float)tile_manager.params.width;
-       float progressive_y = tile_manager.state.height/(float)tile_manager.params.height;
-       int width = tile_manager.params.full_width*progressive_x;
-       int height = tile_manager.params.full_height*progressive_y;
+       int width = tile_manager.state.buffer.full_width;
+       int height = tile_manager.state.buffer.full_height;
 
        if(width != cam->width || height != cam->height) {
                cam->width = width;
@@ -574,16 +572,15 @@ void Session::path_trace(Tile& tile)
        /* add path trace task */
        DeviceTask task(DeviceTask::PATH_TRACE);
 
-       task.x = tile_manager.state.full_x + tile.x;
-       task.y = tile_manager.state.full_y + tile.y;
+       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;
-       task.offset = -(tile_manager.state.full_x + tile_manager.state.full_y*tile_manager.state.width);
-       task.stride = tile_manager.state.width;
+       tile_manager.state.buffer.get_offset_stride(task.offset, task.stride);
 
        device->task_add(task);
 }
@@ -593,16 +590,15 @@ void Session::tonemap()
        /* add tonemap task */
        DeviceTask task(DeviceTask::TONEMAP);
 
-       task.x = tile_manager.state.full_x;
-       task.y = tile_manager.state.full_y;
-       task.w = tile_manager.state.width;
-       task.h = tile_manager.state.height;
+       task.x = tile_manager.state.buffer.full_x;
+       task.y = tile_manager.state.buffer.full_y;
+       task.w = tile_manager.state.buffer.width;
+       task.h = tile_manager.state.buffer.height;
        task.rgba = display->rgba.device_pointer;
        task.buffer = buffers->buffer.device_pointer;
        task.sample = tile_manager.state.sample;
        task.resolution = tile_manager.state.resolution;
-       task.offset = -(tile_manager.state.full_x + tile_manager.state.full_y*tile_manager.state.width);
-       task.stride = tile_manager.state.width;
+       tile_manager.state.buffer.get_offset_stride(task.offset, task.stride);
 
        if(task.w > 0 && task.h > 0) {
                device->task_add(task);
index b118a7ba4781a276fe24ba480a72bdc688209a0c..40833e5b08bb4dcc0c5185f4770c4e76084002e8 100644 (file)
@@ -55,10 +55,7 @@ void TileManager::reset(BufferParams& params_, int samples_)
 
        samples = samples_;
 
-       state.full_x = 0;
-       state.full_y = 0;
-       state.width = 0;
-       state.height = 0;
+       state.buffer = BufferParams();
        state.sample = -1;
        state.resolution = start_resolution;
        state.tiles.clear();
@@ -92,10 +89,13 @@ void TileManager::set_tiles()
                }
        }
 
-       state.full_x = params.full_x/resolution;
-       state.full_y = params.full_y/resolution;
-       state.width = image_w;
-       state.height = image_h;
+       state.buffer.width = image_w;
+       state.buffer.height = image_h;
+
+       state.buffer.full_x = params.full_x/resolution;
+       state.buffer.full_y = params.full_y/resolution;
+       state.buffer.full_width = max(1, params.full_width/resolution);
+       state.buffer.full_height = max(1, params.full_height/resolution);
 }
 
 bool TileManager::done()
index 76863d23498935abcf6b773925b626a2a04cd9c6..b6e610c8d90247976fa658b7a33aff2cee18bd55 100644 (file)
@@ -41,11 +41,9 @@ public:
 class TileManager {
 public:
        BufferParams params;
+
        struct State {
-               int full_x;
-               int full_y;
-               int width;
-               int height;
+               BufferParams buffer;
                int sample;
                int resolution;
                list<Tile> tiles;