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
198
199
200
201
202
203
#include "Headers/IMPrimitive.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Platform/Video/Textures/Headers/Texture.h"
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"

namespace Divide {

IMPrimitive::IMPrimitive(GFXDevice& context)
    : VertexDataInterface(context),
      _forceWireframe(false),
      _paused(true),
      _texture(nullptr),
      _drawShader(nullptr),
      _stateHash(0)
{
}

IMPrimitive::~IMPrimitive() 
{
    clear();
}

void IMPrimitive::clear() {
    stateHash(0);
    clearRenderStates();
    _worldMatrix.identity();
    _texture = nullptr;
    _drawShader = nullptr;
}

void IMPrimitive::fromBox(const vec3<F32>& min, const vec3<F32>& max, const vec4<U8>& colour) {
    paused(false);
    // Create the object
    beginBatch(true, 16, 1);
    // Set it's colour
    attribute4f(to_const_uint(AttribLocation::VERTEX_COLOR), Util::ToFloatColour(colour));
    // Draw the bottom loop
    begin(PrimitiveType::LINE_LOOP);
    vertex(min.x, min.y, min.z);
    vertex(max.x, min.y, min.z);
    vertex(max.x, min.y, max.z);
    vertex(min.x, min.y, max.z);
    end();
    // Draw the top loop
    begin(PrimitiveType::LINE_LOOP);
    vertex(min.x, max.y, min.z);
    vertex(max.x, max.y, min.z);
    vertex(max.x, max.y, max.z);
    vertex(min.x, max.y, max.z);
    end();
    // Connect the top to the bottom
    begin(PrimitiveType::LINES);
    vertex(min.x, min.y, min.z);
    vertex(min.x, max.y, min.z);
    vertex(max.x, min.y, min.z);
    vertex(max.x, max.y, min.z);
    vertex(max.x, min.y, max.z);
    vertex(max.x, max.y, max.z);
    vertex(min.x, min.y, max.z);
    vertex(min.x, max.y, max.z);
    end();
    // Finish our object
    endBatch();
}

void IMPrimitive::fromSphere(const vec3<F32>& center,
                             F32 radius,
                             const vec4<U8>& colour) {
    U32 slices = 8, stacks = 8;
    F32 drho = to_float(M_PI) / stacks;
    F32 dtheta = 2.0f * to_float(M_PI) / slices;
    F32 ds = 1.0f / slices;
    F32 dt = 1.0f / stacks;
    F32 t = 1.0f;
    F32 s = 0.0f;
    U32 i, j;  // Looping variables
    paused(false);
    // Create the object
    beginBatch(true, stacks * ((slices + 1) * 2), 1);
    attribute4f(to_const_uint(AttribLocation::VERTEX_COLOR), Util::ToFloatColour(colour));
    begin(PrimitiveType::LINE_LOOP);
    for (i = 0; i < stacks; i++) {
        F32 rho = i * drho;
        F32 srho = std::sin(rho);
        F32 crho = std::cos(rho);
        F32 srhodrho = std::sin(rho + drho);
        F32 crhodrho = std::cos(rho + drho);
        s = 0.0f;
        for (j = 0; j <= slices; j++) {
            F32 theta = (j == slices) ? 0.0f : j * dtheta;
            F32 stheta = -std::sin(theta);
            F32 ctheta = std::cos(theta);

            F32 x = stheta * srho;
            F32 y = ctheta * srho;
            F32 z = crho;
            vertex((x * radius) + center.x,
                (y * radius) + center.y,
                (z * radius) + center.z);
            x = stheta * srhodrho;
            y = ctheta * srhodrho;
            z = crhodrho;
            s += ds;
            vertex((x * radius) + center.x,
                (y * radius) + center.y,
                (z * radius) + center.z);
        }
        t -= dt;
    }
    end();
    endBatch();
}

void IMPrimitive::fromLines(const vectorImpl<Line>& lines) {
    fromLines(lines, vec4<I32>(), false);
}

void IMPrimitive::fromLines(const vectorImpl<Line>& lines,
                            const vec4<I32>& viewport) {
    fromLines(lines, viewport, true);
}

void IMPrimitive::fromLines(const vectorImpl<Line>& lines,
                            const vec4<I32>& viewport,
                            const bool inViewport) {
    static const vec3<F32> vertices[] = {
        vec3<F32>(-1.0f, -1.0f,  1.0f),
        vec3<F32>(1.0f, -1.0f,  1.0f),
        vec3<F32>(-1.0f,  1.0f,  1.0f),
        vec3<F32>(1.0f,  1.0f,  1.0f),
        vec3<F32>(-1.0f, -1.0f, -1.0f),
        vec3<F32>(1.0f, -1.0f, -1.0f),
        vec3<F32>(-1.0f,  1.0f, -1.0f),
        vec3<F32>(1.0f,  1.0f, -1.0f)
    };

    static const U16 indices[] = {
        0, 1, 2,
        3, 7, 1,
        5, 4, 7,
        6, 2, 4,
        0, 1
    };
    // Check if we have a valid list. The list can be programmatically
    // generated, so this check is required
    if (!lines.empty()) {
        vec4<F32> tempFloatColour;
        paused(false);
        // If we need to render it into a specific viewport, set the pre and post
        // draw functions to set up the
        // needed viewport rendering (e.g. axis lines)
        if (inViewport) {
            setRenderStates(
                [&, viewport]() {
                _context.setViewport(viewport);
            },
                [&]() {
                _context.restoreViewport();
            });
        }
        // Create the object containing all of the lines
        beginBatch(true, to_uint(lines.size()) * 2 * 14, 1);
        Util::ToFloatColour(lines[0]._colourStart, tempFloatColour);
        attribute4f(to_const_uint(AttribLocation::VERTEX_COLOR), tempFloatColour);
        // Set the mode to line rendering
        //primitive.begin(PrimitiveType::TRIANGLE_STRIP);
        begin(PrimitiveType::LINES);
        //vec3<F32> tempVertex;
        // Add every line in the list to the batch
        for (const Line& line : lines) {
            Util::ToFloatColour(line._colourStart, tempFloatColour);
            attribute4f(to_const_uint(AttribLocation::VERTEX_COLOR), tempFloatColour);
            /*for (U16 idx : indices) {
            tempVertex.set(line._startPoint * vertices[idx]);
            tempVertex *= line._widthStart;

            vertex(tempVertex);
            }*/
            vertex(line._startPoint);

            Util::ToFloatColour(line._colourEnd, tempFloatColour);
            attribute4f(to_const_uint(AttribLocation::VERTEX_COLOR), tempFloatColour);
            /*for (U16 idx : indices) {
            tempVertex.set(line._endPoint * vertices[idx]);
            tempVertex *= line._widthEnd;

            vertex(tempVertex);
            }*/

            vertex(line._endPoint);

        }
        end();
        // Finish our object
        endBatch();
    }
}

void IMPrimitive::drawShader(const ShaderProgram_ptr& shaderProgram) {
    _drawShader = shaderProgram;
}

};

