ml_scene_renderer.cpp
Go to the documentation of this file.
00001 #include "ml_scene_renderer.h"
00002 #include "ml_thread_safe_memory_info.h"
00003 #include "glarea.h"
00004 
00005 #include <vector>
00006 
00007 MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles)
00008         :GLMeshAttributesFeeder<CMeshO>(mesh,gpumeminfo,perbatchtriangles),_lock(QReadWriteLock::Recursive)
00009 {
00010 }
00011 
00012 void MLThreadSafeGLMeshAttributesFeeder::setPerBatchTriangles( size_t perbatchtriangles )
00013 {
00014         QWriteLocker locker(&_lock);
00015         GLMeshAttributesFeeder<CMeshO>::setPerBatchPrimitives(perbatchtriangles);
00016 }
00017 
00018 size_t MLThreadSafeGLMeshAttributesFeeder::perBatchTriangles() const
00019 {
00020         QReadLocker locker(&_lock);
00021         return GLMeshAttributesFeeder<CMeshO>::perBatchPrimitives();
00022 
00023 }
00024 
00025 bool MLThreadSafeGLMeshAttributesFeeder::renderedWithBO() const
00026 {
00027         QReadLocker locker(&_lock);
00028         return GLMeshAttributesFeeder<CMeshO>::isPossibleToUseBORendering();
00029 }
00030 
00031 void MLThreadSafeGLMeshAttributesFeeder::meshAttributesUpdated( int mask )
00032 {
00033         QWriteLocker locker(&_lock);
00034         GLMeshAttributesFeeder<CMeshO>::meshAttributesUpdated(mask);
00035 }
00036 
00037 vcg::GLFeederInfo::ReqAtts MLThreadSafeGLMeshAttributesFeeder::setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated )
00038 {
00039         QWriteLocker locker(&_lock);
00040         return GLMeshAttributesFeeder<CMeshO>::setupRequestedAttributes(rq,allocated);
00041 }
00042 
00043 
00044 void MLThreadSafeGLMeshAttributesFeeder::drawWire(vcg::GLFeederInfo::ReqAtts& rq)
00045 {
00046         glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT );
00047         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00048         drawTriangles(rq);
00049         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00050         glPopAttrib();
00051 }
00052 
00053 void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq)
00054 {
00055         glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT );
00056         glEnable(GL_POLYGON_OFFSET_FILL);
00057         glPolygonOffset(1.0, 1);
00058         drawTriangles(rq);
00059         glDisable(GL_POLYGON_OFFSET_FILL);
00060 
00061         glEnable(GL_COLOR_MATERIAL);
00062         glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
00063 
00064         ReqAtts tmp = rq;
00065         tmp[ATT_VERTCOLOR] = false;
00066         tmp[ATT_FACECOLOR] = false;
00067         tmp[ATT_MESHCOLOR] = false;
00068 
00069         glColor3f(.3f,.3f,.3f);
00070         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00071         QReadLocker locker(&_lock);
00072         GLMeshAttributesFeeder<CMeshO>::drawTriangles(tmp,_textids.textId());
00073         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00074 
00075         glPopAttrib();
00076 }
00077 
00078 void MLThreadSafeGLMeshAttributesFeeder::drawPoints(vcg::GLFeederInfo::ReqAtts& rq)
00079 {
00080         QReadLocker locker(&_lock);
00081         GLMeshAttributesFeeder<CMeshO>::drawPoints(rq);
00082 }
00083 
00084 void MLThreadSafeGLMeshAttributesFeeder::drawTriangles(vcg::GLFeederInfo::ReqAtts& rq)
00085 {
00086         QReadLocker locker(&_lock);
00087     GLMeshAttributesFeeder<CMeshO>::drawTriangles(rq,_textids.textId());
00088 }
00089 
00090 void MLThreadSafeGLMeshAttributesFeeder::drawBBox(vcg::GLFeederInfo::ReqAtts& rq)
00091 {
00092         QReadLocker locker(&_lock);
00093         
00094         vcg::Box3f& b = _mesh.bbox;
00095         glPushAttrib(GL_ALL_ATTRIB_BITS);
00096         glDisable(GL_LIGHTING);
00097         GLuint bbhandle;
00098         glGenBuffers(1,&bbhandle);
00099         std::vector<vcg::Point3f> bbox(12 * 2);
00100 
00101         //0
00102         bbox[0] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00103         bbox[1] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00104 
00105         //1
00106         bbox[2] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00107         bbox[3] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00108 
00109         //2
00110         bbox[4] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00111         bbox[5] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00112 
00113         //3
00114         bbox[6] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00115         bbox[7] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00116 
00117         //4
00118         bbox[8] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00119         bbox[9] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00120 
00121         //5
00122         bbox[10] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00123         bbox[11] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00124 
00125         //6
00126         bbox[12] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00127         bbox[13] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00128 
00129         //7
00130         bbox[14] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00131         bbox[15] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00132 
00133         //8
00134         bbox[16] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00135         bbox[17] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00136         
00137         //9
00138         bbox[18] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00139         bbox[19] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00140 
00141         //10
00142         bbox[20] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00143         bbox[21] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00144 
00145         //11
00146         bbox[22] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00147         bbox[23] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00148 
00149         glColor3f(1.0f,1.0f,1.0f);
00150         glBindBuffer(GL_ARRAY_BUFFER,bbhandle);
00151         glBufferData(GL_ARRAY_BUFFER, 12 * 2 * sizeof(vcg::Point3f), &(bbox[0]), GL_STATIC_DRAW);
00152         glVertexPointer(3,GL_FLOAT,0,0);
00153         glBindBuffer(GL_ARRAY_BUFFER,0);
00154         glEnableClientState(GL_VERTEX_ARRAY);
00155         glDrawArrays(GL_LINES,0,24);
00156         glDisableClientState(GL_VERTEX_ARRAY);
00157         glDeleteBuffers(1,&bbhandle);
00158         glPopAttrib();
00159 }
00160 
00161 
00162 void MLThreadSafeGLMeshAttributesFeeder::deAllocateBO()
00163 {
00164         QWriteLocker locker(&_lock);
00165         GLMeshAttributesFeeder<CMeshO>::buffersDeAllocationRequested();
00166 }
00167 
00168 MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::MLThreadSafeTextureNamesContainer()
00169         :_tmid(),_lock(QReadWriteLock::Recursive)
00170 {
00171 
00172 }
00173 
00174 MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::~MLThreadSafeTextureNamesContainer()
00175 {
00176         clear();
00177 }
00178 
00179 void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::push_back( GLuint textid )
00180 {
00181         QWriteLocker locker(&_lock);
00182         _tmid.push_back(textid);
00183 }
00184 
00185 size_t MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::size() const
00186 {
00187         QReadLocker locker(&_lock);
00188         return _tmid.size(); 
00189 }
00190 
00191 bool MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::empty() const
00192 {
00193         QReadLocker locker(&_lock);
00194         return _tmid.empty(); 
00195 }
00196 
00197 void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::clear()
00198 {
00199         QWriteLocker locker(&_lock);
00200         _tmid.clear();
00201 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:33:22