1 // This file belongs to the "MiniCore" game engine. 2 // Copyright (C) 2015 Jussi Lind <jussi.lind@iki.fi> 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 2 7 // of the License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 // MA 02110-1301, USA. 18 // 19 20 #ifndef MCOBJECTRENDERERBASE_HH 21 #define MCOBJECTRENDERERBASE_HH 22 23 #include "mcglcolor.hh" 24 #include "mcglobjectbase.hh" 25 #include "mcgltexcoord.hh" 26 #include "mcglvertex.hh" 27 #include "mcobject.hh" 28 #include "mcrenderlayer.hh" 29 30 #include <memory> 31 32 class MCObjectRendererBase : public MCGLObjectBase 33 { 34 public: 35 explicit MCObjectRendererBase(size_t maxBatchSize = 1024); 36 37 virtual ~MCObjectRendererBase(); 38 39 typedef std::vector<MCObject *> ObjectVector; 40 virtual void setBatch(MCRenderLayer::ObjectBatch & batch, MCCamera * camera = nullptr, bool isShadow = false) = 0; 41 42 //! Render the current object batch. 43 virtual void render() = 0; 44 45 //! Render the current object batch as shadows. 46 virtual void renderShadows() = 0; 47 48 //! Enable/disable blending. 49 void setAlphaBlend(bool useAlphaBlend, GLenum src = GL_SRC_ALPHA, GLenum dst = GL_ONE_MINUS_SRC_ALPHA); 50 51 //! \return Set if shadow needs to be rendered 52 void setHasShadow(bool hasShadow); 53 54 //! \return True if shadow needs to be rendered 55 bool hasShadow() const; 56 57 protected: 58 //! Set current batch size 59 void setBatchSize(size_t batchSize); 60 61 //! Get current batch size 62 size_t batchSize() const; 63 64 //! Set max batch size 65 size_t maxBatchSize() const; 66 67 bool useAlphaBlend() const; 68 69 GLenum alphaSrc() const; 70 71 GLenum alphaDst() const; 72 73 private: 74 DISABLE_COPY(MCObjectRendererBase); 75 DISABLE_ASSI(MCObjectRendererBase); 76 DISABLE_MOVE(MCObjectRendererBase); 77 78 size_t m_batchSize; 79 80 size_t m_maxBatchSize; 81 82 bool m_hasShadow; 83 84 bool m_useAlphaBlend; 85 86 GLenum m_src; 87 88 GLenum m_dst; 89 }; 90 91 typedef std::shared_ptr<MCObjectRendererBase> MCObjectRendererPtr; 92 93 #endif // MCOBJECTRENDERERBASE_HH 94