1 // Copyright (C) 2002-2008 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "COGLESDriver.h"
\r
6 #include "CNullDriver.h"
\r
7 #include "IContextManager.h"
\r
9 #ifdef _IRR_COMPILE_WITH_OGLES1_
\r
11 #include "COpenGLCoreTexture.h"
\r
12 #include "COpenGLCoreRenderTarget.h"
\r
13 #include "COpenGLCoreCacheHandler.h"
\r
15 #include "COGLESMaterialRenderer.h"
\r
17 #include "EVertexAttributes.h"
\r
20 #include "EProfileIDs.h"
\r
21 #include "IProfiler.h"
\r
23 #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
\r
24 #include "android_native_app_glue.h"
\r
32 COGLES1Driver::COGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) :
\r
33 CNullDriver(io, params.WindowSize), COGLES1ExtensionHandler(), CacheHandler(0), CurrentRenderMode(ERM_NONE),
\r
34 ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(params.AntiAlias),
\r
35 ColorFormat(ECF_R8G8B8), Params(params), ContextManager(contextManager)
\r
38 setDebugName("COGLESDriver");
\r
41 core::dimension2d<u32> windowSize(0, 0);
\r
43 if (!ContextManager)
\r
46 ContextManager->grab();
\r
47 ContextManager->generateSurface();
\r
48 ContextManager->generateContext();
\r
49 ExposedData = ContextManager->getContext();
\r
50 ContextManager->activateContext(ExposedData, false);
\r
52 windowSize = params.WindowSize;
\r
54 genericDriverInit(windowSize, params.Stencilbuffer);
\r
57 COGLES1Driver::~COGLES1Driver()
\r
59 RequestedLights.clear();
\r
61 deleteMaterialRenders();
\r
63 CacheHandler->getTextureCache().clear();
\r
65 removeAllRenderTargets();
\r
66 deleteAllTextures();
\r
67 removeAllOcclusionQueries();
\r
68 removeAllHardwareBuffers();
\r
70 delete CacheHandler;
\r
74 ContextManager->destroyContext();
\r
75 ContextManager->destroySurface();
\r
76 ContextManager->terminate();
\r
77 ContextManager->drop();
\r
81 // -----------------------------------------------------------------------
\r
83 // -----------------------------------------------------------------------
\r
85 bool COGLES1Driver::genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer)
\r
87 Name=glGetString(GL_VERSION);
\r
90 // print renderer information
\r
91 VendorName = glGetString(GL_VENDOR);
\r
92 os::Printer::log(VendorName.c_str(), ELL_INFORMATION);
\r
97 // reset cache handler
\r
98 delete CacheHandler;
\r
99 CacheHandler = new COGLES1CacheHandler(this);
\r
101 StencilBuffer = stencilBuffer;
\r
103 DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits);
\r
104 DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits);
\r
105 DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy);
\r
106 DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices);
\r
107 DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize);
\r
108 DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias);
\r
109 DriverAttributes->setAttribute("Version", Version);
\r
110 DriverAttributes->setAttribute("AntiAlias", AntiAlias);
\r
112 glPixelStorei(GL_PACK_ALIGNMENT, 1);
\r
114 UserClipPlane.reallocate(MaxUserClipPlanes);
\r
115 UserClipPlaneEnabled.reallocate(MaxUserClipPlanes);
\r
117 for (s32 i = 0; i < MaxUserClipPlanes; ++i)
\r
119 UserClipPlane.push_back(core::plane3df());
\r
120 UserClipPlaneEnabled.push_back(false);
\r
123 for (s32 i = 0; i < ETS_COUNT; ++i)
\r
124 setTransform(static_cast<E_TRANSFORMATION_STATE>(i), core::IdentityMatrix);
\r
126 setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f));
\r
127 glClearDepthf(1.0f);
\r
129 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
\r
130 glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
\r
131 glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
\r
132 glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
\r
133 glDepthFunc(GL_LEQUAL);
\r
134 glFrontFace(GL_CW);
\r
135 glAlphaFunc(GL_GREATER, 0.f);
\r
137 // create material renderers
\r
138 createMaterialRenderers();
\r
140 // set the renderstates
\r
141 setRenderStates3DMode();
\r
144 setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
\r
146 // create matrix for flipping textures
\r
147 TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f));
\r
149 // We need to reset once more at the beginning of the first rendering.
\r
150 // This fixes problems with intermediate changes to the material during texture load.
\r
151 ResetRenderStates = true;
\r
153 testGLError(__LINE__);
\r
159 void COGLES1Driver::createMaterialRenderers()
\r
161 // create OGLES1 material renderers
\r
163 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_SOLID(this));
\r
164 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_SOLID_2_LAYER(this));
\r
166 // add the same renderer for all lightmap types
\r
167 COGLES1MaterialRenderer_LIGHTMAP* lmr = new COGLES1MaterialRenderer_LIGHTMAP(this);
\r
168 addMaterialRenderer(lmr); // for EMT_LIGHTMAP:
\r
169 addMaterialRenderer(lmr); // for EMT_LIGHTMAP_ADD:
\r
170 addMaterialRenderer(lmr); // for EMT_LIGHTMAP_M2:
\r
171 addMaterialRenderer(lmr); // for EMT_LIGHTMAP_M4:
\r
172 addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING:
\r
173 addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING_M2:
\r
174 addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING_M4:
\r
177 // add remaining material renderer
\r
178 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_DETAIL_MAP(this));
\r
179 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_SPHERE_MAP(this));
\r
180 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_REFLECTION_2_LAYER(this));
\r
181 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ADD_COLOR(this));
\r
182 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(this));
\r
183 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(this));
\r
184 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(this));
\r
185 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(this));
\r
187 // add basic 1 texture blending
\r
188 addAndDropMaterialRenderer(new COGLES1MaterialRenderer_ONETEXTURE_BLEND(this));
\r
191 bool COGLES1Driver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData& videoData, core::rect<s32>* sourceRect)
\r
193 IRR_PROFILE(CProfileScope p1(EPID_ES2_BEGIN_SCENE);)
\r
195 CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect);
\r
197 if (ContextManager)
\r
198 ContextManager->activateContext(videoData, true);
\r
200 clearBuffers(clearFlag, clearColor, clearDepth, clearStencil);
\r
205 bool COGLES1Driver::endScene()
\r
207 IRR_PROFILE(CProfileScope p1(EPID_ES2_END_SCENE);)
\r
209 CNullDriver::endScene();
\r
213 if (ContextManager)
\r
214 return ContextManager->swapBuffers();
\r
220 //! Returns the transformation set by setTransform
\r
221 const core::matrix4& COGLES1Driver::getTransform(E_TRANSFORMATION_STATE state) const
\r
223 return Matrices[state];
\r
227 //! sets transformation
\r
228 void COGLES1Driver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat)
\r
230 Matrices[state] = mat;
\r
231 Transformation3DChanged = true;
\r
238 // OGLES1 only has a model matrix, view and world is not existent. so lets fake these two.
\r
239 glMatrixMode(GL_MODELVIEW);
\r
240 glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
\r
241 // we have to update the clip planes to the latest view matrix
\r
242 for (u32 i=0; i<MaxUserClipPlanes; ++i)
\r
243 if (UserClipPlaneEnabled[i])
\r
244 uploadClipPlane(i);
\r
247 case ETS_PROJECTION:
\r
250 getGLMatrix(glmat, mat);
\r
251 // flip z to compensate OGLES1s right-hand coordinate system
\r
252 glmat[12] *= -1.0f;
\r
253 glMatrixMode(GL_PROJECTION);
\r
254 glLoadMatrixf(glmat);
\r
262 bool COGLES1Driver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
\r
267 const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer;
\r
268 const void* vertices=mb->getVertices();
\r
269 const u32 vertexCount=mb->getVertexCount();
\r
270 const E_VERTEX_TYPE vType=mb->getVertexType();
\r
271 const u32 vertexSize = getVertexPitchFromType(vType);
\r
273 //buffer vertex data, and convert colours...
\r
274 core::array<c8> buffer(vertexSize * vertexCount);
\r
275 memcpy(buffer.pointer(), vertices, vertexSize * vertexCount);
\r
277 // in order to convert the colors into opengl format (RGBA)
\r
282 S3DVertex* pb = reinterpret_cast<S3DVertex*>(buffer.pointer());
\r
283 const S3DVertex* po = static_cast<const S3DVertex*>(vertices);
\r
284 for (u32 i=0; i<vertexCount; i++)
\r
286 po[i].Color.toOpenGLColor((u8*)&(pb[i].Color.color));
\r
292 S3DVertex2TCoords* pb = reinterpret_cast<S3DVertex2TCoords*>(buffer.pointer());
\r
293 const S3DVertex2TCoords* po = static_cast<const S3DVertex2TCoords*>(vertices);
\r
294 for (u32 i=0; i<vertexCount; i++)
\r
296 po[i].Color.toOpenGLColor((u8*)&(pb[i].Color.color));
\r
302 S3DVertexTangents* pb = reinterpret_cast<S3DVertexTangents*>(buffer.pointer());
\r
303 const S3DVertexTangents* po = static_cast<const S3DVertexTangents*>(vertices);
\r
304 for (u32 i=0; i<vertexCount; i++)
\r
306 po[i].Color.toOpenGLColor((u8*)&(pb[i].Color.color));
\r
316 //get or create buffer
\r
317 bool newBuffer=false;
\r
318 if (!HWBuffer->vbo_verticesID)
\r
320 glGenBuffers(1, &HWBuffer->vbo_verticesID);
\r
321 if (!HWBuffer->vbo_verticesID) return false;
\r
324 else if (HWBuffer->vbo_verticesSize < vertexCount*vertexSize)
\r
329 glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID );
\r
331 // copy data to graphics card
\r
333 glBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, buffer.const_pointer());
\r
336 HWBuffer->vbo_verticesSize = vertexCount*vertexSize;
\r
338 if (HWBuffer->Mapped_Vertex==scene::EHM_STATIC)
\r
339 glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_STATIC_DRAW);
\r
341 glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_DYNAMIC_DRAW);
\r
344 glBindBuffer(GL_ARRAY_BUFFER, 0);
\r
346 return (!testGLError(__LINE__));
\r
350 bool COGLES1Driver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
\r
355 const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer;
\r
357 const void* indices=mb->getIndices();
\r
358 u32 indexCount= mb->getIndexCount();
\r
361 switch (mb->getIndexType())
\r
365 indexSize=sizeof(u16);
\r
370 indexSize=sizeof(u32);
\r
380 //get or create buffer
\r
381 bool newBuffer=false;
\r
382 if (!HWBuffer->vbo_indicesID)
\r
384 glGenBuffers(1, &HWBuffer->vbo_indicesID);
\r
385 if (!HWBuffer->vbo_indicesID) return false;
\r
388 else if (HWBuffer->vbo_indicesSize < indexCount*indexSize)
\r
393 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID);
\r
395 // copy data to graphics card
\r
397 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices);
\r
400 HWBuffer->vbo_indicesSize = indexCount*indexSize;
\r
402 if (HWBuffer->Mapped_Index==scene::EHM_STATIC)
\r
403 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW);
\r
405 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW);
\r
408 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
\r
410 return (!testGLError(__LINE__));
\r
414 //! updates hardware buffer if needed
\r
415 bool COGLES1Driver::updateHardwareBuffer(SHWBufferLink *HWBuffer)
\r
420 if (HWBuffer->Mapped_Vertex!=scene::EHM_NEVER)
\r
422 if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex()
\r
423 || !static_cast<SHWBufferLink_opengl*>(HWBuffer)->vbo_verticesID)
\r
426 HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex();
\r
428 if (!updateVertexHardwareBuffer(static_cast<SHWBufferLink_opengl*>(HWBuffer)))
\r
433 if (HWBuffer->Mapped_Index!=scene::EHM_NEVER)
\r
435 if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index()
\r
436 || !((SHWBufferLink_opengl*)HWBuffer)->vbo_indicesID)
\r
439 HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index();
\r
441 if (!updateIndexHardwareBuffer(static_cast<SHWBufferLink_opengl*>(HWBuffer)))
\r
450 //! Create hardware buffer from meshbuffer
\r
451 COGLES1Driver::SHWBufferLink *COGLES1Driver::createHardwareBuffer(const scene::IMeshBuffer* mb)
\r
453 if (!mb || (mb->getHardwareMappingHint_Index()==scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex()==scene::EHM_NEVER))
\r
456 SHWBufferLink_opengl *HWBuffer=new SHWBufferLink_opengl(mb);
\r
459 HWBufferMap.insert(HWBuffer->MeshBuffer, HWBuffer);
\r
461 HWBuffer->ChangedID_Vertex=HWBuffer->MeshBuffer->getChangedID_Vertex();
\r
462 HWBuffer->ChangedID_Index=HWBuffer->MeshBuffer->getChangedID_Index();
\r
463 HWBuffer->Mapped_Vertex=mb->getHardwareMappingHint_Vertex();
\r
464 HWBuffer->Mapped_Index=mb->getHardwareMappingHint_Index();
\r
465 HWBuffer->LastUsed=0;
\r
466 HWBuffer->vbo_verticesID=0;
\r
467 HWBuffer->vbo_indicesID=0;
\r
468 HWBuffer->vbo_verticesSize=0;
\r
469 HWBuffer->vbo_indicesSize=0;
\r
471 if (!updateHardwareBuffer(HWBuffer))
\r
473 deleteHardwareBuffer(HWBuffer);
\r
481 void COGLES1Driver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer)
\r
486 SHWBufferLink_opengl *HWBuffer=static_cast<SHWBufferLink_opengl*>(_HWBuffer);
\r
487 if (HWBuffer->vbo_verticesID)
\r
489 glDeleteBuffers(1, &HWBuffer->vbo_verticesID);
\r
490 HWBuffer->vbo_verticesID=0;
\r
492 if (HWBuffer->vbo_indicesID)
\r
494 glDeleteBuffers(1, &HWBuffer->vbo_indicesID);
\r
495 HWBuffer->vbo_indicesID=0;
\r
498 CNullDriver::deleteHardwareBuffer(_HWBuffer);
\r
502 //! Draw hardware buffer
\r
503 void COGLES1Driver::drawHardwareBuffer(SHWBufferLink *_HWBuffer)
\r
508 SHWBufferLink_opengl *HWBuffer=static_cast<SHWBufferLink_opengl*>(_HWBuffer);
\r
510 updateHardwareBuffer(HWBuffer); //check if update is needed
\r
512 HWBuffer->LastUsed=0;//reset count
\r
514 const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer;
\r
515 const void *vertices=mb->getVertices();
\r
516 const void *indexList=mb->getIndices();
\r
518 if (HWBuffer->Mapped_Vertex!=scene::EHM_NEVER)
\r
520 glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID);
\r
524 if (HWBuffer->Mapped_Index!=scene::EHM_NEVER)
\r
526 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID);
\r
531 drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList,
\r
532 mb->getPrimitiveCount(), mb->getVertexType(),
\r
533 mb->getPrimitiveType(), mb->getIndexType());
\r
535 if (HWBuffer->Mapped_Vertex!=scene::EHM_NEVER)
\r
536 glBindBuffer(GL_ARRAY_BUFFER, 0);
\r
538 if (HWBuffer->Mapped_Index!=scene::EHM_NEVER)
\r
539 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
\r
543 IRenderTarget* COGLES1Driver::addRenderTarget()
\r
545 COGLES1RenderTarget* renderTarget = new COGLES1RenderTarget(this);
\r
546 RenderTargets.push_back(renderTarget);
\r
548 return renderTarget;
\r
552 // small helper function to create vertex buffer object adress offsets
\r
553 static inline u8* buffer_offset(const long offset)
\r
555 return ((u8*)0 + offset);
\r
559 //! draws a vertex primitive list
\r
560 void COGLES1Driver::drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
\r
561 const void* indexList, u32 primitiveCount,
\r
562 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
\r
564 if (!checkPrimitiveCount(primitiveCount))
\r
567 setRenderStates3DMode();
\r
569 drawVertexPrimitiveList2d3d(vertices, vertexCount, (const u16*)indexList, primitiveCount, vType, pType, iType);
\r
573 void COGLES1Driver::drawVertexPrimitiveList2d3d(const void* vertices, u32 vertexCount,
\r
574 const void* indexList, u32 primitiveCount,
\r
575 E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType, bool threed)
\r
577 if (!primitiveCount || !vertexCount)
\r
580 if (!threed && !checkPrimitiveCount(primitiveCount))
\r
583 CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType);
\r
587 // convert colors to gl color format.
\r
588 vertexCount *= 4; //reused as color component count
\r
589 ColorBuffer.set_used(vertexCount);
\r
596 const S3DVertex* p = static_cast<const S3DVertex*>(vertices);
\r
597 for ( i=0; i<vertexCount; i+=4)
\r
599 p->Color.toOpenGLColor(&ColorBuffer[i]);
\r
606 const S3DVertex2TCoords* p = static_cast<const S3DVertex2TCoords*>(vertices);
\r
607 for ( i=0; i<vertexCount; i+=4)
\r
609 p->Color.toOpenGLColor(&ColorBuffer[i]);
\r
616 const S3DVertexTangents* p = static_cast<const S3DVertexTangents*>(vertices);
\r
617 for ( i=0; i<vertexCount; i+=4)
\r
619 p->Color.toOpenGLColor(&ColorBuffer[i]);
\r
628 glClientActiveTexture(GL_TEXTURE0);
\r
629 glEnableClientState(GL_COLOR_ARRAY);
\r
630 glEnableClientState(GL_VERTEX_ARRAY);
\r
631 if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES))
\r
632 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
\r
633 #ifdef GL_OES_point_size_array
\r
634 else if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_size_array] && (Material.Thickness==0.0f))
\r
635 glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
\r
637 if (threed && (pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES))
\r
638 glEnableClientState(GL_NORMAL_ARRAY);
\r
641 glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
\r
649 glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Normal);
\r
650 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
\r
651 glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
\r
655 glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12));
\r
656 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24));
\r
657 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
\r
658 glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0);
\r
661 if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache().get(1))
\r
663 glClientActiveTexture(GL_TEXTURE0 + 1);
\r
664 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
\r
666 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
\r
668 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
\r
675 glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Normal);
\r
676 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].TCoords);
\r
677 glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Pos);
\r
681 glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12));
\r
682 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24));
\r
683 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28));
\r
684 glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0));
\r
687 if (Feature.MaxTextureUnits > 0)
\r
689 glClientActiveTexture(GL_TEXTURE0 + 1);
\r
690 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
\r
692 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].TCoords2);
\r
694 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36));
\r
701 glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Normal);
\r
702 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].TCoords);
\r
703 glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Pos);
\r
707 glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12));
\r
708 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24));
\r
709 glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28));
\r
710 glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0));
\r
713 if (Feature.MaxTextureUnits > 0)
\r
715 glClientActiveTexture(GL_TEXTURE0 + 1);
\r
716 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
\r
718 glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Tangent);
\r
720 glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36));
\r
722 glClientActiveTexture(GL_TEXTURE0 + 2);
\r
723 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
\r
725 glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Binormal);
\r
727 glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(48));
\r
732 GLenum indexSize=0;
\r
738 indexSize=GL_UNSIGNED_SHORT;
\r
743 #ifdef GL_OES_element_index_uint
\r
744 #ifndef GL_UNSIGNED_INT
\r
745 #define GL_UNSIGNED_INT 0x1405
\r
747 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_element_index_uint])
\r
748 indexSize=GL_UNSIGNED_INT;
\r
751 indexSize=GL_UNSIGNED_SHORT;
\r
758 case scene::EPT_POINTS:
\r
759 case scene::EPT_POINT_SPRITES:
\r
761 #ifdef GL_OES_point_sprite
\r
762 if (pType==scene::EPT_POINT_SPRITES && FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_sprite])
\r
763 glEnable(GL_POINT_SPRITE_OES);
\r
765 // if ==0 we use the point size array
\r
766 if (Material.Thickness!=0.f)
\r
768 float quadratic[] = {0.0f, 0.0f, 10.01f};
\r
769 glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, quadratic);
\r
770 float maxParticleSize=1.0f;
\r
771 glGetFloatv(GL_POINT_SIZE_MAX, &maxParticleSize);
\r
772 // maxParticleSize=maxParticleSize<Material.Thickness?maxParticleSize:Material.Thickness;
\r
773 // extGlPointParameterf(GL_POINT_SIZE_MAX,maxParticleSize);
\r
774 // extGlPointParameterf(GL_POINT_SIZE_MIN,Material.Thickness);
\r
775 glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 60.0f);
\r
776 glPointSize(Material.Thickness);
\r
778 #ifdef GL_OES_point_sprite
\r
779 if (pType==scene::EPT_POINT_SPRITES && FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_sprite])
\r
780 glTexEnvf(GL_POINT_SPRITE_OES,GL_COORD_REPLACE_OES, GL_TRUE);
\r
782 glDrawArrays(GL_POINTS, 0, primitiveCount);
\r
783 #ifdef GL_OES_point_sprite
\r
784 if (pType==scene::EPT_POINT_SPRITES && FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_sprite])
\r
786 glDisable(GL_POINT_SPRITE_OES);
\r
787 glTexEnvf(GL_POINT_SPRITE_OES,GL_COORD_REPLACE_OES, GL_FALSE);
\r
792 case scene::EPT_LINE_STRIP:
\r
793 glDrawElements(GL_LINE_STRIP, primitiveCount+1, indexSize, indexList);
\r
795 case scene::EPT_LINE_LOOP:
\r
796 glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList);
\r
798 case scene::EPT_LINES:
\r
799 glDrawElements(GL_LINES, primitiveCount*2, indexSize, indexList);
\r
801 case scene::EPT_TRIANGLE_STRIP:
\r
802 glDrawElements(GL_TRIANGLE_STRIP, primitiveCount+2, indexSize, indexList);
\r
804 case scene::EPT_TRIANGLE_FAN:
\r
805 glDrawElements(GL_TRIANGLE_FAN, primitiveCount+2, indexSize, indexList);
\r
807 case scene::EPT_TRIANGLES:
\r
808 glDrawElements((LastMaterial.Wireframe)?GL_LINES:(LastMaterial.PointCloud)?GL_POINTS:GL_TRIANGLES, primitiveCount*3, indexSize, indexList);
\r
810 case scene::EPT_QUAD_STRIP:
\r
811 case scene::EPT_QUADS:
\r
812 case scene::EPT_POLYGON:
\r
816 if (Feature.MaxTextureUnits > 0)
\r
818 if (vType == EVT_TANGENTS)
\r
820 glClientActiveTexture(GL_TEXTURE0 + 2);
\r
821 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
\r
823 if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache().get(1))
\r
825 glClientActiveTexture(GL_TEXTURE0 + 1);
\r
826 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
\r
828 glClientActiveTexture(GL_TEXTURE0);
\r
831 #ifdef GL_OES_point_size_array
\r
832 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_size_array] && (Material.Thickness==0.0f))
\r
833 glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
\r
836 glDisableClientState(GL_COLOR_ARRAY);
\r
837 glDisableClientState(GL_VERTEX_ARRAY);
\r
838 glDisableClientState(GL_NORMAL_ARRAY);
\r
839 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
\r
843 //! draws a 2d image, using a color and the alpha channel of the texture
\r
844 void COGLES1Driver::draw2DImage(const video::ITexture* texture,
\r
845 const core::position2d<s32>& pos,
\r
846 const core::rect<s32>& sourceRect,
\r
847 const core::rect<s32>* clipRect, SColor color,
\r
848 bool useAlphaChannelOfTexture)
\r
853 if (!sourceRect.isValid())
\r
856 core::position2d<s32> targetPos(pos);
\r
857 core::position2d<s32> sourcePos(sourceRect.UpperLeftCorner);
\r
858 core::dimension2d<s32> sourceSize(sourceRect.getSize());
\r
861 if (targetPos.X < clipRect->UpperLeftCorner.X)
\r
863 sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X;
\r
864 if (sourceSize.Width <= 0)
\r
867 sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X;
\r
868 targetPos.X = clipRect->UpperLeftCorner.X;
\r
871 if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X)
\r
873 sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;
\r
874 if (sourceSize.Width <= 0)
\r
878 if (targetPos.Y < clipRect->UpperLeftCorner.Y)
\r
880 sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;
\r
881 if (sourceSize.Height <= 0)
\r
884 sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;
\r
885 targetPos.Y = clipRect->UpperLeftCorner.Y;
\r
888 if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y)
\r
890 sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;
\r
891 if (sourceSize.Height <= 0)
\r
896 // clip these coordinates
\r
900 sourceSize.Width += targetPos.X;
\r
901 if (sourceSize.Width <= 0)
\r
904 sourcePos.X -= targetPos.X;
\r
908 const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
\r
910 if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width)
\r
912 sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
\r
913 if (sourceSize.Width <= 0)
\r
919 sourceSize.Height += targetPos.Y;
\r
920 if (sourceSize.Height <= 0)
\r
923 sourcePos.Y -= targetPos.Y;
\r
927 if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height)
\r
929 sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
\r
930 if (sourceSize.Height <= 0)
\r
934 // ok, we've clipped everything.
\r
937 // texcoords need to be flipped horizontally for RTTs
\r
938 const bool isRTT = texture->isRenderTarget();
\r
939 const core::dimension2d<u32>& ss = texture->getOriginalSize();
\r
940 const f32 invW = 1.f / static_cast<f32>(ss.Width);
\r
941 const f32 invH = 1.f / static_cast<f32>(ss.Height);
\r
942 const core::rect<f32> tcoords(
\r
943 sourcePos.X * invW,
\r
944 (isRTT?(sourcePos.Y + sourceSize.Height):sourcePos.Y) * invH,
\r
945 (sourcePos.X + sourceSize.Width) * invW,
\r
946 (isRTT?sourcePos.Y:(sourcePos.Y + sourceSize.Height)) * invH);
\r
948 const core::rect<s32> poss(targetPos, sourceSize);
\r
950 if (!CacheHandler->getTextureCache().set(0, texture))
\r
953 setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
\r
955 u16 indices[] = {0,1,2,3};
\r
956 S3DVertex vertices[4];
\r
957 vertices[0] = S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0,0,1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
\r
958 vertices[1] = S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0,0,1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
\r
959 vertices[2] = S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0,0,1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
\r
960 vertices[3] = S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0,0,1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
\r
961 drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false);
\r
965 //! The same, but with a four element array of colors, one for each vertex
\r
966 void COGLES1Driver::draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
\r
967 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
\r
968 const video::SColor* const colors, bool useAlphaChannelOfTexture)
\r
973 // texcoords need to be flipped horizontally for RTTs
\r
974 const bool isRTT = texture->isRenderTarget();
\r
975 const core::dimension2du& ss = texture->getOriginalSize();
\r
976 const f32 invW = 1.f / static_cast<f32>(ss.Width);
\r
977 const f32 invH = 1.f / static_cast<f32>(ss.Height);
\r
978 const core::rect<f32> tcoords(
\r
979 sourceRect.UpperLeftCorner.X * invW,
\r
980 (isRTT?sourceRect.LowerRightCorner.Y:sourceRect.UpperLeftCorner.Y) * invH,
\r
981 sourceRect.LowerRightCorner.X * invW,
\r
982 (isRTT?sourceRect.UpperLeftCorner.Y:sourceRect.LowerRightCorner.Y) *invH);
\r
984 const video::SColor temp[4] =
\r
992 const video::SColor* const useColor = colors ? colors : temp;
\r
994 if (!CacheHandler->getTextureCache().set(0, texture))
\r
997 setRenderStates2DMode(useColor[0].getAlpha()<255 || useColor[1].getAlpha()<255 ||
\r
998 useColor[2].getAlpha()<255 || useColor[3].getAlpha()<255,
\r
999 true, useAlphaChannelOfTexture);
\r
1003 if (!clipRect->isValid())
\r
1006 glEnable(GL_SCISSOR_TEST);
\r
1007 const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
\r
1008 glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height-clipRect->LowerRightCorner.Y,
\r
1009 clipRect->getWidth(), clipRect->getHeight());
\r
1012 u16 indices[] = {0,1,2,3};
\r
1013 S3DVertex vertices[4];
\r
1014 vertices[0] = S3DVertex((f32)destRect.UpperLeftCorner.X, (f32)destRect.UpperLeftCorner.Y, 0, 0,0,1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
\r
1015 vertices[1] = S3DVertex((f32)destRect.LowerRightCorner.X, (f32)destRect.UpperLeftCorner.Y, 0, 0,0,1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
\r
1016 vertices[2] = S3DVertex((f32)destRect.LowerRightCorner.X, (f32)destRect.LowerRightCorner.Y, 0, 0,0,1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
\r
1017 vertices[3] = S3DVertex((f32)destRect.UpperLeftCorner.X, (f32)destRect.LowerRightCorner.Y, 0, 0,0,1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
\r
1018 drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false);
\r
1021 glDisable(GL_SCISSOR_TEST);
\r
1024 void COGLES1Driver::draw2DImage(const video::ITexture* texture, u32 layer, bool flip)
\r
1026 if (!texture || !CacheHandler->getTextureCache().set(0, texture))
\r
1029 setRenderStates2DMode(false, true, true);
\r
1031 glMatrixMode(GL_PROJECTION);
\r
1033 glMatrixMode(GL_MODELVIEW);
\r
1036 Transformation3DChanged = true;
\r
1038 u16 indices[] = { 0,1,2,3 };
\r
1039 S3DVertex vertices[4];
\r
1041 vertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f);
\r
1042 vertices[1].Pos = core::vector3df(1.f, 1.f, 0.f);
\r
1043 vertices[2].Pos = core::vector3df(1.f, -1.f, 0.f);
\r
1044 vertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f);
\r
1046 f32 modificator = (flip) ? 1.f : 0.f;
\r
1048 vertices[0].TCoords = core::vector2df(0.f, 0.f + modificator);
\r
1049 vertices[1].TCoords = core::vector2df(1.f, 0.f + modificator);
\r
1050 vertices[2].TCoords = core::vector2df(1.f, 1.f - modificator);
\r
1051 vertices[3].TCoords = core::vector2df(0.f, 1.f - modificator);
\r
1053 vertices[0].Color = 0xFFFFFFFF;
\r
1054 vertices[1].Color = 0xFFFFFFFF;
\r
1055 vertices[2].Color = 0xFFFFFFFF;
\r
1056 vertices[3].Color = 0xFFFFFFFF;
\r
1058 drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false);
\r
1062 //! draws a set of 2d images, using a color and the alpha channel
\r
1063 void COGLES1Driver::draw2DImageBatch(const video::ITexture* texture,
\r
1064 const core::position2d<s32>& pos,
\r
1065 const core::array<core::rect<s32> >& sourceRects,
\r
1066 const core::array<s32>& indices, s32 kerningWidth,
\r
1067 const core::rect<s32>* clipRect, SColor color,
\r
1068 bool useAlphaChannelOfTexture)
\r
1073 if (!CacheHandler->getTextureCache().set(0, texture))
\r
1076 setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
\r
1080 if (!clipRect->isValid())
\r
1083 glEnable(GL_SCISSOR_TEST);
\r
1084 const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
\r
1085 glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height-clipRect->LowerRightCorner.Y,
\r
1086 clipRect->getWidth(),clipRect->getHeight());
\r
1089 const core::dimension2du& ss = texture->getOriginalSize();
\r
1090 core::position2d<s32> targetPos(pos);
\r
1091 // texcoords need to be flipped horizontally for RTTs
\r
1092 const bool isRTT = texture->isRenderTarget();
\r
1093 const f32 invW = 1.f / static_cast<f32>(ss.Width);
\r
1094 const f32 invH = 1.f / static_cast<f32>(ss.Height);
\r
1096 core::array<S3DVertex> vertices;
\r
1097 core::array<u16> quadIndices;
\r
1098 vertices.reallocate(indices.size()*4);
\r
1099 quadIndices.reallocate(indices.size()*6);
\r
1100 for (u32 i=0; i<indices.size(); ++i)
\r
1102 const s32 currentIndex = indices[i];
\r
1103 if (!sourceRects[currentIndex].isValid())
\r
1106 const core::rect<f32> tcoords(
\r
1107 sourceRects[currentIndex].UpperLeftCorner.X * invW,
\r
1108 (isRTT?sourceRects[currentIndex].LowerRightCorner.Y:sourceRects[currentIndex].UpperLeftCorner.Y) * invH,
\r
1109 sourceRects[currentIndex].LowerRightCorner.X * invW,
\r
1110 (isRTT?sourceRects[currentIndex].UpperLeftCorner.Y:sourceRects[currentIndex].LowerRightCorner.Y) * invH);
\r
1112 const core::rect<s32> poss(targetPos, sourceRects[currentIndex].getSize());
\r
1114 const u32 vstart = vertices.size();
\r
1116 vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0,0,1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y));
\r
1117 vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0,0,1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y));
\r
1118 vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0,0,1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y));
\r
1119 vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0,0,1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y));
\r
1121 quadIndices.push_back(vstart);
\r
1122 quadIndices.push_back(vstart+1);
\r
1123 quadIndices.push_back(vstart+2);
\r
1124 quadIndices.push_back(vstart);
\r
1125 quadIndices.push_back(vstart+2);
\r
1126 quadIndices.push_back(vstart+3);
\r
1128 targetPos.X += sourceRects[currentIndex].getWidth();
\r
1130 if (vertices.size())
\r
1131 drawVertexPrimitiveList2d3d(vertices.pointer(), vertices.size(),
\r
1132 quadIndices.pointer(), vertices.size()/2,
\r
1133 video::EVT_STANDARD, scene::EPT_TRIANGLES,
\r
1134 EIT_16BIT, false);
\r
1136 glDisable(GL_SCISSOR_TEST);
\r
1140 //! draws a set of 2d images, using a color and the alpha channel of the texture if desired.
\r
1141 void COGLES1Driver::draw2DImageBatch(const video::ITexture* texture,
\r
1142 const core::array<core::position2d<s32> >& positions,
\r
1143 const core::array<core::rect<s32> >& sourceRects,
\r
1144 const core::rect<s32>* clipRect,
\r
1146 bool useAlphaChannelOfTexture)
\r
1151 const u32 drawCount = core::min_<u32>(positions.size(), sourceRects.size());
\r
1155 const core::dimension2d<u32>& ss = texture->getOriginalSize();
\r
1156 if (!ss.Width || !ss.Height)
\r
1158 const f32 invW = 1.f / static_cast<f32>(ss.Width);
\r
1159 const f32 invH = 1.f / static_cast<f32>(ss.Height);
\r
1160 const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
\r
1162 if (!CacheHandler->getTextureCache().set(0, texture))
\r
1165 setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
\r
1167 core::array<S3DVertex> vertices;
\r
1168 core::array<u16> quadIndices;
\r
1169 vertices.reallocate(drawCount*4);
\r
1170 quadIndices.reallocate(drawCount*6);
\r
1172 for (u32 i=0; i<drawCount; ++i)
\r
1174 if (!sourceRects[i].isValid())
\r
1177 core::position2d<s32> targetPos(positions[i]);
\r
1178 core::position2d<s32> sourcePos(sourceRects[i].UpperLeftCorner);
\r
1179 // This needs to be signed as it may go negative.
\r
1180 core::dimension2d<s32> sourceSize(sourceRects[i].getSize());
\r
1183 if (targetPos.X < clipRect->UpperLeftCorner.X)
\r
1185 sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X;
\r
1186 if (sourceSize.Width <= 0)
\r
1189 sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X;
\r
1190 targetPos.X = clipRect->UpperLeftCorner.X;
\r
1193 if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X)
\r
1195 sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;
\r
1196 if (sourceSize.Width <= 0)
\r
1200 if (targetPos.Y < clipRect->UpperLeftCorner.Y)
\r
1202 sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;
\r
1203 if (sourceSize.Height <= 0)
\r
1206 sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;
\r
1207 targetPos.Y = clipRect->UpperLeftCorner.Y;
\r
1210 if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y)
\r
1212 sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;
\r
1213 if (sourceSize.Height <= 0)
\r
1218 // clip these coordinates
\r
1220 if (targetPos.X<0)
\r
1222 sourceSize.Width += targetPos.X;
\r
1223 if (sourceSize.Width <= 0)
\r
1226 sourcePos.X -= targetPos.X;
\r
1230 if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width)
\r
1232 sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
\r
1233 if (sourceSize.Width <= 0)
\r
1237 if (targetPos.Y<0)
\r
1239 sourceSize.Height += targetPos.Y;
\r
1240 if (sourceSize.Height <= 0)
\r
1243 sourcePos.Y -= targetPos.Y;
\r
1247 if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height)
\r
1249 sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
\r
1250 if (sourceSize.Height <= 0)
\r
1254 // ok, we've clipped everything.
\r
1256 const core::rect<f32> tcoords(
\r
1257 sourcePos.X * invW,
\r
1258 sourcePos.Y * invH,
\r
1259 (sourcePos.X + sourceSize.Width) * invW,
\r
1260 (sourcePos.Y + sourceSize.Height) * invH);
\r
1262 const core::rect<s32> poss(targetPos, sourceSize);
\r
1264 const u32 vstart = vertices.size();
\r
1266 vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0,0,1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y));
\r
1267 vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0,0,1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y));
\r
1268 vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0,0,1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y));
\r
1269 vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0,0,1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y));
\r
1271 quadIndices.push_back(vstart);
\r
1272 quadIndices.push_back(vstart+1);
\r
1273 quadIndices.push_back(vstart+2);
\r
1274 quadIndices.push_back(vstart);
\r
1275 quadIndices.push_back(vstart+2);
\r
1276 quadIndices.push_back(vstart+3);
\r
1278 if (vertices.size())
\r
1279 drawVertexPrimitiveList2d3d(vertices.pointer(), vertices.size(),
\r
1280 quadIndices.pointer(), vertices.size()/2,
\r
1281 video::EVT_STANDARD, scene::EPT_TRIANGLES,
\r
1282 EIT_16BIT, false);
\r
1286 //! draw a 2d rectangle
\r
1287 void COGLES1Driver::draw2DRectangle(SColor color, const core::rect<s32>& position,
\r
1288 const core::rect<s32>* clip)
\r
1290 setRenderStates2DMode(color.getAlpha() < 255, false, false);
\r
1292 core::rect<s32> pos = position;
\r
1295 pos.clipAgainst(*clip);
\r
1297 if (!pos.isValid())
\r
1300 u16 indices[] = {0,1,2,3};
\r
1301 S3DVertex vertices[4];
\r
1302 vertices[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0,0,1, color, 0,0);
\r
1303 vertices[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0,0,1, color, 0,0);
\r
1304 vertices[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0,0,1, color, 0,0);
\r
1305 vertices[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0,0,1, color, 0,0);
\r
1306 drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false);
\r
1310 //! draw an 2d rectangle
\r
1311 void COGLES1Driver::draw2DRectangle(const core::rect<s32>& position,
\r
1312 SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
\r
1313 const core::rect<s32>* clip)
\r
1315 core::rect<s32> pos = position;
\r
1318 pos.clipAgainst(*clip);
\r
1320 if (!pos.isValid())
\r
1323 setRenderStates2DMode(colorLeftUp.getAlpha() < 255 ||
\r
1324 colorRightUp.getAlpha() < 255 ||
\r
1325 colorLeftDown.getAlpha() < 255 ||
\r
1326 colorRightDown.getAlpha() < 255, false, false);
\r
1328 u16 indices[] = {0,1,2,3};
\r
1329 S3DVertex vertices[4];
\r
1330 vertices[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0,0,1, colorLeftUp, 0,0);
\r
1331 vertices[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0,0,1, colorRightUp, 0,0);
\r
1332 vertices[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0,0,1, colorRightDown, 0,0);
\r
1333 vertices[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0,0,1, colorLeftDown, 0,0);
\r
1334 drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false);
\r
1338 //! Draws a 2d line.
\r
1339 void COGLES1Driver::draw2DLine(const core::position2d<s32>& start,
\r
1340 const core::position2d<s32>& end,
\r
1343 setRenderStates2DMode(color.getAlpha() < 255, false, false);
\r
1345 u16 indices[] = {0,1};
\r
1346 S3DVertex vertices[2];
\r
1347 vertices[0] = S3DVertex((f32)start.X, (f32)start.Y, 0, 0,0,1, color, 0,0);
\r
1348 vertices[1] = S3DVertex((f32)end.X, (f32)end.Y, 0, 0,0,1, color, 1,1);
\r
1349 drawVertexPrimitiveList2d3d(vertices, 2, indices, 1, video::EVT_STANDARD, scene::EPT_LINES, EIT_16BIT, false);
\r
1354 void COGLES1Driver::drawPixel(u32 x, u32 y, const SColor &color)
\r
1356 const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
\r
1357 if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height)
\r
1360 setRenderStates2DMode(color.getAlpha() < 255, false, false);
\r
1362 u16 indices[] = {0};
\r
1363 S3DVertex vertices[1];
\r
1364 vertices[0] = S3DVertex((f32)x, (f32)y, 0, 0, 0, 1, color, 0, 0);
\r
1365 drawVertexPrimitiveList2d3d(vertices, 1, indices, 1, video::EVT_STANDARD, scene::EPT_POINTS, EIT_16BIT, false);
\r
1369 //! creates a matrix in supplied GLfloat array to pass to OGLES1
\r
1370 inline void COGLES1Driver::getGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m)
\r
1372 memcpy(gl_matrix, m.pointer(), 16 * sizeof(f32));
\r
1376 //! creates a opengltexturematrix from a D3D style texture matrix
\r
1377 inline void COGLES1Driver::getGLTextureMatrix(GLfloat *o, const core::matrix4& m)
\r
1400 ITexture* COGLES1Driver::createDeviceDependentTexture(const io::path& name, IImage* image)
\r
1402 core::array<IImage*> imageArray(1);
\r
1403 imageArray.push_back(image);
\r
1405 COGLES1Texture* texture = new COGLES1Texture(name, imageArray, ETT_2D, this);
\r
1410 ITexture* COGLES1Driver::createDeviceDependentTextureCubemap(const io::path& name, const core::array<IImage*>& image)
\r
1412 COGLES1Texture* texture = new COGLES1Texture(name, image, ETT_CUBEMAP, this);
\r
1417 //! Sets a material. All 3d drawing functions draw geometry now using this material.
\r
1418 void COGLES1Driver::setMaterial(const SMaterial& material)
\r
1420 Material = material;
\r
1421 OverrideMaterial.apply(Material);
\r
1423 for (u32 i = 0; i < Feature.MaxTextureUnits; ++i)
\r
1424 setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i));
\r
1428 //! prints error if an error happened.
\r
1429 bool COGLES1Driver::testGLError(int code)
\r
1432 GLenum g = glGetError();
\r
1437 case GL_INVALID_ENUM:
\r
1438 os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR); break;
\r
1439 case GL_INVALID_VALUE:
\r
1440 os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR); break;
\r
1441 case GL_INVALID_OPERATION:
\r
1442 os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR); break;
\r
1443 case GL_STACK_OVERFLOW:
\r
1444 os::Printer::log("GL_STACK_OVERFLOW", core::stringc(code).c_str(), ELL_ERROR); break;
\r
1445 case GL_STACK_UNDERFLOW:
\r
1446 os::Printer::log("GL_STACK_UNDERFLOW", core::stringc(code).c_str(), ELL_ERROR); break;
\r
1447 case GL_OUT_OF_MEMORY:
\r
1448 os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); break;
\r
1450 // _IRR_DEBUG_BREAK_IF(true);
\r
1458 //! sets the needed renderstates
\r
1459 void COGLES1Driver::setRenderStates3DMode()
\r
1461 if (CurrentRenderMode != ERM_3D)
\r
1463 // Reset Texture Stages
\r
1464 CacheHandler->setBlend(false);
\r
1465 glDisable(GL_ALPHA_TEST);
\r
1466 CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
\r
1468 // switch back the matrices
\r
1469 glMatrixMode(GL_MODELVIEW);
\r
1470 glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
\r
1472 GLfloat glmat[16];
\r
1473 getGLMatrix(glmat, Matrices[ETS_PROJECTION]);
\r
1474 glmat[12] *= -1.0f;
\r
1475 glMatrixMode(GL_PROJECTION);
\r
1476 glLoadMatrixf(glmat);
\r
1478 ResetRenderStates = true;
\r
1481 if ( ResetRenderStates || LastMaterial != Material)
\r
1483 // unset old material
\r
1485 if (LastMaterial.MaterialType != Material.MaterialType &&
\r
1486 static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
\r
1487 MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
\r
1489 // set new material.
\r
1490 if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
\r
1491 MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
\r
1492 Material, LastMaterial, ResetRenderStates, this);
\r
1494 LastMaterial = Material;
\r
1495 CacheHandler->correctCacheMaterial(LastMaterial);
\r
1496 ResetRenderStates = false;
\r
1499 if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
\r
1500 MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD);
\r
1502 CurrentRenderMode = ERM_3D;
\r
1506 GLint COGLES1Driver::getTextureWrapMode(u8 clamp) const
\r
1511 // return GL_CLAMP; not supported in ogl-es
\r
1512 return GL_CLAMP_TO_EDGE;
\r
1514 case ETC_CLAMP_TO_EDGE:
\r
1515 return GL_CLAMP_TO_EDGE;
\r
1517 case ETC_CLAMP_TO_BORDER:
\r
1518 // return GL_CLAMP_TO_BORDER; not supported in ogl-es
\r
1519 return GL_CLAMP_TO_EDGE;
\r
1522 #ifdef GL_OES_texture_mirrored_repeat
\r
1523 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_texture_mirrored_repeat])
\r
1524 return GL_MIRRORED_REPEAT_OES;
\r
1529 // the next three are not yet supported at all
\r
1530 case ETC_MIRROR_CLAMP:
\r
1531 case ETC_MIRROR_CLAMP_TO_EDGE:
\r
1532 case ETC_MIRROR_CLAMP_TO_BORDER:
\r
1533 #ifdef GL_OES_texture_mirrored_repeat
\r
1534 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_texture_mirrored_repeat])
\r
1535 return GL_MIRRORED_REPEAT_OES;
\r
1538 return GL_CLAMP_TO_EDGE;
\r
1548 //! Can be called by an IMaterialRenderer to make its work easier.
\r
1549 void COGLES1Driver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
\r
1550 bool resetAllRenderStates)
\r
1552 if (resetAllRenderStates ||
\r
1553 lastmaterial.ColorMaterial != material.ColorMaterial)
\r
1555 // we only have diffuse_and_ambient in ogl-es
\r
1556 if (material.ColorMaterial == ECM_DIFFUSE_AND_AMBIENT)
\r
1557 glEnable(GL_COLOR_MATERIAL);
\r
1559 glDisable(GL_COLOR_MATERIAL);
\r
1562 if (resetAllRenderStates ||
\r
1563 lastmaterial.AmbientColor != material.AmbientColor ||
\r
1564 lastmaterial.DiffuseColor != material.DiffuseColor ||
\r
1565 lastmaterial.EmissiveColor != material.EmissiveColor ||
\r
1566 lastmaterial.ColorMaterial != material.ColorMaterial)
\r
1570 const f32 inv = 1.0f / 255.0f;
\r
1572 if ((material.ColorMaterial != video::ECM_AMBIENT) &&
\r
1573 (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT))
\r
1575 color[0] = material.AmbientColor.getRed() * inv;
\r
1576 color[1] = material.AmbientColor.getGreen() * inv;
\r
1577 color[2] = material.AmbientColor.getBlue() * inv;
\r
1578 color[3] = material.AmbientColor.getAlpha() * inv;
\r
1579 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
\r
1582 if ((material.ColorMaterial != video::ECM_DIFFUSE) &&
\r
1583 (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT))
\r
1585 color[0] = material.DiffuseColor.getRed() * inv;
\r
1586 color[1] = material.DiffuseColor.getGreen() * inv;
\r
1587 color[2] = material.DiffuseColor.getBlue() * inv;
\r
1588 color[3] = material.DiffuseColor.getAlpha() * inv;
\r
1589 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
\r
1592 if (material.ColorMaterial != video::ECM_EMISSIVE)
\r
1594 color[0] = material.EmissiveColor.getRed() * inv;
\r
1595 color[1] = material.EmissiveColor.getGreen() * inv;
\r
1596 color[2] = material.EmissiveColor.getBlue() * inv;
\r
1597 color[3] = material.EmissiveColor.getAlpha() * inv;
\r
1598 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
\r
1602 if (resetAllRenderStates ||
\r
1603 lastmaterial.SpecularColor != material.SpecularColor ||
\r
1604 lastmaterial.Shininess != material.Shininess)
\r
1606 GLfloat color[]={0.f,0.f,0.f,1.f};
\r
1607 const f32 inv = 1.0f / 255.0f;
\r
1609 // disable Specular colors if no shininess is set
\r
1610 if ((material.Shininess != 0.0f) &&
\r
1611 (material.ColorMaterial != video::ECM_SPECULAR))
\r
1613 #ifdef GL_EXT_separate_specular_color
\r
1614 if (FeatureAvailable[IRR_EXT_separate_specular_color])
\r
1615 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
\r
1617 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess);
\r
1618 color[0] = material.SpecularColor.getRed() * inv;
\r
1619 color[1] = material.SpecularColor.getGreen() * inv;
\r
1620 color[2] = material.SpecularColor.getBlue() * inv;
\r
1621 color[3] = material.SpecularColor.getAlpha() * inv;
\r
1622 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
\r
1624 #ifdef GL_EXT_separate_specular_color
\r
1626 if (FeatureAvailable[IRR_EXT_separate_specular_color])
\r
1627 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
\r
1633 // if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud))
\r
1634 // glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud? GL_POINT : GL_FILL);
\r
1637 if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading))
\r
1639 if (material.GouraudShading)
\r
1640 glShadeModel(GL_SMOOTH);
\r
1642 glShadeModel(GL_FLAT);
\r
1646 if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting))
\r
1648 if (material.Lighting)
\r
1649 glEnable(GL_LIGHTING);
\r
1651 glDisable(GL_LIGHTING);
\r
1655 if (resetAllRenderStates || lastmaterial.ZBuffer != material.ZBuffer)
\r
1657 switch (material.ZBuffer)
\r
1659 case ECFN_DISABLED:
\r
1660 glDisable(GL_DEPTH_TEST);
\r
1662 case ECFN_LESSEQUAL:
\r
1663 glEnable(GL_DEPTH_TEST);
\r
1664 glDepthFunc(GL_LEQUAL);
\r
1667 glEnable(GL_DEPTH_TEST);
\r
1668 glDepthFunc(GL_EQUAL);
\r
1671 glEnable(GL_DEPTH_TEST);
\r
1672 glDepthFunc(GL_LESS);
\r
1674 case ECFN_NOTEQUAL:
\r
1675 glEnable(GL_DEPTH_TEST);
\r
1676 glDepthFunc(GL_NOTEQUAL);
\r
1678 case ECFN_GREATEREQUAL:
\r
1679 glEnable(GL_DEPTH_TEST);
\r
1680 glDepthFunc(GL_GEQUAL);
\r
1682 case ECFN_GREATER:
\r
1683 glEnable(GL_DEPTH_TEST);
\r
1684 glDepthFunc(GL_GREATER);
\r
1687 glEnable(GL_DEPTH_TEST);
\r
1688 glDepthFunc(GL_ALWAYS);
\r
1691 glEnable(GL_DEPTH_TEST);
\r
1692 glDepthFunc(GL_NEVER);
\r
1698 if (getWriteZBuffer(material))
\r
1700 glDepthMask(GL_TRUE);
\r
1704 glDepthMask(GL_FALSE);
\r
1707 // back face culling
\r
1708 if (resetAllRenderStates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling))
\r
1710 if ((material.FrontfaceCulling) && (material.BackfaceCulling))
\r
1712 glCullFace(GL_FRONT_AND_BACK);
\r
1713 glEnable(GL_CULL_FACE);
\r
1716 if (material.BackfaceCulling)
\r
1718 glCullFace(GL_BACK);
\r
1719 glEnable(GL_CULL_FACE);
\r
1722 if (material.FrontfaceCulling)
\r
1724 glCullFace(GL_FRONT);
\r
1725 glEnable(GL_CULL_FACE);
\r
1728 glDisable(GL_CULL_FACE);
\r
1732 if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable)
\r
1734 if (material.FogEnable)
\r
1737 glDisable(GL_FOG);
\r
1741 if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals)
\r
1743 if (material.NormalizeNormals)
\r
1744 glEnable(GL_NORMALIZE);
\r
1746 glDisable(GL_NORMALIZE);
\r
1750 if (resetAllRenderStates || lastmaterial.ColorMask != material.ColorMask)
\r
1753 (material.ColorMask & ECP_RED)?GL_TRUE:GL_FALSE,
\r
1754 (material.ColorMask & ECP_GREEN)?GL_TRUE:GL_FALSE,
\r
1755 (material.ColorMask & ECP_BLUE)?GL_TRUE:GL_FALSE,
\r
1756 (material.ColorMask & ECP_ALPHA)?GL_TRUE:GL_FALSE);
\r
1760 if (material.BlendOperation == EBO_NONE)
\r
1761 CacheHandler->setBlend(false);
\r
1764 CacheHandler->setBlend(true);
\r
1766 if (queryFeature(EVDF_BLEND_OPERATIONS))
\r
1768 switch (material.BlendOperation)
\r
1771 #if defined(GL_OES_blend_subtract)
\r
1772 CacheHandler->setBlendEquation(GL_FUNC_ADD_OES);
\r
1775 case EBO_SUBTRACT:
\r
1776 #if defined(GL_OES_blend_subtract)
\r
1777 CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT_OES);
\r
1780 case EBO_REVSUBTRACT:
\r
1781 #if defined(GL_OES_blend_subtract)
\r
1782 CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_OES);
\r
1792 if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF?
\r
1793 && material.MaterialType != EMT_ONETEXTURE_BLEND
\r
1796 E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
\r
1797 E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
\r
1798 E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
\r
1799 E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
\r
1800 E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
\r
1801 u32 alphaSource = 0;
\r
1803 unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, material.BlendFactor);
\r
1805 if (queryFeature(EVDF_BLEND_SEPARATE))
\r
1807 CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact),
\r
1808 getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact));
\r
1812 CacheHandler->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact));
\r
1816 // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver.
\r
1819 if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness)
\r
1823 // glPointSize(core::clamp(static_cast<GLfloat>(material.Thickness), DimSmoothedPoint[0], DimSmoothedPoint[1]));
\r
1824 // we don't use point smoothing
\r
1825 glPointSize(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1]));
\r
1829 glPointSize(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1]));
\r
1830 glLineWidth(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedLine[0], DimAliasedLine[1]));
\r
1835 if (resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing)
\r
1837 // if (FeatureAvailable[IRR_ARB_multisample])
\r
1839 if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE)
\r
1840 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
\r
1841 else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE)
\r
1842 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
\r
1844 if ((AntiAlias >= 2) && (material.AntiAliasing & (EAAM_SIMPLE|EAAM_QUALITY)))
\r
1845 glEnable(GL_MULTISAMPLE);
\r
1847 glDisable(GL_MULTISAMPLE);
\r
1849 if ((material.AntiAliasing & EAAM_LINE_SMOOTH) != (lastmaterial.AntiAliasing & EAAM_LINE_SMOOTH))
\r
1851 if (material.AntiAliasing & EAAM_LINE_SMOOTH)
\r
1852 glEnable(GL_LINE_SMOOTH);
\r
1853 else if (lastmaterial.AntiAliasing & EAAM_LINE_SMOOTH)
\r
1854 glDisable(GL_LINE_SMOOTH);
\r
1856 if ((material.AntiAliasing & EAAM_POINT_SMOOTH) != (lastmaterial.AntiAliasing & EAAM_POINT_SMOOTH))
\r
1858 if (material.AntiAliasing & EAAM_POINT_SMOOTH)
\r
1859 // often in software, and thus very slow
\r
1860 glEnable(GL_POINT_SMOOTH);
\r
1861 else if (lastmaterial.AntiAliasing & EAAM_POINT_SMOOTH)
\r
1862 glDisable(GL_POINT_SMOOTH);
\r
1866 // Texture parameters
\r
1867 setTextureRenderStates(material, resetAllRenderStates);
\r
1870 //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
\r
1871 void COGLES1Driver::setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates)
\r
1873 // Set textures to TU/TIU and apply filters to them
\r
1875 for (s32 i = Feature.MaxTextureUnits - 1; i >= 0; --i)
\r
1877 CacheHandler->getTextureCache().set(i, material.TextureLayer[i].Texture);
\r
1879 const COGLES1Texture* tmpTexture = CacheHandler->getTextureCache().get(i);
\r
1884 GLenum tmpTextureType = tmpTexture->getOpenGLTextureType();
\r
1886 CacheHandler->setActiveTexture(GL_TEXTURE0 + i);
\r
1889 const bool isRTT = tmpTexture->isRenderTarget();
\r
1891 glMatrixMode(GL_TEXTURE);
\r
1893 if (!isRTT && Matrices[ETS_TEXTURE_0 + i].isIdentity())
\r
1897 GLfloat glmat[16];
\r
1899 getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i] * TextureFlipMatrix);
\r
1901 getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i]);
\r
1902 glLoadMatrixf(glmat);
\r
1906 COGLES1Texture::SStatesCache& statesCache = tmpTexture->getStatesCache();
\r
1908 if (resetAllRenderstates)
\r
1909 statesCache.IsCached = false;
\r
1911 #ifdef GL_VERSION_2_1
\r
1912 if (Version >= 210)
\r
1914 if (!statesCache.IsCached || material.TextureLayer[i].LODBias != statesCache.LODBias)
\r
1916 if (material.TextureLayer[i].LODBias)
\r
1918 const float tmp = core::clamp(material.TextureLayer[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
\r
1919 glTexParameterf(tmpTextureType, GL_TEXTURE_LOD_BIAS, tmp);
\r
1922 glTexParameterf(tmpTextureType, GL_TEXTURE_LOD_BIAS, 0.f);
\r
1924 statesCache.LODBias = material.TextureLayer[i].LODBias;
\r
1927 else if (FeatureAvailable[IRR_EXT_texture_lod_bias])
\r
1929 if (material.TextureLayer[i].LODBias)
\r
1931 const float tmp = core::clamp(material.TextureLayer[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
\r
1932 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp);
\r
1935 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f);
\r
1937 #elif defined(GL_EXT_texture_lod_bias)
\r
1938 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_lod_bias])
\r
1940 if (material.TextureLayer[i].LODBias)
\r
1942 const float tmp = core::clamp(material.TextureLayer[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
\r
1943 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp);
\r
1946 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f);
\r
1950 if (!statesCache.IsCached || material.TextureLayer[i].BilinearFilter != statesCache.BilinearFilter ||
\r
1951 material.TextureLayer[i].TrilinearFilter != statesCache.TrilinearFilter)
\r
1953 glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER,
\r
1954 (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST);
\r
1956 statesCache.BilinearFilter = material.TextureLayer[i].BilinearFilter;
\r
1957 statesCache.TrilinearFilter = material.TextureLayer[i].TrilinearFilter;
\r
1960 if (material.UseMipMaps && tmpTexture->hasMipMaps())
\r
1962 if (!statesCache.IsCached || material.TextureLayer[i].BilinearFilter != statesCache.BilinearFilter ||
\r
1963 material.TextureLayer[i].TrilinearFilter != statesCache.TrilinearFilter || !statesCache.MipMapStatus)
\r
1965 glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
\r
1966 material.TextureLayer[i].TrilinearFilter ? GL_LINEAR_MIPMAP_LINEAR :
\r
1967 material.TextureLayer[i].BilinearFilter ? GL_LINEAR_MIPMAP_NEAREST :
\r
1968 GL_NEAREST_MIPMAP_NEAREST);
\r
1970 statesCache.BilinearFilter = material.TextureLayer[i].BilinearFilter;
\r
1971 statesCache.TrilinearFilter = material.TextureLayer[i].TrilinearFilter;
\r
1972 statesCache.MipMapStatus = true;
\r
1977 if (!statesCache.IsCached || material.TextureLayer[i].BilinearFilter != statesCache.BilinearFilter ||
\r
1978 material.TextureLayer[i].TrilinearFilter != statesCache.TrilinearFilter || statesCache.MipMapStatus)
\r
1980 glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
\r
1981 (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST);
\r
1983 statesCache.BilinearFilter = material.TextureLayer[i].BilinearFilter;
\r
1984 statesCache.TrilinearFilter = material.TextureLayer[i].TrilinearFilter;
\r
1985 statesCache.MipMapStatus = false;
\r
1989 #ifdef GL_EXT_texture_filter_anisotropic
\r
1990 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] &&
\r
1991 (!statesCache.IsCached || material.TextureLayer[i].AnisotropicFilter != statesCache.AnisotropicFilter))
\r
1993 glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT,
\r
1994 material.TextureLayer[i].AnisotropicFilter>1 ? core::min_(MaxAnisotropy, material.TextureLayer[i].AnisotropicFilter) : 1);
\r
1996 statesCache.AnisotropicFilter = material.TextureLayer[i].AnisotropicFilter;
\r
2000 if (!statesCache.IsCached || material.TextureLayer[i].TextureWrapU != statesCache.WrapU)
\r
2002 glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayer[i].TextureWrapU));
\r
2003 statesCache.WrapU = material.TextureLayer[i].TextureWrapU;
\r
2006 if (!statesCache.IsCached || material.TextureLayer[i].TextureWrapV != statesCache.WrapV)
\r
2008 glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayer[i].TextureWrapV));
\r
2009 statesCache.WrapV = material.TextureLayer[i].TextureWrapV;
\r
2012 statesCache.IsCached = true;
\r
2015 // be sure to leave in texture stage 0
\r
2016 CacheHandler->setActiveTexture(GL_TEXTURE0);
\r
2020 //! sets the needed renderstates
\r
2021 void COGLES1Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
\r
2023 if (CurrentRenderMode != ERM_2D || Transformation3DChanged)
\r
2025 // unset last 3d material
\r
2026 if (CurrentRenderMode == ERM_3D)
\r
2028 if (static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
\r
2029 MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
\r
2031 if (Transformation3DChanged)
\r
2033 glMatrixMode(GL_PROJECTION);
\r
2035 const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
\r
2036 core::matrix4 m(core::matrix4::EM4CONST_NOTHING);
\r
2037 m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f);
\r
2038 m.setTranslation(core::vector3df(-1, 1, 0));
\r
2039 glLoadMatrixf(m.pointer());
\r
2041 glMatrixMode(GL_MODELVIEW);
\r
2044 Transformation3DChanged = false;
\r
2048 Material = (OverrideMaterial2DEnabled) ? OverrideMaterial2D : InitMaterial2D;
\r
2049 Material.Lighting = false;
\r
2050 Material.TextureLayer[0].Texture = (texture) ? const_cast<COGLES1Texture*>(CacheHandler->getTextureCache().get(0)) : 0;
\r
2051 setTransform(ETS_TEXTURE_0, core::IdentityMatrix);
\r
2053 setBasicRenderStates(Material, LastMaterial, false);
\r
2055 LastMaterial = Material;
\r
2056 CacheHandler->correctCacheMaterial(LastMaterial);
\r
2058 // no alphaChannel without texture
\r
2059 alphaChannel &= texture;
\r
2061 if (alphaChannel || alpha)
\r
2063 CacheHandler->setBlend(true);
\r
2064 CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
\r
2065 glEnable(GL_ALPHA_TEST);
\r
2066 glAlphaFunc(GL_GREATER, 0.f);
\r
2070 CacheHandler->setBlend(false);
\r
2071 glDisable(GL_ALPHA_TEST);
\r
2076 // Due to the transformation change, the previous line would call a reset each frame
\r
2077 // but we can safely reset the variable as it was false before
\r
2078 Transformation3DChanged = false;
\r
2082 // if alpha and alpha texture just modulate, otherwise use only the alpha channel
\r
2085 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
\r
2089 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
\r
2090 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
\r
2091 glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
\r
2092 // rgb always modulates
\r
2093 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
\r
2094 glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
\r
2095 glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
\r
2102 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
\r
2103 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
\r
2104 glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);
\r
2105 // rgb always modulates
\r
2106 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
\r
2107 glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
\r
2108 glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
\r
2112 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
\r
2117 CurrentRenderMode = ERM_2D;
\r
2121 //! \return Returns the name of the video driver.
\r
2122 const wchar_t* COGLES1Driver::getName() const
\r
2124 return Name.c_str();
\r
2128 //! deletes all dynamic lights there are
\r
2129 void COGLES1Driver::deleteAllDynamicLights()
\r
2131 for (s32 i=0; i<MaxLights; ++i)
\r
2132 glDisable(GL_LIGHT0 + i);
\r
2134 RequestedLights.clear();
\r
2136 CNullDriver::deleteAllDynamicLights();
\r
2140 //! adds a dynamic light
\r
2141 s32 COGLES1Driver::addDynamicLight(const SLight& light)
\r
2143 CNullDriver::addDynamicLight(light);
\r
2145 RequestedLights.push_back(RequestedLight(light));
\r
2147 u32 newLightIndex = RequestedLights.size() - 1;
\r
2149 // Try and assign a hardware light just now, but don't worry if I can't
\r
2150 assignHardwareLight(newLightIndex);
\r
2152 return (s32)newLightIndex;
\r
2156 void COGLES1Driver::assignHardwareLight(u32 lightIndex)
\r
2158 setTransform(ETS_WORLD, core::matrix4());
\r
2161 for (lidx=GL_LIGHT0; lidx < GL_LIGHT0 + MaxLights; ++lidx)
\r
2163 if(!glIsEnabled(lidx))
\r
2165 RequestedLights[lightIndex].HardwareLightIndex = lidx;
\r
2170 if(lidx == GL_LIGHT0 + MaxLights) // There's no room for it just now
\r
2174 const SLight & light = RequestedLights[lightIndex].LightData;
\r
2176 switch (light.Type)
\r
2178 case video::ELT_SPOT:
\r
2179 data[0] = light.Direction.X;
\r
2180 data[1] = light.Direction.Y;
\r
2181 data[2] = light.Direction.Z;
\r
2183 glLightfv(lidx, GL_SPOT_DIRECTION, data);
\r
2186 data[0] = light.Position.X;
\r
2187 data[1] = light.Position.Y;
\r
2188 data[2] = light.Position.Z;
\r
2189 data[3] = 1.0f; // 1.0f for positional light
\r
2190 glLightfv(lidx, GL_POSITION, data);
\r
2192 glLightf(lidx, GL_SPOT_EXPONENT, light.Falloff);
\r
2193 glLightf(lidx, GL_SPOT_CUTOFF, light.OuterCone);
\r
2195 case video::ELT_POINT:
\r
2197 data[0] = light.Position.X;
\r
2198 data[1] = light.Position.Y;
\r
2199 data[2] = light.Position.Z;
\r
2200 data[3] = 1.0f; // 1.0f for positional light
\r
2201 glLightfv(lidx, GL_POSITION, data);
\r
2203 glLightf(lidx, GL_SPOT_EXPONENT, 0.0f);
\r
2204 glLightf(lidx, GL_SPOT_CUTOFF, 180.0f);
\r
2206 case video::ELT_DIRECTIONAL:
\r
2208 data[0] = -light.Direction.X;
\r
2209 data[1] = -light.Direction.Y;
\r
2210 data[2] = -light.Direction.Z;
\r
2211 data[3] = 0.0f; // 0.0f for directional light
\r
2212 glLightfv(lidx, GL_POSITION, data);
\r
2214 glLightf(lidx, GL_SPOT_EXPONENT, 0.0f);
\r
2215 glLightf(lidx, GL_SPOT_CUTOFF, 180.0f);
\r
2217 case video::ELT_COUNT:
\r
2221 // set diffuse color
\r
2222 data[0] = light.DiffuseColor.r;
\r
2223 data[1] = light.DiffuseColor.g;
\r
2224 data[2] = light.DiffuseColor.b;
\r
2225 data[3] = light.DiffuseColor.a;
\r
2226 glLightfv(lidx, GL_DIFFUSE, data);
\r
2228 // set specular color
\r
2229 data[0] = light.SpecularColor.r;
\r
2230 data[1] = light.SpecularColor.g;
\r
2231 data[2] = light.SpecularColor.b;
\r
2232 data[3] = light.SpecularColor.a;
\r
2233 glLightfv(lidx, GL_SPECULAR, data);
\r
2235 // set ambient color
\r
2236 data[0] = light.AmbientColor.r;
\r
2237 data[1] = light.AmbientColor.g;
\r
2238 data[2] = light.AmbientColor.b;
\r
2239 data[3] = light.AmbientColor.a;
\r
2240 glLightfv(lidx, GL_AMBIENT, data);
\r
2242 // 1.0f / (constant + linear * d + quadratic*(d*d);
\r
2244 // set attenuation
\r
2245 glLightf(lidx, GL_CONSTANT_ATTENUATION, light.Attenuation.X);
\r
2246 glLightf(lidx, GL_LINEAR_ATTENUATION, light.Attenuation.Y);
\r
2247 glLightf(lidx, GL_QUADRATIC_ATTENUATION, light.Attenuation.Z);
\r
2253 //! Turns a dynamic light on or off
\r
2254 //! \param lightIndex: the index returned by addDynamicLight
\r
2255 //! \param turnOn: true to turn the light on, false to turn it off
\r
2256 void COGLES1Driver::turnLightOn(s32 lightIndex, bool turnOn)
\r
2258 if(lightIndex < 0 || lightIndex >= (s32)RequestedLights.size())
\r
2261 RequestedLight & requestedLight = RequestedLights[lightIndex];
\r
2263 requestedLight.DesireToBeOn = turnOn;
\r
2267 if(-1 == requestedLight.HardwareLightIndex)
\r
2268 assignHardwareLight(lightIndex);
\r
2272 if(-1 != requestedLight.HardwareLightIndex)
\r
2274 // It's currently assigned, so free up the hardware light
\r
2275 glDisable(requestedLight.HardwareLightIndex);
\r
2276 requestedLight.HardwareLightIndex = -1;
\r
2278 // Now let the first light that's waiting on a free hardware light grab it
\r
2279 for(u32 requested = 0; requested < RequestedLights.size(); ++requested)
\r
2280 if(RequestedLights[requested].DesireToBeOn
\r
2282 -1 == RequestedLights[requested].HardwareLightIndex)
\r
2284 assignHardwareLight(requested);
\r
2292 //! returns the maximal amount of dynamic lights the device can handle
\r
2293 u32 COGLES1Driver::getMaximalDynamicLightAmount() const
\r
2299 //! Sets the dynamic ambient light color.
\r
2300 void COGLES1Driver::setAmbientLight(const SColorf& color)
\r
2302 CNullDriver::setAmbientLight(color);
\r
2303 GLfloat data[4] = {color.r, color.g, color.b, color.a};
\r
2304 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data);
\r
2308 // this code was sent in by Oliver Klems, thank you
\r
2309 void COGLES1Driver::setViewPort(const core::rect<s32>& area)
\r
2311 core::rect<s32> vp = area;
\r
2312 core::rect<s32> rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height);
\r
2313 vp.clipAgainst(rendert);
\r
2315 if (vp.getHeight() > 0 && vp.getWidth() > 0)
\r
2316 CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight());
\r
2322 void COGLES1Driver::setViewPortRaw(u32 width, u32 height)
\r
2324 CacheHandler->setViewport(0, 0, width, height);
\r
2325 ViewPort = core::recti(0, 0, width, height);
\r
2329 //! Draws a shadow volume into the stencil buffer.
\r
2330 void COGLES1Driver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
\r
2332 const u32 count=triangles.size();
\r
2333 if (!StencilBuffer || !count)
\r
2336 u8 colorMask = LastMaterial.ColorMask;
\r
2337 const GLboolean lightingEnabled = glIsEnabled(GL_LIGHTING);
\r
2338 const GLboolean fogEnabled = glIsEnabled(GL_FOG);
\r
2339 const GLboolean cullFaceEnabled = glIsEnabled(GL_CULL_FACE);
\r
2341 GLint cullFaceMode = 0;
\r
2342 glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode);
\r
2343 GLint depthFunc = 0;
\r
2344 glGetIntegerv(GL_DEPTH_FUNC, &depthFunc);
\r
2345 GLboolean depthMask = 0;
\r
2346 glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
\r
2348 glDisable(GL_LIGHTING);
\r
2349 glDisable(GL_FOG);
\r
2350 glDepthFunc(GL_LEQUAL);
\r
2351 glDepthMask(GL_FALSE);
\r
2353 if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY)))
\r
2355 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
\r
2356 glEnable(GL_STENCIL_TEST);
\r
2359 glEnableClientState(GL_VERTEX_ARRAY);
\r
2360 glVertexPointer(3, GL_FLOAT, sizeof(core::vector3df), triangles.const_pointer());
\r
2362 glStencilMask(~0);
\r
2363 glStencilFunc(GL_ALWAYS, 0, ~0);
\r
2365 GLenum decr = GL_DECR;
\r
2366 GLenum incr = GL_INCR;
\r
2368 #if defined(GL_OES_stencil_wrap)
\r
2369 if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_stencil_wrap])
\r
2371 decr = GL_DECR_WRAP_OES;
\r
2372 incr = GL_INCR_WRAP_OES;
\r
2376 glEnable(GL_CULL_FACE);
\r
2380 glCullFace(GL_FRONT);
\r
2381 glStencilOp(GL_KEEP, incr, GL_KEEP);
\r
2382 glDrawArrays(GL_TRIANGLES, 0, count);
\r
2384 glCullFace(GL_BACK);
\r
2385 glStencilOp(GL_KEEP, decr, GL_KEEP);
\r
2386 glDrawArrays(GL_TRIANGLES, 0, count);
\r
2390 glCullFace(GL_BACK);
\r
2391 glStencilOp(GL_KEEP, GL_KEEP, incr);
\r
2392 glDrawArrays(GL_TRIANGLES, 0, count);
\r
2394 glCullFace(GL_FRONT);
\r
2395 glStencilOp(GL_KEEP, GL_KEEP, decr);
\r
2396 glDrawArrays(GL_TRIANGLES, 0, count);
\r
2399 glDisableClientState(GL_VERTEX_ARRAY);
\r
2401 glColorMask((colorMask & ECP_RED)?GL_TRUE:GL_FALSE,
\r
2402 (colorMask & ECP_GREEN)?GL_TRUE:GL_FALSE,
\r
2403 (colorMask & ECP_BLUE)?GL_TRUE:GL_FALSE,
\r
2404 (colorMask & ECP_ALPHA)?GL_TRUE:GL_FALSE);
\r
2406 glDisable(GL_STENCIL_TEST);
\r
2408 if (lightingEnabled)
\r
2409 glEnable(GL_LIGHTING);
\r
2414 if (cullFaceEnabled)
\r
2415 glEnable(GL_CULL_FACE);
\r
2417 glDisable(GL_CULL_FACE);
\r
2419 glCullFace(cullFaceMode);
\r
2420 glDepthFunc(depthFunc);
\r
2421 glDepthMask(depthMask);
\r
2425 void COGLES1Driver::drawStencilShadow(bool clearStencilBuffer,
\r
2426 video::SColor leftUpEdge, video::SColor rightUpEdge,
\r
2427 video::SColor leftDownEdge, video::SColor rightDownEdge)
\r
2429 if (!StencilBuffer)
\r
2432 setTextureRenderStates(SMaterial(), false);
\r
2434 u8 colorMask = LastMaterial.ColorMask;
\r
2435 const GLboolean lightingEnabled = glIsEnabled(GL_LIGHTING);
\r
2436 const GLboolean fogEnabled = glIsEnabled(GL_FOG);
\r
2437 const GLboolean blendEnabled = glIsEnabled(GL_BLEND);
\r
2439 GLboolean depthMask = 0;
\r
2440 glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
\r
2441 GLint shadeModel = 0;
\r
2442 glGetIntegerv(GL_SHADE_MODEL, &shadeModel);
\r
2443 GLint blendSrc = 0, blendDst = 0;
\r
2444 glGetIntegerv(GL_BLEND_SRC, &blendSrc);
\r
2445 glGetIntegerv(GL_BLEND_DST, &blendDst);
\r
2447 glDisable(GL_LIGHTING);
\r
2448 glDisable(GL_FOG);
\r
2449 glDepthMask(GL_FALSE);
\r
2451 glShadeModel(GL_FLAT);
\r
2452 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
\r
2454 glEnable(GL_BLEND);
\r
2455 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
\r
2457 glEnable(GL_STENCIL_TEST);
\r
2458 glStencilFunc(GL_NOTEQUAL, 0, ~0);
\r
2459 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
\r
2461 glMatrixMode(GL_MODELVIEW);
\r
2464 glMatrixMode(GL_PROJECTION);
\r
2468 u16 indices[] = {0, 1, 2, 3};
\r
2469 S3DVertex vertices[4];
\r
2470 vertices[0] = S3DVertex(-1.f, 1.f, 0.9f, 0, 0, 1, leftDownEdge, 0, 0);
\r
2471 vertices[1] = S3DVertex(1.f, 1.f, 0.9f, 0, 0, 1, leftUpEdge, 0, 0);
\r
2472 vertices[2] = S3DVertex(1.f, -1.f, 0.9f, 0, 0, 1, rightUpEdge, 0, 0);
\r
2473 vertices[3] = S3DVertex(-1.f, -1.f, 0.9f, 0, 0, 1, rightDownEdge, 0, 0);
\r
2474 drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false);
\r
2476 if (clearStencilBuffer)
\r
2477 glClear(GL_STENCIL_BUFFER_BIT);
\r
2479 glColorMask((colorMask & ECP_RED)?GL_TRUE:GL_FALSE,
\r
2480 (colorMask & ECP_GREEN)?GL_TRUE:GL_FALSE,
\r
2481 (colorMask & ECP_BLUE)?GL_TRUE:GL_FALSE,
\r
2482 (colorMask & ECP_ALPHA)?GL_TRUE:GL_FALSE);
\r
2484 glDisable(GL_STENCIL_TEST);
\r
2487 glMatrixMode(GL_MODELVIEW);
\r
2490 if (lightingEnabled)
\r
2491 glEnable(GL_LIGHTING);
\r
2496 if (!blendEnabled)
\r
2497 glDisable(GL_BLEND);
\r
2499 glDepthMask(depthMask);
\r
2500 glShadeModel(shadeModel);
\r
2501 glBlendFunc(blendSrc, blendDst);
\r
2505 //! Sets the fog mode.
\r
2506 void COGLES1Driver::setFog(SColor c, E_FOG_TYPE fogType, f32 start,
\r
2507 f32 end, f32 density, bool pixelFog, bool rangeFog)
\r
2509 CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog);
\r
2511 glFogf(GL_FOG_MODE, GLfloat((fogType==EFT_FOG_LINEAR)? GL_LINEAR : (fogType==EFT_FOG_EXP)?GL_EXP:GL_EXP2));
\r
2513 #ifdef GL_EXT_fog_coord
\r
2514 if (FeatureAvailable[IRR_EXT_fog_coord])
\r
2515 glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH);
\r
2518 if (fogType==EFT_FOG_LINEAR)
\r
2520 glFogf(GL_FOG_START, start);
\r
2521 glFogf(GL_FOG_END, end);
\r
2524 glFogf(GL_FOG_DENSITY, density);
\r
2527 glHint(GL_FOG_HINT, GL_NICEST);
\r
2529 glHint(GL_FOG_HINT, GL_FASTEST);
\r
2532 GLfloat data[4] = {color.r, color.g, color.b, color.a};
\r
2533 glFogfv(GL_FOG_COLOR, data);
\r
2537 //! Draws a 3d line.
\r
2538 void COGLES1Driver::draw3DLine(const core::vector3df& start,
\r
2539 const core::vector3df& end, SColor color)
\r
2541 setRenderStates3DMode();
\r
2543 u16 indices[] = {0,1};
\r
2544 S3DVertex vertices[2];
\r
2545 vertices[0] = S3DVertex(start.X,start.Y,start.Z, 0,0,1, color, 0,0);
\r
2546 vertices[1] = S3DVertex(end.X,end.Y,end.Z, 0,0,1, color, 0,0);
\r
2547 drawVertexPrimitiveList2d3d(vertices, 2, indices, 1, video::EVT_STANDARD, scene::EPT_LINES);
\r
2551 //! Only used by the internal engine. Used to notify the driver that
\r
2552 //! the window was resized.
\r
2553 void COGLES1Driver::OnResize(const core::dimension2d<u32>& size)
\r
2555 CNullDriver::OnResize(size);
\r
2556 CacheHandler->setViewport(0, 0, size.Width, size.Height);
\r
2557 Transformation3DChanged = true;
\r
2561 //! Returns type of video driver
\r
2562 E_DRIVER_TYPE COGLES1Driver::getDriverType() const
\r
2564 return EDT_OGLES1;
\r
2568 //! returns color format
\r
2569 ECOLOR_FORMAT COGLES1Driver::getColorFormat() const
\r
2571 return ColorFormat;
\r
2575 //! Get a vertex shader constant index.
\r
2576 s32 COGLES1Driver::getVertexShaderConstantID(const c8* name)
\r
2578 return getPixelShaderConstantID(name);
\r
2581 //! Get a pixel shader constant index.
\r
2582 s32 COGLES1Driver::getPixelShaderConstantID(const c8* name)
\r
2584 os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->getPixelShaderConstantID().");
\r
2588 //! Sets a constant for the vertex shader based on an index.
\r
2589 bool COGLES1Driver::setVertexShaderConstant(s32 index, const f32* floats, int count)
\r
2591 //pass this along, as in GLSL the same routine is used for both vertex and fragment shaders
\r
2592 return setPixelShaderConstant(index, floats, count);
\r
2595 //! Int interface for the above.
\r
2596 bool COGLES1Driver::setVertexShaderConstant(s32 index, const s32* ints, int count)
\r
2598 return setPixelShaderConstant(index, ints, count);
\r
2601 bool COGLES1Driver::setVertexShaderConstant(s32 index, const u32* ints, int count)
\r
2603 return setPixelShaderConstant(index, ints, count);
\r
2606 //! Sets a constant for the pixel shader based on an index.
\r
2607 bool COGLES1Driver::setPixelShaderConstant(s32 index, const f32* floats, int count)
\r
2609 os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant().");
\r
2613 //! Int interface for the above.
\r
2614 bool COGLES1Driver::setPixelShaderConstant(s32 index, const s32* ints, int count)
\r
2616 os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant().");
\r
2620 bool COGLES1Driver::setPixelShaderConstant(s32 index, const u32* ints, int count)
\r
2622 os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant().");
\r
2626 //! Sets a vertex shader constant.
\r
2627 void COGLES1Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
\r
2629 #ifdef GL_vertex_program
\r
2630 for (s32 i=0; i<constantAmount; ++i)
\r
2631 extGlProgramLocalParameter4fv(GL_VERTEX_PROGRAM, startRegister+i, &data[i*4]);
\r
2635 //! Sets a pixel shader constant.
\r
2636 void COGLES1Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
\r
2638 #ifdef GL_fragment_program
\r
2639 for (s32 i=0; i<constantAmount; ++i)
\r
2640 extGlProgramLocalParameter4fv(GL_FRAGMENT_PROGRAM, startRegister+i, &data[i*4]);
\r
2645 //! Adds a new material renderer to the VideoDriver, using pixel and/or
\r
2646 //! vertex shaders to render geometry.
\r
2647 s32 COGLES1Driver::addShaderMaterial(const c8* vertexShaderProgram,
\r
2648 const c8* pixelShaderProgram,
\r
2649 IShaderConstantSetCallBack* callback,
\r
2650 E_MATERIAL_TYPE baseMaterial, s32 userData)
\r
2652 os::Printer::log("No shader support.");
\r
2657 //! Adds a new material renderer to the VideoDriver, using GLSL to render geometry.
\r
2658 s32 COGLES1Driver::addHighLevelShaderMaterial(
\r
2659 const c8* vertexShaderProgram,
\r
2660 const c8* vertexShaderEntryPointName,
\r
2661 E_VERTEX_SHADER_TYPE vsCompileTarget,
\r
2662 const c8* pixelShaderProgram,
\r
2663 const c8* pixelShaderEntryPointName,
\r
2664 E_PIXEL_SHADER_TYPE psCompileTarget,
\r
2665 const c8* geometryShaderProgram,
\r
2666 const c8* geometryShaderEntryPointName,
\r
2667 E_GEOMETRY_SHADER_TYPE gsCompileTarget,
\r
2668 scene::E_PRIMITIVE_TYPE inType,
\r
2669 scene::E_PRIMITIVE_TYPE outType,
\r
2671 IShaderConstantSetCallBack* callback,
\r
2672 E_MATERIAL_TYPE baseMaterial,
\r
2675 os::Printer::log("No shader support.");
\r
2679 //! Returns a pointer to the IVideoDriver interface. (Implementation for
\r
2680 //! IMaterialRendererServices)
\r
2681 IVideoDriver* COGLES1Driver::getVideoDriver()
\r
2687 //! Returns pointer to the IGPUProgrammingServices interface.
\r
2688 IGPUProgrammingServices* COGLES1Driver::getGPUProgrammingServices()
\r
2694 ITexture* COGLES1Driver::addRenderTargetTexture(const core::dimension2d<u32>& size,
\r
2695 const io::path& name, const ECOLOR_FORMAT format)
\r
2697 //disable mip-mapping
\r
2698 bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
\r
2699 setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
\r
2701 bool supportForFBO = (Feature.ColorAttachment > 0);
\r
2703 core::dimension2du destSize(size);
\r
2705 if (!supportForFBO)
\r
2707 destSize = core::dimension2d<u32>(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height));
\r
2708 destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false);
\r
2711 COGLES1Texture* renderTargetTexture = new COGLES1Texture(name, destSize, ETT_2D, format, this);
\r
2712 addTexture(renderTargetTexture);
\r
2713 renderTargetTexture->drop();
\r
2715 //restore mip-mapping
\r
2716 setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels);
\r
2718 return renderTargetTexture;
\r
2721 ITexture* COGLES1Driver::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path& name, const ECOLOR_FORMAT format)
\r
2723 //disable mip-mapping
\r
2724 bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
\r
2725 setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
\r
2727 bool supportForFBO = (Feature.ColorAttachment > 0);
\r
2729 const core::dimension2d<u32> size(sideLen, sideLen);
\r
2730 core::dimension2du destSize(size);
\r
2732 if (!supportForFBO)
\r
2734 destSize = core::dimension2d<u32>(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height));
\r
2735 destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false);
\r
2738 COGLES1Texture* renderTargetTexture = new COGLES1Texture(name, destSize, ETT_CUBEMAP, format, this);
\r
2739 addTexture(renderTargetTexture);
\r
2740 renderTargetTexture->drop();
\r
2742 //restore mip-mapping
\r
2743 setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels);
\r
2745 return renderTargetTexture;
\r
2748 //! Returns the maximum amount of primitives
\r
2749 u32 COGLES1Driver::getMaximalPrimitiveCount() const
\r
2754 bool COGLES1Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil)
\r
2756 if (target && target->getDriverType() != EDT_OGLES1)
\r
2758 os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL driver.", ELL_ERROR);
\r
2762 bool supportForFBO = (Feature.ColorAttachment > 0);
\r
2764 core::dimension2d<u32> destRenderTargetSize(0, 0);
\r
2768 COGLES1RenderTarget* renderTarget = static_cast<COGLES1RenderTarget*>(target);
\r
2770 if (supportForFBO)
\r
2772 CacheHandler->setFBO(renderTarget->getBufferID());
\r
2773 renderTarget->update();
\r
2776 destRenderTargetSize = renderTarget->getSize();
\r
2778 setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height);
\r
2782 if (supportForFBO)
\r
2783 CacheHandler->setFBO(0);
\r
2786 COGLES1RenderTarget* prevRenderTarget = static_cast<COGLES1RenderTarget*>(CurrentRenderTarget);
\r
2787 COGLES1Texture* renderTargetTexture = static_cast<COGLES1Texture*>(prevRenderTarget->getTexture());
\r
2789 if (renderTargetTexture)
\r
2791 const COGLES1Texture* prevTexture = CacheHandler->getTextureCache().get(0);
\r
2793 CacheHandler->getTextureCache().set(0, renderTargetTexture);
\r
2795 const core::dimension2d<u32> size = renderTargetTexture->getSize();
\r
2796 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.Width, size.Height);
\r
2798 CacheHandler->getTextureCache().set(0, prevTexture);
\r
2802 destRenderTargetSize = core::dimension2d<u32>(0, 0);
\r
2804 setViewPortRaw(ScreenSize.Width, ScreenSize.Height);
\r
2807 if (CurrentRenderTargetSize != destRenderTargetSize)
\r
2809 CurrentRenderTargetSize = destRenderTargetSize;
\r
2811 Transformation3DChanged = true;
\r
2814 CurrentRenderTarget = target;
\r
2816 if (!supportForFBO)
\r
2818 clearFlag |= ECBF_COLOR;
\r
2819 clearFlag |= ECBF_DEPTH;
\r
2822 clearBuffers(clearFlag, clearColor, clearDepth, clearStencil);
\r
2827 void COGLES1Driver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil)
\r
2829 GLbitfield mask = 0;
\r
2831 if (flag & ECBF_COLOR)
\r
2833 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
\r
2835 const f32 inv = 1.0f / 255.0f;
\r
2836 glClearColor(color.getRed() * inv, color.getGreen() * inv,
\r
2837 color.getBlue() * inv, color.getAlpha() * inv);
\r
2839 mask |= GL_COLOR_BUFFER_BIT;
\r
2842 if (flag & ECBF_DEPTH)
\r
2844 glDepthMask(GL_TRUE);
\r
2845 glClearDepthf(depth);
\r
2846 mask |= GL_DEPTH_BUFFER_BIT;
\r
2849 if (flag & ECBF_STENCIL)
\r
2851 glClearStencil(stencil);
\r
2852 mask |= GL_STENCIL_BUFFER_BIT;
\r
2860 //! Returns an image created from the last rendered frame.
\r
2861 // We want to read the front buffer to get the latest render finished.
\r
2862 // This is not possible under ogl-es, though, so one has to call this method
\r
2863 // outside of the render loop only.
\r
2864 IImage* COGLES1Driver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target)
\r
2866 if (target==video::ERT_MULTI_RENDER_TEXTURES || target==video::ERT_RENDER_TEXTURE || target==video::ERT_STEREO_BOTH_BUFFERS)
\r
2868 GLint internalformat=GL_RGBA;
\r
2869 GLint type=GL_UNSIGNED_BYTE;
\r
2871 && (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_IMG_read_format]
\r
2872 || FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_read_format]
\r
2873 || FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_read_format_bgra]))
\r
2875 #ifdef GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
\r
2876 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &internalformat);
\r
2877 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &type);
\r
2879 // there are formats we don't support ATM
\r
2880 if (GL_UNSIGNED_SHORT_4_4_4_4==type)
\r
2881 type=GL_UNSIGNED_SHORT_5_5_5_1;
\r
2882 #ifdef GL_EXT_read_format_bgra
\r
2883 else if (GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT==type)
\r
2884 type=GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT;
\r
2888 IImage* newImage = 0;
\r
2889 if ((GL_RGBA==internalformat)
\r
2890 #ifdef GL_EXT_read_format_bgra
\r
2891 || (GL_BGRA_EXT==internalformat)
\r
2895 if (GL_UNSIGNED_BYTE==type)
\r
2896 newImage = new CImage(ECF_A8R8G8B8, ScreenSize);
\r
2898 newImage = new CImage(ECF_A1R5G5B5, ScreenSize);
\r
2902 if (GL_UNSIGNED_BYTE==type)
\r
2903 newImage = new CImage(ECF_R8G8B8, ScreenSize);
\r
2905 newImage = new CImage(ECF_R5G6B5, ScreenSize);
\r
2908 u8* pixels = static_cast<u8*>(newImage->getData());
\r
2915 glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels);
\r
2917 // opengl images are horizontally flipped, so we have to fix that here.
\r
2918 const s32 pitch=newImage->getPitch();
\r
2919 u8* p2 = pixels + (ScreenSize.Height - 1) * pitch;
\r
2920 u8* tmpBuffer = new u8[pitch];
\r
2921 for (u32 i=0; i < ScreenSize.Height; i += 2)
\r
2923 memcpy(tmpBuffer, pixels, pitch);
\r
2924 memcpy(pixels, p2, pitch);
\r
2925 memcpy(p2, tmpBuffer, pitch);
\r
2929 delete [] tmpBuffer;
\r
2931 if (testGLError(__LINE__))
\r
2940 void COGLES1Driver::removeTexture(ITexture* texture)
\r
2942 CacheHandler->getTextureCache().remove(texture);
\r
2943 CNullDriver::removeTexture(texture);
\r
2947 //! Set/unset a clipping plane.
\r
2948 bool COGLES1Driver::setClipPlane(u32 index, const core::plane3df& plane, bool enable)
\r
2950 if (index >= MaxUserClipPlanes)
\r
2953 UserClipPlane[index]=plane;
\r
2954 enableClipPlane(index, enable);
\r
2959 void COGLES1Driver::uploadClipPlane(u32 index)
\r
2961 // opengl needs an array of doubles for the plane equation
\r
2962 float clip_plane[4];
\r
2963 clip_plane[0] = UserClipPlane[index].Normal.X;
\r
2964 clip_plane[1] = UserClipPlane[index].Normal.Y;
\r
2965 clip_plane[2] = UserClipPlane[index].Normal.Z;
\r
2966 clip_plane[3] = UserClipPlane[index].D;
\r
2967 glClipPlanef(GL_CLIP_PLANE0 + index, clip_plane);
\r
2971 //! Enable/disable a clipping plane.
\r
2972 void COGLES1Driver::enableClipPlane(u32 index, bool enable)
\r
2974 if (index >= MaxUserClipPlanes)
\r
2978 if (!UserClipPlaneEnabled[index])
\r
2980 uploadClipPlane(index);
\r
2981 glEnable(GL_CLIP_PLANE0 + index);
\r
2985 glDisable(GL_CLIP_PLANE0 + index);
\r
2987 UserClipPlaneEnabled[index]=enable;
\r
2991 core::dimension2du COGLES1Driver::getMaxTextureSize() const
\r
2993 return core::dimension2du(MaxTextureSize, MaxTextureSize);
\r
2997 GLenum COGLES1Driver::getGLBlend(E_BLEND_FACTOR factor) const
\r
2999 static GLenum const blendTable[] =
\r
3004 GL_ONE_MINUS_DST_COLOR,
\r
3006 GL_ONE_MINUS_SRC_COLOR,
\r
3008 GL_ONE_MINUS_SRC_ALPHA,
\r
3010 GL_ONE_MINUS_DST_ALPHA,
\r
3011 GL_SRC_ALPHA_SATURATE
\r
3014 return blendTable[factor];
\r
3017 GLenum COGLES1Driver::getZBufferBits() const
\r
3021 switch (Params.ZBufferBits)
\r
3024 #if defined(GL_OES_depth24)
\r
3025 if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth24))
\r
3026 bits = GL_DEPTH_COMPONENT24_OES;
\r
3029 bits = GL_DEPTH_COMPONENT16;
\r
3032 #if defined(GL_OES_depth32)
\r
3033 if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32))
\r
3034 bits = GL_DEPTH_COMPONENT32_OES;
\r
3037 bits = GL_DEPTH_COMPONENT16;
\r
3040 bits = GL_DEPTH_COMPONENT16;
\r
3047 bool COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
\r
3048 GLenum& pixelType, void(**converter)(const void*, s32, void*)) const
\r
3050 bool supported = false;
\r
3051 internalFormat = GL_RGBA;
\r
3052 pixelFormat = GL_RGBA;
\r
3053 pixelType = GL_UNSIGNED_BYTE;
\r
3058 case ECF_A1R5G5B5:
\r
3060 internalFormat = GL_RGBA;
\r
3061 pixelFormat = GL_RGBA;
\r
3062 pixelType = GL_UNSIGNED_SHORT_5_5_5_1;
\r
3063 *converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1;
\r
3067 internalFormat = GL_RGB;
\r
3068 pixelFormat = GL_RGB;
\r
3069 pixelType = GL_UNSIGNED_SHORT_5_6_5;
\r
3073 internalFormat = GL_RGB;
\r
3074 pixelFormat = GL_RGB;
\r
3075 pixelType = GL_UNSIGNED_BYTE;
\r
3077 case ECF_A8R8G8B8:
\r
3079 if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_IMG_texture_format_BGRA8888) ||
\r
3080 queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_format_BGRA8888) ||
\r
3081 queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_APPLE_texture_format_BGRA8888))
\r
3083 internalFormat = GL_BGRA;
\r
3084 pixelFormat = GL_BGRA;
\r
3088 internalFormat = GL_RGBA;
\r
3089 pixelFormat = GL_RGBA;
\r
3090 *converter = CColorConverter::convert_A8R8G8B8toA8B8G8R8;
\r
3092 pixelType = GL_UNSIGNED_BYTE;
\r
3094 #ifdef GL_EXT_texture_compression_s3tc
\r
3097 internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
\r
3098 pixelFormat = GL_RGBA;
\r
3099 pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
\r
3102 #ifdef GL_EXT_texture_compression_s3tc
\r
3106 internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
\r
3107 pixelFormat = GL_RGBA;
\r
3108 pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
\r
3111 #ifdef GL_EXT_texture_compression_s3tc
\r
3115 internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
\r
3116 pixelFormat = GL_RGBA;
\r
3117 pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
\r
3120 #ifdef GL_IMG_texture_compression_pvrtc
\r
3121 case ECF_PVRTC_RGB2:
\r
3123 internalFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
\r
3124 pixelFormat = GL_RGB;
\r
3125 pixelType = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
\r
3128 #ifdef GL_IMG_texture_compression_pvrtc
\r
3129 case ECF_PVRTC_ARGB2:
\r
3131 internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
\r
3132 pixelFormat = GL_RGBA;
\r
3133 pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
\r
3136 #ifdef GL_IMG_texture_compression_pvrtc
\r
3137 case ECF_PVRTC_RGB4:
\r
3139 internalFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
\r
3140 pixelFormat = GL_RGB;
\r
3141 pixelType = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
\r
3144 #ifdef GL_IMG_texture_compression_pvrtc
\r
3145 case ECF_PVRTC_ARGB4:
\r
3147 internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
\r
3148 pixelFormat = GL_RGBA;
\r
3149 pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
\r
3152 #ifdef GL_IMG_texture_compression_pvrtc2
\r
3153 case ECF_PVRTC2_ARGB2:
\r
3155 internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG;
\r
3156 pixelFormat = GL_RGBA;
\r
3157 pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG;
\r
3160 #ifdef GL_IMG_texture_compression_pvrtc2
\r
3161 case ECF_PVRTC2_ARGB4:
\r
3163 internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG;
\r
3164 pixelFormat = GL_RGBA;
\r
3165 pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG;
\r
3168 #ifdef GL_OES_compressed_ETC1_RGB8_texture
\r
3171 internalFormat = GL_ETC1_RGB8_OES;
\r
3172 pixelFormat = GL_RGB;
\r
3173 pixelType = GL_ETC1_RGB8_OES;
\r
3176 #ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available
\r
3177 case ECF_ETC2_RGB:
\r
3179 internalFormat = GL_COMPRESSED_RGB8_ETC2;
\r
3180 pixelFormat = GL_RGB;
\r
3181 pixelType = GL_COMPRESSED_RGB8_ETC2;
\r
3184 #ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available
\r
3185 case ECF_ETC2_ARGB:
\r
3187 internalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
\r
3188 pixelFormat = GL_RGBA;
\r
3189 pixelType = GL_COMPRESSED_RGBA8_ETC2_EAC;
\r
3194 internalFormat = GL_DEPTH_COMPONENT16;
\r
3195 pixelFormat = GL_DEPTH_COMPONENT;
\r
3196 pixelType = GL_UNSIGNED_SHORT;
\r
3199 #if defined(GL_OES_depth32)
\r
3200 if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32))
\r
3203 internalFormat = GL_DEPTH_COMPONENT32_OES;
\r
3204 pixelFormat = GL_DEPTH_COMPONENT;
\r
3205 pixelType = GL_UNSIGNED_INT;
\r
3210 #ifdef GL_OES_packed_depth_stencil
\r
3211 if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_packed_depth_stencil))
\r
3214 internalFormat = GL_DEPTH24_STENCIL8_OES;
\r
3215 pixelFormat = GL_DEPTH_STENCIL_OES;
\r
3216 pixelType = GL_UNSIGNED_INT_24_8_OES;
\r
3232 case ECF_A16B16G16R16F:
\r
3238 case ECF_A32B32G32R32F:
\r
3244 #ifdef _IRR_IOS_PLATFORM_
\r
3245 if (internalFormat == GL_BGRA)
\r
3246 internalFormat = GL_RGBA;
\r
3252 bool COGLES1Driver::queryTextureFormat(ECOLOR_FORMAT format) const
\r
3254 GLint dummyInternalFormat;
\r
3255 GLenum dummyPixelFormat;
\r
3256 GLenum dummyPixelType;
\r
3257 void (*dummyConverter)(const void*, s32, void*);
\r
3258 return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter);
\r
3261 bool COGLES1Driver::needsTransparentRenderPass(const irr::video::SMaterial& material) const
\r
3263 return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation();
\r
3266 COGLES1CacheHandler* COGLES1Driver::getCacheHandler() const
\r
3268 return CacheHandler;
\r
3271 } // end namespace
\r
3272 } // end namespace
\r
3274 #endif // _IRR_COMPILE_WITH_OGLES1_
\r
3281 #ifndef _IRR_COMPILE_WITH_OGLES1_
\r
3282 class IVideoDriver;
\r
3283 class IContextManager;
\r
3286 IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
\r
3288 #ifdef _IRR_COMPILE_WITH_OGLES1_
\r
3289 return new COGLES1Driver(params, io, contextManager);
\r
3292 #endif // _IRR_COMPILE_WITH_OGLES1_
\r
3295 } // end namespace
\r
3296 } // end namespace
\r