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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "Hardware/Video/OpenGL/Headers/glResources.h"
#include "core.h"
#include "Headers/glPixelBuffer.h"
#include "Hardware/Video/Headers/GFXDevice.h"

namespace Divide {

size_t glPixelBuffer::sizeOf(GLenum dataType) const{
    switch(_dataType){
        case GL_FLOAT: return sizeof(GLfloat);
        case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
        case GL_UNSIGNED_INT: return sizeof(GLuint);
        case GL_UNSIGNED_SHORT: return sizeof(GLushort);
        case GL_BYTE: return sizeof(GLbyte);
        case GL_SHORT: return sizeof(GLshort);
        case GL_INT: return sizeof(GLint);
    };
    return 0;
}

glPixelBuffer::glPixelBuffer(PBType type) : PixelBuffer(type) {
    switch(_pbtype){
        case PB_TEXTURE_1D:
            _textureType = GL_TEXTURE_1D;
            break;
        case PB_TEXTURE_2D:
            _textureType = GL_TEXTURE_2D;
            break;
        case PB_TEXTURE_3D:
            _textureType = GL_TEXTURE_3D;
            break;
        default:
            ERROR_FN(Locale::get("ERROR_PB_INVALID_TYPE"));
            break;
    };
}

void glPixelBuffer::Destroy() {
    if(_textureId > 0){
        glDeleteTextures(1, &_textureId);
        _textureId = 0;
    }

    if(_pixelBufferHandle > 0){
        glDeleteBuffers(1, &_pixelBufferHandle);
        _pixelBufferHandle = 0;
    }
    _width = 0;
    _height = 0;
    _depth = 0;
}

void* glPixelBuffer::Begin(GLubyte nFace) const {
    DIVIDE_ASSERT(nFace < 6, "glPixelBuffer error: Tried to map an invalid PBO texture's face!");

    GL_API::bindTexture(0, _textureId, _textureType);
    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, _pixelBufferHandle);
    switch(_pbtype){
        case PB_TEXTURE_1D:
            glTexSubImage1D(_textureType, 0, 0, _width, _format, _dataType, 0);
            break;
        case PB_TEXTURE_2D:
            glTexSubImage2D(_textureType, 0, 0, 0, _width, _height, _format, _dataType, 0);
            break;
        case PB_TEXTURE_3D:
            glTexSubImage3D(_textureType, 0, 0, 0, 0, _width, _height, _depth, _format, _dataType, 0);
            break;
    };

    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, _pixelBufferHandle);
    switch(_pbtype){
        case PB_TEXTURE_1D:
            glBufferData(GL_PIXEL_UNPACK_BUFFER, (_width*4) * sizeOf(_dataType), NULL, GL_STREAM_DRAW);
            break;
        case PB_TEXTURE_2D:
            glBufferData(GL_PIXEL_UNPACK_BUFFER, (_width*_height*4) * sizeOf(_dataType), NULL, GL_STREAM_DRAW);
            break;
        case PB_TEXTURE_3D:
            glBufferData(GL_PIXEL_UNPACK_BUFFER, (_width*_height*_depth*4) * sizeOf(_dataType), NULL, GL_STREAM_DRAW);
            break;
    };

    return glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
}

void glPixelBuffer::End() const {

    glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // release the mapped buffer
    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    GL_API::unbindTexture(0, _textureType);
}

void glPixelBuffer::Bind(GLubyte unit) const {
    GL_API::bindTexture(unit, _textureId, _textureType);
}

