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
#include "stdafx.h"

#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),
      _primitivesGenerated(0)
{
}

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

void IMPrimitive::clear() {
    clearRenderStates();
    _worldMatrix.identity();
    _texture = 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_base(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_F32(M_PI) / stacks;
    F32 dtheta = 2.0f * to_F32(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_base(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_U32(lines.size()) * 2 * 14, 1);
        Util::ToFloatColour(lines[0]._colourStart, tempFloatColour);
        attribute4f(to_base(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_base(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_base(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::pipeline(const Pipeline& pipeline) {
    _pipeline = pipeline;
}

};

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

Diff revisions: vs.
Revision Author Commited Message
893 Diff Diff IonutCava picture IonutCava Sun 18 Jun, 2017 17:33:07 +0000

[Ionut]
- Initial implementation of a PipelineStateObject (holds shader program, rasterizer state, etc)
- Rework PCH implementation a bit because VS2017 no longer has a /ZM option

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

882 Diff Diff IonutCava picture IonutCava Thu 23 Mar, 2017 16:49:48 +0000

[IonutCava]
- More work on tessellated terrain rendering: got the mesh to render properly and match the collision mesh’s layout.
- Fixed a bug with GenericDrawCommand RenderOptions
- Added a “query number of generated primitives” option to GenericDrawCommand

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

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 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.)