Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "Headers/Reflector.h"

#include "Core/Headers/Application.h"
#include "Hardware/Video/Headers/GFXDevice.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"

namespace Divide {

Reflector::Reflector(ReflectorType type, const vec2<U16>& resolution) : FrameListener(),
                                                                     _type(type),
                                                                     _resolution(resolution),
                                                                     _updateTimer(0),
                                                                     _updateInterval(45), /// 45 milliseconds?
                                                                     _reflectedTexture(nullptr),
                                                                     _createdFB(false),
                                                                     _updateSelf(false),
                                                                     _excludeSelfReflection(true),
                                                                     _previewReflection(false)
{
    REGISTER_FRAME_LISTENER(this, 3);
    ResourceDescriptor reflectionPreviewShader("fbPreview");
    reflectionPreviewShader.setThreadedLoading(false);
    _previewReflectionShader = CreateResource<ShaderProgram>(reflectionPreviewShader);

    GFX_DEVICE.add2DRenderFunction(DELEGATE_BIND(&Reflector::previewReflection, this), 2);
}

Reflector::~Reflector()
{
    UNREGISTER_FRAME_LISTENER(this);
    MemoryManager::DELETE( _reflectedTexture );
    RemoveResource(_previewReflectionShader);
}

/// Returning false in any of the FrameListener methods will exit the entire application!
bool Reflector::framePreRenderEnded(const FrameEvent& evt){
    // Do not update the reflection too often so that we can improve speed
    if(evt._currentTime  - _updateTimer < _updateInterval ){
      return true;
    }
    _updateTimer += _updateInterval;
    if(!_createdFB){
        if(!build()){
            // Something wrong. Exit application!
            ERROR_FN(Locale::get("ERROR_REFLECTOR_INIT_FB"));
            return false;
        }
    }
    //We should never have an invalid FB
    assert(_reflectedTexture != nullptr);
    // mark ourselves as reflection target only if we do not wish to reflect ourself back
    _updateSelf = !_excludeSelfReflection;
    // generate reflection texture
    updateReflection();
    // unmark from reflection target
    _updateSelf = true;
    return true;
}

bool Reflector::build(){
    PRINT_FN(Locale::get("REFLECTOR_INIT_FB"),_resolution.x,_resolution.y );
    SamplerDescriptor reflectionSampler;
    reflectionSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
    reflectionSampler.toggleMipMaps(false);
    //Less precision for reflections
    TextureDescriptor reflectionDescriptor(TEXTURE_2D, RGBA8, UNSIGNED_BYTE); 

    reflectionDescriptor.setSampler(reflectionSampler);

    _reflectedTexture = GFX_DEVICE.newFB();
    _reflectedTexture->AddAttachment(reflectionDescriptor, TextureDescriptor::Color0);
    _reflectedTexture->toggleDepthBuffer(true);
    _createdFB = _reflectedTexture->Create(_resolution.x, _resolution.y);

    return _createdFB;
}

void Reflector::previewReflection() {
#   ifdef _DEBUG
        if (_previewReflection) {
            F32 height = _resolution.y * 0.333f;
            _reflectedTexture->Bind(ShaderProgram::TEXTURE_UNIT0);
            vec4<I32> viewport(0, 
                              Application::getInstance().getResolution().y - height, 
                              _resolution.x  * 0.333f, 
                              height);
			GFX_DEVICE.renderInViewport(viewport,
                                        DELEGATE_BIND((void(GFXDevice::*)(U32, size_t, ShaderProgram* const))
                                                      &GFXDevice::drawPoints,
                                                      &GFX_DEVICE,
                                                      1,
                                                      GFX_DEVICE.getDefaultStateBlock(true),
                                                      _previewReflectionShader));
        }
#   endif
}

};

Commits for Divide-Framework/trunk/Source Code/Rendering/RenderPass/Reflector.cpp

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

299 Diff Diff IonutCava picture IonutCava Mon 04 Aug, 2014 22:09:22 +0000

[Ionut]
- Disabled shader binary dump/load on non-nVidia GPUs (caused issues)
- More code cleanup/comments/formating (GFXDevice.cpp)

296 Diff Diff k1ngp1n picture k1ngp1n Sun 03 Aug, 2014 14:54:21 +0000

[Ionut]
- nVidia compatibility fixes (GUI, shadows, post-processing)
- Texture bind slots are now part of ShaderProgram class
- Renamed ForwardRenderer class to ForwardPlusRenderer and moved ligh grid creation to it
- More code cleanups and comments

288 Diff Diff IonutCava picture IonutCava Wed 23 Jul, 2014 20:34:25 +0000

[Ionut]
- Added a common interface to GenericVertexData and VertexBuffer
- Removed deferred deletion of FrameListeners from FrameListenerManager. It complicated the code with no added benefit
- Added proper FrameListener unregister calls

286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

269 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 12:56:45 +0000

[Ionut] [[BR]]
- All texture objects now properly allocate storage using glTextureStorage*D(w-w/o Multisampled) [[BR]]
- Removed useless “format” element from TextureDescriptor. Format is deduced from the internal format specified (RGBA8 uses RGBA. RG32F uses RG) [[BR]]
- Use GLM only with radians [[BR]]

267 k1ngp1n picture k1ngp1n Wed 28 May, 2014 11:08:12 +0000

[Ionut] [[BR]]
- Improved texture handling: [[BR]]
— No more texture unbind (except when clearing the frame state) [[BR]]
— Moved texture bind checking to the GL_API class [[BR]]
- Fixed a crash related to vegetation loading due to compiler optimizations [[BR]]
- removed all “releaseMaterial” functions as they are no longer needed [[BR]]