~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/gpu/intern/gpu_extensions.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
#include "GPU_draw.h"
46
46
#include "GPU_extensions.h"
 
47
#include "GPU_simple_shader.h"
47
48
#include "gpu_codegen.h"
48
49
 
49
50
#include <stdlib.h>
78
79
} GPUShaders;
79
80
 
80
81
static struct GPUGlobal {
 
82
        GLint maxtexsize;
81
83
        GLint maxtextures;
82
84
        GLuint currentfb;
83
85
        int glslsupport;
106
108
        GG.extdisabled = 1;
107
109
}
108
110
 
 
111
int GPU_max_texture_size(void)
 
112
{
 
113
        return GG.maxtexsize;
 
114
}
 
115
 
109
116
void GPU_extensions_init(void)
110
117
{
111
118
        GLint r, g, b;
123
130
        if (GLEW_ARB_multitexture)
124
131
                glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures);
125
132
 
 
133
        glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GG.maxtexsize);
 
134
 
126
135
        GG.glslsupport = 1;
127
136
        if (!GLEW_ARB_multitexture) GG.glslsupport = 0;
128
137
        if (!GLEW_ARB_vertex_shader) GG.glslsupport = 0;
205
214
#else
206
215
        GG.os = GPU_OS_UNIX;
207
216
#endif
 
217
 
 
218
        GPU_simple_shaders_init();
208
219
}
209
220
 
210
221
void GPU_extensions_exit(void)
211
222
{
212
223
        gpu_extensions_init = 0;
213
224
        GPU_codegen_exit();
 
225
        GPU_simple_shaders_exit();
214
226
}
215
227
 
216
228
int GPU_glsl_support(void)
389
401
 
390
402
                if (fpixels) {
391
403
                        glTexSubImage1D(tex->target, 0, 0, w, format, type,
392
 
                                pixels? pixels: fpixels);
 
404
                                pixels ? pixels : fpixels);
393
405
 
394
406
                        if (tex->w > w)
395
407
                                GPU_glTexSubImageEmpty(tex->target, format, w, 0,
398
410
        }
399
411
        else {
400
412
                glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0,
401
 
                        format, type, NULL);
 
413
                             format, type, NULL);
402
414
 
403
415
                if (fpixels) {
404
416
                        glTexSubImage2D(tex->target, 0, 0, 0, w, h,
405
 
                                format, type, pixels? pixels: fpixels);
 
417
                                format, type, pixels ? pixels : fpixels);
406
418
 
407
419
                        if (tex->w > w)
408
420
                                GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h);
673
685
                /* Now we tweak some of the settings */
674
686
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
675
687
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
676
 
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, size, size, 0, GL_RG, GL_FLOAT, 0);
 
688
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, size, size, 0, GL_RG, GL_FLOAT, NULL);
677
689
 
678
690
                GPU_texture_unbind(tex);
679
691
        }
888
900
void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, int w, int h)
889
901
{
890
902
        /* push attributes */
891
 
        glPushAttrib(GL_ENABLE_BIT);
892
 
        glPushAttrib(GL_VIEWPORT_BIT);
 
903
        glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT);
893
904
        glDisable(GL_SCISSOR_TEST);
894
905
 
895
906
        /* bind framebuffer */
901
912
 
902
913
        glMatrixMode(GL_PROJECTION);
903
914
        glPushMatrix();
904
 
        glLoadIdentity();
905
915
        glMatrixMode(GL_MODELVIEW);
906
916
        glPushMatrix();
907
 
        glLoadIdentity();
908
917
}
909
918
 
910
919
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex))
917
926
 
918
927
        /* restore attributes */
919
928
        glPopAttrib();
920
 
        glPopAttrib();
921
929
        glEnable(GL_SCISSOR_TEST);
922
930
}
923
931
 
1006
1014
        glTexCoord2d(0, 1); glVertex2f(1, -1);
1007
1015
        glEnd();
1008
1016
 
1009
 
        GPU_shader_unbind(blur_shader);
 
1017
        GPU_shader_unbind();
1010
1018
}
1011
1019
 
1012
1020
/* GPUOffScreen */
1092
1100
        glReadPixels(0, 0, ofs->w, ofs->h, GL_RGBA, type, pixels);
1093
1101
}
1094
1102
 
 
1103
int GPU_offscreen_width(GPUOffScreen *ofs)
 
1104
{
 
1105
        return ofs->w;
 
1106
}
 
1107
 
 
1108
int GPU_offscreen_height(GPUOffScreen *ofs)
 
1109
{
 
1110
        return ofs->h;
 
1111
}
 
1112
 
1095
1113
/* GPUShader */
1096
1114
 
1097
1115
struct GPUShader {
1124
1142
        fprintf(stderr, "%s\n", log);
1125
1143
}
1126
1144
 
1127
 
GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPUShader *lib,*/ const char *libcode)
 
1145
static const char *gpu_shader_standard_extensions(void)
 
