mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-27 03:48:21 +01:00
Use a single big video buffer for rendering instead of one buffer peer primitive shapes
Some checks reported errors
gitea-sync/Diya-API/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
gitea-sync/Diya-API/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
parent
c1f2de2896
commit
d99d6f3604
@ -2,7 +2,8 @@ Class {
|
|||||||
#name : #Diya2DNode,
|
#name : #Diya2DNode,
|
||||||
#superclass : #DiyaNode,
|
#superclass : #DiyaNode,
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'vbuffer'
|
'vbuffer',
|
||||||
|
'voffset'
|
||||||
],
|
],
|
||||||
#category : #'Diya-Graphics'
|
#category : #'Diya-Graphics'
|
||||||
}
|
}
|
||||||
@ -43,6 +44,7 @@ Diya2DNode >> initialize [
|
|||||||
tf := MatrixTransform2x3 identity .
|
tf := MatrixTransform2x3 identity .
|
||||||
shader := Diya2DShader uniqueInstance.
|
shader := Diya2DShader uniqueInstance.
|
||||||
vbuffer := nil.
|
vbuffer := nil.
|
||||||
|
voffset := 0.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -28,18 +28,13 @@ Diya2DPrimShape >> draw [
|
|||||||
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA.
|
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA.
|
||||||
"configure vao vbo for texture QUAD"
|
"configure vao vbo for texture QUAD"
|
||||||
self texture ifNotNil: [
|
self texture ifNotNil: [
|
||||||
self texture setup.
|
context setTexture: self texture.
|
||||||
context texture0 setImage2D: self texture.
|
|
||||||
context texture0 active.
|
|
||||||
].
|
].
|
||||||
context vao enableAttribute: 0.
|
voffset := context submitData: vbuffer.
|
||||||
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil.
|
OpenGL drawArrays: type first: voffset count:((vbuffer size )>> 2 ).
|
||||||
context vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_DYNAMIC_DRAW.
|
|
||||||
OpenGL drawArrays: type first:0 count:((vbuffer size )>> 2 ).
|
|
||||||
"reset value"
|
"reset value"
|
||||||
self texture ifNotNil: [self texture drop.].
|
self texture ifNotNil: [self texture drop.].
|
||||||
self borderWidth > 0 ifTrue: [ self drawBorder ].
|
self borderWidth > 0 ifTrue: [ self drawBorder ].
|
||||||
context vao disableAttribute: 0.
|
|
||||||
OpenGL
|
OpenGL
|
||||||
disable: GL_CULL_FACE;
|
disable: GL_CULL_FACE;
|
||||||
disable: GL_BLEND.
|
disable: GL_BLEND.
|
||||||
|
@ -33,7 +33,7 @@ DiyaConvexPolygon >> calculateVertices [
|
|||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaConvexPolygon >> drawLines [
|
DiyaConvexPolygon >> drawLines [
|
||||||
OpenGL drawArrays: GL_LINE_LOOP first:0 count: (vbuffer size >> 2) - 1.
|
OpenGL drawArrays: GL_LINE_LOOP first:voffset count: (vbuffer size >> 2) - 1.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
|
@ -16,7 +16,7 @@ DiyaRectangle class >> size: size shader:s [
|
|||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaRectangle >> drawLines [
|
DiyaRectangle >> drawLines [
|
||||||
OpenGL drawArrays: GL_LINE_LOOP first:0 count: (vbuffer size >> 2).
|
OpenGL drawArrays: GL_LINE_LOOP first:voffset count: (vbuffer size >> 2).
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@ Class {
|
|||||||
'texture0',
|
'texture0',
|
||||||
'projection',
|
'projection',
|
||||||
'assets',
|
'assets',
|
||||||
'window'
|
'window',
|
||||||
|
'vbuffer',
|
||||||
|
'voffset'
|
||||||
],
|
],
|
||||||
#pools : [
|
#pools : [
|
||||||
'OpenGLConstants',
|
'OpenGLConstants',
|
||||||
@ -18,6 +20,11 @@ Class {
|
|||||||
#category : #'Diya-Graphics'
|
#category : #'Diya-Graphics'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRendererContext class >> bufferSize [
|
||||||
|
^ 524288 "512Kb"
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
DiyaRendererContext class >> cleanUpInstance: singleton [
|
DiyaRendererContext class >> cleanUpInstance: singleton [
|
||||||
singleton ifNil:[^self].
|
singleton ifNil:[^self].
|
||||||
@ -41,11 +48,18 @@ DiyaRendererContext >> assets: anObject [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> destroy [
|
DiyaRendererContext >> destroy [
|
||||||
|
self disableGLAttribute: 0.
|
||||||
|
vbuffer free.
|
||||||
vao delete.
|
vao delete.
|
||||||
vbo delete.
|
vbo delete.
|
||||||
texture0 delete.
|
texture0 delete.
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #registration }
|
||||||
|
DiyaRendererContext >> disableGLAttribute: attribute [
|
||||||
|
vao disableAttribute: attribute
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> display [
|
DiyaRendererContext >> display [
|
||||||
^ display
|
^ display
|
||||||
@ -56,6 +70,11 @@ DiyaRendererContext >> display: anObject [
|
|||||||
display := anObject
|
display := anObject
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #registration }
|
||||||
|
DiyaRendererContext >> enableGLAttribute: attribute [
|
||||||
|
vao enableAttribute: attribute.
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> initialize [
|
DiyaRendererContext >> initialize [
|
||||||
super initialize.
|
super initialize.
|
||||||
@ -66,6 +85,14 @@ DiyaRendererContext >> initialize [
|
|||||||
vbo bind: GL_ARRAY_BUFFER.
|
vbo bind: GL_ARRAY_BUFFER.
|
||||||
projection := Array2D identity: 4.
|
projection := Array2D identity: 4.
|
||||||
assets := AssetManager new.
|
assets := AssetManager new.
|
||||||
|
"allocate vbuffer"
|
||||||
|
vbuffer := FFIExternalArray externalNewType: GLfloat size: self class bufferSize.
|
||||||
|
vbuffer autoRelease.
|
||||||
|
voffset := 0.
|
||||||
|
vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_STREAM_DRAW.
|
||||||
|
self enableGLAttribute: 0.
|
||||||
|
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil.
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
@ -83,17 +110,42 @@ DiyaRendererContext >> projection [
|
|||||||
^ projection
|
^ projection
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #registration }
|
||||||
|
DiyaRendererContext >> resetBuffer [
|
||||||
|
voffset := 0
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> resolution [
|
DiyaRendererContext >> resolution [
|
||||||
^ (display w) @ (display h)
|
^ (display w) @ (display h)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #registration }
|
||||||
|
DiyaRendererContext >> setTexture: texture [
|
||||||
|
texture setup.
|
||||||
|
texture0 setImage2D: texture.
|
||||||
|
texture0 active.
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #registration }
|
||||||
|
DiyaRendererContext >> submitData: data [
|
||||||
|
|n|
|
||||||
|
n := self voffset.
|
||||||
|
voffset := voffset + (data size << 2).
|
||||||
|
voffset > self class bufferSize ifTrue:[
|
||||||
|
^ DiyaCoreAPIError signal: 'Out of video buffer memory'
|
||||||
|
].
|
||||||
|
vbo subData: GL_ARRAY_BUFFER offset: n data: data.
|
||||||
|
^ (n >> 4)
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> texture0 [
|
DiyaRendererContext >> texture0 [
|
||||||
^ texture0
|
^ texture0
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'as yet unclassified' }
|
{ #category : #registration }
|
||||||
DiyaRendererContext >> useProjection: aClass [
|
DiyaRendererContext >> useProjection: aClass [
|
||||||
projection := aClass fromDisplay: self display
|
projection := aClass fromDisplay: self display
|
||||||
]
|
]
|
||||||
@ -108,6 +160,16 @@ DiyaRendererContext >> vbo [
|
|||||||
^ vbo
|
^ vbo
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRendererContext >> vbuffer [
|
||||||
|
^ vbuffer
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRendererContext >> voffset [
|
||||||
|
^ voffset
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> window [
|
DiyaRendererContext >> window [
|
||||||
^ window
|
^ window
|
||||||
|
@ -25,10 +25,11 @@ DiyaRootNode >> cleanDirtyNode: aNode [
|
|||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRootNode >> draw [
|
DiyaRootNode >> draw [
|
||||||
|c|
|
|c|
|
||||||
|
context resetBuffer.
|
||||||
c := self ? #bgColor.
|
c := self ? #bgColor.
|
||||||
OpenGL clearColorR: c red G: c green B: c blue A: c alpha.
|
OpenGL clearColorR: c red G: c green B: c blue A: c alpha.
|
||||||
OpenGL clear: GL_COLOR_BUFFER_BIT.
|
OpenGL clear: GL_COLOR_BUFFER_BIT.
|
||||||
context vbo bind: GL_ARRAY_BUFFER.
|
"context vbo bind: GL_ARRAY_BUFFER."
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'add/remove' }
|
{ #category : #'add/remove' }
|
||||||
|
@ -62,6 +62,7 @@ Class {
|
|||||||
'GL_SRC_ALPHA',
|
'GL_SRC_ALPHA',
|
||||||
'GL_STATIC_DRAW',
|
'GL_STATIC_DRAW',
|
||||||
'GL_STENCIL_BUFFER_BIT',
|
'GL_STENCIL_BUFFER_BIT',
|
||||||
|
'GL_STREAM_DRAW',
|
||||||
'GL_TESS_CONTROL_SHADER',
|
'GL_TESS_CONTROL_SHADER',
|
||||||
'GL_TESS_EVALUATION_SHADER',
|
'GL_TESS_EVALUATION_SHADER',
|
||||||
'GL_TEXTURE_2D',
|
'GL_TEXTURE_2D',
|
||||||
@ -108,6 +109,7 @@ OpenGLConstants class >> initCommonConstants [
|
|||||||
GL_UNIFORM_BUFFER := 16r8A11.
|
GL_UNIFORM_BUFFER := 16r8A11.
|
||||||
GL_STATIC_DRAW := 16r88E4.
|
GL_STATIC_DRAW := 16r88E4.
|
||||||
GL_DYNAMIC_DRAW := 16r88E8.
|
GL_DYNAMIC_DRAW := 16r88E8.
|
||||||
|
GL_STREAM_DRAW := 16r88E0.
|
||||||
GL_FALSE := 0.
|
GL_FALSE := 0.
|
||||||
GL_TRUE := 1.
|
GL_TRUE := 1.
|
||||||
GL_ARRAY_BUFFER_BINDING := 16r8894.
|
GL_ARRAY_BUFFER_BINDING := 16r8894.
|
||||||
|
@ -26,7 +26,7 @@ OpenGLVertexBuffer class >> deleteBuffersSize:n buffers: buffers [
|
|||||||
^self ffiCall: #(void glDeleteBuffers( GLsizei n,const GLuint * buffers))
|
^self ffiCall: #(void glDeleteBuffers( GLsizei n,const GLuint * buffers))
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'as yet unclassified' }
|
{ #category : #'library path' }
|
||||||
OpenGLVertexBuffer class >> ffiLibraryName [
|
OpenGLVertexBuffer class >> ffiLibraryName [
|
||||||
^ OpenGL ffiLibraryName
|
^ OpenGL ffiLibraryName
|
||||||
]
|
]
|
||||||
@ -78,7 +78,8 @@ OpenGLVertexBuffer >> initialize [
|
|||||||
vertexBufferID := FFIExternalArray externalNewType: GLint size:1.
|
vertexBufferID := FFIExternalArray externalNewType: GLint size:1.
|
||||||
vertexBufferID at:1 put: -1.
|
vertexBufferID at:1 put: -1.
|
||||||
vertexBufferID autoRelease.
|
vertexBufferID autoRelease.
|
||||||
OpenGLVertexBuffer genVertexBuffersSize: 1 buffers: vertexBufferID getHandle
|
OpenGLVertexBuffer genVertexBuffersSize: 1 buffers: vertexBufferID getHandle.
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'as yet unclassified' }
|
{ #category : #'as yet unclassified' }
|
||||||
|
Loading…
Reference in New Issue
Block a user