
-----------------------LONGTERM TODO----------------------------------------------------------------
 - Debug tools 
   - Camera controls + world grid
 - Renderable (contains mesh/material)
 - RenderManager (iterated through Renderables and displays them on screen)
   - And its plugin implementation ForwardRenderingManager
 - Integrate with Camelot Editor
 - SceneManager plugin
   - Frustum culling and octree (or some other) acceleration structure
   - Render queue and sorting

-----------------------IMMEDIATE TODO---------------------------------------------------------------


>>>>>>>>>>FINAL SPRINT BEFORE EDITOR WORK
Pass
 - A way to bind buffers to a Pass, while specifying buffer range
 - GpuParams support for bools, buffers, structs

 Null mesh VertexDeclaration never gets freed.
  - Similar issue with all the four states and their defaults
 Add MeshManager which creates a mesh and also creates and releases null mesh.
Even if all resources are released I still get a crash on exit. Probably because I don't properly release all factories.
 Test DX9 and DX11 versions, and see if everything is released properly.
When rendering with renderable a lot of references don't get released so I need to check where are they kept

Stuff that needs to derive from CoreGpuObject:
 - GpuProgram (DONE)
 - HighLevelGpuProgram (DONE)
 - Texture (DONE)
 - Mesh - (DONE)
 - VertexBuffer (DONE)
 - IndexBuffer (DONE)
 - GpuBuffer (DONE)
 - VertexDeclaration (DONE)
 - RenderWindow (DONE)
 - RenderTexture (DONE)
 - MultiRenderTexture (DONE)
 - Blend/DepthStencil/Rasterizer/SamplerState (DONE)
 - GpuParamBlock
---
 Maybe
  - Material (DONE)
  - Pass (NOT REQUIRED)
  - Shader (DONE)
  - Technique (NOT REQUIRED)

Test if async loading still works

RenderTextures and MultiRenderTextures will only work properly if used directly from render thread, as setting each surface calls render methods, so its impossible to set one outside of render thread
 - also they don't have initialize_internal
 - I should probably make these immutable. Once they are set they can't be changed, so everything can be initialized when calling initialize()

OpenGL render window no longer looks for a monitor index

CoreGpuObject and CoreGpuObjectManager
 - make ::Destroy() virtual as Resources need to make it private
 
ResourceHandle::reset removes ALL references to a resource. It's probably smarter if it just removes the one reference

Plan today & saturday:
 Add destroy() for remaining classes

 - Support loading of compound objects:
   - Loading Material also loads attached Shader and Textures/Samplers
  - Make Resources::destroy() private
  - Have Resources::unload which calls destroy() internally
  - Have Resources::unloadUnused() which unloads all with reference count of 1
  - Don't store heavyweight GUID in each ResourceHandle

  Calling CoreGpuObject::waitUntilInitialized and initialization fails (or is never called) it will block forever

Material RTTI should also serialize shared buffers (they need to be made into a resource)
 - BE CAREFUL on how this will be implemented. Likely it will have much of the same interface as a material and/or GpuParams

Add support for include file resource
Make sure we can add an include file to a HighLevelGpuProgram, and make sure it uses it
 - Also a way to list all referenced includes, and a way to remove them

Loading material should also load attached shader and textures/sampler states

 Refactor how we handle RenderTargets (no attach/detach, and no waitForVSync propery in RenderSystem)
 waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)

Go through RenderSystem classes and make sure we don't hold any raw pointer references.

Can be delayed:
 Make sure that I am able to blit contents from render textures on all render systems
 Once I get DX11 running make sure to test if driver complains about missing shader attributes or invalid size ones
 Better creation of PrimaryWindow
  - RENDERWINDOWDESC accepts a "externalWindow" flag and an "externalHandle" so when creating the primary window with RenderSystem::initialize we don't always need to create a new window
  - Actually new OpenGL seems to support creating context without a window with the help of wglCreateContextAttribsARB and wglMakeCurrent:
 ImportOptions
 Instead of doing setThisPtr on every CoreGpuObject, use intrusive shared_ptr instead?
>>>>>>>>>>>>>>>START WORKING ON THE EDITOR!
 

---------------------------------------------------

<<<<Handle multithreaded object management>>>:
 - Make everything that is possible immutable. Once created it cant be changed.
  - Example are shaders, state objects and similar
 - Things like Textures, Vertex, Index buffers, GpuParams may be changed
  - Make Vertex/Index buffers and similar only accesible from render thread. Higher level classes like meshes can have deferred methods
  - TODO - How to handle the remaining actually deferred methods? Like Textures?

