Beispiel #1
0
    def bindProgram(self):
        GLTools.checkForGLError()

        if self.needsCompile():
            self.unbindProgram()
            self.compileProgram()

        if not self.needsCompile():
            glUseProgram(self.__program_object)
            GLTools.checkForGLError()
    def uploadData(self):
        glBindBuffer(GL_ARRAY_BUFFER, self.__vertex_buffer_object)
        buffer = numpy.array(self.__vertices, dtype="f")
        glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW)

        glBindBuffer(GL_ARRAY_BUFFER, self.__texture_buffer_object)
        buffer = numpy.array(self.__texture_coordinates, dtype="f")
        glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW)

        self.__data_changed = False
        GLTools.checkForGLError()
Beispiel #3
0
    def uploadData(self):
        glBindBuffer(GL_ARRAY_BUFFER, self.__vertex_buffer_object)
        buffer = numpy.array(self.__vertices, dtype="f")
        glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW)

        glBindBuffer(GL_ARRAY_BUFFER, self.__texture_buffer_object)
        buffer = numpy.array(self.__texture_coordinates, dtype="f")
        glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW)

        self.__data_changed = False
        GLTools.checkForGLError()
Beispiel #4
0
    def bind(self):
        glEnable(GL_TEXTURE_1D)

        if self.__texture_reference is None:
            self.createTexture()

        if self.__data_changed:
            self.uploadData()


        glBindTexture(GL_TEXTURE_1D, self.__texture_reference)
        GLTools.checkForGLError()
Beispiel #5
0
    def bind(self):
        glEnable(GL_TEXTURE_3D)

        if self.__texture_reference is None:
            self.createTexture()

        if self.__data_changed:
            self.uploadData()


        glBindTexture(GL_TEXTURE_3D, self.__texture_reference)
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, self.__filter_mode)
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, self.__filter_mode) #GL_LINEAR or GL_NEAREST
        GLTools.checkForGLError()
Beispiel #6
0
    def createTexture(self):
        glEnable(GL_TEXTURE_1D)

        self.__texture_reference = glGenTextures(1)

        glBindTexture(GL_TEXTURE_1D, self.__texture_reference)

        # glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, self.__wrap)
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) #GL_LINEAR or GL_NEAREST

        GLTools.checkForGLError()

        glTexImage1D(GL_TEXTURE_1D, 0, self.__internal_format, self.__width, 0, self.__pixel_format, self.__pixel_type, None)

        GLTools.checkForGLError()

        glBindTexture(GL_TEXTURE_1D, 0)
Beispiel #7
0
    def compileShader(self):
        if self.__shader_object is None:
            self.__shader_object = glCreateShader(self.__type)

        if self.needsCompile():
            with open(self.__shader_source, "r") as f:
                shader_code = f.read()

            glShaderSource(self.__shader_object, shader_code)
            GLTools.checkForGLError()

            glCompileShader(self.__shader_object)
            # self.checkForError()

            self.checkCompileStatus()

            if self.__compiled:
                self.__time_stamp = os.path.getmtime(self.__shader_source)
                print("Shader source '%s' compiled!" % self.__shader_source)
Beispiel #8
0
    def compileShader(self):
        if self.__shader_object is None:
            self.__shader_object = glCreateShader(self.__type)

        if self.needsCompile():
            with open(self.__shader_source, "r") as f:
                shader_code = f.read()

            glShaderSource(self.__shader_object, shader_code)
            GLTools.checkForGLError()

            glCompileShader(self.__shader_object)
            # self.checkForError()

            self.checkCompileStatus()

            if self.__compiled:
                self.__time_stamp = os.path.getmtime(self.__shader_source)
                print("Shader source '%s' compiled!" % self.__shader_source)
Beispiel #9
0
    def createTexture(self):
        glEnable(GL_TEXTURE_3D)

        self.__texture_reference = glGenTextures(1)

        glBindTexture(GL_TEXTURE_3D, self.__texture_reference)

        # glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)
        # glTexParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, [0, 0, 0, 0])
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, self.__filter_mode)
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, self.__filter_mode) #GL_LINEAR or GL_NEAREST

        GLTools.checkForGLError()

        glTexImage3D(GL_TEXTURE_3D, 0, self.__internal_format, self.__width, self.__height, self.__depth, 0, self.__pixel_format, self.__pixel_type, None)

        GLTools.checkForGLError()

        glBindTexture(GL_TEXTURE_3D, 0)
 def createVertexBufferObject(self):
     self.__vertex_buffer_object = glGenBuffers(1)
     self.__texture_buffer_object = glGenBuffers(1)
     GLTools.checkForGLError()
Beispiel #11
0
 def uploadData(self):
     glBindTexture(GL_TEXTURE_3D, self.__texture_reference)
     glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, self.__width, self.__height, self.__depth, self.__pixel_format, self.__pixel_type, self.__data)
     GLTools.checkForGLError()
     glBindTexture(GL_TEXTURE_3D, 0)
     self.__data_changed = False
Beispiel #12
0
 def createVertexBufferObject(self):
     self.__vertex_buffer_object = glGenBuffers(1)
     self.__texture_buffer_object = glGenBuffers(1)
     GLTools.checkForGLError()
Beispiel #13
0
 def unbindProgram(self):
     GLTools.checkForGLError()
     glUseProgram(0)
     GLTools.checkForGLError()