Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2013-01-28 05:26:36 +0400
committerDalai Felinto <dfelinto@gmail.com>2013-01-28 05:26:36 +0400
commit3a1ee13278b21176482b98d86709a3bdd489d531 (patch)
treecc2eedec28b5e8bba5062db0fedf5d07930e5efc /source
parentf64124cb781fee2366f1c5db4f0068420f874556 (diff)
BGE Profile : visual feedback bars and improvements
You can see a screenshot of the funcionality here: http://wiki.blender.org/index.php/Doc:2.6/manual/Game_Engine/Performance/Display/Framerate_and_Profile This patch creates a bar-like graph to quickly allow the game dev to see the performance changes. Also it changes the font to monospace (too allow ' ' padding) and reduced shadow border to match the blenderplayer one. Patch finalized and commited at Global Game Jam Vancouver (last one, time to sleep forever now)
Diffstat (limited to 'source')
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderGL.cpp56
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderGL.h1
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp10
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h7
-rw-r--r--source/gameengine/GamePlayer/common/GPC_RenderTools.cpp72
-rw-r--r--source/gameengine/GamePlayer/common/GPC_RenderTools.h6
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp8
-rw-r--r--source/gameengine/Rasterizer/RAS_IRenderTools.h16
8 files changed, 170 insertions, 6 deletions
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
index f8ad8870e83..3a9a10dd0cc 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
@@ -121,6 +121,50 @@ static void DisableForText()
}
}
+void BL_draw_gamedebug_box(int xco, int yco, int width, int height, float percentage)
+{
+ /* This is a rather important line :( The gl-mode hasn't been left
+ * behind quite as neatly as we'd have wanted to. I don't know
+ * what cause it, though :/ .*/
+ glDisable(GL_DEPTH_TEST);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glOrtho(0, width, 0, height, -100, 100);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ yco = height - yco;
+ int barsize = 50;
+
+ /* draw in black first*/
+ glColor3ub(0, 0, 0);
+ glBegin(GL_QUADS);
+ glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1 + 10);
+ glVertex2f(xco + 1, yco - 1 + 10);
+ glVertex2f(xco + 1, yco - 1);
+ glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1);
+ glEnd();
+
+ glColor3ub(255, 255, 255);
+ glBegin(GL_QUADS);
+ glVertex2f(xco + 1 + barsize * percentage, yco + 10);
+ glVertex2f(xco, yco + 10);
+ glVertex2f(xco, yco);
+ glVertex2f(xco + 1 + barsize * percentage, yco);
+ glEnd();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+ glEnable(GL_DEPTH_TEST);
+}
+
/* Print 3D text */
void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect)
{
@@ -164,7 +208,9 @@ void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int
/* the actual drawing */
glColor3ub(255, 255, 255);
- BLF_draw_default((float)xco, (float)(height-yco), 0.0f, (char *)text, 65535); /* XXX, use real len */
+ BLF_size(blf_mono_font, 11, 72);
+ BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
+ BLF_draw(blf_mono_font, (char *)text, 65535); /* XXX, use real len */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
@@ -193,9 +239,13 @@ void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int widt
/* draw in black first*/
glColor3ub(0, 0, 0);
- BLF_draw_default((float)(xco+2), (float)(height-yco-2), 0.0f, text, 65535); /* XXX, use real len */
+ BLF_size(blf_mono_font, 11, 72);
+ BLF_position(blf_mono_font, (float)xco+1, (float)(height-yco-1), 0.0f);
+ BLF_draw(blf_mono_font, (char *)text, 65535);/* XXX, use real len */
+
glColor3ub(255, 255, 255);
- BLF_draw_default((float)xco, (float)(height-yco), 0.0f, text, 65535); /* XXX, use real len */
+ BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
+ BLF_draw(blf_mono_font, (char *)text, 65535);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h
index 7ba612b19cf..5c3f0684764 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderGL.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h
@@ -50,6 +50,7 @@ void BL_HideMouse(struct wmWindow *win);
void BL_NormalMouse(struct wmWindow *win);
void BL_WaitMouse(struct wmWindow *win);
+void BL_draw_gamedebug_box(int xco, int yco, int width, int height, float percentage);
void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect);
void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height);
void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int width, int height);
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
index e32239b148d..64ed384e961 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
@@ -280,6 +280,16 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat
}
}
}
+
+void KX_BlenderRenderTools::RenderBox2D(int xco,
+ int yco,
+ int width,
+ int height,
+ float percentage)
+{
+ BL_draw_gamedebug_box(xco, yco, width, height, percentage);
+}
+
void KX_BlenderRenderTools::RenderText3D(int fontid,
const char* text,
int size,
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
index 7195524ceae..228763e7d2d 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
@@ -71,6 +71,13 @@ public:
void DisableOpenGLLights();
void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat);
+ void RenderBox2D(int xco,
+ int yco,
+ int width,
+ int height,
+ float percentage);
+
+
void RenderText3D(int fontid,
const char* text,
int size,
diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
index dfc866526eb..bab4aa14bbd 100644
--- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
+++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
@@ -283,6 +283,78 @@ void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,in
}
}
+void GPC_RenderTools::RenderBox2D(int xco,
+ int yco,
+ int width,
+ int height,
+ float percentage)
+{
+ // Save and change OpenGL settings
+ int texture2D;
+ glGetIntegerv(GL_TEXTURE_2D, (GLint*)&texture2D);
+ glDisable(GL_TEXTURE_2D);
+ int fog;
+ glGetIntegerv(GL_FOG, (GLint*)&fog);
+ glDisable(GL_FOG);
+
+ int light;
+ glGetIntegerv(GL_LIGHTING, (GLint*)&light);
+ glDisable(GL_LIGHTING);
+
+ glDisable(GL_DEPTH_TEST);
+
+ // Set up viewing settings
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(0, width, 0, height, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ yco = height - yco;
+ int barsize = 50;
+
+ // draw in black first
+ glColor3ub(0, 0, 0);
+ glBegin(GL_QUADS);
+ glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1 + 10);
+ glVertex2f(xco + 1, yco - 1 + 10);
+ glVertex2f(xco + 1, yco - 1);
+ glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1);
+ glEnd();
+
+ glColor3ub(255, 255, 255);
+ glBegin(GL_QUADS);
+ glVertex2f(xco + 1 + barsize * percentage, yco + 10);
+ glVertex2f(xco, yco + 10);
+ glVertex2f(xco, yco);
+ glVertex2f(xco + 1 + barsize * percentage, yco);
+ glEnd();
+
+ // Restore view settings
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ // Restore OpenGL Settings
+ if (fog)
+ glEnable(GL_FOG);
+ else
+ glDisable(GL_FOG);
+
+ if (texture2D)
+ glEnable(GL_TEXTURE_2D);
+ else
+ glDisable(GL_TEXTURE_2D);
+ if (light)
+ glEnable(GL_LIGHTING);
+ else
+ glDisable(GL_LIGHTING);
+}
+
+
void GPC_RenderTools::RenderText3D( int fontid,
const char* text,
int size,
diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.h b/source/gameengine/GamePlayer/common/GPC_RenderTools.h
index 1030c09548a..f4dcddd3250 100644
--- a/source/gameengine/GamePlayer/common/GPC_RenderTools.h
+++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.h
@@ -70,6 +70,12 @@ public:
void DisableOpenGLLights();
void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat);
+ void RenderBox2D(int xco,
+ int yco,
+ int width,
+ int height,
+ float percentage);
+
void RenderText3D(int fontid,
const char* text,
int size,
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 0ddac9c897a..23419f11cd5 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -1446,7 +1446,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
int xcoord = 12; // mmmm, these constants were taken from blender source
int ycoord = 17; // to 'mimic' behavior
- int profile_indent = 64;
+ int profile_indent = 72;
float tottime = m_logger->GetAverage();
if (tottime < 1e-6f) {
@@ -1481,7 +1481,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
m_canvas->GetWidth() /* RdV, TODO ?? */,
m_canvas->GetHeight() /* RdV, TODO ?? */);
- debugtxt.Format("%5.1fms (%5.1f fps)", tottime * 1000.f, 1.0/tottime);
+ debugtxt.Format("%5.1fms (%.1ffps)", tottime * 1000.f, 1.0/tottime);
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
debugtxt.ReadPtr(),
xcoord + const_xindent + profile_indent,
@@ -1504,12 +1504,14 @@ void KX_KetsjiEngine::RenderDebugProperties()
double time = m_logger->GetAverage((KX_TimeCategory)j);
- debugtxt.Format("%5.2fms (%2d%%)", time*1000.f, (int)(time/tottime * 100.f));
+ debugtxt.Format("%5.2fms | %d%%", time*1000.f, (int)(time/tottime * 100.f));
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
debugtxt.ReadPtr(),
xcoord + const_xindent + profile_indent, ycoord,
m_canvas->GetWidth(),
m_canvas->GetHeight());
+
+ m_rendertools->RenderBox2D(xcoord + (int)(2.2 * profile_indent), ycoord, m_canvas->GetWidth(), m_canvas->GetHeight(), time/tottime);
ycoord += const_ysize;
}
}
diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h
index bccda634222..6131abc0650 100644
--- a/source/gameengine/Rasterizer/RAS_IRenderTools.h
+++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h
@@ -100,6 +100,22 @@ public:
double* oglmatrix,
int drawingmode
)=0;
+
+ /**
+ * Renders 2D boxes.
+ * \param xco Position on the screen (origin in lower left corner).
+ * \param yco Position on the screen (origin in lower left corner).
+ * \param width Width of the canvas to draw to.
+ * \param height Height of the canvas to draw to.
+ * \param percentage Percentage of bar.
+ */
+ virtual
+ void
+ RenderBox2D(int xco,
+ int yco,
+ int width,
+ int height,
+ float percentage) = 0;
/**
* Renders 3D text string using BFL.