glcaps

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2021 License: BSD-3-Clause, MIT, MIT-0, + 1 more Imports: 6 Imported by: 0

README

glcaps - read and check OpenGL capabilities

go get "tawesoft.co.uk/go/"
import "tawesoft.co.uk/go/glcaps"
Links License Stable?
homedocssrc MIT ✔ yes

About

Package glcaps provides a nice interface to declare OpenGL capabilities you care about, including minimum required extensions or capabilities. Glcaps has no dependencies and is agnostic to the exact OpenGL binding used.

OpenGL® and the oval logo are trademarks or registered trademarks of Hewlett Packard Enterprise in the United States and/or other countries worldwide.

Example

Usage involves defining an OpenGL binding and parsing into an annotated struct.

See https://godoc.org/tawesoft.co.uk/go/glcaps#Parse for a description of the struct annotation syntax.

package main

// Example output:
//
//     glcaps error: FluxCapacitor is required
//     glcaps error: Frobbinators is 150 but must be < 100
//     Supports.TextureCompressionBPTC: true
//     Supports.FluxCapacitor: false
//     Supports.BigTextures: true
//     MaxTextureUnits: 192
//     Frobbinators: 150
//     380 extensions supported
//
//     Info struct { Version string "glcaps:\"GetString GL_VERSION\"";
//     GLSLVersion string "glcaps:\"GetString GL_SHADING_LANGUAGE_VERSION\"";
//     Vendor string "glcaps:\"GetString GL_VENDOR\"";
//     Renderer string "glcaps:\"GetString GL_RENDERER\"" }{
//         Version:"4.6.0 NVIDIA 4??.??",
//         GLSLVersion:"4.60 NVIDIA",
//         Vendor:"NVIDIA Corporation",
//         Renderer:"GeForce GTX ????/PCIe/SSE2",
//     }

import (
    "fmt"

    "github.com/go-gl/gl/v3.3-core/gl"
    "github.com/go-gl/glfw/v3.2/glfw"
    "tawesoft.co.uk/go/glcaps"
)

func start() func() {
    var err = gl.Init()
    if err != nil { panic(err.Error()) }

    err = glfw.Init()
    if err != nil { panic(err.Error()) }

    glfw.WindowHint(glfw.Visible, glfw.False)

    window, err := glfw.CreateWindow(640, 480, "Example", nil, nil)
    if err != nil { panic(err.Error()) }

    window.MakeContextCurrent()

    return glfw.Terminate
}

func main() {
    var closer = start()
    defer closer()

    type Caps struct {
        Info struct {
            Version                 string `glcaps:"GetString GL_VERSION"`
            GLSLVersion             string `glcaps:"GetString GL_SHADING_LANGUAGE_VERSION"`
            Vendor                  string `glcaps:"GetString GL_VENDOR"`
            Renderer                string `glcaps:"GetString GL_RENDERER"`
        }

        Supports struct {
            NPOTTextures            bool `glcaps:"ext GL_ARB_texture_non_power_of_two; required"`
            BPTextureCompression    bool `glcaps:"ext GL_ARB_texture_compression_bptc; required"`
            BigTextures             bool `glcaps:"gte GetIntegerv GL_MAX_TEXTURE_SIZE 8192"`
            AnisotropicFiltering    bool `glcaps:"and ext GL_EXT_texture_filter_anisotropic gte GetFloatv GL_MAX_TEXTURE_MAX_ANISOTROPY 1.0"`
            FluxCapacitor           bool `glcaps:"and ext FLUX1 ext FLUX2; required"`
        }

        MaxTextureUnits             int     `glcaps:"GetIntegerv GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS"`
        MaxTextureSize              int     `glcaps:"GetIntegerv GL_MAX_TEXTURE_SIZE; gte 8192"`
        MaxAnisotropy               float32 `glcaps:"if ext GL_EXT_texture_filter_anisotropic GetFloatv GL_MAX_TEXTURE_MAX_ANISOTROPY 1.0"`
        Frobbinators                int     `glcaps:"150; gte 10 lt 100 neq 13"`
    }

    var Binding = glcaps.Binding{
        GetIntegerv: gl.GetIntegerv,
        GetFloatv:   gl.GetFloatv,
        GetString:   func(name uint32) string {
            return gl.GoStr(gl.GetString(name))
        },
        GetStringi:  func(name uint32, index uint32) string {
            return gl.GoStr(gl.GetStringi(name, index))
        },
    }

    var MyCaps Caps

    var extensions, errors = glcaps.Parse(&Binding, &MyCaps)
    for _, i := range errors {
        fmt.Printf("glcaps error: %s\n", i.Message)
    }

    fmt.Printf("Supports.TextureCompressionBPTC: %t\n", MyCaps.Supports.BPTextureCompression)
    fmt.Printf("Supports.FluxCapacitor: %t\n", MyCaps.Supports.FluxCapacitor)
    fmt.Printf("Supports.BigTextures: %t\n", MyCaps.Supports.BigTextures)
    fmt.Printf("MaxTextureUnits: %d\n", MyCaps.MaxTextureUnits)
    fmt.Printf("Frobbinators: %d\n", MyCaps.Frobbinators)
    fmt.Printf("%d extensions supported\n", len(extensions))

    fmt.Printf("\nInfo %#v\n", MyCaps.Info)
}