DirectX11 supports concurrent drawing and resource creation so all my resource updates should be direct calls to DX methods (I'll need a deferred context?)
 - DX9 doesn't so creating/updating resources should wait for render thread?
  - Although these are sync points which kill the whole concept of separate render thread
  - Updating via copy then? (DX11 driver does it internally if resource is used anyway)
 - OpenGL? No idea, need to study GL contexts
 - Although it seems DX11 also copies data when mapping/unmapping or updating on a non-immediate context. So maybe copy is the solution?

So final solution:
 - Copy all data that will be updated on a deferred context
  - Make deferred context have a scratch buffer it can use for storing temporary copied data
 - Immediate context will execute all commands right away
  - This applies when rendering thread calls resource create/update internally
  - Or when other thread blocks and waits for rendering thread
 - Create a simple distinction so user knows when is something executed deferred and when immediate?
  - Move resource update/create methods to DeferredContext?
    - Not ALL methods need to be moved, only those that are resource heavy
    - Smaller methods may remain and always stay async, but keep internal state?
 - Resource creation on DX11 should be direct though, without a queue (especially if we manage to populate a resource in the same step)
 - (Make sure to update GpuParamBlock implementations as they do their copying internally)


<<<<Issue of setting individual parameters on a material>>>
 - Material can contain multiple techniques
 - How do I ensure parameters are valid for all techniques?
 - Require user to create a Material parameter specification?
 - Also need a way to avoid displaying internal parameters used by the active renderer

<<<<RenderSystem needed modifications>>>>
  - Texture resource views (Specifying just a subresource of a texture as a shader parameter)
  - UAV for textures
  - Stream out (write vertex buffers) (DX11 and GL)
  - Texture buffers 
   - Just add a special texture type? OpenGL doesn't support getting offset from within a texture buffer anyway
  - Tesselation (hull/domain) shader
  - Detachable and readable depthstencil buffer (Window buffers not required as they behave a bit differently in OpenGL)
  - OpenGL provides image load/store which seems to be GL UAV equivalent (http://www.opengl.org/wiki/Image_Load_Store)
  - Resolving MSAA textures (i.e. copying them to non-MSAA so they can be displayed on-screen). DX has ResolveSubresource, and OpenGL might have something similar.
  - Single and dual channel textures (especially render textures, which are very important for effects like SSAO)
  - Compute pipeline
  - Instancing (DrawInstanced) (DX11 and GL)
  - OpenGL append/consume buffers
  - Indirect drawing via indirect argument buffers
  - Texture arrays
  - Rendertargets that aren't just 2D (Volumetric (3D) render targets in particular)
  - Shader support for doubles
  - Dynamic shader linkage (Interfaces and similar)
  - Multisampled texture resources
  - Multiple adapters (multi gpu)
  - Passing initial data when creating a resource (DX11, but possibly GL too)
  - Sample mask when setting blend state (DX11, check if equivalent exists in GL)
  - RGBA blend factor when setting blend state(DX11, check if equivalent exists in GL)
  - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes

Command buffer TODO:
 - Make CommandQueue not use mutexes and use atomics instead??
 - Figure out how to handle accessing texture from a non-render thread?
 - When importing a resource, and registering it with Resources I don't think it properly gets added to the loaded resources array? For some reason shaders get created twice.
 - Doing setPixels_async in the texture doesn't make sure that the user doesn't actually modify the provided PixelData after
    that call.
 - In general I need to rethink how to handle modifying resources with multithreading

Editor IMPORTANT:
 - When displaying inspector data for a component, take into consideration that it will need to be able
    to display that data for user created C# classes as well. AND I will most certainly have C# versions of all my
	components. Therefore is there any purpose of having C++ only inspector parsing code?

-----------------------BACKLOG TODO---------------------------------------------------------------

HIGH PRIORITY TODO:
 - Issue with deserialization and value types:
  - Value types are only set at the end of deserialization, because I want to be sure all of their fields are initialized. However there is nothing stopping a custom RTTI method from accessing a (yet uninitialized) value in a ptr field. (See CmMaterialRTTI, setTexParam). I need to initialize fields in a better order.
   - Solution?: Set (empty) ptr values immediately, and only load them later
 - GetRenderOperation doesn't consider sub-meshes

Mid priority TODO:
 - monitorIndex is ignored in DX11
 - Make sure to queue up mesh deletion to make sure it gets destroyed on the render thread
 - Resource handle should store a unique integer ID, which just points to a table of GUIDs. Keeping GUID string everywhere in not efficient.
 - Add a field that tracks % of resource deserialization in BinarySerializer
 - Mesh loading:
  - Example Freefall mesh has one index per vertex, and there are 17k+ vertices. I think I need a post-process step that optimizes them.
  - Imported FBX meshes are too big
  - Search for all remaining "TODO PORT" comments and fix them
  - Ogre performed special DDS loading. I removed that. I'm not sure if I'll need to re-add it?
  - My log is not thread safe yet it is being called from multiple threads.
  - Handling of shader array parameters? This needs testing
   - I'm currently ignoring array elements in GL due to the name their names are handled
 - RTTI:
     When defining RTTIType like so: 
      RTTIType<D3D9HLSLProgram, HighLevelGpuProgram, D3D9HLSLProgramRTTI>
     I need to make sure that HighLevelGpuProgram class has valid RTTI type as well. Otherwise the inheritance hierarchy will not be correct. Right now this isn't checked anywhere.

Low priority TODO:
 - Can I assign a RenderTexture to a Pass?
 - Mesh loading:
  - Sub-meshes aren't being transformed by world matrices of their nodes
 - Are resource getting properly unloaded? e.g. when shared_ptr destroys a texture is it removed from gpu?
  - Make sure resources only get properly unloaded at end of every frame. This is because a lot of RenderSystem stuff holds raw ptrs
	to resources, and it keeps them throughout the frame (especially with deferred rendering). Plus this can only be done on the render thread anyway.
 - Remove template from RTTIType and move it to IReflectable? This way i can hopefully move GetRTTITypeStatic and GetRTTIType to IReflectable so I don't
   need to manually implement those for every method.
 - Viewport needs to be updated when I call RenderTarget::setFullscreen/finishSwitchingFullscreen/updateWindowRect/windowMovedOrResized. Currently it's not
 - D3D9Texture::createTextureResources is commented out at the moment. It gets called on device reset, and at that point I should reload texture resources.
  - I should probably keep all resources by DX managed. OpenGL apparently keeps a mirror of all its resources anyway.
 - Device reset and resource re-loading in general
 - In RTTIType it is possible to add a non-plain data type using addPlainField. This can cause memory corruption issues
   if pointer is saved/loaded as a plain field. I need to add a check that ensures the type is POD. 
   See: http://www.boost.org/doc/libs/1_51_0/boost/mpi/datatype.hpp for a possible implementation of a compile time check.
 - Fix up WorkQueue as it doesn't lock when initializing, to make sure threads are actually started before returning
 - DepthStencilBuffer & Texture should possibly share the same interface instead of being two separate classes? I'll need to assign DepthStencil to shaders sometimes. Not possible in DX9 but possible in DX11.
 - CPU reading or writing to a render texture in OpenGL is not supported. (CmGLHardwarePixelBuffer::upload/download). 
 - When saving a resource, make sure resource is properly loaded before saving
   - Add doc to Resources::save that says it will block until render thread updates the resource
   - Add documentation that tells the user that reading a resource non-async will block the thread and execute all queued render commands first
   - Remove Response handlers from Resources
- Cg doesn't work. Either remove it or get it to work
- System is not yet ready for multiple rendering contexts

Optional TODO:
 - Add precompiled headers to all projects
 - If possible, make sure GLSL uses EntryPoint and Profile fields I have added to GpuProgram
 - Move all x86 libs to x86 folders. Move all binaries to x86 folders as well
 - Serializable callbacks can't be null otherwise compiler complains
 - FBX importer can be greatly sped up by implementing a better allocator
 - Extend texture copy so it accepts different subregions & subresources (currently only entire resource can be copied)
 - Need a way to convert MSAA render texture into a normal render texture
 - Vertex buffer start offset is not supported when calling Draw methods

 -----------------------------------------------------------------------------------------------

After everything is polished
 - Each view (i.e. camera) of the scene should be put into its own thread
 - How do I handle multiple mesh formats? Some files need animation, other don't. Some would mabye like to use QTangent, others the proper tangent frame.
  - Asset postprocessor? Imports a regular mesh using normal importers and then postprocesses it into a specialized format?
 - Load texture mips separately so we can unload HQ textures from far away objects (like UE3)
 - Add Unified shader so I can easily switch between HLSL and GLSL shaders (they need same parameters usually, just different code)
    - Maybe just add support for Cg and force everyone to use that? - I'd like to be able to just switch out renderer in a single location and that everything keeps on working without 
	  further modifications.
 - Port boost threads to std threads (CmThreadDefines.h)
 - Remove HardwarePixelBuffer (DX11 doesn't use it, and DX9 and OpenGL textures can be rewritten so they have its methods internally)
 - Multihead device
 - 3D rendering (use low level hardware methods for it)
 
 - Don't forget to check out Unity DX11 documentation on how to implement DX11 features (http://docs.unity3d.com/Documentation/Manual/DirectX11.html)
 - Go to Game Engine Architecture book and make a list of Utility systems we will need (Config files, Parsers, File I/O etc)
 - Go to GEA book and read about resource managers before implementing them
   - Actually I should re-read most of the chapers in the book, or all of it

 - OpenGL non-Win32 window files haven't been properly parsed or tested
   - Since I probably can't compile them, try adding them to VS and see what intellisense says?

 - Textures and all other buffers keep a copy of their data in system memory. If there are memory constraints we might need a way to avoid this.

