TPrimitive is the base class of a lot of the simple classes such as TCube, TSphere, TRectangle. It is primarily used to help manage graphics caching.
ProtoObjectObjectTObjectTFrameTPrimitive
- TCube
- TCylinder
- TManifold
- TPrimitiveMesh
- TPrimitiveString
- TPrimitiveText
- TQuad
- TRectangle
- TSierpinski
- TSphere
- TTeapot
- TTorus
- TTriangle
- TWindowFrame
| boundSphere | boundsChanged | cachingEnabled | glListID | material | materialAlpha | oglInstance | texture | textureAlpha |
| OpenGLConstants |
| boundSphere |
|---|
| boundsChanged |
|---|
| cachingEnabled |
|---|
| glListID |
|---|
| material |
|---|
| materialAlpha |
|---|
| oglInstance |
|---|
| texture |
|---|
| textureAlpha |
|---|
| accessing |
|---|
| boundsChanged |
boundsChanged _ true. (cachingEnabled = true)ifTrue: [ self resetCaching. ]. "reset cache" |
| colorize: col |
| mat | mat _ TMaterial new. mat ambientColor: col. mat diffuseColor: col. mat textureMode: GLModulate. self material: mat. |
| disableCaching |
cachingEnabled _ false. |
| enableCaching |
cachingEnabled _ true. |
| material |
^ material. |
| material: mat |
mat ifNil:[^self]. material _ mat. material ifNotNil:[ material hasAlpha ifTrue:[ self materialAlpha: mat.].]. |
| materialAlpha |
^ materialAlpha. |
| materialAlpha: mat |
materialAlpha _ mat. |
| resetCaching |
cachingEnabled _ #reset. |
| texture |
^ texture. |
| texture: txtr |
texture _ txtr. textureAlpha _ txtr. |
| textureAlpha |
^ textureAlpha. |
| textureAlpha: txtr |
textureAlpha _ txtr. |
| transparency: trans |
super transparency: trans. material ifNotNil:[material transparency: trans]. materialAlpha ifNotNil:[materialAlpha transparency: trans.]. |
| copying |
|---|
| copy |
| c | c _ super copy. c boundsChanged. ^ c. |
| fileIn/Out |
|---|
| postImportFrom: importer |
super postImportFrom: importer. glListID ifNotNil:[ glListID := nil. self enableCaching. ]. self boundsChanged. "so as to invalidate the cache" |
| initialize |
|---|
| initBounds |
| initialize |
super initialize. boundsChanged _ true. self enableCaching. ^self |
| properties-material |
|---|
| getAlpha |
^materialAlpha ifNil:[1.0] ifNotNil:[materialAlpha getAlpha] |
| getColor |
^material ifNil:[super getColor] ifNotNil:[material getColor] |
| getSpecularColor |
^material ifNil:[super getSpecularColor] ifNotNil:[material getSpecularColor] |
| setAlpha: newAlpha |
self frameChildrenDo:[:each| each setAlpha: newAlpha]. materialAlpha ifNil:[materialAlpha _ material]. materialAlpha setAlpha: newAlpha. newAlpha <= 0.0 ifTrue:[materialAlpha := nil]. |
| setColor: newColor |
self frameChildrenDo:[:child| child setColor: newColor]. material setColor: newColor. materialAlpha ifNotNil:[materialAlpha setColor: newColor]. |
| setSpecularColor: newColor |
self frameChildrenDo:[:child| child setSpecularColor: newColor]. material setSpecularColor: newColor. materialAlpha ifNotNil:[materialAlpha setSpecularColor: newColor]. |
| render |
|---|
| boundSphere |
| | boundsChanged ifTrue:[ self initBounds. boundsChanged _ false. " ts _ TSphere initialize: ogl. ts translation: boundSphere localPosition. ts radius: boundSphere radius. ts material: (TMaterial initialize: ogl). ts boundSphere frame: nil. ts segments: 4. self removeAll. self addChild: ts." ]. ^ boundSphere. |
| hasAlpha |
" Does this object have an alpha channel to render? Return true if it does." materialAlpha ifNotNil:[ ^ materialAlpha hasAlpha.]. ^ false. |
| opaque |
" Does this object have an opaque channel to render? Return true if it does." material ifNotNil:[ ^ (material hasAlpha) not .]. ^ true. |
| render: ogl |
self opaque ifTrue:[ material ifNotNil:[material enable: ogl.]. texture ifNotNil:[texture enable: ogl]. self renderPrimitiveCached: ogl. material ifNotNil:[material disable: ogl.]. texture ifNotNil:[texture disable: ogl.]. ]. |
| renderAlpha: ogl |
materialAlpha ifNotNil:[materialAlpha enable: ogl. ]. textureAlpha ifNotNil:[textureAlpha enable: ogl]. self renderPrimitiveCached: ogl. materialAlpha ifNotNil:[materialAlpha disable: ogl.]. textureAlpha ifNotNil:[textureAlpha disable: ogl.]. |
| renderPrimitive: ogl |
super render: ogl |
| renderPrimitiveCached: ogl |
ogl forceWire ifTrue:[^self renderPrimitive: ogl]. (cachingEnabled = true) ifFalse:[ (glListID notNil and:[ oglInstance = ogl instance]) ifTrue:[ ogl glDeleteLists: glListID with: 1. ogl unregisterList: self. ]. glListID _ nil. cachingEnabled = #reset ifTrue:[ cachingEnabled _ true.]. ^self renderPrimitive: ogl. ]. "if there is a cached list and ogl has not changed, call it" (glListID notNil and: [oglInstance = ogl instance]) ifTrue:[ ogl glCallList: glListID. ] ifFalse:[ glListID _ ogl glGenLists: 1. ogl registerList: glListID range: 1 owner: self. oglInstance _ nil. ogl glNewList: glListID with: GLCompileAndExecute. self renderPrimitive: ogl. "See if current display list completed correctly. If any other has been constructed in the mean time defer this lists creation until the next rendering loop." (ogl glGetInteger: GLListIndex) = glListID ifTrue:[oglInstance _ ogl instance]. ogl glEndList. ]. |