TTexture


Croquet-Teapot

Comment:

This is used to create a GL texture from a form, either directly or from a file.

This is dependent upon the TForm class, which handles the actual bits.

DAS

Hierarchy:

ProtoObject
Object
TObject
TFrame
TPrimitive
TRectangle
TTexture
  • TTextureForm

Summary:

instance variables:

baseScale mode tform uvAngle uvOffset uvScale

Pool:

OpenGLConstants

methods:

instance class
access copying fileIn/Out initialize render testing instance creation

Detail:

instance variables:

baseScale
mode
tform
uvAngle
uvOffset
uvScale

instance methods:

access
bMipmap


	^ tform bMipmap.
extension

	
	^ tform extension.
extent: ext


	super extent: ext.
	baseScale _ (extent x/tform extent x) asFloat.
fileName


	^ tform fileName.
formExtent


	^ tform extent.
isStatic

	^ tform isStatic.
isStatic: aBool

	
	tform isStatic: aBool.
magFilter

	^ tform magFilter.
minFilter

	^ tform minFilter.
mode


	^ mode.
mode: md


	mode _ md.
scale


	^ baseScale.
scale: sc


	baseScale _ baseScale * sc.
	self translation: (self translation * sc).
	extent _ tform extent * baseScale. 	"save the original value if we have to render this object."
	self boundsChanged.
shrinkFit


^ tform bShrinkFit.
shrinkFit: bSF


 tform shrinkFit: bSF.
targetExtent


	^ tform extent.
targetForm

	^tform form.
textureForm

	^tform form.
updateRect: aRect


	tform updateRect: aRect.
uvAngle


	^ uvAngle.
uvAngle: uva


	uvAngle _ uva.
uvOffset


	^ uvOffset.
uvOffset: uvo


	uvOffset_ uvo.
uvScale


	^uvScale.
uvScale: uvs


	uvScale_ uvs.

copying
copy


	^ self shallowCopy.

fileIn/Out
isLoaded


	^tform isLoaded.

initialize
delete

"Very important - a TTexture is not allowed to delete a TForm. This is because a TForm may be shared among multiple TTextures."
	tform invalidate: Croquet world ogl.
destroy

	"destroy me"
	super destroy.
	self delete.
flipVertically

	"Flip the texture vertically"
	tform form flipVertically.
	tform updateAll.
initializeOpaque: aBool extent: targetExtent

| mat |
	self 
		initializeWithForm: (Form extent: targetExtent depth: 32) 
		mipmap: false "aCroquetWorld ogl autoMipmap"
		shrinkFit: false. "the form needs to grow"
	uvScale _ (tform extent/tform trueExtent) asFloatPoint.
	mat _ TMaterial new.
	aBool ifTrue:[
		mat ambientColor: #(1.0 1.0 1.0 1) asFloatArray.
		mat diffuseColor: #(1.0 1.0 1.0 1) asFloatArray.
	] ifFalse:[
		mat ambientColor: #(1.0 1.0 1.0 0.9) asFloatArray.
		mat diffuseColor: #(1.0 1.0 1.0 0.9) asFloatArray.
	].
	mat emissiveColor: #(1.0 1.0 1.0 1.0) asFloatArray.
	super material: mat.
	^self.
initializeWithFileName: fName

	^self initializeWithFileName: fName mipmap: true shrinkFit: false.
initializeWithFileName: fName mipmap: bMM

	^self initializeWithFileName: fName mipmap: bMM shrinkFit: false.

initializeWithFileName: fName mipmap: bMM shrinkFit: bSF
 

	^self initializeWithFileName: fName mipmap: bMM shrinkFit: false extension: nil.

initializeWithFileName: fName mipmap: bMM shrinkFit: bSF extension: ext


	tform _ TForm fromFileNamed: fName mipmap: bMM shrinkFit: bSF extension: ext.
	self setup.
initializeWithForm: baseForm mipmap: bMM shrinkFit: bSF
 

	self initializeWithForm: baseForm mipmap: bMM shrinkFit: bSF extension: nil.
initializeWithForm: baseForm mipmap: bMM shrinkFit: bSF extension: ext


	tform _ TForm fromForm: baseForm mipmap: bMM shrinkFit: bSF extension: ext.
	self setup.
setup


	baseScale _ 0.01.
	extent _ tform extent * baseScale.
	self aspectFixed: true.
	self aspect: (extent y/extent x) asFloat.
	self texture: self.
	uvScale _ 1.0@1.0.
	uvOffset _ 0.0@0.0.
	uvAngle _ 0.0.
	extent _ extent * baseScale. 	"save the original value if we have to render this object."
	self objectName: tform fileName.
	tform addParent: self.
	mode _ GLModulate.

render
disable: ogl


	ogl changeTexture ifFalse:[^false].
	ogl glDisable: GLTexture2d.
enable: ogl


	(tform notNil and: [tform bind: ogl]) ifTrue:[.
		ogl glEnable: GLTexture2d.

		timeStamp ~= ogl timeStamp ifTrue:[self update.].
		ogl glTexParameteri: GLTexture2d with: GLTextureWrapS with:GLRepeat;
			glTexParameteri: GLTexture2d with: GLTextureWrapT with:GLRepeat.].
	timeStamp _ ogl timeStamp.
renderFrame: ogl parent: parent root: root

	self update.
	^ super renderFrame: ogl parent: parent root: root.
renderFrame: ogl space: space

	self update.
	^ super renderFrame: ogl space: space.
renderPrimitive: ogl


	self enable: ogl.
	ogl glTexEnvi: GLTextureEnv with: GLTextureEnvMode with: mode.
	super renderPrimitive: ogl.
	self disable:ogl.

update


"This is used when you are about to use or render this texture. This is called whenever we are send #enable: to the texture, and it is only called once per render."
upload


	tform updateAll.
uploadDirtyRect: aRectangle


	tform upload: Croquet world ogl dirtyRect: aRectangle

testing
isTexture


	^ true.

class methods:

^top


- made by Dandelion -