eVoid Development Weblog Burn The Land And Boil The Sea But You Can't Take The Sky From Me

5Aug/100

Pimpl + RAII + Exceptions

The acronym RAII stands for Resource Acquisition Is Instanciation. Basicly this means that resources are allocated in the constructor of a class and released in the destructor. What the Pimpl idiom is I've described earlies this day. When using RAII, constructors that may throw exceptions are unavoidable. But this isn't a problem at all when RAII is applied consequently, for when an exception is being thrown before the constructor of an object isn't fully processed, the destructors of all statically allocated members will be called automatically. How to deal with dynamically allocated objects? Simply allocate a scoped pointer like std::auto_ptr statically and reference it to the dynamically allocated object. The problem about this method in combination with Pimpl is: The compiler will throw a warning for the code line "std::auto_ptr<MyClassImpl> pImpl;" that the destructor of MyClassImpl won't be invoked since the type of MyClassImpl is unknown. Once more, the solution is quite simple:

class __BaseImpl
{
public:
    virtual ~__BaseImpl()
    {
    }
}; // class __BaseImpl

Afterwards, simply use "std::auto_ptr<__BaseImpl> pImpl;". The only problem about this is that you will have to cast pImpl everytime you are going to access the object's implementation.

  • Share/Bookmark
5Aug/100

The Pimpl Pattern

Today I want to blog about a design pattern that is called "pImpl",which I am using widely. If used consequently, almost all inclusions inside of headers can be replaced by forward declarations, only except those which are required for inheritance. So, compile time reduction is one great advantage of that pattern. Much more significant is the improved abstraction: Classes that are defined in header files are reduced to what they originally were meant to be, namely interfaces, whose implementation is totally irrelevant. Anyway, note that excessive appliance of the "pImpl" pattern might lead to some disadvantages. It is at it has always have been concerning patterns, it is highly useful to keep them in mind, but you should never apply them just for the sake of appliance.

  • Share/Bookmark
5Aug/100

Personal Ubuntu Setup Apt Line

Just a notice to myself (and anyone other who appreciate it) a list of Ubuntu packages I keep installing after every fresh Ubuntu installation:

  • vim - my favorite text editor
  • mesa-utils - contains glxinfo and glxgears
  • rxvt-unicode - fast, lightweight and flexible terminal emulator
  • qtcreator - my favorite IDE for C++
  • nmap - network analysis
  • subversion - provides a svn client
  • git-core - provides a git client
  • ubuntu-restricted-extras - provides Flash support, MP3 and many more
  • g++ - simply the GNU C++ compiler
  • libboost-all-dev - development files for all boost libraries

Copy&paste apt command line:

sudo aptitude install vim mesa-utils rxvt-unicode qtcreator nmap subversion git-core ubuntu-restricted-extras g++ libboost-all-dev
  • Share/Bookmark
23Jul/100

Alpha 2 & Resource Organization

Today I finished the last tasks I had queued for alpha 2. Furthermore I've put a snapshot of the recent version online accomplished by some documentation. By doing so I decided to share some thoughts on the organization of resources by contexts and I'd like to draw your attention to it: What's your opinion on my solution, how do you handle it?

I've also written a roadmap for the project:

  • Alpha 1 (5. February 2010)
    • First usable version with a basic implementation of all the most important features, those are:
      • Post Processing Pipeline: Satisfying the demand on being easy to use, effects like blooming can be activated by up to three lines of code.
      • Object oriented encapsulation of most important OpenGL elements like textures, frame buffer objects and many more, providing the paradigm of orthogonality while satisfying the demand on being flexible & robust.
  • Alpha 2 (23. July 2010)
    • Countless bug-fixes & increased robustness
    • Widely improved GL encapsulation
    • Straightforward user-oriented design
    • API completely re-organized by layers

      ← Here we are
  • Alpha 3
    • Implementation of per-object motion- & usual blurring
    • Material property for specular highlighting
    • GL/gl.h dependency removal from vertexbuffer.hpp
    • Lazy state changes to avoid redundancy
    • Major API changes
      • Renderer class merged into RenderTarget
      • Materials organized by resource contexts
      • Potentially some kind of a shader abstraction:
        - Stack-like organization of shader states
        - Automatized shader generation
  • Share/Bookmark
22Jul/102

Z-Fighting Problem Solved

Thanks to an user named kRogue on the OpenGL forums the problem mentioned here is finally solved:

glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_ALPHA );

is not part of GL3 core... though it is there in a compatible context. Try taking that call out and use the .r component of the depth texture in your shader... this should NOT make a difference, but you never know.

- kRogue

Furthermore I've been notified that the problem didn't occur on a GF GTX260.

One more important aspect to notice that you should check if you should ever happen to run into the same problem as I did: The GL_MIN_FILTER and GL_MAG_FILTER properties of the depth texture object must be set to GL_NEAREST. At least they are not allowed to be set to GL_LINEAR. Don't ask me for the reason. Otherwise you will experience the same Z-Fighting as I did.

  • Share/Bookmark
21Jul/100

C++0x, Lambda Expressions and Visitors

