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
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _SPHERE_3D_H_
#define _SPHERE_3D_H_

#include "Geometry/Shapes/Headers/Object3D.h"
#include "Platform/Video/Buffers/VertexBuffer/Headers/VertexBuffer.h"

namespace Divide {

class Sphere3D : public Object3D {
   public:
    /// Change resolution to affect the spacing between vertices
    explicit Sphere3D(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, F32 radius, U32 resolution)
        : Object3D(context, parentCache, descriptorHash, name, ObjectType::SPHERE_3D, ObjectFlag::OBJECT_FLAG_NONE),
          _radius(radius),
          _resolution(resolution)
    {
        _vertexCount = resolution * resolution;
        getGeometryVB()->setVertexCount(_vertexCount);
        getGeometryVB()->reserveIndexCount(_vertexCount);
        if (_vertexCount + 1 > std::numeric_limits<U16>::max()) {
            getGeometryVB()->useLargeIndices(true);
        }
        rebuild();
    }

    virtual ~Sphere3D() {}
    inline F32 getRadius() { return _radius; }
    inline U32 getResolution() { return _resolution; }
    inline void setRadius(F32 radius) {
        _radius = radius;
        _geometryDirty = true;
    }

    inline void setResolution(U32 resolution) {
        _resolution = resolution;
        _geometryDirty = true;
    }

   private:
    // SuperBible stuff
    void rebuildVB() override {
        U32 slices = _resolution;
        U32 stacks = _resolution;

        VertexBuffer* const vb = getGeometryVB();

        vb->reset();
        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
        U32 index = 0;  /// for the index buffer

        vb->setVertexCount(stacks * ((slices + 1) * 2));

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

            // Many sources of OpenGL sphere drawing code uses a triangle fan
            // for the caps of the sphere. This however introduces texturing
            // artifacts at the poles on some OpenGL implementations
            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;

                vb->modifyPositionValue(index, x * _radius, y * _radius, z * _radius);
                vb->modifyTexCoordValue(index, s, t);
                vb->modifyNormalValue(index, x, y, z);
                vb->addIndex(index++);

                x = stheta * srhodrho;
                y = ctheta * srhodrho;
                z = crhodrho;
                s += ds;

                vb->modifyPositionValue(index, x * _radius, y * _radius, z * _radius);
                vb->modifyTexCoordValue(index, s, t - dt);
                vb->modifyNormalValue(index, x, y, z);
                vb->addIndex(index++);
            }
            t -= dt;
        }

        vb->create();
        vb->queueRefresh();
        setFlag(UpdateFlag::BOUNDS_CHANGED);
    }

    inline void updateBoundsInternal(SceneGraphNode& sgn) override {
        // add some depth padding for collision and nav meshes
        _boundingBox.set(vec3<F32>(-_radius), vec3<F32>(_radius));
        Object3D::updateBoundsInternal(sgn);
    }

   protected:
    F32 _radius;
    U32 _resolution;
    U32 _vertexCount;
};

TYPEDEF_SMART_POINTERS_FOR_CLASS(Sphere3D);

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Geometry/Shapes/Headers/Predefined/Sphere3D.h

Diff revisions: vs.
Revision Author Commited Message
949 Diff Diff IonutCava picture IonutCava Thu 19 Oct, 2017 21:48:37 +0000

[Ionut]
- More command buffer refactoring

948 Diff Diff IonutCava picture IonutCava Tue 17 Oct, 2017 22:41:09 +0000

[Ionut]
- Move rendering data caching outside of CommandBuffer and into RenderPackage for better control.

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.

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

851 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 23:38:14 +0000

[IonutCava]
- Replaced most RenderStage params with RenderStagePass types
- More work on water rendering

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
773 Diff Diff IonutCava picture IonutCava Tue 04 Oct, 2016 15:53:18 +0000

[IonutCava]
- Split GenericDrawCommand gathering system into Init/Update to facilitate future threading support
- Fix drawCount() == 0 case in submitRenderCommand
- Make _cameraPool (more) threadsafe

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

705 IonutCava picture IonutCava Thu 12 May, 2016 20:27:20 +0000

[IonutCava]
- Decouple asset loading from the active scene
— completely remove GET_ACTIVE_SCENE() method