Changeset 1247
- Timestamp:
- Apr 21, 2012, 10:18:24 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 deleted
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r1244 r1247 30 30 \ 31 31 gpu/shader.cpp gpu/shader.h \ 32 gpu/ vbo.cpp gpu/vbo.h \32 gpu/indexbuffer.cpp gpu/indexbuffer.h \ 33 33 gpu/vertexbuffer.cpp gpu/vertexbuffer.h \ 34 34 \ -
trunk/src/core.h
r1243 r1247 101 101 #include "layer.h" 102 102 #include "gpu/shader.h" 103 #include "gpu/indexbuffer.h" 103 104 #include "gpu/vertexbuffer.h" 104 #include "gpu/vbo.h"105 105 #include "image/image.h" 106 106 #include "application/application.h" -
trunk/src/gpu/indexbuffer.h
r1246 r1247 2 2 // Lol Engine 3 3 // 4 // Copyright: (c) 2010-201 1Sam Hocevar <sam@hocevar.net>4 // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> 5 5 // This program is free software; you can redistribute it and/or 6 6 // modify it under the terms of the Do What The Fuck You Want To … … 10 10 11 11 // 12 // The GpuVboclass13 // ---------------- 12 // The IndexBuffer class 13 // --------------------- 14 14 // 15 15 16 #if !defined __LOL_VBO_H__ 17 #define __LOL_VBO_H__ 16 #if !defined __LOL_INDEXBUFFER_H__ 17 #define __LOL_INDEXBUFFER_H__ 18 19 #include <cstring> 18 20 19 21 namespace lol 20 22 { 21 23 22 class GpuVboData; 23 24 class GpuVbo 24 class IndexBuffer 25 25 { 26 26 public: 27 GpuVbo();28 ~ GpuVbo();27 IndexBuffer(size_t size); 28 ~IndexBuffer(); 29 29 30 void SetSize(size_t elemsize, size_t elemcount); 31 size_t GetSize(); 32 uint8_t *GetData(); 33 uint8_t const *GetData() const; 30 void *Lock(size_t offset, size_t size); 31 void Unlock(); 34 32 35 33 void Bind(); … … 37 35 38 36 private: 39 GpuVboData *data;37 class IndexBufferData *m_data; 40 38 }; 41 39 42 40 } /* namespace lol */ 43 41 44 #endif // __LOL_ VBO_H__42 #endif // __LOL_INDEXBUFFER_H__ 45 43 -
trunk/src/gpu/vertexbuffer.cpp
r1246 r1247 138 138 case MeshPrimitive::Triangles: 139 139 glDrawArrays(GL_TRIANGLES, skip * 3, count * 3); 140 break; 141 } 142 #endif 143 } 144 145 void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, 146 int vskip, int vcount, 147 int skip, int count) 148 { 149 #if defined _XBOX || defined USE_D3D9 150 if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW))) 151 Abort(); 152 switch (type) 153 { 154 case MeshPrimitive::Triangles: 155 if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vbase, vskip, vcount, skip, count))) 156 Abort(); 157 break; 158 } 159 #else 160 switch (type) 161 { 162 case MeshPrimitive::Triangles: 163 /* FIXME: ignores most of the arguments! */ 164 glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_SHORT, 0); 140 165 break; 141 166 } -
trunk/src/gpu/vertexbuffer.h
r1231 r1247 178 178 void Bind(); 179 179 void DrawElements(MeshPrimitive type, int skip, int count); 180 void DrawIndexedElements(MeshPrimitive type, int vbase, int vskip, 181 int vcount, int skip, int count); 180 182 void Unbind(); 181 183 void SetStream(VertexBuffer *vb, ShaderAttrib attr1, -
trunk/test/tutorial/02_cube.cpp
r1243 r1247 14 14 15 15 #include "core.h" 16 #include "lolgl.h"17 16 #include "loldebug.h" 18 17 19 18 using namespace std; 20 19 using namespace lol; 21 22 #if defined _WIN32 && defined USE_D3D923 # define FAR24 # define NEAR25 # include <d3d9.h>26 #endif27 20 28 21 #if USE_SDL && defined __APPLE__ … … 33 26 # undef main /* FIXME: still needed? */ 34 27 # include <direct.h> 35 #endif36 37 #if defined USE_D3D938 extern IDirect3DDevice9 *g_d3ddevice;39 #elif defined _XBOX40 extern D3DDevice *g_d3ddevice;41 28 #endif 42 29 … … 145 132 m_vbo->Unlock(); 146 133 147 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 148 /* Method 1: store vertex buffer on the GPU memory */ 149 glGenBuffers(1, &m_ibo); 150 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); 151 glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.Bytes(), 152 &m_indices[0], GL_STATIC_DRAW); 153 #elif defined _XBOX || defined USE_D3D9 154 int16_t *indices; 155 if (FAILED(g_d3ddevice->CreateIndexBuffer(m_indices.Bytes(), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ibo, NULL))) 156 Abort(); 157 if (FAILED(m_ibo->Lock(0, 0, (void **)&indices, 0))) 158 Abort(); 134 m_ibo = new IndexBuffer(m_indices.Bytes()); 135 void *indices = m_ibo->Lock(0, 0); 159 136 memcpy(indices, &m_indices[0], m_indices.Bytes()); 160 137 m_ibo->Unlock(); 161 #else162 /* TODO */163 #endif164 138 165 139 /* FIXME: this object never cleans up */ … … 173 147 m_vdecl->SetStream(m_vbo, m_coord, m_color); 174 148 m_vdecl->Bind(); 175 176 #if defined _XBOX || defined USE_D3D9 177 if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW))) 178 Abort(); 179 if (FAILED(g_d3ddevice->SetIndices(m_ibo))) 180 Abort(); 181 if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, m_indices.Count()))) 182 Abort(); 183 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ 184 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); 185 int size; 186 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 187 188 189 glDrawElements(GL_TRIANGLES, size / sizeof(uint16_t), GL_UNSIGNED_SHORT, 0); 190 191 glBindBuffer(GL_ARRAY_BUFFER, 0); 192 #else 193 /* FIXME */ 194 glEnableClientState(GL_VERTEX_ARRAY); 195 glVertexPointer(3, GL_FLOAT, 0, m_vertices); 196 glDisableClientState(GL_VERTEX_ARRAY); 197 #endif 149 m_ibo->Bind(); 150 m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, 8, 0, 151 m_indices.Count()); 152 m_ibo->Unbind(); 198 153 m_vdecl->Unbind(); 199 154 } … … 209 164 VertexDeclaration *m_vdecl; 210 165 VertexBuffer *m_vbo; 211 #if defined USE_D3D9 212 IDirect3DIndexBuffer9 *m_ibo; 213 #elif defined _XBOX 214 D3DIndexBuffer *m_ibo; 215 #else 216 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ 217 GLuint m_ibo; 218 #endif 219 #endif 166 IndexBuffer *m_ibo; 220 167 bool m_ready; 221 168 }; -
trunk/win32/lolcore.vcxproj
r1237 r1247 87 87 <ClCompile Include="..\src\forge.cpp" /> 88 88 <ClCompile Include="..\src\gpu\shader.cpp" /> 89 <ClCompile Include="..\src\gpu\vbo.cpp" />90 89 <ClCompile Include="..\src\gpu\vertexbuffer.cpp" /> 91 90 <ClCompile Include="..\src\gradient.cpp" /> … … 141 140 <ClInclude Include="..\src\forge.h" /> 142 141 <ClInclude Include="..\src\gpu\shader.h" /> 143 <ClInclude Include="..\src\gpu\vbo.h" />144 142 <ClInclude Include="..\src\gpu\vertexbuffer.h" /> 145 143 <ClInclude Include="..\src\gradient.h" /> -
trunk/win32/lolcore.vcxproj.filters
r1224 r1247 161 161 <Filter>src</Filter> 162 162 </ClCompile> 163 <ClCompile Include="..\src\gpu\indexbuffer.cpp"> 164 <Filter>src\gpu</Filter> 165 </ClCompile> 163 166 <ClCompile Include="..\src\gpu\shader.cpp"> 164 <Filter>src\gpu</Filter>165 </ClCompile>166 <ClCompile Include="..\src\gpu\vbo.cpp">167 167 <Filter>src\gpu</Filter> 168 168 </ClCompile> … … 337 337 <Filter>src\lol</Filter> 338 338 </ClInclude> 339 <ClInclude Include="..\src\gpu\indexbuffer.h"> 340 <Filter>src\gpu</Filter> 341 </ClInclude> 339 342 <ClInclude Include="..\src\gpu\shader.h"> 340 <Filter>src\gpu</Filter>341 </ClInclude>342 <ClInclude Include="..\src\gpu\vbo.h">343 343 <Filter>src\gpu</Filter> 344 344 </ClInclude>
Note: See TracChangeset
for help on using the changeset viewer.