I know there are thousands and millions of articles out there dealing with the new features that are being introduced by the new C++ ISO standard commonly known as C++0x. Today I read that on Code Project and got very enthusiastic about the part that described the lambda expressions. I know that is damn geeky but I almost went bananas :D when I read what they are and what kinda stuff you can do with them. Countless situations came immediately on my mind in which I could take advantage of them. Usually I tend to make very extensive use of the Visitor pattern. Most of my classes that encapsulate some kind of an 1 -to- n>1 association do offer a function like VisitObjects( :UnaryFunction ). I like it that much because I believe it's the most short and abstract way to offer an interface for the traversal of associated objects. No matter how the data is internally organized - whether it's a tree or maybe a flat structure like a linked list or an array - the interface stays all the same. Up to now I had to do the following to make use of that kind of interfaces:

namespace impl
{
 
class MyFunctor
{
public:
 
    int i;
 
    MyFunctor( int i )
        : i( i )
    {
    }
 
    bool operator() ( const MyElement& e )
    {
        std::cout << ( i++ ) << " - " << e << std::endl;
        return true;  //< continue traversal
    }
 
};
 
}  // namespace impl
 
 
void MyClass::MyFunction()
{
    impl::MyFunctor visitor( 0 );
 
    MySet.VisitMyElements( visitor );
 
    std::cout << "We've vistited " << visitor.i << " elements" << std::endl;
}

Everyone will admit that is kinda ugly. Now, thanks to lambda expressions, I could just inline the whole logic into the one really necessary function:

void MyClass::MyFunction()
{
    int i = 0;
    MySet.VisitMyElements( [&]( const MyElement& e )->bool
            {
                std::cout << ( i++ ) << " - " << e << std::endl;
                return true;  //< continue traversal
            } );
 
    std::cout << "We've vistited " << i << " elements" << std::endl;
}

Though I haven't tested it, to me lambda expressions and the visitor pattern seem like made for each other :D

  • Share/Bookmark
20Jul/100

WordPress 3.0 & SFTP

WordPress 3.0 has a nice feature that does all the platform and plugin updating for you by just clicking an 'Update' button at the admin console. In order to do so it needs to connect to the server the blog is hosted. By the default configuration of my (and I guess almost any) server only FTP and FTPS (FTP via SSL) are available here. Since my server doesn't run a FTP server module for security reasons I looked for a way to teach SFTP (kinda FTP tunneled via SSH) to the platform and stumbled over a blog post by Raditha Dissanayake from June 2009 that described the required procedure for a Fedora box. Since I'm running Ubuntu Hardy Heron LTS I'll sum up what I had to do on that specific system:

aptitude install libssh2-1-dev php-pear php5-dev
pecl install -f ssh2
echo "extension=ssh2.so" > /etc/php5/conf.d/ssh2.ini
/etc/init.d/apache2 restart

This procedure will enable the SSH2 extension for PHP. Afterwards there will immediately be a 'SSH2' option beside FTP and FTPS located in WordPress' update dialog.

  • Share/Bookmark
5Jul/102

Update + Thoughts of Quad- & Octtrees

Even though I didn't update that blog during the past few months, the work proceeded quite well. A countless amount of bugs has been fixed, the abstraction from OpenGL improved a lot and the API itself completely revised. I've outlined a road map of what still has to be done 'til Alpha 2 and it's not that much:

  1. Implement DefaultMesh::CreateSphere
  2. Implement DefaultMesh::CreateCylinder
  3. Implement DefaultMesh::CreateCone
  4. Solve Bloom-zBuffer-Problem
  5. Clean up some header files

So #1 was an ease and now I'm still almost done with #4 which is the last greater task. The problem here was that rendering with bloom worked like a charm but when rendering in combination with objects that should have been not affected by the bloom effect, the depth-buffer information messed up. The bad thing about it is that I finally reached the limits of the possibilities of my GeForce 6600 and am not able to proceed right now, for I also don't have the money to buy me a new card. So it's fairly probable that I won't continue work on this task until September, when I expect to get a new notebook bought by the institute I will start working at, namely the Institute for Medical Engineering as an appliance.

So I spent a few thoughts on the later organization of the world data in octtrees recently when I was bored. The following short article will describe a way of organizing the nodes of a quadtree (for the sake of clarity) in a certain way which allows a very easy and straightforward traversal of the tree. It is trivial to expend this technique to work with octtrees.

  • Share/Bookmark
16Jan/100

kcachegrind

Ein Super-Tool, um sich mal einen Überblick über die Performance-Bremsen in einem Programm zu verschaffen:

kcachegrind

  • Share/Bookmark
veröffentlicht unter: Know-How keine Kommentare
30Jun/090

Resources Detail Stack

Die im Folgenden vorgestellte Datenstruktur kann verwendet werden, um verschiedene Detailstufen einer Geometrie zu verwalten. Sie wird besonders der Annahme gerecht, dass die Frage, wie viele Detailstufen eine Geometrie hat, allein ihre eigene Sache ist, was die Portabilität und Erweiterbarkeit deutlich fördert.

  • Share/Bookmark