Getting Help

This package is part of tawesoft.co.uk/go, a monorepo for small Go modules maintained by Tawesoft®. Check out that URL for more information about other Go modules from Tawesoft plus community and commercial support options.

Documentation

Overview

Package glcaps provides a nice interface to declare OpenGL capabilities you care about, including minimum required extensions or capabilities. Glcaps has no dependencies and is agnostic to the exact OpenGL binding used.

OpenGL® and the oval logo are trademarks or registered trademarks of Hewlett Packard Enterprise in the United States and/or other countries worldwide.

Example

Usage involves defining an OpenGL binding and parsing into an annotated struct.

See https://godoc.org/tawesoft.co.uk/go/glcaps#Parse for a description of the struct annotation syntax.

package main

// Example output:
//
//     glcaps error: FluxCapacitor is required
//     glcaps error: Frobbinators is 150 but must be < 100
//     Supports.TextureCompressionBPTC: true
//     Supports.FluxCapacitor: false
//     Supports.BigTextures: true
//     MaxTextureUnits: 192
//     Frobbinators: 150
//     380 extensions supported
//
//     Info struct { Version string "glcaps:\"GetString GL_VERSION\"";
//     GLSLVersion string "glcaps:\"GetString GL_SHADING_LANGUAGE_VERSION\"";
//     Vendor string "glcaps:\"GetString GL_VENDOR\"";
//     Renderer string "glcaps:\"GetString GL_RENDERER\"" }{
//         Version:"4.6.0 NVIDIA 4??.??",
//         GLSLVersion:"4.60 NVIDIA",
//         Vendor:"NVIDIA Corporation",
//         Renderer:"GeForce GTX ????/PCIe/SSE2",
//     }

import (
    "fmt"

    "github.com/go-gl/gl/v3.3-core/gl"
    "github.com/go-gl/glfw/v3.2/glfw"
    "tawesoft.co.uk/go/glcaps"
)

func start() func() {
    var err = gl.Init()
    if err != nil { panic(err.Error()) }

    err = glfw.Init()
    if err != nil { panic(err.Error()) }

    glfw.WindowHint(glfw.Visible, glfw.False)

    window, err := glfw.CreateWindow(640, 480, "Example", nil, nil)
    if err != nil { panic(err.Error()) }

    window.MakeContextCurrent()

    return glfw.Terminate
}

