| 1255 | } |
| 1256 | |
| 1257 | void OpenGLGuiHelper::copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], |
| 1258 | unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, |
| 1259 | float* depthBuffer, int depthBufferSizeInPixels, |
| 1260 | int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels, |
| 1261 | int startPixelIndex, int destinationWidth, |
| 1262 | int destinationHeight, int* numPixelsCopied) |
| 1263 | { |
| 1264 | int sourceWidth = btMin(destinationWidth, (int)(m_data->m_glApp->m_window->getWidth() * m_data->m_glApp->m_window->getRetinaScale())); |
| 1265 | int sourceHeight = btMin(destinationHeight, (int)(m_data->m_glApp->m_window->getHeight() * m_data->m_glApp->m_window->getRetinaScale())); |
| 1266 | m_data->m_glApp->setViewport(sourceWidth, sourceHeight); |
| 1267 | |
| 1268 | if (numPixelsCopied) |
| 1269 | *numPixelsCopied = 0; |
| 1270 | |
| 1271 | int numTotalPixels = destinationWidth * destinationHeight; |
| 1272 | int numRemainingPixels = numTotalPixels - startPixelIndex; |
| 1273 | int numBytesPerPixel = 4; //RGBA |
| 1274 | int numRequestedPixels = btMin(rgbaBufferSizeInPixels, numRemainingPixels); |
| 1275 | if (numRequestedPixels) |
| 1276 | { |
| 1277 | if (startPixelIndex == 0) |
| 1278 | { |
| 1279 | CommonCameraInterface* oldCam = getRenderInterface()->getActiveCamera(); |
| 1280 | SimpleCamera tempCam; |
| 1281 | getRenderInterface()->setActiveCamera(&tempCam); |
| 1282 | getRenderInterface()->getActiveCamera()->setVRCamera(viewMatrix, projectionMatrix); |
| 1283 | { |
| 1284 | BT_PROFILE("renderScene"); |
| 1285 | getRenderInterface()->renderScene(); |
| 1286 | } |
| 1287 | |
| 1288 | { |
| 1289 | BT_PROFILE("copy pixels"); |
| 1290 | btAlignedObjectArray<unsigned char> sourceRgbaPixelBuffer; |
| 1291 | btAlignedObjectArray<float> sourceDepthBuffer; |
| 1292 | //copy the image into our local cache |
| 1293 | sourceRgbaPixelBuffer.resize(sourceWidth * sourceHeight * numBytesPerPixel); |
| 1294 | sourceDepthBuffer.resize(sourceWidth * sourceHeight); |
| 1295 | { |
| 1296 | BT_PROFILE("getScreenPixels"); |
| 1297 | m_data->m_glApp->getScreenPixels(&(sourceRgbaPixelBuffer[0]), sourceRgbaPixelBuffer.size(), &sourceDepthBuffer[0], sizeof(float) * sourceDepthBuffer.size()); |
| 1298 | } |
| 1299 | |
| 1300 | m_data->m_rgbaPixelBuffer1.resize(destinationWidth * destinationHeight * numBytesPerPixel); |
| 1301 | m_data->m_depthBuffer1.resize(destinationWidth * destinationHeight); |
| 1302 | //rescale and flip |
| 1303 | { |
| 1304 | BT_PROFILE("resize and flip"); |
| 1305 | for (int j = 0; j < destinationHeight; j++) |
| 1306 | { |
| 1307 | for (int i = 0; i < destinationWidth; i++) |
| 1308 | { |
| 1309 | int xIndex = int(float(i) * (float(sourceWidth) / float(destinationWidth))); |
| 1310 | int yIndex = int(float(destinationHeight - 1 - j) * (float(sourceHeight) / float(destinationHeight))); |
| 1311 | btClamp(xIndex, 0, sourceWidth); |
| 1312 | btClamp(yIndex, 0, sourceHeight); |
| 1313 | int bytesPerPixel = 4; //RGBA |
| 1314 |
nothing calls this directly
no test coverage detected