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
207
208
209
210
211
212
213
214
215
216
#include "Headers/ImageTools.h"
#include "Hardware/Video/Headers/RenderAPIEnums.h"

#define IL_STATIC_LIB
#undef _UNICODE
#include <IL/il.h>
#include <IL/ilu.h>

namespace Divide {
namespace ImageTools {
	inline GFXImageFormat textureFormatDevIL(ILint format)
	{
		switch(format)	{
			case IL_RGB   : return RGB;
			case IL_ALPHA : return ALPHA;
			case IL_RGBA  : return RGBA;
			case IL_BGR   : return BGR;
			case IL_BGRA  : return BGRA;
			case IL_LUMINANCE : return LUMINANCE;
			case IL_LUMINANCE_ALPHA : return LUMINANCE_ALPHA;
		};

		return RGB;
	}

	void initialize() {
		// used to play nice with DevIL (DevIL acts like OpenGL - a state machine)
		static bool first = true;
		if(!first)
			return;

		first = false;
		ilInit();
		ilEnable(IL_TYPE_SET);
		ilTypeFunc(IL_UNSIGNED_BYTE);
	}

	void ImageData::throwLoadError(const stringImpl& fileName){
		ERROR_FN(Locale::get("ERROR_IMAGETOOLS_INVALID_IMAGE_FILE"),fileName.c_str());
		ILenum error;
		while((error = ilGetError()) != IL_NO_ERROR) {
			ERROR_FN(Locale::get("ERROR_IMAGETOOLS_DEVIL"), iluErrorString(error));
		}

		ilDeleteImage(_ilTexture);
		_ilTexture = 0;
	}

	bool ImageData::prepareInternalData() {
		initialize();

		ilOriginFunc(_flip ? IL_ORIGIN_LOWER_LEFT : IL_ORIGIN_UPPER_LEFT);
		ilEnable(IL_ORIGIN_SET);
		ilGenImages(1, &_ilTexture);
		ilBindImage(_ilTexture);
		return true;
	}

	bool ImageData::setInternalData() {
		DIVIDE_ASSERT(ilGetInteger(IL_CUR_IMAGE) != 0, "INVALID IMAGE FILE TARGET FOR INTERNAL DATA UPDATE!");
		_dimensions.set(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT));
		_bpp    = ilGetInteger(IL_IMAGE_BPP);
		ILint format = ilGetInteger(IL_IMAGE_FORMAT);

		// we determine the target format and use a flag to determine if we should convert or not
		ILint targetFormat = format;

		switch(format){
			//palette types
			case IL_COLOR_INDEX: {
				switch(ilGetInteger(IL_PALETTE_TYPE)) {
					default:
					case IL_PAL_NONE: {
						throwLoadError(_name);
						return false;
					}
					case IL_PAL_RGB24:
					case IL_PAL_RGB32:
					case IL_PAL_BGR24:
					case IL_PAL_BGR32:  targetFormat = IL_RGB;  break;
					case IL_PAL_BGRA32:
					case IL_PAL_RGBA32:	targetFormat = IL_RGBA; break;
				}
			} break;
			case IL_BGRA: targetFormat = IL_RGBA; break;
			case IL_BGR:  targetFormat = IL_RGB; break;
		}

		// if the image's format is not desired or the image's data type is not in unsigned byte format, we should convert it
		if(format != targetFormat || (ilGetInteger(IL_IMAGE_TYPE) != IL_UNSIGNED_BYTE)){
			if(ilConvertImage(targetFormat, IL_UNSIGNED_BYTE) != IL_TRUE){
				throwLoadError(_name);
				return false;
			}
			format = targetFormat;
		}

		// most formats do not have an alpha channel
		_alpha = (format == IL_RGBA || format == IL_LUMINANCE_ALPHA || format == IL_ALPHA);
		_format = textureFormatDevIL(format);
		_imageSize = (size_t)(_dimensions.width) * (size_t)(_dimensions.height) * (size_t)(_bpp);

        _data = MemoryManager_NEW U8[_imageSize];
        memcpy(_data, ilGetData(), _imageSize);

		ilBindImage(0);
		return true;
	}