bool glPixelBuffer::Create(GLushort width, 
                           GLushort height,
                           GLushort depth, 
                           GFXImageFormat internalFormatEnum, 
                           GFXImageFormat formatEnum,
                           GFXDataFormat dataTypeEnum) {

    _internalFormat = GLUtil::GL_ENUM_TABLE::glImageFormatTable[internalFormatEnum];
    _format         = GLUtil::GL_ENUM_TABLE::glImageFormatTable[formatEnum];
    _dataType       = GLUtil::GL_ENUM_TABLE::glDataFormat[dataTypeEnum];

    Destroy();
    PRINT_FN(Locale::get("GL_PB_GEN"),width,height);
    _width = width;
    _height = height;
    _depth = depth;
    GLuint size = _width;
    if(_pbtype != PB_TEXTURE_1D)
        size *= _height;
    if(_pbtype == PB_TEXTURE_3D)
        size *= _depth;

    size *= 4/*channels*/;

    glGenTextures(1, &_textureId);
    GL_API::setPixelPackUnpackAlignment();
    GL_API::bindTexture(0, _textureId, _textureType);
    glTexParameteri(_textureType, GL_GENERATE_MIPMAP, GL_FALSE);
    glTexParameteri(_textureType,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(_textureType,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(_textureType, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(_textureType, GL_TEXTURE_MAX_LEVEL, 1000);
    glTexParameteri(_textureType, GL_TEXTURE_WRAP_S, GL_REPEAT);
    if(_pbtype != PB_TEXTURE_1D){
        glTexParameteri(_textureType, GL_TEXTURE_WRAP_T, GL_REPEAT);
    }
    if(_pbtype == PB_TEXTURE_3D){
        glTexParameteri(_textureType, GL_TEXTURE_WRAP_R, GL_REPEAT);
    }

    void *pixels = nullptr;

    switch(_dataType){
        default                : pixels = MemoryManager_NEW GLubyte[size];  break;
        case GL_FLOAT          : pixels = MemoryManager_NEW GLfloat[size];  break;
        case GL_UNSIGNED_INT   : pixels = MemoryManager_NEW GLuint[size];   break;
        case GL_UNSIGNED_SHORT : pixels = MemoryManager_NEW GLushort[size]; break;
        case GL_BYTE           : pixels = MemoryManager_NEW GLbyte[size];   break;
        case GL_SHORT          : pixels = MemoryManager_NEW GLshort[size];  break;
        case GL_INT            : pixels = MemoryManager_NEW GLint[size];    break;
    };

    memset(pixels, 0, size * sizeOf(_dataType) );

    switch(_pbtype){
        case PB_TEXTURE_1D:
            glTexImage1D(_textureType, 0, _internalFormat, _width, 0, _format, _dataType, pixels);
            break;
        case PB_TEXTURE_2D:
            glTexImage2D(_textureType, 0, _internalFormat, _width, _height, 0, _format, _dataType, pixels);
            break;
        case PB_TEXTURE_3D:
            glTexImage3D(_textureType, 0, _internalFormat, _width, _height,_depth, 0, _format, _dataType, pixels);
            break;
    };
    MemoryManager::DELETE_ARRAY( pixels );

    glGenBuffers(1, &_pixelBufferHandle);
    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, _pixelBufferHandle);
    glBufferData(GL_PIXEL_UNPACK_BUFFER, size * sizeOf(_dataType), NULL, GL_STREAM_DRAW);

    GL_API::unbindTexture(0, _textureType);
    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    return true;
}

void glPixelBuffer::updatePixels(const GLfloat * const pixels) {
    GL_API::bindTexture(0, _textureId, _textureType);
    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, _pixelBufferHandle);
    switch(_pbtype){
        case PB_TEXTURE_1D:
            glBufferData(GL_PIXEL_UNPACK_BUFFER, (_width*4) * sizeOf(_dataType), NULL, GL_STREAM_DRAW);
            break;
        case PB_TEXTURE_2D:
            glBufferData(GL_PIXEL_UNPACK_BUFFER, (_width*_height*4) * sizeOf(_dataType), NULL, GL_STREAM_DRAW);
            break;
        case PB_TEXTURE_3D:
            glBufferData(GL_PIXEL_UNPACK_BUFFER, (_width*_height*_depth*4) * sizeOf(_dataType), NULL, GL_STREAM_DRAW);
            break;
    };

    GLfloat* ptr = (GLfloat*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
    if(ptr)	{
        memcpy(ptr, pixels, _width * _height * 4 * sizeOf(_dataType));
        glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // release the mapped buffer
    }

    GL_API::setActiveBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}

};

Commits for Divide-Framework/trunk/Source Code/Hardware/Video/OpenGL/Buffers/PixelBuffer/glPixelBuffer.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)

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)

302 Diff Diff IonutCava picture IonutCava Wed 06 Aug, 2014 22:09:55 +0000

[Ionut]
- GenericVertexData buffer size (for read/write buffering) is now configurable instead of a fixed 3x and also applies to non-persistently mapped buffers
- Moved OpenGL enum tables to Divide::GLUtil::GL_ENUM_TABLE
- More code cleanups (glResources, glError, glVertexArray, glGenericVertexData, glIMPrimitive)

293 Diff Diff k1ngp1n picture k1ngp1n Tue 29 Jul, 2014 20:01:28 +0000

[Ionut]
- Code cleanup and comments in GLFWWrapper (for starters. more to follow)
- Reworked main loop logic (no more delegates and rendering api querying)
- Replaced all GLvoid with regular void
- replaced all boost::this_thread::sleep (deprecated calls) with boost::this_thread::sleep_for

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]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

272 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 11:30:51 +0000

[Ionut] [[BR]]
- Added initial code for Forward+ rendering (grid based light culling) [[BR]]
- Simplified Light class [[BR]]
- Moved more light uniform data to ShaderBuffers [[BR]]
- Double buffered grass rendering [[BR]]
- Added a better attribute interface to GenericVertexData [[BR]]
- Fixed screenshot capture [[BR]]
- Fixed texture double-bind checks [[BR]]

268 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 10:20:27 +0000

[IonutCava] [[BR]]
- Terrain and vegetation updates: [[BR]]
— Use standard phong lighting model [[BR]]
— Separate grass patches per chunk [[BR]]
— Reduce number of required texture bind points for terrain by adding both textures and normal maps in a single texture array [[BR]]
— Draw terrain with 2 drawcalls (using glMultiDrawElements twice, once for LoD == 0 and once for LoD > 0) [[BR]]
[[BR]]
- Buffer management updates: [[BR]]
— Unified buffer binding system [[BR]]
— Made Uniform buffer objects visible to all classes and moved lightUBO to LightManager, matricesUBO to GFXDevice etc [[BR]]
— Added initial support for Shader Buffer Objects [[BR]]
— Moved viewport management to GFXDevice class [[BR]]
[[BR]]
- Rendering improvements: [[BR]]
— Added Hi-Z occlusion culling to instanceCull shader (using Hi-Z depth buffer constructed in GFXDevice class) [[BR]]
— Resolved issues with shadow maps overriding texture bind locations [[[BR]]
— Improved shader and shader program loading [[BR]]
— Improved material transparency support [[BR]]
— Added buffer lock manager class from “Approaching Zero Driver Overhead in OpenGL (Presented by NVIDIA)” speech at GDC14 [[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]]