2
* Copyright 2011, Blender Foundation.
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.
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.
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
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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
19
17
#include <stdlib.h>
44
42
void Device::pixels_copy_from(device_memory& mem, int y, int w, int h)
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));
47
mem_copy_from(mem, y, w, h, sizeof(uchar4));
49
50
void Device::pixels_free(device_memory& mem)
60
61
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
63
glPixelZoom((float)width/(float)w, (float)height/(float)h);
66
uint8_t *pixels = (uint8_t*)rgba.data_pointer;
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 */
72
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
74
glRasterPos2f(0.0f, 0.0f);
75
glPixelZoom(1.0f, 1.0f);
64
glColor3f(1.0f, 1.0f, 1.0f);
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;
72
/* draw half float texture, GLSL shader for display transform assumed to be bound */
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);
80
glEnable(GL_TEXTURE_2D);
83
glTranslatef(0.0f, (float)dy, 0.0f);
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);
100
glBindTexture(GL_TEXTURE_2D, 0);
101
glDisable(GL_TEXTURE_2D);
102
glDeleteTextures(1, &texid);
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);
110
uint8_t *pixels = (uint8_t*)rgba.data_pointer;
114
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
116
glRasterPos2f(0.0f, 0.0f);
117
glPixelZoom(1.0f, 1.0f);
78
121
glDisable(GL_BLEND);