Class Shader

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String SHADERS_LOCATION
      Default location of the glsl shader files
    • Constructor Summary

      Constructors 
      Constructor Description
      Shader()
      Creates new Shader and creating shader program in opengl
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addShader​(String[] shaderCode, int shaderType, String name)
      Adding new shader from sourcecode to the program
      protected abstract void addShaders()
      Adding shaders to program
      protected abstract void bindAttribs()
      Binding all vbo attributes to shader attribute ("in" variable)
      protected void bindAttribute​(int attrib, String name)
      Binding an attribute from a vbo to an 'in' variable in the shader programm
      protected void bindTexture​(int texture, int unit, int type)
      Binding texture to an opengl textureunit
      protected void bindTextureUnit​(String uniform, int unit)
      Binding uniform variable to opengl texture unit
      protected int getUniformLocation​(String uniform)
      Getting location of anshader uniform variable
      protected abstract void loadUniforms()
      Loading uniform locations
      protected void setUniform​(int location, boolean value)
      Loading a boolean into a uniform variable
      protected void setUniform​(int location, float value)
      Loading a float into a uniform variable
      protected void setUniform​(int location, float[] matrix)
      Loading a 4x4 matrix into a uniform variable
      protected void setUniform​(int location, float x, float y)
      Loading a 2d vector into a uniform variable
      protected void setUniform​(int location, float x, float y, float z)
      Loading a 3d vector into a uniform variable
      protected void setUniform​(int location, float x, float y, float z, float w)
      Loading a 4d vector into a uniform variable
      protected void setUniform​(int location, int value)
      Loading an int into a uniform variable
      protected void setUniform​(int location, Color col)
      Loading a color into a uniform vec3f variable
      protected void setUniformArray1f​(int location, float[] floats)
      Loading a float array into a uniform variable
      protected void setUniformArray1i​(int location, int[] ints)
      Loading a int array into a uniform variable
      protected void setUniformArray2f​(int location, float[] floats)
      Loading a vec2 array into a uniform variable
      protected void setUniformArray3f​(int location, float[] floats)
      Loading a vec3 array into a uniform variable
      void start()
      Starting/enable shaderprogram
      void stop()
      Stopping/disable shaderprogram (use 0)
    • Field Detail

      • SHADERS_LOCATION

        public static final String SHADERS_LOCATION
        Default location of the glsl shader files
        See Also:
        Constant Field Values
    • Constructor Detail

      • Shader

        public Shader()
        Creates new Shader and creating shader program in opengl
    • Method Detail

      • addShader

        protected final void addShader​(String[] shaderCode,
                                       int shaderType,
                                       String name)
        Adding new shader from sourcecode to the program
        Parameters:
        shaderCode - String that contains the shader source code
        shaderType - Type of the shader (vs, fs, geo, tes, tcs, cs)
        name - Pseudonym name of the shader for faster error detection
      • getUniformLocation

        protected final int getUniformLocation​(String uniform)
        Getting location of anshader uniform variable
        Parameters:
        uniform - Uniform variable name in shader code
        Returns:
        Uniforms location
      • bindAttribute

        protected final void bindAttribute​(int attrib,
                                           String name)
        Binding an attribute from a vbo to an 'in' variable in the shader programm
        Parameters:
        attrib - Vbos attrib to bind (row)
        name - 'in' Variable name in shader code
      • bindTextureUnit

        protected final void bindTextureUnit​(String uniform,
                                             int unit)
        Binding uniform variable to opengl texture unit
        Parameters:
        uniform - Uniform variable name in shader code
        unit - Opengl texture unit id
      • addShaders

        protected abstract void addShaders()
        Adding shaders to program
      • bindAttribs

        protected abstract void bindAttribs()
        Binding all vbo attributes to shader attribute ("in" variable)
      • loadUniforms

        protected abstract void loadUniforms()
        Loading uniform locations
      • start

        public void start()
        Starting/enable shaderprogram
      • stop

        public void stop()
        Stopping/disable shaderprogram (use 0)
      • setUniform

        protected final void setUniform​(int location,
                                        boolean value)
        Loading a boolean into a uniform variable
        Parameters:
        location - Location of the uniform variable
        value - Boolean to load
      • setUniform

        protected final void setUniform​(int location,
                                        float value)
        Loading a float into a uniform variable
        Parameters:
        location - Location of the uniform variable
        value - Float to load
      • setUniform

        protected final void setUniform​(int location,
                                        int value)
        Loading an int into a uniform variable
        Parameters:
        location - Location of the uniform variable
        value - Int to load
      • setUniform

        protected final void setUniform​(int location,
                                        float x,
                                        float y)
        Loading a 2d vector into a uniform variable
        Parameters:
        location - Location of the uniform variable
        x - First value of the vector
        y - Second value of the vector
      • setUniform

        protected final void setUniform​(int location,
                                        float x,
                                        float y,
                                        float z)
        Loading a 3d vector into a uniform variable
        Parameters:
        location - Location of the uniform variable
        x - First value of the vector
        y - Second value of the vector
        z - Third value ofthe vector
      • setUniform

        protected final void setUniform​(int location,
                                        float x,
                                        float y,
                                        float z,
                                        float w)
        Loading a 4d vector into a uniform variable
        Parameters:
        location - Location of the uniform variable
        x - First value of the vector
        y - Second value of the vector
        z - Third value ofthe vector
        w - Fourth value of the vector
      • setUniform

        protected final void setUniform​(int location,
                                        float[] matrix)
        Loading a 4x4 matrix into a uniform variable
        Parameters:
        location - Location of the uniform variable
        matrix - 4x4 matrix to load as float array
      • setUniformArray3f

        protected final void setUniformArray3f​(int location,
                                               float[] floats)
        Loading a vec3 array into a uniform variable
        Parameters:
        location - Location of the uniform variable
        floats - float array to use (x0,y0,z0,x1,y1,z1,x2,...)
      • setUniformArray2f

        protected final void setUniformArray2f​(int location,
                                               float[] floats)
        Loading a vec2 array into a uniform variable
        Parameters:
        location - Location of the uniform variable
        floats - float array to use (x0,y0,x1,y1,x2,...)
      • setUniformArray1f

        protected final void setUniformArray1f​(int location,
                                               float[] floats)
        Loading a float array into a uniform variable
        Parameters:
        location - Location of the uniform variable
        floats - float array to use (x0,x1,x2,...)
      • setUniformArray1i

        protected final void setUniformArray1i​(int location,
                                               int[] ints)
        Loading a int array into a uniform variable
        Parameters:
        location - Location of the uniform variable
        ints - int array to use (x0,x1,x2,...)
      • setUniform

        protected final void setUniform​(int location,
                                        Color col)
        Loading a color into a uniform vec3f variable
        Parameters:
        location - Location of the uniform variable
        col - color to load as vec3f
      • bindTexture

        protected final void bindTexture​(int texture,
                                         int unit,
                                         int type)
        Binding texture to an opengl textureunit
        Parameters:
        texture - TextureData to bind
        unit - Textureunit to bind texture to
        type - TextureData type (GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, ...)