| 39 | stbtt_bakedchar chardata[numChars]; |
| 40 | |
| 41 | void WrappedOpenGL::ContextData::CreateDebugData() |
| 42 | { |
| 43 | // if these constants change, update glsl_ubos.h and gltext.vert |
| 44 | RDCCOMPILE_ASSERT(FONT_FIRST_CHAR == int(' '), "FONT_FIRST_CHAR is incorrect"); |
| 45 | RDCCOMPILE_ASSERT(FONT_LAST_CHAR == 126, "FONT_LAST_CHAR is incorrect"); |
| 46 | |
| 47 | // to let us display the overlay on old GL contexts, use as simple a subset of functionality as |
| 48 | // possible to upload the texture. VAO and shaders are used optionally on modern contexts, |
| 49 | // otherwise we fall back to immediate mode rendering by hand |
| 50 | if(GL.glGetIntegerv && GL.glGenTextures && GL.glBindTexture && GL.glTexImage2D && GL.glTexParameteri) |
| 51 | { |
| 52 | rdcstr ttfstring = GetEmbeddedResource(sourcecodepro_ttf); |
| 53 | byte *ttfdata = (byte *)ttfstring.c_str(); |
| 54 | |
| 55 | byte *buf = new byte[FONT_TEX_WIDTH * FONT_TEX_HEIGHT]; |
| 56 | |
| 57 | stbtt_BakeFontBitmap(ttfdata, 0, charPixelHeight, buf, FONT_TEX_WIDTH, FONT_TEX_HEIGHT, |
| 58 | FONT_FIRST_CHAR + 1, numChars, chardata); |
| 59 | |
| 60 | CharSize = charPixelHeight; |
| 61 | #if ENABLED(RDOC_ANDROID) |
| 62 | CharSize *= 2.0f; |
| 63 | #endif |
| 64 | CharAspect = chardata[0].xadvance / charPixelHeight; |
| 65 | |
| 66 | stbtt_fontinfo f = {0}; |
| 67 | stbtt_InitFont(&f, ttfdata, 0); |
| 68 | |
| 69 | int ascent = 0; |
| 70 | stbtt_GetFontVMetrics(&f, &ascent, NULL, NULL); |
| 71 | |
| 72 | float maxheight = float(ascent) * stbtt_ScaleForPixelHeight(&f, charPixelHeight); |
| 73 | |
| 74 | { |
| 75 | PixelPackState pack; |
| 76 | PixelUnpackState unpack; |
| 77 | GLuint pixelPackBuffer = 0; |
| 78 | GLuint pixelUnpackBuffer = 0; |
| 79 | |
| 80 | GL.glGetIntegerv(eGL_PIXEL_PACK_BUFFER_BINDING, (GLint *)&pixelPackBuffer); |
| 81 | GL.glGetIntegerv(eGL_PIXEL_UNPACK_BUFFER_BINDING, (GLint *)&pixelUnpackBuffer); |
| 82 | GL.glBindBuffer(eGL_PIXEL_PACK_BUFFER, 0); |
| 83 | GL.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, 0); |
| 84 | |
| 85 | pack.Fetch(false); |
| 86 | unpack.Fetch(false); |
| 87 | |
| 88 | ResetPixelPackState(false, 1); |
| 89 | ResetPixelUnpackState(false, 1); |
| 90 | |
| 91 | GLenum oldActive = eGL_TEXTURE0; |
| 92 | GL.glGetIntegerv(eGL_ACTIVE_TEXTURE, (GLint *)&oldActive); |
| 93 | GL.glActiveTexture(eGL_TEXTURE0); |
| 94 | |
| 95 | GLuint curtex = 0; |
| 96 | GL.glGetIntegerv(eGL_TEXTURE_BINDING_2D, (GLint *)&curtex); |
| 97 | |
| 98 | GLenum texFmt = eGL_R8; |
no test coverage detected