00001 /**************************************************************************** 00002 * MeshLab o o * 00003 * A versatile mesh processing toolbox o o * 00004 * _ O _ * 00005 * Copyright(C) 2005 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 00024 #ifndef __ML_SCENE_RENDERER_H 00025 #define __ML_SCENE_RENDERER_H 00026 00027 #include <GL/glew.h> 00028 #include "mesh.h" 00029 #include <wrap/gl/gl_mesh_attributes_feeder.h> 00030 00031 #include <QObject> 00032 #include <QMap> 00033 #include <QReadWriteLock> 00034 00035 00036 00037 class MLThreadSafeMemoryInfo; 00038 00039 00040 class MLThreadSafeGLMeshAttributesFeeder : public vcg::GLMeshAttributesFeeder<CMeshO> 00041 { 00042 public: 00043 struct MLThreadSafeTextureNamesContainer 00044 { 00045 MLThreadSafeTextureNamesContainer(); 00046 ~MLThreadSafeTextureNamesContainer(); 00047 00048 void push_back(GLuint textid); 00049 size_t size() const; 00050 bool empty() const; 00051 void clear(); 00052 GLuint& operator[](size_t ii) {return _tmid[ii];}; 00053 inline std::vector<GLuint>& textId() {return _tmid;}; 00054 private: 00055 std::vector<GLuint> _tmid; 00056 mutable QReadWriteLock _lock; 00057 }; 00058 00059 00060 MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles); 00061 ~MLThreadSafeGLMeshAttributesFeeder() {}; 00062 00063 void setPerBatchTriangles(size_t perbatchtriangles); 00064 00065 size_t perBatchTriangles() const; 00066 00067 bool renderedWithBO() const; 00068 00069 GLuint bufferObjectHandle() const; 00070 00071 void meshAttributesUpdated(int mask); 00072 00073 vcg::GLFeederInfo::ReqAtts setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated); 00074 00075 void deAllocateBO(); 00076 00077 void drawWire(vcg::GLFeederInfo::ReqAtts& rq); 00078 00079 void drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq); 00080 00081 void drawPoints(vcg::GLFeederInfo::ReqAtts& rq); 00082 00083 void drawTriangles(vcg::GLFeederInfo::ReqAtts& rq); 00084 00085 void drawBBox(vcg::GLFeederInfo::ReqAtts& rq); 00086 00087 inline CMeshO& mesh() {return _mesh;} 00088 00089 inline MLThreadSafeTextureNamesContainer& textureIDContainer() {return _textids;} 00090 00091 void buffersDeAllocationRequested(); 00092 private: 00093 mutable QReadWriteLock _lock; 00094 MLThreadSafeTextureNamesContainer _textids; 00095 }; 00096 00097 #endif