00001 /***************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #ifndef GLUONGRAPHICS_MATERIALINSTANCE_H 00021 #define GLUONGRAPHICS_MATERIALINSTANCE_H 00022 00023 #include <core/gluonobject.h> 00024 #include "gluon_graphics_export.h" 00025 00026 namespace GluonGraphics 00027 { 00028 00029 class Texture; 00030 class Material; 00031 00041 class GLUON_GRAPHICS_EXPORT MaterialInstance : public GluonCore::GluonObject 00042 { 00043 Q_OBJECT 00044 GLUON_OBJECT( MaterialInstance ) 00045 00046 public: 00055 Q_INVOKABLE explicit MaterialInstance( QObject* parent = 0 ); 00056 00060 virtual ~MaterialInstance(); 00061 00069 virtual void bind(); 00070 00074 virtual void release(); 00075 00081 Material* material(); 00082 00088 void setMaterial( Material* material ); 00089 00098 int uniformLocation( const QString& name ); 00099 00108 int attributeLocation( const QString& attrib ); 00109 00121 void setModelViewProjectionMatrix( QMatrix4x4 mvp ); 00122 00127 void setPropertiesFromMaterial(); 00128 00129 protected: 00142 void setGLUniform( const QString& name, const QVariant& value ); 00143 00151 void bindTexture( const QString& name, GluonGraphics::Texture* tex ); 00152 00153 private: 00154 class MaterialInstancePrivate; 00155 MaterialInstancePrivate* const d; 00156 }; 00157 00158 } 00159 00160 Q_DECLARE_METATYPE( GluonGraphics::MaterialInstance ); 00161 Q_DECLARE_METATYPE( GluonGraphics::MaterialInstance* ); 00162 00163 #endif // GLUONGRAPHICS_MATERIALINSTANCE_H