opengl.geometry: Pre-initialise texture uniforms.

This commit is contained in:
Rod Kay
2023-05-04 21:32:03 +10:00
parent eb17c310f1
commit 4ca946531a
14 changed files with 48 additions and 36 deletions

View File

@@ -274,7 +274,7 @@ is
overriding
procedure enable_Texture (Self : in Item)
procedure enable_Texture (Self : in out Item)
is
use GL,
GL.Binding,

View File

@@ -42,6 +42,6 @@ private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
procedure enable_Texture (Self : in out Item);
end openGL.Geometry.lit_colored_textured;

View File

@@ -288,7 +288,7 @@ is
overriding
procedure enable_Texture (Self : in Item)
procedure enable_Texture (Self : in out Item)
is
use GL,
GL.Binding,

View File

@@ -53,6 +53,6 @@ private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
procedure enable_Texture (Self : in out Item);
end openGL.Geometry.lit_colored_textured_skinned;

View File

@@ -246,7 +246,7 @@ is
overriding
procedure enable_Texture (Self : in Item)
procedure enable_Texture (Self : in out Item)
is
use GL,
GL.Binding,

View File

@@ -43,6 +43,6 @@ private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
procedure enable_Texture (Self : in out Item);
end openGL.Geometry.lit_textured;

View File

@@ -262,7 +262,7 @@ is
overriding
procedure enable_Texture (Self : in Item)
procedure enable_Texture (Self : in out Item)
is
use GL,
GL.Binding,

View File

@@ -52,6 +52,6 @@ private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
procedure enable_Texture (Self : in out Item);
end openGL.Geometry.lit_textured_skinned;

View File

@@ -3,21 +3,18 @@ with
openGL.Shader,
openGL.Program.lit,
openGL.Attribute,
openGL.Variable.uniform,
openGL.Texture,
openGL.Palette,
openGL.Tasks,
openGL.Errors,
GL.Binding,
GL.lean,
GL.Pointers,
ada.Strings.fixed,
Interfaces.C.Strings,
System.storage_Elements;
with ada.Text_IO; use ada.Text_IO;
-- with ada.Text_IO; use ada.Text_IO;
package body openGL.Geometry.lit_textured_x2
@@ -175,6 +172,7 @@ is
end if;
Self.Program_is (the_Program.all'Access);
return Self;
end new_Geometry;
@@ -324,7 +322,7 @@ is
overriding
procedure enable_Texture (Self : in Item)
procedure enable_Texture (Self : in out Item)
is
-- check_is_OK : constant Boolean := openGL.Tasks.Check
-- with unreferenced;

View File

@@ -61,6 +61,6 @@ private
overriding
procedure enable_Texture (Self : in Item);
procedure enable_Texture (Self : in out Item);
end openGL.Geometry.lit_textured_x2;

View File

@@ -164,7 +164,7 @@ is
overriding
procedure enable_Texture (Self : in Item)
procedure enable_Texture (Self : in out Item)
is
use GL,
GL.Binding,

View File

@@ -40,6 +40,6 @@ private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
procedure enable_Texture (Self : in out Item);
end openGL.Geometry.textured;

View File

@@ -157,7 +157,7 @@ is
procedure Texture_is (in_Set : in out texture_Set; Which : texture_ID; Now : in openGL.Texture.Object)
is
begin
in_Set.Textures (Which) := (0.0, Now);
in_Set.Textures (Which) := (0.0, Now, 0);
in_Set.is_Transparent := in_Set.is_Transparent
or Now .is_Transparent;
@@ -566,19 +566,18 @@ is
-- Textures
--
procedure enable (the_Textures : in texture_Set;
procedure enable (the_Textures : in out texture_Set;
Program : in openGL.Program.view)
is
use GL,
GL.Binding,
openGL.Texture;
-- check_is_OK : constant Boolean := openGL.Tasks.Check
-- with unreferenced;
begin
Tasks.check;
if not the_Textures.Initialised
then
for i in 1 .. the_Textures.Count
loop
declare
@@ -588,6 +587,22 @@ is
ada.Strings.fixed,
Interfaces;
uniform_Name : aliased C.char_array := C.to_C ("Textures[" & Trim (Natural'Image (i - 1), Left) & "]");
uniform_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (uniform_Name'unchecked_Access);
Id : constant texture_Id := texture_Id (i);
begin
the_Textures.Textures (Id).uniform_Location := glGetUniformLocation (Program.gl_Program, +uniform_Name_ptr);
end;
end loop;
the_Textures.Initialised := True;
end if;
for i in 1 .. the_Textures.Count
loop
declare
use GL.lean;
use type GL.GLint;
type texture_Units is array (texture_Id) of GLenum;
@@ -625,14 +640,11 @@ is
GL_TEXTURE30,
GL_TEXTURE31);
uniform_Name : aliased C.char_array := C.to_C ("Textures[" & Trim (Natural'Image (i - 1), Left) & "]");
uniform_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (uniform_Name'unchecked_Access);
loc : constant GL.GLint := glGetUniformLocation (Program.gl_Program, +uniform_Name_ptr);
Id : constant texture_Id := texture_Id (i);
begin
-- put_Line ("1-openGL.Program.lit.set_Uniforms:" & loc'Image);
glUniform1i (loc,
glUniform1i (the_Textures.Textures (Id).uniform_Location, -- loc,
GLint (i) - 1);
glActiveTexture (all_texture_Units (Id));

View File

@@ -64,6 +64,7 @@ is
record
Fade : fade_Level := 0.0;
Object : openGL.Texture.Object := openGL.Texture.null_Object;
uniform_Location : GL.GLint := 0;
end record;
type fadeable_Textures is array (texture_Id range 1 .. max_Textures) of fadeable_Texture;
@@ -73,9 +74,10 @@ is
Textures : fadeable_Textures;
Count : Natural := 0;
is_Transparent : Boolean := False; -- Any of the textures contains lucid colors.
Initialised : Boolean := False;
end record;
procedure enable (the_Textures : in texture_Set;
procedure enable (the_Textures : in out texture_Set;
Program : in openGL.Program.view);
procedure Texture_is (in_Set : in out texture_Set; Which : texture_ID; Now : in openGL.Texture.Object);
@@ -110,7 +112,7 @@ is
--
procedure render (Self : in out Item'Class);
procedure enable_Texture (Self : in Item) is null;
procedure enable_Texture (Self : in out Item) is null;
-----------