Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_shader.c
| Show First 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | GPUShader *GPU_shader_create(const char *vertexcode, | ||||
| return GPU_shader_create_ex(vertexcode, | return GPU_shader_create_ex(vertexcode, | ||||
| fragcode, | fragcode, | ||||
| geocode, | geocode, | ||||
| libcode, | libcode, | ||||
| defines, | defines, | ||||
| GPU_SHADER_FLAGS_NONE); | GPU_SHADER_FLAGS_NONE); | ||||
| } | } | ||||
| static void gpu_dump_shader(const char **code, const int num_shaders) | |||||
| { | |||||
| const char *foldername = "/tmp/"; | |||||
| static int i = 0; | |||||
| char filename[512] = {'\0'}; | |||||
| sprintf(filename, "%s/%04d.shader", foldername, i++); | |||||
| FILE *f = fopen(filename, "w"); | |||||
| if (f == NULL) { | |||||
| printf("Error writing to file: %s\n", filename); | |||||
| } | |||||
| for (int j = 0; j < num_shaders; j++) { | |||||
| fprintf(f, "%s", code[j]); | |||||
| } | |||||
| fclose(f); | |||||
| } | |||||
| GPUShader *GPU_shader_create_ex(const char *vertexcode, | GPUShader *GPU_shader_create_ex(const char *vertexcode, | ||||
| const char *fragcode, | const char *fragcode, | ||||
| const char *geocode, | const char *geocode, | ||||
| const char *libcode, | const char *libcode, | ||||
| const char *defines, | const char *defines, | ||||
| const int flags) | const int flags) | ||||
| { | { | ||||
| #ifdef WITH_OPENSUBDIV | #ifdef WITH_OPENSUBDIV | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (vertexcode) { | ||||
| source[num_source++] = gpu_shader_version(); | source[num_source++] = gpu_shader_version(); | ||||
| source[num_source++] = standard_extensions; | source[num_source++] = standard_extensions; | ||||
| source[num_source++] = standard_defines; | source[num_source++] = standard_defines; | ||||
| if (defines) source[num_source++] = defines; | if (defines) source[num_source++] = defines; | ||||
| source[num_source++] = vertexcode; | source[num_source++] = vertexcode; | ||||
| //gpu_dump_shader(source, num_source); | |||||
| glAttachShader(shader->program, shader->vertex); | glAttachShader(shader->program, shader->vertex); | ||||
| glShaderSource(shader->vertex, num_source, source, NULL); | glShaderSource(shader->vertex, num_source, source, NULL); | ||||
| glCompileShader(shader->vertex); | glCompileShader(shader->vertex); | ||||
| glGetShaderiv(shader->vertex, GL_COMPILE_STATUS, &status); | glGetShaderiv(shader->vertex, GL_COMPILE_STATUS, &status); | ||||
| if (!status) { | if (!status) { | ||||
| glGetShaderInfoLog(shader->vertex, sizeof(log), &length, log); | glGetShaderInfoLog(shader->vertex, sizeof(log), &length, log); | ||||
| Show All 23 Lines | if (use_opensubdiv) { | ||||
| "#endif\n"; | "#endif\n"; | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (defines) source[num_source++] = defines; | if (defines) source[num_source++] = defines; | ||||
| if (libcode) source[num_source++] = libcode; | if (libcode) source[num_source++] = libcode; | ||||
| source[num_source++] = fragcode; | source[num_source++] = fragcode; | ||||
| gpu_dump_shader(source, num_source); | |||||
| glAttachShader(shader->program, shader->fragment); | glAttachShader(shader->program, shader->fragment); | ||||
| glShaderSource(shader->fragment, num_source, source, NULL); | glShaderSource(shader->fragment, num_source, source, NULL); | ||||
| glCompileShader(shader->fragment); | glCompileShader(shader->fragment); | ||||
| glGetShaderiv(shader->fragment, GL_COMPILE_STATUS, &status); | glGetShaderiv(shader->fragment, GL_COMPILE_STATUS, &status); | ||||
| if (!status) { | if (!status) { | ||||
| glGetShaderInfoLog(shader->fragment, sizeof(log), &length, log); | glGetShaderInfoLog(shader->fragment, sizeof(log), &length, log); | ||||
| Show All 10 Lines | if (geocode) { | ||||
| source[num_source++] = gpu_shader_version(); | source[num_source++] = gpu_shader_version(); | ||||
| source[num_source++] = standard_extensions; | source[num_source++] = standard_extensions; | ||||
| source[num_source++] = standard_defines; | source[num_source++] = standard_defines; | ||||
| if (defines) source[num_source++] = defines; | if (defines) source[num_source++] = defines; | ||||
| source[num_source++] = geocode; | source[num_source++] = geocode; | ||||
| //gpu_dump_shader(source, num_source); | |||||
| glAttachShader(shader->program, shader->geometry); | glAttachShader(shader->program, shader->geometry); | ||||
| glShaderSource(shader->geometry, num_source, source, NULL); | glShaderSource(shader->geometry, num_source, source, NULL); | ||||
| glCompileShader(shader->geometry); | glCompileShader(shader->geometry); | ||||
| glGetShaderiv(shader->geometry, GL_COMPILE_STATUS, &status); | glGetShaderiv(shader->geometry, GL_COMPILE_STATUS, &status); | ||||
| if (!status) { | if (!status) { | ||||
| glGetShaderInfoLog(shader->geometry, sizeof(log), &length, log); | glGetShaderInfoLog(shader->geometry, sizeof(log), &length, log); | ||||
| ▲ Show 20 Lines • Show All 497 Lines • Show Last 20 Lines | |||||