1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "OgreGLRenderTexture.h"
|
---|
26 | #include "OgreGLPixelFormat.h"
|
---|
27 | #include "OgreLogManager.h"
|
---|
28 | #include "OgreStringConverter.h"
|
---|
29 | #include "OgreRoot.h"
|
---|
30 | #include "OgreGLHardwarePixelBuffer.h"
|
---|
31 |
|
---|
32 | namespace Ogre {
|
---|
33 |
|
---|
34 |
|
---|
35 | //-----------------------------------------------------------------------------
|
---|
36 |
|
---|
37 | template<> GLRTTManager* Singleton<GLRTTManager>::ms_Singleton = 0;
|
---|
38 | GLRTTManager::~GLRTTManager()
|
---|
39 | {
|
---|
40 | }
|
---|
41 | MultiRenderTarget* GLRTTManager::createMultiRenderTarget(const String & name)
|
---|
42 | {
|
---|
43 | OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE, "MultiRenderTarget can only be used with GL_EXT_framebuffer_object extension", "GLRTTManager::createMultiRenderTarget");
|
---|
44 | }
|
---|
45 | PixelFormat GLRTTManager::getSupportedAlternative(PixelFormat format)
|
---|
46 | {
|
---|
47 | if(checkFormat(format))
|
---|
48 | return format;
|
---|
49 | /// Find first alternative
|
---|
50 | PixelComponentType pct = PixelUtil::getComponentType(format);
|
---|
51 | switch(pct)
|
---|
52 | {
|
---|
53 | case PCT_BYTE: format = PF_A8R8G8B8; break;
|
---|
54 | case PCT_SHORT: format = PF_SHORT_RGBA; break;
|
---|
55 | case PCT_FLOAT16: format = PF_FLOAT16_RGBA; break;
|
---|
56 | case PCT_FLOAT32: format = PF_FLOAT32_RGBA; break;
|
---|
57 | }
|
---|
58 | if(checkFormat(format))
|
---|
59 | return format;
|
---|
60 | /// If none at all, return to default
|
---|
61 | return PF_A8R8G8B8;
|
---|
62 | }
|
---|
63 | //-----------------------------------------------------------------------------
|
---|
64 | GLRenderTexture::GLRenderTexture(const String &name, const GLSurfaceDesc &target):
|
---|
65 | RenderTexture(target.buffer, target.zoffset)
|
---|
66 | {
|
---|
67 | mName = name;
|
---|
68 | }
|
---|
69 | GLRenderTexture::~GLRenderTexture()
|
---|
70 | {
|
---|
71 | }
|
---|
72 | //-----------------------------------------------------------------------------
|
---|
73 | GLCopyingRenderTexture::GLCopyingRenderTexture(GLCopyingRTTManager *manager, const String &name, const GLSurfaceDesc &target):
|
---|
74 | GLRenderTexture(name, target)
|
---|
75 | {
|
---|
76 | }
|
---|
77 | void GLCopyingRenderTexture::getCustomAttribute(const String& name, void* pData)
|
---|
78 | {
|
---|
79 | if(name=="TARGET")
|
---|
80 | {
|
---|
81 | GLSurfaceDesc &target = *static_cast<GLSurfaceDesc*>(pData);
|
---|
82 | target.buffer = static_cast<GLHardwarePixelBuffer*>(mBuffer);
|
---|
83 | target.zoffset = mZOffset;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | //-----------------------------------------------------------------------------
|
---|
87 | GLCopyingRTTManager::GLCopyingRTTManager()
|
---|
88 | {
|
---|
89 | }
|
---|
90 | GLCopyingRTTManager::~GLCopyingRTTManager()
|
---|
91 | {
|
---|
92 | }
|
---|
93 |
|
---|
94 | RenderTexture *GLCopyingRTTManager::createRenderTexture(const String &name, const GLSurfaceDesc &target)
|
---|
95 | {
|
---|
96 | return new GLCopyingRenderTexture(this, name, target);
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool GLCopyingRTTManager::checkFormat(PixelFormat format)
|
---|
100 | {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void GLCopyingRTTManager::bind(RenderTarget *target)
|
---|
105 | {
|
---|
106 | // Nothing to do here
|
---|
107 | }
|
---|
108 |
|
---|
109 | void GLCopyingRTTManager::unbind(RenderTarget *target)
|
---|
110 | {
|
---|
111 | // Copy on unbind
|
---|
112 | GLSurfaceDesc surface;
|
---|
113 | surface.buffer = 0;
|
---|
114 | target->getCustomAttribute("TARGET", &surface);
|
---|
115 | if(surface.buffer)
|
---|
116 | static_cast<GLTextureBuffer*>(surface.buffer)->copyFromFramebuffer(surface.zoffset);
|
---|
117 | }
|
---|
118 | //---------------------------------------------------------------------------------------------
|
---|
119 |
|
---|
120 | }
|
---|
121 |
|
---|