Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_draw.c
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| #include "GPU_glew.h" | #include "GPU_glew.h" | ||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "PIL_time.h" | #include "PIL_time.h" | ||||
| #ifdef WITH_SMOKE | #ifdef WITH_MANTA | ||||
| # include "smoke_API.h" | # include "manta_fluid_API.h" | ||||
| #endif | #endif | ||||
| static void gpu_free_image_immediate(Image *ima); | static void gpu_free_image_immediate(Image *ima); | ||||
| //* Checking powers of two for images since OpenGL ES requires it */ | //* Checking powers of two for images since OpenGL ES requires it */ | ||||
| #ifdef WITH_DDS | #ifdef WITH_DDS | ||||
| static bool is_power_of_2_resolution(int w, int h) | static bool is_power_of_2_resolution(int w, int h) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 730 Lines • ▼ Show 20 Lines | |||||
| enum { | enum { | ||||
| TFUNC_FLAME_SPECTRUM = 0, | TFUNC_FLAME_SPECTRUM = 0, | ||||
| TFUNC_COLOR_RAMP = 1, | TFUNC_COLOR_RAMP = 1, | ||||
| }; | }; | ||||
| #define TFUNC_WIDTH 256 | #define TFUNC_WIDTH 256 | ||||
| #ifdef WITH_SMOKE | #ifdef WITH_MANTA | ||||
| static void create_flame_spectrum_texture(float *data) | static void create_flame_spectrum_texture(float *data) | ||||
| { | { | ||||
| #define FIRE_THRESH 7 | #define FIRE_THRESH 7 | ||||
| #define MAX_FIRE_ALPHA 0.06f | #define MAX_FIRE_ALPHA 0.06f | ||||
| #define FULL_ON_FIRE 100 | #define FULL_ON_FIRE 100 | ||||
| float *spec_pixels = MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 * sizeof(float), "spec_pixels"); | float *spec_pixels = MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 * sizeof(float), "spec_pixels"); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static void swizzle_texture_channel_rrrr(GPUTexture *tex) | ||||
| GPU_texture_unbind(tex); | GPU_texture_unbind(tex); | ||||
| } | } | ||||
| static GPUTexture *create_field_texture(SmokeDomainSettings *sds) | static GPUTexture *create_field_texture(SmokeDomainSettings *sds) | ||||
| { | { | ||||
| float *field = NULL; | float *field = NULL; | ||||
| switch (sds->coba_field) { | switch (sds->coba_field) { | ||||
| case FLUID_FIELD_DENSITY: field = smoke_get_density(sds->fluid); break; | case FLUID_DOMAIN_FIELD_DENSITY: field = smoke_get_density(sds->fluid); break; | ||||
| case FLUID_FIELD_HEAT: field = smoke_get_heat(sds->fluid); break; | case FLUID_DOMAIN_FIELD_HEAT: field = smoke_get_heat(sds->fluid); break; | ||||
| case FLUID_FIELD_FUEL: field = smoke_get_fuel(sds->fluid); break; | case FLUID_DOMAIN_FIELD_FUEL: field = smoke_get_fuel(sds->fluid); break; | ||||
| case FLUID_FIELD_REACT: field = smoke_get_react(sds->fluid); break; | case FLUID_DOMAIN_FIELD_REACT: field = smoke_get_react(sds->fluid); break; | ||||
| case FLUID_FIELD_FLAME: field = smoke_get_flame(sds->fluid); break; | case FLUID_DOMAIN_FIELD_FLAME: field = smoke_get_flame(sds->fluid); break; | ||||
| case FLUID_FIELD_VELOCITY_X: field = smoke_get_velocity_x(sds->fluid); break; | case FLUID_DOMAIN_FIELD_VELOCITY_X: field = fluid_get_velocity_x(sds->fluid); break; | ||||
| case FLUID_FIELD_VELOCITY_Y: field = smoke_get_velocity_y(sds->fluid); break; | case FLUID_DOMAIN_FIELD_VELOCITY_Y: field = fluid_get_velocity_y(sds->fluid); break; | ||||
| case FLUID_FIELD_VELOCITY_Z: field = smoke_get_velocity_z(sds->fluid); break; | case FLUID_DOMAIN_FIELD_VELOCITY_Z: field = fluid_get_velocity_z(sds->fluid); break; | ||||
| case FLUID_FIELD_COLOR_R: field = smoke_get_color_r(sds->fluid); break; | case FLUID_DOMAIN_FIELD_COLOR_R: field = smoke_get_color_r(sds->fluid); break; | ||||
| case FLUID_FIELD_COLOR_G: field = smoke_get_color_g(sds->fluid); break; | case FLUID_DOMAIN_FIELD_COLOR_G: field = smoke_get_color_g(sds->fluid); break; | ||||
| case FLUID_FIELD_COLOR_B: field = smoke_get_color_b(sds->fluid); break; | case FLUID_DOMAIN_FIELD_COLOR_B: field = smoke_get_color_b(sds->fluid); break; | ||||
| case FLUID_FIELD_FORCE_X: field = smoke_get_force_x(sds->fluid); break; | case FLUID_DOMAIN_FIELD_FORCE_X: field = fluid_get_force_x(sds->fluid); break; | ||||
| case FLUID_FIELD_FORCE_Y: field = smoke_get_force_y(sds->fluid); break; | case FLUID_DOMAIN_FIELD_FORCE_Y: field = fluid_get_force_y(sds->fluid); break; | ||||
| case FLUID_FIELD_FORCE_Z: field = smoke_get_force_z(sds->fluid); break; | case FLUID_DOMAIN_FIELD_FORCE_Z: field = fluid_get_force_z(sds->fluid); break; | ||||
| default: return NULL; | default: return NULL; | ||||
| } | } | ||||
| GPUTexture *tex = GPU_texture_create_nD( | GPUTexture *tex = GPU_texture_create_nD( | ||||
| sds->res[0], sds->res[1], sds->res[2], 3, | sds->res[0], sds->res[1], sds->res[2], 3, | ||||
| field, GPU_R8, GPU_DATA_FLOAT, 0, true, NULL); | field, GPU_R8, GPU_DATA_FLOAT, 0, true, NULL); | ||||
| swizzle_texture_channel_rrrr(tex); | swizzle_texture_channel_rrrr(tex); | ||||
| return tex; | return tex; | ||||
| } | } | ||||
| static GPUTexture *create_density_texture(SmokeDomainSettings *sds, int highres) | static GPUTexture *create_density_texture(SmokeDomainSettings *sds, int highres) | ||||
| { | { | ||||
| float *data = NULL, *source; | float *data = NULL, *source; | ||||
| int cell_count = (highres) ? smoke_turbulence_get_cells(sds->wt) : sds->total_cells; | int cell_count = (highres) ? smoke_turbulence_get_cells(sds->fluid) : sds->total_cells; | ||||
| const bool has_color = (highres) ? smoke_turbulence_has_colors(sds->wt) : smoke_has_colors(sds->fluid); | const bool has_color = (highres) ? smoke_turbulence_has_colors(sds->fluid) : smoke_has_colors(sds->fluid); | ||||
| int *dim = (highres) ? sds->res_wt : sds->res; | int *dim = (highres) ? sds->res_noise : sds->res; | ||||
| eGPUTextureFormat format = (has_color) ? GPU_RGBA8 : GPU_R8; | eGPUTextureFormat format = (has_color) ? GPU_RGBA8 : GPU_R8; | ||||
| if (has_color) { | if (has_color) { | ||||
| data = MEM_callocN(sizeof(float) * cell_count * 4, "smokeColorTexture"); | data = MEM_callocN(sizeof(float) * cell_count * 4, "smokeColorTexture"); | ||||
| } | } | ||||
| if (highres) { | if (highres) { | ||||
| if (has_color) { | if (has_color) { | ||||
| smoke_turbulence_get_rgba(sds->wt, data, 0); | smoke_turbulence_get_rgba(sds->fluid, data, 0); | ||||
| } | } | ||||
| else { | else { | ||||
| source = smoke_turbulence_get_density(sds->wt); | source = smoke_turbulence_get_density(sds->fluid); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (has_color) { | if (has_color) { | ||||
| smoke_get_rgba(sds->fluid, data, 0); | smoke_get_rgba(sds->fluid, data, 0); | ||||
| } | } | ||||
| else { | else { | ||||
| source = smoke_get_density(sds->fluid); | source = smoke_get_density(sds->fluid); | ||||
| Show All 15 Lines | if (format == GPU_R8) { | ||||
| swizzle_texture_channel_rrrr(tex); | swizzle_texture_channel_rrrr(tex); | ||||
| } | } | ||||
| return tex; | return tex; | ||||
| } | } | ||||
| static GPUTexture *create_flame_texture(SmokeDomainSettings *sds, int highres) | static GPUTexture *create_flame_texture(SmokeDomainSettings *sds, int highres) | ||||
| { | { | ||||
| float *source = NULL; | float *source = NULL; | ||||
| const bool has_fuel = (highres) ? smoke_turbulence_has_fuel(sds->wt) : smoke_has_fuel(sds->fluid); | const bool has_fuel = (highres) ? smoke_turbulence_has_fuel(sds->fluid) : smoke_has_fuel(sds->fluid); | ||||
| int *dim = (highres) ? sds->res_wt : sds->res; | int *dim = (highres) ? sds->res_noise : sds->res; | ||||
| if (!has_fuel) | if (!has_fuel) | ||||
| return NULL; | return NULL; | ||||
| if (highres) { | if (highres) { | ||||
| source = smoke_turbulence_get_flame(sds->wt); | source = smoke_turbulence_get_flame(sds->fluid); | ||||
| } | } | ||||
| else { | else { | ||||
| source = smoke_get_flame(sds->fluid); | source = smoke_get_flame(sds->fluid); | ||||
| } | } | ||||
| GPUTexture *tex = GPU_texture_create_nD( | GPUTexture *tex = GPU_texture_create_nD( | ||||
| dim[0], dim[1], dim[2], 3, | dim[0], dim[1], dim[2], 3, | ||||
| source, GPU_R8, GPU_DATA_FLOAT, 0, true, NULL); | source, GPU_R8, GPU_DATA_FLOAT, 0, true, NULL); | ||||
| swizzle_texture_channel_rrrr(tex); | swizzle_texture_channel_rrrr(tex); | ||||
| return tex; | return tex; | ||||
| } | } | ||||
| #endif /* WITH_SMOKE */ | #endif /* WITH_MANTA */ | ||||
| void GPU_free_smoke(SmokeModifierData *smd) | void GPU_free_smoke(SmokeModifierData *smd) | ||||
| { | { | ||||
| if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) { | if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) { | ||||
| if (smd->domain->tex) | if (smd->domain->tex) | ||||
| GPU_texture_free(smd->domain->tex); | GPU_texture_free(smd->domain->tex); | ||||
| smd->domain->tex = NULL; | smd->domain->tex = NULL; | ||||
| Show All 16 Lines | if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) { | ||||
| if (smd->domain->tex_field) | if (smd->domain->tex_field) | ||||
| GPU_texture_free(smd->domain->tex_field); | GPU_texture_free(smd->domain->tex_field); | ||||
| smd->domain->tex_field = NULL; | smd->domain->tex_field = NULL; | ||||
| } | } | ||||
| } | } | ||||
| void GPU_create_smoke_coba_field(SmokeModifierData *smd) | void GPU_create_smoke_coba_field(SmokeModifierData *smd) | ||||
| { | { | ||||
| #ifdef WITH_SMOKE | #ifdef WITH_MANTA | ||||
| if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { | if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { | ||||
| SmokeDomainSettings *sds = smd->domain; | SmokeDomainSettings *sds = smd->domain; | ||||
| if (!sds->tex_field) { | if (!sds->tex_field) { | ||||
| sds->tex_field = create_field_texture(sds); | sds->tex_field = create_field_texture(sds); | ||||
| } | } | ||||
| if (!sds->tex_coba) { | if (!sds->tex_coba) { | ||||
| sds->tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, sds->coba); | sds->tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, sds->coba); | ||||
| } | } | ||||
| } | } | ||||
| #else // WITH_SMOKE | #else // WITH_MANTA | ||||
| smd->domain->tex_field = NULL; | smd->domain->tex_field = NULL; | ||||
| #endif // WITH_SMOKE | #endif // WITH_MANTA | ||||
| } | } | ||||
| void GPU_create_smoke(SmokeModifierData *smd, int highres) | void GPU_create_smoke(SmokeModifierData *smd, int highres) | ||||
| { | { | ||||
| #ifdef WITH_SMOKE | #ifdef WITH_MANTA | ||||
| if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { | if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { | ||||
| SmokeDomainSettings *sds = smd->domain; | SmokeDomainSettings *sds = smd->domain; | ||||
| if (!sds->tex) { | if (!sds->tex) { | ||||
| sds->tex = create_density_texture(sds, highres); | sds->tex = create_density_texture(sds, highres); | ||||
| } | } | ||||
| if (!sds->tex_flame) { | if (!sds->tex_flame) { | ||||
| sds->tex_flame = create_flame_texture(sds, highres); | sds->tex_flame = create_flame_texture(sds, highres); | ||||
| } | } | ||||
| if (!sds->tex_flame_coba && sds->tex_flame) { | if (!sds->tex_flame_coba && sds->tex_flame) { | ||||
| sds->tex_flame_coba = create_transfer_function(TFUNC_FLAME_SPECTRUM, NULL); | sds->tex_flame_coba = create_transfer_function(TFUNC_FLAME_SPECTRUM, NULL); | ||||
| } | } | ||||
| if (!sds->tex_shadow) { | if (!sds->tex_shadow) { | ||||
| sds->tex_shadow = GPU_texture_create_nD( | sds->tex_shadow = GPU_texture_create_nD( | ||||
| sds->res[0], sds->res[1], sds->res[2], 3, | sds->res[0], sds->res[1], sds->res[2], 3, | ||||
| sds->shadow, | smoke_get_shadow(sds->fluid), | ||||
| GPU_R8, GPU_DATA_FLOAT, 0, true, NULL); | GPU_R8, GPU_DATA_FLOAT, 0, true, NULL); | ||||
| } | } | ||||
| } | } | ||||
| #else // WITH_SMOKE | #else // WITH_MANTA | ||||
| (void)highres; | (void)highres; | ||||
| smd->domain->tex = NULL; | smd->domain->tex = NULL; | ||||
| smd->domain->tex_flame = NULL; | smd->domain->tex_flame = NULL; | ||||
| smd->domain->tex_flame_coba = NULL; | smd->domain->tex_flame_coba = NULL; | ||||
| smd->domain->tex_shadow = NULL; | smd->domain->tex_shadow = NULL; | ||||
| #endif // WITH_SMOKE | #endif // WITH_MANTA | ||||
| } | } | ||||
| void GPU_create_smoke_velocity(SmokeModifierData *smd) | void GPU_create_smoke_velocity(SmokeModifierData *smd) | ||||
| { | { | ||||
| #ifdef WITH_SMOKE | #ifdef WITH_MANTA | ||||
| if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { | if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { | ||||
| SmokeDomainSettings *sds = smd->domain; | SmokeDomainSettings *sds = smd->domain; | ||||
| const float *vel_x = smoke_get_velocity_x(sds->fluid); | const float *vel_x = fluid_get_velocity_x(sds->fluid); | ||||
| const float *vel_y = smoke_get_velocity_y(sds->fluid); | const float *vel_y = fluid_get_velocity_y(sds->fluid); | ||||
| const float *vel_z = smoke_get_velocity_z(sds->fluid); | const float *vel_z = fluid_get_velocity_z(sds->fluid); | ||||
| if (ELEM(NULL, vel_x, vel_y, vel_z)) { | if (ELEM(NULL, vel_x, vel_y, vel_z)) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (!sds->tex_velocity_x) { | if (!sds->tex_velocity_x) { | ||||
| sds->tex_velocity_x = GPU_texture_create_3d(sds->res[0], sds->res[1], sds->res[2], GPU_R16F, vel_x, NULL); | sds->tex_velocity_x = GPU_texture_create_3d(sds->res[0], sds->res[1], sds->res[2], GPU_R16F, vel_x, NULL); | ||||
| sds->tex_velocity_y = GPU_texture_create_3d(sds->res[0], sds->res[1], sds->res[2], GPU_R16F, vel_y, NULL); | sds->tex_velocity_y = GPU_texture_create_3d(sds->res[0], sds->res[1], sds->res[2], GPU_R16F, vel_y, NULL); | ||||
| sds->tex_velocity_z = GPU_texture_create_3d(sds->res[0], sds->res[1], sds->res[2], GPU_R16F, vel_z, NULL); | sds->tex_velocity_z = GPU_texture_create_3d(sds->res[0], sds->res[1], sds->res[2], GPU_R16F, vel_z, NULL); | ||||
| } | } | ||||
| } | } | ||||
| #else // WITH_SMOKE | #else // WITH_MANTA | ||||
| smd->domain->tex_velocity_x = NULL; | smd->domain->tex_velocity_x = NULL; | ||||
| smd->domain->tex_velocity_y = NULL; | smd->domain->tex_velocity_y = NULL; | ||||
| smd->domain->tex_velocity_z = NULL; | smd->domain->tex_velocity_z = NULL; | ||||
| #endif // WITH_SMOKE | #endif // WITH_MANTA | ||||
| } | } | ||||
| /* TODO Unify with the other GPU_free_smoke. */ | /* TODO Unify with the other GPU_free_smoke. */ | ||||
| void GPU_free_smoke_velocity(SmokeModifierData *smd) | void GPU_free_smoke_velocity(SmokeModifierData *smd) | ||||
| { | { | ||||
| if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) { | if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) { | ||||
| if (smd->domain->tex_velocity_x) | if (smd->domain->tex_velocity_x) | ||||
| GPU_texture_free(smd->domain->tex_velocity_x); | GPU_texture_free(smd->domain->tex_velocity_x); | ||||
| ▲ Show 20 Lines • Show All 361 Lines • Show Last 20 Lines | |||||