Advertisement
matyklug

Untitled

Jul 10th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. //Warinig: works only with JOML
  2. public <T> void setUniform(String name, T data) {
  3.         T t = data;
  4.         if(t instanceof Float) {
  5.             float tt;
  6.             tt = (float)t;
  7.             GL20.glUniform1f(getUniLoc(name),tt);
  8.         } else if(t instanceof Integer) {
  9.             int tt;
  10.             tt = (Integer)t;
  11.             GL20.glUniform1i(getUniLoc(name),tt);
  12.         } else if(t instanceof Boolean) {
  13.             Boolean tt;
  14.             tt = (Boolean)t;
  15.             GL20.glUniform1i(getUniLoc(name),tt ? 1 : 0);
  16.         } else if(t instanceof Vector2f) {
  17.             Vector2f tt;
  18.             tt = (Vector2f)t;
  19.             GL20.glUniform2f(getUniLoc(name),tt.x, tt.y);
  20.         } else if(t instanceof Vector3f) {
  21.             Vector3f tt;
  22.             tt = (Vector3f)t;
  23.             GL20.glUniform3f(getUniLoc(name),tt.x, tt.y, tt.z);
  24.         } else if(t instanceof Matrix4f) {
  25.             Matrix4f tt;
  26.             tt = (Matrix4f)t;
  27.             float[] arr = {
  28.                 tt.m00(),tt.m01(),tt.m02(),tt.m03(),
  29.                 tt.m10(),tt.m11(),tt.m12(),tt.m13(),
  30.                 tt.m20(),tt.m21(),tt.m22(),tt.m23(),
  31.                 tt.m30(),tt.m31(),tt.m32(),tt.m33()
  32.             };
  33.            
  34.             FloatBuffer buff = MemoryUtil.memAllocFloat(arr.length);
  35.             buff.put(arr);
  36.             buff.flip();
  37.             GL20.glUniformMatrix4fv(getUniLoc(name), true, buff);
  38.         }
  39.        
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement