Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_draw.c
| Context not available. | |||||
| extern Material defmaterial; /* from material.c */ | extern Material defmaterial; /* from material.c */ | ||||
| /* Text Rendering */ | |||||
| static void gpu_mcol(unsigned int ucol) | |||||
| { | |||||
| /* mcol order is swapped */ | |||||
| const char *cp = (char *)&ucol; | |||||
| glColor3ub(cp[3], cp[2], cp[1]); | |||||
| } | |||||
| void GPU_render_text( | |||||
| MTexPoly *mtexpoly, int mode, | |||||
| const char *textstr, int textlen, unsigned int *col, | |||||
| const float *v_quad[4], const float *uv_quad[4], | |||||
| int glattrib) | |||||
| { | |||||
| if ((mode & GEMAT_TEXT) && (textlen > 0) && mtexpoly->tpage) { | |||||
| const float *v1 = v_quad[0]; | |||||
| const float *v2 = v_quad[1]; | |||||
| const float *v3 = v_quad[2]; | |||||
| const float *v4 = v_quad[3]; | |||||
| Image *ima = (Image *)mtexpoly->tpage; | |||||
| const size_t textlen_st = textlen; | |||||
| float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance; | |||||
| /* multiline */ | |||||
| float line_start = 0.0f, line_height; | |||||
| if (v4) | |||||
| line_height = max_ffff(v1[1], v2[1], v3[1], v4[2]) - min_ffff(v1[1], v2[1], v3[1], v4[2]); | |||||
| else | |||||
| line_height = max_fff(v1[1], v2[1], v3[1]) - min_fff(v1[1], v2[1], v3[1]); | |||||
| line_height *= 1.2f; /* could be an option? */ | |||||
| /* end multiline */ | |||||
| /* color has been set */ | |||||
| if (mtexpoly->mode & TF_OBCOL) | |||||
| col = NULL; | |||||
| else if (!col) | |||||
| glColor3f(1.0f, 1.0f, 1.0f); | |||||
| glPushMatrix(); | |||||
| /* get the tab width */ | |||||
| ImBuf *first_ibuf = BKE_image_get_first_ibuf(ima); | |||||
| matrixGlyph(first_ibuf, ' ', ¢erx, ¢ery, | |||||
| &sizex, &sizey, &transx, &transy, &movex, &movey, &advance); | |||||
| float advance_tab = advance * 4; /* tab width could also be an option */ | |||||
| for (size_t index = 0; index < textlen_st; ) { | |||||
| unsigned int character; | |||||
| float uv[4][2]; | |||||
| /* lets calculate offset stuff */ | |||||
| character = BLI_str_utf8_as_unicode_and_size_safe(textstr + index, &index); | |||||
| if (character == '\n') { | |||||
| glTranslatef(line_start, -line_height, 0.0f); | |||||
| line_start = 0.0f; | |||||
| continue; | |||||
| } | |||||
| else if (character == '\t') { | |||||
| glTranslatef(advance_tab, 0.0f, 0.0f); | |||||
| line_start -= advance_tab; /* so we can go back to the start of the line */ | |||||
| continue; | |||||
| } | |||||
| else if (character > USHRT_MAX) { | |||||
| /* not much we can do here bmfonts take ushort */ | |||||
| character = '?'; | |||||
| } | |||||
| /* space starts at offset 1 */ | |||||
| /* character = character - ' ' + 1; */ | |||||
| matrixGlyph(first_ibuf, character, & centerx, ¢ery, | |||||
| &sizex, &sizey, &transx, &transy, &movex, &movey, &advance); | |||||
| uv[0][0] = (uv_quad[0][0] - centerx) * sizex + transx; | |||||
| uv[0][1] = (uv_quad[0][1] - centery) * sizey + transy; | |||||
| uv[1][0] = (uv_quad[1][0] - centerx) * sizex + transx; | |||||
| uv[1][1] = (uv_quad[1][1] - centery) * sizey + transy; | |||||
| uv[2][0] = (uv_quad[2][0] - centerx) * sizex + transx; | |||||
| uv[2][1] = (uv_quad[2][1] - centery) * sizey + transy; | |||||
| glBegin(GL_POLYGON); | |||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[0]); | |||||
| else glTexCoord2fv(uv[0]); | |||||
| if (col) gpu_mcol(col[0]); | |||||
| glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]); | |||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[1]); | |||||
| else glTexCoord2fv(uv[1]); | |||||
| if (col) gpu_mcol(col[1]); | |||||
| glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]); | |||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[2]); | |||||
| else glTexCoord2fv(uv[2]); | |||||
| if (col) gpu_mcol(col[2]); | |||||
| glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]); | |||||
| if (v4) { | |||||
| uv[3][0] = (uv_quad[3][0] - centerx) * sizex + transx; | |||||
| uv[3][1] = (uv_quad[3][1] - centery) * sizey + transy; | |||||
| if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[3]); | |||||
| else glTexCoord2fv(uv[3]); | |||||
| if (col) gpu_mcol(col[3]); | |||||
| glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]); | |||||
| } | |||||
| glEnd(); | |||||
| glTranslatef(advance, 0.0f, 0.0f); | |||||
| line_start -= advance; /* so we can go back to the start of the line */ | |||||
| } | |||||
| glPopMatrix(); | |||||
| BKE_image_release_ibuf(ima, first_ibuf, NULL); | |||||
| } | |||||
| } | |||||
| /* Checking powers of two for images since OpenGL ES requires it */ | /* Checking powers of two for images since OpenGL ES requires it */ | ||||
| static bool is_power_of_2_resolution(int w, int h) | static bool is_power_of_2_resolution(int w, int h) | ||||
| Context not available. | |||||
| if (glsl) { | if (glsl) { | ||||
| GMS.gmatbuf[0] = &defmaterial; | GMS.gmatbuf[0] = &defmaterial; | ||||
| GPU_material_from_blender(GMS.gscene, &defmaterial, GMS.is_opensubdiv); | GPU_material_from_blender(GMS.gscene, &defmaterial, GMS.is_opensubdiv, false); | ||||
| } | } | ||||
| GMS.alphablend[0] = GPU_BLEND_SOLID; | GMS.alphablend[0] = GPU_BLEND_SOLID; | ||||
| Context not available. | |||||
| if (ma == NULL) ma = &defmaterial; | if (ma == NULL) ma = &defmaterial; | ||||
| /* create glsl material if requested */ | /* create glsl material if requested */ | ||||
| gpumat = glsl ? GPU_material_from_blender(GMS.gscene, ma, GMS.is_opensubdiv) : NULL; | gpumat = glsl ? GPU_material_from_blender(GMS.gscene, ma, GMS.is_opensubdiv, false) : NULL; | ||||
| if (gpumat) { | if (gpumat) { | ||||
| /* do glsl only if creating it succeed, else fallback */ | /* do glsl only if creating it succeed, else fallback */ | ||||
| Context not available. | |||||
| /* unbind glsl material */ | /* unbind glsl material */ | ||||
| if (GMS.gboundmat) { | if (GMS.gboundmat) { | ||||
| if (GMS.is_alpha_pass) glDepthMask(0); | if (GMS.is_alpha_pass) glDepthMask(0); | ||||
| GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat, GMS.is_opensubdiv)); | GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat, GMS.is_opensubdiv, false)); | ||||
| GMS.gboundmat = NULL; | GMS.gboundmat = NULL; | ||||
| } | } | ||||
| Context not available. | |||||
| float auto_bump_scale; | float auto_bump_scale; | ||||
| GPUMaterial *gpumat = GPU_material_from_blender(GMS.gscene, mat, GMS.is_opensubdiv); | GPUMaterial *gpumat = GPU_material_from_blender(GMS.gscene, mat, GMS.is_opensubdiv, false); | ||||
| GPU_material_vertex_attributes(gpumat, gattribs); | GPU_material_vertex_attributes(gpumat, gattribs); | ||||
| if (GMS.dob) | if (GMS.dob) | ||||
| Context not available. | |||||
| glDisable(GL_CULL_FACE); | glDisable(GL_CULL_FACE); | ||||
| if (GMS.is_alpha_pass) glDepthMask(0); | if (GMS.is_alpha_pass) glDepthMask(0); | ||||
| GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat, GMS.is_opensubdiv)); | GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat, GMS.is_opensubdiv, false)); | ||||
| GMS.gboundmat = NULL; | GMS.gboundmat = NULL; | ||||
| } | } | ||||
| else | else | ||||
| Context not available. | |||||
| gpu_material = GPU_material_from_blender(GMS.gscene, | gpu_material = GPU_material_from_blender(GMS.gscene, | ||||
| material, | material, | ||||
| GMS.is_opensubdiv); | GMS.is_opensubdiv, | ||||
| false); | |||||
| GPU_material_update_fvar_offset(gpu_material, dm); | GPU_material_update_fvar_offset(gpu_material, dm); | ||||
| } | } | ||||
| Context not available. | |||||