Nux

Merge lp:~unity-team/nux/nux.gpudevice-cleanup into lp:nux

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
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::DrawIndexedPrimitive.
* 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::DrawIndexedPrimitive.
* 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 :

Looks OK.

review: Approve
Revision history for this message
Michi Henning (michihenning) wrote :

This also fixes Bug #1052765

Revision history for this message
Eleni Maria Stea (hikiko) wrote :

It seems OK!

review: Approve
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
=== modified file 'Nux/Theme.cpp'
--- Nux/Theme.cpp 2012-09-26 12:23:04 +0000
+++ Nux/Theme.cpp 2012-09-30 17:24:22 +0000
@@ -151,7 +151,10 @@
151 std::list<PainterImage*>::iterator it;151 std::list<PainterImage*>::iterator it;
152 for (it = painter_image_list_.begin(); it != painter_image_list_.end(); it++)152 for (it = painter_image_list_.begin(); it != painter_image_list_.end(); it++)
153 {153 {
154 (*it)->texture->UnReference();154 if ((*it)->texture)
155 {
156 (*it)->texture->UnReference();
157 }
155 delete(*it);158 delete(*it);
156 }159 }
157 painter_image_list_.clear();160 painter_image_list_.clear();
@@ -204,8 +207,8 @@
204 {207 {
205 BaseTexture* device_texture;208 BaseTexture* device_texture;
206209
207 NString texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(*value_cursor);210 std::string texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(*value_cursor);
208 device_texture = theme->Load2DTextureFile(texture_filename.GetTCharPtr());211 device_texture = theme->Load2DTextureFile(texture_filename.c_str());
209212
210 pimage->texture = device_texture;213 pimage->texture = device_texture;
211 }214 }
@@ -228,8 +231,8 @@
228231
229 void UXTheme::LoadPainterImages()232 void UXTheme::LoadPainterImages()
230 {233 {
231 NString file_search = "Painter.xml";234 std::string file_search = "Painter.xml";
232 NString painter_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(file_search.GetTCharPtr());235 std::string painter_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(file_search.c_str());
233236
234 if (painter_filename == "")237 if (painter_filename == "")
235 {238 {
@@ -253,10 +256,10 @@
253 this,256 this,
254 NULL);257 NULL);
255258
256 NString str;259 std::string str;
257 LoadFileToString(str, painter_filename.GetTCharPtr());260 LoadFileToString(str, painter_filename.c_str());
258261
259 if (g_markup_parse_context_parse(context, str.GetTCharPtr(), str.Length(), NULL) == FALSE)262 if (g_markup_parse_context_parse(context, str.c_str(), str.length(), NULL) == FALSE)
260 {263 {
261 nuxCriticalMsg("[GraphicsEngine::LoadPainterImages] Failed to parse data.");264 nuxCriticalMsg("[GraphicsEngine::LoadPainterImages] Failed to parse data.");
262 return;265 return;
@@ -264,7 +267,7 @@
264267
265#else268#else
266269
267 TiXmlDocument doc(painter_filename.GetTCharPtr());270 TiXmlDocument doc(painter_filename.c_str());
268 doc.LoadFile();271 doc.LoadFile();
269272
270 TiXmlHandle docHandle( &doc );273 TiXmlHandle docHandle( &doc );
@@ -273,12 +276,12 @@
273276
274 for (image = data->FirstChildElement(TCHARToUTF8("Image")); image; image = image->NextSiblingElement(TCHARToUTF8("Image")))277 for (image = data->FirstChildElement(TCHARToUTF8("Image")); image; image = image->NextSiblingElement(TCHARToUTF8("Image")))
275 {278 {
276 PainterImage *pimage = new PainterImage;279 PainterImage* pimage = new PainterImage;
277 Memset(pimage, 0, sizeof(PainterImage));280 Memset(pimage, 0, sizeof(PainterImage));
278281
279 NString style = image->Attribute(TCHARToUTF8("style"));282 std::string style = image->Attribute(TCHARToUTF8("style"));
280283
281 pimage->style = GetStyleImageRef(style.GetTCharPtr());284 pimage->style = GetStyleImageRef(style.c_str());
282285
283 // If the attributes border_left, border_right, border_top, border_bottom are not present, assume they are equal to 0;286 // If the attributes border_left, border_right, border_top, border_bottom are not present, assume they are equal to 0;
284 pimage->border_left = pimage->border_right = pimage->border_top = pimage->border_bottom = 0;287 pimage->border_left = pimage->border_right = pimage->border_top = pimage->border_bottom = 0;
@@ -309,16 +312,16 @@
309312
310 if (1)313 if (1)
311 {314 {
312 NString filename = image->Attribute(TCHARToUTF8("Name"));315 std::string filename = image->Attribute(TCHARToUTF8("Name"));
313 NString texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.GetTCharPtr());316 std::string texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.c_str());
314 pimage->texture = 0;317 pimage->texture = 0;
315 pimage->filename = texture_filename;318 pimage->filename = texture_filename;
316 }319 }
317 else320 else
318 {321 {
319 NString filename = image->Attribute(TCHARToUTF8("Name"));322 std::string filename = image->Attribute(TCHARToUTF8("Name"));
320 NString texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.GetTCharPtr());323 std::string texture_filename = NUX_FIND_RESOURCE_LOCATION_NOFAIL(filename.c_str());
321 pimage->texture = Load2DTextureFile(texture_filename.GetTCharPtr());324 pimage->texture = Load2DTextureFile(texture_filename.c_str());
322 }325 }
323326
324 painter_image_list_.push_back(pimage);327 painter_image_list_.push_back(pimage);
325328
=== modified file 'NuxCore/FileIO.cpp'
--- NuxCore/FileIO.cpp 2011-10-21 22:06:35 +0000
+++ NuxCore/FileIO.cpp 2012-09-30 17:24:22 +0000
@@ -229,10 +229,10 @@
229 }229 }
230230
231 /*!231 /*!
232 Load a text file to an NString. The file maybe ANSI or Unicode.232 Load a text file to an std::string. The file maybe ANSI or Unicode.
233 The resulting string is TCHAR.233 The resulting string is TCHAR.
234 */234 */
235 bool LoadFileToString ( NString &Result, const TCHAR *Filename, NFileManager &FileManager )235 bool LoadFileToString(std::string &Result, const TCHAR *Filename, NFileManager &FileManager)
236 {236 {
237 NSerializer *Reader = FileManager.CreateFileReader (Filename);237 NSerializer *Reader = FileManager.CreateFileReader (Filename);
238238
@@ -318,9 +318,9 @@
318 /*!318 /*!
319 Save string to File. Attempt to write it as ASCII if possible. If not write as UTF16-BE.319 Save string to File. Attempt to write it as ASCII if possible. If not write as UTF16-BE.
320 */320 */
321 bool SaveStringToFile ( const NString &String, const TCHAR *Filename, NFileManager &FileManager )321 bool SaveStringToFile(const std::string &String, const TCHAR *Filename, NFileManager &FileManager)
322 {322 {
323 if ( !String.Length() )323 if ( !String.length() )
324 return 0;324 return 0;
325325
326 NSerializer *Ar = FileManager.CreateFileWriter ( Filename );326 NSerializer *Ar = FileManager.CreateFileWriter ( Filename );
@@ -347,20 +347,20 @@
347347
348 if ( SaveAsUnicode || (sizeof (TCHAR) == 1) )348 if ( SaveAsUnicode || (sizeof (TCHAR) == 1) )
349 {349 {
350 unsigned int s = (unsigned int) String.Length() * sizeof (TCHAR);350 unsigned int s = (unsigned int) String.length() * sizeof (TCHAR);
351 Ar->Serialize ( NUX_CONST_CAST (TCHAR *, String.GetTCharPtr() ), (unsigned int) s);351 Ar->Serialize(NUX_CONST_CAST(TCHAR *, String.c_str()), (unsigned int) s);
352 }352 }
353 else353 else
354 {354 {
355 unsigned int s = (unsigned int) String.Length();355 unsigned int s = (unsigned int) String.length();
356 std::vector<ANSICHAR> AnsiBuffer ( (unsigned int) s);356 std::vector<ANSICHAR> AnsiBuffer ( (unsigned int) s);
357357
358 // Cast all character down from UTF16 to ANSI358 // Cast all character down from UTF16 to ANSI
359 for (unsigned int i = 0; i < (unsigned int) String.Length(); i++ )359 for (unsigned int i = 0; i < (unsigned int) String.length(); i++)
360 AnsiBuffer[i] = ConvertTCHARToAnsiChar ( (unsigned int) String[i]);360 AnsiBuffer[i] = ConvertTCHARToAnsiChar ( (unsigned int) String[i]);
361361
362 // serialize362 // serialize
363 s = (unsigned int) String.Length();363 s = (unsigned int) String.length();
364 Ar->Serialize ( NUX_CONST_CAST (ANSICHAR *, &AnsiBuffer[0]), s);364 Ar->Serialize ( NUX_CONST_CAST (ANSICHAR *, &AnsiBuffer[0]), s);
365 }365 }
366366
367367
=== modified file 'NuxCore/FileIO.h'
--- NuxCore/FileIO.h 2011-04-06 21:54:09 +0000
+++ NuxCore/FileIO.h 2012-09-30 17:24:22 +0000
@@ -29,9 +29,9 @@
29 bool LoadFileToArray ( std::vector<BYTE>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );29 bool LoadFileToArray ( std::vector<BYTE>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
30 bool LoadTextFileToAnsiArray ( std::vector<ANSICHAR>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );30 bool LoadTextFileToAnsiArray ( std::vector<ANSICHAR>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
31 bool LoadTextFileToUnicodeArray ( std::vector<UNICHAR>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );31 bool LoadTextFileToUnicodeArray ( std::vector<UNICHAR>& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
32 bool LoadFileToString ( NString &Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );32 bool LoadFileToString(std::string &Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
33 bool SaveArrayToFile ( const std::vector<BYTE>& Array, const TCHAR *Filename, NFileManager &FileManager = GFileManager );33 bool SaveArrayToFile(const std::vector<BYTE>& Array, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
34 bool SaveStringToFile ( const NString &String, const TCHAR *Filename, NFileManager &FileManager = GFileManager );34 bool SaveStringToFile(const std::string &String, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
3535
36}36}
3737
3838
=== modified file 'NuxGraphics/FontRenderer.cpp'
--- NuxGraphics/FontRenderer.cpp 2012-08-27 09:09:21 +0000
+++ NuxGraphics/FontRenderer.cpp 2012-09-30 17:24:22 +0000
@@ -179,7 +179,7 @@
179 if (NumCharacter == 0)179 if (NumCharacter == 0)
180 NumChar = str_len;180 NumChar = str_len;
181 else181 else
182 NumChar = std::min(str_len, NumCharacter);182 NumChar = std::min<int>(str_len, NumCharacter);
183183
184 strBBox.width = Font->GetStringWidth(str, NumChar);184 strBBox.width = Font->GetStringWidth(str, NumChar);
185 strBBox.height = Font->GetLineHeight();185 strBBox.height = Font->GetLineHeight();
@@ -323,7 +323,7 @@
323 nuxAssertMsg(StartCharacter >= 0, "[FontRenderer::RenderText] Incorrect value for StartCharacter.");323 nuxAssertMsg(StartCharacter >= 0, "[FontRenderer::RenderText] Incorrect value for StartCharacter.");
324 nuxAssertMsg(StartCharacter <= StrLength, "[FontRenderer::RenderText] Incorrect value for StartCharacter.");324 nuxAssertMsg(StartCharacter <= StrLength, "[FontRenderer::RenderText] Incorrect value for StartCharacter.");
325325
326 int NumCharToDraw = std::min(StrLength - StartCharacter, NumCharacters);326 int NumCharToDraw = std::min<int>(StrLength - StartCharacter, NumCharacters);
327327
328 if (NumCharToDraw <= 0)328 if (NumCharToDraw <= 0)
329 return 0;329 return 0;
330330
=== modified file 'NuxGraphics/GLError.cpp'
--- NuxGraphics/GLError.cpp 2012-09-17 09:55:43 +0000
+++ NuxGraphics/GLError.cpp 2012-09-30 17:24:22 +0000
@@ -83,8 +83,10 @@
83 if (logger.IsWarningEnabled() && !error_msg.empty())83 if (logger.IsWarningEnabled() && !error_msg.empty())
84 {84 {
85 std::string stacktrace;85 std::string stacktrace;
86#if defined(NUX_OS_LINUX)
86 if (debug_glerror_stack())87 if (debug_glerror_stack())
87 stacktrace = "\n" + logging::Backtrace();88 stacktrace = "\n" + logging::Backtrace();
89#endif
88 logging::LogStream(logging::Warning, logger.module(), file, line).stream()90 logging::LogStream(logging::Warning, logger.module(), file, line).stream()
89#ifndef NUX_OPENGLES_2091#ifndef NUX_OPENGLES_20
90 << "[CheckGLError] OpenGL Error " << glErr << " (" << gluErrorString(glErr) << ")"92 << "[CheckGLError] OpenGL Error " << glErr << " (" << gluErrorString(glErr) << ")"
9193
=== modified file 'NuxGraphics/GLRenderStates.cpp'
--- NuxGraphics/GLRenderStates.cpp 2012-02-21 06:57:05 +0000
+++ NuxGraphics/GLRenderStates.cpp 2012-09-30 17:24:22 +0000
@@ -113,8 +113,8 @@
113113
114 GpuRenderStates::GpuRenderStates(GpuBrand board, GpuInfo* info)114 GpuRenderStates::GpuRenderStates(GpuBrand board, GpuInfo* info)
115 {115 {
116 _gpu_brand = board;116 gpu_brand_ = board;
117 _gpu_info = info;117 gpu_info_ = info;
118 Memcpy(&render_state_changes_, &s_StateLUT.default_render_state, sizeof(render_state_changes_));118 Memcpy(&render_state_changes_, &s_StateLUT.default_render_state, sizeof(render_state_changes_));
119 }119 }
120120
121121
=== modified file 'NuxGraphics/GLRenderStates.h'
--- NuxGraphics/GLRenderStates.h 2012-02-21 06:18:24 +0000
+++ NuxGraphics/GLRenderStates.h 2012-09-30 17:24:22 +0000
@@ -264,8 +264,8 @@
264264
265 private:265 private:
266266
267 GpuBrand _gpu_brand;267 GpuBrand gpu_brand_;
268 GpuInfo *_gpu_info;268 GpuInfo* gpu_info_;
269269
270 inline void HW__EnableAlphaTest(unsigned int b);270 inline void HW__EnableAlphaTest(unsigned int b);
271271
@@ -963,11 +963,11 @@
963 (BlendOpAlpha_ == GL_MAX),963 (BlendOpAlpha_ == GL_MAX),
964 "Error(HW__SetAlphaBlendOp): Invalid Blend Equation RenderState");964 "Error(HW__SetAlphaBlendOp): Invalid Blend Equation RenderState");
965965
966 if (_gpu_info->SupportOpenGL20())966 if (gpu_info_->SupportOpenGL20())
967 {967 {
968 CHECKGL(glBlendEquationSeparate(BlendOpRGB_, BlendOpAlpha_));968 CHECKGL(glBlendEquationSeparate(BlendOpRGB_, BlendOpAlpha_));
969 }969 }
970 else if (_gpu_info->Support_EXT_Blend_Equation_Separate())970 else if (gpu_info_->Support_EXT_Blend_Equation_Separate())
971 {971 {
972 CHECKGL(glBlendEquationSeparateEXT(BlendOpRGB_, BlendOpAlpha_));972 CHECKGL(glBlendEquationSeparateEXT(BlendOpRGB_, BlendOpAlpha_));
973 }973 }
@@ -1138,7 +1138,7 @@
1138 {1138 {
1139 if (b)1139 if (b)
1140 {1140 {
1141 if (_gpu_brand == GPU_BRAND_AMD)1141 if (gpu_brand_ == GPU_BRAND_AMD)
1142 {1142 {
1143 CHECKGL(glEnable(GL_STENCIL_TEST));1143 CHECKGL(glEnable(GL_STENCIL_TEST));
1144 }1144 }
@@ -1149,7 +1149,7 @@
1149 }1149 }
1150 else1150 else
1151 {1151 {
1152 if (_gpu_brand == GPU_BRAND_AMD)1152 if (gpu_brand_ == GPU_BRAND_AMD)
1153 {1153 {
1154 CHECKGL(glDisable(GL_STENCIL_TEST));1154 CHECKGL(glDisable(GL_STENCIL_TEST));
1155 }1155 }
@@ -1215,7 +1215,7 @@
1215 (Func_ == GL_ALWAYS),1215 (Func_ == GL_ALWAYS),
1216 "Error(HW__SetBackFaceStencilFunc): Invalid Stencil Function RenderState");1216 "Error(HW__SetBackFaceStencilFunc): Invalid Stencil Function RenderState");
12171217
1218 if (_gpu_brand == GPU_BRAND_AMD)1218 if (gpu_brand_ == GPU_BRAND_AMD)
1219 {1219 {
1220 CHECKGL(glStencilFuncSeparateATI(Func_/*Front function*/, Func_/*Back function*/, Ref_, Mask_)); // incorrect1220 CHECKGL(glStencilFuncSeparateATI(Func_/*Front function*/, Func_/*Back function*/, Ref_, Mask_)); // incorrect
1221 }1221 }
@@ -1268,7 +1268,7 @@
1268 (ZPassOp_ == GL_INVERT),1268 (ZPassOp_ == GL_INVERT),
1269 "Error(HW__SetFrontFaceStencilOp): Invalid ZPassOp RenderState");1269 "Error(HW__SetFrontFaceStencilOp): Invalid ZPassOp RenderState");
12701270
1271 if (_gpu_brand == GPU_BRAND_AMD)1271 if (gpu_brand_ == GPU_BRAND_AMD)
1272 {1272 {
1273 CHECKGL(glStencilOpSeparateATI(GL_FRONT, FailOp_, ZFailOp_, ZPassOp_));1273 CHECKGL(glStencilOpSeparateATI(GL_FRONT, FailOp_, ZFailOp_, ZPassOp_));
1274 }1274 }
@@ -1321,7 +1321,7 @@
1321 (ZPassOp_ == GL_INVERT),1321 (ZPassOp_ == GL_INVERT),
1322 "Error(HW__SetBackFaceStencilOp): Invalid ZPassOp RenderState");1322 "Error(HW__SetBackFaceStencilOp): Invalid ZPassOp RenderState");
13231323
1324 if (_gpu_brand == GPU_BRAND_AMD)1324 if (gpu_brand_ == GPU_BRAND_AMD)
1325 {1325 {
1326 CHECKGL(glStencilOpSeparateATI(GL_BACK, FailOp_, ZFailOp_, ZPassOp_));1326 CHECKGL(glStencilOpSeparateATI(GL_BACK, FailOp_, ZFailOp_, ZPassOp_));
1327 }1327 }
13281328
=== modified file 'NuxGraphics/GLShaderParameter.h'
--- NuxGraphics/GLShaderParameter.h 2011-10-19 20:32:38 +0000
+++ NuxGraphics/GLShaderParameter.h 2012-09-30 17:24:22 +0000
@@ -50,8 +50,8 @@
50 {50 {
51 public:51 public:
52 int m_Index; // Register m_Index / Attribute m_Index52 int m_Index; // Register m_Index / Attribute m_Index
53 eShaderParameterType m_ShaderParameterType;53 eShaderParameterType m_ShaderParameterType;
54 NString m_Name;54 std::string m_Name;
55 bool m_bIsOptional;55 bool m_bIsOptional;
56 bool m_bIsStatic;56 bool m_bIsStatic;
57 bool bStaticSet;57 bool bStaticSet;
5858
=== modified file 'NuxGraphics/GpuDevice.cpp'
--- NuxGraphics/GpuDevice.cpp 2012-09-19 04:53:45 +0000
+++ NuxGraphics/GpuDevice.cpp 2012-09-30 17:24:22 +0000
@@ -32,6 +32,8 @@
32#include "GLTemplatePrimitiveBuffer.h"32#include "GLTemplatePrimitiveBuffer.h"
33#include "GraphicsEngine.h"33#include "GraphicsEngine.h"
3434
35#include <algorithm>
36
35namespace nux37namespace nux
36{38{
37#if (NUX_ENABLE_CG_SHADERS)39#if (NUX_ENABLE_CG_SHADERS)
@@ -299,11 +301,14 @@
299 bool opengl_es_20)301 bool opengl_es_20)
300#endif302#endif
301#endif303#endif
304 : opengl_major_(0)
305 , opengl_minor_(0)
306 , use_pixel_buffer_object_(false)
307 , pixel_store_alignment_(4)
308 , gpu_render_states_(NULL)
309 , gpu_info_(NULL)
302 {310 {
303 _PixelStoreAlignment = 4;311 gpu_brand_ = GPU_VENDOR_UNKNOWN;
304 _UsePixelBufferObject = false;
305 _gpu_info = NULL;
306 _gpu_brand = GPU_VENDOR_UNKNOWN;
307312
308#ifndef NUX_OPENGLES_20 313#ifndef NUX_OPENGLES_20
309 // OpenGL extension initialization314 // OpenGL extension initialization
@@ -328,35 +333,70 @@
328#endif333#endif
329334
330#ifndef NUX_OPENGLES_20335#ifndef NUX_OPENGLES_20
331 _glsl_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION)));336 _openGL_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION)));
332 CHECKGL_MSG(glGetString(GL_VERSION));337 CHECKGL_MSG(glGetString(GL_VERSION));
333338
334 NString opengl_major;339 // We need OpenGL minor and major version. Before OpenGL 3.0, the version number was reported as a string of format
335 NString opengl_minor;340 // "major.minor". That string has to be parsed to extract the major and minor version numbers. This is not really safe as
336 char split = '.';341 // we have no guaranty that the version string is has we think it is. Some drivers report a version string like "xx.xx.xx".
337 _glsl_version_string.SplitAtFirstOccurenceOf(split, opengl_major, opengl_minor);342
338343 // Begin string parsing to extract the major and minor version numbers.
339 _opengl_major = (char)opengl_major.GetTCharPtr()[0] - '0';344 std::string opengl_major;
340 _opengl_minor = (char)opengl_minor.GetTCharPtr()[0] - '0';345 std::string opengl_minor;
341346 std::string split = ".";
342 if (_opengl_major >= 3)347
343 {348 size_t pos = 0;
344 CHECKGL(glGetIntegerv(GL_MAJOR_VERSION, &_opengl_major));349 pos = _openGL_version_string.find(split, pos);
345 CHECKGL(glGetIntegerv(GL_MINOR_VERSION, &_opengl_minor));350
351 if (pos != tstring::npos)
352 {
353 size_t split_string_size = split.length();
354 opengl_major = _openGL_version_string.substr(0, pos);
355 opengl_minor = _openGL_version_string.substr(pos + split_string_size, _openGL_version_string.length() - (pos + split_string_size) );
356 }
357
358 int major_length = opengl_major.length();
359 opengl_major_ = 0;
360 int digit_position = 1;
361 while (major_length && (opengl_major.c_str()[major_length-1] >= '0') && (opengl_major.c_str()[major_length-1] <= '9'))
362 {
363 opengl_major_ += (opengl_major.c_str()[major_length-1] - '0') * digit_position;
364
365 digit_position *= 10;
366 --major_length;
367 }
368
369 int minor_length = opengl_minor.length();
370 opengl_minor_ = 0;
371 digit_position = 0;
372 while (minor_length && (opengl_minor.c_str()[digit_position] >= '0') && (opengl_minor.c_str()[digit_position] <= '9'))
373 {
374 opengl_minor_ += opengl_minor_ * 10 + (opengl_minor.c_str()[digit_position] - '0');
375
376 ++digit_position;
377 --minor_length;
378 }
379
380 // End string parsing
381
382 if (opengl_major_ >= 3)
383 {
384 CHECKGL(glGetIntegerv(GL_MAJOR_VERSION, &opengl_major_));
385 CHECKGL(glGetIntegerv(GL_MINOR_VERSION, &opengl_minor_));
346 }386 }
347#else387#else
348 _opengl_major = 2;388 opengl_major_ = 2;
349 _opengl_minor = 0;389 opengl_minor_ = 0;
350#endif390#endif
351391
352#if defined(NUX_OS_WINDOWS)392#if defined(NUX_OS_WINDOWS)
353 bool opengl_es_context_created = false;393 bool opengl_es_context_created = false;
354 if (((_opengl_major >= 3) && (req_opengl_major >= 3)) || (_opengl_major >= 3) || opengl_es_20)394 if (((opengl_major_ >= 3) && (req_opengl_major >= 3)) || (opengl_major_ >= 3) || opengl_es_20)
355#elif defined(NUX_OS_LINUX)395#elif defined(NUX_OS_LINUX)
356 //bool opengl_es_context_created = false;396 //bool opengl_es_context_created = false;
357 if (has_glx_13_support &&397 if (has_glx_13_support &&
358 (((_opengl_major >= 3) && (req_opengl_major >= 3)) ||398 (((opengl_major_ >= 3) && (req_opengl_major >= 3)) ||
359 ((_opengl_major >= 3) && opengl_es_20)))399 ((opengl_major_ >= 3) && opengl_es_20)))
360#endif400#endif
361 {401 {
362 // Create a new Opengl Rendering Context402 // Create a new Opengl Rendering Context
@@ -367,22 +407,22 @@
367 if ((OpenGLVersionTable[index].major == req_opengl_major) &&407 if ((OpenGLVersionTable[index].major == req_opengl_major) &&
368 (OpenGLVersionTable[index].minor == req_opengl_minor))408 (OpenGLVersionTable[index].minor == req_opengl_minor))
369 {409 {
370 if (_opengl_major == 1)410 if (opengl_major_ == 1)
371 {411 {
372 if ((req_opengl_major == 1) && (req_opengl_minor >= 0) && (req_opengl_minor <= 5))412 if ((req_opengl_major == 1) && (req_opengl_minor >= 0) && (req_opengl_minor <= 5))
373 requested_profile_is_supported = true;413 requested_profile_is_supported = true;
374 }414 }
375 else if (_opengl_major == 2)415 else if (opengl_major_ == 2)
376 {416 {
377 if ((req_opengl_major == 2) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1))417 if ((req_opengl_major == 2) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1))
378 requested_profile_is_supported = true;418 requested_profile_is_supported = true;
379 }419 }
380 else if (_opengl_major == 3)420 else if (opengl_major_ == 3)
381 {421 {
382 if ((req_opengl_major == 3) && (req_opengl_minor >= 0) && (req_opengl_minor <= 3))422 if ((req_opengl_major == 3) && (req_opengl_minor >= 0) && (req_opengl_minor <= 3))
383 requested_profile_is_supported = true;423 requested_profile_is_supported = true;
384 }424 }
385 else if (_opengl_major == 4)425 else if (opengl_major_ == 4)
386 {426 {
387 if ((req_opengl_major == 4) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1))427 if ((req_opengl_major == 4) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1))
388 requested_profile_is_supported = true;428 requested_profile_is_supported = true;
@@ -528,43 +568,32 @@
528 _openGL_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION)));568 _openGL_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION)));
529 CHECKGL_MSG(glGetString(GL_VERSION));569 CHECKGL_MSG(glGetString(GL_VERSION));
530570
531 nuxDebugMsg("Gpu Vendor: %s", _board_vendor_string.GetTCharPtr());571 nuxDebugMsg("Gpu Vendor: %s", _board_vendor_string.c_str());
532 nuxDebugMsg("Gpu Renderer: %s", _board_renderer_string.GetTCharPtr());572 nuxDebugMsg("Gpu Renderer: %s", _board_renderer_string.c_str());
533 nuxDebugMsg("Gpu OpenGL Version: %s", _openGL_version_string.GetTCharPtr());573 nuxDebugMsg("Gpu OpenGL Version: %s", _openGL_version_string.c_str());
534 nuxDebugMsg("Gpu OpenGL Major Version: %d", _opengl_major);574 nuxDebugMsg("Gpu OpenGL Major Version: %d", opengl_major_);
535 nuxDebugMsg("Gpu OpenGL Minor Version: %d", _opengl_minor);575 nuxDebugMsg("Gpu OpenGL Minor Version: %d", opengl_minor_);
536 nuxDebugMsg("Gpu GLSL Version: %s", _glsl_version_string.GetTCharPtr());576
537577 std::transform(_board_vendor_string.begin(), _board_vendor_string.end(), _board_vendor_string.begin(), ::toupper);
538 NString TempStr = (const char *) TCharToUpperCase(_board_vendor_string.GetTCharPtr());578
539579 if (_board_vendor_string.find("NVIDIA", 0) != tstring::npos)
540 if (TempStr.FindFirstOccurence("NVIDIA") != tstring::npos)580 {
541 {581 gpu_brand_ = GPU_BRAND_NVIDIA;
542 _gpu_brand = GPU_BRAND_NVIDIA;582 }
543 }583 else if (_board_vendor_string.find("ATI", 0) != tstring::npos)
544 else if (TempStr.FindFirstOccurence("ATI") != tstring::npos)584 {
545 {585 gpu_brand_ = GPU_BRAND_AMD;
546 _gpu_brand = GPU_BRAND_AMD;586 }
547 }587 else if (_board_vendor_string.find("TUNGSTEN", 0) != tstring::npos)
548 else if (TempStr.FindFirstOccurence("TUNGSTEN") != tstring::npos)588 {
549 {589 gpu_brand_ = GPU_BRAND_INTEL;
550 _gpu_brand = GPU_BRAND_INTEL;590 }
551 }591
552592 use_pixel_buffer_object_ = false;
553 if (0)593
554 {594 gpu_info_ = new GpuInfo();
555 if (GetGPUBrand() == GPU_BRAND_AMD)595 gpu_info_->Setup();
556 _UsePixelBufferObject = false;596 gpu_render_states_ = new GpuRenderStates(gpu_brand_, gpu_info_);
557 else
558 _UsePixelBufferObject = true;
559 }
560 else
561 {
562 _UsePixelBufferObject = false;
563 }
564
565 _gpu_info = new GpuInfo();
566 _gpu_info->Setup();
567 _gpu_render_states = new GpuRenderStates(_gpu_brand, _gpu_info);
568597
569#if defined(NUX_OS_WINDOWS)598#if defined(NUX_OS_WINDOWS)
570 OGL_EXT_SWAP_CONTROL = WGLEW_EXT_swap_control ? true : false;599 OGL_EXT_SWAP_CONTROL = WGLEW_EXT_swap_control ? true : false;
@@ -579,8 +608,8 @@
579 // http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/608 // http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
580 // We use a pack /unpack alignment to 1 so we don't have any padding at the end of row.609 // We use a pack /unpack alignment to 1 so we don't have any padding at the end of row.
581610
582 CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, _PixelStoreAlignment));611 CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, pixel_store_alignment_));
583 CHECKGL(glPixelStorei(GL_PACK_ALIGNMENT, _PixelStoreAlignment));612 CHECKGL(glPixelStorei(GL_PACK_ALIGNMENT, pixel_store_alignment_));
584613
585// _DeviceWidth = DeviceWidth;614// _DeviceWidth = DeviceWidth;
586// _DeviceHeight = DeviceHeight;615// _DeviceHeight = DeviceHeight;
@@ -619,8 +648,8 @@
619648
620 GpuDevice::~GpuDevice()649 GpuDevice::~GpuDevice()
621 {650 {
622 NUX_SAFE_DELETE(_gpu_info);651 NUX_SAFE_DELETE(gpu_info_);
623 NUX_SAFE_DELETE(_gpu_render_states);652 NUX_SAFE_DELETE(gpu_render_states_);
624653
625 _FrameBufferObject.Release();654 _FrameBufferObject.Release();
626 active_framebuffer_object_.Release();655 active_framebuffer_object_.Release();
@@ -656,37 +685,47 @@
656685
657 int GpuDevice::GetOpenGLMajorVersion() const686 int GpuDevice::GetOpenGLMajorVersion() const
658 {687 {
659 return _opengl_major;688 return opengl_major_;
660 }689 }
661690
662 int GpuDevice::GetOpenGLMinorVersion() const691 int GpuDevice::GetOpenGLMinorVersion() const
663 {692 {
664 return _opengl_minor;693 return opengl_minor_;
694 }
695
696 unsigned int GpuDevice::GetPixelStoreAlignment() const
697 {
698 return pixel_store_alignment_;
699 }
700
701 bool GpuDevice::UsePixelBufferObjects() const
702 {
703 return use_pixel_buffer_object_;
665 }704 }
666705
667 GpuBrand GpuDevice::GetGPUBrand() const706 GpuBrand GpuDevice::GetGPUBrand() const
668 {707 {
669 return _gpu_brand;708 return gpu_brand_;
670 }709 }
671710
672 GpuRenderStates &GpuDevice::GetRenderStates()711 GpuRenderStates &GpuDevice::GetRenderStates()
673 {712 {
674 return *_gpu_render_states;713 return *gpu_render_states_;
675 }714 }
676715
677 GpuInfo &GpuDevice::GetGpuInfo()716 const GpuInfo& GpuDevice::GetGpuInfo() const
678 {717 {
679 return *_gpu_info;718 return *gpu_info_;
680 }719 }
681720
682 void GpuDevice::ResetRenderStates()721 void GpuDevice::ResetRenderStates()
683 {722 {
684 _gpu_render_states->ResetStateChangeToDefault();723 gpu_render_states_->ResetStateChangeToDefault();
685 }724 }
686725
687 void GpuDevice::VerifyRenderStates()726 void GpuDevice::VerifyRenderStates()
688 {727 {
689 _gpu_render_states->CheckStateChange();728 gpu_render_states_->CheckStateChange();
690 }729 }
691730
692 void GpuDevice::InvalidateTextureUnit(int TextureUnitIndex)731 void GpuDevice::InvalidateTextureUnit(int TextureUnitIndex)
693732
=== modified file 'NuxGraphics/GpuDevice.h'
--- NuxGraphics/GpuDevice.h 2012-09-17 09:55:43 +0000
+++ NuxGraphics/GpuDevice.h 2012-09-30 17:24:22 +0000
@@ -362,11 +362,6 @@
362 //! Setup a NULL texture362 //! Setup a NULL texture
363 void InvalidateTextureUnit(int TextureUnitIndex);363 void InvalidateTextureUnit(int TextureUnitIndex);
364364
365 unsigned int GetPixelStoreAlignment()
366 {
367 return _PixelStoreAlignment;
368 }
369
370 int AllocateUnpackPixelBufferIndex(int *index);365 int AllocateUnpackPixelBufferIndex(int *index);
371 int FreeUnpackPixelBufferIndex(const int index);366 int FreeUnpackPixelBufferIndex(const int index);
372 int BindUnpackPixelBufferIndex(const int index);367 int BindUnpackPixelBufferIndex(const int index);
@@ -389,6 +384,8 @@
389 //! Restore the backbuffer as the render target.384 //! Restore the backbuffer as the render target.
390 void DeactivateFrameBuffer(); 385 void DeactivateFrameBuffer();
391386
387 unsigned int GetPixelStoreAlignment() const;
388
392 public:389 public:
393 void SetCurrentFrameBufferObject(ObjectPtr<IOpenGLFrameBufferObject> fbo);390 void SetCurrentFrameBufferObject(ObjectPtr<IOpenGLFrameBufferObject> fbo);
394 ObjectPtr<IOpenGLFrameBufferObject> GetCurrentFrameBufferObject();391 ObjectPtr<IOpenGLFrameBufferObject> GetCurrentFrameBufferObject();
@@ -409,10 +406,6 @@
409 bool IsReserved;406 bool IsReserved;
410 };407 };
411408
412 unsigned int _PixelStoreAlignment;
413
414 std::vector<PixelBufferObject> _PixelBufferArray;
415
416 public:409 public:
417410
418#if (NUX_ENABLE_CG_SHADERS)411#if (NUX_ENABLE_CG_SHADERS)
@@ -423,16 +416,13 @@
423 CGcontext m_Cgcontext;416 CGcontext m_Cgcontext;
424#endif417#endif
425418
426 inline bool UsePixelBufferObjects() const419 bool UsePixelBufferObjects() const;
427 {
428 return _UsePixelBufferObject;
429 }
430420
431 GpuBrand GetGPUBrand() const;421 GpuBrand GetGPUBrand() const;
432422
433 GpuRenderStates &GetRenderStates();423 GpuRenderStates& GetRenderStates();
434424
435 GpuInfo &GetGpuInfo();425 const GpuInfo& GetGpuInfo() const;
436426
437 void ResetRenderStates();427 void ResetRenderStates();
438428
@@ -460,34 +450,34 @@
460450
461 bool SUPPORT_GL_ARB_TEXTURE_NON_POWER_OF_TWO() const451 bool SUPPORT_GL_ARB_TEXTURE_NON_POWER_OF_TWO() const
462 {452 {
463 return _gpu_info->Support_ARB_Texture_Non_Power_Of_Two();453 return gpu_info_->Support_ARB_Texture_Non_Power_Of_Two();
464 }454 }
465455
466 bool SUPPORT_GL_EXT_TEXTURE_RECTANGLE() const456 bool SUPPORT_GL_EXT_TEXTURE_RECTANGLE() const
467 {457 {
468 return _gpu_info->Support_EXT_Texture_Rectangle();458 return gpu_info_->Support_EXT_Texture_Rectangle();
469 }459 }
470460
471 bool SUPPORT_GL_ARB_TEXTURE_RECTANGLE() const461 bool SUPPORT_GL_ARB_TEXTURE_RECTANGLE() const
472 {462 {
473 return _gpu_info->Support_ARB_Texture_Rectangle();463 return gpu_info_->Support_ARB_Texture_Rectangle();
474 }464 }
475 465
476 private:466 private:
477467
478 // 468 //
479 int _opengl_major; //!< OpenGL major version.469 int opengl_major_; //!< OpenGL major version.
480 int _opengl_minor; //!< OpenGL minor version.470 int opengl_minor_; //!< OpenGL minor version.
481 int _glsl_version_major; //!< GLSL major version.471
482 int _glsl_version_minor; //!< GLSL major version.472 std::string _board_vendor_string; //!< GPU vendor sting.
483473 std::string _board_renderer_string; //!< GPU renderer sting.
484 NString _board_vendor_string; //!< GPU vendor sting.474 std::string _openGL_version_string; //!< OpenGL version string.
485 NString _board_renderer_string; //!< GPU renderer sting.475 GpuBrand gpu_brand_; //!< GPU brand.
486 NString _openGL_version_string; //!< OpenGL version string.476
487 NString _glsl_version_string; //!< GLSL version string.477 bool use_pixel_buffer_object_;
488 GpuBrand _gpu_brand; //!< GPU brand.478 unsigned int pixel_store_alignment_;
489479 std::vector<PixelBufferObject> _PixelBufferArray;
490 bool _UsePixelBufferObject;480
491481
492 bool OGL_EXT_SWAP_CONTROL;482 bool OGL_EXT_SWAP_CONTROL;
493 bool GL_ARB_VERTEX_PROGRAM;483 bool GL_ARB_VERTEX_PROGRAM;
@@ -504,8 +494,8 @@
504 bool GL_ARB_TEXTURE_RECTANGLE; //!< Promoted from GL_EXT_TEXTURE_RECTANGLE to ARB.494 bool GL_ARB_TEXTURE_RECTANGLE; //!< Promoted from GL_EXT_TEXTURE_RECTANGLE to ARB.
505 bool GL_NV_TEXTURE_RECTANGLE;495 bool GL_NV_TEXTURE_RECTANGLE;
506496
507 GpuRenderStates *_gpu_render_states;497 GpuRenderStates* gpu_render_states_;
508 GpuInfo *_gpu_info;498 GpuInfo* gpu_info_;
509499
510 public:500 public:
511 501
512502
=== modified file 'NuxGraphics/GpuDeviceVertex.cpp'
--- NuxGraphics/GpuDeviceVertex.cpp 2012-09-19 04:53:45 +0000
+++ NuxGraphics/GpuDeviceVertex.cpp 2012-09-30 17:24:22 +0000
@@ -160,7 +160,7 @@
160 vtxelement.Type,160 vtxelement.Type,
161 GL_FALSE,161 GL_FALSE,
162 vtxelement.stride_,162 vtxelement.stride_,
163 (void*)vtxelement.Offset)); // TODO: Bug. It doesn't make sense to convert a 4-byte int into an 8-byte pointer.163 (void*)&vtxelement.Offset));
164164
165 VertexDeclaration->_valid_vertex_input[shader_attribute_location] = 1;165 VertexDeclaration->_valid_vertex_input[shader_attribute_location] = 1;
166 ++decl;166 ++decl;
167167
=== modified file 'NuxGraphics/GraphicsEngine.cpp'
--- NuxGraphics/GraphicsEngine.cpp 2012-09-17 09:55:43 +0000
+++ NuxGraphics/GraphicsEngine.cpp 2012-09-30 17:24:22 +0000
@@ -230,7 +230,7 @@
230 }230 }
231#endif231#endif
232232
233 GpuInfo& gpu_info = _graphics_display.GetGpuDevice()->GetGpuInfo();233 const GpuInfo& gpu_info = _graphics_display.GetGpuDevice()->GetGpuInfo();
234234
235 if ((gpu_info.Support_ARB_Vertex_Program() && gpu_info.Support_ARB_Fragment_Program())235 if ((gpu_info.Support_ARB_Vertex_Program() && gpu_info.Support_ARB_Fragment_Program())
236 || (gpu_info.Support_ARB_Vertex_Shader() && gpu_info.Support_ARB_Fragment_Shader()))236 || (gpu_info.Support_ARB_Vertex_Shader() && gpu_info.Support_ARB_Fragment_Shader()))
237237
=== modified file 'NuxGraphics/GraphicsEngine.h'
--- NuxGraphics/GraphicsEngine.h 2012-09-19 04:53:45 +0000
+++ NuxGraphics/GraphicsEngine.h 2012-09-30 17:24:22 +0000
@@ -662,15 +662,15 @@
662662
663 GpuRenderStates& GetRenderStates()663 GpuRenderStates& GetRenderStates()
664 {664 {
665 return *_graphics_display.m_DeviceFactory->_gpu_render_states;665 return *_graphics_display.m_DeviceFactory->gpu_render_states_;
666 }666 }
667 void ResetRenderStates()667 void ResetRenderStates()
668 {668 {
669 _graphics_display.m_DeviceFactory->_gpu_render_states->ResetStateChangeToDefault();669 _graphics_display.m_DeviceFactory->gpu_render_states_->ResetStateChangeToDefault();
670 }670 }
671 void VerifyRenderStates()671 void VerifyRenderStates()
672 {672 {
673 _graphics_display.m_DeviceFactory->_gpu_render_states->CheckStateChange();673 _graphics_display.m_DeviceFactory->gpu_render_states_->CheckStateChange();
674 }674 }
675675
676 ObjectPtr<FontTexture> GetFont();676 ObjectPtr<FontTexture> GetFont();
677677
=== modified file 'NuxGraphics/IOpenGLAsmShader.cpp'
--- NuxGraphics/IOpenGLAsmShader.cpp 2012-08-02 16:29:19 +0000
+++ NuxGraphics/IOpenGLAsmShader.cpp 2012-09-30 17:24:22 +0000
@@ -39,7 +39,7 @@
39 NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLAsmPixelShader);39 NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLAsmPixelShader);
40 NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLAsmShaderProgram);40 NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLAsmShaderProgram);
4141
42 bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString ShaderPreprocessorDefines);42 bool ExtractShaderString3(const std::string& ShaderToken, const std::string& ShaderSource, std::string& RetSource, std::string ShaderPreprocessorDefines);
4343
44 IOpenGLAsmShader::IOpenGLAsmShader(std::string const& shader_name, GLint shader_type, OpenGLResourceType ResourceType)44 IOpenGLAsmShader::IOpenGLAsmShader(std::string const& shader_name, GLint shader_type, OpenGLResourceType ResourceType)
45 : IOpenGLResource(ResourceType)45 : IOpenGLResource(ResourceType)
@@ -113,7 +113,7 @@
113 {113 {
114 }114 }
115115
116 IOpenGLAsmShaderProgram::IOpenGLAsmShaderProgram(NString ShaderProgramName)116 IOpenGLAsmShaderProgram::IOpenGLAsmShaderProgram(std::string ShaderProgramName)
117 : IOpenGLResource(RT_GLSL_SHADERPROGRAM)117 : IOpenGLResource(RT_GLSL_SHADERPROGRAM)
118 , _ShaderProgramName(ShaderProgramName)118 , _ShaderProgramName(ShaderProgramName)
119 {119 {
@@ -131,19 +131,19 @@
131 {131 {
132 nuxAssertMsg(ShaderFileName, "[IOpenGLAsmShaderProgram::LoadIShaderFile] Invalid shader file name.");132 nuxAssertMsg(ShaderFileName, "[IOpenGLAsmShaderProgram::LoadIShaderFile] Invalid shader file name.");
133 NUX_RETURN_IF_NULL(ShaderFileName);133 NUX_RETURN_IF_NULL(ShaderFileName);
134 NString SourceCode;134 std::string SourceCode;
135 LoadFileToString(SourceCode, ShaderFileName);135 LoadFileToString(SourceCode, ShaderFileName);
136 LoadIShader(&SourceCode[0]);136 LoadIShader(&SourceCode[0]);
137 }137 }
138138
139 void IOpenGLAsmShaderProgram::LoadIShader(const char *ShaderCode)139 void IOpenGLAsmShaderProgram::LoadIShader(const char* ShaderCode)
140 {140 {
141 nuxAssertMsg(ShaderCode, "[IOpenGLAsmShaderProgram::LoadIShader] Invalid shader code.");141 nuxAssertMsg(ShaderCode, "[IOpenGLAsmShaderProgram::LoadIShader] Invalid shader code.");
142 NUX_RETURN_IF_NULL(ShaderCode);142 NUX_RETURN_IF_NULL(ShaderCode);
143 NString VertexShaderSource;143 std::string VertexShaderSource;
144 ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, NString(""));144 ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, std::string(""));
145 NString PixelShaderSource;145 std::string PixelShaderSource;
146 ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, NString(""));146 ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, std::string(""));
147147
148 m_AsmVertexProgram->SetShaderCode(&VertexShaderSource[0]);148 m_AsmVertexProgram->SetShaderCode(&VertexShaderSource[0]);
149 m_AsmFragmentProgram->SetShaderCode(&PixelShaderSource[0]);149 m_AsmFragmentProgram->SetShaderCode(&PixelShaderSource[0]);
@@ -152,7 +152,7 @@
152 m_AsmFragmentProgram->Compile();152 m_AsmFragmentProgram->Compile();
153 }153 }
154154
155 void IOpenGLAsmShaderProgram::LoadVertexShader(const char *glslshader)155 void IOpenGLAsmShaderProgram::LoadVertexShader(const char* glslshader)
156 {156 {
157 nuxAssertMsg(glslshader, "[IOpenGLAsmShaderProgram::LoadVertexShader] Invalid shader code.");157 nuxAssertMsg(glslshader, "[IOpenGLAsmShaderProgram::LoadVertexShader] Invalid shader code.");
158 NUX_RETURN_IF_NULL(glslshader);158 NUX_RETURN_IF_NULL(glslshader);
159159
=== modified file 'NuxGraphics/IOpenGLAsmShader.h'
--- NuxGraphics/IOpenGLAsmShader.h 2012-08-02 16:29:19 +0000
+++ NuxGraphics/IOpenGLAsmShader.h 2012-09-30 17:24:22 +0000
@@ -121,9 +121,9 @@
121 void SetFragmentLocalParameter4fvARB (unsigned int index, const float *params);121 void SetFragmentLocalParameter4fvARB (unsigned int index, const float *params);
122122
123 private:123 private:
124 IOpenGLAsmShaderProgram(NString ShaderProgramName = NString("AsmShaderProgram"));124 IOpenGLAsmShaderProgram(std::string ShaderProgramName = std::string("AsmShaderProgram"));
125 std::vector<ObjectPtr<IOpenGLAsmShader> > ShaderObjectList;125 std::vector<ObjectPtr<IOpenGLAsmShader> > ShaderObjectList;
126 NString _ShaderProgramName;126 std::string _ShaderProgramName;
127127
128 ObjectPtr<IOpenGLAsmVertexShader> m_AsmVertexProgram;128 ObjectPtr<IOpenGLAsmVertexShader> m_AsmVertexProgram;
129 ObjectPtr<IOpenGLAsmPixelShader> m_AsmFragmentProgram;129 ObjectPtr<IOpenGLAsmPixelShader> m_AsmFragmentProgram;
130130
=== modified file 'NuxGraphics/IOpenGLCgShader.h'
--- NuxGraphics/IOpenGLCgShader.h 2011-10-19 20:32:38 +0000
+++ NuxGraphics/IOpenGLCgShader.h 2012-09-30 17:24:22 +0000
@@ -33,7 +33,7 @@
33 NUX_DECLARE_OBJECT_TYPE(ICgShader, IOpenGLResource);33 NUX_DECLARE_OBJECT_TYPE(ICgShader, IOpenGLResource);
3434
35 public:35 public:
36 ICgShader(NString ShaderName, OpenGLResourceType ResourceType);36 ICgShader(std::string ShaderName, OpenGLResourceType ResourceType);
37 virtual ~ICgShader();37 virtual ~ICgShader();
3838
39 virtual void CreateProgram(const ANSICHAR *ShaderCode, const ANSICHAR *EntryPoint) = 0;39 virtual void CreateProgram(const ANSICHAR *ShaderCode, const ANSICHAR *EntryPoint) = 0;
@@ -45,9 +45,9 @@
45 virtual bool IsValid() = 0;45 virtual bool IsValid() = 0;
46 CGparameter GetNamedParameter(const char *parameter);46 CGparameter GetNamedParameter(const char *parameter);
4747
48 NString _ShaderName;48 std::string _ShaderName;
49 NString _ShaderCode;49 std::string _ShaderCode;
50 NString _EntryPoint;50 std::string _EntryPoint;
51 CGprogram _CgProgram;51 CGprogram _CgProgram;
52 };52 };
5353
@@ -62,7 +62,7 @@
62 virtual bool Compile();62 virtual bool Compile();
63 virtual bool IsValid();63 virtual bool IsValid();
64 private:64 private:
65 ICgVertexShader(NString ShaderName = NString("VertexProgram"));65 ICgVertexShader(std::string ShaderName = std::string("VertexProgram"));
66 int _ready;66 int _ready;
67 friend class GpuDevice;67 friend class GpuDevice;
68 };68 };
@@ -78,7 +78,7 @@
78 virtual bool Compile();78 virtual bool Compile();
79 virtual bool IsValid();79 virtual bool IsValid();
80 private:80 private:
81 ICgPixelShader(NString ShaderName = NString("PixelProgram"));81 ICgPixelShader(std::string ShaderName = std::string("PixelProgram"));
82 int _ready;82 int _ready;
83 friend class GpuDevice;83 friend class GpuDevice;
84 };84 };
8585
=== modified file 'NuxGraphics/IOpenGLGLSLShader.cpp'
--- NuxGraphics/IOpenGLGLSLShader.cpp 2012-02-23 16:30:14 +0000
+++ NuxGraphics/IOpenGLGLSLShader.cpp 2012-09-30 17:24:22 +0000
@@ -43,7 +43,7 @@
43 NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLShaderProgram);43 NUX_IMPLEMENT_OBJECT_TYPE(IOpenGLShaderProgram);
4444
4545
46 bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString ShaderPreprocessorDefines)46 bool ExtractShaderString3(const std::string &ShaderToken, const std::string &ShaderSource, std::string &RetSource, std::string ShaderPreprocessorDefines)
47 {47 {
48 size_t lineStart = 0;48 size_t lineStart = 0;
49 size_t lineCount = 1;49 size_t lineCount = 1;
@@ -57,7 +57,7 @@
57 {57 {
58 size_t i;58 size_t i;
5959
60 for (i = 0; i < ShaderSource.Length(); i++)60 for (i = 0; i < ShaderSource.length(); i++)
61 {61 {
62 //Check if the starting character '[' (open bracket) is found at the beginning of the line62 //Check if the starting character '[' (open bracket) is found at the beginning of the line
63 // i counts the characters in the file. lineStart is equal to i at the beginning of the line.63 // i counts the characters in the file. lineStart is equal to i at the beginning of the line.
@@ -66,10 +66,10 @@
66 if (!startTokenFound)66 if (!startTokenFound)
67 {67 {
68 //Test for the start token68 //Test for the start token
69 if (ShaderSource.FindFirstOccurence(ShaderToken) == i)69 if (ShaderSource.find(ShaderToken, 0) == i)
70 {70 {
71 // Found the shader token71 // Found the shader token
72 shaderStringStart = i + ShaderToken.Length();72 shaderStringStart = i + ShaderToken.length();
73 startTokenFound = true;73 startTokenFound = true;
7474
75 //Set what line the shader was found on75 //Set what line the shader was found on
@@ -104,11 +104,11 @@
104 }104 }
105105
106 //Assign the return string106 //Assign the return string
107 RetSource = ShaderSource.GetSubString(shaderStringStart, i - shaderStringStart);107 RetSource = ShaderSource.substr(shaderStringStart, i - shaderStringStart);
108108
109 //Add the line directive to the shader source. See the documentation for GLSL #line directive.109 //Add the line directive to the shader source. See the documentation for GLSL #line directive.
110 // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space.110 // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space.
111 size_t Pos = RetSource.FindFirstOccurence("#version");111 size_t Pos = RetSource.find("#version", 0);
112112
113 while (RetSource[Pos] != '\n')113 while (RetSource[Pos] != '\n')
114 {114 {
@@ -124,17 +124,21 @@
124 size_t EndOfLinePosition = 0;124 size_t EndOfLinePosition = 0;
125 size_t LinePosition = 0;125 size_t LinePosition = 0;
126126
127 while ((EndOfLinePosition = RetSource.FindNextOccurence('\n', EndOfLinePosition)) < Pos - 1)127 while ((EndOfLinePosition = RetSource.find('\n', EndOfLinePosition)) < Pos - 1)
128 {128 {
129 ++EndOfLinePosition;129 ++EndOfLinePosition;
130 ++LinePosition;130 ++LinePosition;
131 }131 }
132132
133 RetSource.Insert(Pos, NString::Printf("#line %u\n", LinePosition + shaderStartLine));133 std::ostringstream o_str_stream;
134 o_str_stream << "#line " << LinePosition + shaderStartLine << "\n";
135 std::string line_num_str = o_str_stream.str();
136
137 RetSource.insert(Pos, line_num_str);
134138
135 // Insert the preprocessor definitions before the #line directive139 // Insert the preprocessor definitions before the #line directive
136 if (ShaderPreprocessorDefines.Length())140 if (ShaderPreprocessorDefines.length())
137 RetSource.Insert(Pos, ShaderPreprocessorDefines + NString('\n'));141 RetSource.insert(Pos, ShaderPreprocessorDefines + std::string("\n"));
138142
139 return true;143 return true;
140 }144 }
@@ -146,26 +150,26 @@
146 }150 }
147 }151 }
148152
149 static void InsertPreProcessorDefinitions(const NString &ShaderSource, NString &RetSource, NString &ShaderPreprocessorDefines)153 static void InsertPreProcessorDefinitions(const std::string &ShaderSource, std::string &RetSource, std::string &ShaderPreprocessorDefines)
150 {154 {
151 RetSource = ShaderSource;155 RetSource = ShaderSource;
152156
153 if (ShaderPreprocessorDefines.Length() == 0)157 if (ShaderPreprocessorDefines.length() == 0)
154 return;158 return;
155159
156 // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space.160 // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space.
157 size_t Pos = RetSource.FindFirstOccurence("#version");161 size_t Pos = RetSource.find("#version", 0);
158162
159 if (Pos != tstring::npos)163 if (Pos != tstring::npos)
160 {164 {
161 Pos = RetSource.FindNextOccurence('\n', Pos);165 Pos = RetSource.find('\n', Pos);
162166
163 if (Pos == tstring::npos)167 if (Pos == tstring::npos)
164 {168 {
165 // this is most likely an incorrect shader169 // this is most likely an incorrect shader
166 Pos = RetSource.Size();170 Pos = RetSource.size();
167 RetSource.Insert(Pos, NString('\n'));171 RetSource.insert(Pos, std::string("\n"));
168 Pos = RetSource.Size();172 Pos = RetSource.size();
169 }173 }
170 else174 else
171 {175 {
@@ -178,11 +182,11 @@
178 Pos = 0;182 Pos = 0;
179 }183 }
180184
181 if (ShaderPreprocessorDefines.Length())185 if (ShaderPreprocessorDefines.length())
182 RetSource.Insert(Pos, ShaderPreprocessorDefines + NString('\n'));186 RetSource.insert(Pos, ShaderPreprocessorDefines + std::string("\n"));
183 }187 }
184188
185 IOpenGLShader::IOpenGLShader(NString ShaderName, OpenGLResourceType ResourceType)189 IOpenGLShader::IOpenGLShader(std::string ShaderName, OpenGLResourceType ResourceType)
186 : IOpenGLResource(ResourceType)190 : IOpenGLResource(ResourceType)
187 , _ShaderName(ShaderName)191 , _ShaderName(ShaderName)
188 {192 {
@@ -194,7 +198,7 @@
194198
195 }199 }
196200
197 IOpenGLVertexShader::IOpenGLVertexShader(NString ShaderName)201 IOpenGLVertexShader::IOpenGLVertexShader(std::string ShaderName)
198 : IOpenGLShader(ShaderName, RT_GLSL_VERTEXSHADER)202 : IOpenGLShader(ShaderName, RT_GLSL_VERTEXSHADER)
199 , m_CompiledAndReady(false)203 , m_CompiledAndReady(false)
200 {204 {
@@ -213,8 +217,8 @@
213 {217 {
214 nuxAssertMsg(ShaderCode, "[IOpenGLVertexShader::SetShaderCode] Invalid shader code.");218 nuxAssertMsg(ShaderCode, "[IOpenGLVertexShader::SetShaderCode] Invalid shader code.");
215 NUX_RETURN_IF_NULL(ShaderCode);219 NUX_RETURN_IF_NULL(ShaderCode);
216 NString ProcessedShaderSource;220 std::string ProcessedShaderSource;
217 NString Defines(VtxShaderPreprocessorDefines);221 std::string Defines(VtxShaderPreprocessorDefines);
218 InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines);222 InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines);
219223
220 m_CompiledAndReady = false;224 m_CompiledAndReady = false;
@@ -223,7 +227,7 @@
223227
224 bool IOpenGLVertexShader::Compile()228 bool IOpenGLVertexShader::Compile()
225 {229 {
226 size_t CodeSize = _ShaderCode.Size();230 size_t CodeSize = _ShaderCode.size();
227231
228 if (CodeSize == 0)232 if (CodeSize == 0)
229 {233 {
@@ -232,7 +236,7 @@
232236
233 char *ShaderSource = new char[CodeSize+1];237 char *ShaderSource = new char[CodeSize+1];
234 Memset(ShaderSource, 0, CodeSize + 1);238 Memset(ShaderSource, 0, CodeSize + 1);
235 Memcpy(ShaderSource, _ShaderCode.GetTCharPtr(), CodeSize);239 Memcpy(ShaderSource, _ShaderCode.c_str(), CodeSize);
236240
237 CHECKGL(glShaderSource(_OpenGLID, 1, (const GLcharARB **) &ShaderSource, NULL));241 CHECKGL(glShaderSource(_OpenGLID, 1, (const GLcharARB **) &ShaderSource, NULL));
238 delete [] ShaderSource;242 delete [] ShaderSource;
@@ -272,7 +276,7 @@
272 return(m_CompiledAndReady ? true : false);276 return(m_CompiledAndReady ? true : false);
273 }277 }
274278
275 IOpenGLPixelShader::IOpenGLPixelShader(NString ShaderName)279 IOpenGLPixelShader::IOpenGLPixelShader(std::string ShaderName)
276 : IOpenGLShader(ShaderName, RT_GLSL_PIXELSHADER)280 : IOpenGLShader(ShaderName, RT_GLSL_PIXELSHADER)
277 , m_CompiledAndReady(false)281 , m_CompiledAndReady(false)
278282
@@ -292,8 +296,8 @@
292 {296 {
293 nuxAssertMsg(ShaderCode, "[IOpenGLPixelShader::SetShaderCode] Invalid shader code.");297 nuxAssertMsg(ShaderCode, "[IOpenGLPixelShader::SetShaderCode] Invalid shader code.");
294 NUX_RETURN_IF_NULL(ShaderCode);298 NUX_RETURN_IF_NULL(ShaderCode);
295 NString ProcessedShaderSource;299 std::string ProcessedShaderSource;
296 NString Defines(FrgShaderPreprocessorDefines);300 std::string Defines(FrgShaderPreprocessorDefines);
297 InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines);301 InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines);
298302
299 m_CompiledAndReady = false;303 m_CompiledAndReady = false;
@@ -303,7 +307,7 @@
303 bool IOpenGLPixelShader::Compile()307 bool IOpenGLPixelShader::Compile()
304 {308 {
305309
306 GLint CodeSize = (GLint) _ShaderCode.Size();310 GLint CodeSize = (GLint) _ShaderCode.size();
307311
308 if (CodeSize == 0)312 if (CodeSize == 0)
309 {313 {
@@ -312,7 +316,7 @@
312316
313 char *ShaderSource = new char[CodeSize+1];317 char *ShaderSource = new char[CodeSize+1];
314 Memset(ShaderSource, 0, CodeSize + 1);318 Memset(ShaderSource, 0, CodeSize + 1);
315 Memcpy(ShaderSource, _ShaderCode.m_string.c_str(), CodeSize);319 Memcpy(ShaderSource, _ShaderCode.c_str(), CodeSize);
316 CHECKGL(glShaderSource(_OpenGLID, 1, (const GLcharARB **) &ShaderSource, &CodeSize));320 CHECKGL(glShaderSource(_OpenGLID, 1, (const GLcharARB **) &ShaderSource, &CodeSize));
317 delete [] ShaderSource;321 delete [] ShaderSource;
318322
@@ -354,7 +358,7 @@
354 }358 }
355359
356#if 0360#if 0
357 IOpenGLGeometryShader::IOpenGLGeometryShader(NString ShaderName)361 IOpenGLGeometryShader::IOpenGLGeometryShader(std::string ShaderName)
358 : IOpenGLShader(ShaderName, RT_GLSL_GEOMETRYSHADER)362 : IOpenGLShader(ShaderName, RT_GLSL_GEOMETRYSHADER)
359 , m_CompiledAndReady(false)363 , m_CompiledAndReady(false)
360364
@@ -374,8 +378,8 @@
374 {378 {
375 nuxAssertMsg(ShaderCode, "[IOpenGLGeometryShader::SetShaderCode] Invalid shader code.");379 nuxAssertMsg(ShaderCode, "[IOpenGLGeometryShader::SetShaderCode] Invalid shader code.");
376 NUX_RETURN_IF_NULL(ShaderCode);380 NUX_RETURN_IF_NULL(ShaderCode);
377 NString ProcessedShaderSource;381 std::string ProcessedShaderSource;
378 NString Defines(GeometryShaderPreprocessorDefines);382 std::string Defines(GeometryShaderPreprocessorDefines);
379 InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines);383 InsertPreProcessorDefinitions(ShaderCode, ProcessedShaderSource, Defines);
380384
381 m_CompiledAndReady = false;385 m_CompiledAndReady = false;
@@ -449,7 +453,7 @@
449 }453 }
450#endif454#endif
451455
452 IOpenGLShaderProgram::IOpenGLShaderProgram(NString ShaderProgramName)456 IOpenGLShaderProgram::IOpenGLShaderProgram(std::string ShaderProgramName)
453 : IOpenGLResource(RT_GLSL_SHADERPROGRAM)457 : IOpenGLResource(RT_GLSL_SHADERPROGRAM)
454 , _FirstParameter(0)458 , _FirstParameter(0)
455 , m_CompiledAndReady(false)459 , m_CompiledAndReady(false)
@@ -476,7 +480,7 @@
476 {480 {
477 nuxAssertMsg(ShaderFileName, "[IOpenGLShaderProgram::LoadIShaderFile] Invalid shader file name.");481 nuxAssertMsg(ShaderFileName, "[IOpenGLShaderProgram::LoadIShaderFile] Invalid shader file name.");
478 NUX_RETURN_IF_NULL(ShaderFileName);482 NUX_RETURN_IF_NULL(ShaderFileName);
479 NString SourceCode;483 std::string SourceCode;
480 LoadFileToString(SourceCode, ShaderFileName);484 LoadFileToString(SourceCode, ShaderFileName);
481 LoadIShader(&SourceCode[0], VtxShaderPreprocessorDefines, FrgShaderPreprocessorDefines);485 LoadIShader(&SourceCode[0], VtxShaderPreprocessorDefines, FrgShaderPreprocessorDefines);
482 }486 }
@@ -485,10 +489,10 @@
485 {489 {
486 nuxAssertMsg(ShaderCode, "[IOpenGLShaderProgram::LoadIShader] Invalid shader code.");490 nuxAssertMsg(ShaderCode, "[IOpenGLShaderProgram::LoadIShader] Invalid shader code.");
487 NUX_RETURN_IF_NULL(ShaderCode);491 NUX_RETURN_IF_NULL(ShaderCode);
488 NString VertexShaderSource;492 std::string VertexShaderSource;
489 ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, NString(VtxShaderPreprocessorDefines));493 ExtractShaderString3("[Vertex Shader]", ShaderCode, VertexShaderSource, std::string(VtxShaderPreprocessorDefines));
490 NString PixelShaderSource;494 std::string PixelShaderSource;
491 ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, NString(FrgShaderPreprocessorDefines));495 ExtractShaderString3("[Fragment Shader]", ShaderCode, PixelShaderSource, std::string(FrgShaderPreprocessorDefines));
492496
493 ObjectPtr<IOpenGLVertexShader> vs = GetGraphicsDisplay()->GetGpuDevice()->CreateVertexShader(); //new IOpenGLVertexShader;497 ObjectPtr<IOpenGLVertexShader> vs = GetGraphicsDisplay()->GetGpuDevice()->CreateVertexShader(); //new IOpenGLVertexShader;
494 ObjectPtr<IOpenGLPixelShader> ps = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader(); //new IOpenGLPixelShader;498 ObjectPtr<IOpenGLPixelShader> ps = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader(); //new IOpenGLPixelShader;
@@ -510,8 +514,8 @@
510 NUX_RETURN_IF_NULL(glslshader);514 NUX_RETURN_IF_NULL(glslshader);
511 ObjectPtr<IOpenGLVertexShader> vs = GetGraphicsDisplay()->GetGpuDevice()->CreateVertexShader(); //new IOpenGLVertexShader;515 ObjectPtr<IOpenGLVertexShader> vs = GetGraphicsDisplay()->GetGpuDevice()->CreateVertexShader(); //new IOpenGLVertexShader;
512516
513 NString ProcessedShaderSource;517 std::string ProcessedShaderSource;
514 NString Defines(VtxShaderPreprocessorDefines);518 std::string Defines(VtxShaderPreprocessorDefines);
515 InsertPreProcessorDefinitions(glslshader, ProcessedShaderSource, Defines);519 InsertPreProcessorDefinitions(glslshader, ProcessedShaderSource, Defines);
516520
517 vs->SetShaderCode(glslshader);521 vs->SetShaderCode(glslshader);
@@ -525,8 +529,8 @@
525 NUX_RETURN_IF_NULL(glslshader);529 NUX_RETURN_IF_NULL(glslshader);
526 ObjectPtr<IOpenGLPixelShader> ps = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader(); //new IOpenGLPixelShader;530 ObjectPtr<IOpenGLPixelShader> ps = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader(); //new IOpenGLPixelShader;
527531
528 NString ProcessedShaderSource;532 std::string ProcessedShaderSource;
529 NString Defines(FrgShaderPreprocessorDefines);533 std::string Defines(FrgShaderPreprocessorDefines);
530 InsertPreProcessorDefinitions(glslshader, ProcessedShaderSource, Defines);534 InsertPreProcessorDefinitions(glslshader, ProcessedShaderSource, Defines);
531535
532 ps->SetShaderCode(glslshader);536 ps->SetShaderCode(glslshader);
@@ -607,7 +611,7 @@
607 {611 {
608 if (ShaderObjectList[i]->Compile() == false)612 if (ShaderObjectList[i]->Compile() == false)
609 {613 {
610 nuxDebugMsg("[IOpenGLShaderProgram::Link] Attached shader %s does not compile with program: %s.", ShaderObjectList[i]->_ShaderName.GetTCharPtr(), _ShaderProgramName.GetTCharPtr());614 nuxDebugMsg("[IOpenGLShaderProgram::Link] Attached shader %s does not compile with program: %s.", ShaderObjectList[i]->_ShaderName.c_str(), _ShaderProgramName.c_str());
611 }615 }
612 }616 }
613617
@@ -793,13 +797,13 @@
793797
794 while (m_CompiledAndReady && parameter)798 while (m_CompiledAndReady && parameter)
795 {799 {
796 int location = glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.GetTCharPtr()));800 int location = glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.c_str()));
797 CHECKGL_MSG( glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.GetTCharPtr())));801 CHECKGL_MSG( glGetUniformLocationARB(_OpenGLID, TCHAR_TO_ANSI(parameter->m_Name.c_str())));
798802
799 //nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Location index: %d", location);803 //nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Location index: %d", location);
800 if (location == -1 && (!parameter->m_bIsOptional))804 if (location == -1 && (!parameter->m_bIsOptional))
801 {805 {
802 nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Couldn't find shader program parameter %s \n", parameter->m_Name.GetTCharPtr());806 nuxDebugMsg("[IOpenGLShaderProgram::CheckUniformLocation] Couldn't find shader program parameter %s \n", parameter->m_Name.c_str());
803 nuxAssert(0);807 nuxAssert(0);
804 }808 }
805809
806810
=== modified file 'NuxGraphics/IOpenGLGLSLShader.h'
--- NuxGraphics/IOpenGLGLSLShader.h 2011-10-19 20:32:38 +0000
+++ NuxGraphics/IOpenGLGLSLShader.h 2012-09-30 17:24:22 +0000
@@ -28,19 +28,19 @@
2828
29 class IOpenGLResource;29 class IOpenGLResource;
3030
31 bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString ShaderPreprocessorDefines = NString(""));31 bool ExtractShaderString3(const std::string &ShaderToken, const std::string &ShaderSource, std::string &RetSource, std::string ShaderPreprocessorDefines = std::string(""));
3232
33 class IOpenGLShader: public IOpenGLResource33 class IOpenGLShader: public IOpenGLResource
34 {34 {
35 NUX_DECLARE_OBJECT_TYPE(IOpenGLShader, IOpenGLResource);35 NUX_DECLARE_OBJECT_TYPE(IOpenGLShader, IOpenGLResource);
36 IOpenGLShader(NString ShaderName, OpenGLResourceType ResourceType);36 IOpenGLShader(std::string ShaderName, OpenGLResourceType ResourceType);
37 virtual ~IOpenGLShader();37 virtual ~IOpenGLShader();
38 public:38 public:
39 virtual void SetShaderCode(const ANSICHAR *ShaderCode, const char *ShaderPreprocessorDefines = "") = 0;39 virtual void SetShaderCode(const ANSICHAR *ShaderCode, const char *ShaderPreprocessorDefines = "") = 0;
40 virtual bool Compile() = 0;40 virtual bool Compile() = 0;
41 virtual bool IsValid() = 0;41 virtual bool IsValid() = 0;
42 NString _ShaderName;42 std::string _ShaderName;
43 NString _ShaderCode;43 std::string _ShaderCode;
44 };44 };
4545
46 class IOpenGLVertexShader: public IOpenGLShader46 class IOpenGLVertexShader: public IOpenGLShader
@@ -52,7 +52,7 @@
52 virtual bool Compile();52 virtual bool Compile();
53 virtual bool IsValid();53 virtual bool IsValid();
54 private:54 private:
55 IOpenGLVertexShader(NString ShaderName = NString("Vertex Shader"));55 IOpenGLVertexShader(std::string ShaderName = std::string("Vertex Shader"));
56 int m_CompiledAndReady;56 int m_CompiledAndReady;
57 friend class GpuDevice;57 friend class GpuDevice;
58 };58 };
@@ -66,7 +66,7 @@
66 virtual bool Compile();66 virtual bool Compile();
67 virtual bool IsValid();67 virtual bool IsValid();
68 private:68 private:
69 IOpenGLPixelShader(NString ShaderName = NString("Fragment Shader"));69 IOpenGLPixelShader(std::string ShaderName = std::string("Fragment Shader"));
70 int m_CompiledAndReady;70 int m_CompiledAndReady;
71 friend class GpuDevice;71 friend class GpuDevice;
72 };72 };
@@ -86,7 +86,7 @@
86 void SetMaxVertexOutput(int max_vertex_output);86 void SetMaxVertexOutput(int max_vertex_output);
8787
88 private:88 private:
89 IOpenGLGeometryShader(NString ShaderName = NString("Geometry Shader"));89 IOpenGLGeometryShader(std::string ShaderName = std::string("Geometry Shader"));
90 int m_CompiledAndReady;90 int m_CompiledAndReady;
91 friend class GpuDevice;91 friend class GpuDevice;
92 };92 };
@@ -207,11 +207,11 @@
207 int GetAttributeLocation(const char *AttributeName);207 int GetAttributeLocation(const char *AttributeName);
208208
209 private:209 private:
210 IOpenGLShaderProgram(NString ShaderProgramName = NString("ShaderProgram"));210 IOpenGLShaderProgram(std::string ShaderProgramName = std::string("ShaderProgram"));
211 ShaderAttributeDefinition m_ProgramAttributeDefinition[16/*NUM_VERTEX_SHADER_INPUT_ATTRIBUTE*/];211 ShaderAttributeDefinition m_ProgramAttributeDefinition[16/*NUM_VERTEX_SHADER_INPUT_ATTRIBUTE*/];
212 std::vector<ObjectPtr<IOpenGLShader> > ShaderObjectList;212 std::vector<ObjectPtr<IOpenGLShader> > ShaderObjectList;
213 bool m_CompiledAndReady;213 bool m_CompiledAndReady;
214 NString _ShaderProgramName;214 std::string _ShaderProgramName;
215 friend class GpuDevice;215 friend class GpuDevice;
216 };216 };
217217

Subscribers

People subscribed via source and target branches