Commits for Divide-Framework/trunk/Source Code/Platform/Video/IMPrimitive.cpp

Diff revisions: vs.
Revision Author Commited Message
777 Diff Diff IonutCava picture IonutCava Fri 07 Oct, 2016 16:14:48 +0000

[IonutCava]
- Continue to implement CommandBuffer / RenderPass / RenderSubPass system.
— Rendering artefacts are still present.

776 Diff Diff IonutCava picture IonutCava Thu 06 Oct, 2016 15:57:56 +0000

[IonutCava]
- Improve the CommandBuffer system to include the notion of a RenderPass /RenderSubPass with output render target info stored in them (not used yet)

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

720 Diff Diff IonutCava picture IonutCava Mon 06 Jun, 2016 15:51:06 +0000

[IonutCava]
- PVS-Studio guided static analysis fixes and optimizations
- Added a flag to SceneState to bypass the Save/Load system not needed for certain types of scenes (menus, cinematics, etc)

718 Diff Diff IonutCava picture IonutCava Thu 02 Jun, 2016 16:02:48 +0000

[IonutCava]
- Code cleanup:
— Rename Framebuffer to RenderTarget. Only OpenGL uses the Framebuffer nomenclature.
— Remove base Shader class as only OpenGL will have separate shaders (and eventually move to pipeline objects) as Direct3D uses FX files and may end up with different structure
— Remove drawBox3D, drawSphere3D and drawLines from GFXDevice class and add them as member functions to the IMPrimitive class (renamed to fromXYZ)
— Pull some elements from SceneManager and move them to standalone classes (W.I.P.)

591 Diff Diff IonutCava picture IonutCava Wed 02 Dec, 2015 17:17:23 +0000

[IonutCava]
- More work on the ForwardPlus renderer
- Singleton cleanup
- First steps for reducing scope of GFXDevice class

450 Diff Diff IonutCava picture IonutCava Wed 27 May, 2015 16:06:41 +0000

[Ionut]
- Window size != game resolution
- Always draw to a render target and always load PostFX data.
— PostFX enable/disable toggles batch processing on and off
- Added a resize method to textures that allows texture dimension changes without creating new resources

439 Diff Diff IonutCava picture IonutCava Sun 17 May, 2015 21:18:15 +0000

[Ionut]
- Added start and end color options to the Line structure
- Changed the root node’s BB calculation algorithm
- Improved IMInterface garbage collection
- Simplified hacky scene line rendering system

436 Diff Diff IonutCava picture IonutCava Thu 14 May, 2015 16:09:08 +0000

[Ionut]
- Initial cleanup of RenderStateBlock and RenderStateBlockDescriptor classes
- lineWith is now part of the render state and as such, must be explicitly set in the state hash
— This affects all IMPrimitives, especially those rendered via drawBox3D and drawLines

403 IonutCava picture IonutCava Fri 17 Apr, 2015 16:06:14 +0000

[Ionut]
- Improved the DSA wrapper
- Improved IMPrimitive debugging info
- Added sync objects for multi-threaded texture and shader loading
- Cleaned up the animation system a bit:
— Still to do: Create skeleton per sub-mesh starting from the sub meshes' parent node instead of the root scene node. SubMeshes should not have identical skeletons but only the skeletons for their own geometry!