Move all constants and types to raylib.go

This commit is contained in:
Milan Nikolic 2017-12-07 20:32:31 +01:00
parent f71025719c
commit 135a4637a6
12 changed files with 916 additions and 910 deletions

View file

@ -7,189 +7,41 @@ package raylib
import "C"
import "unsafe"
// Shader location point type
const (
LocVertexPosition = iota
LocVertexTexcoord01
LocVertexTexcoord02
LocVertexNormal
LocVertexTangent
LocVertexColor
LocMatrixMvp
LocMatrixModel
LocMatrixView
LocMatrixProjection
LocVectorView
LocColorDiffuse
LocColorSpecular
LocColorAmbient
LocMapAlbedo
LocMapMetalness
LocMapNormal
LocMapRoughness
LocMapOccusion
LocMapEmission
LocMapHeight
LocMapCubemap
LocMapIrradiance
LocMapPrefilter
LocMapBrdf
)
// Material map type
const (
// MapDiffuse
MapAlbedo = iota
MapMetalness
MapNormal
MapRoughness
MapOcclusion
MapEmission
MapHeight
// NOTE: Uses GL_TEXTURE_CUBE_MAP
MapCubemap
// NOTE: Uses GL_TEXTURE_CUBE_MAP
MapIrradiance
// NOTE: Uses GL_TEXTURE_CUBE_MAP
MapPrefilter
MapBrdf
)
// Material map type
const (
MapDiffuse = MapAlbedo
MapSpecular = MapMetalness
LocMapDiffuse = LocMapAlbedo
LocMapSpecular = LocMapMetalness
)
// Shader and material limits
const (
// Maximum number of predefined locations stored in shader struct
MaxShaderLocations = 32
// Maximum number of texture maps stored in shader struct
MaxMaterialMaps = 12
)
// Mesh - Vertex data definning a mesh
type Mesh struct {
// Number of vertices stored in arrays
VertexCount int32
// Number of triangles stored (indexed or not)
TriangleCount int32
// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
Vertices *[]float32
// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
Texcoords *[]float32
// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
Texcoords2 *[]float32
// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
Normals *[]float32
// Vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
Tangents *[]float32
// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
Colors *[]uint8
// Vertex indices (in case vertex data comes indexed)
Indices *[]uint16
// OpenGL Vertex Array Object id
VaoID uint32
// OpenGL Vertex Buffer Objects id (7 types of vertex data)
VboID [7]uint32
}
// cptr returns C pointer
func (m *Mesh) cptr() *C.Mesh {
return (*C.Mesh)(unsafe.Pointer(m))
}
// NewMesh - Returns new Mesh
func NewMesh(vertexCount, triangleCount int32, vertices, texcoords, texcoords2, normals, tangents *[]float32, colors *[]uint8, indices *[]uint16, vaoID uint32, vboID [7]uint32) Mesh {
return Mesh{vertexCount, triangleCount, vertices, texcoords, texcoords2, normals, tangents, colors, indices, vaoID, vboID}
}
// newMeshFromPointer - Returns new Mesh from pointer
func newMeshFromPointer(ptr unsafe.Pointer) Mesh {
return *(*Mesh)(ptr)
}
// Material type
type Material struct {
// Shader
Shader Shader
// Maps
Maps [MaxMaterialMaps]MaterialMap
// Padding
_ [4]byte
// Generic parameters (if required)
Params *[]float32
}
// cptr returns C pointer
func (m *Material) cptr() *C.Material {
return (*C.Material)(unsafe.Pointer(m))
}
// NewMaterial - Returns new Material
func NewMaterial(shader Shader, maps [MaxMaterialMaps]MaterialMap, params *[]float32) Material {
return Material{shader, maps, [4]byte{}, params}
}
// newMaterialFromPointer - Returns new Material from pointer
func newMaterialFromPointer(ptr unsafe.Pointer) Material {
return *(*Material)(ptr)
}
// MaterialMap type
type MaterialMap struct {
// Texture
Texture Texture2D
// Color
Color Color
// Value
Value float32
}
// Model type
type Model struct {
// Vertex data buffers (RAM and VRAM)
Mesh Mesh
// Local transform matrix
Transform Matrix
// Shader and textures data
Material Material
// Padding
_ [4]byte
}
// cptr returns C pointer
func (m *Model) cptr() *C.Model {
return (*C.Model)(unsafe.Pointer(m))
}
// NewModel - Returns new Model
func NewModel(mesh Mesh, transform Matrix, material Material) Model {
return Model{mesh, transform, material, [4]byte{}}
}
// newModelFromPointer - Returns new Model from pointer
func newModelFromPointer(ptr unsafe.Pointer) Model {
return *(*Model)(ptr)
}
// Ray type (useful for raycast)
type Ray struct {
// Ray position (origin)
Position Vector3
// Ray direction
Direction Vector3
}
// cptr returns C pointer
func (r *Ray) cptr() *C.Ray {
return (*C.Ray)(unsafe.Pointer(r))
}
// NewRay - Returns new Ray
func NewRay(position, direction Vector3) Ray {
return Ray{position, direction}
}
// newRayFromPointer - Returns new Ray from pointer
func newRayFromPointer(ptr unsafe.Pointer) Ray {
return *(*Ray)(ptr)