2022-02-15 18:04:54 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaRendererContext,
|
|
|
|
#superclass : #DiyaSingleton,
|
|
|
|
#instVars : [
|
|
|
|
'mouse',
|
2022-03-02 20:11:01 +01:00
|
|
|
'display',
|
|
|
|
'vbo',
|
2022-03-03 19:19:40 +01:00
|
|
|
'vao',
|
2022-08-14 15:42:59 +02:00
|
|
|
'textures',
|
2022-03-21 18:03:15 +01:00
|
|
|
'projection',
|
2022-08-10 19:55:49 +02:00
|
|
|
'assets',
|
2022-08-14 01:38:22 +02:00
|
|
|
'window',
|
|
|
|
'root'
|
2022-02-15 18:04:54 +01:00
|
|
|
],
|
|
|
|
#pools : [
|
|
|
|
'OpenGLConstants',
|
|
|
|
'OpenGLTypes'
|
|
|
|
],
|
|
|
|
#category : #'Diya-Graphics'
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:11:01 +01:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaRendererContext class >> cleanUpInstance: singleton [
|
2022-03-15 19:11:19 +01:00
|
|
|
singleton ifNil:[^self].
|
2022-03-02 20:11:01 +01:00
|
|
|
singleton destroy
|
|
|
|
]
|
|
|
|
|
2022-03-06 12:07:20 +01:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaRendererContext class >> maxFloatBufferSize [
|
2022-03-06 18:33:10 +01:00
|
|
|
^4096
|
2022-03-06 12:07:20 +01:00
|
|
|
]
|
|
|
|
|
2022-08-14 18:13:23 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext class >> maxTextureNumber [
|
|
|
|
^ 32
|
|
|
|
]
|
|
|
|
|
2022-03-21 18:03:15 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> assets [
|
|
|
|
^ assets
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> assets: anObject [
|
|
|
|
assets := anObject
|
|
|
|
]
|
|
|
|
|
2022-03-02 20:11:01 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> destroy [
|
2022-08-13 23:48:23 +02:00
|
|
|
vao disableAttribute: 0.
|
2022-03-02 20:11:01 +01:00
|
|
|
vao delete.
|
|
|
|
vbo delete.
|
2022-08-14 15:42:59 +02:00
|
|
|
textures do: [:e | e key delete ].
|
|
|
|
textures := OrderedCollection new.
|
2022-03-02 20:11:01 +01:00
|
|
|
]
|
|
|
|
|
2022-02-15 18:04:54 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> display [
|
|
|
|
^ display
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> display: anObject [
|
|
|
|
display := anObject
|
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #rendering }
|
|
|
|
DiyaRendererContext >> findTextureUnit [
|
|
|
|
textures withIndexDo: [ :e :i|
|
|
|
|
e value ifNil: [ ^ i - 1]
|
|
|
|
].
|
|
|
|
"random unit value"
|
2022-08-14 18:13:23 +02:00
|
|
|
^ (Random new nextInt: self class maxTextureNumber) - 1
|
2022-08-14 15:42:59 +02:00
|
|
|
]
|
|
|
|
|
2022-03-02 20:11:01 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> initialize [
|
|
|
|
super initialize.
|
|
|
|
vbo := OpenGLVertexBuffer new.
|
|
|
|
vao := OpenGLVertexArray new.
|
2022-08-14 15:42:59 +02:00
|
|
|
textures := Dictionary new.
|
2022-03-02 20:11:01 +01:00
|
|
|
vao bind.
|
|
|
|
vbo bind: GL_ARRAY_BUFFER.
|
2022-03-03 19:19:40 +01:00
|
|
|
projection := Array2D identity: 4.
|
2022-03-21 18:03:15 +01:00
|
|
|
assets := AssetManager new.
|
2022-08-13 23:48:23 +02:00
|
|
|
vao enableAttribute: 0.
|
2022-08-14 15:42:59 +02:00
|
|
|
OpenGLVertexArray
|
|
|
|
vertexAttributePointerIndex: 0
|
|
|
|
size:4
|
|
|
|
type: GL_FLOAT
|
|
|
|
normalized: GL_FALSE
|
|
|
|
stride: 16
|
|
|
|
pointer: nil.
|
|
|
|
textures :=
|
2022-08-14 18:13:23 +02:00
|
|
|
(1 to: self class maxTextureNumber ) collect:[:i|
|
2022-08-14 15:42:59 +02:00
|
|
|
(OpenGLTexture fromUnit: i - 1) -> nil] .
|
2022-03-02 20:11:01 +01:00
|
|
|
]
|
|
|
|
|
2022-02-15 18:04:54 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> mouse [
|
|
|
|
^ mouse
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> mouse: anObject [
|
|
|
|
mouse := anObject
|
|
|
|
]
|
|
|
|
|
2022-03-03 19:19:40 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> projection [
|
|
|
|
^ projection
|
|
|
|
]
|
|
|
|
|
2022-08-14 01:38:22 +02:00
|
|
|
{ #category : #rendering }
|
|
|
|
DiyaRendererContext >> render [
|
|
|
|
root render.
|
|
|
|
root readyForSwap ifTrue: [
|
|
|
|
SDL2 glSwapWindow: window.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2022-08-12 16:37:53 +02:00
|
|
|
{ #category : #accessing }
|
2022-02-15 18:04:54 +01:00
|
|
|
DiyaRendererContext >> resolution [
|
|
|
|
^ (display w) @ (display h)
|
|
|
|
]
|
2022-03-02 20:11:01 +01:00
|
|
|
|
2022-08-14 01:38:22 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> root [
|
|
|
|
root ifNil: [ root := DiyaRootNode new ].
|
|
|
|
^ root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #rendering }
|
|
|
|
DiyaRendererContext >> submitData: vbuffer [
|
2022-08-15 12:28:09 +02:00
|
|
|
vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_STATIC_DRAW.
|
2022-03-03 19:19:40 +01:00
|
|
|
]
|
|
|
|
|
2022-08-14 01:38:22 +02:00
|
|
|
{ #category : #'transformation matrices' }
|
2022-03-03 19:19:40 +01:00
|
|
|
DiyaRendererContext >> useProjection: aClass [
|
|
|
|
projection := aClass fromDisplay: self display
|
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #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.
|
|
|
|
]
|
|
|
|
|
2022-08-10 19:55:49 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> window [
|
|
|
|
^ window
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaRendererContext >> window: anObject [
|
|
|
|
window := anObject
|
|
|
|
]
|