Changeset 701
- Timestamp:
- Feb 28, 2011, 3:26:18 AM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/debugquad.cpp
r699 r701 24 24 25 25 /* 26 * Debug Triimplementation class26 * DebugQuad implementation class 27 27 */ 28 28 29 class Debug TriData30 { 31 friend class Debug Tri;29 class DebugQuadData 30 { 31 friend class DebugQuad; 32 32 33 33 private: 34 34 int initialised; 35 35 #if defined HAVE_GL_2X || defined HAVE_GLES_2X 36 GLuint buflist[ 2];36 GLuint buflist[3]; 37 37 Shader *shader; 38 38 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X 39 GLuint buflist[2]; 40 #endif 39 GLuint buflist[3]; 40 #endif 41 GLuint texlist[1]; 42 uint8_t image[1][32 * 32 * 4]; 41 43 }; 42 44 43 45 /* 44 * Public Debug Triclass46 * Public DebugQuad class 45 47 */ 46 48 47 Debug Tri::DebugTri()48 : data(new Debug TriData())49 DebugQuad::DebugQuad() 50 : data(new DebugQuadData()) 49 51 { 50 52 data->initialised = 0; 51 53 } 52 54 53 void Debug Tri::TickGame(float deltams)55 void DebugQuad::TickGame(float deltams) 54 56 { 55 57 Entity::TickGame(deltams); 56 58 } 57 59 58 void Debug Tri::TickDraw(float deltams)60 void DebugQuad::TickDraw(float deltams) 59 61 { 60 62 Entity::TickDraw(deltams); … … 65 67 { 66 68 #if defined HAVE_GL_2X || defined HAVE_GLES_2X 67 glDeleteBuffers( 2, data->buflist);69 glDeleteBuffers(3, data->buflist); 68 70 Shader::Destroy(data->shader); 69 71 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X 70 glDeleteBuffers(2, data->buflist); 71 #endif 72 glDeleteBuffers(3, data->buflist); 73 #endif 74 glDeleteTextures(1, data->texlist); 72 75 data->initialised = 0; 73 76 } … … 76 79 { 77 80 #if defined HAVE_GL_2X || defined HAVE_GLES_2X 78 glGenBuffers( 2, data->buflist);81 glGenBuffers(3, data->buflist); 79 82 80 83 static char const *vertexshader = 81 84 "#version 130\n" 82 85 "in vec2 in_Position;\n" 83 "in vec3 in_Color;\n" 84 "out vec3 pass_Color;\n" 86 "in vec4 in_Color;\n" 87 "in vec2 in_TexCoord;\n" 88 "out vec4 pass_Color;\n" 85 89 "void main()\n" 86 90 "{\n" 87 91 " gl_Position = vec4(in_Position, 0.0f, 1.0f);\n" 92 " gl_TexCoord[0] = vec4(in_TexCoord, 0.0, 0.0);\n" 88 93 " pass_Color = in_Color;\n" 89 94 "}\n"; 90 95 static char const *fragmentshader = 91 96 "#version 130\n" 92 "in vec3 pass_Color;\n" 97 "in vec4 pass_Color;\n" 98 "uniform sampler2D in_Texture;\n" 93 99 "void main()\n" 94 100 "{\n" 95 " gl_FragColor = vec4(pass_Color, 1.0);\n" 101 " vec4 col = pass_Color;\n" 102 " vec4 tex = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n" 103 " gl_FragColor = col * tex;\n" 96 104 "}\n"; 97 105 data->shader = Shader::Create(vertexshader, fragmentshader); 98 106 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X 99 glGenBuffers(2, data->buflist); 100 #endif 107 glGenBuffers(3, data->buflist); 108 #endif 109 glGenTextures(1, data->texlist); 110 111 glActiveTexture(GL_TEXTURE0); 112 glBindTexture(GL_TEXTURE_2D, data->texlist[0]); 113 for (int j = 0; j < 32; j++) 114 for (int i = 0; i < 32; i++) 115 { 116 uint8_t wb = (((i / 2) ^ (j / 2)) & 1) * 0xff; 117 data->image[0][(j * 32 + i) * 4 + 0] = wb; 118 data->image[0][(j * 32 + i) * 4 + 1] = wb; 119 data->image[0][(j * 32 + i) * 4 + 2] = wb; 120 data->image[0][(j * 32 + i) * 4 + 3] = 255; 121 } 122 /* Use GL_RGBA instead of 4 for the internal format (Android) */ 123 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, 124 GL_RGBA, GL_UNSIGNED_BYTE, data->image[0]); 125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 101 127 102 128 data->initialised = 1; … … 109 135 }; 110 136 137 /* Using only 3 components breaks on Android for some reason. */ 111 138 static GLfloat const cols[6][4] = 112 139 { 113 { 0.8f, 0.2f, 0.2f, 1.0f }, { 0.2f, 0.2f, 0.8f, 1.0f }, { 0.8f, 0.8f, 0.2f, 1.0f }, 114 { 0.8f, 0.8f, 0.2f, 1.0f }, { 0.2f, 0.2f, 0.8f, 1.0f }, { 0.2f, 0.8f, 0.2f, 1.0f }, 140 { 0.8f, 0.2f, 0.2f, 1.0f }, 141 { 0.2f, 0.2f, 0.8f, 1.0f }, 142 { 0.8f, 0.8f, 0.2f, 1.0f }, 143 144 { 0.8f, 0.8f, 0.2f, 1.0f }, 145 { 0.2f, 0.2f, 0.8f, 1.0f }, 146 { 0.2f, 0.8f, 0.2f, 1.0f }, 115 147 }; 116 148 149 static GLfloat const tcs[6][2] = 150 { 151 { 0.0f, 1.0f }, { 1.0f, 1.0f }, { 0.0f, 0.0f }, 152 { 0.0f, 0.0f }, { 1.0f, 1.0f }, { 1.0f, 0.0f }, 153 }; 154 117 155 #if defined HAVE_GL_2X || defined HAVE_GLES_2X 118 156 data->shader->Bind(); 119 GLuint attr_pos, attr_col ;157 GLuint attr_pos, attr_col, attr_tex; 120 158 attr_pos = data->shader->GetAttribLocation("in_Position"); 121 159 attr_col = data->shader->GetAttribLocation("in_Color"); 160 attr_tex = data->shader->GetAttribLocation("in_TexCoord"); 122 161 123 162 glEnableVertexAttribArray(attr_pos); 124 163 glEnableVertexAttribArray(attr_col); 164 glEnableVertexAttribArray(attr_tex); 125 165 126 166 glBindBuffer(GL_ARRAY_BUFFER, data->buflist[0]); … … 132 172 glVertexAttribPointer(attr_col, 4, GL_FLOAT, GL_FALSE, 0, 0); 133 173 174 glBindBuffer(GL_ARRAY_BUFFER, data->buflist[2]); 175 glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), tcs, GL_STATIC_DRAW); 176 glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); 177 134 178 glDrawArrays(GL_TRIANGLES, 0, 6); 135 179 136 180 glDisableVertexAttribArray(attr_pos); 137 181 glDisableVertexAttribArray(attr_col); 138 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X 182 glDisableVertexAttribArray(attr_tex); 183 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X 184 /* Reset all model-view-projection matrices */ 139 185 glMatrixMode(GL_PROJECTION); 140 186 glPushMatrix(); … … 144 190 glLoadIdentity(); 145 191 146 glDisableClientState(GL_NORMAL_ARRAY);147 gl DisableClientState(GL_TEXTURE_COORD_ARRAY);148 gl Disable(GL_TEXTURE_2D);192 /* Set up state machine */ 193 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 194 glEnable(GL_TEXTURE_2D); 149 195 glEnableClientState(GL_VERTEX_ARRAY); 150 196 glEnableClientState(GL_COLOR_ARRAY); 151 197 198 glActiveTexture(GL_TEXTURE0); 199 glBindTexture(GL_TEXTURE_2D, data->texlist[0]); 200 201 /* Bind vertex, color and texture coordinate buffers */ 152 202 #if defined HAVE_GL_1X 153 203 glBindBuffer(GL_ARRAY_BUFFER, data->buflist[0]); … … 158 208 glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), cols, GL_STATIC_DRAW); 159 209 glColorPointer(4, GL_FLOAT, 0, NULL); 210 211 glBindBuffer(GL_ARRAY_BUFFER, data->buflist[2]); 212 glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), tcs, GL_STATIC_DRAW); 213 glTexCoordPointer(2, GL_FLOAT, 0, NULL); 160 214 #else 161 215 glVertexPointer(2, GL_FLOAT, 0, verts); 162 216 glColorPointer(4, GL_FLOAT, 0, cols); 163 #endif 164 217 glTexCoordPointer(2, GL_FLOAT, 0, tcs); 218 #endif 219 220 /* Draw arrays */ 165 221 glDrawArrays(GL_TRIANGLES, 0, 6); 166 222 223 /* Disable state machine features */ 167 224 glDisableClientState(GL_VERTEX_ARRAY); 168 225 glDisableClientState(GL_COLOR_ARRAY); 169 226 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 227 228 /* Restore matrices */ 170 229 glMatrixMode(GL_PROJECTION); 171 230 glPopMatrix(); … … 175 234 } 176 235 177 Debug Tri::~DebugTri()236 DebugQuad::~DebugQuad() 178 237 { 179 238 delete data; -
trunk/src/debugquad.h
r699 r701 10 10 11 11 // 12 // The Debug Triclass13 // ------------------ 12 // The DebugQuad class 13 // ------------------- 14 14 // 15 15 … … 22 22 { 23 23 24 class Debug TriData;24 class DebugQuadData; 25 25 26 class Debug Tri: public Entity26 class DebugQuad : public Entity 27 27 { 28 28 public: 29 Debug Tri();30 virtual ~Debug Tri();29 DebugQuad(); 30 virtual ~DebugQuad(); 31 31 32 32 protected: … … 35 35 36 36 private: 37 Debug TriData *data;37 DebugQuadData *data; 38 38 }; 39 39
Note: See TracChangeset
for help on using the changeset viewer.