1
1
using ColorChord . NET . API ;
2
+ using ColorChord . NET . API . Config ;
2
3
using ColorChord . NET . API . Outputs . Display ;
3
4
using ColorChord . NET . API . Visualizers ;
4
5
using ColorChord . NET . API . Visualizers . Formats ;
6
+ using ColorChord . NET . Config ;
5
7
using OpenTK . Graphics . OpenGL4 ;
6
8
using OpenTK . Mathematics ;
7
9
using OpenTK . Windowing . Common ;
8
10
using OpenTK . Windowing . GraphicsLibraryFramework ;
9
11
using System ;
12
+ using System . Collections . Generic ;
10
13
11
14
namespace ColorChord . NET . Outputs . Display ;
12
15
13
- public class CaptureCompare : IDisplayMode
16
+ public class CaptureCompare : IDisplayMode , IConfigurableAttr
14
17
{
15
18
private readonly DisplayOpenGL HostWindow ;
16
19
private readonly IDiscrete1D DataSourceA , DataSourceB ;
17
20
18
- private const int TEX_HEIGHT = 128 ;
21
+ [ ConfigInt ( "HistoryLength" , 16 , 16384 , 768 ) ]
22
+ private int TextureHeight = 768 ;
19
23
20
24
private Shader ? Shader ;
21
25
@@ -44,11 +48,17 @@ public class CaptureCompare : IDisplayMode
44
48
- 1F , 1F , 0F , 0F
45
49
} ;
46
50
47
- public CaptureCompare ( DisplayOpenGL parent , IVisualizer visualizer )
51
+ public CaptureCompare ( DisplayOpenGL parent , IVisualizer visualizer , Dictionary < string , object > config )
48
52
{
49
53
this . HostWindow = parent ;
50
54
this . DataSourceA = visualizer as IDiscrete1D ?? throw new Exception ( $ "{ nameof ( CaptureCompare ) } cannot use the provided visualizer, as it doesn't support { nameof ( IDiscrete1D ) } output mode.") ;
51
- this . DataSourceB = this . DataSourceA ; // TODO: Actually read the second one
55
+
56
+ IDiscrete1D ? DataSourceBTemp = null ;
57
+ if ( config . TryGetValue ( "SecondaryVisualizer" , out object ? SecondVizNameObj ) && SecondVizNameObj is string SecondVizName ) { DataSourceBTemp = Configurer . FindComponentByName ( Component . Visualizers , SecondVizName ) as IDiscrete1D ; }
58
+ if ( DataSourceBTemp == null ) { Log . Warn ( $ "{ nameof ( CaptureCompare ) } could not find the secondary visualizer, and is instead using the primary one for both inputs. You may set it using \" SecondaryVisualizer\" .") ; }
59
+ this . DataSourceB = DataSourceBTemp ?? this . DataSourceA ;
60
+ config . Remove ( "SecondaryVisualizer" ) ;
61
+ Configurer . Configure ( this , config ) ;
52
62
}
53
63
54
64
public void Load ( )
@@ -67,37 +77,37 @@ public void Load()
67
77
this . TextureHandleCaptureB = GL . GenTexture ( ) ;
68
78
this . TextureWidthA = this . DataSourceA . GetCountDiscrete ( ) ;
69
79
this . TextureWidthB = this . DataSourceB . GetCountDiscrete ( ) ;
70
- this . NewTextureDataA = new uint [ this . TextureWidthA * TEX_HEIGHT ] ;
71
- this . NewTextureDataB = new uint [ this . TextureWidthB * TEX_HEIGHT ] ;
80
+ this . NewTextureDataA = new uint [ this . TextureWidthA * TextureHeight ] ;
81
+ this . NewTextureDataB = new uint [ this . TextureWidthB * TextureHeight ] ;
72
82
73
83
// Activate texture
74
84
GL . ActiveTexture ( TextureUnit . Texture0 ) ;
75
85
GL . BindTexture ( TextureTarget . Texture2D , this . TextureHandleA ) ;
76
- GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthA , TEX_HEIGHT , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
86
+ GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthA , TextureHeight , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
77
87
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMinFilter , ( int ) TextureMinFilter . Nearest ) ;
78
88
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMagFilter , ( int ) TextureMinFilter . Nearest ) ;
79
89
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapS , ( int ) TextureWrapMode . Repeat ) ;
80
90
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapT , ( int ) TextureWrapMode . Repeat ) ;
81
91
82
92
GL . ActiveTexture ( TextureUnit . Texture1 ) ;
83
93
GL . BindTexture ( TextureTarget . Texture2D , this . TextureHandleB ) ;
84
- GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthB , TEX_HEIGHT , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataB ) ;
94
+ GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthB , TextureHeight , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataB ) ;
85
95
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMinFilter , ( int ) TextureMinFilter . Nearest ) ;
86
96
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMagFilter , ( int ) TextureMinFilter . Nearest ) ;
87
97
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapS , ( int ) TextureWrapMode . Repeat ) ;
88
98
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapT , ( int ) TextureWrapMode . Repeat ) ;
89
99
90
100
GL . ActiveTexture ( TextureUnit . Texture2 ) ;
91
101
GL . BindTexture ( TextureTarget . Texture2D , this . TextureHandleCaptureA ) ;
92
- GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthA , TEX_HEIGHT , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
102
+ GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthA , TextureHeight , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
93
103
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMinFilter , ( int ) TextureMinFilter . Nearest ) ;
94
104
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMagFilter , ( int ) TextureMinFilter . Nearest ) ;
95
105
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapS , ( int ) TextureWrapMode . Repeat ) ;
96
106
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapT , ( int ) TextureWrapMode . Repeat ) ;
97
107
98
108
GL . ActiveTexture ( TextureUnit . Texture3 ) ;
99
109
GL . BindTexture ( TextureTarget . Texture2D , this . TextureHandleCaptureB ) ;
100
- GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthB , TEX_HEIGHT , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataB ) ;
110
+ GL . TexImage2D ( TextureTarget . Texture2D , 0 , PixelInternalFormat . Rgba , this . TextureWidthB , TextureHeight , 0 , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataB ) ;
101
111
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMinFilter , ( int ) TextureMinFilter . Nearest ) ;
102
112
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureMagFilter , ( int ) TextureMinFilter . Nearest ) ;
103
113
GL . TexParameter ( TextureTarget . Texture2D , TextureParameterName . TextureWrapS , ( int ) TextureWrapMode . Repeat ) ;
@@ -139,17 +149,28 @@ public void Load()
139
149
public void Dispatch ( )
140
150
{
141
151
if ( ! this . SetupDone ) { return ; }
142
- bool IsFromA = true ;
143
- IDiscrete1D Source = IsFromA ? this . DataSourceA : this . DataSourceB ;
144
152
145
- int Count = Source . GetCountDiscrete ( ) ;
146
- uint [ ] Data = Source . GetDataDiscrete ( ) ;
147
- if ( PopulatedTextureLocA == TEX_HEIGHT - 1 ) { return ; } // Drop this data, we are too behind
148
- lock ( NewTextureDataA )
149
153
{
150
- Array . Copy ( Data , 0 , NewTextureDataA , PopulatedTextureLocA * TextureWidthA , Count ) ;
151
- PopulatedTextureLocA ++ ;
154
+ int Count = this . DataSourceA . GetCountDiscrete ( ) ;
155
+ uint [ ] Data = this . DataSourceA . GetDataDiscrete ( ) ;
156
+ if ( this . PopulatedTextureLocA >= TextureHeight - 1 ) { return ; } // Drop this data, we are too behind
157
+ lock ( this . NewTextureDataA )
158
+ {
159
+ Array . Copy ( Data , 0 , this . NewTextureDataA , this . PopulatedTextureLocA * TextureWidthA , Count ) ;
160
+ this . PopulatedTextureLocA ++ ;
161
+ }
152
162
}
163
+ {
164
+ int Count = this . DataSourceB . GetCountDiscrete ( ) ;
165
+ uint [ ] Data = this . DataSourceB . GetDataDiscrete ( ) ;
166
+ if ( this . PopulatedTextureLocB >= TextureHeight - 1 ) { return ; } // Drop this data, we are too behind
167
+ lock ( this . NewTextureDataB )
168
+ {
169
+ Array . Copy ( Data , 0 , this . NewTextureDataB , this . PopulatedTextureLocB * TextureWidthB , Count ) ;
170
+ this . PopulatedTextureLocB ++ ;
171
+ }
172
+ }
173
+
153
174
this . NewData = true ;
154
175
}
155
176
@@ -163,30 +184,57 @@ public void Render()
163
184
if ( this . PopulatedTextureLocA != 0 )
164
185
{
165
186
GL . ActiveTexture ( TextureUnit . Texture0 ) ;
166
- lock ( NewTextureDataA )
187
+ lock ( this . NewTextureDataA )
167
188
{
168
- GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , this . UploadedTextureLocA , this . TextureWidthA , this . PopulatedTextureLocA , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
169
- this . UploadedTextureLocA = ( this . UploadedTextureLocA + this . PopulatedTextureLocA ) % TEX_HEIGHT ;
170
- GL . Uniform1 ( this . LocationAdvanceALive , ( float ) this . UploadedTextureLocA / TEX_HEIGHT ) ;
189
+ if ( this . UploadedTextureLocA + this . PopulatedTextureLocA < TextureHeight )
190
+ {
191
+ GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , this . UploadedTextureLocA , this . TextureWidthA , this . PopulatedTextureLocA , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
192
+ }
193
+ else
194
+ {
195
+ int BottomCount = TextureHeight - this . UploadedTextureLocA ;
196
+ int TopCount = this . PopulatedTextureLocA - BottomCount ;
197
+ GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , this . UploadedTextureLocA , this . TextureWidthA , BottomCount , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataA ) ;
198
+ GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , 0 , this . TextureWidthA , TopCount , PixelFormat . Rgba , PixelType . UnsignedByte , ref this . NewTextureDataA [ this . TextureWidthA * BottomCount ] ) ;
199
+ }
200
+ this . UploadedTextureLocA = ( this . UploadedTextureLocA + this . PopulatedTextureLocA ) % TextureHeight ;
201
+ GL . Uniform1 ( this . LocationAdvanceALive , ( float ) this . UploadedTextureLocA / TextureHeight ) ;
171
202
this . PopulatedTextureLocA = 0 ;
172
203
}
173
204
}
174
205
if ( this . PopulatedTextureLocB != 0 )
175
206
{
176
-
207
+ GL . ActiveTexture ( TextureUnit . Texture1 ) ;
208
+ lock ( this . NewTextureDataB )
209
+ {
210
+ if ( this . UploadedTextureLocB + this . PopulatedTextureLocB < TextureHeight )
211
+ {
212
+ GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , this . UploadedTextureLocB , this . TextureWidthB , this . PopulatedTextureLocB , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataB ) ;
213
+ }
214
+ else
215
+ {
216
+ int BottomCount = TextureHeight - this . UploadedTextureLocB ;
217
+ int TopCount = this . PopulatedTextureLocB - BottomCount ;
218
+ GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , this . UploadedTextureLocB , this . TextureWidthB , BottomCount , PixelFormat . Rgba , PixelType . UnsignedByte , this . NewTextureDataB ) ;
219
+ GL . TexSubImage2D ( TextureTarget . Texture2D , 0 , 0 , 0 , this . TextureWidthB , TopCount , PixelFormat . Rgba , PixelType . UnsignedByte , ref this . NewTextureDataB [ this . TextureWidthB * BottomCount ] ) ;
220
+ }
221
+ this . UploadedTextureLocB = ( this . UploadedTextureLocB + this . PopulatedTextureLocB ) % TextureHeight ;
222
+ GL . Uniform1 ( this . LocationAdvanceBLive , ( float ) this . UploadedTextureLocB / TextureHeight ) ;
223
+ this . PopulatedTextureLocB = 0 ;
224
+ }
177
225
}
178
226
}
179
227
180
228
if ( this . DoCaptureA )
181
229
{
182
- GL . CopyImageSubData ( this . TextureHandleA , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureHandleCaptureA , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureWidthA , TEX_HEIGHT , 1 ) ;
183
- GL . Uniform1 ( this . LocationAdvanceACapture , ( float ) this . UploadedTextureLocA / TEX_HEIGHT ) ;
230
+ GL . CopyImageSubData ( this . TextureHandleA , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureHandleCaptureA , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureWidthA , TextureHeight , 1 ) ;
231
+ GL . Uniform1 ( this . LocationAdvanceACapture , ( float ) this . UploadedTextureLocA / TextureHeight ) ;
184
232
this . DoCaptureA = false ;
185
233
}
186
234
if ( this . DoCaptureB )
187
235
{
188
- GL . CopyImageSubData ( this . TextureHandleA , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureHandleCaptureB , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureWidthA , TEX_HEIGHT , 1 ) ;
189
- GL . Uniform1 ( this . LocationAdvanceBCapture , ( float ) this . UploadedTextureLocA / TEX_HEIGHT ) ;
236
+ GL . CopyImageSubData ( this . TextureHandleB , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureHandleCaptureB , ImageTarget . Texture2D , 0 , 0 , 0 , 0 , this . TextureWidthB , TextureHeight , 1 ) ;
237
+ GL . Uniform1 ( this . LocationAdvanceBCapture , ( float ) this . UploadedTextureLocB / TextureHeight ) ;
190
238
this . DoCaptureB = false ;
191
239
}
192
240
0 commit comments