| 1148 | } |
| 1149 | |
| 1150 | void |
| 1151 | TrackerNodeInteract::convertImageTosRGBOpenGLTexture(const ImagePtr& image, |
| 1152 | const TexturePtr& tex, |
| 1153 | const RectI& renderWindow) |
| 1154 | { |
| 1155 | RectI bounds; |
| 1156 | RectI roi; |
| 1157 | |
| 1158 | if (image) { |
| 1159 | bounds = image->getBounds(); |
| 1160 | renderWindow.intersect(bounds, &roi); |
| 1161 | } else { |
| 1162 | bounds = renderWindow; |
| 1163 | roi = bounds; |
| 1164 | } |
| 1165 | if ( roi.isNull() ) { |
| 1166 | return; |
| 1167 | } |
| 1168 | |
| 1169 | |
| 1170 | std::size_t bytesCount = 4 * sizeof(unsigned char) * roi.area(); |
| 1171 | TextureRect region; |
| 1172 | region.x1 = roi.x1; |
| 1173 | region.x2 = roi.x2; |
| 1174 | region.y1 = roi.y1; |
| 1175 | region.y2 = roi.y2; |
| 1176 | |
| 1177 | GLint currentBoundPBO = 0; |
| 1178 | glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, ¤tBoundPBO); |
| 1179 | |
| 1180 | if (pboID == 0) { |
| 1181 | glGenBuffers(1, &pboID); |
| 1182 | } |
| 1183 | |
| 1184 | // bind PBO to update texture source |
| 1185 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, pboID ); |
| 1186 | |
| 1187 | // Note that glMapBufferARB() causes sync issue. |
| 1188 | // If GPU is working with this buffer, glMapBufferARB() will wait(stall) |
| 1189 | // until GPU to finish its job. To avoid waiting (idle), you can call |
| 1190 | // first glBufferDataARB() with NULL pointer before glMapBufferARB(). |
| 1191 | // If you do that, the previous data in PBO will be discarded and |
| 1192 | // glMapBufferARB() returns a new allocated pointer immediately |
| 1193 | // even if GPU is still working with the previous data. |
| 1194 | glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, bytesCount, NULL, GL_DYNAMIC_DRAW_ARB); |
| 1195 | |
| 1196 | // map the buffer object into client's memory |
| 1197 | GLvoid *buf = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB); |
| 1198 | glCheckError(); |
| 1199 | assert(buf); |
| 1200 | if (buf) { |
| 1201 | // update data directly on the mapped buffer |
| 1202 | if (!image) { |
| 1203 | int pixelsCount = roi.area(); |
| 1204 | unsigned int* dstPixels = (unsigned int*)buf; |
| 1205 | for (int i = 0; i < pixelsCount; ++i, ++dstPixels) { |
| 1206 | *dstPixels = toBGRA(0, 0, 0, 255); |
| 1207 | } |
nothing calls this directly
no test coverage detected