mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-26 03:18:22 +01:00
f61e17de9c
Some checks reported errors
gitea-sync/Diya-API/pipeline/head Something is wrong with the build of this commit
180 lines
3.5 KiB
Smalltalk
180 lines
3.5 KiB
Smalltalk
Class {
|
|
#name : #DiyaRendererContext,
|
|
#superclass : #DiyaSingleton,
|
|
#instVars : [
|
|
'mouse',
|
|
'display',
|
|
'vbo',
|
|
'vao',
|
|
'textures',
|
|
'projection',
|
|
'assets',
|
|
'window',
|
|
'root',
|
|
'lock'
|
|
],
|
|
#pools : [
|
|
'OpenGLConstants',
|
|
'OpenGLTypes'
|
|
],
|
|
#category : #'Diya-Graphics'
|
|
}
|
|
|
|
{ #category : #'instance creation' }
|
|
DiyaRendererContext class >> cleanUpInstance: singleton [
|
|
singleton ifNil:[^self].
|
|
singleton destroy
|
|
]
|
|
|
|
{ #category : #'instance creation' }
|
|
DiyaRendererContext class >> maxFloatBufferSize [
|
|
^4096
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext class >> maxTextureNumber [
|
|
^ 32
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> assets [
|
|
^ assets
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> assets: anObject [
|
|
assets := anObject
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> destroy [
|
|
vao disableAttribute: 0.
|
|
vao delete.
|
|
vbo delete.
|
|
textures do: [:e | e key delete ].
|
|
textures := OrderedCollection new.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> display [
|
|
^ display
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> display: anObject [
|
|
display := anObject
|
|
]
|
|
|
|
{ #category : #rendering }
|
|
DiyaRendererContext >> findTextureUnit [
|
|
textures withIndexDo: [ :e :i|
|
|
e value ifNil: [ ^ i - 1]
|
|
].
|
|
"random unit value"
|
|
^ (Random new nextInt: self class maxTextureNumber) - 1
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> initialize [
|
|
super initialize.
|
|
vbo := OpenGLVertexBuffer new.
|
|
vao := OpenGLVertexArray new.
|
|
textures := Dictionary new.
|
|
lock := Mutex new.
|
|
vao bind.
|
|
vbo bind: GL_ARRAY_BUFFER.
|
|
projection := Array2D identity: 4.
|
|
assets := AssetManager new.
|
|
vao enableAttribute: 0.
|
|
OpenGLVertexArray
|
|
vertexAttributePointerIndex: 0
|
|
size:4
|
|
type: GL_FLOAT
|
|
normalized: GL_FALSE
|
|
stride: 16
|
|
pointer: nil.
|
|
textures :=
|
|
(1 to: self class maxTextureNumber ) collect:[:i|
|
|
(OpenGLTexture fromUnit: i - 1) -> nil] .
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> lock [
|
|
^ lock
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> mouse [
|
|
^ mouse
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> mouse: anObject [
|
|
mouse := anObject
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> projection [
|
|
^ projection
|
|
]
|
|
|
|
{ #category : #rendering }
|
|
DiyaRendererContext >> render [
|
|
root render.
|
|
root readyForSwap ifTrue: [
|
|
SDL2 glSwapWindow: window.
|
|
]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> resolution [
|
|
^ (display w) @ (display h)
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> root [
|
|
root ifNil: [ root := DiyaRootNode new ].
|
|
^ root
|
|
|
|
|
|
|
|
]
|
|
|
|
{ #category : #rendering }
|
|
DiyaRendererContext >> submitData: vbuffer [
|
|
vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_STATIC_DRAW.
|
|
]
|
|
|
|
{ #category : #'transformation matrices' }
|
|
DiyaRendererContext >> useProjection: aClass [
|
|
projection := aClass fromDisplay: self display
|
|
]
|
|
|
|
{ #category : #rendering }
|
|
DiyaRendererContext >> useTexture: aTexture [
|
|
|assoc|
|
|
aTexture unit == -1 ifTrue:[ aTexture unit: self findTextureUnit].
|
|
assoc := textures at: aTexture unit + 1.
|
|
assoc value = aTexture ifFalse:[
|
|
"unregister current texture"
|
|
assoc value ifNotNil: [ assoc value commited: false ].
|
|
aTexture commited: false.
|
|
assoc value: aTexture.
|
|
].
|
|
assoc key active.
|
|
aTexture commited ifTrue:[ ^ self ].
|
|
"self stdlog: 'Commit data data to texture ', aTexture name, ' on Unit ', aTexture unit asString."
|
|
assoc key setImage2D: aTexture.
|
|
aTexture commited: true.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> window [
|
|
^ window
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaRendererContext >> window: anObject [
|
|
window := anObject
|
|
]
|