mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Depth fbo+renderer work+texture slots enum+optimize shaders+more
This commit is contained in:
@ -2,6 +2,7 @@ package rend3dgl
|
||||
|
||||
import (
|
||||
"github.com/bloeys/gglm/gglm"
|
||||
"github.com/bloeys/nmage/buffers"
|
||||
"github.com/bloeys/nmage/materials"
|
||||
"github.com/bloeys/nmage/meshes"
|
||||
"github.com/bloeys/nmage/renderer"
|
||||
@ -11,23 +12,56 @@ import (
|
||||
var _ renderer.Render = &Rend3DGL{}
|
||||
|
||||
type Rend3DGL struct {
|
||||
BoundVao *buffers.VertexArray
|
||||
BoundMesh *meshes.Mesh
|
||||
BoundMat *materials.Material
|
||||
}
|
||||
|
||||
func (r3d *Rend3DGL) Draw(mesh *meshes.Mesh, trMat *gglm.TrMat, mat *materials.Material) {
|
||||
func (r *Rend3DGL) DrawMesh(mesh *meshes.Mesh, modelMat *gglm.TrMat, mat *materials.Material) {
|
||||
|
||||
if mesh != r3d.BoundMesh {
|
||||
if mesh != r.BoundMesh {
|
||||
mesh.Vao.Bind()
|
||||
r3d.BoundMesh = mesh
|
||||
r.BoundMesh = mesh
|
||||
}
|
||||
|
||||
if mat != r3d.BoundMat {
|
||||
if mat != r.BoundMat {
|
||||
mat.Bind()
|
||||
r3d.BoundMat = mat
|
||||
r.BoundMat = mat
|
||||
}
|
||||
|
||||
mat.SetUnifMat4("modelMat", &trMat.Mat4)
|
||||
mat.SetUnifMat4("modelMat", &modelMat.Mat4)
|
||||
|
||||
for i := 0; i < len(mesh.SubMeshes); i++ {
|
||||
gl.DrawElementsBaseVertexWithOffset(gl.TRIANGLES, mesh.SubMeshes[i].IndexCount, gl.UNSIGNED_INT, uintptr(mesh.SubMeshes[i].BaseIndex), mesh.SubMeshes[i].BaseVertex)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Rend3DGL) DrawVertexArray(mat *materials.Material, vao *buffers.VertexArray, firstElement int32, elementCount int32) {
|
||||
|
||||
if vao != r.BoundVao {
|
||||
vao.Bind()
|
||||
r.BoundVao = vao
|
||||
}
|
||||
|
||||
if mat != r.BoundMat {
|
||||
mat.Bind()
|
||||
r.BoundMat = mat
|
||||
}
|
||||
|
||||
gl.DrawArrays(gl.TRIANGLES, firstElement, elementCount)
|
||||
}
|
||||
|
||||
func (r *Rend3DGL) DrawCubemap(mesh *meshes.Mesh, mat *materials.Material) {
|
||||
|
||||
if mesh != r.BoundMesh {
|
||||
mesh.Vao.Bind()
|
||||
r.BoundMesh = mesh
|
||||
}
|
||||
|
||||
if mat != r.BoundMat {
|
||||
mat.Bind()
|
||||
r.BoundMat = mat
|
||||
}
|
||||
|
||||
for i := 0; i < len(mesh.SubMeshes); i++ {
|
||||
gl.DrawElementsBaseVertexWithOffset(gl.TRIANGLES, mesh.SubMeshes[i].IndexCount, gl.UNSIGNED_INT, uintptr(mesh.SubMeshes[i].BaseIndex), mesh.SubMeshes[i].BaseVertex)
|
||||
|
||||
Reference in New Issue
Block a user