bool D3D9DebugManager::InitFontRendering() { HRESULT hr = S_OK; int width = FONT_TEX_WIDTH; int height = FONT_TEX_HEIGHT; string font = GetEmbeddedResource(sourcecodepro_ttf); byte *ttfdata = (byte *)font.c_str(); const int firstChar = int(' ') + 1; const int lastChar = 127; const int numChars = lastChar - firstChar; byte *buf = new byte[width * height]; const float pixelHeight = 20.0f; stbtt_BakeFontBitmap(ttfdata, 0, pixelHeight, buf, width, height, firstChar, numChars, m_Font.charData); stbtt_fontinfo f = {0}; stbtt_InitFont(&f, ttfdata, 0); int ascent = 0; stbtt_GetFontVMetrics(&f, &ascent, NULL, NULL); m_Font.maxHeight = float(ascent) * stbtt_ScaleForPixelHeight(&f, pixelHeight); IDirect3DTexture9 *fontTex = NULL; hr = m_WrappedDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &fontTex, NULL); if(FAILED(hr)) { RDCERR("Failed to create font texture %08x", hr); } D3DLOCKED_RECT lockedRegion; hr = fontTex->LockRect(0, &lockedRegion, NULL, D3DLOCK_DISCARD); if(FAILED(hr)) { RDCERR("Failed to lock font texture %08x", hr); } else { BYTE *texBase = (BYTE *)lockedRegion.pBits; for(int y = 0; y < height; y++) { byte *curRow = (texBase + (y * lockedRegion.Pitch)); for(int x = 0; x < width; x++) { curRow[x * 4 + 0] = buf[(y * width) + x]; curRow[x * 4 + 1] = buf[(y * width) + x]; curRow[x * 4 + 2] = buf[(y * width) + x]; curRow[x * 4 + 3] = buf[(y * width) + x]; } } hr = fontTex->UnlockRect(0); if(hr != S_OK) { RDCERR("Failed to unlock font texture %08x", hr); } } m_Font.Tex = fontTex; delete[] buf; return true; }
void GLReplay::InitDebugData() { if(m_pDriver == NULL) return; { uint64_t id = MakeOutputWindow(NULL, true); m_DebugCtx = &m_OutputWindows[id]; } DebugData.outWidth = 0.0f; DebugData.outHeight = 0.0f; DebugData.blitvsSource = GetEmbeddedResource(blit_vert); DebugData.blitfsSource = GetEmbeddedResource(blit_frag); DebugData.blitProg = CreateShaderProgram(DebugData.blitvsSource.c_str(), DebugData.blitfsSource.c_str()); string texfs = GetEmbeddedResource(texdisplay_frag); DebugData.texDisplayProg = CreateShaderProgram(DebugData.blitvsSource.c_str(), texfs.c_str()); string checkerfs = GetEmbeddedResource(checkerboard_frag); DebugData.checkerProg = CreateShaderProgram(DebugData.blitvsSource.c_str(), checkerfs.c_str()); DebugData.genericvsSource = GetEmbeddedResource(generic_vert); DebugData.genericfsSource = GetEmbeddedResource(generic_frag); DebugData.genericProg = CreateShaderProgram(DebugData.genericvsSource.c_str(), DebugData.genericfsSource.c_str()); string meshvs = GetEmbeddedResource(mesh_vert); DebugData.meshProg = CreateShaderProgram(meshvs.c_str(), DebugData.genericfsSource.c_str()); WrappedOpenGL &gl = *m_pDriver; { float data[] = { 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, }; gl.glGenBuffers(1, &DebugData.outlineStripVB); gl.glBindBuffer(eGL_ARRAY_BUFFER, DebugData.outlineStripVB); gl.glBufferData(eGL_ARRAY_BUFFER, sizeof(data), data, eGL_STATIC_DRAW); gl.glGenVertexArrays(1, &DebugData.outlineStripVAO); gl.glBindVertexArray(DebugData.outlineStripVAO); gl.glVertexAttribPointer(0, 4, eGL_FLOAT, false, 0, (const void *)0); gl.glEnableVertexAttribArray(0); } gl.glGenSamplers(1, &DebugData.linearSampler); gl.glSamplerParameteri(DebugData.linearSampler, eGL_TEXTURE_MIN_FILTER, eGL_LINEAR_MIPMAP_NEAREST); gl.glSamplerParameteri(DebugData.linearSampler, eGL_TEXTURE_MAG_FILTER, eGL_LINEAR); gl.glSamplerParameteri(DebugData.linearSampler, eGL_TEXTURE_WRAP_S, eGL_CLAMP_TO_EDGE); gl.glSamplerParameteri(DebugData.linearSampler, eGL_TEXTURE_WRAP_T, eGL_CLAMP_TO_EDGE); gl.glGenSamplers(1, &DebugData.pointSampler); gl.glSamplerParameteri(DebugData.pointSampler, eGL_TEXTURE_MIN_FILTER, eGL_NEAREST_MIPMAP_NEAREST); gl.glSamplerParameteri(DebugData.pointSampler, eGL_TEXTURE_MAG_FILTER, eGL_NEAREST); gl.glSamplerParameteri(DebugData.pointSampler, eGL_TEXTURE_WRAP_S, eGL_CLAMP_TO_EDGE); gl.glSamplerParameteri(DebugData.pointSampler, eGL_TEXTURE_WRAP_T, eGL_CLAMP_TO_EDGE); gl.glGenBuffers(ARRAY_COUNT(DebugData.UBOs), DebugData.UBOs); for(size_t i=0; i < ARRAY_COUNT(DebugData.UBOs); i++) { gl.glBindBuffer(eGL_UNIFORM_BUFFER, DebugData.UBOs[i]); gl.glBufferData(eGL_UNIFORM_BUFFER, DebugData.UBOSize, NULL, eGL_DYNAMIC_DRAW); } DebugData.overlayTexWidth = DebugData.overlayTexHeight = 0; DebugData.overlayTex = DebugData.overlayFBO = 0; gl.glGenFramebuffers(1, &DebugData.pickPixelFBO); gl.glBindFramebuffer(eGL_FRAMEBUFFER, DebugData.pickPixelFBO); gl.glGenTextures(1, &DebugData.pickPixelTex); gl.glBindTexture(eGL_TEXTURE_2D, DebugData.pickPixelTex); gl.glTexStorage2D(eGL_TEXTURE_2D, 1, eGL_RGBA32F, 1, 1); gl.glTexParameteri(eGL_TEXTURE_2D, eGL_TEXTURE_MIN_FILTER, eGL_NEAREST); gl.glTexParameteri(eGL_TEXTURE_2D, eGL_TEXTURE_MAG_FILTER, eGL_NEAREST); gl.glTexParameteri(eGL_TEXTURE_2D, eGL_TEXTURE_WRAP_S, eGL_CLAMP_TO_EDGE); gl.glTexParameteri(eGL_TEXTURE_2D, eGL_TEXTURE_WRAP_T, eGL_CLAMP_TO_EDGE); gl.glFramebufferTexture(eGL_FRAMEBUFFER, eGL_COLOR_ATTACHMENT0, DebugData.pickPixelTex, 0); gl.glGenVertexArrays(1, &DebugData.emptyVAO); gl.glBindVertexArray(DebugData.emptyVAO); MakeCurrentReplayContext(&m_ReplayCtx); gl.glGenVertexArrays(1, &DebugData.meshVAO); gl.glBindVertexArray(DebugData.meshVAO); }
void GenerateGLSLShader(std::vector<std::string> &sources, ShaderType type, const std::string &defines, const std::string &shader, int version, bool uniforms) { sources.resize(4); sources[0] = StringFormat::Fmt("#version %d %s\n", version, type == eShaderGLSLES ? "es" : "core"); if(uniforms) sources[1] = GetEmbeddedResource(glsl_debuguniforms_h); else sources[1] = ""; if(shader.find("#include \"texsample.h\"") != string::npos) { if(type == eShaderVulkan) sources[2] = GetEmbeddedResource(glsl_vk_texsample_h); else if(type == eShaderGLSL) sources[2] = GetEmbeddedResource(glsl_gl_texsample_h); else if(type == eShaderGLSLES) sources[2] = GetEmbeddedResource(glsl_gles_texsample_h); else RDCERR("Unknown type! %d", type); } else { sources[2] = ""; } sources[3] = shader; for(int i = 0; i < 4; i++) { // hoist up any #extension directives size_t extsearch = 0; do { extsearch = sources[i].find("#extension", extsearch); if(extsearch == string::npos) break; size_t begin = extsearch; extsearch = sources[i].find('\n', extsearch); string ext = sources[i].substr(begin, extsearch - begin + 1); if(ext.find("#extension_gles") == 0) { if(type != eShaderGLSLES) continue; ext.erase(ext.find("_gles"), 5); } else if(ext.find("#extension_nongles") == 0) { if(type == eShaderGLSLES) continue; ext.erase(ext.find("_nongles"), 8); } sources[0] += ext; } while(extsearch != string::npos); } sources[0] += "\n" + defines + "\n"; }