Browse Source

added a way to get information about the amount of draw calls

its under the custom frame control features as its done automatically per default if no custom frame control is chosen
accessor exist so it can be adapted to custom frame control
pull/4600/head
gk646 4 days ago
parent
commit
2ad2ac55ca
3 changed files with 32 additions and 3 deletions
  1. +2
    -1
      src/raylib.h
  2. +9
    -1
      src/rcore.c
  3. +21
    -1
      src/rlgl.h

+ 2
- 1
src/raylib.h View File

@ -1088,6 +1088,7 @@ RLAPI int GetFPS(void); // Get current
RLAPI void SwapScreenBuffer(void); // Swap back buffer with front buffer (screen drawing)
RLAPI void PollInputEvents(void); // Register all input events
RLAPI void WaitTime(double seconds); // Wait for some time (halt program execution)
RLAPI int GetDrawCalls(void); // Returns draw calls made during the last tick
// Random values generation functions
RLAPI void SetRandomSeed(unsigned int seed); // Set the seed for the random number generator
@ -1710,4 +1711,4 @@ RLAPI void DetachAudioMixedProcessor(AudioCallback processor); // Detach audio s
}
#endif
#endif // RAYLIB_H
#endif // RAYLIB_H

+ 9
- 1
src/rcore.c View File

@ -955,6 +955,7 @@ void EndDrawing(void)
CORE.Time.frame += waitTime; // Total frame time: update + draw + wait
}
rlSwapDrawCallsCounter();
PollInputEvents(); // Poll user events (before next frame update)
#endif
@ -1754,6 +1755,13 @@ void WaitTime(double seconds)
#endif
}
// Returns the draw calls of the previous tick
// This is because we don't know the full count until the current tick ends
int GetDrawCalls(void)
{
return rlGetPreviousDrawCalls();
}
//----------------------------------------------------------------------------------
// Module Functions Definition: Misc
//----------------------------------------------------------------------------------
@ -4076,4 +4084,4 @@ const char *TextFormat(const char *text, ...)
return currentBuffer;
}
#endif // !SUPPORT_MODULE_RTEXT
#endif // !SUPPORT_MODULE_RTEXT

+ 21
- 1
src/rlgl.h View File

@ -718,6 +718,8 @@ RLAPI int rlGetFramebufferHeight(void); // Get default framebuff
RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id
RLAPI unsigned int rlGetShaderIdDefault(void); // Get default shader id
RLAPI int *rlGetShaderLocsDefault(void); // Get default shader locations
RLAPI int rlGetPreviousDrawCalls(void); // Get previous ticks draw calls
RLAPI void rlSwapDrawCallsCounter(void); // Swap previous with current draw calls (marks end of a tick)
// Render batch management
// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
@ -1087,6 +1089,8 @@ typedef struct rlglData {
int framebufferWidth; // Current framebuffer width
int framebufferHeight; // Current framebuffer height
int currentDrawCalls; // Draw calls made in the current tick (might be incomplete)
int previousDrawCalls; // Draw calls made during the last tick
} State; // Renderer state
struct {
@ -1110,6 +1114,7 @@ typedef struct rlglData {
float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f)
int maxDepthBits; // Maximum bits for depth component
} ExtSupported; // Extensions supported flags
} rlglData;
@ -2724,6 +2729,20 @@ int *rlGetShaderLocsDefault(void)
return locs;
}
// Get previous ticks draw calls
RLAPI int rlGetPreviousDrawCalls(void)
{
return RLGL.State.previousDrawCalls;
}
// Swap previous with current draw calls (marks end of a tick)
RLAPI void rlSwapDrawCallsCounter(void)
{
RLGL.State.previousDrawCalls = RLGL.State.currentDrawCalls;
RLGL.State.currentDrawCalls = 0; // Reset counter
}
// Render batch management
//------------------------------------------------------------------------------------------------
// Load render batch
@ -2983,6 +3002,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
// Draw buffers
if (RLGL.State.vertexCounter > 0)
{
RLGL.State.currentDrawCalls++;
// Set current shader and upload current MVP matrix
glUseProgram(RLGL.State.currentShaderId);
@ -5266,4 +5286,4 @@ static Matrix rlMatrixInvert(Matrix mat)
return result;
}
#endif // RLGL_IMPLEMENTATION
#endif // RLGL_IMPLEMENTATION

Loading…
Cancel
Save