source: OGRE/trunk/ogrenew/RenderSystems/GL/src/GLX/OgreGLXRenderTexture.cpp @ 657

Revision 657, 6.7 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreException.h"
28#include "OgreLogManager.h"
29#include "OgreRoot.h"
30#include "OgreStringConverter.h"
31
32#include "OgreGLRenderSystem.h"
33
34#include "OgreGLXRenderTexture.h"
35#include "OgreGLXContext.h"
36#include "OgreGLXUtils.h"
37
38#include <iostream>
39
40// Replace by arb ASAP
41#ifndef GLX_ATI_pixel_format_float
42#define GLX_ATI_pixel_format_float  1
43#define GLX_RGBA_FLOAT_ATI_BIT                          0x00000100
44#endif
45
46
47namespace Ogre
48{
49 
50    GLXRenderTexture::GLXRenderTexture( const String & name, unsigned int width, unsigned int height,
51                        TextureType texType, PixelFormat internalFormat,
52                        const NameValuePairList *miscParams):
53        GLRenderTexture(name, width, height, texType, internalFormat, miscParams),
54        _hPBuffer(0),
55        mContext(0)
56    {
57        createPBuffer();
58        // Create context
59        mContext = new GLXContext(_pDpy, _hPBuffer, _hGLContext);
60        // Register the context with the rendersystem
61        GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());
62        rs->_registerContext(this, mContext);
63    }
64
65    void GLXRenderTexture::createPBuffer() {       
66        LogManager::getSingleton().logMessage(
67        "GLXRenderTexture::Creating PBuffer"
68        );
69           
70        _pDpy = glXGetCurrentDisplay();
71        ::GLXContext context = glXGetCurrentContext();
72        int screen = DefaultScreen(_pDpy);
73        int iFormat = 0;
74        int iNumFormats;
75        int attribs[50], ideal[50];
76        int attrib;
77        // Attribs for glXChooseFBConfig
78        // Get R,G,B,A depths
79        int depths[4];
80        PixelUtil::getBitDepths(mInternalFormat, depths);
81        int renderType;
82        if(PixelUtil::getFlags(mInternalFormat) & PFF_FLOAT)
83            renderType = GLX_RGBA_FLOAT_ATI_BIT; // GLX_RGBA_FLOAT_BIT
84        else
85            renderType = GLX_RGBA_BIT;
86
87        // Create base required format description
88        attrib = 0;
89        attribs[attrib++] = GLX_RENDER_TYPE;
90        attribs[attrib++] = renderType;       
91        attribs[attrib++] = GLX_DRAWABLE_TYPE;
92        attribs[attrib++] = GLX_PBUFFER_BIT;
93        attribs[attrib++] = GLX_DOUBLEBUFFER;
94        attribs[attrib++] = 0;
95        attribs[attrib++] = None;
96       
97        // Create "ideal" format description
98        attrib = 0;
99        ideal[attrib++] = GLX_RED_SIZE;
100        ideal[attrib++] = depths[0];       
101        ideal[attrib++] = GLX_GREEN_SIZE;
102        ideal[attrib++] = depths[1];
103        ideal[attrib++] = GLX_BLUE_SIZE;
104        ideal[attrib++] = depths[2];       
105        ideal[attrib++] = GLX_ALPHA_SIZE;
106        ideal[attrib++] = depths[3];
107        ideal[attrib++] = GLX_DEPTH_SIZE;
108        ideal[attrib++] = 24;
109        ideal[attrib++] = GLX_STENCIL_SIZE;
110        ideal[attrib++] = 8;
111        ideal[attrib++] = GLX_ACCUM_RED_SIZE;
112        ideal[attrib++] = 0;    // Accumulation buffer not used
113        ideal[attrib++] = GLX_ACCUM_GREEN_SIZE;
114        ideal[attrib++] = 0;    // Accumulation buffer not used
115        ideal[attrib++] = GLX_ACCUM_BLUE_SIZE;
116        ideal[attrib++] = 0;    // Accumulation buffer not used
117        ideal[attrib++] = GLX_ACCUM_ALPHA_SIZE;
118        ideal[attrib++] = 0;    // Accumulation buffer not used
119        ideal[attrib++] = None;
120
121        // Create vector of existing config data formats       
122        GLXFBConfig config = GLXUtils::findBestMatch(_pDpy, screen, attribs, ideal);
123
124        // Create the pbuffer in the best matching format
125        attrib = 0;
126        attribs[attrib++] = GLX_PBUFFER_WIDTH;
127        attribs[attrib++] = mWidth; // Get from texture?
128        attribs[attrib++] = GLX_PBUFFER_HEIGHT;
129        attribs[attrib++] = mHeight; // Get from texture?
130        attribs[attrib++] = GLX_PRESERVED_CONTENTS;
131        attribs[attrib++] = 1;
132        attribs[attrib++] = None;
133
134        FBConfigData configData(_pDpy, config);
135        LogManager::getSingleton().logMessage(
136                LML_NORMAL,
137                "GLXRenderTexture::PBuffer chose format "+configData.toString());                   
138
139        _hPBuffer = glXCreatePbuffer(_pDpy, config, attribs);
140        if (!_hPBuffer)
141            OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE, "glXCreatePbuffer() failed", "GLRenderTexture::createPBuffer");
142
143        _hGLContext = glXCreateNewContext(_pDpy, config, GLX_RGBA_TYPE, context, True);
144        if (!_hGLContext)
145            OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE, "glXCreateContext() failed", "GLRenderTexture::createPBuffer");       
146
147        // Query real width and height
148        GLuint iWidth, iHeight;
149        glXQueryDrawable(_pDpy, _hPBuffer, GLX_WIDTH, &iWidth);
150        glXQueryDrawable(_pDpy, _hPBuffer, GLX_HEIGHT, &iHeight);
151
152        LogManager::getSingleton().logMessage(
153             LML_NORMAL,
154                "GLXRenderTexture::PBuffer created -- Real dimensions "+
155                StringConverter::toString(iWidth)+"x"+StringConverter::toString(iHeight)
156        );
157        mWidth = iWidth; 
158        mHeight = iHeight;
159    }
160
161    GLXRenderTexture::~GLXRenderTexture()
162    {
163        // Unregister and destroy mContext
164        GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());
165        rs->_unregisterContext(this);
166        delete mContext;
167        // Destroy GL context
168        glXDestroyContext(_pDpy, _hGLContext);
169        _hGLContext = 0;
170        glXDestroyPbuffer(_pDpy, _hPBuffer);
171        _hPBuffer = 0;
172    }
173
174/*
175    void GLXRenderTexture::_copyToTexture()
176    {
177        // Should do nothing
178    }
179 */ 
180   
181 
182}
Note: See TracBrowser for help on using the repository browser.