Merge lp:~unity-team/nux/nux.gpudevice-cleanup into lp:nux
- nux.gpudevice-cleanup
- Merge into trunk
Proposed by
Jay Taoko
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Michi Henning | ||||
Approved revision: | 677 | ||||
Merged at revision: | 676 | ||||
Proposed branch: | lp:~unity-team/nux/nux.gpudevice-cleanup | ||||
Merge into: | lp:nux | ||||
Diff against target: |
1259 lines (+267/-229) 18 files modified
Nux/Theme.cpp (+20/-17) NuxCore/FileIO.cpp (+9/-9) NuxCore/FileIO.h (+3/-3) NuxGraphics/FontRenderer.cpp (+2/-2) NuxGraphics/GLError.cpp (+2/-0) NuxGraphics/GLRenderStates.cpp (+2/-2) NuxGraphics/GLRenderStates.h (+9/-9) NuxGraphics/GLShaderParameter.h (+2/-2) NuxGraphics/GpuDevice.cpp (+114/-75) NuxGraphics/GpuDevice.h (+22/-32) NuxGraphics/GpuDeviceVertex.cpp (+1/-1) NuxGraphics/GraphicsEngine.cpp (+1/-1) NuxGraphics/GraphicsEngine.h (+3/-3) NuxGraphics/IOpenGLAsmShader.cpp (+9/-9) NuxGraphics/IOpenGLAsmShader.h (+2/-2) NuxGraphics/IOpenGLCgShader.h (+6/-6) NuxGraphics/IOpenGLGLSLShader.cpp (+51/-47) NuxGraphics/IOpenGLGLSLShader.h (+9/-9) |
||||
To merge this branch: | bzr merge lp:~unity-team/nux/nux.gpudevice-cleanup | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nicolas d'Offay (community) | Approve | ||
Eleni Maria Stea (community) | Approve | ||
Michi Henning (community) | Approve | ||
Review via email: mp+127168@code.launchpad.net |
Commit message
* Removing instances of NString.
* Fixed integer to pointer convertion in GpuDevice:
* Fixed bug in Them.cpp: Check that a pointer is NULL before calling UnReference.
* Use proper member variables naming.
* GpuDevice: Changed code for detection of OpenGL minor and minor version.
Description of the change
* Removing instances of NString.
* Fixed integer to pointer convertion in GpuDevice:
* Fixed bug in Them.cpp: Check that a pointer is NULL before calling UnReference.
* Use proper member variables naming.
* GpuDevice: Changed code for detection of OpenGL minor and minor version.
To post a comment you must log in.
Revision history for this message
Michi Henning (michihenning) wrote : | # |
This also fixes Bug #1052765
Revision history for this message
Nicolas d'Offay (nicolas-doffay) wrote : | # |
Looks good to land from here.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Nux/Theme.cpp' |
2 | --- Nux/Theme.cpp 2012-09-26 12:23:04 +0000 |
3 | +++ Nux/Theme.cpp 2012-09-30 17:24:22 +0000 |
4 | @@ -151,7 +151,10 @@ |
5 | std::list<PainterImage*>::iterator it; |
6 | for (it = painter_image_list_.begin(); it != painter_image_list_.end(); it++) |
7 | { |
8 | - (*it)->texture->UnReference(); |
9 | + if ((*it)->texture) |
10 | + { |
11 | + (*it)->texture->UnReference(); |
12 | + } |
13 | delete(*it); |
14 | } |
15 | painter_image_list_.clear(); |
16 | @@ -204,8 +207,8 @@ |
17 | { |
18 | BaseTexture* device_texture; |
19 | |
20 | - NString texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(*value_cursor); |
21 | - device_texture = theme->Load2DTextureFile(texture_filename.GetTCharPtr()); |
22 | + std::string texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(*value_cursor); |
23 | + device_texture = theme->Load2DTextureFile(texture_filename.c_str()); |
24 | |
25 | pimage->texture = device_texture; |
26 | } |
27 | @@ -228,8 +231,8 @@ |
28 | |
29 | void UXTheme::LoadPainterImages() |
30 | { |
31 | - NString file_search = "Painter.xml"; |
32 | - NString painter_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(file_search.GetTCharPtr()); |
33 | + std::string file_search = "Painter.xml"; |
34 | + std::string painter_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(file_search.c_str()); |
35 | |
36 | if (painter_filename == "") |
37 | { |
38 | @@ -253,10 +256,10 @@ |
39 | this, |
40 | NULL); |
41 | |
42 | - NString str; |
43 | - LoadFileToString(str, painter_filename.GetTCharPtr()); |
44 | + std::string str; |
45 | + LoadFileToString(str, painter_filename.c_str()); |
46 | |
47 | - if (g_markup_parse_context_parse(context, str.GetTCharPtr(), str.Length(), NULL) == FALSE) |
48 | + if (g_markup_parse_context_parse(context, str.c_str(), str.length(), NULL) == FALSE) |
49 | { |
50 | nuxCriticalMsg("[GraphicsEngine::LoadPainterImages] Failed to parse data."); |
51 | return; |
52 | @@ -264,7 +267,7 @@ |
53 | |
54 | #else |
55 | |
56 | - TiXmlDocument doc(painter_filename.GetTCharPtr()); |
57 | + TiXmlDocument doc(painter_filename.c_str()); |
58 | doc.LoadFile(); |
59 | |
60 | TiXmlHandle docHandle( &doc ); |
61 | @@ -273,12 +276,12 @@ |
62 | |
63 | for (image = data->FirstChildElement(TCHARToUTF8("Image")); image; image = image->NextSiblingElement(TCHARToUTF8("Image"))) |
64 | { |
65 | - PainterImage *pimage = new PainterImage; |
66 | + PainterImage* pimage = new PainterImage; |
67 | Memset(pimage, 0, sizeof(PainterImage)); |
68 | |
69 | - NString style = image->Attribute(TCHARToUTF8("style")); |
70 | + std::string style = image->Attribute(TCHARToUTF8("style")); |
71 | |
72 | - pimage->style = GetStyleImageRef(style.GetTCharPtr()); |
73 | + pimage->style = GetStyleImageRef(style.c_str()); |
74 | |
75 | // If the attributes border_left, border_right, border_top, border_bottom are not present, assume they are equal to 0; |
76 | pimage->border_left = pimage->border_right = pimage->border_top = pimage->border_bottom = 0; |
77 | @@ -309,16 +312,16 @@ |
78 | |
79 | if (1) |
80 | { |
81 | - NString filename = image->Attribute(TCHARToUTF8("Name")); |
82 | - NString texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.GetTCharPtr()); |
83 | + std::string filename = image->Attribute(TCHARToUTF8("Name")); |
84 | + std::string texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.c_str()); |
85 | pimage->texture = 0; |
86 | pimage->filename = texture_filename; |
87 | } |
88 | else |
89 | { |
90 | - NString filename = image->Attribute(TCHARToUTF8("Name")); |
91 | - NString texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.GetTCharPtr()); |
92 | - pimage->texture = Load2DTextureFile(texture_filename.GetTCharPtr()); |
93 | + std::string filename = image->Attribute(TCHARToUTF8("Name")); |
94 | + std::string texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.c_str()); |
95 | + pimage->texture = Load2DTextureFile(texture_filename.c_str()); |
96 | } |
97 | |
98 | painter_image_list_.push_back(pimage); |
99 | |
100 | === modified file 'NuxCore/FileIO.cpp' |
101 | --- NuxCore/FileIO.cpp 2011-10-21 22:06:35 +0000 |
102 | +++ NuxCore/FileIO.cpp 2012-09-30 17:24:22 +0000 |
103 | @@ -229,10 +229,10 @@ |
104 | } |
105 | |
106 | /*! |
107 | - Load a text file to an NString. The file maybe ANSI or Unicode. |
108 | + Load a text file to an std::string. The file maybe ANSI or Unicode. |
109 | The resulting string is TCHAR. |
110 | */ |
111 | - bool LoadFileToString ( NString &Result, const TCHAR *Filename, NFileManager &FileManager ) |
112 | + bool LoadFileToString(std::string &Result, const TCHAR *Filename, NFileManager &FileManager) |
113 | { |
114 | NSerializer *Reader = FileManager.CreateFileReader (Filename); |
115 | |
116 | @@ -318,9 +318,9 @@ |
117 | /*! |
118 | Save string to File. Attempt to write it as ASCII if possible. If not write as UTF16-BE. |
119 | */ |
120 | - bool SaveStringToFile ( const NString &String, const TCHAR *Filename, NFileManager &FileManager ) |
121 | + bool SaveStringToFile(const std::string &String, const TCHAR *Filename, NFileManager &FileManager) |
122 | { |
123 | - if ( !String.Length() ) |
124 | + if ( !String.length() ) |
125 | return 0; |
126 | |
127 | NSerializer *Ar = FileManager.CreateFileWriter ( Filename ); |
128 | @@ -347,20 +347,20 @@ |
129 | |
130 | if ( SaveAsUnicode || (sizeof (TCHAR) == 1) ) |
131 | { |
132 | - unsigned int s = (unsigned int) String.Length() * sizeof (TCHAR); |
133 | - Ar->Serialize ( NUX_CONST_CAST (TCHAR *, String.GetTCharPtr() ), (unsigned int) s); |
134 | + unsigned int s = (unsigned int) String.length() * sizeof (TCHAR); |
135 | + Ar->Serialize(NUX_CONST_CAST(TCHAR *, String.c_str()), (unsigned int) s); |
136 | } |
137 | else |
138 | { |
139 | - unsigned int s = (unsigned int) String.Length(); |
140 | + unsigned int s = (unsigned int) String.length(); |
141 | std::vector<ANSICHAR> AnsiBuffer ( (unsigned int) s); |
142 | |
143 | // Cast all character down from UTF16 to ANSI |
144 | - for (unsigned int i = 0; i < (unsigned int) String.Length(); i++ ) |
145 | + for (unsigned int i = 0; i < (unsigned int) String.length(); i++) |
146 | AnsiBuffer[i] = ConvertTCHARToAnsiChar ( (unsigned int) String[i]); |
147 | |
148 | // serialize |
149 | - s = (unsigned int) String.Length(); |
150 | + s = (unsigned int) String.length(); |
151 | Ar->Serialize ( NUX_CONST_CAST (ANSICHAR *, &AnsiBuffer[0]), s); |
152 | } |
153 | |
154 | |
155 | === modified file 'NuxCore/FileIO.h' |
156 | --- NuxCore/FileIO.h 2011-04-06 21:54:09 +0000 |
157 | +++ NuxCore/FileIO.h 2012-09-30 17:24:22 +0000 |
158 | @@ -29,9 +29,9 @@ |
159 | bool LoadFileToArray ( std::vector<BYTE>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
160 | bool LoadTextFileToAnsiArray ( std::vector<ANSICHAR>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
161 | bool LoadTextFileToUnicodeArray ( std::vector<UNICHAR>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
162 | - bool LoadFileToString ( NString &Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
163 | - bool SaveArrayToFile ( const std::vector<BYTE>& Array, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
164 | - bool SaveStringToFile ( const NString &String, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
165 | + bool LoadFileToString(std::string &Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
166 | + bool SaveArrayToFile(const std::vector<BYTE>& Array, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
167 | + bool SaveStringToFile(const std::string &String, const TCHAR *Filename, NFileManager &FileManager = GFileManager ); |
168 | |
169 | } |
170 | |
171 | |
172 | === modified file 'NuxGraphics/FontRenderer.cpp' |
173 | --- NuxGraphics/FontRenderer.cpp 2012-08-27 09:09:21 +0000 |
174 | +++ NuxGraphics/FontRenderer.cpp 2012-09-30 17:24:22 +0000 |
175 | @@ -179,7 +179,7 @@ |
176 | if (NumCharacter == 0) |
177 | NumChar = str_len; |
178 | else |
179 | - NumChar = std::min(str_len, NumCharacter); |
180 | + NumChar = std::min<int>(str_len, NumCharacter); |
181 | |
182 | strBBox.width = Font->GetStringWidth(str, NumChar); |
183 | strBBox.height = Font->GetLineHeight(); |
184 | @@ -323,7 +323,7 @@ |
185 | nuxAssertMsg(StartCharacter >= 0, "[FontRenderer::RenderText] Incorrect value for StartCharacter."); |
186 | nuxAssertMsg(StartCharacter <= StrLength, "[FontRenderer::RenderText] Incorrect value for StartCharacter."); |
187 | |
188 | - int NumCharToDraw = std::min(StrLength - StartCharacter, NumCharacters); |
189 | + int NumCharToDraw = std::min<int>(StrLength - StartCharacter, NumCharacters); |
190 | |
191 | if (NumCharToDraw <= 0) |
192 | return 0; |
193 | |
194 | === modified file 'NuxGraphics/GLError.cpp' |
195 | --- NuxGraphics/GLError.cpp 2012-09-17 09:55:43 +0000 |
196 | +++ NuxGraphics/GLError.cpp 2012-09-30 17:24:22 +0000 |
197 | @@ -83,8 +83,10 @@ |
198 | if (logger.IsWarningEnabled() && !error_msg.empty()) |
199 | { |
200 | std::string stacktrace; |
201 | +#if defined(NUX_OS_LINUX) |
202 | if (debug_glerror_stack()) |
203 | stacktrace = "\n" + logging::Backtrace(); |
204 | +#endif |
205 | logging::LogStream(logging::Warning, logger.module(), file, line).stream() |
206 | #ifndef NUX_OPENGLES_20 |
207 | << "[CheckGLError] OpenGL Error " << glErr << " (" << gluErrorString(glErr) << ")" |
208 | |
209 | === modified file 'NuxGraphics/GLRenderStates.cpp' |
210 | --- NuxGraphics/GLRenderStates.cpp 2012-02-21 06:57:05 +0000 |
211 | +++ NuxGraphics/GLRenderStates.cpp 2012-09-30 17:24:22 +0000 |
212 | @@ -113,8 +113,8 @@ |
213 | |
214 | GpuRenderStates::GpuRenderStates(GpuBrand board, GpuInfo* info) |
215 | { |
216 | - _gpu_brand = board; |
217 | - _gpu_info = info; |
218 | + gpu_brand_ = board; |
219 | + gpu_info_ = info; |
220 | Memcpy(&render_state_changes_, &s_StateLUT.default_render_state, sizeof(render_state_changes_)); |
221 | } |
222 | |
223 | |
224 | === modified file 'NuxGraphics/GLRenderStates.h' |
225 | --- NuxGraphics/GLRenderStates.h 2012-02-21 06:18:24 +0000 |
226 | +++ NuxGraphics/GLRenderStates.h 2012-09-30 17:24:22 +0000 |
227 | @@ -264,8 +264,8 @@ |
228 | |
229 | private: |
230 | |
231 | - GpuBrand _gpu_brand; |
232 | - GpuInfo *_gpu_info; |
233 | + GpuBrand gpu_brand_; |
234 | + GpuInfo* gpu_info_; |
235 | |
236 | inline void HW__EnableAlphaTest(unsigned int b); |
237 | |
238 | @@ -963,11 +963,11 @@ |
239 | (BlendOpAlpha_ == GL_MAX), |
240 | "Error(HW__SetAlphaBlendOp): Invalid Blend Equation RenderState"); |
241 | |
242 | - if (_gpu_info->SupportOpenGL20()) |
243 | + if (gpu_info_->SupportOpenGL20()) |
244 | { |
245 | CHECKGL(glBlendEquationSeparate(BlendOpRGB_, BlendOpAlpha_)); |
246 | } |
247 | - else if (_gpu_info->Support_EXT_Blend_Equation_Separate()) |
248 | + else if (gpu_info_->Support_EXT_Blend_Equation_Separate()) |
249 | { |
250 | CHECKGL(glBlendEquationSeparateEXT(BlendOpRGB_, BlendOpAlpha_)); |
251 | } |
252 | @@ -1138,7 +1138,7 @@ |
253 | { |
254 | if (b) |
255 | { |
256 | - if (_gpu_brand == GPU_BRAND_AMD) |
257 | + if (gpu_brand_ == GPU_BRAND_AMD) |
258 | { |
259 | CHECKGL(glEnable(GL_STENCIL_TEST)); |
260 | } |
261 | @@ -1149,7 +1149,7 @@ |
262 | } |
263 | else |
264 | { |
265 | - if (_gpu_brand == GPU_BRAND_AMD) |
266 | + if (gpu_brand_ == GPU_BRAND_AMD) |
267 | { |
268 | CHECKGL(glDisable(GL_STENCIL_TEST)); |
269 | } |
270 | @@ -1215,7 +1215,7 @@ |
271 | (Func_ == GL_ALWAYS), |
272 | "Error(HW__SetBackFaceStencilFunc): Invalid Stencil Function RenderState"); |
273 | |
274 | - if (_gpu_brand == GPU_BRAND_AMD) |
275 | + if (gpu_brand_ == GPU_BRAND_AMD) |
276 | { |
277 | CHECKGL(glStencilFuncSeparateATI(Func_/*Front function*/, Func_/*Back function*/, Ref_, Mask_)); // incorrect |
278 | } |
279 | @@ -1268,7 +1268,7 @@ |
280 | (ZPassOp_ == GL_INVERT), |
281 | "Error(HW__SetFrontFaceStencilOp): Invalid ZPassOp RenderState"); |
282 | |
283 | - if (_gpu_brand == GPU_BRAND_AMD) |
284 | + if (gpu_brand_ == GPU_BRAND_AMD) |
285 | { |
286 | CHECKGL(glStencilOpSeparateATI(GL_FRONT, FailOp_, ZFailOp_, ZPassOp_)); |
287 | } |
288 | @@ -1321,7 +1321,7 @@ |
289 | (ZPassOp_ == GL_INVERT), |
290 | "Error(HW__SetBackFaceStencilOp): Invalid ZPassOp RenderState"); |
291 | |
292 | - if (_gpu_brand == GPU_BRAND_AMD) |
293 | + if (gpu_brand_ == GPU_BRAND_AMD) |
294 | { |
295 | CHECKGL(glStencilOpSeparateATI(GL_BACK, FailOp_, ZFailOp_, ZPassOp_)); |
296 | } |
297 | |
298 | === modified file 'NuxGraphics/GLShaderParameter.h' |
299 | --- NuxGraphics/GLShaderParameter.h 2011-10-19 20:32:38 +0000 |
300 | +++ NuxGraphics/GLShaderParameter.h 2012-09-30 17:24:22 +0000 |
301 | @@ -50,8 +50,8 @@ |
302 | { |
303 | public: |
304 | int m_Index; // Register m_Index / Attribute m_Index |
305 | - eShaderParameterType m_ShaderParameterType; |
306 | - NString m_Name; |
307 | + eShaderParameterType m_ShaderParameterType; |
308 | + std::string m_Name; |
309 | bool m_bIsOptional; |
310 | bool m_bIsStatic; |
311 | bool bStaticSet; |
312 | |
313 | === modified file 'NuxGraphics/GpuDevice.cpp' |
314 | --- NuxGraphics/GpuDevice.cpp 2012-09-19 04:53:45 +0000 |
315 | +++ NuxGraphics/GpuDevice.cpp 2012-09-30 17:24:22 +0000 |
316 | @@ -32,6 +32,8 @@ |
317 | #include "GLTemplatePrimitiveBuffer.h" |
318 | #include "GraphicsEngine.h" |
319 | |
320 | +#include <algorithm> |
321 | + |
322 | namespace nux |
323 | { |
324 | #if (NUX_ENABLE_CG_SHADERS) |
325 | @@ -299,11 +301,14 @@ |
326 | bool opengl_es_20) |
327 | #endif |
328 | #endif |
329 | + : opengl_major_(0) |
330 | + , opengl_minor_(0) |
331 | + , use_pixel_buffer_object_(false) |
332 | + , pixel_store_alignment_(4) |
333 | + , gpu_render_states_(NULL) |
334 | + , gpu_info_(NULL) |
335 | { |
336 | - _PixelStoreAlignment = 4; |
337 | - _UsePixelBufferObject = false; |
338 | - _gpu_info = NULL; |
339 | - _gpu_brand = GPU_VENDOR_UNKNOWN; |
340 | + gpu_brand_ = GPU_VENDOR_UNKNOWN; |
341 | |
342 | #ifndef NUX_OPENGLES_20 |
343 | // OpenGL extension initialization |
344 | @@ -328,35 +333,70 @@ |
345 | #endif |
346 | |
347 | #ifndef NUX_OPENGLES_20 |
348 | - _glsl_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION))); |
349 | + _openGL_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION))); |
350 | CHECKGL_MSG(glGetString(GL_VERSION)); |
351 | |
352 | - NString opengl_major; |
353 | - NString opengl_minor; |
354 | - char split = '.'; |
355 | - _glsl_version_string.SplitAtFirstOccurenceOf(split, opengl_major, opengl_minor); |
356 | - |
357 | - _opengl_major = (char)opengl_major.GetTCharPtr()[0] - '0'; |
358 | - _opengl_minor = (char)opengl_minor.GetTCharPtr()[0] - '0'; |
359 | - |
360 | - if (_opengl_major >= 3) |
361 | - { |
362 | - CHECKGL(glGetIntegerv(GL_MAJOR_VERSION, &_opengl_major)); |
363 | - CHECKGL(glGetIntegerv(GL_MINOR_VERSION, &_opengl_minor)); |
364 | + // We need OpenGL minor and major version. Before OpenGL 3.0, the version number was reported as a string of format |
365 | + // "major.minor". That string has to be parsed to extract the major and minor version numbers. This is not really safe as |
366 | + // we have no guaranty that the version string is has we think it is. Some drivers report a version string like "xx.xx.xx". |
367 | + |
368 | + // Begin string parsing to extract the major and minor version numbers. |
369 | + std::string opengl_major; |
370 | + std::string opengl_minor; |
371 | + std::string split = "."; |
372 | + |
373 | + size_t pos = 0; |
374 | + pos = _openGL_version_string.find(split, pos); |
375 | + |
376 | + if (pos != tstring::npos) |
377 | + { |
378 | + size_t split_string_size = split.length(); |
379 | + opengl_major = _openGL_version_string.substr(0, pos); |
380 | + opengl_minor = _openGL_version_string.substr(pos + split_string_size, _openGL_version_string.length() - (pos + split_string_size) ); |
381 | + } |
382 | + |
383 | + int major_length = opengl_major.length(); |
384 | + opengl_major_ = 0; |
385 | + int digit_position = 1; |
386 | + while (major_length && (opengl_major.c_str()[major_length-1] >= '0') && (opengl_major.c_str()[major_length-1] <= '9')) |
387 | + { |
388 | + opengl_major_ += (opengl_major.c_str()[major_length-1] - '0') * digit_position; |
389 | + |
390 | + digit_position *= 10; |
391 | + --major_length; |
392 | + } |
393 | + |
394 | + int minor_length = opengl_minor.length(); |
395 | + opengl_minor_ = 0; |
396 | + digit_position = 0; |
397 | + while (minor_length && (opengl_minor.c_str()[digit_position] >= '0') && (opengl_minor.c_str()[digit_position] <= '9')) |
398 | + { |
399 | + opengl_minor_ += opengl_minor_ * 10 + (opengl_minor.c_str()[digit_position] - '0'); |
400 | + |
401 | + ++digit_position; |
402 | + --minor_length; |
403 | + } |
404 | + |
405 | + // End string parsing |
406 | + |
407 | + if (opengl_major_ >= 3) |
408 | + { |
409 | + CHECKGL(glGetIntegerv(GL_MAJOR_VERSION, &opengl_major_)); |
410 | + CHECKGL(glGetIntegerv(GL_MINOR_VERSION, &opengl_minor_)); |
411 | } |
412 | #else |
413 | - _opengl_major = 2; |
414 | - _opengl_minor = 0; |
415 | + opengl_major_ = 2; |
416 | + opengl_minor_ = 0; |
417 | #endif |
418 | |
419 | #if defined(NUX_OS_WINDOWS) |
420 | bool opengl_es_context_created = false; |
421 | - if (((_opengl_major >= 3) && (req_opengl_major >= 3)) || (_opengl_major >= 3) || opengl_es_20) |
422 | + if (((opengl_major_ >= 3) && (req_opengl_major >= 3)) || (opengl_major_ >= 3) || opengl_es_20) |
423 | #elif defined(NUX_OS_LINUX) |
424 | //bool opengl_es_context_created = false; |
425 | if (has_glx_13_support && |
426 | - (((_opengl_major >= 3) && (req_opengl_major >= 3)) || |
427 | - ((_opengl_major >= 3) && opengl_es_20))) |
428 | + (((opengl_major_ >= 3) && (req_opengl_major >= 3)) || |
429 | + ((opengl_major_ >= 3) && opengl_es_20))) |
430 | #endif |
431 | { |
432 | // Create a new Opengl Rendering Context |
433 | @@ -367,22 +407,22 @@ |
434 | if ((OpenGLVersionTable[index].major == req_opengl_major) && |
435 | (OpenGLVersionTable[index].minor == req_opengl_minor)) |
436 | { |
437 | - if (_opengl_major == 1) |
438 | + if (opengl_major_ == 1) |
439 | { |
440 | if ((req_opengl_major == 1) && (req_opengl_minor >= 0) && (req_opengl_minor <= 5)) |
441 | requested_profile_is_supported = true; |
442 | } |
443 | - else if (_opengl_major == 2) |
444 | + else if (opengl_major_ == 2) |
445 | { |
446 | if ((req_opengl_major == 2) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1)) |
447 | requested_profile_is_supported = true; |
448 | } |
449 | - else if (_opengl_major == 3) |
450 | + else if (opengl_major_ == 3) |
451 | { |
452 | if ((req_opengl_major == 3) && (req_opengl_minor >= 0) && (req_opengl_minor <= 3)) |
453 | requested_profile_is_supported = true; |
454 | } |
455 | - else if (_opengl_major == 4) |
456 | + else if (opengl_major_ == 4) |
457 | { |
458 | if ((req_opengl_major == 4) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1)) |
459 | requested_profile_is_supported = true; |
460 | @@ -528,43 +568,32 @@ |
461 | _openGL_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION))); |
462 | CHECKGL_MSG(glGetString(GL_VERSION)); |
463 | |
464 | - nuxDebugMsg("Gpu Vendor: %s", _board_vendor_string.GetTCharPtr()); |
465 | - nuxDebugMsg("Gpu Renderer: %s", _board_renderer_string.GetTCharPtr()); |
466 | - nuxDebugMsg("Gpu OpenGL Version: %s", _openGL_version_string.GetTCharPtr()); |
467 | - nuxDebugMsg("Gpu OpenGL Major Version: %d", _opengl_major); |
468 | - nuxDebugMsg("Gpu OpenGL Minor Version: %d", _opengl_minor); |
469 | - nuxDebugMsg("Gpu GLSL Version: %s", _glsl_version_string.GetTCharPtr()); |
470 | - |
471 | - NString TempStr = (const char *) TCharToUpperCase(_board_vendor_string.GetTCharPtr()); |
472 | - |
473 | - if (TempStr.FindFirstOccurence("NVIDIA") != tstring::npos) |
474 | - { |
475 | - _gpu_brand = GPU_BRAND_NVIDIA; |
476 | - } |
477 | - else if (TempStr.FindFirstOccurence("ATI") != tstring::npos) |
478 | - { |
479 | - _gpu_brand = GPU_BRAND_AMD; |
480 | - } |
481 | - else if (TempStr.FindFirstOccurence("TUNGSTEN") != tstring::npos) |
482 | - { |
483 | - _gpu_brand = GPU_BRAND_INTEL; |
484 | - } |
485 | - |
486 | - if (0) |
487 | - { |
488 | - if (GetGPUBrand() == GPU_BRAND_AMD) |
489 | - _UsePixelBufferObject = false; |
490 | - else |
491 | - _UsePixelBufferObject = true; |
492 | - } |
493 | - else |
494 | - { |
495 | - _UsePixelBufferObject = false; |
496 | - } |
497 | - |
498 | - _gpu_info = new GpuInfo(); |
499 | - _gpu_info->Setup(); |
500 | - _gpu_render_states = new GpuRenderStates(_gpu_brand, _gpu_info); |
501 | + nuxDebugMsg("Gpu Vendor: %s", _board_vendor_string.c_str()); |
502 | + nuxDebugMsg("Gpu Renderer: %s", _board_renderer_string.c_str()); |
503 | + nuxDebugMsg("Gpu OpenGL Version: %s", _openGL_version_string.c_str()); |
504 | + nuxDebugMsg("Gpu OpenGL Major Version: %d", opengl_major_); |
505 | + nuxDebugMsg("Gpu OpenGL Minor Version: %d", opengl_minor_); |
506 | + |
507 | + std::transform(_board_vendor_string.begin(), _board_vendor_string.end(), _board_vendor_string.begin(), ::toupper); |
508 | + |
509 | + if (_board_vendor_string.find("NVIDIA", 0) != tstring::npos) |
510 | + { |
511 | + gpu_brand_ = GPU_BRAND_NVIDIA; |
512 | + } |
513 | + else if (_board_vendor_string.find("ATI", 0) != tstring::npos) |
514 | + { |
515 | + gpu_brand_ = GPU_BRAND_AMD; |
516 | + } |
517 | + else if (_board_vendor_string.find("TUNGSTEN", 0) != tstring::npos) |
518 | + { |
519 | + gpu_brand_ = GPU_BRAND_INTEL; |
520 | + } |
521 | + |
522 | + use_pixel_buffer_object_ = false; |
523 | + |
524 | + gpu_info_ = new GpuInfo(); |
525 | + gpu_info_->Setup(); |
526 | + gpu_render_states_ = new GpuRenderStates(gpu_brand_, gpu_info_); |
527 | |
528 | #if defined(NUX_OS_WINDOWS) |
529 | OGL_EXT_SWAP_CONTROL = WGLEW_EXT_swap_control ? true : false; |
530 | @@ -579,8 +608,8 @@ |
531 | // http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/ |
532 | // We use a pack /unpack alignment to 1 so we don't have any padding at the end of row. |
533 | |
534 | - CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, _PixelStoreAlignment)); |
535 | - CHECKGL(glPixelStorei(GL_PACK_ALIGNMENT, _PixelStoreAlignment)); |
536 | + CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, pixel_store_alignment_)); |
537 | + CHECKGL(glPixelStorei(GL_PACK_ALIGNMENT, pixel_store_alignment_)); |
538 | |
539 | // _DeviceWidth = DeviceWidth; |
540 | // _DeviceHeight = DeviceHeight; |
541 | @@ -619,8 +648,8 @@ |
542 | |
543 | GpuDevice::~GpuDevice() |
544 | { |
545 | - NUX_SAFE_DELETE(_gpu_info); |
546 | - NUX_SAFE_DELETE(_gpu_render_states); |
547 | + NUX_SAFE_DELETE(gpu_info_); |
548 | + NUX_SAFE_DELETE(gpu_render_states_); |
549 | |
550 | _FrameBufferObject.Release(); |
551 | active_framebuffer_object_.Release(); |
552 | @@ -656,37 +685,47 @@ |
553 | |
554 | int GpuDevice::GetOpenGLMajorVersion() const |
555 | { |
556 | - return _opengl_major; |
557 | + return opengl_major_; |
558 | } |
559 | |
560 | int GpuDevice::GetOpenGLMinorVersion() const |
561 | { |
562 | - return _opengl_minor; |
563 | + return opengl_minor_; |
564 | + } |
565 | + |
566 | + unsigned int GpuDevice::GetPixelStoreAlignment() const |
567 | + { |
568 | + return pixel_store_alignment_; |
569 | + } |
570 | + |
571 | + bool GpuDevice::UsePixelBufferObjects() const |
572 | + { |
573 | + return use_pixel_buffer_object_; |
574 | } |
575 | |
576 | GpuBrand GpuDevice::GetGPUBrand() const |
577 | { |
578 | - return _gpu_brand; |
579 | + return gpu_brand_; |
580 | } |
581 | |
582 | GpuRenderStates &GpuDevice::GetRenderStates() |
583 | { |
584 | - return *_gpu_render_states; |
585 | + return *gpu_render_states_; |
586 | } |
587 | |
588 | - GpuInfo &GpuDevice::GetGpuInfo() |
589 | + const GpuInfo& GpuDevice::GetGpuInfo() const |
590 | { |
591 | - return *_gpu_info; |
592 | + return *gpu_info_; |
593 | } |
594 | |
595 | void GpuDevice::ResetRenderStates() |
596 | { |
597 | - _gpu_render_states->ResetStateChangeToDefault(); |
598 | + gpu_render_states_->ResetStateChangeToDefault(); |
599 | } |
600 | |
601 | void GpuDevice::VerifyRenderStates() |
602 | { |
603 | - _gpu_render_states->CheckStateChange(); |
604 | + gpu_render_states_->CheckStateChange(); |
605 | } |
606 | |
607 | void GpuDevice::InvalidateTextureUnit(int TextureUnitIndex) |
608 | |
609 | === modified file 'NuxGraphics/GpuDevice.h' |
610 | --- NuxGraphics/GpuDevice.h 2012-09-17 09:55:43 +0000 |
611 | +++ NuxGraphics/GpuDevice.h 2012-09-30 17:24:22 +0000 |
612 | @@ -362,11 +362,6 @@ |
613 | //! Setup a NULL texture |
614 | void InvalidateTextureUnit(int TextureUnitIndex); |
615 | |
616 | - unsigned int GetPixelStoreAlignment() |
617 | - { |
618 | - return _PixelStoreAlignment; |
619 | - } |
620 | - |
621 | int AllocateUnpackPixelBufferIndex(int *index); |
622 | int FreeUnpackPixelBufferIndex(const int index); |
623 | int BindUnpackPixelBufferIndex(const int index); |
624 | @@ -389,6 +384,8 @@ |
625 | //! Restore the backbuffer as the render target. |
626 | void DeactivateFrameBuffer(); |
627 | |
628 | + unsigned int GetPixelStoreAlignment() const; |
629 | + |
630 | public: |
631 | void SetCurrentFrameBufferObject(ObjectPtr<IOpenGLFrameBufferObject> fbo); |
632 | ObjectPtr<IOpenGLFrameBufferObject> GetCurrentFrameBufferObject(); |
633 | @@ -409,10 +406,6 @@ |
634 | bool IsReserved; |
635 | }; |
636 | |
637 | - unsigned int _PixelStoreAlignment; |
638 | - |
639 | - std::vector<PixelBufferObject> _PixelBufferArray; |
640 | - |
641 | public: |
642 | |
643 | #if (NUX_ENABLE_CG_SHADERS) |
644 | @@ -423,16 +416,13 @@ |
645 | CGcontext m_Cgcontext; |
646 | #endif |
647 | |
648 | - inline bool UsePixelBufferObjects() const |
649 | - { |
650 | - return _UsePixelBufferObject; |
651 | - } |
652 | + bool UsePixelBufferObjects() const; |
653 | |
654 | GpuBrand GetGPUBrand() const; |
655 | |
656 | - GpuRenderStates &GetRenderStates(); |
657 | + GpuRenderStates& GetRenderStates(); |
658 | |
659 | - GpuInfo &GetGpuInfo(); |
660 | + const GpuInfo& GetGpuInfo() const; |
661 | |
662 | void ResetRenderStates(); |
663 | |
664 | @@ -460,34 +450,34 @@ |
665 | |
666 | bool SUPPORT_GL_ARB_TEXTURE_NON_POWER_OF_TWO() const |
667 | { |
668 | - return _gpu_info->Support_ARB_Texture_Non_Power_Of_Two(); |
669 | + return gpu_info_->Support_ARB_Texture_Non_Power_Of_Two(); |
670 | } |
671 | |
672 | bool SUPPORT_GL_EXT_TEXTURE_RECTANGLE() const |
673 | { |
674 | - return _gpu_info->Support_EXT_Texture_Rectangle(); |
675 | + return gpu_info_->Support_EXT_Texture_Rectangle(); |
676 | } |
677 | |
678 | bool SUPPORT_GL_ARB_TEXTURE_RECTANGLE() const |
679 | { |
680 | - return _gpu_info->Support_ARB_Texture_Rectangle(); |
681 | + return gpu_info_->Support_ARB_Texture_Rectangle(); |
682 | } |
683 | |
684 | private: |
685 | |
686 | // |
687 | - int _opengl_major; //!< OpenGL major version. |
688 | - int _opengl_minor; //!< OpenGL minor version. |
689 | - int _glsl_version_major; //!< GLSL major version. |
690 | - int _glsl_version_minor; //!< GLSL major version. |
691 | - |
692 | - NString _board_vendor_string; //!< GPU vendor sting. |
693 | - NString _board_renderer_string; //!< GPU renderer sting. |
694 | - NString _openGL_version_string; //!< OpenGL version string. |
695 | - NString _glsl_version_string; //!< GLSL version string. |
696 | - GpuBrand _gpu_brand; //!< GPU brand. |
697 | - |
698 | - bool _UsePixelBufferObject; |
699 | + int opengl_major_; //!< OpenGL major version. |
700 | + int opengl_minor_; //!< OpenGL minor version. |
701 | + |
702 | + std::string _board_vendor_string; //!< GPU vendor sting. |
703 | + std::string _board_renderer_string; //!< GPU renderer sting. |
704 | + std::string _openGL_version_string; //!< OpenGL version string. |
705 | + GpuBrand gpu_brand_; //!< GPU brand. |
706 | + |
707 | + bool use_pixel_buffer_object_; |
708 | + unsigned int pixel_store_alignment_; |
709 | + std::vector<PixelBufferObject> _PixelBufferArray; |
710 | + |
711 | |
712 | bool OGL_EXT_SWAP_CONTROL; |
713 | bool GL_ARB_VERTEX_PROGRAM; |
714 | @@ -504,8 +494,8 @@ |
715 | bool GL_ARB_TEXTURE_RECTANGLE; //!< Promoted from GL_EXT_TEXTURE_RECTANGLE to ARB. |
716 | bool GL_NV_TEXTURE_RECTANGLE; |
717 | |
718 | - GpuRenderStates *_gpu_render_states; |
719 | - GpuInfo *_gpu_info; |
720 | + GpuRenderStates* gpu_render_states_; |
721 | + GpuInfo* gpu_info_; |
722 | |
723 | public: |
724 | |
725 | |
726 | === modified file 'NuxGraphics/GpuDeviceVertex.cpp' |
727 | --- NuxGraphics/GpuDeviceVertex.cpp 2012-09-19 04:53:45 +0000 |
728 | +++ NuxGraphics/GpuDeviceVertex.cpp 2012-09-30 17:24:22 +0000 |
729 | @@ -160,7 +160,7 @@ |
730 | vtxelement.Type, |
731 | GL_FALSE, |
732 | vtxelement.stride_, |
733 | - (void*)vtxelement.Offset)); // TODO: Bug. It doesn't make sense to convert a 4-byte int into an 8-byte pointer. |
734 | + (void*)&vtxelement.Offset)); |
735 | |
736 | VertexDeclaration->_valid_vertex_input[shader_attribute_location] = 1; |
737 | ++decl; |
738 | |
739 | === modified file 'NuxGraphics/GraphicsEngine.cpp' |
740 | --- NuxGraphics/GraphicsEngine.cpp 2012-09-17 09:55:43 +0000 |
741 | +++ NuxGraphics/GraphicsEngine.cpp 2012-09-30 17:24:22 +0000 |
742 | @@ -230,7 +230,7 @@ |
743 | } |
744 | #endif |
745 | |
746 | - GpuInfo& gpu_info = _graphics_display.GetGpuDevice()->GetGpuInfo(); |
747 | + const GpuInfo& gpu_info = _graphics_display.GetGpuDevice()->GetGpuInfo(); |
748 | |
749 | if ((gpu_info.Support_ARB_Vertex_Program() && gpu_info.Support_ARB_Fragment_Program()) |
750 | || (gpu_info.Support_ARB_Vertex_Shader() && gpu_info.Support_ARB_Fragment_Shader())) |
751 | |
752 | === modified file 'NuxGraphics/GraphicsEngine.h' |
753 | --- NuxGraphics/GraphicsEngine.h 2012-09-19 04:53:45 +0000 |
754 | +++ NuxGraphics/GraphicsEngine.h 2012-09-30 17:24:22 +0000 |
755 | @@ -662,15 +662,15 @@ |
756 | |
757 | GpuRenderStates& GetRenderStates() |
758 | { |
759 | - return *_graphics_display.m_DeviceFactory->_gpu_render_states; |
760 | + return *_graphics_display.m_DeviceFactory->gpu_render_states_; |
761 | } |
762 | void ResetRenderStates() |
763 | { |
764 | - _graphics_display.m_DeviceFactory->_gpu_render_states->ResetStateChangeToDefault(); |
765 | + _graphics_display.m_DeviceFactory->gpu_render_states_->ResetStateChangeToDefault(); |
766 | } |
767 | void VerifyRenderStates() |
768 | { |
769 | - _graphics_display.m_DeviceFactory->_gpu_render_states->CheckStateChange(); |
770 | + _graphics_display.m_DeviceFactory->gpu_render_states_->CheckStateChange(); |
771 | } |
772 | |
773 | ObjectPtr<FontTexture> GetFont(); |
774 | |
775 | === modified file 'NuxGraphics/IOpenGLAsmShader.cpp' |
776 | --- NuxGraphics/IOpenGLAsmShader.cpp 2012-08-02 16:29:19 +0000 |
777 | +++ NuxGraphics/IOpenGLAsmShader.cpp 2012-09-30 17:24:22 +0000 |
778 | @@ -39,7 +39,7 @@ |
779 | NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLAsmPixelShader); |
780 | NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLAsmShaderProgram); |
781 | |
782 | - bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString ShaderPreprocessorDefines); |
783 | + bool ExtractShaderString3(const std::string& ShaderToken, const std::string& ShaderSource, std::string& RetSource, std::string ShaderPreprocessorDefines); |
784 | |
785 | IOpenGLAsmShader::IOpenGLAsmShader(std::string const& shader_name, GLint shader_type, OpenGLResourceType ResourceType) |
786 | : IOpenGLResource(ResourceType) |
787 | @@ -113,7 +113,7 @@ |
788 | { |
789 | } |
790 | |
791 | - IOpenGLAsmShaderProgram::IOpenGLAsmShaderProgram(NString ShaderProgramName) |
792 | + IOpenGLAsmShaderProgram::IOpenGLAsmShaderProgram(std::string ShaderProgramName) |
793 | : IOpenGLResource(RT_GLSL_SHADERPROGRAM) |
794 | , _ShaderProgramName(ShaderProgramName) |
795 | { |
796 | @@ -131,19 +131,19 @@ |
797 | { |
798 | nuxAssertMsg(ShaderFileName, "[IOpenGLAsmShaderProgram::LoadIShaderFile] Invalid shader file name."); |
799 | NUX_RETURN_IF_NULL(ShaderFileName); |
800 | - NString SourceCode; |
801 | + std::string SourceCode; |
802 | LoadFileToString(SourceCode, ShaderFileName); |
803 | LoadIShader(&SourceCode[0]); |
804 | } |
805 | |
806 | - void IOpenGLAsmShaderProgram::LoadIShader(const char *ShaderCode) |
807 | + void IOpenGLAsmShaderProgram::LoadIShader(const char* ShaderCode) |
808 | { |
809 | nuxAssertMsg(ShaderCode, "[IOpenGLAsmShaderProgram::LoadIShader] Invalid shader code."); |
810 | NUX_RETURN_IF_NULL(ShaderCode); |
811 | - NString VertexShaderSource; |
812 | - ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, NString("")); |
813 | - NString PixelShaderSource; |
814 | - ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, NString("")); |
815 | + std::string VertexShaderSource; |
816 | + ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, std::string("")); |
817 | + std::string PixelShaderSource; |
818 | + ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, std::string("")); |
819 | |
820 | m_AsmVertexProgram->SetShaderCode(&VertexShaderSource[0]); |
821 | m_AsmFragmentProgram->SetShaderCode(&PixelShaderSource[0]); |
822 | @@ -152,7 +152,7 @@ |
823 | m_AsmFragmentProgram->Compile(); |
824 | } |
825 | |
826 | - void IOpenGLAsmShaderProgram::LoadVertexShader(const char *glslshader) |
827 | + void IOpenGLAsmShaderProgram::LoadVertexShader(const char* glslshader) |
828 | { |
829 | nuxAssertMsg(glslshader, "[IOpenGLAsmShaderProgram::LoadVertexShader] Invalid shader code."); |
830 | NUX_RETURN_IF_NULL(glslshader); |
831 | |
832 | === modified file 'NuxGraphics/IOpenGLAsmShader.h' |
833 | --- NuxGraphics/IOpenGLAsmShader.h 2012-08-02 16:29:19 +0000 |
834 | +++ NuxGraphics/IOpenGLAsmShader.h 2012-09-30 17:24:22 +0000 |
835 | @@ -121,9 +121,9 @@ |
836 | void SetFragmentLocalParameter4fvARB (unsigned int index, const float *params); |
837 | |
838 | private: |
839 | - IOpenGLAsmShaderProgram(NString ShaderProgramName = NString("AsmShaderProgram")); |
840 | + IOpenGLAsmShaderProgram(std::string ShaderProgramName = std::string("AsmShaderProgram")); |
841 | std::vector<ObjectPtr<IOpenGLAsmShader> > ShaderObjectList; |
842 | - NString _ShaderProgramName; |
843 | + std::string _ShaderProgramName; |
844 | |
845 | ObjectPtr<IOpenGLAsmVertexShader> m_AsmVertexProgram; |
846 | ObjectPtr<IOpenGLAsmPixelShader> m_AsmFragmentProgram; |
847 | |
848 | === modified file 'NuxGraphics/IOpenGLCgShader.h' |
849 | --- NuxGraphics/IOpenGLCgShader.h 2011-10-19 20:32:38 +0000 |
850 | +++ NuxGraphics/IOpenGLCgShader.h 2012-09-30 17:24:22 +0000 |
851 | @@ -33,7 +33,7 @@ |
852 | NUX_DECLARE_OBJECT_TYPE(ICgShader, IOpenGLResource); |
853 | |
854 | public: |
855 | - ICgShader(NString ShaderName, OpenGLResourceType ResourceType); |
856 | + ICgShader(std::string ShaderName, OpenGLResourceType ResourceType); |
857 | virtual ~ICgShader(); |
858 | |
859 | virtual void CreateProgram(const ANSICHAR *ShaderCode, const ANSICHAR *EntryPoint) = 0; |
860 | @@ -45,9 +45,9 @@ |
861 | virtual bool IsValid() = 0; |
862 | CGparameter GetNamedParameter(const char *parameter); |
863 | |
864 | - NString _ShaderName; |
865 | - NString _ShaderCode; |
866 | - NString _EntryPoint; |
867 | + std::string _ShaderName; |
868 | + std::string _ShaderCode; |
869 | + std::string _EntryPoint; |
870 | CGprogram _CgProgram; |
871 | }; |
872 | |
873 | @@ -62,7 +62,7 @@ |
874 | virtual bool Compile(); |
875 | virtual bool IsValid(); |
876 | private: |
877 | - ICgVertexShader(NString ShaderName = NString("VertexProgram")); |
878 | + ICgVertexShader(std::string ShaderName = std::string("VertexProgram")); |
879 | int _ready; |
880 | friend class GpuDevice; |
881 | }; |
882 | @@ -78,7 +78,7 @@ |
883 | virtual bool Compile(); |
884 | virtual bool IsValid(); |
885 | private: |
886 | - ICgPixelShader(NString ShaderName = NString("PixelProgram")); |
887 | + ICgPixelShader(std::string ShaderName = std::string("PixelProgram")); |
888 | int _ready; |
889 | friend class GpuDevice; |
890 | }; |
891 | |
892 | === modified file 'NuxGraphics/IOpenGLGLSLShader.cpp' |
893 | --- NuxGraphics/IOpenGLGLSLShader.cpp 2012-02-23 16:30:14 +0000 |
894 | +++ NuxGraphics/IOpenGLGLSLShader.cpp 2012-09-30 17:24:22 +0000 |
895 | @@ -43,7 +43,7 @@ |
896 | NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLShaderProgram); |
897 | |
898 | |
899 | - bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString ShaderPreprocessorDefines) |
900 | + bool ExtractShaderString3(const std::string &ShaderToken, const std::string &ShaderSource, std::string &RetSource, std::string ShaderPreprocessorDefines) |
901 | { |
902 | size_t lineStart = 0; |
903 | size_t lineCount = 1; |
904 | @@ -57,7 +57,7 @@ |
905 | { |
906 | size_t i; |
907 | |
908 | - for (i = 0; i < ShaderSource.Length(); i++) |
909 | + for (i = 0; i < ShaderSource.length(); i++) |
910 | { |
911 | //Check if the starting character '[' (open bracket) is found at the beginning of the line |
912 | // i counts the characters in the file. lineStart is equal to i at the beginning of the line. |
913 | @@ -66,10 +66,10 @@ |
914 | if (!startTokenFound) |
915 | { |
916 | //Test for the start token |
917 | - if (ShaderSource.FindFirstOccurence(ShaderToken) == i) |
918 | + if (ShaderSource.find(ShaderToken, 0) == i) |
919 | { |
920 | // Found the shader token |
921 | - shaderStringStart = i + ShaderToken.Length(); |
922 | + shaderStringStart = i + ShaderToken.length(); |
923 | startTokenFound = true; |
924 | |
925 | //Set what line the shader was found on |
926 | @@ -104,11 +104,11 @@ |
927 | } |
928 | |
929 | //Assign the return string |
930 | - RetSource = ShaderSource.GetSubString(shaderStringStart, i - shaderStringStart); |
931 | + RetSource = ShaderSource.substr(shaderStringStart, i - shaderStringStart); |
932 | |
933 | //Add the line directive to the shader source. See the documentation for GLSL #line directive. |
934 | // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space. |
935 | - size_t Pos = RetSource.FindFirstOccurence("#version"); |
936 | + size_t Pos = RetSource.find("#version", 0); |
937 | |
938 | while (RetSource[Pos] != '\n') |
939 | { |
940 | @@ -124,17 +124,21 @@ |
941 | size_t EndOfLinePosition = 0; |
942 | size_t LinePosition = 0; |
943 | |
944 | - while ((EndOfLinePosition = RetSource.FindNextOccurence('\n', EndOfLinePosition)) < Pos - 1) |
945 | + while ((EndOfLinePosition = RetSource.find('\n', EndOfLinePosition)) < Pos - 1) |
946 | { |
947 | ++EndOfLinePosition; |
948 | ++LinePosition; |
949 | } |
950 | |
951 | - RetSource.Insert(Pos, NString::Printf("#line %u\n", LinePosition + shaderStartLine)); |
952 | + std::ostringstream o_str_stream; |
953 | + o_str_stream << "#line " << LinePosition + shaderStartLine << "\n"; |
954 | + std::string line_num_str = o_str_stream.str(); |
955 | + |
956 | + RetSource.insert(Pos, line_num_str); |
957 | |
958 | // Insert the preprocessor definitions before the #line directive |
959 | - if (ShaderPreprocessorDefines.Length()) |
960 | - RetSource.Insert(Pos, ShaderPreprocessorDefines + NString('\n')); |
961 | + if (ShaderPreprocessorDefines.length()) |
962 | + RetSource.insert(Pos, ShaderPreprocessorDefines + std::string("\n")); |
963 | |
964 | return true; |
965 | } |
966 | @@ -146,26 +150,26 @@ |
967 | } |
968 | } |
969 | |
970 | - static void InsertPreProcessorDefinitions(const NString &ShaderSource, NString &RetSource, NString &ShaderPreprocessorDefines) |
971 | + static void InsertPreProcessorDefinitions(const std::string &ShaderSource, std::string &RetSource, std::string &ShaderPreprocessorDefines) |
972 | { |
973 | RetSource = ShaderSource; |
974 | |
975 | - if (ShaderPreprocessorDefines.Length() == 0) |
976 | + if (ShaderPreprocessorDefines.length() == 0) |
977 | return; |
978 | |
979 | // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space. |
980 | - size_t Pos = RetSource.FindFirstOccurence("#version"); |
981 | + size_t Pos = RetSource.find("#version", 0); |
982 | |
983 | if (Pos != tstring::npos) |
984 | { |
985 | - Pos = RetSource.FindNextOccurence('\n', Pos); |
986 | + Pos = RetSource.find('\n', Pos); |
987 | |
988 | if (Pos == tstring::npos) |
989 | { |
990 | // this is most likely an incorrect shader |
991 | - Pos = RetSource.Size(); |
992 | - RetSource.Insert(Pos, NString('\n')); |
993 | - Pos = RetSource.Size(); |
994 | + Pos = RetSource.size(); |
995 | + RetSource.insert(Pos, std::string("\n")); |
996 | + Pos = RetSource.size(); |
997 | } |
998 | else |
999 | { |
1000 | @@ -178,11 +182,11 @@ |
1001 | Pos = 0; |
1002 | } |
1003 | |
1004 | - if (ShaderPreprocessorDefines.Length()) |
1005 | - RetSource.Insert(Pos, ShaderPreprocessorDefines + NString('\n')); |
1006 | + if (ShaderPreprocessorDefines.length()) |
1007 | + RetSource.insert(Pos, ShaderPreprocessorDefines + std::string("\n")); |
1008 | } |
1009 | |
1010 | - IOpenGLShader::IOpenGLShader(NString ShaderName, OpenGLResourceType ResourceType) |
1011 | + IOpenGLShader::IOpenGLShader(std::string ShaderName, OpenGLResourceType ResourceType) |
1012 | : IOpenGLResource(ResourceType) |
1013 | , _ShaderName(ShaderName) |
1014 | { |
1015 | @@ -194,7 +198,7 @@ |
1016 | |
1017 | } |
1018 | |
1019 | - IOpenGLVertexShader::IOpenGLVertexShader(NString ShaderName) |
1020 | + IOpenGLVertexShader::IOpenGLVertexShader(std::string ShaderName) |
1021 | : IOpenGLShader(ShaderName, RT_GLSL_VERTEXSHADER) |
1022 | , m_CompiledAndReady(false) |
1023 | { |
1024 | @@ -213,8 +217,8 @@ |
1025 | { |
1026 | nuxAssertMsg(ShaderCode, "[IOpenGLVertexShader::SetShaderCode] Invalid shader code."); |
1027 | NUX_RETURN_IF_NULL(ShaderCode); |
1028 | - NString ProcessedShaderSource; |
1029 | - NString Defines(VtxShaderPreprocessorDefines); |
1030 | + std::string ProcessedShaderSource; |
1031 | + std::string Defines(VtxShaderPreprocessorDefines); |
1032 | InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines); |
1033 | |
1034 | m_CompiledAndReady = false; |
1035 | @@ -223,7 +227,7 @@ |
1036 | |
1037 | bool IOpenGLVertexShader::Compile() |
1038 | { |
1039 | - size_t CodeSize = _ShaderCode.Size(); |
1040 | + size_t CodeSize = _ShaderCode.size(); |
1041 | |
1042 | if (CodeSize == 0) |
1043 | { |
1044 | @@ -232,7 +236,7 @@ |
1045 | |
1046 | char *ShaderSource = new char[CodeSize+1]; |
1047 | Memset(ShaderSource, 0, CodeSize + 1); |
1048 | - Memcpy(ShaderSource, _ShaderCode.GetTCharPtr(), CodeSize); |
1049 | + Memcpy(ShaderSource, _ShaderCode.c_str(), CodeSize); |
1050 | |
1051 | CHECKGL(glShaderSource(_OpenGLID, 1, (const GLcharARB **) &ShaderSource, NULL)); |
1052 | delete [] ShaderSource; |
1053 | @@ -272,7 +276,7 @@ |
1054 | return(m_CompiledAndReady ? true : false); |
1055 | } |
1056 | |
1057 | - IOpenGLPixelShader::IOpenGLPixelShader(NString ShaderName) |
1058 | + IOpenGLPixelShader::IOpenGLPixelShader(std::string ShaderName) |
1059 | : IOpenGLShader(ShaderName, RT_GLSL_PIXELSHADER) |
1060 | , m_CompiledAndReady(false) |
1061 | |
1062 | @@ -292,8 +296,8 @@ |
1063 | { |
1064 | nuxAssertMsg(ShaderCode, "[IOpenGLPixelShader::SetShaderCode] Invalid shader code."); |
1065 | NUX_RETURN_IF_NULL(ShaderCode); |
1066 | - NString ProcessedShaderSource; |
1067 | - NString Defines(FrgShaderPreprocessorDefines); |
1068 | + std::string ProcessedShaderSource; |
1069 | + std::string Defines(FrgShaderPreprocessorDefines); |
1070 | InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines); |
1071 | |
1072 | m_CompiledAndReady = false; |
1073 | @@ -303,7 +307,7 @@ |
1074 | bool IOpenGLPixelShader::Compile() |
1075 | { |
1076 | |
1077 | - GLint CodeSize = (GLint) _ShaderCode.Size(); |
1078 | + GLint CodeSize = (GLint) _ShaderCode.size(); |
1079 | |
1080 | if (CodeSize == 0) |
1081 | { |
1082 | @@ -312,7 +316,7 @@ |
1083 | |
1084 | char *ShaderSource = new char[CodeSize+1]; |
1085 | Memset(ShaderSource, 0, CodeSize + 1); |
1086 | - Memcpy(ShaderSource, _ShaderCode.m_string.c_str(), CodeSize); |
1087 | + Memcpy(ShaderSource, _ShaderCode.c_str(), CodeSize); |
1088 | CHECKGL(glShaderSource(_OpenGLID, 1, (const GLcharARB **) &ShaderSource, &CodeSize)); |
1089 | delete [] ShaderSource; |
1090 | |
1091 | @@ -354,7 +358,7 @@ |
1092 | } |
1093 | |
1094 | #if 0 |
1095 | - IOpenGLGeometryShader::IOpenGLGeometryShader(NString ShaderName) |
1096 | + IOpenGLGeometryShader::IOpenGLGeometryShader(std::string ShaderName) |
1097 | : IOpenGLShader(ShaderName, RT_GLSL_GEOMETRYSHADER) |
1098 | , m_CompiledAndReady(false) |
1099 | |
1100 | @@ -374,8 +378,8 @@ |
1101 | { |
1102 | nuxAssertMsg(ShaderCode, "[IOpenGLGeometryShader::SetShaderCode] Invalid shader code."); |
1103 | NUX_RETURN_IF_NULL(ShaderCode); |
1104 | - NString ProcessedShaderSource; |
1105 | - NString Defines(GeometryShaderPreprocessorDefines); |
1106 | + std::string ProcessedShaderSource; |
1107 | + std::string Defines(GeometryShaderPreprocessorDefines); |
1108 | InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines); |
1109 | |
1110 | m_CompiledAndReady = false; |
1111 | @@ -449,7 +453,7 @@ |
1112 | } |
1113 | #endif |
1114 | |
1115 | - IOpenGLShaderProgram::IOpenGLShaderProgram(NString ShaderProgramName) |
1116 | + IOpenGLShaderProgram::IOpenGLShaderProgram(std::string ShaderProgramName) |
1117 | : IOpenGLResource(RT_GLSL_SHADERPROGRAM) |
1118 | , _FirstParameter(0) |
1119 | , m_CompiledAndReady(false) |
1120 | @@ -476,7 +480,7 @@ |
1121 | { |
1122 | nuxAssertMsg(ShaderFileName, "[IOpenGLShaderProgram::LoadIShaderFile] Invalid shader file name."); |
1123 | NUX_RETURN_IF_NULL(ShaderFileName); |
1124 | - NString SourceCode; |
1125 | + std::string SourceCode; |
1126 | LoadFileToString(SourceCode, ShaderFileName); |
1127 | LoadIShader(&SourceCode[0], VtxShaderPreprocessorDefines, FrgShaderPreprocessorDefines); |
1128 | } |
1129 | @@ -485,10 +489,10 @@ |
1130 | { |
1131 | nuxAssertMsg(ShaderCode, "[IOpenGLShaderProgram::LoadIShader] Invalid shader code."); |
1132 | NUX_RETURN_IF_NULL(ShaderCode); |
1133 | - NString VertexShaderSource; |
1134 | - ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, NString(VtxShaderPreprocessorDefines)); |
1135 | - NString PixelShaderSource; |
1136 | - ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, NString(FrgShaderPreprocessorDefines)); |
1137 | + std::string VertexShaderSource; |
1138 | + ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, std::string(VtxShaderPreprocessorDefines)); |
1139 | + std::string PixelShaderSource; |
1140 | + ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, std::string(FrgShaderPreprocessorDefines)); |
1141 | |
1142 | ObjectPtr<IOpenGLVertexShader> vs = GetGraphicsDisplay()->GetGpuDevice()->CreateVertexShader(); //new IOpenGLVertexShader; |
1143 | ObjectPtr<IOpenGLPixelShader> ps = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader(); //new IOpenGLPixelShader; |
1144 | @@ -510,8 +514,8 @@ |
1145 | NUX_RETURN_IF_NULL(glslshader); |
1146 | ObjectPtr<IOpenGLVertexShader> vs = GetGraphicsDisplay()->GetGpuDevice()->CreateVertexShader(); //new IOpenGLVertexShader; |
1147 | |
1148 | - NString ProcessedShaderSource; |
1149 | - NString Defines(VtxShaderPreprocessorDefines); |
1150 | + std::string ProcessedShaderSource; |
1151 | + std::string Defines(VtxShaderPreprocessorDefines); |
1152 | InsertPreProcessorDefinitions(glslshader, ProcessedShaderSource, Defines); |
1153 | |
1154 | vs->SetShaderCode(glslshader); |
1155 | @@ -525,8 +529,8 @@ |
1156 | NUX_RETURN_IF_NULL(glslshader); |
1157 | ObjectPtr<IOpenGLPixelShader> ps = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader(); //new IOpenGLPixelShader; |
1158 | |
1159 | - NString ProcessedShaderSource; |
1160 | - NString Defines(FrgShaderPreprocessorDefines); |
1161 | + std::string ProcessedShaderSource; |
1162 | + std::string Defines(FrgShaderPreprocessorDefines); |
1163 | InsertPreProcessorDefinitions(glslshader, ProcessedShaderSource, Defines); |
1164 | |
1165 | ps->SetShaderCode(glslshader); |
1166 | @@ -607,7 +611,7 @@ |
1167 | { |
1168 | if (ShaderObjectList[i]->Compile() == false) |
1169 | { |
1170 | - nuxDebugMsg("[IOpenGLShaderProgram::Link] Attached shader %s does not compile with program: %s.", ShaderObjectList[i]->_ShaderName.GetTCharPtr(), _ShaderProgramName.GetTCharPtr()); |
1171 | + nuxDebugMsg("[IOpenGLShaderProgram::Link] Attached shader %s does not compile with program: %s.", ShaderObjectList[i]->_ShaderName.c_str(), _ShaderProgramName.c_str()); |
1172 | } |
1173 | } |
1174 | |
1175 | @@ -793,13 +797,13 @@ |
1176 | |
1177 | while (m_CompiledAndReady && parameter) |
1178 | { |
1179 | - int location = glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.GetTCharPtr())); |
1180 | - CHECKGL_MSG( glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.GetTCharPtr()))); |
1181 | + int location = glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.c_str())); |
1182 | + CHECKGL_MSG( glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.c_str()))); |
1183 | |
1184 | //nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Location index: %d", location); |
1185 | if (location == -1 && (!parameter->m_bIsOptional)) |
1186 | { |
1187 | - nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Couldn't find shader program parameter %s \n", parameter->m_Name.GetTCharPtr()); |
1188 | + nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Couldn't find shader program parameter %s \n", parameter->m_Name.c_str()); |
1189 | nuxAssert(0); |
1190 | } |
1191 | |
1192 | |
1193 | === modified file 'NuxGraphics/IOpenGLGLSLShader.h' |
1194 | --- NuxGraphics/IOpenGLGLSLShader.h 2011-10-19 20:32:38 +0000 |
1195 | +++ NuxGraphics/IOpenGLGLSLShader.h 2012-09-30 17:24:22 +0000 |
1196 | @@ -28,19 +28,19 @@ |
1197 | |
1198 | class IOpenGLResource; |
1199 | |
1200 | - bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString ShaderPreprocessorDefines = NString("")); |
1201 | + bool ExtractShaderString3(const std::string &ShaderToken, const std::string &ShaderSource, std::string &RetSource, std::string ShaderPreprocessorDefines = std::string("")); |
1202 | |
1203 | class IOpenGLShader: public IOpenGLResource |
1204 | { |
1205 | NUX_DECLARE_OBJECT_TYPE(IOpenGLShader, IOpenGLResource); |
1206 | - IOpenGLShader(NString ShaderName, OpenGLResourceType ResourceType); |
1207 | + IOpenGLShader(std::string ShaderName, OpenGLResourceType ResourceType); |
1208 | virtual ~IOpenGLShader(); |
1209 | public: |
1210 | virtual void SetShaderCode(const ANSICHAR *ShaderCode, const char *ShaderPreprocessorDefines = "") = 0; |
1211 | virtual bool Compile() = 0; |
1212 | virtual bool IsValid() = 0; |
1213 | - NString _ShaderName; |
1214 | - NString _ShaderCode; |
1215 | + std::string _ShaderName; |
1216 | + std::string _ShaderCode; |
1217 | }; |
1218 | |
1219 | class IOpenGLVertexShader: public IOpenGLShader |
1220 | @@ -52,7 +52,7 @@ |
1221 | virtual bool Compile(); |
1222 | virtual bool IsValid(); |
1223 | private: |
1224 | - IOpenGLVertexShader(NString ShaderName = NString("Vertex Shader")); |
1225 | + IOpenGLVertexShader(std::string ShaderName = std::string("Vertex Shader")); |
1226 | int m_CompiledAndReady; |
1227 | friend class GpuDevice; |
1228 | }; |
1229 | @@ -66,7 +66,7 @@ |
1230 | virtual bool Compile(); |
1231 | virtual bool IsValid(); |
1232 | private: |
1233 | - IOpenGLPixelShader(NString ShaderName = NString("Fragment Shader")); |
1234 | + IOpenGLPixelShader(std::string ShaderName = std::string("Fragment Shader")); |
1235 | int m_CompiledAndReady; |
1236 | friend class GpuDevice; |
1237 | }; |
1238 | @@ -86,7 +86,7 @@ |
1239 | void SetMaxVertexOutput(int max_vertex_output); |
1240 | |
1241 | private: |
1242 | - IOpenGLGeometryShader(NString ShaderName = NString("Geometry Shader")); |
1243 | + IOpenGLGeometryShader(std::string ShaderName = std::string("Geometry Shader")); |
1244 | int m_CompiledAndReady; |
1245 | friend class GpuDevice; |
1246 | }; |
1247 | @@ -207,11 +207,11 @@ |
1248 | int GetAttributeLocation(const char *AttributeName); |
1249 | |
1250 | private: |
1251 | - IOpenGLShaderProgram(NString ShaderProgramName = NString("ShaderProgram")); |
1252 | + IOpenGLShaderProgram(std::string ShaderProgramName = std::string("ShaderProgram")); |
1253 | ShaderAttributeDefinition m_ProgramAttributeDefinition[16/*NUM_VERTEX_SHADER_INPUT_ATTRIBUTE*/]; |
1254 | std::vector<ObjectPtr<IOpenGLShader> > ShaderObjectList; |
1255 | bool m_CompiledAndReady; |
1256 | - NString _ShaderProgramName; |
1257 | + std::string _ShaderProgramName; |
1258 | friend class GpuDevice; |
1259 | }; |
1260 |
Looks OK.