~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to intern/cycles/device/device.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2011, Blender Foundation.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License
6
 
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software Foundation,
16
 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
2
 * Copyright 2011-2013 Blender Foundation
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License
17
15
 */
18
16
 
19
17
#include <stdlib.h>
43
41
 
44
42
void Device::pixels_copy_from(device_memory& mem, int y, int w, int h)
45
43
{
46
 
        mem_copy_from(mem, y, w, h, sizeof(uint8_t)*4);
 
44
        if(mem.data_type == TYPE_HALF)
 
45
                mem_copy_from(mem, y, w, h, sizeof(half4));
 
46
        else
 
47
                mem_copy_from(mem, y, w, h, sizeof(uchar4));
47
48
}
48
49
 
49
50
void Device::pixels_free(device_memory& mem)
60
61
                glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
61
62
        }
62
63
 
63
 
        glPixelZoom((float)width/(float)w, (float)height/(float)h);
64
 
        glRasterPos2f(0, dy);
65
 
 
66
 
        uint8_t *pixels = (uint8_t*)rgba.data_pointer;
67
 
 
68
 
        /* for multi devices, this assumes the ineffecient method that we allocate
69
 
         * all pixels on the device even though we only render to a subset */
70
 
        pixels += 4*y*w;
71
 
 
72
 
        glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
73
 
 
74
 
        glRasterPos2f(0.0f, 0.0f);
75
 
        glPixelZoom(1.0f, 1.0f);
 
64
        glColor3f(1.0f, 1.0f, 1.0f);
 
65
 
 
66
        if(rgba.data_type == TYPE_HALF) {
 
67
                /* for multi devices, this assumes the ineffecient method that we allocate
 
68
                 * all pixels on the device even though we only render to a subset */
 
69
                GLhalf *data_pointer = (GLhalf*)rgba.data_pointer;
 
70
                data_pointer += 4*y*w;
 
71
 
 
72
                /* draw half float texture, GLSL shader for display transform assumed to be bound */
 
73
                GLuint texid;
 
74
                glGenTextures(1, &texid);
 
75
                glBindTexture(GL_TEXTURE_2D, texid);
 
76
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGBA, GL_HALF_FLOAT, data_pointer);
 
77
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
78
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
79
 
 
80
                glEnable(GL_TEXTURE_2D);
 
81
 
 
82
                glPushMatrix();
 
83
                glTranslatef(0.0f, (float)dy, 0.0f);
 
84
 
 
85
                glBegin(GL_QUADS);
 
86
                
 
87
                glTexCoord2f(0.0f, 0.0f);
 
88
                glVertex2f(0.0f, 0.0f);
 
89
                glTexCoord2f(1.0f, 0.0f);
 
90
                glVertex2f((float)width, 0.0f);
 
91
                glTexCoord2f(1.0f, 1.0f);
 
92
                glVertex2f((float)width, (float)height);
 
93
                glTexCoord2f(0.0f, 1.0f);
 
94
                glVertex2f(0.0f, (float)height);
 
95
 
 
96
                glEnd();
 
97
 
 
98
                glPopMatrix();
 
99
 
 
100
                glBindTexture(GL_TEXTURE_2D, 0);
 
101
                glDisable(GL_TEXTURE_2D);
 
102
                glDeleteTextures(1, &texid);
 
103
        }
 
104
        else {
 
105
                /* fallback for old graphics cards that don't support GLSL, half float,
 
106
                 * and non-power-of-two textures */
 
107
                glPixelZoom((float)width/(float)w, (float)height/(float)h);
 
108
                glRasterPos2f(0, dy);
 
109
 
 
110
                uint8_t *pixels = (uint8_t*)rgba.data_pointer;
 
111
 
 
112
                pixels += 4*y*w;
 
113
 
 
114
                glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
 
115
 
 
116
                glRasterPos2f(0.0f, 0.0f);
 
117
                glPixelZoom(1.0f, 1.0f);
 
118
        }
76
119
 
77
120
        if(transparent)
78
121
                glDisable(GL_BLEND);