opengl.errors: Use new 'Debugging' function to optimise out error checks when not building in 'debug' mode.

This commit is contained in:
Rod Kay
2024-04-24 19:20:07 +10:00
parent 5860ed71fb
commit 55099f4991

View File

@@ -3,6 +3,7 @@ with
GL.Binding, GL.Binding,
ada.Text_IO; ada.Text_IO;
package body openGL.Errors package body openGL.Errors
is is
use GL; use GL;
@@ -10,11 +11,16 @@ is
function Current return String function Current return String
is is
begin
if Debugging
then
declare
use GL.Binding; use GL.Binding;
check_is_OK : constant Boolean := openGL.Tasks.Check; pragma Unreferenced (check_is_OK); check_is_OK : constant Boolean := openGL.Tasks.Check; pragma Unreferenced (check_is_OK);
the_Error : constant GL.GLenum := glGetError; the_Error : constant GL.GLenum := glGetError;
begin begin
case the_Error is case the_Error
is
when GL.GL_NO_ERROR => return "no error"; when GL.GL_NO_ERROR => return "no error";
when GL_INVALID_ENUM => return "invalid Enum"; when GL_INVALID_ENUM => return "invalid Enum";
when GL_INVALID_VALUE => return "invalid Value"; when GL_INVALID_VALUE => return "invalid Value";
@@ -22,12 +28,20 @@ is
when GL_OUT_OF_MEMORY => return "out of Memory"; when GL_OUT_OF_MEMORY => return "out of Memory";
when others => return "unknown openGL error detected (Code:" & the_Error'Image & ")"; when others => return "unknown openGL error detected (Code:" & the_Error'Image & ")";
end case; end case;
end;
end if;
return "";
end Current; end Current;
procedure log (Prefix : in String := "") procedure log (Prefix : in String := "")
is is
begin
if Debugging
then
declare
current_Error : constant String := Current; current_Error : constant String := Current;
function Error_Message return String function Error_Message return String
@@ -46,12 +60,18 @@ is
end if; end if;
raise openGL.Error with Error_Message; raise openGL.Error with Error_Message;
end;
end if;
end log; end log;
procedure log (Prefix : in String := ""; Error_occurred : out Boolean) procedure log (Prefix : in String := ""; Error_occurred : out Boolean)
is is
begin
if Debugging
then
declare
use ada.Text_IO; use ada.Text_IO;
current_Error : constant String := Current; current_Error : constant String := Current;
begin begin
@@ -67,6 +87,8 @@ is
then put_Line ("openGL error: '" & current_Error & "'"); then put_Line ("openGL error: '" & current_Error & "'");
else put_Line (Prefix & ": '" & current_Error & "'"); else put_Line (Prefix & ": '" & current_Error & "'");
end if; end if;
end;
end if;
end log; end log;