# Path: PyOpenGLng/Wrapper/PythonicWrapper.py
# class PythonicWrapper(object):
# 
#     _logger = _module_logger.getChild('PythonicWrapper')
# 
#     ##############################################
# 
#     def glGetActiveUniformBlockiv(self, program, index, pname):
# 
#         """ Query information about an active uniform block. """
# 
#         # Check index
#         number_of_uniform_blocks = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORM_BLOCKS)
#         # if not(0 <= index < number_of_uniform_blocks):
#         if index < 0 or index >= number_of_uniform_blocks:
#             raise IndexError('Index %s out of range 0 to %i' % (index, number_of_uniform_blocks -1))
# 
#         if pname != self.GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
#             array_size = 1
#         else:
#             array_size = self.glGetActiveUniformBlockiv(program, index, self.GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS)
#         params = np.zeros(array_size, dtype=np.int32)
# 
#         self.commands.glGetActiveUniformBlockiv(program, index, pname, params)
# 
#         if array_size > 1: 
#             return list(params)
#         else:
#             return params[0]
# 
#     ##############################################
# 
#     def glGetActiveUniformBlockName(self, program, index):
# 
#         """ Retrieve the name of an active uniform block. """
# 
#         number_of_uniform_blocks = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORM_BLOCKS)
#         if index < 0 or index >= number_of_uniform_blocks:
#             raise IndexError("Index %s out of range 0 to %i" % (index, number_of_uniform_blocks -1))
# 
#         max_name_length = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH)
#         name, name_length = self.commands.glGetActiveUniformBlockName(program, index, max_name_length)
#         return name
# 
#     ##############################################    
# 
#     def glGetActiveUniformsiv(self, program, indices, pname):
# 
#         """ Returns information about several active uniform variables for the specified program
#         object.
#         """
# 
#         try:
#             indices = list(indices)
#         except TypeError:
#             indices = (indices,)
# 
#         number_of_uniform_blocks = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORMS)
#         for index in indices:
#             if index < 0 or index >= number_of_uniform_blocks:
#                 raise IndexError('Index %s out of range 0 to %i' % (index, number_of_uniform_blocks -1))
# 
#         gl_indices = np.array(indices, dtype=np.uint32)
#         params = np.zeros(len(indices), dtype=np.int32)
# 
#         self.commands.glGetActiveUniformsiv(program, len(indices), gl_indices, pname, params)
# 
#         if len(indices) > 1:
#             return list(params)
#         else:
#             return params[0]
# 
#     ##############################################    
#     
#     def glGetProgram(self, program, pname):
# 
#         self._logger.info("Use commands_dict")
# 
#         dtype, size = Getter.commands_dict['glGetProgram'][pname]
# 
#         command_wrapper = self.commands.glGetProgramiv
# 
#         # dtype is imposed by command
#         # size is COMPSIZE
#         # can we accelerate wrapper ??? overhead versus ctype pointer
#         #  pass size
#         dtype, size = command_wrapper._getter[pname]
#         data = np.zeros(size, dtype=dtype)
#         command_wrapper(program, pname, data)
#         data = data.tolist()
#         if size == 1:
#             return data[0]
#         else:
#             return data
# 
#     ##############################################    
#     
#     def glGetProgramiv(self, program, pname):
# 
#         self._logger.info("Use commands_dict")
# 
#         command_wrapper = self.commands.glGetProgramiv
#         # dtype is imposed by command
#         # size is COMPSIZE
#         # can we accelerate wrapper ??? overhead versus ctype pointer
#         #  pass size
#         dtype, size = command_wrapper._getter[pname]
#         data = np.zeros(size, dtype=dtype)
#         command_wrapper(program, pname, data)
#         data = data.tolist()
#         if size == 1:
#             return data[0]
#         else:
#             return data
# 
#     ##############################################    
# 
#     def glGetShaderiv(self, program, pname):
# 
#         # Fixme: cf. infra
#         data = np.zeros(1, dtype=np.int32)
#         self.commands.glGetShaderiv(program, pname, data)
#         return int(data[0])
# 
#     ##############################################
# 
#     def glGetString(self, *args, **kwargs):
# 
#         # Fixme:
#         value = self.commands.glGetString(*args, **kwargs)
#         if value is not None:
#             return value.decode('ascii')
#         else:
#             return value


import collections
import ctypes
import logging
import os
import subprocess
import sys
import types
import numpy as np
import PyOpenGLng.Config as Config
from cffi import FFI
from .PythonicWrapper import PythonicWrapper
            # store enumerants and commands at the same level
            setattr(self, enum_name, enum_value)
            # store enumerants in a dedicated place
            setattr(gl_enums, enum_name, enum_value)
        self.enums = gl_enums

    ##############################################

    def _reload_library(self, api_commands):

        api_definition = ''
        for command in api_commands.values():
            prototype = command.prototype(with_size=False)
            if 'GLDEBUGPROC' not in prototype and 'GLsync' not in prototype: # Fixme:
                api_definition += prototype + ';\n'
        ffi.cdef(api_definition, override=True)

    ##############################################

    def _init_commands(self, api_commands):

        self._reload_library(api_commands)

        gl_commands = GlCommands()
        for command in api_commands.values():
            try:
                command_name = str(command)
                command_wrapper = GlCommandWrapper(self, command)
                # store enumerants and commands at the same level
                if hasattr(PythonicWrapper, command_name):

