cg Package

cg Package

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

Bases: cg.utils.Disposable

Gateway to using python-cg.

Note

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

by user code.

Note

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

create_context()[source]

Creates CG context.

Return type:cg.context.Context

context Module

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

Bases: cg.utils.Disposable

Wraps Cg context.

create_effect(source)[source]

Creates effect from source.

Parameters:source (string) – effect source
Return type:cg.effect.Effect
create_effect_from_file(filename)[source]

Loads effect source from file and creates effect using it.

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

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

register_states()[source]

Register graphics API states for use in effects.

Note

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

set_value(value)[source]

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

Note

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

Note

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.

by_name[source]

Gets parameter dictionary indexed by names.

by_semantic[source]

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.

set_value(value)[source]

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.

dispose()[source]

Disposes of resources that are owned by the object.

Note

This method is idempotent.

perform_dispose()[source]

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

Note

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

cg.utils.autoassign(function)[source]

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

Note

Decorated method accepts only keyword arguments.

cg.utils.nativerepr(repr_function)[source]

__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