	bool ImageData::create(const void* ptr, U32 size) {
		WriteLock w_lock(_loadingMutex);
		prepareInternalData();
		_name = "[buffer offset file]";
		if (ilLoadL(IL_TYPE_UNKNOWN, ptr, size) == IL_FALSE)	{
			throwLoadError(_name);
			return false;
		}

		return setInternalData();
	}

	bool ImageData::create(const stringImpl& filename) {
		WriteLock w_lock(_loadingMutex);
		prepareInternalData();
		_name = filename;
		if (ilLoadImage(filename.c_str()) == IL_FALSE)	{
			throwLoadError(_name);
			return false;
		}

		return setInternalData();
	}

    void ImageData::destroy() {
        ilDeleteImage( _ilTexture );
		_ilTexture = 0;
        MemoryManager::DELETE_ARRAY( _data );
    }

	vec4<U8> ImageData::getColor(U16 x, U16 y) const {
		I32 idx = (y * _dimensions.width + x) * _bpp;
        return vec4<U8>(_data[idx + 0], _data[idx + 1], _data[idx + 2], _alpha ? _data[idx + 3] : 255);
	}

	void ImageData::resize(U16 width, U16 height) {
		ilBindImage(_ilTexture);
		iluImageParameter(ILU_FILTER,ILU_SCALE_BELL);
		iluScale(width,height,_bpp);
		_dimensions.set(width,height);
		ilBindImage(0);
	}

	I8 SaveToTGA(const char *filename, const vec2<U16>& dimensions, U8 pixelDepth, U8 *imageData) {
		U8 cGarbage = 0, type,mode,aux;
		I16 iGarbage = 0;
		U16 width = dimensions.width;
		U16 height = dimensions.height;

		// open file and check for errors
		FILE *file = fopen(filename, "wb");
		if (file == nullptr) {
			return(-1);
		}

		// compute image type: 2 for RGB(A), 3 for greyscale
		mode = pixelDepth / 8;
		type = ((pixelDepth == 24) || (pixelDepth == 32)) ?  2 : 3;

		// write the header
		fwrite(&cGarbage, sizeof(U8), 1, file);
		fwrite(&cGarbage, sizeof(U8), 1, file);
		fwrite(&type,     sizeof(U8), 1, file);

		fwrite(&iGarbage, sizeof(I16), 1, file);
		fwrite(&iGarbage, sizeof(I16), 1, file);
		fwrite(&cGarbage, sizeof(U8),  1, file);
		fwrite(&iGarbage, sizeof(I16), 1, file);
		fwrite(&iGarbage, sizeof(I16), 1, file);

		fwrite(&width,      sizeof(U16), 1, file);
		fwrite(&height,     sizeof(U16), 1, file);
		fwrite(&pixelDepth, sizeof(U8),  1, file);
		fwrite(&cGarbage,   sizeof(U8),  1, file);

		// convert the image data from RGB(a) to BGR(A)
		if (mode >= 3)
		for (I32 i=0; i < width * height * mode ; i+= mode) {
			aux = imageData[i];
			imageData[i] = imageData[i+2];
			imageData[i+2] = aux;
		}

		// save the image data
		fwrite(imageData, sizeof(U8), width * height * mode, file);
		fclose(file);
		return 0;
	}

	/// saves a series of files with names "filenameX.tga"
	I8 SaveSeries(char *filename, const vec2<U16>& dimensions, U8 pixelDepth, U8 *imageData) {
		static I32 savedImages = 0;
        stringImpl newFilename(filename);
		// compute the new filename by adding the
		// series number and the extension
		newFilename.append(stringAlg::toBase(Util::toString(savedImages) + ".tga"));

		// save the image
		I8 status = SaveToTGA(newFilename.c_str(),dimensions,pixelDepth,imageData);

		//increase the counter
		if (status == 0) savedImages++;

		return status;
	}
}; //namespace ImageTools
}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Utility/ImageTools.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)

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

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)

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)

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

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

249 k1ngp1n picture k1ngp1n Mon 31 Mar, 2014 20:42:31 +0000

[Ionut] [[BR]]
- Migrated to platform toolset v100 [[BR]]
- Updated boost to 1.55 [[BR]]
- Moved from “NULL” to “nullptr” [[BR]]
- DevIL is now linked dynamically [[BR]]