[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/kstars/kstars
From: Akarsh Simha <akarshsimha () gmail ! com>
Date: 2011-01-01 4:27:21
Message-ID: 20110101042721.00B1AAC8B6 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1210552 by asimha:
Allow runtime switching between OpenGL and QPainter backends. Still
buggy and ugly.
Note that as of this commit, HAVE_OPENGL is still not defined
anywhere. Must be manually defined if required.
M +7 -0 kstars.cpp
M +6 -0 kstars.kcfg
M +7 -0 kstarsinit.cpp
M +1 -0 kstarsui-indi.rc
M +1 -0 kstarsui-win.rc
M +1 -0 kstarsui.rc
M +62 -25 skymap.cpp
M +4 -0 skymap.h
M +13 -7 texture.cpp
M +12 -0 texture.h
M +2 -0 texturemanager.h
--- trunk/KDE/kdeedu/kstars/kstars/kstars.cpp #1210551:1210552
@@ -153,6 +153,13 @@
actionCollection()->action("coordsys")->setText(
Options::useAltAz() ? i18n("Switch to star globe view (Equatorial \
&Coordinates)"): i18n("Switch to horizonal view (Horizontal &Coordinates)") );
+ #ifdef HAVE_OPENGL
+ Q_ASSERT( SkyMap::Instance() ); // This assert should not fail, because SkyMap \
is already created by now. Just throwing it in anyway. + \
actionCollection()->action("opengl")->setText( (Options::useGL() ? i18n("Switch to \
QPainter backend"): i18n("Switch to OpenGL backend")) ); + kDebug() << "We have \
OpenGL! Do you?"; + #endif
+
+
actionCollection()->action("show_time_box" )->setChecked( \
Options::showTimeBox() );
actionCollection()->action("show_location_box")->setChecked( \
Options::showGeoBox() );
actionCollection()->action("show_focus_box" )->setChecked( \
Options::showFocusBox() );
--- trunk/KDE/kdeedu/kstars/kstars/kstars.kcfg #1210551:1210552
@@ -688,6 +688,12 @@
<whatsthis>The maximum solar distance for drawing comets.</whatsthis>
<default>3.0</default>
</entry>
+ <!-- TODO: Hilarious label and whatsthis strings used to preserve "translation \
invariance". Please fix in 4.7 --> + <entry name="UseGL" type="Bool">
+ <label>Switch to OpenGL backend</label>
+ <whatsthis>This version of KStars comes with new experimental OpenGL support. Our \
experience is that OpenGL works much faster on machines with hardware acceleration. \
Would you like to switch to OpenGL painting backends?</whatsthis> \
+ <default>false</default> + </entry>
</group>
<group name="Colors">
--- trunk/KDE/kdeedu/kstars/kstars/kstarsinit.cpp #1210551:1210552
@@ -219,6 +219,13 @@
<< (Options::useAltAz() ? i18n("Switch to star globe view (Equatorial \
&Coordinates)"): i18n("Switch to horizonal view (Horizontal &Coordinates)")) << \
KShortcut("Space" );
+ #ifdef HAVE_OPENGL
+ Q_ASSERT( SkyMap::Instance() ); // This assert should not fail, because SkyMap \
is already created by now. Just throwing it in anyway. + \
actionCollection()->addAction("opengl", SkyMap::Instance(), SLOT( slotToggleGL() ) ) \
+ << (Options::useGL() ? i18n("Switch to QPainter backend"): i18n("Switch to \
OpenGL backend")); + kDebug() << "We have OpenGL! Do you?";
+ #endif
+
actionCollection()->addAction("project_lambert", this, SLOT( slotMapProjection() \
) ) << i18n("&Lambert Azimuthal Equal-area" )
<< KShortcut("F5" )
--- trunk/KDE/kdeedu/kstars/kstars/kstarsui-indi.rc #1210551:1210552
@@ -95,6 +95,7 @@
</Menu>
<Action name="colorschemes" /> <!--This is a KMenuAction-->
<Action name="fovsymbols" /> <!-- This is a KMenuAction-->
+ <Action name="opengl" />
<Separator />
<Action name="ewriter"/>
<Action name="obsadd"/>
--- trunk/KDE/kdeedu/kstars/kstars/kstarsui-win.rc #1210551:1210552
@@ -91,6 +91,7 @@
</Menu>
<Action name="colorschemes" /> <!--This is a KMenuAction-->
<Action name="fovsymbols" /> <!-- This is a KMenuAction-->
+ <Action name="opengl" />
<Separator />
<Action name="ewriter"/>
<Action name="obsadd"/>
--- trunk/KDE/kdeedu/kstars/kstars/kstarsui.rc #1210551:1210552
@@ -87,6 +87,7 @@
</Menu>
<Action name="colorschemes" /> <!--This is a KMenuAction-->
<Action name="fovsymbols" /> <!-- This is a KMenuAction-->
+ <Action name="opengl" />
<Separator />
<Action name="ewriter"/>
<Action name="obsadd"/>
--- trunk/KDE/kdeedu/kstars/kstars/skymap.cpp #1210551:1210552
@@ -172,6 +172,9 @@
ClickedObject = NULL;
FocusObject = NULL;
+ m_SkyMapDraw = 0;
+ m_SkyMapDrawWidget = 0;
+
pmenu = new KSPopupMenu();
setupProjector();
@@ -223,39 +226,32 @@
m_iboxes->addInfoBox(m_objBox);
- // TODO: Pick the render enging from Options. For now, we will
- // hardcode it here, for testing purposes only!
- /*
- // HARDCODE NATIVE ENGINE
+ // TODO: Duplicated code. Please do something better
+
+ #ifdef HAVE_OPENGL
+ kDebug() << "We have OpenGL! Do you?";
+ // TODO: Can this code be written more elegantly? Or is it a bad idea to cast?
+ if( !Options::useGL() ) {
SkyMapQDraw *smqd = new SkyMapQDraw( this );
+ // NOTE: Two different kinds of casts here
+ m_SkyMapDrawWidget = smqd;
m_SkyMapDraw = smqd;
- m_SkyMapDrawWidget = smqd;
- */
- // HARDCODE GL ENGINE
- Q_ASSERT( TextureManager::getContext() );
+ smqd->setParent( this->viewport() );
+ smqd->show();
+ }
+ else
+ #endif
+ {
SkyMapGLDraw *smgld = new SkyMapGLDraw( this );
+ Q_ASSERT( TextureManager::getContext() ); // Should not fail, because \
TextureManager should be already created. + // NOTE: Two different kinds of \
casts here + m_SkyMapDrawWidget = smgld;
m_SkyMapDraw = smgld;
- m_SkyMapDrawWidget = smgld;
-
-
- // FIXME: Okay. None of this seems to work. So I'm going to do it
- // the stupid way -- where I just add the SkyMapQDraw (QWidget) as
- // a child of this QGV.
- /*
- m_SkyScene = new QGraphicsScene( this );
- m_SkyScene->addWidget( smqd );
- setCacheMode( QGraphicsView::CacheNone );
- smqd->show();
- setScene( m_SkyScene );
- */
- /*
- smqd->setParent( this->viewport() );
- smqd->show();
- */
smgld->setParent( this->viewport() );
smgld->show();
+ }
//The update timer will be destructed when SkyMap is..
QTimer *update = new QTimer(this);
@@ -310,6 +306,8 @@
Options::setFocusDec( focus()->dec().Degrees() );
}
+ delete m_SkyMapDrawWidget;
+
delete pmenu;
delete m_proj;
@@ -1079,6 +1077,45 @@
return (slewing || ( clockSlewing && data->clock()->isActive() ) );
}
+#ifdef HAVE_OPENGL
+void SkyMap::slotToggleGL() {
+ kDebug() << "We have OpenGL! Do you?";
+
+ delete m_SkyMapDrawWidget;
+
+ // TODO: Can this code be written more elegantly? Or is it a bad idea to cast?
+ if( Options::useGL() ) {
+ Options::setUseGL( false );
+
+ SkyMapQDraw *smqd = new SkyMapQDraw( this );
+ // NOTE: Two different kinds of casts here
+ m_SkyMapDrawWidget = smqd;
+ m_SkyMapDraw = smqd;
+
+ smqd->setParent( this->viewport() );
+ smqd->show();
+
+ KStars::Instance()->actionCollection()->action( "opengl" \
)->setText(i18n("Switch to OpenGL backend")); + }
+ else {
+ Options::setUseGL( true );
+
+ SkyMapGLDraw *smgld = new SkyMapGLDraw( this );
+ Q_ASSERT( TextureManager::getContext() ); // Should not fail, because \
TextureManager should be already created. + // NOTE: Two different kinds of \
casts here + m_SkyMapDrawWidget = smgld;
+ m_SkyMapDraw = smgld;
+
+ smgld->setParent( this->viewport() );
+ smgld->show();
+
+ KStars::Instance()->actionCollection()->action( "opengl" \
)->setText(i18n("Switch to QPainter backend")); + }
+}
+#endif
+
+
+
#ifdef HAVE_XPLANET
void SkyMap::startXplanet( const QString & outputFile ) {
QString year, month, day, hour, minute, seconde, fov;
--- trunk/KDE/kdeedu/kstars/kstars/skymap.h #1210551:1210552
@@ -437,6 +437,10 @@
* in the status bar */
void slotCancelAngularDistance();
+#ifdef HAVE_OPENGL
+ void slotToggleGL();
+#endif
+
#ifdef HAVE_XPLANET
/**Run Xplanet to print a view on the screen*/
void slotXplanetToScreen();
--- trunk/KDE/kdeedu/kstars/kstars/texture.cpp #1210551:1210552
@@ -20,8 +20,11 @@
#include "texture.h"
#include "texturemanager.h"
#include "skymap.h"
+#include "Options.h"
+#if HAVE_OPENGL
#include <QGLContext>
+#endif
Texture::Texture(QObject* parent): QObject(parent)
{
@@ -31,9 +34,8 @@
bool Texture::bind() const
{
-
- #ifdef USEGL
- if( m_ready ) {
+ #ifdef HAVE_OPENGL
+ if( m_ready && Options::useGL() ) {
glBindTexture(GL_TEXTURE_2D, m_tid);
return true;
} else
@@ -58,17 +60,21 @@
genTexture();
}
+#ifdef HAVE_OPENGL
void Texture::genTexture()
{
//FIXME do proper mipmapping
- #ifdef USEGL
- if( SkyMap::Instance() && !m_image.isNull() ) {
- m_tid = SkyMap::Instance()->bindTexture(m_image, GL_TEXTURE_2D, GL_RGBA, \
QGLContext::DefaultBindOption); + if( Options::useGL() ) {
+ if( !m_image.isNull() ) {
+ Q_ASSERT( TextureManager::getContext() );
+ m_tid = TextureManager::getContext()->bindTexture(m_image, \
GL_TEXTURE_2D, GL_RGBA, QGLContext::DefaultBindOption); m_ready = (m_tid != 0);
+ Q_ASSERT( m_ready );
} else
m_ready = false;
+ }
+}
#endif
-}
--- trunk/KDE/kdeedu/kstars/kstars/texture.h #1210551:1210552
@@ -20,7 +20,11 @@
#ifndef KSTEXTURE_H
#define KSTEXTURE_H
+#include <config-kstars.h>
+
+#ifdef HAVE_OPENGL
#include <GL/gl.h>
+#endif
#include <QImage>
@@ -28,19 +32,27 @@
{
Q_OBJECT
friend class TextureManager;
+
public:
///Returns true if the texture is ready to be used. If false, don't try to use \
the texture. bool isReady() const;
///Get a pointer to the image associated with this texture
const QImage& image() const;
///Bind the texture for use with GL -- return true if successful
+ #ifdef HAVE_OPENGL
bool bind() const;
+ #endif
protected:
Texture(QObject *parent = 0);
+
+ #ifdef HAVE_OPENGL
void genTexture();
+ #endif
+
protected slots:
void setImage(const QImage& img);
+
private:
QImage m_image;
bool m_ready;
--- trunk/KDE/kdeedu/kstars/kstars/texturemanager.h #1210551:1210552
@@ -25,6 +25,8 @@
#include "texture.h"
+#include <config-kstars.h>
+
class QGLContext;
/** @brief a singleton class to manage texture loading/retrieval */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic