
#ifndef __WFX_RENDERER_RENDERTARGET_H__
#define __WFX_RENDERER_RENDERTARGET_H__

#include <WFX/WFXIncludes.h>
#include <WFX/scene/Color.h>
#include <WFX/renderer/RenderJob.h>
#include <WFX/io/File.h>

namespace WFX {

    namespace renderer {

        /**
         * abstract RenderTarget base class 
         * A RenderTarget could be an image, a texture or
         * a window...
         * RenderTargets are doublebuffered, all operations
         * are executed on the backbuffer and swapBuffers needs to
         * be called for these to be brought to effect
         */
        class RenderTarget {
            public:
                /**
                 * Ctor
                 * @param: w - Width
                 * @param: h - height
                 * @param: d - depth
                 */
                RenderTarget(Int w, Int h, Int d);
                virtual ~RenderTarget() {}

                /**
                 * adds a RenderJob to the target
                 * renderables receive a call to render() any
                 * time the RenderTarget gets drawn
                 */
                void addRenderJob(WFX::renderer::RenderJob* r);
                /** removes the given RenderJob from this target */
                void removeRenderJob(WFX::renderer::RenderJob* r) {
                    RenderJobs.remove(r);
                }

                /**
                 * this function renders the Rendertarget
                 * and all its attached RenderJobs
                 * IMOPRTANT: swapBuffers is *not* called within this
                 * function, users need to call it themselves to actually
                 * see stuff!
                 */
                void render();
                
                /** returns this RenderTarget's Width */
                virtual Int getWidth() {
                    return Width;
                }
                /** returns this RenderTarget's Height */
                virtual Int getHeight() {
                    return Height;
                }
                /** returns this RenderTarget's Depth */
                virtual Int getDepth() {
                    return Depth;
                }

                /** swaps the render buffers */
                virtual void swapBuffers() = 0;
                /** sets the ClearColor */
                virtual void setClearColor(const WFX::scene::Color& c) = 0;
                /** Clears the Backbuffer */
                virtual void clear() = 0;

                /** save contents to given file */
                virtual void saveToFile(const WFX::io::File& f) = 0;

                /** debug */
                void printDebug();
            protected:
                /** Width, Height, Depth */
                Int Width;
                Int Height;
                Int Depth;

                /** list of renderables */
                std::list<WFX::renderer::RenderJob*> RenderJobs;
            
            private:

        };

    }

}


#endif //include guard


