cg Package

cg Package

class cg.__init__.Cg(context_factory=None)[source]

Bases: cg.utils.Disposable

Gateway to using python-cg.


This is the only class that should (or need to) be manually instantiated

by user code.


There should be one instance of this class per process. Having multiple instances, although possible, can result in some unexpected behaviour.


Creates CG context.

Return type:cg.context.Context

context Module

class cg.context.Context(cgcontext, bridge)[source]

Bases: cg.utils.Disposable

Wraps Cg context.


Creates effect from source.

Parameters:source (string) – effect source
Return type:cg.effect.Effect

Loads effect source from file and creates effect using it.

Parameters:filename (string) – file containing effect source.
Return type:cg.effect.Effect

Gets and sets whether Cg is supposed to automatically manage (enable/disable) texture parameters (bool).


Register graphics API states for use in effects.


This method is idempotent.

errors Module

exception cg.errors.Error[source]

Bases: exceptions.Exception

Base class for all CG errors.

parameter Module

class cg.parameter.NumericParameter(row_count, column_count, **kwargs)[source]

Bases: cg.parameter.Parameter

Represents numeric parameter (float, array of ints, matrix of doubles etc.).

column_count = None

Gets parameter column count

row_count = None

Gets parameter row count


Sets the parameter value. Value can be one of the following:

  • numpy.ndarray of float32, float64 or int32. If the array is multidimensional, it will be reshaped to one dimension.
  • iterable of elements of type matching parameter type
  • scalar value of type matching parameter type


Setting parameter value is a slow operation and should be performed as rarely as possible.


Matrices will be filled with data in row-major order.

class cg.parameter.Parameter(bridge, cgparameter, name, semantic, type, base_type)[source]

Bases: cg.utils.ReprMixin

Effect or program parameter base class.

base_type = None

Gets base type of the parameter (string)

name = None

Gets name of the parameter (string)

semantic = None

Gets parameter semantic (string)

type = None

Gets type of the parameter (string)

class cg.parameter.ParameterCollection[source]

Bases: tuple

Collection of cg.parameter.Parameter. Provides tuple interface (iteration, indexing etc.) and some parameter-specific extensions.


Gets parameter dictionary indexed by names.


Gets parameter dictionary indexed by semantic. Only parameters with non-empty semantic are included.

class cg.parameter.SamplerParameter(bridge, cgparameter, name, semantic, type, base_type)[source]

Bases: cg.parameter.Parameter

Represents sampler* parameter.


Sets sampler value.

Parameters:value (uint) – OpenGL texture object

utils Module

class cg.utils.Disposable[source]

Bases: abc.WithABCMeta

Exposes method to release resources held by the class.


Disposes of resources that are owned by the object.


This method is idempotent.


Performs actual disposing, needs to be overridden by a subclass.


This method is not supposed to be called directly by the user code. Please use dispose() instead.


Decorator for instance methods, copies all keyword arguments to instance members and then calls the decorated method passing all the parameters.


Decorated method accepts only keyword arguments.


__repr__ decorator that makes sure __repr__ returns result of the right type (byte string for Python 2.x, (unicode) string for Python 3). Performs conversion from unicode to byte string when necessary.

Project Versions

Table Of Contents

This Page