1146
{
 
1147
        /* need this extensions for high quality bump mapping */
 
1148
        if (GPU_bicubic_bump_support()) {
 
1149
                return "#version 130\n"
 
1150
                       "#extension GL_ARB_texture_query_lod: enable\n"
 
1151
                       "#define BUMP_BICUBIC\n";
 
1152
        }
 
1153
 
 
1154
        return "";
 
1155
}
 
1156
 
 
1157
static const char *gpu_shader_standard_defines(void)
 
1158
{
 
1159
        /* some useful defines to detect GPU type */
 
1160
        if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY))
 
1161
                return "#define GPU_ATI\n";
 
1162
        else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY))
 
1163
                return "#define GPU_NVIDIA\n";
 
1164
        else if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY))
 
1165
                return "#define GPU_INTEL\n";
 
1166
        
 
1167
        return "";
 
1168
}
 
1169
 
 
1170
GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines)
1128
1171
{
1129
1172
        GLint status;
1130
1173
        GLcharARB log[5000];
1131
 
        const char *fragsource[2];
1132
1174
        GLsizei length = 0;
1133
 
        GLint count;
1134
1175
        GPUShader *shader;
1135
1176
 
1136
1177
        if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
1154
1195
        }
1155
1196
 
1156
1197
        if (vertexcode) {
 
1198
                const char *source[4];
 
1199
                int num_source = 0;
 
1200
 
 
1201
                source[num_source++] = gpu_shader_standard_extensions();
 
1202
                source[num_source++] = gpu_shader_standard_defines();
 
1203
 
 
1204
                if (defines) source[num_source++] = defines;
 
1205
                if (vertexcode) source[num_source++] = vertexcode;
 
1206
 
1157
1207
                glAttachObjectARB(shader->object, shader->vertex);
1158
 
                glShaderSourceARB(shader->vertex, 1, (const char**)&vertexcode, NULL);
 
1208
                glShaderSourceARB(shader->vertex, num_source, source, NULL);
1159
1209
 
1160
1210
                glCompileShaderARB(shader->vertex);
1161
1211
                glGetObjectParameterivARB(shader->vertex, GL_OBJECT_COMPILE_STATUS_ARB, &status);
1170
1220
        }
1171
1221
 
1172
1222
        if (fragcode) {
1173
 
                count = 0;
1174
 
                if (libcode) fragsource[count++] = libcode;
1175
 
                if (fragcode) fragsource[count++] = fragcode;
 
1223
                const char *source[5];
 
1224
                int num_source = 0;
 
1225
 
 
1226
                source[num_source++] = gpu_shader_standard_extensions();
 
1227
                source[num_source++] = gpu_shader_standard_defines();
 
1228
 
 
1229
                if (defines) source[num_source++] = defines;
 
1230
                if (libcode) source[num_source++] = libcode;
 
1231
                if (fragcode) source[num_source++] = fragcode;
1176
1232
 
1177
1233
                glAttachObjectARB(shader->object, shader->fragment);
1178
 
                glShaderSourceARB(shader->fragment, count, fragsource, NULL);
 
1234
                glShaderSourceARB(shader->fragment, num_source, source, NULL);
1179
1235
 
1180
1236
                glCompileShaderARB(shader->fragment);
1181
1237
                glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status);
1254
1310
        GPU_print_error("Post Shader Bind");
1255
1311
}
1256
1312
 
1257
 
void GPU_shader_unbind(GPUShader *UNUSED(shader))
 
1313
void GPU_shader_unbind(void)
1258
1314
{
1259
1315
        GPU_print_error("Pre Shader Unbind");
1260
1316
        glUseProgramObjectARB(0);
1296
1352
        GPU_print_error("Post Uniform Vector");
1297
1353
}
1298
1354
 
 
1355
void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
 
1356
{
 
1357
        if (location == -1)
 
1358
                return;
 
1359
 
 
1360
        GPU_print_error("Pre Uniform Int");
 
1361
        glUniform1iARB(location, value);
 
1362
        GPU_print_error("Post Uniform Int");
 
1363
}
 
1364
 
1299
1365
void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex)
1300
1366
{
1301
1367
        GLenum arbnumber;
1344
1410
        switch (shader) {
1345
1411
                case GPU_SHADER_VSM_STORE:
1346
1412
                        if (!GG.shaders.vsm_store)
1347
 
                                GG.shaders.vsm_store = GPU_shader_create(datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL);
 
1413
                                GG.shaders.vsm_store = GPU_shader_create(datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL, NULL);
1348
1414
                        retval = GG.shaders.vsm_store;
1349
1415
                        break;
1350
1416
                case GPU_SHADER_SEP_GAUSSIAN_BLUR:
1351
1417
                        if (!GG.shaders.sep_gaussian_blur)
1352
 
                                GG.shaders.sep_gaussian_blur = GPU_shader_create(datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL);
 
1418
                                GG.shaders.sep_gaussian_blur = GPU_shader_create(datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL, NULL);
1353
1419
                        retval = GG.shaders.sep_gaussian_blur;
1354
1420
                        break;
1355
1421
        }