# Path: PyOpenGLng/Wrapper/PythonicWrapper.py
# class PythonicWrapper(object):
# 
#     _logger = _module_logger.getChild('PythonicWrapper')
# 
#     ##############################################
# 
#     def glGetActiveUniformBlockiv(self, program, index, pname):
# 
#         """ Query information about an active uniform block. """
# 
#         # Check index
#         number_of_uniform_blocks = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORM_BLOCKS)
#         # if not(0 <= index < number_of_uniform_blocks):
#         if index < 0 or index >= number_of_uniform_blocks:
#             raise IndexError('Index %s out of range 0 to %i' % (index, number_of_uniform_blocks -1))
# 
#         if pname != self.GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
#             array_size = 1
#         else:
#             array_size = self.glGetActiveUniformBlockiv(program, index, self.GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS)
#         params = np.zeros(array_size, dtype=np.int32)
# 
#         self.commands.glGetActiveUniformBlockiv(program, index, pname, params)
# 
#         if array_size > 1: 
#             return list(params)
#         else:
#             return params[0]
# 
#     ##############################################
# 
#     def glGetActiveUniformBlockName(self, program, index):
# 
#         """ Retrieve the name of an active uniform block. """
# 
#         number_of_uniform_blocks = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORM_BLOCKS)
#         if index < 0 or index >= number_of_uniform_blocks:
#             raise IndexError("Index %s out of range 0 to %i" % (index, number_of_uniform_blocks -1))
# 
#         max_name_length = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH)
#         name, name_length = self.commands.glGetActiveUniformBlockName(program, index, max_name_length)
#         return name
# 
#     ##############################################    
# 
#     def glGetActiveUniformsiv(self, program, indices, pname):
# 
#         """ Returns information about several active uniform variables for the specified program
#         object.
#         """
# 
#         try:
#             indices = list(indices)
#         except TypeError:
#             indices = (indices,)
# 
#         number_of_uniform_blocks = self.glGetProgramiv(program, self.GL_ACTIVE_UNIFORMS)
#         for index in indices:
#             if index < 0 or index >= number_of_uniform_blocks:
#                 raise IndexError('Index %s out of range 0 to %i' % (index, number_of_uniform_blocks -1))
# 
#         gl_indices = np.array(indices, dtype=np.uint32)
#         params = np.zeros(len(indices), dtype=np.int32)
# 
#         self.commands.glGetActiveUniformsiv(program, len(indices), gl_indices, pname, params)
# 
#         if len(indices) > 1:
#             return list(params)
#         else:
#             return params[0]
# 
#     ##############################################    
#     
#     def glGetProgram(self, program, pname):
# 
#         self._logger.info("Use commands_dict")
# 
#         dtype, size = Getter.commands_dict['glGetProgram'][pname]
# 
#         command_wrapper = self.commands.glGetProgramiv
# 
#         # dtype is imposed by command
#         # size is COMPSIZE
#         # can we accelerate wrapper ??? overhead versus ctype pointer
#         #  pass size
#         dtype, size = command_wrapper._getter[pname]
#         data = np.zeros(size, dtype=dtype)
#         command_wrapper(program, pname, data)
#         data = data.tolist()
#         if size == 1:
#             return data[0]
#         else:
#             return data
# 
#     ##############################################    
#     
#     def glGetProgramiv(self, program, pname):
# 
#         self._logger.info("Use commands_dict")
# 
#         command_wrapper = self.commands.glGetProgramiv
#         # dtype is imposed by command
#         # size is COMPSIZE
#         # can we accelerate wrapper ??? overhead versus ctype pointer
#         #  pass size
#         dtype, size = command_wrapper._getter[pname]
#         data = np.zeros(size, dtype=dtype)
#         command_wrapper(program, pname, data)
#         data = data.tolist()
#         if size == 1:
#             return data[0]
#         else:
#             return data
# 
#     ##############################################    
# 
#     def glGetShaderiv(self, program, pname):
# 
#         # Fixme: cf. infra
#         data = np.zeros(1, dtype=np.int32)
#         self.commands.glGetShaderiv(program, pname, data)
#         return int(data[0])
# 
#     ##############################################
# 
#     def glGetString(self, *args, **kwargs):
# 
#         # Fixme:
#         value = self.commands.glGetString(*args, **kwargs)
#         if value is not None:
#             return value.decode('ascii')
#         else:
#             return value


# Path: PyOpenGLng/Wrapper/CffiWrapper.py
import collections
import ctypes
import logging
import os
import subprocess
import sys
import types
import numpy as np
import PyOpenGLng.Config as Config
from cffi import FFI
from .PythonicWrapper import PythonicWrapper

            # store enumerants and commands at the same level
            setattr(self, enum_name, enum_value)
            # store enumerants in a dedicated place
            setattr(gl_enums, enum_name, enum_value)
        self.enums = gl_enums

    ##############################################

    def _reload_library(self, api_commands):

        api_definition = ''
        for command in api_commands.values():
            prototype = command.prototype(with_size=False)
            if 'GLDEBUGPROC' not in prototype and 'GLsync' not in prototype: # Fixme:
                api_definition += prototype + ';\n'
        ffi.cdef(api_definition, override=True)

    ##############################################

    def _init_commands(self, api_commands):

        self._reload_library(api_commands)

        gl_commands = GlCommands()
        for command in api_commands.values():
            try:
                command_name = str(command)
                command_wrapper = GlCommandWrapper(self, command)
                # store enumerants and commands at the same level
                if hasattr(PythonicWrapper, command_name):

                    method = getattr(PythonicWrapper, command_name)