Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_draw_legacy.c
| Context not available. | |||||
| static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) | static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) | ||||
| { | { | ||||
| if (scene->world && (v3d->flag3 & V3D_SHOW_WORLD)) { | if (scene->world && (v3d->flag3 & V3D_SHOW_WORLD)) { | ||||
| RegionView3D *rv3d = ar->regiondata; | bool glsl = GPU_glsl_support(); | ||||
| GPUMaterial *gpumat = GPU_material_world(scene, scene->world); | if (glsl) { | ||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| GPUMaterial *gpumat = GPU_material_world(scene, scene->world); | |||||
| /* calculate full shader for background */ | /* calculate full shader for background */ | ||||
| GPU_material_bind(gpumat, 1, 1, 1.0, false, rv3d->viewmat, rv3d->viewinv, rv3d->viewcamtexcofac, (v3d->scenelock != 0)); | GPU_material_bind(gpumat, 1, 1, 1.0, false, rv3d->viewmat, rv3d->viewinv, rv3d->viewcamtexcofac, (v3d->scenelock != 0)); | ||||
| bool material_not_bound = !GPU_material_bound(gpumat); | |||||
| if (material_not_bound) { | |||||
| glMatrixMode(GL_PROJECTION); | |||||
| glPushMatrix(); | |||||
| glLoadIdentity(); | |||||
| glMatrixMode(GL_MODELVIEW); | |||||
| glPushMatrix(); | |||||
| glLoadIdentity(); | |||||
| glColor4f(0.0f, 0.0f, 0.0f, 1.0f); | |||||
| } | |||||
| // Draw world | |||||
| glEnable(GL_DEPTH_TEST); | |||||
| glDepthFunc(GL_ALWAYS); | |||||
| glBegin(GL_TRIANGLE_STRIP); | |||||
| glVertex3f(-1.0, -1.0, 1.0); | |||||
| glVertex3f(1.0, -1.0, 1.0); | |||||
| glVertex3f(-1.0, 1.0, 1.0); | |||||
| glVertex3f(1.0, 1.0, 1.0); | |||||
| glEnd(); | |||||
| // | |||||
| if (material_not_bound) { | |||||
| glMatrixMode(GL_PROJECTION); | |||||
| glPopMatrix(); | |||||
| glMatrixMode(GL_MODELVIEW); | |||||
| glPopMatrix(); | |||||
| } | |||||
| GPU_material_unbind(gpumat); | |||||
| glDepthFunc(GL_LEQUAL); | |||||
| glDisable(GL_DEPTH_TEST); | |||||
| } | |||||
| else if (scene->world->skytype & WO_SKYBLEND) { /* blend sky */ | |||||
| int x, y; | |||||
| float col_hor[3]; | |||||
| float col_zen[3]; | |||||
| bool material_not_bound = !GPU_material_bound(gpumat); | #define VIEWGRAD_RES_X 16 | ||||
| #define VIEWGRAD_RES_Y 16 | |||||
| GLubyte grid_col[VIEWGRAD_RES_X][VIEWGRAD_RES_Y][4]; | |||||
| static float grid_pos[VIEWGRAD_RES_X][VIEWGRAD_RES_Y][3]; | |||||
| static GLushort indices[VIEWGRAD_RES_X - 1][VIEWGRAD_RES_X - 1][4]; | |||||
| static bool buf_calculated = false; | |||||
| IMB_colormanagement_pixel_to_display_space_v3(col_hor, &scene->world->horr, &scene->view_settings, | |||||
| &scene->display_settings); | |||||
| IMB_colormanagement_pixel_to_display_space_v3(col_zen, &scene->world->zenr, &scene->view_settings, | |||||
| &scene->display_settings); | |||||
| if (material_not_bound) { | |||||
| glMatrixMode(GL_PROJECTION); | glMatrixMode(GL_PROJECTION); | ||||
| glPushMatrix(); | glPushMatrix(); | ||||
| glLoadIdentity(); | glLoadIdentity(); | ||||
| glMatrixMode(GL_MODELVIEW); | glMatrixMode(GL_MODELVIEW); | ||||
| glPushMatrix(); | glPushMatrix(); | ||||
| glLoadIdentity(); | glLoadIdentity(); | ||||
| glColor4f(0.0f, 0.0f, 0.0f, 1.0f); | |||||
| } | |||||
| /* Draw world */ | /* calculate buffers the first time only */ | ||||
| glEnable(GL_DEPTH_TEST); | if (!buf_calculated) { | ||||
| glDepthFunc(GL_ALWAYS); | for (x = 0; x < VIEWGRAD_RES_X; x++) { | ||||
| glBegin(GL_TRIANGLE_STRIP); | for (y = 0; y < VIEWGRAD_RES_Y; y++) { | ||||
| glVertex3f(-1.0, -1.0, 1.0); | const float xf = (float)x / (float)(VIEWGRAD_RES_X - 1); | ||||
| glVertex3f(1.0, -1.0, 1.0); | const float yf = (float)y / (float)(VIEWGRAD_RES_Y - 1); | ||||
| glVertex3f(-1.0, 1.0, 1.0); | |||||
| glVertex3f(1.0, 1.0, 1.0); | /* -1..1 range */ | ||||
| glEnd(); | grid_pos[x][y][0] = (xf - 0.5f) * 2.0f; | ||||
| grid_pos[x][y][1] = (yf - 0.5f) * 2.0f; | |||||
| grid_pos[x][y][2] = 1.0; | |||||
| } | |||||
| } | |||||
| for (x = 0; x < VIEWGRAD_RES_X - 1; x++) { | |||||
| for (y = 0; y < VIEWGRAD_RES_Y - 1; y++) { | |||||
| indices[x][y][0] = x * VIEWGRAD_RES_X + y; | |||||
| indices[x][y][1] = x * VIEWGRAD_RES_X + y + 1; | |||||
| indices[x][y][2] = (x + 1) * VIEWGRAD_RES_X + y + 1; | |||||
| indices[x][y][3] = (x + 1) * VIEWGRAD_RES_X + y; | |||||
| } | |||||
| } | |||||
| buf_calculated = true; | |||||
| } | |||||
| for (x = 0; x < VIEWGRAD_RES_X; x++) { | |||||
| for (y = 0; y < VIEWGRAD_RES_Y; y++) { | |||||
| const float xf = (float)x / (float)(VIEWGRAD_RES_X - 1); | |||||
| const float yf = (float)y / (float)(VIEWGRAD_RES_Y - 1); | |||||
| const float mval[2] = {xf * (float)ar->winx, yf * ar->winy}; | |||||
| const float z_up[3] = {0.0f, 0.0f, 1.0f}; | |||||
| float out[3]; | |||||
| GLubyte *col_ub = grid_col[x][y]; | |||||
| float col_fac; | |||||
| float col_fl[3]; | |||||
| ED_view3d_win_to_vector(ar, mval, out); | |||||
| if (scene->world->skytype & WO_SKYPAPER) { | |||||
| if (scene->world->skytype & WO_SKYREAL) { | |||||
| col_fac = fabsf(((float)y / (float)VIEWGRAD_RES_Y) - 0.5f) * 2.0f; | |||||
| } | |||||
| else { | |||||
| col_fac = (float)y / (float)VIEWGRAD_RES_Y; | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (scene->world->skytype & WO_SKYREAL) { | |||||
| col_fac = fabsf((angle_normalized_v3v3(z_up, out) / (float)M_PI) - 0.5f) * 2.0f; | |||||
| } | |||||
| else { | |||||
| col_fac = 1.0f - (angle_normalized_v3v3(z_up, out) / (float)M_PI); | |||||
| } | |||||
| } | |||||
| interp_v3_v3v3(col_fl, col_hor, col_zen, col_fac); | |||||
| rgb_float_to_uchar(col_ub, col_fl); | |||||
| col_ub[3] = 255; | |||||
| } | |||||
| } | |||||
| glEnable(GL_DEPTH_TEST); | |||||
| glDepthFunc(GL_ALWAYS); | |||||
| glEnableClientState(GL_VERTEX_ARRAY); | |||||
| glEnableClientState(GL_COLOR_ARRAY); | |||||
| glVertexPointer(3, GL_FLOAT, 0, grid_pos); | |||||
| glColorPointer(4, GL_UNSIGNED_BYTE, 0, grid_col); | |||||
| glDrawElements(GL_QUADS, (VIEWGRAD_RES_X - 1) * (VIEWGRAD_RES_Y - 1) * 4, GL_UNSIGNED_SHORT, indices); | |||||
| glDisableClientState(GL_VERTEX_ARRAY); | |||||
| glDisableClientState(GL_COLOR_ARRAY); | |||||
| glDepthFunc(GL_LEQUAL); | |||||
| glDisable(GL_DEPTH_TEST); | |||||
| if (material_not_bound) { | |||||
| glMatrixMode(GL_PROJECTION); | glMatrixMode(GL_PROJECTION); | ||||
| glPopMatrix(); | glPopMatrix(); | ||||
| glMatrixMode(GL_MODELVIEW); | glMatrixMode(GL_MODELVIEW); | ||||
| glPopMatrix(); | glPopMatrix(); | ||||
| } | |||||
| GPU_material_unbind(gpumat); | #undef VIEWGRAD_RES_X | ||||
| #undef VIEWGRAD_RES_Y | |||||
| } | |||||
| else { /* solid sky */ | |||||
| float col_hor[3]; | |||||
| IMB_colormanagement_pixel_to_display_space_v3(col_hor, &scene->world->horr, &scene->view_settings, | |||||
| &scene->display_settings); | |||||
| glDepthFunc(GL_LEQUAL); | glClearColor(col_hor[0], col_hor[1], col_hor[2], 1.0); | ||||
| glDisable(GL_DEPTH_TEST); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) { | if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) { | ||||
| Context not available. | |||||