использование glCompressedTexImage2D AttributeError: ("модуль 'OpenGL.arrays' не имеет атрибута 'ArrayType'", "ошибка в cConverter - PullRequest
0 голосов
/ 08 июля 2019

Я получаю ошибку с функцией glCompressedTexImage2D.Вот сообщение об ошибке:

AttributeError: ("module 'OpenGL.arrays' has no attribute 'ArrayType'", 
'Failure in cConverter <OpenGL.GL.images.CompressedImageConverter object at 
0x7f15f16a9978>', (GL_TEXTURE_2D, 0, GL_COMPRESSED_RED_RGTC1, 512, 512, 0, 
131072.0), 6, <OpenGL.platform.baseplatform.glCompressedTexImage2D object at 
0x7f15f16ac7c8>)

ожидаемый вывод:

enter image description here

файлы поддержки: compressrgtc_support.zip

исходный код:

#!/usr/bin/python3

import sys
import time
import ctypes

fullscreen = True
sys.path.append("./shared")

from sbmloader import SBMObject    # location of sbm file format loader
from ktxloader import KTXObject    # location of ktx file format loader
from textoverlay import OVERLAY_
from shader import shader_load, link_from_shaders

from sbmath import m3dDegToRad, m3dRadToDeg, m3dTranslateMatrix44, m3dRotationMatrix44, \
    m3dMultiply, m3dOrtho, m3dPerspective, rotation_matrix, translate, m3dScaleMatrix44, \
    scale, m3dLookAt, normalize

try:
    from OpenGL.GLUT import *
    from OpenGL.GL import *
    from OpenGL.GLU import *
    #from OpenGL.raw.GL.ARB.vertex_array_object import glGenVertexArrays, glBindVertexArray
    from OpenGL.raw.GL.ARB.texture_compression_rgtc import *
except:
    print ('''
    ERROR: PyOpenGL not installed properly.
        ''')
    sys.exit()

import numpy as np
from math import cos, sin
import glm
identityMatrix = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]

myobject = SBMObject()
ktxobject = KTXObject()
overlay = OVERLAY_()

TEXTURE_WIDTH = 512
TEXTURE_HEIGHT = 512

compress_program = GLuint(0)
render_program = GLuint(0)
input_texture = GLuint(0)
output_texture = GLuint(0)
output_buffer = GLuint(0)
output_buffer_texture = GLuint(0)
dummy_vao = GLuint(0)

SHOW_INPUT = 0
SHOW_OUTPUT = 1
MAX_MODE = 2

display_mode = 0

def load_shaders():
    global compress_program
    global render_program

    glDeleteProgram(compress_program)
    glDeleteProgram(render_program)

    cs = GLuint(0)

    cs = shader_load("rgtccompress.cs.glsl", GL_COMPUTE_SHADER)

    compress_program = link_from_shaders(cs, 1, True)

    shaders = [GLuint(0) for _ in range(2)]

    shaders[0] = shader_load("drawquad.fs.glsl", GL_FRAGMENT_SHADER)
    shaders[1] = shader_load("drawquad.vs.glsl", GL_VERTEX_SHADER)

    render_program = link_from_shaders(shaders, 2, True)

class Scene:

    def __init__(self, width, height):
        global output_texture
        global output_buffer
        global output_buffer_texture
        global input_texture
        global dummy_vao

        self.width = width
        self.height = height


        input_texture = ktxobject.ktx_load("gllogodistsm.ktx")

        output_texture = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, output_texture)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

        output_buffer = glGenBuffers(1)
        glBindBuffer(GL_TEXTURE_BUFFER, output_buffer)
        glBufferStorage(GL_TEXTURE_BUFFER, TEXTURE_WIDTH * TEXTURE_HEIGHT // 2, None, GL_MAP_READ_BIT)

        output_buffer_texture = glGenTextures(1)
        glBindTexture(GL_TEXTURE_BUFFER, output_buffer_texture)
        glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32UI, output_buffer)

        load_shaders()

        glGenVertexArrays(1, dummy_vao)
        display_mode = SHOW_OUTPUT


    def display(self):

        currentTime = time.time()


        glClearBufferfv(GL_COLOR, 0, [0.0,0.0,0.0])

        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, input_texture)
        glBindImageTexture(0, output_buffer_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32UI)

        glUseProgram(compress_program)
        glDispatchCompute(TEXTURE_WIDTH // 4, TEXTURE_WIDTH // 4, 1)

        glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)

        ptr = glMapBufferRange(GL_TEXTURE_BUFFER, 0, TEXTURE_WIDTH * TEXTURE_HEIGHT // 2, GL_MAP_READ_BIT)

        glUnmapBuffer(GL_TEXTURE_BUFFER)

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, output_buffer)
        glBindTexture(GL_TEXTURE_2D, output_texture)
        glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RED_RGTC1, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, TEXTURE_WIDTH * TEXTURE_HEIGHT // 2, None)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

        glViewport(0, 0, self.width, self.height)

        glBindVertexArray(dummy_vao)
        glUseProgram(render_program)

        if (display_mode == SHOW_INPUT):
            glBindTexture(GL_TEXTURE_2D, input_texture)

        elif (display_mode == SHOW_OUTPUT):
            glBindTexture(GL_TEXTURE_2D, output_texture)


        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)

        glutSwapBuffers()

    def reshape(self, width, height):
        self.width = width
        self.height = height

    def keyboard(self, key, x, y ):
        global fullscreen

        print ('key:' , key)
        if key == b'\x1b': # ESC
            sys.exit()

        elif key == b'f' or key == b'F': #fullscreen toggle
            if (fullscreen == True):
                glutReshapeWindow(512, 512)
                glutPositionWindow(int((1360/2)-(512/2)), int((768/2)-(512/2)))
                fullscreen = False
            else:
                glutFullScreen()
                fullscreen = True

    def init(self):
        pass

    def timer(self, blah):
        glutPostRedisplay()
        glutTimerFunc( int(1/60), self.timer, 0)
        time.sleep(1/60.0)

if __name__ == '__main__':
    glutInit()
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
    glutInitWindowSize(512, 512)

    #glutInitContextVersion(4,1)
    #glutInitContextProfile(GLUT_CORE_PROFILE)    

    w1 = glutCreateWindow('OpenGL SuperBible - RGTC Compressor')
    glutInitWindowPosition(int((1360/2)-(512/2)), int((768/2)-(512/2)))
    fullscreen = False
    #glutFullScreen()
    scene = Scene(512,512)
    glutReshapeFunc(scene.reshape)
    glutDisplayFunc(scene.display)
    glutKeyboardFunc(scene.keyboard)
    glutIdleFunc(scene.display)
    #glutTimerFunc( int(1/60), scene.timer, 0)
    scene.init()
    glutMainLoop()

перенесен из: compressrgtc.cpp из Superbible 7-е изд.p.575

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...