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
204
205
206
/*
   Copyright (c) 2014 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 CORE_H_
#define CORE_H_

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory>
#include <malloc.h>
#include <time.h>

#include "Hardware/Platform/Headers/PlatformDefines.h" //For data types
#include "Hardware/Platform/Headers/SharedMutex.h"     //For multi-threading
#include "Core/Math/Headers/MathClasses.h"     //For math classes (mat3,mat4,vec2,vec3,vec4 etc)
#include "Core/Headers/ApplicationTimer.h"       //For time management
#include "Core/Headers/Console.h"              //For printing to the standard output
#include "Utility/Headers/Localization.h"      //For language parsing

namespace Divide {

#ifdef _DEBUG
#define STUBBED(x) \
do {\
    static bool seen_this = false;\
    if(!seen_this){\
        seen_this = true; \
        ERROR_FN("STUBBED: %s (%s : %d)\n", \
                 x, __FILE__, __LINE__); \
    }\
} while (0);

#else
#define STUBBED(x)
#endif

//Helper method to emulate GLSL
inline F32 fract(F32 floatValue){  return (F32)fmod(floatValue, 1.0f); }
///Packs a floating point value into the [0...255] range (thx sqrt[-1] of opengl.org forums)
inline U8 PACK_FLOAT(F32 floatValue){
    //Scale and bias
  floatValue = (floatValue + 1.0f) * 0.5f;
  return (U8)(floatValue*255.0f);
}
//Pack 3 values into 1 float
inline F32 PACK_FLOAT(U8 x, U8 y, U8 z) {
  U32 packedColor = (x << 16) | (y << 8) | z;
  F32 packedFloat = (F32) ( ((D32)packedColor) / ((D32) (1 << 24)) );
   return packedFloat;
}

//UnPack 3 values from 1 float
inline void UNPACK_FLOAT(F32 src, F32& r, F32& g, F32& b){
  r = fract(src);
  g = fract(src * 256.0f);
  b = fract(src * 65536.0f);

  //Unpack to the -1..1 range
  r = (r * 2.0f) - 1.0f;
  g = (g * 2.0f) - 1.0f;
  b = (b * 2.0f) - 1.0f;
}

enum ErrorCode {
    NO_ERR = 0,
    MISSING_SCENE_DATA = -1,
    MISSING_SCENE_LOAD_CALL = -2,
	GFX_NOT_SUPPORTED = -3,
	GFX_NON_SPECIFIED = -4,
    GLFW_INIT_ERROR = -5,
    GLFW_WINDOW_INIT_ERROR = -6,
    GLEW_INIT_ERROR = -7,
    GLEW_OLD_HARDWARE = -8,
    DX_INIT_ERROR = -9,
    DX_OLD_HARDWARE = -10,
    SDL_AUDIO_INIT_ERROR = -11,
    SDL_AUDIO_MIX_INIT_ERROR = -12,
    FMOD_AUDIO_INIT_ERROR = -13,
    OAL_INIT_ERROR = -14,
    PHYSX_INIT_ERROR = -15,
    PHYSX_EXTENSION_ERROR = -16,
    NO_LANGUAGE_INI = -17
};

inline const char* getErrorCodeName(ErrorCode code) {
    switch (code) {
        default:
        case NO_ERR : {
            return "Unknown error";
        };
        case MISSING_SCENE_DATA : {
            return "Invalid Scene Data. SceneManager failed to load the specified scene";
        };
        case MISSING_SCENE_LOAD_CALL : {
            return "The specified scene failed to load all of its data properly";
        };
		case  GFX_NOT_SUPPORTED : {
			return "The specified rendering API is not fully implemented and as such, it's not supported";
		};
		case GFX_NON_SPECIFIED: {
			return "No rendering API specified before trying to initialize the GFX Device";
		};
        case GLFW_INIT_ERROR : {
            return "GLFW system failed to initialize";
        };
        case GLFW_WINDOW_INIT_ERROR : {
            return "GLFW failed to create a valid window";
        };
        case GLEW_INIT_ERROR : {
            return "GLEW failed to initialize";
        };
        case GLEW_OLD_HARDWARE : {
            return "Current hardware does not support the minimum OpenGL features required";
        };
        case DX_INIT_ERROR : {
            return "DirectX API failed to initialize";
        };
        case DX_OLD_HARDWARE : {
            return "Current hardware does not support the minimum DirectX features required";
        };
        case SDL_AUDIO_INIT_ERROR : {
            return "SDL Audio library failed to initialize";
        };
        case SDL_AUDIO_MIX_INIT_ERROR : {
            return "SDL Audio Mixer failed to initialize";
        };
        case FMOD_AUDIO_INIT_ERROR : {
            return "FMod Audio library failed to initialize";
        };
        case OAL_INIT_ERROR : {
            return "OpenAL failed to initialize";
        };
        case PHYSX_INIT_ERROR : {
            return "The PhysX library failed to initialize";
        };
        case PHYSX_EXTENSION_ERROR: {
            return "The PhysX library failed to load the required extensions";
        };
        case NO_LANGUAGE_INI : {
            return "Invalid language file";
        };
    };
}

namespace DefaultColors {
    ///Random stuff added for convenience
    inline vec4<F32> WHITE() { 
        return vec4<F32>(1.0f,1.0f,1.0f,1.0f); 
    }

    inline vec4<F32> BLACK() { 
        return vec4<F32>(0.0f,0.0f,0.0f,1.0f);
    }

    inline vec4<F32> RED()   { 
        return vec4<F32>(1.0f,0.0f,0.0f,1.0f);
    }

    inline vec4<F32> GREEN() { 
        return vec4<F32>(0.0f,1.0f,0.0f,1.0f); 
    }

    inline vec4<F32> BLUE()  { 
        return vec4<F32>(0.0f,0.0f,1.0f,1.0f);
    }

    inline vec4<F32> DIVIDE_BLUE() { 
        return vec4<F32>(0.1f,0.1f,0.8f,1.0f);
    }

    inline vec4<U8> RANDOM() {
        return vec4<U8>(rand() % 256,
                        rand() % 256,
                        rand() % 256,
                        255);
    }
    
    inline vec4<F32> RANDOM_NORMALIZED() {
        return Util::toFloatColor(RANDOM());
    }
};

}; //namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/core.h

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)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

323 Diff Diff IonutCava picture IonutCava Thu 11 Sep, 2014 20:58:50 +0000

[Ionut]
- Reworked GFXDevice API initialization system
- Added a separate map for boolean values in ParamHandler
- More cleanups in GFXDevice class
- Fixed an infinite loop issue in Task class

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

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)

314 Diff Diff IonutCava picture IonutCava Sun 24 Aug, 2014 19:54:33 +0000

[Ionut]
- More AI work
- Added some needed audio dlls

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

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

248 k1ngp1n picture k1ngp1n Mon 24 Feb, 2014 22:35:21 +0000

[Ionut][[BR]]
- Added a GenericVertexData class that can be used to fill VBOs with generic data and upload it to the GPU (and render it, either direct or instanced) [[BR]]
- Added a basic (soft) particle system [[BR]]
- Reworked memory allocation logging [[BR]]
- Improved transparency detection for textures on load [[BR]]