コード例 #1
0
//	Prepares this TextureCube for uploading the specified Images via Recreate().
//	This sets all of the following fields to applicable values:
//	me.PixelData.Type, me.PixelData.Format, me.PixelData.Ptrs, me.Width, me.Height, me.MipMap.NumLevels, me.SizedInternalFormat
func (me *TextureCube) PrepFromImages(bgra, uintRev bool, images ...image.Image) (err error) {
	if len(images) < 6 {
		err = errf("TextureCube.PrepFromImages: expected 6 cube-faces, but only %v were supplied", len(images))
	} else {
		me.Width, me.Height = gl.Sizei(images[0].Bounds().Dx()), gl.Sizei(images[0].Bounds().Dy())
		me.MipMap.NumLevels = me.MaxNumMipLevels()
		err = me.prepFromImages(bgra, uintRev, images...)
	}
	return
}
コード例 #2
0
ファイル: render-canvas.gt.go プロジェクト: go3d/go-ngine
func (me *RenderCanvasLib) AddNew(relative bool, width, height float64) (canv *RenderCanvas) {
	canv = new(RenderCanvas)
	me.add(canv)
	canv.SetSize(relative, width, height)
	if !canv.isRtt {
		canv.frameBuf.GlTarget, canv.Srgb = gl.FRAMEBUFFER, !Options.Initialization.DefaultCanvas.GammaViaShader
	} else {
		canv.frameBuf.Create(gl.Sizei(UserIO.Window.width), gl.Sizei(UserIO.Window.height), false)
		canv.frameBuf.AttachRendertexture()
		canv.frameBuf.AttachRenderbuffer()
	}
	Diag.LogIfGlErr("newRenderCanvas()")
	Core.refreshWinSizeRels()
	return
}
コード例 #3
0
ファイル: render-canvas.gt.go プロジェクト: go3d/go-ngine
func (me *RenderCanvas) onResize(viewWidth, viewHeight int) {
	if me.viewSizeRelative {
		me.absViewWidth, me.absViewHeight = me.relViewWidth*float64(viewWidth), me.relViewHeight*float64(viewHeight)
	}
	if me.isRtt {
		me.frameBuf.Resize(gl.Sizei(int(me.absViewWidth)), gl.Sizei(int(me.absViewHeight)))
	}
	var rts *RenderTechniqueScene
	for i := 0; i < len(me.Views); i++ {
		me.Views[i].Port.canvWidth, me.Views[i].Port.canvHeight = me.absViewWidth, me.absViewHeight
		me.Views[i].Port.update()
		if rts = me.Views[i].Technique_Scene(); rts != nil {
			rts.ApplyCameraPerspective()
		}
	}
}
コード例 #4
0
ファイル: render-view.gt.go プロジェクト: go3d/go-ngine
func (me *RenderViewport) update() {
	me.shouldScissor = !(me.relative && me.relX == 0 && me.relY == 0 && me.relW == 1 && me.relH == 1)
	if me.relative {
		me.absW, me.absH = int(me.relW*float64(me.canvWidth)), int(me.relH*float64(me.canvHeight))
		me.absX, me.absY = int(me.relX*float64(me.canvWidth)), int(me.relY*float64(me.canvHeight))
	}
	me.glVpX, me.glVpY, me.glVpW, me.glVpH = gl.Int(me.absX), gl.Int(me.absY), gl.Sizei(me.absW), gl.Sizei(me.absH)
	me.aspect = float64(me.absW) / float64(me.absH)
}
コード例 #5
0
ファイル: mesh.gt.go プロジェクト: go3d/go-ngine
func (me *Mesh) load(meshData *u3d.MeshDescriptor) (err error) {
	var (
		offsetFloat, offsetIndex, offsetVertex, vindex uint32
		f                                              float64
		vreuse, offsetFace, ei, numFinalVerts, tvi     int
		vexists                                        bool
		ventry                                         u3d.MeshDescF3V
		tvp                                            [3]unum.Vec3
	)
	numVerts := 3 * int32(len(meshData.Faces))
	vertsMap := make(map[u3d.MeshDescF3V]uint32, numVerts)
	me.gpuSynced = false
	me.raw.bounding.Reset()
	me.raw.verts = make([]float32, Core.Mesh.Buffers.FloatsPerVertex()*numVerts)
	me.raw.indices = make([]uint32, numVerts)
	me.raw.lastNumIndices = gl.Sizei(numVerts)
	me.raw.faces = make([]meshRawFace, len(meshData.Faces))
	for fi := 0; fi < len(meshData.Faces); fi++ {
		me.raw.faces[offsetFace].base = meshData.Faces[fi].MeshFaceBase
		meshData.Positions[meshData.Faces[fi].V[0].PosIndex].ToVec3(&tvp[0])
		meshData.Positions[meshData.Faces[fi].V[1].PosIndex].ToVec3(&tvp[1])
		meshData.Positions[meshData.Faces[fi].V[2].PosIndex].ToVec3(&tvp[2])
		for tvi = 0; tvi < len(tvp); tvi++ {
			if f = tvp[tvi].Magnitude(); f > me.raw.bounding.Sphere {
				me.raw.bounding.Sphere = f
			}
			me.raw.bounding.AaBox.UpdateMinMax(&tvp[tvi])
		}
		me.raw.faces[offsetFace].center.X = (tvp[0].X + tvp[1].X + tvp[2].X) / 3
		me.raw.faces[offsetFace].center.Y = (tvp[0].Y + tvp[1].Y + tvp[2].Y) / 3
		me.raw.faces[offsetFace].center.Z = (tvp[0].Z + tvp[1].Z + tvp[2].Z) / 3
		for ei, ventry = range meshData.Faces[fi].V {
			if vindex, vexists = vertsMap[ventry]; !vexists {
				vindex, vertsMap[ventry] = offsetVertex, offsetVertex
				copy(me.raw.verts[offsetFloat:(offsetFloat+3)], meshData.Positions[ventry.PosIndex][0:3])
				offsetFloat += 3
				copy(me.raw.verts[offsetFloat:(offsetFloat+2)], meshData.TexCoords[ventry.TexCoordIndex][0:2])
				offsetFloat += 2
				copy(me.raw.verts[offsetFloat:(offsetFloat+3)], meshData.Normals[ventry.NormalIndex][0:3])
				offsetFloat += 3
				offsetVertex++
				numFinalVerts++
			} else {
				vreuse++
			}
			me.raw.indices[offsetIndex] = vindex
			me.raw.faces[offsetFace].entries[ei] = offsetIndex
			offsetIndex++
		}
		offsetFace++
	}
	me.raw.bounding.AaBox.SetCenterExtent()
	Diag.LogMeshes("mesh{%v}.Load() gave %v faces, %v att floats for %v final verts (%v source verts), %v indices (%vx vertex reuse)", me.Name, len(me.raw.faces), len(me.raw.verts), numFinalVerts, numVerts, len(me.raw.indices), vreuse)
	return
}
コード例 #6
0
ファイル: main.go プロジェクト: LonelyPale/go-opengl
func compileShaders() (err error) {
	var glStatus gl.Int

	makeShader := func(stage gl.Enum, src string) (shader gl.Uint) {
		shader = gl.CreateShader(stage)
		logLastGlError("gl.CreateShader()")
		glStr := gl.Util.CStringArray(src)
		defer gl.Util.CStringArrayFree(glStr)
		gl.ShaderSource(shader, gl.Sizei(len(glStr)), &glStr[0], nil)
		logLastGlError("gl.ShaderSource()")
		gl.CompileShader(shader)
		if gl.GetShaderiv(shader, gl.COMPILE_STATUS, &glStatus); glStatus == 0 {
			panic("Shader compilation failed: " + src)
		}
		return
	}

	glVertShader := makeShader(gl.VERTEX_SHADER, srcVertShader)
	defer gl.DeleteShader(glVertShader)
	glFragShader := makeShader(gl.FRAGMENT_SHADER, srcFragShader)
	defer gl.DeleteShader(glFragShader)

	shaderProg = gl.CreateProgram()
	for stageName, shader := range map[string]gl.Uint{"vert": glVertShader, "frag": glFragShader} {
		gl.AttachShader(shaderProg, shader)
		logLastGlError("gl.AttachShader " + stageName)
		defer gl.DetachShader(shaderProg, shader)
	}

	gl.LinkProgram(shaderProg)
	if gl.GetProgramiv(shaderProg, gl.LINK_STATUS, &glStatus); glStatus == 0 {
		panic("Program linking failed...")
	}

	glAttName := gl.Util.CString("aPos")
	defer gl.Util.CStringFree(glAttName)
	progPosAttrLoc = gl.Uint(gl.GetAttribLocation(shaderProg, glAttName))
	logLastGlError("gl.GetAttribLocation()")

	return
}
コード例 #7
0
ファイル: gl-shader.go プロジェクト: LonelyPale/go-opengl
//	Replaces the GLSL source code in this shader object with source,
//	prepending a #version (core) directive with the current Support.Glsl.Version.Num
//	and #define directives for all specified name-value pairs in defines.
func (me *Shader) SetSource(source string, defines map[string]interface{}) (finalRealSrc string, err error) {
	i, lines := 1, make([]string, (len(defines)*5)+3)
	lines[0] = strf("#version %v core\n", Support.Glsl.Version.Num)
	if len(defines) > 0 {
		for dk, dv := range defines {
			lines[i+0] = "#define "
			lines[i+1] = dk
			lines[i+2] = " "
			lines[i+3] = fmt.Sprintf("%v", dv)
			lines[i+4] = "\n"
			i = i + 5
		}
	}
	lines[i] = "#line 1\n"
	lines[i+1] = source
	finalRealSrc = strings.Join(lines, "")
	src := gl.Util.CStringArray(lines...)
	defer gl.Util.CStringArrayFree(src)
	err = Try.ShaderSource(me.GlHandle, gl.Sizei(len(src)), &src[0], nil)
	return
}
コード例 #8
0
ファイル: gl-texture-2d.go プロジェクト: LonelyPale/go-opengl
//	Prepares this Texture2D for uploading the specified Image via Recreate().
//	This sets all of the following fields to applicable values:
//	me.PixelData.Type, me.PixelData.Format, me.PixelData.Ptrs[0], me.Width, me.Height, me.MipMap.NumLevels, me.SizedInternalFormat
func (me *Texture2D) PrepFromImage(bgra, uintRev bool, img image.Image) (err error) {
	me.Width, me.Height = gl.Sizei(img.Bounds().Dx()), gl.Sizei(img.Bounds().Dy())
	me.MipMap.NumLevels = me.MaxNumMipLevels()
	err = me.prepFromImages(bgra, uintRev, img)
	return
}
コード例 #9
0
ファイル: gl-texture-2d.go プロジェクト: LonelyPale/go-opengl
//	Returns the maximum number of possible MIP map levels for this 2-dimensional texture image according to its current Width and Height.
func (me *Texture2D) MaxNumMipLevels() gl.Sizei {
	return gl.Sizei(texture2DMaxNumMipLevels(float64(me.Width), float64(me.Height)))
}