diff --git a/examples/CommonInterfaces/CommonGUIHelperInterface.h b/examples/CommonInterfaces/CommonGUIHelperInterface.h index f871a7e0e..baea8daf4 100644 --- a/examples/CommonInterfaces/CommonGUIHelperInterface.h +++ b/examples/CommonInterfaces/CommonGUIHelperInterface.h @@ -47,6 +47,18 @@ struct GUIHelperInterface virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ)=0; virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], + unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, + float* depthBuffer, int depthBufferSizeInPixels, + int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied) + { + copyCameraImageData(viewMatrix,projectionMatrix,pixelsRGBA,rgbaBufferSizeInPixels, + depthBuffer,depthBufferSizeInPixels, + 0,0, + startPixelIndex,destinationWidth, + destinationHeight,numPixelsCopied); + } + + virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels, diff --git a/examples/RenderingExamples/TinyRendererSetup.cpp b/examples/RenderingExamples/TinyRendererSetup.cpp index 89fd1437d..9114d0889 100644 --- a/examples/RenderingExamples/TinyRendererSetup.cpp +++ b/examples/RenderingExamples/TinyRendererSetup.cpp @@ -187,9 +187,9 @@ TinyRendererSetup::TinyRendererSetup(struct GUIHelperInterface* gui) TinyRenderObjectData* ob = new TinyRenderObjectData( m_internalData->m_rgbColorBuffer, m_internalData->m_depthBuffer, - m_internalData->m_segmentationMaskBuffer, - m_internalData->m_renderObjects.size(),0); - //ob->loadModel("cube.obj"); + &m_internalData->m_segmentationMaskBuffer, + m_internalData->m_renderObjects.size()); + const int* indices = &meshData.m_gfxShape->m_indices->at(0); ob->registerMeshShape(&meshData.m_gfxShape->m_vertices->at(0).xyzw[0], meshData.m_gfxShape->m_numvertices, diff --git a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp index 1cce9ef57..be35c9626 100644 --- a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp @@ -490,7 +490,7 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(int linkIndex, const if (vertices.size() && indices.size()) { - TinyRenderObjectData* tinyObj = new TinyRenderObjectData(m_data->m_rgbColorBuffer,m_data->m_depthBuffer, m_data->m_segmentationMaskBuffer, objectIndex,0); + TinyRenderObjectData* tinyObj = new TinyRenderObjectData(m_data->m_rgbColorBuffer,m_data->m_depthBuffer, &m_data->m_segmentationMaskBuffer, objectIndex); unsigned char* textureImage=0; int textureWidth=0; int textureHeight=0; diff --git a/examples/TinyRenderer/TinyRenderer.cpp b/examples/TinyRenderer/TinyRenderer.cpp index 75518abd5..a382c1564 100644 --- a/examples/TinyRenderer/TinyRenderer.cpp +++ b/examples/TinyRenderer/TinyRenderer.cpp @@ -87,11 +87,17 @@ struct Shader : public IShader { } }; +TinyRenderObjectData::TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray&depthBuffer) +:TinyRenderObjectData(rgbColorBuffer,depthBuffer,0,0) +{ + +} -TinyRenderObjectData::TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray&depthBuffer, b3AlignedObjectArray& segmentationMaskBuffer, int objectIndex,int objectIndex2) + +TinyRenderObjectData::TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray&depthBuffer, b3AlignedObjectArray* segmentationMaskBuffer, int objectIndex) :m_rgbColorBuffer(rgbColorBuffer), m_depthBuffer(depthBuffer), -m_segmentationMaskBuffer(segmentationMaskBuffer), +m_segmentationMaskBufferPtr(segmentationMaskBuffer), m_model(0), m_userData(0), m_userIndex(-1), @@ -249,7 +255,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData) renderData.m_viewportMatrix = viewport(0,0,width, height); b3AlignedObjectArray& zbuffer = renderData.m_depthBuffer; - b3AlignedObjectArray& segmentationMaskBuffer = renderData.m_segmentationMaskBuffer; + int* segmentationMaskBufferPtr = &renderData.m_segmentationMaskBufferPtr->at(0); TGAImage& frame = renderData.m_rgbColorBuffer; @@ -267,7 +273,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData) for (int j=0; j<3; j++) { shader.vertex(i, j); } - triangle(shader.varying_tri, shader, frame, &zbuffer[0], &segmentationMaskBuffer[0], renderData.m_viewportMatrix, renderData.m_objectIndex); + triangle(shader.varying_tri, shader, frame, &zbuffer[0], segmentationMaskBufferPtr, renderData.m_viewportMatrix, renderData.m_objectIndex); } } diff --git a/examples/TinyRenderer/TinyRenderer.h b/examples/TinyRenderer/TinyRenderer.h index 550134be7..1819790a6 100644 --- a/examples/TinyRenderer/TinyRenderer.h +++ b/examples/TinyRenderer/TinyRenderer.h @@ -27,10 +27,11 @@ struct TinyRenderObjectData //Output TGAImage& m_rgbColorBuffer; - b3AlignedObjectArray& m_depthBuffer; - b3AlignedObjectArray& m_segmentationMaskBuffer; + b3AlignedObjectArray& m_depthBuffer;//required, hence a reference + b3AlignedObjectArray* m_segmentationMaskBufferPtr;//optional, hence a pointer - TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray&depthBuffer, b3AlignedObjectArray& segmentationMaskBuffer,int objectIndex,int objectIndex2); + TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray&depthBuffer); + TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray&depthBuffer, b3AlignedObjectArray* segmentationMaskBuffer,int objectIndex); virtual ~TinyRenderObjectData(); void loadModel(const char* fileName); diff --git a/examples/TinyRenderer/our_gl.cpp b/examples/TinyRenderer/our_gl.cpp index 53e8cd021..639db9b0b 100644 --- a/examples/TinyRenderer/our_gl.cpp +++ b/examples/TinyRenderer/our_gl.cpp @@ -59,6 +59,11 @@ Vec3f barycentric(Vec2f A, Vec2f B, Vec2f C, Vec2f P) { return Vec3f(-1,1,1); // in this case generate negative coordinates, it will be thrown away by the rasterizator } +void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zbuffer, const Matrix& viewPortMatrix, int objectIndex) +{ + triangle(clipc,shader,image,zbuffer,0,viewPortMatrix,0); +} + void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zbuffer, int* segmentationMaskBuffer, const Matrix& viewPortMatrix, int objectIndex) { mat<3,4,float> pts = (viewPortMatrix*clipc).transpose(); // transposed to ease access to each of the points @@ -100,7 +105,10 @@ void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zb bool discard = shader.fragment(bc_clip, color); if (!discard) { zbuffer[P.x+P.y*image.get_width()] = frag_depth; - segmentationMaskBuffer[P.x+P.y*image.get_width()] = objectIndex; + if (segmentationMaskBuffer) + { + segmentationMaskBuffer[P.x+P.y*image.get_width()] = objectIndex; + } image.set(P.x, P.y, color); } } diff --git a/examples/TinyRenderer/our_gl.h b/examples/TinyRenderer/our_gl.h index 60d5c400f..378324cbd 100644 --- a/examples/TinyRenderer/our_gl.h +++ b/examples/TinyRenderer/our_gl.h @@ -16,7 +16,7 @@ struct IShader { virtual bool fragment(Vec3f bar, TGAColor &color) = 0; }; -//void triangle(Vec4f *pts, IShader &shader, TGAImage &image, float *zbuffer); +void triangle(mat<4,3,float> &pts, IShader &shader, TGAImage &image, float *zbuffer, const Matrix& viewPortMatrix); void triangle(mat<4,3,float> &pts, IShader &shader, TGAImage &image, float *zbuffer, int* segmentationMaskBuffer, const Matrix& viewPortMatrix, int objectIndex); #endif //__OUR_GL_H__