Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_draw.c
| Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
| #ifdef WITH_GAMEENGINE | #ifdef WITH_GAMEENGINE | ||||
| # include "BKE_object.h" | # include "BKE_object.h" | ||||
| #endif | #endif | ||||
| #include "GPU_basic_shader.h" | #include "GPU_basic_shader.h" | ||||
| #include "GPU_buffers.h" | #include "GPU_buffers.h" | ||||
| #include "GPU_draw.h" | #include "GPU_draw.h" | ||||
| #include "GPU_extensions.h" | #include "GPU_extensions.h" | ||||
| #include "GPU_legacy_stubs.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_SMOKE | ||||
| Show All 10 Lines | |||||
| extern Material defmaterial; /* from material.c */ | extern Material defmaterial; /* from material.c */ | ||||
| /* Text Rendering */ | /* Text Rendering */ | ||||
| static void gpu_mcol(unsigned int ucol) | static void gpu_mcol(unsigned int ucol) | ||||
| { | { | ||||
| /* mcol order is swapped */ | /* mcol order is swapped */ | ||||
| const char *cp = (char *)&ucol; | const char *cp = (char *)&ucol; | ||||
| glColor3ub(cp[3], cp[2], cp[1]); | oldColor3ub(cp[3], cp[2], cp[1]); | ||||
| } | } | ||||
| void GPU_render_text( | void GPU_render_text( | ||||
| MTexPoly *mtexpoly, int mode, | MTexPoly *mtexpoly, int mode, | ||||
| const char *textstr, int textlen, unsigned int *col, | const char *textstr, int textlen, unsigned int *col, | ||||
| const float *v_quad[4], const float *uv_quad[4], | const float *v_quad[4], const float *uv_quad[4], | ||||
| int glattrib) | int glattrib) | ||||
| { | { | ||||
| Show All 16 Lines | if ((mode & GEMAT_TEXT) && (textlen > 0) && mtexpoly->tpage) { | ||||
| line_height *= 1.2f; /* could be an option? */ | line_height *= 1.2f; /* could be an option? */ | ||||
| /* end multiline */ | /* end multiline */ | ||||
| /* color has been set */ | /* color has been set */ | ||||
| if (mtexpoly->mode & TF_OBCOL) | if (mtexpoly->mode & TF_OBCOL) | ||||
| col = NULL; | col = NULL; | ||||
| else if (!col) | else if (!col) | ||||
| glColor3f(1.0f, 1.0f, 1.0f); | oldColor3f(1.0f, 1.0f, 1.0f); | ||||
| gpuPushMatrix(); | gpuPushMatrix(); | ||||
| /* get the tab width */ | /* get the tab width */ | ||||
| ImBuf *first_ibuf = BKE_image_get_first_ibuf(ima); | ImBuf *first_ibuf = BKE_image_get_first_ibuf(ima); | ||||
| matrixGlyph(first_ibuf, ' ', ¢erx, ¢ery, | matrixGlyph(first_ibuf, ' ', ¢erx, ¢ery, | ||||
| &sizex, &sizey, &transx, &transy, &movex, &movey, &advance); | &sizex, &sizey, &transx, &transy, &movex, &movey, &advance); | ||||
| Show All 30 Lines | for (size_t index = 0; index < textlen_st; ) { | ||||
| uv[0][0] = (uv_quad[0][0] - centerx) * sizex + transx; | uv[0][0] = (uv_quad[0][0] - centerx) * sizex + transx; | ||||
| uv[0][1] = (uv_quad[0][1] - centery) * sizey + transy; | uv[0][1] = (uv_quad[0][1] - centery) * sizey + transy; | ||||
| uv[1][0] = (uv_quad[1][0] - centerx) * sizex + transx; | uv[1][0] = (uv_quad[1][0] - centerx) * sizex + transx; | ||||
| uv[1][1] = (uv_quad[1][1] - centery) * sizey + transy; | uv[1][1] = (uv_quad[1][1] - centery) * sizey + transy; | ||||
| uv[2][0] = (uv_quad[2][0] - centerx) * sizex + transx; | uv[2][0] = (uv_quad[2][0] - centerx) * sizex + transx; | ||||
| uv[2][1] = (uv_quad[2][1] - centery) * sizey + transy; | uv[2][1] = (uv_quad[2][1] - centery) * sizey + transy; | ||||
| glBegin(GL_POLYGON); | oldBegin(GL_POLYGON); | ||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[0]); | if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[0]); | ||||
| else glTexCoord2fv(uv[0]); | else oldTexCoord2fv(uv[0]); | ||||
| if (col) gpu_mcol(col[0]); | if (col) gpu_mcol(col[0]); | ||||
| glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]); | oldVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]); | ||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[1]); | if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[1]); | ||||
| else glTexCoord2fv(uv[1]); | else oldTexCoord2fv(uv[1]); | ||||
| if (col) gpu_mcol(col[1]); | if (col) gpu_mcol(col[1]); | ||||
| glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]); | oldVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]); | ||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[2]); | if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[2]); | ||||
| else glTexCoord2fv(uv[2]); | else oldTexCoord2fv(uv[2]); | ||||
| if (col) gpu_mcol(col[2]); | if (col) gpu_mcol(col[2]); | ||||
| glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]); | oldVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]); | ||||
| if (v4) { | if (v4) { | ||||
| uv[3][0] = (uv_quad[3][0] - centerx) * sizex + transx; | uv[3][0] = (uv_quad[3][0] - centerx) * sizex + transx; | ||||
| uv[3][1] = (uv_quad[3][1] - centery) * sizey + transy; | uv[3][1] = (uv_quad[3][1] - centery) * sizey + transy; | ||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[3]); | if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[3]); | ||||
| else glTexCoord2fv(uv[3]); | else oldTexCoord2fv(uv[3]); | ||||
| if (col) gpu_mcol(col[3]); | if (col) gpu_mcol(col[3]); | ||||
| glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]); | oldVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]); | ||||
| } | } | ||||
| glEnd(); | oldEnd(); | ||||
| gpuTranslate2f(advance, 0.0f); | gpuTranslate2f(advance, 0.0f); | ||||
| line_start -= advance; /* so we can go back to the start of the line */ | line_start -= advance; /* so we can go back to the start of the line */ | ||||
| } | } | ||||
| gpuPopMatrix(); | gpuPopMatrix(); | ||||
| BKE_image_release_ibuf(ima, first_ibuf, NULL); | BKE_image_release_ibuf(ima, first_ibuf, NULL); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | if (GTS.curtilemode != 0) { | ||||
| glMatrixMode(GL_MODELVIEW); | glMatrixMode(GL_MODELVIEW); | ||||
| } | } | ||||
| GTS.curtilemode = 0; | GTS.curtilemode = 0; | ||||
| GTS.curtileXRep = 0; | GTS.curtileXRep = 0; | ||||
| GTS.curtileYRep = 0; | GTS.curtileYRep = 0; | ||||
| GTS.alphablend = -1; | GTS.alphablend = -1; | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| glDisable(GL_TEXTURE_2D); | oldDisable(GL_TEXTURE_2D); | ||||
| glDisable(GL_TEXTURE_GEN_S); | oldDisable(GL_TEXTURE_GEN_S); | ||||
| glDisable(GL_TEXTURE_GEN_T); | oldDisable(GL_TEXTURE_GEN_T); | ||||
| glDisable(GL_ALPHA_TEST); | oldDisable(GL_ALPHA_TEST); | ||||
| } | } | ||||
| static void gpu_set_alpha_blend(GPUBlendMode alphablend) | static void gpu_set_alpha_blend(GPUBlendMode alphablend) | ||||
| { | { | ||||
| if (alphablend == GPU_BLEND_SOLID) { | if (alphablend == GPU_BLEND_SOLID) { | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| glDisable(GL_ALPHA_TEST); | oldDisable(GL_ALPHA_TEST); | ||||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
| } | } | ||||
| else if (alphablend == GPU_BLEND_ADD) { | else if (alphablend == GPU_BLEND_ADD) { | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| glBlendFunc(GL_ONE, GL_ONE); | glBlendFunc(GL_ONE, GL_ONE); | ||||
| glDisable(GL_ALPHA_TEST); | oldDisable(GL_ALPHA_TEST); | ||||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||||
| } | } | ||||
| else if (ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_SORT)) { | else if (ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_SORT)) { | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||||
| /* for OpenGL render we use the alpha channel, this makes alpha blend correct */ | /* for OpenGL render we use the alpha channel, this makes alpha blend correct */ | ||||
| glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | ||||
| /* if U.glalphaclip == 1.0, some cards go bonkers... | /* if U.glalphaclip == 1.0, some cards go bonkers... | ||||
| * turn off alpha test in this case */ | * turn off alpha test in this case */ | ||||
| /* added after 2.45 to clip alpha */ | /* added after 2.45 to clip alpha */ | ||||
| if (U.glalphaclip == 1.0f) { | if (U.glalphaclip == 1.0f) { | ||||
| glDisable(GL_ALPHA_TEST); | oldDisable(GL_ALPHA_TEST); | ||||
| } | } | ||||
| else { | else { | ||||
| glEnable(GL_ALPHA_TEST); | oldEnable(GL_ALPHA_TEST); | ||||
| glAlphaFunc(GL_GREATER, U.glalphaclip); | oldAlphaFunc(GL_GREATER, U.glalphaclip); | ||||
| } | } | ||||
| } | } | ||||
| else if (alphablend == GPU_BLEND_CLIP) { | else if (alphablend == GPU_BLEND_CLIP) { | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||||
| glEnable(GL_ALPHA_TEST); | oldEnable(GL_ALPHA_TEST); | ||||
| glAlphaFunc(GL_GREATER, 0.5f); | oldAlphaFunc(GL_GREATER, 0.5f); | ||||
| } | } | ||||
| else if (alphablend == GPU_BLEND_ALPHA_TO_COVERAGE) { | else if (alphablend == GPU_BLEND_ALPHA_TO_COVERAGE) { | ||||
| glEnable(GL_ALPHA_TEST); | oldEnable(GL_ALPHA_TEST); | ||||
| glAlphaFunc(GL_GREATER, U.glalphaclip); | oldAlphaFunc(GL_GREATER, U.glalphaclip); | ||||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||||
| } | } | ||||
| } | } | ||||
| static void gpu_verify_alpha_blend(int alphablend) | static void gpu_verify_alpha_blend(int alphablend) | ||||
| { | { | ||||
| /* verify alpha blending modes */ | /* verify alpha blending modes */ | ||||
| if (GTS.alphablend == alphablend) | if (GTS.alphablend == alphablend) | ||||
| return; | return; | ||||
| gpu_set_alpha_blend(alphablend); | gpu_set_alpha_blend(alphablend); | ||||
| GTS.alphablend = alphablend; | GTS.alphablend = alphablend; | ||||
| } | } | ||||
| static void gpu_verify_reflection(Image *ima) | static void gpu_verify_reflection(Image *ima) | ||||
| { | { | ||||
| if (ima && (ima->flag & IMA_REFLECT)) { | if (ima && (ima->flag & IMA_REFLECT)) { | ||||
| /* enable reflection mapping */ | /* enable reflection mapping */ | ||||
| glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); | oldTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); | ||||
| glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); | oldTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); | ||||
| glEnable(GL_TEXTURE_GEN_S); | oldEnable(GL_TEXTURE_GEN_S); | ||||
| glEnable(GL_TEXTURE_GEN_T); | oldEnable(GL_TEXTURE_GEN_T); | ||||
| } | } | ||||
| else { | else { | ||||
| /* disable reflection mapping */ | /* disable reflection mapping */ | ||||
| glDisable(GL_TEXTURE_GEN_S); | oldDisable(GL_TEXTURE_GEN_S); | ||||
| glDisable(GL_TEXTURE_GEN_T); | oldDisable(GL_TEXTURE_GEN_T); | ||||
| } | } | ||||
| } | } | ||||
| typedef struct VerifyThreadData { | typedef struct VerifyThreadData { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| float *srgb_frect; | float *srgb_frect; | ||||
| } VerifyThreadData; | } VerifyThreadData; | ||||
| ▲ Show 20 Lines • Show All 1,450 Lines • ▼ Show 20 Lines | if (gattribs && GMS.gmatbuf[nr]) { | ||||
| if (GMS.backface_culling) { | if (GMS.backface_culling) { | ||||
| if (mat->game.flag) | if (mat->game.flag) | ||||
| glEnable(GL_CULL_FACE); | glEnable(GL_CULL_FACE); | ||||
| else | else | ||||
| glDisable(GL_CULL_FACE); | glDisable(GL_CULL_FACE); | ||||
| } | } | ||||
| if (GMS.use_matcaps) | if (GMS.use_matcaps) | ||||
| glColor3f(1.0f, 1.0f, 1.0f); | oldColor3f(1.0f, 1.0f, 1.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| /* or do fixed function opengl material */ | /* or do fixed function opengl material */ | ||||
| GPU_basic_shader_colors( | GPU_basic_shader_colors( | ||||
| GMS.matbuf[nr].diff, | GMS.matbuf[nr].diff, | ||||
| GMS.matbuf[nr].spec, GMS.matbuf[nr].hard, GMS.matbuf[nr].alpha); | GMS.matbuf[nr].spec, GMS.matbuf[nr].hard, GMS.matbuf[nr].alpha); | ||||
| if (GMS.two_sided_lighting) | if (GMS.two_sided_lighting) | ||||
| ▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | |||||
| * exceptions that we should try to get rid of. */ | * exceptions that we should try to get rid of. */ | ||||
| void GPU_state_init(void) | void GPU_state_init(void) | ||||
| { | { | ||||
| GPU_default_lights(); | GPU_default_lights(); | ||||
| GPU_disable_program_point_size(); | GPU_disable_program_point_size(); | ||||
| /* TODO: remove this when we switch to core profile */ | oldEnable(GL_POINT_SPRITE); | ||||
| glEnable(GL_POINT_SPRITE); | |||||
| glDepthFunc(GL_LEQUAL); | glDepthFunc(GL_LEQUAL); | ||||
| /* scaling matrices */ | /* scaling matrices */ | ||||
| glEnable(GL_NORMALIZE); | glEnable(GL_NORMALIZE); | ||||
| glDisable(GL_ALPHA_TEST); | oldDisable(GL_ALPHA_TEST); | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| glDisable(GL_DEPTH_TEST); | glDisable(GL_DEPTH_TEST); | ||||
| glDisable(GL_LOGIC_OP); | glDisable(GL_LOGIC_OP); | ||||
| glDisable(GL_STENCIL_TEST); | glDisable(GL_STENCIL_TEST); | ||||
| glDisable(GL_TEXTURE_1D); | oldDisable(GL_TEXTURE_1D); | ||||
| glDisable(GL_TEXTURE_2D); | oldDisable(GL_TEXTURE_2D); | ||||
| glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | oldTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | ||||
| glDepthRange(0.0, 1.0); | glDepthRange(0.0, 1.0); | ||||
| glMatrixMode(GL_TEXTURE); | glMatrixMode(GL_TEXTURE); | ||||
| glLoadIdentity(); /* TEXTURE */ | glLoadIdentity(); /* TEXTURE */ | ||||
| glMatrixMode(GL_MODELVIEW); | glMatrixMode(GL_MODELVIEW); | ||||
| glFrontFace(GL_CCW); | glFrontFace(GL_CCW); | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| #endif | #endif | ||||
| void GPU_select_index_set(int index) | void GPU_select_index_set(int index) | ||||
| { | { | ||||
| const int col = index_to_framebuffer(index); | const int col = index_to_framebuffer(index); | ||||
| glColor3ub(( (col) & 0xFF), | oldColor3ub(( (col) & 0xFF), | ||||
| (((col) >> 8) & 0xFF), | (((col) >> 8) & 0xFF), | ||||
| (((col) >> 16) & 0xFF)); | (((col) >> 16) & 0xFF)); | ||||
| } | } | ||||
| void GPU_select_index_get(int index, int *r_col) | void GPU_select_index_get(int index, int *r_col) | ||||
| { | { | ||||
| const int col = index_to_framebuffer(index); | const int col = index_to_framebuffer(index); | ||||
| char *c_col = (char *)r_col; | char *c_col = (char *)r_col; | ||||
| ▲ Show 20 Lines • Show All 192 Lines • Show Last 20 Lines | |||||