@@ -3,11 +3,14 @@ stores functions needed to create bind and update OpenGl textues
33"""
44module TextureManag
55using Base: Float16
6+ using GLFW
67using ModernGL, Base. Threads, Logging, Setfield
78using .. OpenGLDisplayUtils, .. ForDisplayStructs, .. Uniforms, .. CustomFragShad, .. DataStructs, .. DisplayWords
89export activateTextures, addTextToTexture, initializeTextures, createTexture, getProperGL_TEXTURE, updateImagesDisplayed, updateTexture, assignUniformsAndTypesToMasks
910
1011
12+
13+
1114"""
1215uploading data to given texture; of given types associated - specified in TextureSpec
1316if we want to update only part of the texture we need to specify offset and size of texture we use
@@ -138,45 +141,112 @@ function getProperGL_TEXTURE(index::Int)::UInt32
138141 return eval (Meta. parse (" GL_TEXTURE$(index) " ))
139142end # getProperGL_TEXTURE
140143
144+ """
145+ Defines the switching of vao buffers for the rendering of
146+ dynamic crosshair
147+ """
148+ # function crosshairDisplay(crosshair::GlShaderAndBufferFields, mainRect::GlShaderAndBufferFields, forDisplayConstants::forDisplayObjects)
149+ # #render onto the screen
150+ # glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, C_NULL) #taken out from the basicRender
151+ # ############################################
152+ # # glBindVertexArray(0) #unbinding the vao for main rect
153+ # # glUseProgram(crosshair.shaderProgram)
154+ # glBindVertexArray(crosshair.vao[]) #binding the vao for crosshair
155+ # glDrawElements(GL_LINES, 4, GL_UNSIGNED_INT, C_NULL)
156+
157+ # glBindVertexArray(0)
158+ # # glUseProgram(mainRect.shaderProgram) #unbinding the vao for crosshair
159+ # glBindVertexArray(mainRect.vao[])
160+ # ############################################
161+
162+ # GLFW.SwapBuffers(forDisplayConstants.window) #from basic render function
163+
164+ # end
165+ function crosshairDisplay (crosshair:: GlShaderAndBufferFields , mainRect:: GlShaderAndBufferFields , forDisplayConstants:: forDisplayObjects )
166+ # Render main image
167+ glDrawElements (GL_TRIANGLES, 6 , GL_UNSIGNED_INT, C_NULL )
168+
169+ # Switch to crosshair shader and render crosshair
170+ glUseProgram (crosshair. shaderProgram)
171+ glBindVertexArray (crosshair. vao[])
172+ glDrawElements (GL_LINES, 4 , GL_UNSIGNED_INT, C_NULL )
173+
174+ # Switch back to main shader program
175+ # using the shader program from the mainRect causes the image render to disappear, so better use the one from forDisplayConstants !!
176+ glUseProgram (forDisplayConstants. shader_program)
177+ glBindVertexArray (mainRect. vao[])
178+
179+ GLFW. SwapBuffers (forDisplayConstants. window)
180+ end
141181"""
142182coordinating updating all of the images, masks...
143183singleSliceDat - holds data we want to use for update
144184forDisplayObjects - stores all needed constants that holds reference to GLFW and OpenGL
145185"""
146- function updateImagesDisplayed (singleSliceDat:: SingleSliceDat , forDisplayConstants:: forDisplayObjects , wordsDispObj:: ForWordsDispStruct , calcDimStruct:: CalcDimsStruct , valueForMaskToSett:: valueForMasToSetStruct )
186+ function updateImagesDisplayed (
187+ singleSliceDat:: SingleSliceDat ,
188+ forDisplayConstants:: forDisplayObjects ,
189+ wordsDispObj:: ForWordsDispStruct ,
190+ calcDimStruct:: CalcDimsStruct ,
191+ valueForMaskToSett:: valueForMasToSetStruct ,
192+ crosshair:: GlShaderAndBufferFields ,
193+ mainRect:: GlShaderAndBufferFields ,
194+ displayMode:: DisplayMode )
195+
196+
197+ updateImagesDisplayed_inner (
198+ singleSliceDat,
199+ forDisplayConstants,
200+ wordsDispObj,
201+ calcDimStruct,
202+ valueForMaskToSett,
203+ crosshair,
204+ mainRect,
205+ displayMode)
206+ end
207+
208+ function updateImagesDisplayed_inner (
209+ singleSliceDat:: SingleSliceDat ,
210+ forDisplayConstants:: forDisplayObjects ,
211+ wordsDispObj:: ForWordsDispStruct ,
212+ calcDimStruct:: CalcDimsStruct ,
213+ valueForMaskToSett:: valueForMasToSetStruct ,
214+ crosshair:: GlShaderAndBufferFields ,
215+ mainRect:: GlShaderAndBufferFields ,
216+ displayMode:: DisplayMode )
147217
148218
149- updateImagesDisplayed_inner (singleSliceDat, forDisplayConstants, wordsDispObj, calcDimStruct, valueForMaskToSett)
150- end
151219
152- function updateImagesDisplayed_inner (singleSliceDat:: SingleSliceDat , forDisplayConstants:: forDisplayObjects , wordsDispObj:: ForWordsDispStruct , calcDimStruct:: CalcDimsStruct , valueForMaskToSett:: valueForMasToSetStruct )
153- # @info "top of updateimaegsDisplayed_inner"
154220 modulelistOfTextSpecs = forDisplayConstants. listOfTextSpecifications
155221
156222 for updateDat in singleSliceDat. listOfDataAndImageNames
157223 findList = findall ((texSpec) -> texSpec. name == updateDat. name, modulelistOfTextSpecs)
158- texSpec = ! isempty (findList) ? modulelistOfTextSpecs[findList[1 ]] : throw (DomainError (findList, " no such name specified in start configuration - $( updateDat[1 ]) " ))
159- updateTexture (updateDat. type, updateDat. dat, texSpec, 0 , 0 , calcDimStruct. imageTextureWidth, calcDimStruct. imageTextureHeight)
224+ # texSpec = !isempty(findList) ? modulelistOfTextSpecs[findList[1]] : throw(DomainError(findList, "no such name specified in start configuration - $( updateDat[1])"))
225+ texSpec = Nothing
226+ if ! isempty (findList)
227+ texSpec = modulelistOfTextSpecs[findList[1 ]]
228+ updateTexture (updateDat. type, updateDat. dat, texSpec, 0 , 0 , calcDimStruct. imageTextureWidth, calcDimStruct. imageTextureHeight)
229+ end
160230 end # for
161231 # render text associated with this slice
162232
163- # @info "above activate for text display"
164233 activateForTextDisp (
165234 wordsDispObj. shader_program_words, wordsDispObj. vbo_words, calcDimStruct)
166235
167-
168- # @info "below activate for text display"
169236 matr = addTextToTexture (wordsDispObj, [singleSliceDat. textToDisp... , valueForMaskToSett. text], calcDimStruct)
170237
171238 glDrawElements (GL_TRIANGLES, 6 , GL_UNSIGNED_INT, C_NULL )
172239
173- # @info "inside updateImagesDisplayed_inner"
174-
175240 reactivateMainObj (forDisplayConstants. shader_program, forDisplayConstants. vbo, calcDimStruct)
176241
177242
178- # render onto the screen
243+ # only display crosshair in multi-image display mode
244+ # if displayMode == SingleImage
179245 OpenGLDisplayUtils. basicRender (forDisplayConstants. window)
246+ # elseif displayMode == MultiImage
247+ # crosshairDisplay(crosshair, mainRect, forDisplayConstants) #[source of issue in multi image and images do no apeear]
248+ # end
249+
180250 glFinish ()
181251end
182252
@@ -189,7 +259,7 @@ It would also assign proper openGl types to given julia data type, and pass data
189259textSpecs - list of texture specificaton that we want to enrich by adding information about ..Uniforms
190260return list of texture specifications enriched by information about ..Uniforms
191261"""
192- function assignUniformsAndTypesToMasks (textSpecs:: Vector{TextureSpec} , shader_program:: UInt32 , windowControlStruct :: WindowControlStruct )
262+ function assignUniformsAndTypesToMasks (textSpecs:: Vector{TextureSpec{Float32}} , shader_program:: UInt32 )
193263
194264
195265 mapped = map (x -> setuniforms (x, shader_program), textSpecs)
@@ -375,3 +445,4 @@ end #addTextToTexture
375445
376446
377447end # ..TextureManag
448+
0 commit comments