我在 Mac OS 上的目标 c 中使用 AudioVisualizer。我有 2 个 NSWindows,里面有 NSOpenGLView。
如果仅使用 NSOpenGLView 打开 1 个 NSWindow,它会显示没有任何问题的形状。
但是如果打开2个上面有NSOpenGLView的NSWindows,只有一个GLView绘制一个形状,但是在其他NSWindow中播放其他音频时,该形状与它的音频不匹配。
在 NSOpenGLViews 中,只要 CADisplayLink 需要显示,它就会调用 redraw 方法。
这是与OpenGLContext相关的部分。
self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:self.pixelFormat
shareContext:nil];
这是redraw
方法
[self.openGLContext makeCurrentContext];
[self.openGLContext lock];
[self redrawWithPoints:self.info->points
pointCount:self.info->pointCount
baseEffect:self.baseEffect
vertexBufferObject:self.info->vbo
vertexArrayBuffer:self.info->vab
interpolated:self.info->interpolated
mirrored:self.shouldMirror
gain:self.gain];
[self.openGLContext flushBuffer];
[self.openGLContext unlock];
[NSOpenGLContext clearCurrentContext];
这里是 redrawWithPoints 方法
glClear(GL_COLOR_BUFFER_BIT);
GLenum mode = interpolated ? GL_TRIANGLE_STRIP : GL_LINE_STRIP;
float interpolatedFactor = interpolated ? 2.0f : 1.0f;
float xscale = 2.0f / ((float)pointCount / interpolatedFactor);
float yscale = 1.0f * gain;
GLKMatrix4 transform = GLKMatrix4MakeTranslation(-1.0f, 0.0f, 0.0f);
transform = GLKMatrix4Scale(transform, xscale, yscale, 1.0f);
baseEffect.transform.modelviewMatrix = transform;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
[baseEffect prepareToDraw];
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition,
2,
GL_FLOAT,
GL_FALSE,
sizeof(GOAudioPlotGLPoint),
NULL);
glDrawArrays(mode, 0, pointCount);
if (mirrored)
{
baseEffect.transform.modelviewMatrix = GLKMatrix4Rotate(transform, M_PI, 1.0f, 0.0f, 0.0f);
[baseEffect prepareToDraw];
glDrawArrays(mode, 0, pointCount);
}
glFlush();
我想同时在不同的 NSOpenGLViews 中显示不同的音频可视化器。
有可能与OpenGL有关吗?