그래서 특정 색상의 화면에있는 모든 픽셀의 위치를 찾으려고합니다.CCRenderTexture에서 픽셀의 색상을 가져옵니다.
다음 코드는 작동하지만 매우 느립니다. 왜냐하면 모든 픽셀 좌표를 반복해야하기 때문입니다.
다음 코드를 개선하여 더욱 효율적으로 만들 수있는 방법이 있습니까?
// Detect the position of all red points in the sprite
UInt8 data[4];
CCRenderTexture* renderTexture = [[CCRenderTexture alloc] initWithWidth: mySprite.boundingBox.size.width * CC_CONTENT_SCALE_FACTOR()
height: mySprite.boundingBox.size.height * CC_CONTENT_SCALE_FACTOR()
pixelFormat:kCCTexture2DPixelFormat_RGBA8888];
[renderTexture begin];
[mySprite draw];
for (int x = 0; x < 960; x++)
{
for (int y = 0; y < 640; y++)
{
ccColor4B *buffer = malloc(sizeof(ccColor4B));
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
ccColor4B color = buffer[0];
if (color.r == 133 && color.g == 215 && color.b == 44)
{
NSLog(@"Found the red point at x: %d y: %d", x, y);
}
}
}
[renderTexture end];
[renderTexture release];
프레임 버퍼에서 픽셀을 읽는 속도가 느립니다. 특히 픽셀 단위로 수행하는 경우 속도가 느립니다. 렌더링 텍스쳐의 텍스쳐 메모리를 가져 와서 glReadPixel을 사용하지 않고 반복합니다. 그 속도는 훨씬 빨라야합니다! – LearnCocos2D
@ LearnCocos2D 안녕 친구! 나는 어떻게 그것에 대해 갈 것인가? 공유 할 수있는 예가 있습니까? 그럼 당신의 응답을 올바르게 표시 할 수 있습니다 :) – Sneaksta
실수로, CCTexture2D 메모리 버퍼를 유지하지 않습니다, 그것은 모두 GL 메모리 어쨌든. – LearnCocos2D