func main() {
    var closer = start()
    defer closer()

    type Caps struct {
        Info struct {
            Version                 string `glcaps:"GetString GL_VERSION"`
            GLSLVersion             string `glcaps:"GetString GL_SHADING_LANGUAGE_VERSION"`
            Vendor                  string `glcaps:"GetString GL_VENDOR"`
            Renderer                string `glcaps:"GetString GL_RENDERER"`
        }

        Supports struct {
            NPOTTextures            bool `glcaps:"ext GL_ARB_texture_non_power_of_two; required"`
            BPTextureCompression    bool `glcaps:"ext GL_ARB_texture_compression_bptc; required"`
            BigTextures             bool `glcaps:"gte GetIntegerv GL_MAX_TEXTURE_SIZE 8192"`
            AnisotropicFiltering    bool `glcaps:"and ext GL_EXT_texture_filter_anisotropic gte GetFloatv GL_MAX_TEXTURE_MAX_ANISOTROPY 1.0"`
            FluxCapacitor           bool `glcaps:"and ext FLUX1 ext FLUX2; required"`
        }

        MaxTextureUnits             int     `glcaps:"GetIntegerv GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS"`
        MaxTextureSize              int     `glcaps:"GetIntegerv GL_MAX_TEXTURE_SIZE; gte 8192"`
        MaxAnisotropy               float32 `glcaps:"if ext GL_EXT_texture_filter_anisotropic GetFloatv GL_MAX_TEXTURE_MAX_ANISOTROPY 1.0"`
        Frobbinators                int     `glcaps:"150; gte 10 lt 100 neq 13"`
    }

    var Binding = glcaps.Binding{
        GetIntegerv: gl.GetIntegerv,
        GetFloatv:   gl.GetFloatv,
        GetString:   func(name uint32) string {
            return gl.GoStr(gl.GetString(name))
        },
        GetStringi:  func(name uint32, index uint32) string {
            return gl.GoStr(gl.GetStringi(name, index))
        },
    }

    var MyCaps Caps

    var extensions, errors = glcaps.Parse(&Binding, &MyCaps)
    for _, i := range errors {
        fmt.Printf("glcaps error: %s\n", i.Message)
    }

    fmt.Printf("Supports.TextureCompressionBPTC: %t\n", MyCaps.Supports.BPTextureCompression)
    fmt.Printf("Supports.FluxCapacitor: %t\n", MyCaps.Supports.FluxCapacitor)
    fmt.Printf("Supports.BigTextures: %t\n", MyCaps.Supports.BigTextures)
    fmt.Printf("MaxTextureUnits: %d\n", MyCaps.MaxTextureUnits)
    fmt.Printf("Frobbinators: %d\n", MyCaps.Frobbinators)
    fmt.Printf("%d extensions supported\n", len(extensions))

    fmt.Printf("\nInfo %#v\n", MyCaps.Info)
}

Package Information

License: MIT (see LICENSE.txt)

Stable: yes

For more information, documentation, source code, examples, support, links, etc. please see https://www.tawesoft.co.uk/go and https://www.tawesoft.co.uk/go/glcaps

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(binding *Binding, target interface{}) (extensions Extensions, errors Errors)

Parse parses a struct and parses struct tag annotations to identify the required OpenGL information. It fills the target struct with the results, and returns zero or more Errors if any defined requirements are not met. It also returns a sorted string list of all supported OpenGL extensions.

The struct tag key is `glcaps`. The struct tag syntax is a space-separated list of commands, optionally followed by a colon and a space-separated list of requirements.

Commands:

and command1 command2          - return true if command1 and command2 are true
or  command1 command2          - return true if either command1 or command2 are true
not command                    - return the boolean opposite of a command
ext GL_EXT_name                - return true if the given extension is supported
GetIntegerv GL_name            - lookup and return an integer value
GetFloatv GL_name              - lookup and return a float value
if command1 command2 command3  - if command1 is true, return the result of command2 otherwise return command3
eq|neq|lt|lte|gt|gte command1 command2 - return true if command1 ==/!=/</<=/>/>= command2 respectively
value                          - a value literal (e.g. true, false, 123, 1.23, 128KiB)

Requirements:

required                       - generate an error if the result is not true
eq|neq|lt|lte|gt|gte value     - generate an error if the command is not ==, !=, <, <=, >, >= value respectively

Types

type Binding

type Binding struct {
	GetIntegerv func(name uint32, data *int32)
	GetFloatv   func(name uint32, data *float32)
	GetString   func(name uint32) string               // required to return a Go string, not a C string!
	GetStringi  func(name uint32, index uint32) string // required to return a Go string, not a C string!
}

Binding implements a binding between this package and a specific OpenGL implementation (e.g. a specific `go-gl` module).

func (*Binding) QueryExtensions

func (b *Binding) QueryExtensions() Extensions

QueryExtensions returns all extensions supported by the current OpenGL context as a sorted list of strings. It is an error to call this method if a current OpenGL context does not exist.

type Error

type Error struct {
	Field       string      // the name of the field in the struct that failed
	Tag         string      // the original tag string
	Requirement requirement // the requirement that failed
	Message     string      // a human-readable message
}

Error implements an error result type for reporting a capability that doesn't meet a requirement.

type Errors

type Errors []Error

type Extensions

type Extensions []string

Extensions is an ordered list of supported OpenGL extensions.

func (Extensions) Contains

func (extensions Extensions) Contains(key string) bool

HaveExtension returns true iff the ordered list of supported OpenGL extensions contains a given extension.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL