Skip to content

Commit

Permalink
Extensions support
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Feb 7, 2021
1 parent 689207d commit 72931a8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 19 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# opengl-registry

**NOTE: The repository is currently a work-in-progress. This warning
will be removed once the first stable version is released on PyPI**

* [opengl-registry Documentation](https://opengl-registry.readthedocs.io)
* [opengl-registry on PyPI](https://pypi.org/project/opengl-registry)
* [opengl-registry on Github](https://github.com/moderngl/opengl-registry)
Expand Down
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
author = 'Einar Forselv'

# The short X.Y version
version = '0.2.0'
version = '0.3.0'
# The full version, including alpha/beta/rc tags
release = '0.2.0'

release = '0.3.0'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion opengl_registry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from opengl_registry.reader import RegistryReader # noqa
from opengl_registry.registry import Registry # noqa

__version__ = "0.2.0"
__version__ = "0.3.0"
29 changes: 28 additions & 1 deletion opengl_registry/extensions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
from typing import List

class Extension:
pass
"""An OpenGL extensions containins enum and command names to add"""

def __init__(self, *, name: str, supported: str, enums: List[str], commands: List[str]):
self._name = name
self._supported = supported
self._enums = enums
self._commands = commands

def __repr__(self) -> str:
return "<Extension {} [{}]: enums={} commands={}".format(
self._name, self._supported, self._enums, self._commands
)

@property
def name(self) -> str:
return self._name

@property
def enums(self) -> List[str]:
"""List if enum names to include"""
return self._enums

@property
def commands(self) -> List[str]:
"""List of command names to include"""
return self._commands
16 changes: 14 additions & 2 deletions opengl_registry/reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from io import StringIO
from opengl_registry.extensions import Extension
from typing import Dict, List
from xml.etree import ElementTree
import requests
Expand Down Expand Up @@ -244,10 +245,21 @@ def read_features(self) -> List[Feature]:

return features

def read_extensions(self):
def read_extensions(self) -> Dict[str, Extension]:
"""Reads all extensions.
Returns:
List[Extension]: list of extensions
"""
return []
extensions = {}
# NOTE: Extensions done have <remove>. We can safely iter
for ext_elem in self._tree.iter("extension"):
name = ext_elem.get("name")
extensions[name] = Extension(
name=name,
supported=ext_elem.get("supported"),
enums=[e.get("name") for e in ext_elem.iter("enum")],
commands=[e.get("name") for e in ext_elem.iter("command")],
)

return extensions
23 changes: 19 additions & 4 deletions opengl_registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
enums: Dict[str, Enum] = None,
commands: Dict[str, Command] = None,
features: List[Feature] = None,
extensions: List[Extension] = None,
extensions: Dict[str, Extension] = None,
):
"""Initialize the registry.
Expand All @@ -32,10 +32,10 @@ def __init__(
self._enums: Dict[str, Enum] = enums or {}
self._commands: Dict[str, Command] = commands or {}
self._features = features or []
self._extensions = extensions or []
self._extensions: Dict[str, Extension] = extensions or {}

def __repr__(self) -> str:
return f"<Registry: enums={len(self._enums)}, commands={len(self._commands)}>"
return f"<Registry: enums={len(self._enums)}, commands={len(self._commands)} extensions={len(self._extensions)}>"

@property
def enums(self) -> Dict[str, Enum]:
Expand Down Expand Up @@ -82,8 +82,15 @@ def remove_command(self, name: str) -> bool:
return True
return False

def get_extension(self, name) -> Extension:
"""Get an extension by name"""
if not name.startswith("GL_"):
name = f"GL_{name}"

return self._extensions[name]

def get_profile(
self, api: str = "gl", profile: str = "core", version: str = "3.3", extensions=None
self, api: str = "gl", profile: str = "core", version: str = "3.3", extensions=List[str],
) -> "Registry":
"""Get a subset of the registry"""
# Create the new registry
Expand Down Expand Up @@ -127,4 +134,12 @@ def get_profile(
if not registry.remove_command(name):
raise ValueError("Cannot remove command", name)

# Add extensions
for ext_name in extensions:
ext = self.get_extension(ext_name)
for name in ext.enums:
registry.add_enum(self.get_enum(name))
for name in ext.commands:
registry.add_command(self.get_enum(name))

return registry
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

setup(
name="opengl-registry",
version="0.2.0",
version="0.3.0",
description="A simple tool for extracting information from the OpenGL API Registry",
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url="https://github.com/moderngl/opengl-registry",
author="Einar Forselv",
author_email="[email protected]",
python_requires='>=3.5',
python_requires='>=3.6',
platforms=['any'],
license='MIT',
packages=find_namespace_packages(include=['opengl_registry']),
Expand All @@ -26,9 +26,6 @@
'Topic :: Multimedia :: Graphics',
'Topic :: Multimedia :: Graphics :: 3D Rendering',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
entry_points={
'console_scripts': [
Expand Down

0 comments on commit 72931a8

Please sign in to comment.