render

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2013 License: BSD-2-Clause-Views, Zlib Imports: 9 Imported by: 0

Documentation

Overview

Package render provides access to 3D graphics. Render attempts to shield the engine from graphic layer implementation details. Its job is to transfer 3D data to the graphics card and ensure it is made visible.

Note that vectors and matricies are down converted before being passed to the graphics layer. This is because graphics cards are happier with 32 bit floats than the 64 bit floats prefered by math and physics. No math operations are expected or supported with the 32-bit vector or matrix structures. Use vu/math/lin instead.

Package render is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

View Source
const (
	BLEND uint32 = gl.BLEND      // Alpha blending.
	CULL         = gl.CULL_FACE  // Backface culling.
	DEPTH        = gl.DEPTH_TEST // Z-buffer (depth) awareness.
)

Enable/Disable graphic state constants. These are the attributes used in the Renderer.Enable method.

Variables

This section is empty.

Functions

func CreateShader

func CreateShader(shaderName string, sh *data.Shader)

CreateShader creates one of the known shaders. This is expected to be used by eng.LoadShader when a shader is not already in the cache. Nil is returned for unrecognized shaders. This function contains the list of official shader names.

Types

type Light

type Light struct {
	X, Y, Z float32  // Light position.
	Ld      data.Rgb // Light colour.
}

Light has a position and a colour.

type M3 added in v1.3.1

type M3 struct {
	X0, Y0, Z0 float32 // row 1 : indicies 0, 1, 2 [00, 01, 02]
	X1, Y1, Z1 float32 // row 2 : indicies 3, 4, 5 [10, 11, 12]
	X2, Y2, Z2 float32 // row 3 : indicies 6, 7, 8 [20, 21, 22]
}

M3 is a 3x3 float32 matrix that is populated from the more precise math/lin float64 representation.

func (*M3) M3 added in v1.3.1

func (m *M3) M3(m4 *M4) *M3

M3 updates calling matrix m to be the 3x3 matrix from the top left corner of the given 4x4 matrix m4. The source matrix m4 is unchanged.

[ x0 y0 z0 w0 ]    [ x0 y0 z0 ]
[ x1 y1 z1 w1 ] => [ x1 y1 z1 ]
[ x2 y2 z2 w2 ]    [ x2 y2 z2 ]
[ x3 y3 z3 w3 ]

func (*M3) Pointer added in v1.3.1

func (m *M3) Pointer() *float32

Pointer is used to access the matrix data as an array of floats. Used to pass the matrix to native graphic layer.

type M4 added in v1.3.1

type M4 struct {
	X0, Y0, Z0, W0 float32 // row 1 : indicies 0, 1, 2, 3 [00, 01, 02, 03]
	X1, Y1, Z1, W1 float32 // row 2 : indicies 4, 5, 6, 7 [10, 11, 12, 13]
	X2, Y2, Z2, W2 float32 // row 3 : indicies 8, 9, a, b [20, 21, 22, 23]
	X3, Y3, Z3, W3 float32 // row 4 : indicies c, d, e, f [30, 31, 32, 33]
}

M4 is a 4x4 float32 matrix that is populated from the more precise math/lin float64 representation.

func (*M4) Pointer added in v1.3.1

func (m *M4) Pointer() *float32

Pointer is used to access the matrix data as an array of floats. Used to pass the matrix to native graphic layer.

type Renderer

type Renderer interface {
	Init() (err error)                    // Init must be called first and only once.
	Clear()                               // Clear all buffers before rendering.
	Color(r, g, b, a float32)             // Set the default render clear colour
	Enable(attribute uint32, enable bool) // Enable or disable graphic state.
	Viewport(width int, height int)       // Set the available screen real estate.
	MapTexture(tid int, t *data.Texture)  // Link textures with texture units.

	// BindModel makes mesh model data available to the graphics card.
	// This copies the model data into the graphics card memory.
	// Note that the model data is no longer needed in the CPU memory.
	BindModel(mesh *data.Mesh) (err error)

	// BindGlyphs makes bitmap font data available to the graphics card.
	BindGlyphs(mesh *data.Mesh) (err error)

	// BindTexture makes texture data available to the graphics card. This
	// copies the texture data into the graphics card memory. Note that the
	// texture data is no longer needed in the CPU memory.
	BindTexture(texture *data.Texture) (err error)

	// BindShader combines a vertex and fragment shader into a program.
	// Error information is returned when there are compile or link problems.
	BindShader(shader *data.Shader) (programRef uint32, err error)

	// Render draws 3D data. Render is expected to be called by a Mesh to render
	// itself. This will be called frequently as each Scene draws its parts
	// multiple times a second.
	Render(v *Vis)
}

Renderer is used to draw 3D model objects using a graphics context. The expected usage is along the lines of:

  • Initialize the graphics layer.
  • Initialize the graphics data by "binding" it to the graphics card. Binding copies data to the graphics card leaving references for later manipulation by the engine.
  • Enter a loop that calls Render many times a second, completely redrawing all visible objects.

func New

func New() Renderer

New provides a default graphics implementation.

type V3 added in v1.3.1

type V3 struct {
	X, Y, Z float32
}

V3 is a float32 based vector that is populated from the more precise math/physics float64 representation.

type Vis added in v1.3.1

type Vis struct {
	Mv         *M4            // Model view.
	Mvp        *M4            // Model view projection.
	Scale      *V3            // Model scaling.
	L          *Light         // Light information.
	Alpha      float32        // Model alpha value.
	RotSpeed   float32        // Rotation speed.
	Fade       float32        // Fade value.
	Is2D       bool           // 2D or 3D.
	MeshName   string         // Mesh resource identifier.
	ShaderName string         // Shader identifier.
	MatName    string         // Material resource identifier.
	TexName    string         // Texture resource identifier.
	GlyphName  string         // Glyph resource identifier.
	GlyphText  string         // Banner text.
	GlyphPrev  string         // Previous banner text.
	GlyphWidth int            // Banner size.
	Mesh       *data.Mesh     // Mesh resource.
	Shader     *data.Shader   // Shader resource.
	Mat        *data.Material // Material resource.
	Tex        *data.Texture  // Texture resource.
	Glyph      *data.Glyphs   // Glyph resource.
}

Vis contains the information needed to completely render a Part. It passes visible scene graph information to the render system.

func NewVis added in v1.3.1

func NewVis() *Vis

NewVis creates and allocates space for a Vis structure.

Directories

Path Synopsis
gl
Package gl provides a golang 3D graphics library that was auto-generated from open gl spec src/vu/render/gl/gen/glcorearb.h-v4.3.
Package gl provides a golang 3D graphics library that was auto-generated from open gl spec src/vu/render/gl/gen/glcorearb.h-v4.3.
gen
Package gen is used to generate the golang OpenGL bindings from the latest OpenGL specification header file.
Package gen is used to generate the golang OpenGL bindings from the latest OpenGL specification header file.

Jump to

Keyboard shortcuts

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