Jump to content

  • Log In with Google      Sign In   
  • Create Account

TheKreature

Member Since 24 Mar 2006
Offline Last Active Dec 20 2014 03:18 PM

#5193896 Proper C++ header file?

Posted by TheKreature on 20 November 2014 - 07:57 PM

 

I would also suggest to replace

 

#ifndef INCLUDED_TILEMAP_H

#define INCLUDED_TILEMAP_H

 

by

 

#pragma once

 

it's simpler and you don't need the #endif at the end smile.png

 

The only problem with it is that it is not part of the C/C++ standard, so while it is supported by major compilers, it can't be guaranteed to always work.

 

 

 

I thought that I should extend this a little.

Compiler support for this is wide.

http://en.wikipedia.org/wiki/Pragma_once

 

However, I'm yet to see someone screw up #ifndef INCLUDED_#

(Aside from me, just then). tongue.png.

 

Maybe I'm just being old and crotchety and indicating to people to get off of my lawn. 

For me, I prefer #ifndef/#define.

I prefer not to see "#pragma" in my code unless it is inline adding a library (which I prefer it wouldn't (still guilty of this myslef)), or disabling particularly annoying Microsoft compile warnings.

I started with Visual Studio 5.0, and #pragma meant "hear be dragons" to me.

 

I think that preference on this may fit under "religious/other".

 

smile.png.




#5193869 Proper C++ header file?

Posted by TheKreature on 20 November 2014 - 03:59 PM

Some general thoughts and ramblings.

Ramblings are inlined in comments. :).

#ifndef INCLUDED_TILEMAP_H
#define INCLUDED_TILEMAP_H

// You are only using string.
// You should only include string.
// Judiciously including only what you use will improve compile times.
// This is so important that people have written tools to ensure that a
// code base adheres to this:
// https://code.google.com/p/include-what-you-use/wiki/WhyIWYU
//
#include <string>

// Style guides, totally worth reading up on.
// Seeing as you are just starting out, choose a different one for every project.
// Adhere to it. Learn what you don't like about it:
// http://google-styleguide.googlecode.com/svn/trunk/cppguide.html
// http://udn.epicgames.com/Three/CodingStandard.html
// http://wiki.ros.org/CppStyleGuide
// Many more by googling "c++ style guide" + some company name.
class TileMap
{
  public:
    // Declare the default constructor. Even though a default is provided, it is
    // a really, really good habit to get into.
    //
    TileMap();

    // Declare the copy constructor. It will save you later.
    // I would also (maybe) suggest looking into the concept of "non copyable".
    // 
    TileMap(const TileMap& from);
    TileMap(const std::string& name, const std::string& location);

    // Declare the default destructor. Even though a default is provided, it is a 
    // life saving habit to get into.
    //
    ~TileMap();

    // Again, one is provided, but quite honestly, this is a another life saving habit
    // to get into when you are just starting out.
    //
    TileMap&            operator=(const TileMap &);

    // Const references for input when setting a value.
    //
    void                setName(const std::string& inName);

    // I assume that "loc" is location. 
    // A longer variable name will help you later when you have other stuff to think about.
    //
    void                setLocation(const std::string& inLocation);

    // Accessors usually are const. I tend to loathe using get on the "gettor".
    // Returning a const ref here is also faster. 
    // I also suggest reading up on return value optimization...
    // http://en.wikipedia.org/wiki/Return_value_optimization
    // If you are aiming for well performing code I would recommend doing away with
    // the use of std::string all together and using const char*.
    // Supplying a const char* in the "create" function should also lead you onto
    // topics such as "copy on write", which is something totally worth reading about:
    // (But not until you know why you shouldn't have a function 
    //  operator in a class declaration :) ).
    // http://en.wikipedia.org/wiki/Copy-on-write 
    // Now I'm rambling, so I will stop.
    //
    const std::string&  name() const;
    const std::string&  location() const;

  private:
    // You should probably consider marking your members with a character 
    // that indicates the variable is a member. 
    // Some naming models become very elaborate at the expense of readability.
    // I prefer underscores, others prefer m, some specs prefer extended information
    // for pointers. I.e., if _name were a pointer, the variable would be _pName or mpName.
    //
    std::string         _name; // or mName
    std::string         _loc; // or mLoc
};


#endif




#5191944 Tool release for physically based rendering

Posted by TheKreature on 09 November 2014 - 12:43 PM

I've recently released an image based lighting baker for physically based rendering to generate preconvonvolved specular cube maps (computed against a user specified brdf) using the seperable method proposed by Epic during Siggraph 2013.

 

The tool also bakes out the BRDF LUT, and a diffuse irradiance environment map. Cubemaps are saved as both MDR and HDR.

 

You can find the tool at:
https://github.com/derkreature/IBLBaker
 
There are also a number of walkthrough and example videos at:
http://www.derkreature.com/

I have also supplied 2 Maya example scenes to test the cubemap outputs using Viewport 2.0 and cgfx.

 

Please contact me through my github account if you find any bugs, have questions or have any suggestions. The code is based on some of my older framework code. You'll have to hold your nose around some of the more horrible bits.

 

Hopefully some of you find this useful.

If there is any interest, I'd consider writing an article on this.

 

I thought I'd throw in another quick demo of this tech applied to character rendering. (Still proof of concept really):




#5049073 Free texture image memory after binding it

Posted by TheKreature on 01 April 2013 - 09:42 PM

Yes, glTexImage2D is copying your image data.

 

Probably worth mentioning GL synchronization notes:

This stuff used to be a little different, and has improved immensely:

 

From: http://www.opengl.org/wiki/Synchronization


Legacy Note: The only OpenGL functions that behave differently are functions that end in Pointer​. When these use client-side memory (which is no longer permitted in core OpenGL), the pointers are stored for a period of time. During that period, they must remain valid.

These are usually used for rendering calls; in which case, once the rendering call has returned, the memory to be read from client data has been read. Modifications to client memory after the rendering call will only affect future rendering calls, not those that have already passed.
This is generally why Buffer Objects are better than using client memory for rendering. A rendering call with buffers does not have to handle the possibility of the user changing the memory later, so it can simply write a few tokens into the command stream. With client memory, it must copy all of the vertices out of the client-side arrays.




PARTNERS