Ejemplo n.º 1
0
// Move into child tables or return to parent tables based on the given number
void CProfileViewerInternals::NavigateTree(int id)
{
    if (id == 0)
    {
        if (path.size() > 1)
            path.pop_back();
    }
    else
    {
        AbstractProfileTable* table = path[path.size() - 1];
        size_t numrows = table->GetNumberRows();

        for(size_t row = 0; row < numrows; ++row)
        {
            AbstractProfileTable* child = table->GetChild(row);

            if (!child)
                continue;

            --id;
            if (id == 0)
            {
                path.push_back(child);
                break;
            }
        }
    }
}
Ejemplo n.º 2
0
// Render
void CProfileViewer::RenderProfile()
{
    if (!m->profileVisible)
        return;

    if (!m->path.size())
    {
        m->profileVisible = false;
        return;
    }

    PROFILE3_GPU("profile viewer");

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    AbstractProfileTable* table = m->path[m->path.size() - 1];
    const std::vector<ProfileColumn>& columns = table->GetColumns();
    size_t numrows = table->GetNumberRows();

    CFont font(L"mono-stroke-10");
    font.Bind();
    int lineSpacing = font.GetLineSpacing();

    // Render background
    GLint estimate_height;
    GLint estimate_width;

    estimate_width = 50;
    for(size_t i = 0; i < columns.size(); ++i)
        estimate_width += (GLint)columns[i].width;

    estimate_height = 3 + (GLint)numrows;
    if (m->path.size() > 1)
        estimate_height += 2;
    estimate_height = lineSpacing*estimate_height;

    glDisable(GL_TEXTURE_2D);
    glColor4ub(0,0,0,128);
    glBegin(GL_QUADS);
    glVertex2i(estimate_width, g_yres);
    glVertex2i(0, g_yres);
    glVertex2i(0, g_yres-estimate_height);
    glVertex2i(estimate_width, g_yres-estimate_height);
    glEnd();
    glEnable(GL_TEXTURE_2D);

    // Print table and column titles
    glPushMatrix();
    glTranslatef(2.0f, g_yres - lineSpacing, 0.0f );
    glScalef(1.0f, -1.0f, 1.0f);
    glColor3ub(255, 255, 255);

    glPushMatrix();
    glwprintf(L"%hs", table->GetTitle().c_str());
    glPopMatrix();
    glTranslatef( 20.0f, lineSpacing, 0.0f );

    glPushMatrix();
    for(size_t col = 0; col < columns.size(); ++col)
    {
        CStr text = columns[col].title;
        int w, h;
        font.CalculateStringSize(text.FromUTF8(), w, h);
        glPushMatrix();
        if (col > 0) // right-align all but the first column
            glTranslatef(columns[col].width - w, 0, 0);
        glwprintf(L"%hs", text.c_str());
        glPopMatrix();
        glTranslatef(columns[col].width, 0, 0);
    }
    glPopMatrix();
    glTranslatef( 0.0f, lineSpacing, 0.0f );

    // Print rows
    int currentExpandId = 1;

    for(size_t row = 0; row < numrows; ++row)
    {
        glPushMatrix();

        glDisable(GL_TEXTURE_2D);
        if (row % 2)
            glColor4ub(255, 255, 255, 16);
        else
            glColor4ub(0, 0, 0, 16);
        glBegin(GL_QUADS);
        glVertex2i(-22.f, 2.f);
        glVertex2i(estimate_width-22.f, 2.f);
        glVertex2i(estimate_width-22.f, 2.f-lineSpacing);
        glVertex2i(-22.f, 2.f-lineSpacing);
        glEnd();
        glEnable(GL_TEXTURE_2D);

        if (table->IsHighlightRow(row))
            glColor3ub(255, 128, 128);
        else
            glColor3ub(255, 255, 255);

        if (table->GetChild(row))
        {
            glPushMatrix();
            glTranslatef( -15.0f, 0.0f, 0.0f );
            glwprintf(L"%d", currentExpandId);
            glPopMatrix();
            currentExpandId++;
        }

        for(size_t col = 0; col < columns.size(); ++col)
        {
            CStr text = table->GetCellText(row, col);
            int w, h;
            font.CalculateStringSize(text.FromUTF8(), w, h);
            glPushMatrix();
            if (col > 0) // right-align all but the first column
                glTranslatef(columns[col].width - w, 0, 0);
            glwprintf(L"%hs", text.c_str());
            glPopMatrix();
            glTranslatef(columns[col].width, 0, 0);
        }

        glPopMatrix();
        glTranslatef( 0.0f, lineSpacing, 0.0f );
    }
    glColor3ub(255, 255, 255);

    if (m->path.size() > 1)
    {
        glTranslatef( 0.0f, lineSpacing, 0.0f );
        glPushMatrix();
        glPushMatrix();
        glTranslatef( -15.0f, 0.0f, 0.0f );
        glwprintf( L"0" );
        glPopMatrix();
        glwprintf( L"back to parent" );
        glPopMatrix();
    }

    glPopMatrix();

    glDisable(GL_BLEND);
}
Ejemplo n.º 3
0
// Render
void CProfileViewer::RenderProfile()
{
	if (!m->profileVisible)
		return;

	if (!m->path.size())
	{
		m->profileVisible = false;
		return;
	}

	PROFILE3_GPU("profile viewer");

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	AbstractProfileTable* table = m->path[m->path.size() - 1];
	const std::vector<ProfileColumn>& columns = table->GetColumns();
	size_t numrows = table->GetNumberRows();

	CStrIntern font_name("mono-stroke-10");
	CFontMetrics font(font_name);
	int lineSpacing = font.GetLineSpacing();

	// Render background
	GLint estimate_height;
	GLint estimate_width;

	estimate_width = 50;
	for(size_t i = 0; i < columns.size(); ++i)
		estimate_width += (GLint)columns[i].width;

	estimate_height = 3 + (GLint)numrows;
	if (m->path.size() > 1)
		estimate_height += 2;
	estimate_height = lineSpacing*estimate_height;

	CShaderTechniquePtr solidTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
	solidTech->BeginPass();
	CShaderProgramPtr solidShader = solidTech->GetShader();

	solidShader->Uniform(str_color, 0.0f, 0.0f, 0.0f, 0.5f);

	CMatrix3D transform = GetDefaultGuiMatrix();
	solidShader->Uniform(str_transform, transform);

	float backgroundVerts[] = {
		(float)estimate_width, 0.0f,
		0.0f, 0.0f,
		0.0f, (float)estimate_height,
		0.0f, (float)estimate_height,
		(float)estimate_width, (float)estimate_height,
		(float)estimate_width, 0.0f
	};
	solidShader->VertexPointer(2, GL_FLOAT, 0, backgroundVerts);
	solidShader->AssertPointersBound();
	glDrawArrays(GL_TRIANGLES, 0, 6);

	transform.PostTranslate(22.0f, lineSpacing*3.0f, 0.0f);
	solidShader->Uniform(str_transform, transform);

	// Draw row backgrounds
	for (size_t row = 0; row < numrows; ++row)
	{
		if (row % 2)
			solidShader->Uniform(str_color, 1.0f, 1.0f, 1.0f, 0.1f);
		else
			solidShader->Uniform(str_color, 0.0f, 0.0f, 0.0f, 0.1f);

		float rowVerts[] = {
			-22.f, 2.f,
			estimate_width-22.f, 2.f,
			estimate_width-22.f, 2.f-lineSpacing,

			estimate_width-22.f, 2.f-lineSpacing,
			-22.f, 2.f-lineSpacing,
			-22.f, 2.f
		};
		solidShader->VertexPointer(2, GL_FLOAT, 0, rowVerts);
		solidShader->AssertPointersBound();
		glDrawArrays(GL_TRIANGLES, 0, 6);

		transform.PostTranslate(0.0f, lineSpacing, 0.0f);
		solidShader->Uniform(str_transform, transform);
	}

	solidTech->EndPass();

	// Print table and column titles

	CShaderTechniquePtr textTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
	textTech->BeginPass();

	CTextRenderer textRenderer(textTech->GetShader());
	textRenderer.Font(font_name);
	textRenderer.Color(1.0f, 1.0f, 1.0f);

	textRenderer.PrintfAt(2.0f, lineSpacing, L"%hs", table->GetTitle().c_str());

	textRenderer.Translate(22.0f, lineSpacing*2.0f, 0.0f);

	float colX = 0.0f;
	for (size_t col = 0; col < columns.size(); ++col)
	{
		CStrW text = columns[col].title.FromUTF8();
		int w, h;
		font.CalculateStringSize(text.c_str(), w, h);

		float x = colX;
		if (col > 0) // right-align all but the first column
			x += columns[col].width - w;
		textRenderer.Put(x, 0.0f, text.c_str());
		
		colX += columns[col].width;
	}

	textRenderer.Translate(0.0f, lineSpacing, 0.0f);

	// Print rows
	int currentExpandId = 1;

	for (size_t row = 0; row < numrows; ++row)
	{
		if (table->IsHighlightRow(row))
			textRenderer.Color(1.0f, 0.5f, 0.5f);
		else
			textRenderer.Color(1.0f, 1.0f, 1.0f);

		if (table->GetChild(row))
		{
			textRenderer.PrintfAt(-15.0f, 0.0f, L"%d", currentExpandId);
			currentExpandId++;
		}

		float colX = 0.0f;
		for (size_t col = 0; col < columns.size(); ++col)
		{
			CStrW text = table->GetCellText(row, col).FromUTF8();
			int w, h;
			font.CalculateStringSize(text.c_str(), w, h);

			float x = colX;
			if (col > 0) // right-align all but the first column
				x += columns[col].width - w;
			textRenderer.Put(x, 0.0f, text.c_str());

			colX += columns[col].width;
		}

		textRenderer.Translate(0.0f, lineSpacing, 0.0f);
	}

	textRenderer.Color(1.0f, 1.0f, 1.0f);

	if (m->path.size() > 1)
	{
		textRenderer.Translate(0.0f, lineSpacing, 0.0f);
		textRenderer.Put(-15.0f, 0.0f, L"0");
		textRenderer.Put(0.0f, 0.0f, L"back to parent");
	}

	textRenderer.Render();
	textTech->EndPass();

	glDisable(GL_BLEND);

	glEnable(GL_DEPTH_TEST);
}