Nux

Merge lp:~unity-team/nux/nux.save-base-texture into lp:nux

Proposed by Eleni Maria Stea
Status: Merged
Approved by: Eleni Maria Stea
Approved revision: 759
Merged at revision: 759
Proposed branch: lp:~unity-team/nux/nux.save-base-texture
Merge into: lp:nux
Diff against target: 159 lines (+58/-59)
4 files modified
NuxGraphics/IOpenGLBaseTexture.cpp (+56/-0)
NuxGraphics/IOpenGLBaseTexture.h (+2/-0)
NuxGraphics/IOpenGLTexture2D.cpp (+0/-57)
NuxGraphics/IOpenGLTexture2D.h (+0/-2)
To merge this branch: bzr merge lp:~unity-team/nux/nux.save-base-texture
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Eleni Maria Stea (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+148165@code.launchpad.net

Description of the change

moved the debug function that saves textures to disk to the IOpenGLBaseTexture class

To post a comment you must log in.
Revision history for this message
Eleni Maria Stea (hikiko) :
review: Approve
Revision history for this message
Mirco Müller (macslow) wrote :

Look good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NuxGraphics/IOpenGLBaseTexture.cpp'
2--- NuxGraphics/IOpenGLBaseTexture.cpp 2012-11-17 14:22:27 +0000
3+++ NuxGraphics/IOpenGLBaseTexture.cpp 2013-02-13 12:32:21 +0000
4@@ -264,6 +264,62 @@
5 return 0;
6 }
7
8+ void IOpenGLBaseTexture::Save(const char* filename)
9+ {
10+ GLuint tex_id = GetOpenGLID();
11+ glBindTexture(GL_TEXTURE_2D, tex_id);
12+
13+ int width, height;
14+
15+#ifndef NUX_OPENGLES_20
16+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
17+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
18+#else
19+ width = GetWidth();
20+ height = GetHeight();
21+#endif
22+
23+ if(!width || !height)
24+ return;
25+
26+ uint32_t* pixels = new uint32_t[width * height];
27+ uint32_t* tmp = pixels;
28+
29+#ifndef NUX_OPENGLES_20
30+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
31+#else
32+ GLuint fbo;
33+ glGenFramebuffers(1, &fbo);
34+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
35+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 0);
36+ glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
37+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
38+ glDeleteFramebuffers(1, &fbo);
39+#endif
40+
41+ FILE* fp;
42+ if(!(fp = fopen(filename, "wb"))) {
43+ fprintf(stderr, "Cannot open file: %s\n", filename);
44+ return;
45+ }
46+
47+ fprintf(fp, "P6\n%d %d\n255\n", width, height);
48+
49+ int sz = width * height;
50+ for(int i=0; i<sz; i++) {
51+ uint32_t pix = *tmp++;
52+ int r = (pix >> 16) & 0xff;
53+ int g = (pix >> 8) & 0xff;
54+ int b = pix & 0xff;
55+
56+ fputc(r, fp);
57+ fputc(g, fp);
58+ fputc(b, fp);
59+ }
60+
61+ fclose(fp);
62+ delete [] pixels;
63+ }
64
65 int GetTextureSize(IOpenGLBaseTexture *pTexture)
66 {
67
68=== modified file 'NuxGraphics/IOpenGLBaseTexture.h'
69--- NuxGraphics/IOpenGLBaseTexture.h 2012-01-17 03:57:31 +0000
70+++ NuxGraphics/IOpenGLBaseTexture.h 2013-02-13 12:32:21 +0000
71@@ -151,6 +151,8 @@
72 */
73 virtual unsigned char* GetSurfaceData(int level, int &width, int &height, int &stride);
74
75+ void Save(const char* filename);
76+
77 protected:
78 GLTextureStates _TextureStates;
79 bool _IsPOT; // is power of two?
80
81=== modified file 'NuxGraphics/IOpenGLTexture2D.cpp'
82--- NuxGraphics/IOpenGLTexture2D.cpp 2013-02-08 17:40:29 +0000
83+++ NuxGraphics/IOpenGLTexture2D.cpp 2013-02-13 12:32:21 +0000
84@@ -87,63 +87,6 @@
85
86 }
87
88- void IOpenGLTexture2D::Save(const char* filename)
89- {
90- GLuint tex_id = GetOpenGLID();
91- glBindTexture(GL_TEXTURE_2D, tex_id);
92-
93- int width, height;
94-
95-#ifndef NUX_OPENGLES_20
96- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
97- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
98-#else
99- width = GetWidth();
100- height = GetHeight();
101-#endif
102-
103- if(!width || !height)
104- return;
105-
106- uint32_t* pixels = new uint32_t[width * height];
107- uint32_t* tmp = pixels;
108-
109-#ifndef NUX_OPENGLES_20
110- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
111-#else
112- GLuint fbo;
113- glGenFramebuffers(1, &fbo);
114- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
115- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 0);
116- glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
117- glBindFramebuffer(GL_FRAMEBUFFER, 0);
118- glDeleteFramebuffers(1, &fbo);
119-#endif
120-
121- FILE* fp;
122- if(!(fp = fopen(filename, "wb"))) {
123- fprintf(stderr, "Cannot open file: %s\n", filename);
124- return;
125- }
126-
127- fprintf(fp, "P6\n%d %d\n255\n", width, height);
128-
129- int sz = width * height;
130- for(int i=0; i<sz; i++) {
131- uint32_t pix = *tmp++;
132- int r = (pix >> 16) & 0xff;
133- int g = (pix >> 8) & 0xff;
134- int b = pix & 0xff;
135-
136- fputc(r, fp);
137- fputc(g, fp);
138- fputc(b, fp);
139- }
140-
141- fclose(fp);
142- delete [] pixels;
143-}
144-
145 ObjectPtr<IOpenGLSurface> IOpenGLTexture2D::GetSurfaceLevel(int Level)
146 {
147 if ((Level >= 0) && (Level < _NumMipLevel))
148
149=== modified file 'NuxGraphics/IOpenGLTexture2D.h'
150--- NuxGraphics/IOpenGLTexture2D.h 2013-02-08 15:13:55 +0000
151+++ NuxGraphics/IOpenGLTexture2D.h 2013-02-13 12:32:21 +0000
152@@ -33,8 +33,6 @@
153 public:
154 virtual ~IOpenGLTexture2D();
155
156- void Save(const char* filename);
157-
158 void GetSurfaceLevel(int Level, ObjectPtr<IOpenGLSurface>& surface);
159 ObjectPtr<IOpenGLSurface> GetSurfaceLevel(int Level);
160

Subscribers

People subscribed via source and target branches