2014-07-28 10:49:05 -07:00
|
|
|
// Copyright (C) 2014 Patryk Nadrowski
|
2010-08-08 10:46:48 -07:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in Irrlicht.h
|
2011-06-07 01:56:52 -07:00
|
|
|
|
2010-08-08 10:46:48 -07:00
|
|
|
#include "COGLES2Driver.h"
|
|
|
|
// needed here also because of the create methods' parameters
|
|
|
|
#include "CNullDriver.h"
|
|
|
|
|
|
|
|
#ifdef _IRR_COMPILE_WITH_OGLES2_
|
|
|
|
|
|
|
|
#include "COGLES2Texture.h"
|
|
|
|
#include "COGLES2MaterialRenderer.h"
|
2013-01-14 16:31:37 -08:00
|
|
|
#include "COGLES2FixedPipelineRenderer.h"
|
2010-08-08 10:46:48 -07:00
|
|
|
#include "COGLES2NormalMapRenderer.h"
|
|
|
|
#include "COGLES2ParallaxMapRenderer.h"
|
|
|
|
#include "COGLES2Renderer2D.h"
|
|
|
|
#include "CImage.h"
|
|
|
|
#include "os.h"
|
2014-10-15 15:50:34 -07:00
|
|
|
#include "EProfileIDs.h"
|
|
|
|
#include "IProfiler.h"
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2012-07-12 18:18:54 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
#include <OpenGLES/ES2/gl.h>
|
|
|
|
#include <OpenGLES/ES2/glext.h>
|
|
|
|
#else
|
2010-08-08 10:46:48 -07:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <GLES2/gl2.h>
|
2013-04-17 22:10:42 -07:00
|
|
|
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
|
|
|
|
#include "android_native_app_glue.h"
|
|
|
|
#endif
|
2012-07-12 18:18:54 -07:00
|
|
|
#endif
|
2010-08-08 10:46:48 -07:00
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
2011-05-22 13:25:05 -07:00
|
|
|
namespace video
|
|
|
|
{
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
COGLES2Driver::COGLES2Driver(const SIrrlichtCreationParameters& params,
|
2013-11-13 15:20:30 -08:00
|
|
|
io::IFileSystem* io
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
, IContextManager* contextManager
|
2013-10-20 13:38:20 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
, CIrrDeviceIPhone* device
|
2012-07-12 18:18:54 -07:00
|
|
|
#endif
|
2013-10-20 13:38:20 -07:00
|
|
|
) : CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(),
|
2014-05-10 14:47:14 -07:00
|
|
|
CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
|
2014-05-23 10:28:19 -07:00
|
|
|
Transformation3DChanged(true), AntiAlias(params.AntiAlias), OGLES2ShaderPath(params.OGLES2ShaderPath),
|
2014-05-10 14:47:14 -07:00
|
|
|
RenderTargetTexture(0), CurrentRendertargetSize(0, 0), ColorFormat(ECF_R8G8B8), BridgeCalls(0)
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
, ContextManager(contextManager)
|
2010-08-08 10:46:48 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
2013-10-20 13:38:20 -07:00
|
|
|
, Device(device), ViewFramebuffer(0),
|
|
|
|
ViewRenderbuffer(0), ViewDepthRenderbuffer(0)
|
2010-08-08 10:46:48 -07:00
|
|
|
#endif
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2010-08-08 10:46:48 -07:00
|
|
|
#ifdef _DEBUG
|
2013-10-20 13:38:20 -07:00
|
|
|
setDebugName("COGLES2Driver");
|
2010-08-08 10:46:48 -07:00
|
|
|
#endif
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(
|
|
|
|
static bool initProfile = false;
|
|
|
|
if (!initProfile )
|
|
|
|
{
|
|
|
|
initProfile = true;
|
|
|
|
getProfiler().add(EPID_ES2_END_SCENE, L"endScene", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_BEGIN_SCENE, L"beginScene", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_UPDATE_VERTEX_HW_BUF, L"upVertBuf", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_UPDATE_INDEX_HW_BUF, L"upIdxBuf", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_PRIMITIVES, L"drawPrim", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_2DIMAGE, L"draw2dImg", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_2DIMAGE_BATCH, L"draw2dImgB", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_2DRECTANGLE, L"draw2dRect", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_2DLINE, L"draw2dLine", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_3DLINE, L"draw3dLine", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_SET_RENDERSTATE_2D, L"rstate2d", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_SET_RENDERSTATE_3D, L"rstate3d", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_SET_RENDERSTATE_BASIC, L"rstateBasic", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_SET_RENDERSTATE_TEXTURE, L"rstateTex", L"ES2");
|
|
|
|
getProfiler().add(EPID_ES2_DRAW_SHADOW, L"shadows", L"ES2");
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
core::dimension2d<u32> windowSize(0, 0);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
if (!ContextManager)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ContextManager->grab();
|
2013-11-13 15:20:30 -08:00
|
|
|
ContextManager->generateSurface();
|
|
|
|
ContextManager->generateContext();
|
|
|
|
ExposedData = ContextManager->getContext();
|
|
|
|
ContextManager->activateContext(ExposedData);
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
windowSize = params.WindowSize;
|
2013-10-20 13:38:20 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
glGenFramebuffers(1, &ViewFramebuffer);
|
|
|
|
glGenRenderbuffers(1, &ViewRenderbuffer);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
ExposedData.OGLESIPhone.AppDelegate = Device;
|
|
|
|
Device->displayInitialize(&ExposedData.OGLESIPhone.Context, &ExposedData.OGLESIPhone.View);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
GLint backingWidth;
|
|
|
|
GLint backingHeight;
|
|
|
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
|
|
|
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
glGenRenderbuffers(1, &ViewDepthRenderbuffer);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, ViewDepthRenderbuffer);
|
2012-07-12 18:18:54 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
GLenum depthComponent = GL_DEPTH_COMPONENT16;
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
if (params.ZBufferBits >= 24)
|
|
|
|
depthComponent = GL_DEPTH_COMPONENT24_OES;
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, depthComponent, backingWidth, backingHeight);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, ViewFramebuffer);
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ViewRenderbuffer);
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ViewDepthRenderbuffer);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
windowSize = core::dimension2d<u32>(backingWidth, backingHeight);
|
|
|
|
CNullDriver::ScreenSize = windowSize;
|
|
|
|
CNullDriver::ViewPort = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(windowSize));
|
2013-10-20 13:38:20 -07:00
|
|
|
#endif
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
genericDriverInit(windowSize, params.Stencilbuffer);
|
2013-10-20 13:38:20 -07:00
|
|
|
}
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
COGLES2Driver::~COGLES2Driver()
|
|
|
|
{
|
|
|
|
RequestedLights.clear();
|
2014-05-22 10:07:49 -07:00
|
|
|
CurrentTexture.clear();
|
2013-10-20 13:38:20 -07:00
|
|
|
deleteMaterialRenders();
|
|
|
|
delete MaterialRenderer2D;
|
|
|
|
deleteAllTextures();
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
delete BridgeCalls;
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
if (ContextManager)
|
|
|
|
{
|
|
|
|
ContextManager->destroyContext();
|
2013-11-13 15:20:30 -08:00
|
|
|
ContextManager->destroySurface();
|
2013-10-26 05:13:26 -07:00
|
|
|
ContextManager->drop();
|
|
|
|
}
|
2013-10-20 13:38:20 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
if (0 != ViewFramebuffer)
|
|
|
|
{
|
2014-02-13 13:09:38 -08:00
|
|
|
glDeleteFramebuffers(1,&ViewFramebuffer);
|
2013-10-20 13:38:20 -07:00
|
|
|
ViewFramebuffer = 0;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2013-10-20 13:38:20 -07:00
|
|
|
if (0 != ViewRenderbuffer)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-02-13 13:09:38 -08:00
|
|
|
glDeleteRenderbuffers(1,&ViewRenderbuffer);
|
2013-10-20 13:38:20 -07:00
|
|
|
ViewRenderbuffer = 0;
|
|
|
|
}
|
|
|
|
if (0 != ViewDepthRenderbuffer)
|
|
|
|
{
|
2014-02-13 13:09:38 -08:00
|
|
|
glDeleteRenderbuffers(1,&ViewDepthRenderbuffer);
|
2013-10-20 13:38:20 -07:00
|
|
|
ViewDepthRenderbuffer = 0;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2013-10-20 13:38:20 -07:00
|
|
|
#endif
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// METHODS
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
bool COGLES2Driver::genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer)
|
|
|
|
{
|
|
|
|
Name = glGetString(GL_VERSION);
|
|
|
|
printVersion();
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// print renderer information
|
2014-10-16 07:35:26 -07:00
|
|
|
VendorName = glGetString(GL_VENDOR);
|
|
|
|
os::Printer::log(VendorName.c_str(), ELL_INFORMATION);
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2014-05-22 10:07:49 -07:00
|
|
|
CurrentTexture.clear();
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// load extensions
|
2013-10-20 13:38:20 -07:00
|
|
|
initExtensions(this, stencilBuffer);
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
if (!BridgeCalls)
|
|
|
|
BridgeCalls = new COGLES2CallBridge(this);
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
StencilBuffer = stencilBuffer;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-06-09 09:19:22 -07:00
|
|
|
DriverAttributes->setAttribute("MaxTextures", MaxTextureUnits);
|
|
|
|
DriverAttributes->setAttribute("MaxSupportedTextures", MaxSupportedTextures);
|
2013-03-19 08:54:47 -07:00
|
|
|
// DriverAttributes->setAttribute("MaxLights", MaxLights);
|
2011-06-09 09:19:22 -07:00
|
|
|
DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy);
|
2013-03-19 08:54:47 -07:00
|
|
|
// DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes);
|
2011-06-09 09:19:22 -07:00
|
|
|
// DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers);
|
|
|
|
// DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets);
|
|
|
|
DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices);
|
|
|
|
DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize);
|
|
|
|
DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias);
|
|
|
|
DriverAttributes->setAttribute("Version", Version);
|
|
|
|
DriverAttributes->setAttribute("AntiAlias", AntiAlias);
|
|
|
|
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// Reset The Current Viewport
|
2013-03-19 08:54:47 -07:00
|
|
|
BridgeCalls->setViewport(core::rect<s32>(0, 0, screenSize.Width, screenSize.Height));
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-06-09 09:19:22 -07:00
|
|
|
UserClipPlane.reallocate(0);
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
glClearDepthf(1.0f);
|
|
|
|
|
|
|
|
//TODO : OpenGL ES 2.0 Port : GL_PERSPECTIVE_CORRECTION_HINT
|
|
|
|
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
|
|
|
glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glFrontFace(GL_CW);
|
|
|
|
|
|
|
|
// create material renderers
|
|
|
|
createMaterialRenderers();
|
|
|
|
|
|
|
|
// set the renderstates
|
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
// set fog mode
|
|
|
|
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
|
|
|
|
|
|
|
|
// create matrix for flipping textures
|
|
|
|
TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f));
|
|
|
|
|
|
|
|
// We need to reset once more at the beginning of the first rendering.
|
|
|
|
// This fixes problems with intermediate changes to the material during texture load.
|
|
|
|
ResetRenderStates = true;
|
|
|
|
|
|
|
|
testGLError();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
void COGLES2Driver::loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-05-23 10:28:19 -07:00
|
|
|
io::path vsPath(OGLES2ShaderPath);
|
|
|
|
vsPath += vertexShaderName;
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
io::path fsPath(OGLES2ShaderPath);
|
|
|
|
fsPath += fragmentShaderName;
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
*vertexShaderData = 0;
|
|
|
|
*fragmentShaderData = 0;
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
io::IReadFile* vsFile = FileSystem->createAndOpenFile(vsPath);
|
|
|
|
if ( !vsFile )
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
2014-05-23 10:28:19 -07:00
|
|
|
core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n");
|
|
|
|
warning += core::stringw(vsPath) + L"\n";
|
|
|
|
warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath";
|
|
|
|
os::Printer::log(warning.c_str(), ELL_WARNING);
|
|
|
|
return;
|
2013-01-14 16:31:37 -08:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
io::IReadFile* fsFile = FileSystem->createAndOpenFile(fsPath);
|
|
|
|
if ( !fsFile )
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
2014-05-23 10:28:19 -07:00
|
|
|
core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n");
|
|
|
|
warning += core::stringw(fsPath) + L"\n";
|
|
|
|
warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath";
|
|
|
|
os::Printer::log(warning.c_str(), ELL_WARNING);
|
|
|
|
return;
|
2013-01-14 16:31:37 -08:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
long size = vsFile->getSize();
|
|
|
|
if (size)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
2014-05-23 10:28:19 -07:00
|
|
|
*vertexShaderData = new c8[size+1];
|
|
|
|
vsFile->read(*vertexShaderData, size);
|
|
|
|
(*vertexShaderData)[size] = 0;
|
2013-01-14 16:31:37 -08:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
size = fsFile->getSize();
|
|
|
|
if (size)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
// if both handles are the same we must reset the file
|
2014-05-23 10:28:19 -07:00
|
|
|
if (fsFile == vsFile)
|
|
|
|
fsFile->seek(0);
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
*fragmentShaderData = new c8[size+1];
|
|
|
|
fsFile->read(*fragmentShaderData, size);
|
|
|
|
(*fragmentShaderData)[size] = 0;
|
2013-01-14 16:31:37 -08:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
vsFile->drop();
|
|
|
|
fsFile->drop();
|
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
void COGLES2Driver::createMaterialRenderers()
|
|
|
|
{
|
2014-07-10 10:21:22 -07:00
|
|
|
// Create callbacks.
|
|
|
|
|
|
|
|
COGLES2MaterialSolidCB* SolidCB = new COGLES2MaterialSolidCB();
|
|
|
|
COGLES2MaterialSolid2CB* Solid2LayerCB = new COGLES2MaterialSolid2CB();
|
|
|
|
COGLES2MaterialLightmapCB* LightmapCB = new COGLES2MaterialLightmapCB(1.f);
|
|
|
|
COGLES2MaterialLightmapCB* LightmapAddCB = new COGLES2MaterialLightmapCB(1.f);
|
|
|
|
COGLES2MaterialLightmapCB* LightmapM2CB = new COGLES2MaterialLightmapCB(2.f);
|
|
|
|
COGLES2MaterialLightmapCB* LightmapM4CB = new COGLES2MaterialLightmapCB(4.f);
|
|
|
|
COGLES2MaterialLightmapCB* LightmapLightingCB = new COGLES2MaterialLightmapCB(1.f);
|
|
|
|
COGLES2MaterialLightmapCB* LightmapLightingM2CB = new COGLES2MaterialLightmapCB(2.f);
|
|
|
|
COGLES2MaterialLightmapCB* LightmapLightingM4CB = new COGLES2MaterialLightmapCB(4.f);
|
|
|
|
COGLES2MaterialSolid2CB* DetailMapCB = new COGLES2MaterialSolid2CB();
|
|
|
|
COGLES2MaterialReflectionCB* SphereMapCB = new COGLES2MaterialReflectionCB();
|
|
|
|
COGLES2MaterialReflectionCB* Reflection2LayerCB = new COGLES2MaterialReflectionCB();
|
|
|
|
COGLES2MaterialSolidCB* TransparentAddColorCB = new COGLES2MaterialSolidCB();
|
|
|
|
COGLES2MaterialSolidCB* TransparentAlphaChannelCB = new COGLES2MaterialSolidCB();
|
|
|
|
COGLES2MaterialSolidCB* TransparentAlphaChannelRefCB = new COGLES2MaterialSolidCB();
|
|
|
|
COGLES2MaterialSolidCB* TransparentVertexAlphaCB = new COGLES2MaterialSolidCB();
|
|
|
|
COGLES2MaterialReflectionCB* TransparentReflection2LayerCB = new COGLES2MaterialReflectionCB();
|
|
|
|
COGLES2MaterialNormalMapCB* NormalMapCB = new COGLES2MaterialNormalMapCB();
|
|
|
|
COGLES2MaterialNormalMapCB* NormalMapAddColorCB = new COGLES2MaterialNormalMapCB();
|
|
|
|
COGLES2MaterialNormalMapCB* NormalMapVertexAlphaCB = new COGLES2MaterialNormalMapCB();
|
|
|
|
COGLES2MaterialParallaxMapCB* ParallaxMapCB = new COGLES2MaterialParallaxMapCB();
|
|
|
|
COGLES2MaterialParallaxMapCB* ParallaxMapAddColorCB = new COGLES2MaterialParallaxMapCB();
|
|
|
|
COGLES2MaterialParallaxMapCB* ParallaxMapVertexAlphaCB = new COGLES2MaterialParallaxMapCB();
|
2014-07-15 11:30:46 -07:00
|
|
|
COGLES2MaterialOneTextureBlendCB* OneTextureBlendCB = new COGLES2MaterialOneTextureBlendCB();
|
2014-07-10 10:21:22 -07:00
|
|
|
|
|
|
|
// Create built-in materials.
|
|
|
|
|
|
|
|
core::stringc VertexShader = OGLES2ShaderPath + "COGLES2Solid.vsh";
|
|
|
|
core::stringc FragmentShader = OGLES2ShaderPath + "COGLES2Solid.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SolidCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Solid2.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2Solid2Layer.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Solid2LayerCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Solid2.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2LightmapModulate.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2LightmapAdd.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapAddCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2LightmapModulate.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM2CB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM4CB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM2CB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM4CB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Solid2.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2DetailMap.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, DetailMapCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2SphereMap.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2SphereMap.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SphereMapCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Reflection2Layer.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2Reflection2Layer.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Reflection2LayerCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Solid.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2Solid.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2TransparentAlphaChannelRef.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelRefCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2TransparentVertexAlpha.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Reflection2Layer.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2Reflection2Layer.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentReflection2LayerCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2NormalMap.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2NormalMap.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, NormalMapCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, NormalMapAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, NormalMapVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2ParallaxMap.vsh";
|
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2ParallaxMap.fsh";
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, ParallaxMapCB, EMT_SOLID, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, ParallaxMapAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, ParallaxMapVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
VertexShader = OGLES2ShaderPath + "COGLES2Solid.vsh";
|
2014-07-15 11:30:46 -07:00
|
|
|
FragmentShader = OGLES2ShaderPath + "COGLES2OneTextureBlend.fsh";
|
2014-07-10 10:21:22 -07:00
|
|
|
|
|
|
|
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
|
|
|
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, OneTextureBlendCB, EMT_ONETEXTURE_BLEND, 0, EGSL_DEFAULT);
|
|
|
|
|
|
|
|
// Drop callbacks.
|
|
|
|
|
|
|
|
SolidCB->drop();
|
|
|
|
Solid2LayerCB->drop();
|
|
|
|
LightmapCB->drop();
|
|
|
|
LightmapAddCB->drop();
|
|
|
|
LightmapM2CB->drop();
|
|
|
|
LightmapM4CB->drop();
|
|
|
|
LightmapLightingCB->drop();
|
|
|
|
LightmapLightingM2CB->drop();
|
|
|
|
LightmapLightingM4CB->drop();
|
|
|
|
DetailMapCB->drop();
|
|
|
|
SphereMapCB->drop();
|
|
|
|
Reflection2LayerCB->drop();
|
|
|
|
TransparentAddColorCB->drop();
|
|
|
|
TransparentAlphaChannelCB->drop();
|
|
|
|
TransparentAlphaChannelRefCB->drop();
|
|
|
|
TransparentVertexAlphaCB->drop();
|
|
|
|
TransparentReflection2LayerCB->drop();
|
|
|
|
NormalMapCB->drop();
|
|
|
|
NormalMapAddColorCB->drop();
|
|
|
|
NormalMapVertexAlphaCB->drop();
|
|
|
|
ParallaxMapCB->drop();
|
|
|
|
ParallaxMapAddColorCB->drop();
|
|
|
|
ParallaxMapVertexAlphaCB->drop();
|
|
|
|
OneTextureBlendCB->drop();
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
// Create 2D material renderer.
|
2014-07-10 10:21:22 -07:00
|
|
|
|
2014-05-23 10:28:19 -07:00
|
|
|
c8* vs2DData = 0;
|
|
|
|
c8* fs2DData = 0;
|
|
|
|
loadShaderData(io::path("COGLES2Renderer2D.vsh"), io::path("COGLES2Renderer2D.fsh"), &vs2DData, &fs2DData);
|
|
|
|
MaterialRenderer2D = new COGLES2Renderer2D(vs2DData, fs2DData, this);
|
|
|
|
delete[] vs2DData;
|
|
|
|
delete[] fs2DData;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
//! presents the rendered scene on the screen, returns false if failed
|
|
|
|
bool COGLES2Driver::endScene()
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_END_SCENE);)
|
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
CNullDriver::endScene();
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
if (ContextManager)
|
|
|
|
ContextManager->swapBuffers();
|
2013-10-20 13:38:20 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
glFlush();
|
2014-02-13 13:09:38 -08:00
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer);
|
2013-10-20 13:38:20 -07:00
|
|
|
Device->displayEnd();
|
2012-07-12 18:18:54 -07:00
|
|
|
#endif
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
return true;
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
//! clears the zbuffer
|
|
|
|
bool COGLES2Driver::beginScene(bool backBuffer, bool zBuffer, SColor color,
|
|
|
|
const SExposedVideoData& videoData, core::rect<s32>* sourceRect)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_BEGIN_SCENE);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
CNullDriver::beginScene(backBuffer, zBuffer, color);
|
|
|
|
|
|
|
|
GLbitfield mask = 0;
|
|
|
|
|
|
|
|
if (backBuffer)
|
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setColorMask(true, true, true, true);
|
2014-05-25 08:34:18 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const f32 inv = 1.0f / 255.0f;
|
|
|
|
glClearColor(color.getRed() * inv, color.getGreen() * inv,
|
2011-06-07 01:56:52 -07:00
|
|
|
color.getBlue() * inv, color.getAlpha() * inv);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
mask |= GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zBuffer)
|
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthMask(true);
|
2011-05-22 13:25:05 -07:00
|
|
|
mask |= GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
glClear(mask);
|
2014-05-25 08:34:18 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns the transformation set by setTransform
|
|
|
|
const core::matrix4& COGLES2Driver::getTransform(E_TRANSFORMATION_STATE state) const
|
|
|
|
{
|
|
|
|
return Matrices[state];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! sets transformation
|
|
|
|
void COGLES2Driver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat)
|
|
|
|
{
|
|
|
|
Matrices[state] = mat;
|
|
|
|
Transformation3DChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool COGLES2Driver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
|
|
|
|
{
|
|
|
|
if (!HWBuffer)
|
|
|
|
return false;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_UPDATE_VERTEX_HW_BUF);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer;
|
|
|
|
const void* vertices = mb->getVertices();
|
|
|
|
const u32 vertexCount = mb->getVertexCount();
|
|
|
|
const E_VERTEX_TYPE vType = mb->getVertexType();
|
|
|
|
const u32 vertexSize = getVertexPitchFromType(vType);
|
|
|
|
|
|
|
|
//buffer vertex data, and convert colours...
|
|
|
|
core::array<c8> buffer(vertexSize * vertexCount);
|
|
|
|
memcpy(buffer.pointer(), vertices, vertexSize * vertexCount);
|
|
|
|
|
|
|
|
//get or create buffer
|
|
|
|
bool newBuffer = false;
|
|
|
|
if (!HWBuffer->vbo_verticesID)
|
|
|
|
{
|
|
|
|
glGenBuffers(1, &HWBuffer->vbo_verticesID);
|
|
|
|
if (!HWBuffer->vbo_verticesID) return false;
|
|
|
|
newBuffer = true;
|
|
|
|
}
|
|
|
|
else if (HWBuffer->vbo_verticesSize < vertexCount*vertexSize)
|
|
|
|
{
|
|
|
|
newBuffer = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID);
|
|
|
|
|
2014-05-25 08:43:33 -07:00
|
|
|
// copy data to graphics card
|
2011-05-22 13:25:05 -07:00
|
|
|
if (!newBuffer)
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, buffer.const_pointer());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HWBuffer->vbo_verticesSize = vertexCount * vertexSize;
|
|
|
|
|
|
|
|
if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC)
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_STATIC_DRAW);
|
|
|
|
else
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_DYNAMIC_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
2014-05-25 08:43:33 -07:00
|
|
|
return (!testGLError());
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool COGLES2Driver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
|
|
|
|
{
|
|
|
|
if (!HWBuffer)
|
|
|
|
return false;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_UPDATE_INDEX_HW_BUF);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer;
|
|
|
|
|
|
|
|
const void* indices = mb->getIndices();
|
|
|
|
u32 indexCount = mb->getIndexCount();
|
|
|
|
|
|
|
|
GLenum indexSize;
|
|
|
|
switch (mb->getIndexType())
|
|
|
|
{
|
|
|
|
case(EIT_16BIT):
|
|
|
|
{
|
|
|
|
indexSize = sizeof(u16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(EIT_32BIT):
|
|
|
|
{
|
|
|
|
indexSize = sizeof(u32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//get or create buffer
|
|
|
|
bool newBuffer = false;
|
|
|
|
if (!HWBuffer->vbo_indicesID)
|
|
|
|
{
|
|
|
|
glGenBuffers(1, &HWBuffer->vbo_indicesID);
|
|
|
|
if (!HWBuffer->vbo_indicesID) return false;
|
|
|
|
newBuffer = true;
|
|
|
|
}
|
|
|
|
else if (HWBuffer->vbo_indicesSize < indexCount*indexSize)
|
|
|
|
{
|
|
|
|
newBuffer = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID);
|
|
|
|
|
2014-05-25 08:43:33 -07:00
|
|
|
// copy data to graphics card
|
2011-05-22 13:25:05 -07:00
|
|
|
if (!newBuffer)
|
|
|
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HWBuffer->vbo_indicesSize = indexCount * indexSize;
|
|
|
|
|
|
|
|
if (HWBuffer->Mapped_Index == scene::EHM_STATIC)
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW);
|
|
|
|
else
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
2014-05-25 08:43:33 -07:00
|
|
|
return (!testGLError());
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! updates hardware buffer if needed
|
|
|
|
bool COGLES2Driver::updateHardwareBuffer(SHWBufferLink *HWBuffer)
|
|
|
|
{
|
|
|
|
if (!HWBuffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER)
|
|
|
|
{
|
|
|
|
if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex()
|
2014-10-16 07:35:26 -07:00
|
|
|
|| !static_cast<SHWBufferLink_opengl*>(HWBuffer)->vbo_verticesID)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex();
|
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
if (!updateVertexHardwareBuffer(static_cast<SHWBufferLink_opengl*>(HWBuffer)))
|
2011-05-22 13:25:05 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HWBuffer->Mapped_Index != scene::EHM_NEVER)
|
|
|
|
{
|
|
|
|
if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index()
|
2014-10-16 07:35:26 -07:00
|
|
|
|| !static_cast<SHWBufferLink_opengl*>(HWBuffer)->vbo_indicesID)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index();
|
|
|
|
|
|
|
|
if (!updateIndexHardwareBuffer((SHWBufferLink_opengl*)HWBuffer))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Create hardware buffer from meshbuffer
|
|
|
|
COGLES2Driver::SHWBufferLink *COGLES2Driver::createHardwareBuffer(const scene::IMeshBuffer* mb)
|
|
|
|
{
|
|
|
|
if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb);
|
|
|
|
|
|
|
|
//add to map
|
|
|
|
HWBufferMap.insert(HWBuffer->MeshBuffer, HWBuffer);
|
|
|
|
|
|
|
|
HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex();
|
|
|
|
HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index();
|
|
|
|
HWBuffer->Mapped_Vertex = mb->getHardwareMappingHint_Vertex();
|
|
|
|
HWBuffer->Mapped_Index = mb->getHardwareMappingHint_Index();
|
|
|
|
HWBuffer->LastUsed = 0;
|
|
|
|
HWBuffer->vbo_verticesID = 0;
|
|
|
|
HWBuffer->vbo_indicesID = 0;
|
|
|
|
HWBuffer->vbo_verticesSize = 0;
|
|
|
|
HWBuffer->vbo_indicesSize = 0;
|
|
|
|
|
|
|
|
if (!updateHardwareBuffer(HWBuffer))
|
|
|
|
{
|
|
|
|
deleteHardwareBuffer(HWBuffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HWBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void COGLES2Driver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer)
|
|
|
|
{
|
|
|
|
if (!_HWBuffer)
|
|
|
|
return;
|
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
SHWBufferLink_opengl *HWBuffer = static_cast<SHWBufferLink_opengl*>(_HWBuffer);
|
2011-05-22 13:25:05 -07:00
|
|
|
if (HWBuffer->vbo_verticesID)
|
|
|
|
{
|
|
|
|
glDeleteBuffers(1, &HWBuffer->vbo_verticesID);
|
|
|
|
HWBuffer->vbo_verticesID = 0;
|
|
|
|
}
|
|
|
|
if (HWBuffer->vbo_indicesID)
|
|
|
|
{
|
|
|
|
glDeleteBuffers(1, &HWBuffer->vbo_indicesID);
|
|
|
|
HWBuffer->vbo_indicesID = 0;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
CNullDriver::deleteHardwareBuffer(_HWBuffer);
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
//! Draw hardware buffer
|
|
|
|
void COGLES2Driver::drawHardwareBuffer(SHWBufferLink *_HWBuffer)
|
|
|
|
{
|
|
|
|
if (!_HWBuffer)
|
|
|
|
return;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2014-10-16 07:35:26 -07:00
|
|
|
SHWBufferLink_opengl *HWBuffer = static_cast<SHWBufferLink_opengl*>(_HWBuffer);
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
updateHardwareBuffer(HWBuffer); //check if update is needed
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
HWBuffer->LastUsed = 0;//reset count
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer;
|
|
|
|
const void *vertices = mb->getVertices();
|
|
|
|
const void *indexList = mb->getIndices();
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER)
|
|
|
|
{
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID);
|
|
|
|
vertices = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HWBuffer->Mapped_Index != scene::EHM_NEVER)
|
|
|
|
{
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID);
|
|
|
|
indexList = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-07 01:56:52 -07:00
|
|
|
drawVertexPrimitiveList(vertices, mb->getVertexCount(),
|
|
|
|
indexList, mb->getIndexCount() / 3,
|
|
|
|
mb->getVertexType(), scene::EPT_TRIANGLES,
|
|
|
|
mb->getIndexType());
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER)
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (HWBuffer->Mapped_Index != scene::EHM_NEVER)
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// small helper function to create vertex buffer object adress offsets
|
|
|
|
static inline u8* buffer_offset(const long offset)
|
|
|
|
{
|
|
|
|
return ((u8*)0 + offset);
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
//! draws a vertex primitive list
|
|
|
|
void COGLES2Driver::drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
|
2011-06-07 01:56:52 -07:00
|
|
|
const void* indexList, u32 primitiveCount,
|
|
|
|
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
|
|
|
if (!primitiveCount || !vertexCount)
|
|
|
|
return;
|
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
if (!checkPrimitiveCount(primitiveCount))
|
2011-05-22 13:25:05 -07:00
|
|
|
return;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_PRIMITIVES);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType);
|
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glEnableVertexAttribArray(EVA_NORMAL);
|
|
|
|
glEnableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
|
|
|
|
switch (vType)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-28 10:49:05 -07:00
|
|
|
case EVT_STANDARD:
|
|
|
|
if (vertices)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-28 10:49:05 -07:00
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Normal);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2014-07-28 10:49:05 -07:00
|
|
|
else
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-28 10:49:05 -07:00
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), 0);
|
|
|
|
glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex), buffer_offset(12));
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), buffer_offset(24));
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), buffer_offset(28));
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
break;
|
|
|
|
case EVT_2TCOORDS:
|
|
|
|
glEnableVertexAttribArray(EVA_TCOORD1);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
if (vertices)
|
|
|
|
{
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Normal);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].TCoords);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD1, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].TCoords2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(0));
|
|
|
|
glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(12));
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex2TCoords), buffer_offset(24));
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(28));
|
|
|
|
glVertexAttribPointer(EVA_TCOORD1, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(36));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVT_TANGENTS:
|
|
|
|
glEnableVertexAttribArray(EVA_TANGENT);
|
|
|
|
glEnableVertexAttribArray(EVA_BINORMAL);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
if (vertices)
|
|
|
|
{
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Normal);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].TCoords);
|
|
|
|
glVertexAttribPointer(EVA_TANGENT, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Tangent);
|
|
|
|
glVertexAttribPointer(EVA_BINORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Binormal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(0));
|
|
|
|
glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(12));
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertexTangents), buffer_offset(24));
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(28));
|
|
|
|
glVertexAttribPointer(EVA_TANGENT, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(36));
|
|
|
|
glVertexAttribPointer(EVA_BINORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(48));
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2014-07-28 10:49:05 -07:00
|
|
|
break;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GLenum indexSize = 0;
|
|
|
|
|
|
|
|
switch (iType)
|
|
|
|
{
|
|
|
|
case(EIT_16BIT):
|
|
|
|
{
|
|
|
|
indexSize = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(EIT_32BIT):
|
|
|
|
{
|
2010-08-08 10:46:48 -07:00
|
|
|
#ifdef GL_OES_element_index_uint
|
|
|
|
#ifndef GL_UNSIGNED_INT
|
2011-06-07 01:56:52 -07:00
|
|
|
#define GL_UNSIGNED_INT 0x1405
|
2010-08-08 10:46:48 -07:00
|
|
|
#endif
|
2011-05-22 13:25:05 -07:00
|
|
|
if (FeatureAvailable[IRR_OES_element_index_uint])
|
|
|
|
indexSize = GL_UNSIGNED_INT;
|
|
|
|
else
|
2010-08-08 10:46:48 -07:00
|
|
|
#endif
|
2011-05-22 13:25:05 -07:00
|
|
|
indexSize = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pType)
|
|
|
|
{
|
|
|
|
case scene::EPT_POINTS:
|
|
|
|
case scene::EPT_POINT_SPRITES:
|
|
|
|
glDrawArrays(GL_POINTS, 0, primitiveCount);
|
2014-07-28 10:49:05 -07:00
|
|
|
break;
|
2011-05-22 13:25:05 -07:00
|
|
|
case scene::EPT_LINE_STRIP:
|
|
|
|
glDrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList);
|
|
|
|
break;
|
|
|
|
case scene::EPT_LINE_LOOP:
|
|
|
|
glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList);
|
|
|
|
break;
|
|
|
|
case scene::EPT_LINES:
|
|
|
|
glDrawElements(GL_LINES, primitiveCount*2, indexSize, indexList);
|
|
|
|
break;
|
|
|
|
case scene::EPT_TRIANGLE_STRIP:
|
|
|
|
glDrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList);
|
|
|
|
break;
|
|
|
|
case scene::EPT_TRIANGLE_FAN:
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList);
|
|
|
|
break;
|
|
|
|
case scene::EPT_TRIANGLES:
|
|
|
|
glDrawElements((LastMaterial.Wireframe) ? GL_LINES : (LastMaterial.PointCloud) ? GL_POINTS : GL_TRIANGLES, primitiveCount*3, indexSize, indexList);
|
|
|
|
break;
|
2014-07-28 10:49:05 -07:00
|
|
|
default:
|
2011-05-22 13:25:05 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
switch (vType)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-28 10:49:05 -07:00
|
|
|
case EVT_2TCOORDS:
|
|
|
|
glDisableVertexAttribArray(EVA_TCOORD1);
|
|
|
|
break;
|
|
|
|
case EVT_TANGENTS:
|
|
|
|
glDisableVertexAttribArray(EVA_TANGENT);
|
|
|
|
glDisableVertexAttribArray(EVA_BINORMAL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
|
|
|
glDisableVertexAttribArray(EVA_NORMAL);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_TCOORD0);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! draws a 2d image, using a color and the alpha channel of the texture
|
|
|
|
void COGLES2Driver::draw2DImage(const video::ITexture* texture,
|
|
|
|
const core::position2d<s32>& pos,
|
|
|
|
const core::rect<s32>& sourceRect,
|
|
|
|
const core::rect<s32>* clipRect, SColor color,
|
|
|
|
bool useAlphaChannelOfTexture)
|
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sourceRect.isValid())
|
|
|
|
return;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DIMAGE);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
core::position2d<s32> targetPos(pos);
|
|
|
|
core::position2d<s32> sourcePos(sourceRect.UpperLeftCorner);
|
|
|
|
core::dimension2d<s32> sourceSize(sourceRect.getSize());
|
|
|
|
if (clipRect)
|
|
|
|
{
|
|
|
|
if (targetPos.X < clipRect->UpperLeftCorner.X)
|
|
|
|
{
|
|
|
|
sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
return;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X;
|
|
|
|
targetPos.X = clipRect->UpperLeftCorner.X;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X)
|
|
|
|
{
|
|
|
|
sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
return;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.Y < clipRect->UpperLeftCorner.Y)
|
|
|
|
{
|
|
|
|
sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
return;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;
|
|
|
|
targetPos.Y = clipRect->UpperLeftCorner.Y;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y)
|
|
|
|
{
|
|
|
|
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// clip these coordinates
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.X < 0)
|
|
|
|
{
|
|
|
|
sourceSize.Width += targetPos.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
return;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
sourcePos.X -= targetPos.X;
|
|
|
|
targetPos.X = 0;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width)
|
|
|
|
{
|
|
|
|
sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
return;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.Y < 0)
|
|
|
|
{
|
|
|
|
sourceSize.Height += targetPos.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
return;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
sourcePos.Y -= targetPos.Y;
|
|
|
|
targetPos.Y = 0;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height)
|
|
|
|
{
|
|
|
|
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
return;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// ok, we've clipped everything.
|
|
|
|
// now draw it.
|
|
|
|
|
|
|
|
// texcoords need to be flipped horizontally for RTTs
|
|
|
|
const bool isRTT = texture->isRenderTarget();
|
|
|
|
const core::dimension2d<u32>& ss = texture->getOriginalSize();
|
|
|
|
const f32 invW = 1.f / static_cast<f32>(ss.Width);
|
|
|
|
const f32 invH = 1.f / static_cast<f32>(ss.Height);
|
|
|
|
const core::rect<f32> tcoords(
|
|
|
|
sourcePos.X * invW,
|
|
|
|
(isRTT ? (sourcePos.Y + sourceSize.Height) : sourcePos.Y) * invH,
|
|
|
|
(sourcePos.X + sourceSize.Width) * invW,
|
|
|
|
(isRTT ? sourcePos.Y : (sourcePos.Y + sourceSize.Height)) * invH);
|
|
|
|
|
|
|
|
const core::rect<s32> poss(targetPos, sourceSize);
|
|
|
|
|
|
|
|
disableTextures(1);
|
2011-06-03 04:32:53 -07:00
|
|
|
if (!setActiveTexture(0, texture))
|
2011-05-22 13:25:05 -07:00
|
|
|
return;
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
u16 indices[] = {0, 1, 2, 3};
|
|
|
|
S3DVertex vertices[4];
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glEnableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void COGLES2Driver::draw2DImageBatch(const video::ITexture* texture,
|
|
|
|
const core::array<core::position2d<s32> >& positions,
|
|
|
|
const core::array<core::rect<s32> >& sourceRects,
|
|
|
|
const core::rect<s32>* clipRect,
|
|
|
|
SColor color, bool useAlphaChannelOfTexture)
|
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DIMAGE_BATCH);)
|
|
|
|
|
2011-06-03 04:32:53 -07:00
|
|
|
if (!setActiveTexture(0, const_cast<video::ITexture*>(texture)))
|
2011-05-22 13:25:05 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
const irr::u32 drawCount = core::min_<u32>(positions.size(), sourceRects.size());
|
|
|
|
|
|
|
|
core::array<S3DVertex> vtx(drawCount * 4);
|
|
|
|
core::array<u16> indices(drawCount * 6);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < drawCount; i++)
|
2010-08-08 10:46:48 -07:00
|
|
|
{
|
2011-05-22 13:25:05 -07:00
|
|
|
core::position2d<s32> targetPos = positions[i];
|
|
|
|
core::position2d<s32> sourcePos = sourceRects[i].UpperLeftCorner;
|
|
|
|
// This needs to be signed as it may go negative.
|
|
|
|
core::dimension2d<s32> sourceSize(sourceRects[i].getSize());
|
|
|
|
|
|
|
|
if (clipRect)
|
2010-08-08 10:46:48 -07:00
|
|
|
{
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.X < clipRect->UpperLeftCorner.X)
|
2010-08-08 10:46:48 -07:00
|
|
|
{
|
2011-05-22 13:25:05 -07:00
|
|
|
sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X;
|
|
|
|
targetPos.X = clipRect->UpperLeftCorner.X;
|
2010-08-08 10:46:48 -07:00
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
if (targetPos.X + (s32)sourceSize.Width > clipRect->LowerRightCorner.X)
|
2010-08-08 10:46:48 -07:00
|
|
|
{
|
2011-05-22 13:25:05 -07:00
|
|
|
sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
2010-08-08 10:46:48 -07:00
|
|
|
}
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.Y < clipRect->UpperLeftCorner.Y)
|
|
|
|
{
|
|
|
|
sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;
|
|
|
|
targetPos.Y = clipRect->UpperLeftCorner.Y;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.Y + (s32)sourceSize.Height > clipRect->LowerRightCorner.Y)
|
|
|
|
{
|
|
|
|
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// clip these coordinates
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.X < 0)
|
|
|
|
{
|
|
|
|
sourceSize.Width += targetPos.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
sourcePos.X -= targetPos.X;
|
|
|
|
targetPos.X = 0;
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width)
|
|
|
|
{
|
|
|
|
sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetPos.Y < 0)
|
|
|
|
{
|
|
|
|
sourceSize.Height += targetPos.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sourcePos.Y -= targetPos.Y;
|
|
|
|
targetPos.Y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height)
|
|
|
|
{
|
|
|
|
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok, we've clipped everything.
|
|
|
|
// now draw it.
|
|
|
|
|
|
|
|
core::rect<f32> tcoords;
|
|
|
|
tcoords.UpperLeftCorner.X = (((f32)sourcePos.X)) / texture->getOriginalSize().Width ;
|
|
|
|
tcoords.UpperLeftCorner.Y = (((f32)sourcePos.Y)) / texture->getOriginalSize().Height;
|
|
|
|
tcoords.LowerRightCorner.X = tcoords.UpperLeftCorner.X + ((f32)(sourceSize.Width) / texture->getOriginalSize().Width);
|
|
|
|
tcoords.LowerRightCorner.Y = tcoords.UpperLeftCorner.Y + ((f32)(sourceSize.Height) / texture->getOriginalSize().Height);
|
|
|
|
|
|
|
|
const core::rect<s32> poss(targetPos, sourceSize);
|
|
|
|
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
|
|
|
|
vtx.push_back(S3DVertex(left, top, 0.0f,
|
2011-06-07 01:56:52 -07:00
|
|
|
0.0f, 0.0f, 0.0f, color,
|
|
|
|
tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y));
|
2014-07-22 14:45:38 -07:00
|
|
|
vtx.push_back(S3DVertex(right, top, 0.0f,
|
2011-06-07 01:56:52 -07:00
|
|
|
0.0f, 0.0f, 0.0f, color,
|
|
|
|
tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y));
|
2014-07-22 14:45:38 -07:00
|
|
|
vtx.push_back(S3DVertex(right, down, 0.0f,
|
2011-06-07 01:56:52 -07:00
|
|
|
0.0f, 0.0f, 0.0f, color,
|
|
|
|
tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y));
|
2014-07-22 14:45:38 -07:00
|
|
|
vtx.push_back(S3DVertex(left, down, 0.0f,
|
2011-06-07 01:56:52 -07:00
|
|
|
0.0f, 0.0f, 0.0f, color,
|
|
|
|
tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y));
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
const u32 curPos = vtx.size() - 4;
|
|
|
|
indices.push_back(0 + curPos);
|
|
|
|
indices.push_back(1 + curPos);
|
|
|
|
indices.push_back(2 + curPos);
|
|
|
|
|
|
|
|
indices.push_back(0 + curPos);
|
|
|
|
indices.push_back(2 + curPos);
|
|
|
|
indices.push_back(3 + curPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vtx.size())
|
|
|
|
{
|
2014-07-28 10:49:05 -07:00
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glEnableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &vtx[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &vtx[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &vtx[0].TCoords);
|
|
|
|
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, indices.pointer());
|
|
|
|
glDisableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! The same, but with a four element array of colors, one for each vertex
|
|
|
|
void COGLES2Driver::draw2DImage(const video::ITexture* texture,
|
|
|
|
const core::rect<s32>& destRect,
|
|
|
|
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
|
|
|
|
const video::SColor* const colors, bool useAlphaChannelOfTexture)
|
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DIMAGE);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
// texcoords need to be flipped horizontally for RTTs
|
|
|
|
const bool isRTT = texture->isRenderTarget();
|
|
|
|
const core::dimension2du& ss = texture->getOriginalSize();
|
|
|
|
const f32 invW = 1.f / static_cast<f32>(ss.Width);
|
|
|
|
const f32 invH = 1.f / static_cast<f32>(ss.Height);
|
|
|
|
const core::rect<f32> tcoords(
|
|
|
|
sourceRect.UpperLeftCorner.X * invW,
|
|
|
|
(isRTT ? sourceRect.LowerRightCorner.Y : sourceRect.UpperLeftCorner.Y) * invH,
|
|
|
|
sourceRect.LowerRightCorner.X * invW,
|
|
|
|
(isRTT ? sourceRect.UpperLeftCorner.Y : sourceRect.LowerRightCorner.Y) *invH);
|
|
|
|
|
|
|
|
const video::SColor temp[4] =
|
|
|
|
{
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF
|
|
|
|
};
|
|
|
|
|
|
|
|
const video::SColor* const useColor = colors ? colors : temp;
|
|
|
|
|
|
|
|
disableTextures(1);
|
2011-06-03 04:32:53 -07:00
|
|
|
setActiveTexture(0, texture);
|
2011-05-22 13:25:05 -07:00
|
|
|
setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 ||
|
2011-06-07 01:56:52 -07:00
|
|
|
useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255,
|
|
|
|
true, useAlphaChannelOfTexture);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (clipRect)
|
|
|
|
{
|
|
|
|
if (!clipRect->isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y,
|
2011-06-07 01:56:52 -07:00
|
|
|
clipRect->getWidth(), clipRect->getHeight());
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
f32 left = (f32)destRect.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 right = (f32)destRect.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 down = 2.f - (f32)destRect.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 top = 2.f - (f32)destRect.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
u16 indices[] = {0, 1, 2, 3};
|
|
|
|
S3DVertex vertices[4];
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glEnableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
if (clipRect)
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
testGLError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! draws a set of 2d images, using a color and the alpha channel
|
|
|
|
void COGLES2Driver::draw2DImageBatch(const video::ITexture* texture,
|
|
|
|
const core::position2d<s32>& pos,
|
|
|
|
const core::array<core::rect<s32> >& sourceRects,
|
|
|
|
const core::array<s32>& indices, s32 kerningWidth,
|
|
|
|
const core::rect<s32>* clipRect, SColor color,
|
|
|
|
bool useAlphaChannelOfTexture)
|
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DIMAGE_BATCH);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
disableTextures(1);
|
2011-06-03 04:32:53 -07:00
|
|
|
if (!setActiveTexture(0, texture))
|
2011-05-22 13:25:05 -07:00
|
|
|
return;
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (clipRect)
|
|
|
|
{
|
|
|
|
if (!clipRect->isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y,
|
2011-06-07 01:56:52 -07:00
|
|
|
clipRect->getWidth(), clipRect->getHeight());
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const core::dimension2du& ss = texture->getOriginalSize();
|
|
|
|
core::position2d<s32> targetPos(pos);
|
|
|
|
// texcoords need to be flipped horizontally for RTTs
|
|
|
|
const bool isRTT = texture->isRenderTarget();
|
|
|
|
const f32 invW = 1.f / static_cast<f32>(ss.Width);
|
|
|
|
const f32 invH = 1.f / static_cast<f32>(ss.Height);
|
|
|
|
|
|
|
|
core::array<S3DVertex> vertices;
|
|
|
|
core::array<u16> quadIndices;
|
|
|
|
vertices.reallocate(indices.size()*4);
|
|
|
|
quadIndices.reallocate(indices.size()*3);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
for (u32 i = 0; i < indices.size(); ++i)
|
|
|
|
{
|
|
|
|
const s32 currentIndex = indices[i];
|
|
|
|
if (!sourceRects[currentIndex].isValid())
|
|
|
|
break;
|
|
|
|
|
|
|
|
const core::rect<f32> tcoords(
|
|
|
|
sourceRects[currentIndex].UpperLeftCorner.X * invW,
|
|
|
|
(isRTT ? sourceRects[currentIndex].LowerRightCorner.Y : sourceRects[currentIndex].UpperLeftCorner.Y) * invH,
|
|
|
|
sourceRects[currentIndex].LowerRightCorner.X * invW,
|
|
|
|
(isRTT ? sourceRects[currentIndex].UpperLeftCorner.Y : sourceRects[currentIndex].LowerRightCorner.Y) * invH);
|
|
|
|
|
|
|
|
const core::rect<s32> poss(targetPos, sourceRects[currentIndex].getSize());
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
|
2012-07-19 04:31:32 -07:00
|
|
|
const u32 vstart = vertices.size();
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices.push_back(S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y));
|
|
|
|
vertices.push_back(S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y));
|
|
|
|
vertices.push_back(S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y));
|
|
|
|
vertices.push_back(S3DVertex(left, down, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y));
|
2012-07-19 04:31:32 -07:00
|
|
|
quadIndices.push_back(vstart);
|
|
|
|
quadIndices.push_back(vstart+1);
|
|
|
|
quadIndices.push_back(vstart+2);
|
|
|
|
quadIndices.push_back(vstart);
|
|
|
|
quadIndices.push_back(vstart+2);
|
|
|
|
quadIndices.push_back(vstart+3);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
targetPos.X += sourceRects[currentIndex].getWidth();
|
|
|
|
}
|
2014-07-28 10:49:05 -07:00
|
|
|
|
2012-07-19 05:27:34 -07:00
|
|
|
if (vertices.size())
|
2014-07-28 10:49:05 -07:00
|
|
|
{
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glEnableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &vertices[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &vertices[0].Color);
|
|
|
|
glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &vertices[0].TCoords);
|
|
|
|
glDrawElements(GL_TRIANGLES, quadIndices.size(), GL_UNSIGNED_SHORT, quadIndices.pointer());
|
|
|
|
glDisableVertexAttribArray(EVA_TCOORD0);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
|
|
|
}
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (clipRect)
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
testGLError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! draw a 2d rectangle
|
|
|
|
void COGLES2Driver::draw2DRectangle(SColor color,
|
|
|
|
const core::rect<s32>& position,
|
|
|
|
const core::rect<s32>* clip)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DRECTANGLE);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
disableTextures();
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, false, false);
|
|
|
|
|
|
|
|
core::rect<s32> pos = position;
|
|
|
|
|
|
|
|
if (clip)
|
|
|
|
pos.clipAgainst(*clip);
|
|
|
|
|
|
|
|
if (!pos.isValid())
|
|
|
|
return;
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
|
|
|
|
|
|
|
f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
u16 indices[] = {0, 1, 2, 3};
|
|
|
|
S3DVertex vertices[4];
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, 0, 0);
|
|
|
|
vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, 0, 0);
|
|
|
|
vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0);
|
|
|
|
vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! draw an 2d rectangle
|
|
|
|
void COGLES2Driver::draw2DRectangle(const core::rect<s32>& position,
|
|
|
|
SColor colorLeftUp, SColor colorRightUp,
|
|
|
|
SColor colorLeftDown, SColor colorRightDown,
|
|
|
|
const core::rect<s32>* clip)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DRECTANGLE);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
core::rect<s32> pos = position;
|
|
|
|
|
|
|
|
if (clip)
|
|
|
|
pos.clipAgainst(*clip);
|
|
|
|
|
|
|
|
if (!pos.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
disableTextures();
|
|
|
|
|
|
|
|
setRenderStates2DMode(colorLeftUp.getAlpha() < 255 ||
|
|
|
|
colorRightUp.getAlpha() < 255 ||
|
|
|
|
colorLeftDown.getAlpha() < 255 ||
|
|
|
|
colorRightDown.getAlpha() < 255, false, false);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
|
|
|
|
|
|
|
f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
u16 indices[] = {0, 1, 2, 3};
|
|
|
|
S3DVertex vertices[4];
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, colorLeftUp, 0, 0);
|
|
|
|
vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, colorRightUp, 0, 0);
|
|
|
|
vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0);
|
|
|
|
vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Draws a 2d line.
|
|
|
|
void COGLES2Driver::draw2DLine(const core::position2d<s32>& start,
|
|
|
|
const core::position2d<s32>& end, SColor color)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_2DLINE);)
|
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
if (start==end)
|
|
|
|
drawPixel(start.X, start.Y, color);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableTextures();
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, false, false);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
2014-07-22 14:45:38 -07:00
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
f32 startX = (f32)start.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 endX = (f32)end.X / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 startY = 2.f - (f32)start.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
|
|
|
f32 endY = 2.f - (f32)end.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
2014-07-22 14:45:38 -07:00
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
u16 indices[] = {0, 1};
|
|
|
|
S3DVertex vertices[2];
|
|
|
|
vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0);
|
|
|
|
vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1);
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-09 07:52:15 -07:00
|
|
|
//! Draws a pixel
|
|
|
|
void COGLES2Driver::drawPixel(u32 x, u32 y, const SColor &color)
|
|
|
|
{
|
|
|
|
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
|
|
|
|
if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
disableTextures();
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, false, false);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
f32 X = (f32)x / (f32)renderTargetSize.Width * 2.f - 1.f;
|
|
|
|
f32 Y = 2.f - (f32)y / (f32)renderTargetSize.Height * 2.f - 1.f;
|
2011-06-09 07:52:15 -07:00
|
|
|
|
|
|
|
S3DVertex vertices[1];
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glDrawArrays(GL_POINTS, 0, 1);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-06-09 07:52:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-03 04:32:53 -07:00
|
|
|
bool COGLES2Driver::setActiveTexture(u32 stage, const video::ITexture* texture)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2013-01-14 16:31:37 -08:00
|
|
|
if (stage >= MaxSupportedTextures)
|
2011-05-22 13:25:05 -07:00
|
|
|
return false;
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
if (CurrentTexture[stage]==texture)
|
2011-05-22 13:25:05 -07:00
|
|
|
return true;
|
|
|
|
|
2014-05-22 10:07:49 -07:00
|
|
|
CurrentTexture.set(stage,texture);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
if (!texture)
|
|
|
|
return true;
|
2013-01-14 16:31:37 -08:00
|
|
|
else if (texture->getDriverType() != EDT_OGLES2)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-05-22 10:07:49 -07:00
|
|
|
CurrentTexture.set(stage, 0);
|
2013-01-14 16:31:37 -08:00
|
|
|
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
|
|
|
|
return false;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-19 17:30:45 -07:00
|
|
|
bool COGLES2Driver::isActiveTexture(u32 stage)
|
|
|
|
{
|
|
|
|
return (CurrentTexture[stage]) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
//! disables all textures beginning with the optional fromStage parameter.
|
|
|
|
bool COGLES2Driver::disableTextures(u32 fromStage)
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
for (u32 i = fromStage; i < MaxTextureUnits; ++i)
|
2011-06-03 04:32:53 -07:00
|
|
|
result &= setActiveTexture(i, 0);
|
2011-05-22 13:25:05 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! creates a matrix in supplied GLfloat array to pass to OGLES1
|
|
|
|
inline void COGLES2Driver::createGLMatrix(float gl_matrix[16], const core::matrix4& m)
|
|
|
|
{
|
|
|
|
memcpy(gl_matrix, m.pointer(), 16 * sizeof(f32));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! creates a opengltexturematrix from a D3D style texture matrix
|
|
|
|
inline void COGLES2Driver::createGLTextureMatrix(float *o, const core::matrix4& m)
|
|
|
|
{
|
|
|
|
o[0] = m[0];
|
|
|
|
o[1] = m[1];
|
|
|
|
o[2] = 0.f;
|
|
|
|
o[3] = 0.f;
|
|
|
|
|
|
|
|
o[4] = m[4];
|
|
|
|
o[5] = m[5];
|
|
|
|
o[6] = 0.f;
|
|
|
|
o[7] = 0.f;
|
|
|
|
|
|
|
|
o[8] = 0.f;
|
|
|
|
o[9] = 0.f;
|
|
|
|
o[10] = 1.f;
|
|
|
|
o[11] = 0.f;
|
|
|
|
|
|
|
|
o[12] = m[8];
|
|
|
|
o[13] = m[9];
|
|
|
|
o[14] = 0.f;
|
|
|
|
o[15] = 1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! returns a device dependent texture from a software surface (IImage)
|
2013-11-18 17:05:49 -08:00
|
|
|
ITexture* COGLES2Driver::createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2013-05-27 10:16:52 -07:00
|
|
|
COGLES2Texture* texture = 0;
|
|
|
|
|
|
|
|
if (surface && checkColorFormat(surface->getColorFormat(), surface->getDimension()))
|
|
|
|
texture = new COGLES2Texture(surface, name, mipmapData, this);
|
|
|
|
|
|
|
|
return texture;
|
2013-11-18 17:05:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! returns a device dependent texture from a software surface (IImage)
|
2014-05-08 09:23:12 -07:00
|
|
|
ITexture* COGLES2Driver::createDeviceDependentTextureCube(const io::path& name, IImage* posXImage, IImage* negXImage,
|
2013-11-18 17:05:49 -08:00
|
|
|
IImage* posYImage, IImage* negYImage, IImage* posZImage, IImage* negZImage)
|
|
|
|
{
|
|
|
|
COGLES2Texture* texture = 0;
|
|
|
|
|
|
|
|
if (posXImage && negXImage && posYImage && negYImage && posZImage && negZImage &&
|
|
|
|
checkTextureCube(posXImage, negXImage, posYImage, negYImage, posZImage, negZImage) &&
|
|
|
|
checkColorFormat(posXImage->getColorFormat(), posXImage->getDimension()))
|
|
|
|
{
|
|
|
|
texture = new COGLES2Texture(name, posXImage, negXImage, posYImage, negYImage, posZImage, negZImage, this);
|
|
|
|
}
|
2014-05-08 09:23:12 -07:00
|
|
|
|
2013-11-18 17:05:49 -08:00
|
|
|
return texture;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets a material.
|
|
|
|
void COGLES2Driver::setMaterial(const SMaterial& material)
|
|
|
|
{
|
|
|
|
Material = material;
|
|
|
|
OverrideMaterial.apply(Material);
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
for (u32 i = 0; i < MaxTextureUnits; ++i)
|
2014-10-02 11:22:36 -07:00
|
|
|
{
|
2013-01-14 16:31:37 -08:00
|
|
|
setActiveTexture(i, material.getTexture(i));
|
2014-10-02 11:22:36 -07:00
|
|
|
setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i));
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//! prints error if an error happened.
|
|
|
|
bool COGLES2Driver::testGLError()
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
GLenum g = glGetError();
|
|
|
|
switch (g)
|
|
|
|
{
|
|
|
|
case GL_NO_ERROR:
|
|
|
|
return false;
|
|
|
|
case GL_INVALID_ENUM:
|
|
|
|
os::Printer::log("GL_INVALID_ENUM", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case GL_INVALID_VALUE:
|
|
|
|
os::Printer::log("GL_INVALID_VALUE", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case GL_INVALID_OPERATION:
|
|
|
|
os::Printer::log("GL_INVALID_OPERATION", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case GL_OUT_OF_MEMORY:
|
|
|
|
os::Printer::log("GL_OUT_OF_MEMORY", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
//! prints error if an error happened.
|
2011-05-22 13:25:05 -07:00
|
|
|
bool COGLES2Driver::testEGLError()
|
|
|
|
{
|
|
|
|
#if defined(EGL_VERSION_1_0) && defined(_DEBUG)
|
|
|
|
EGLint g = eglGetError();
|
|
|
|
switch (g)
|
|
|
|
{
|
|
|
|
case EGL_SUCCESS:
|
|
|
|
return false;
|
|
|
|
case EGL_NOT_INITIALIZED :
|
|
|
|
os::Printer::log("Not Initialized", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_ACCESS:
|
|
|
|
os::Printer::log("Bad Access", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_ALLOC:
|
|
|
|
os::Printer::log("Bad Alloc", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_ATTRIBUTE:
|
|
|
|
os::Printer::log("Bad Attribute", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_CONTEXT:
|
|
|
|
os::Printer::log("Bad Context", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_CONFIG:
|
|
|
|
os::Printer::log("Bad Config", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_CURRENT_SURFACE:
|
|
|
|
os::Printer::log("Bad Current Surface", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_DISPLAY:
|
|
|
|
os::Printer::log("Bad Display", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_SURFACE:
|
|
|
|
os::Printer::log("Bad Surface", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_MATCH:
|
|
|
|
os::Printer::log("Bad Match", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_PARAMETER:
|
|
|
|
os::Printer::log("Bad Parameter", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_NATIVE_PIXMAP:
|
|
|
|
os::Printer::log("Bad Native Pixmap", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_BAD_NATIVE_WINDOW:
|
|
|
|
os::Printer::log("Bad Native Window", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
case EGL_CONTEXT_LOST:
|
|
|
|
os::Printer::log("Context Lost", ELL_ERROR);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void COGLES2Driver::setRenderStates3DMode()
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_SET_RENDERSTATE_3D);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (CurrentRenderMode != ERM_3D)
|
|
|
|
{
|
|
|
|
// Reset Texture Stages
|
2013-01-14 16:31:37 -08:00
|
|
|
BridgeCalls->setBlend(false);
|
2014-05-10 14:47:14 -07:00
|
|
|
BridgeCalls->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
ResetRenderStates = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ResetRenderStates || LastMaterial != Material)
|
|
|
|
{
|
|
|
|
// unset old material
|
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
// unset last 3d material
|
|
|
|
if (CurrentRenderMode == ERM_2D)
|
|
|
|
MaterialRenderer2D->OnUnsetMaterial();
|
|
|
|
else if (LastMaterial.MaterialType != Material.MaterialType &&
|
2013-01-14 16:31:37 -08:00
|
|
|
static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
|
2011-05-22 13:25:05 -07:00
|
|
|
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
|
|
|
|
|
|
|
|
// set new material.
|
|
|
|
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
|
|
|
|
Material, LastMaterial, ResetRenderStates, this);
|
|
|
|
|
|
|
|
LastMaterial = Material;
|
|
|
|
ResetRenderStates = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD);
|
|
|
|
|
|
|
|
CurrentRenderMode = ERM_3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Can be called by an IMaterialRenderer to make its work easier.
|
2013-01-14 16:31:37 -08:00
|
|
|
void COGLES2Driver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_SET_RENDERSTATE_BASIC);)
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// ZBuffer
|
2014-07-22 14:45:38 -07:00
|
|
|
switch (material.ZBuffer)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-10-11 02:37:30 -07:00
|
|
|
case ECFN_DISABLED:
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthTest(false);
|
|
|
|
break;
|
|
|
|
case ECFN_LESSEQUAL:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_LEQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_EQUAL:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_EQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_LESS:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_LESS);
|
|
|
|
break;
|
|
|
|
case ECFN_NOTEQUAL:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_NOTEQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_GREATEREQUAL:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_GEQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_GREATER:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_GREATER);
|
|
|
|
break;
|
|
|
|
case ECFN_ALWAYS:
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_ALWAYS);
|
|
|
|
break;
|
2014-10-11 02:37:30 -07:00
|
|
|
case ECFN_NEVER:
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_NEVER);
|
2014-10-11 02:37:30 -07:00
|
|
|
break;
|
2014-07-22 14:45:38 -07:00
|
|
|
default:
|
|
|
|
break;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// ZWrite
|
2014-07-22 14:45:38 -07:00
|
|
|
if (material.ZWriteEnable && (AllowZWriteOnTransparent || (material.BlendOperation == EBO_NONE &&
|
|
|
|
!MaterialRenderers[material.MaterialType].Renderer->isTransparent())))
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthMask(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BridgeCalls->setDepthMask(false);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// Back face culling
|
2014-07-22 14:45:38 -07:00
|
|
|
if ((material.FrontfaceCulling) && (material.BackfaceCulling))
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setCullFaceFunc(GL_FRONT_AND_BACK);
|
|
|
|
BridgeCalls->setCullFace(true);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2014-07-22 14:45:38 -07:00
|
|
|
else if (material.BackfaceCulling)
|
|
|
|
{
|
|
|
|
BridgeCalls->setCullFaceFunc(GL_BACK);
|
|
|
|
BridgeCalls->setCullFace(true);
|
|
|
|
}
|
|
|
|
else if (material.FrontfaceCulling)
|
|
|
|
{
|
|
|
|
BridgeCalls->setCullFaceFunc(GL_FRONT);
|
|
|
|
BridgeCalls->setCullFace(true);
|
|
|
|
}
|
|
|
|
else
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setCullFace(false);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
// Color Mask
|
|
|
|
BridgeCalls->setColorMask(
|
|
|
|
(material.ColorMask & ECP_RED)?GL_TRUE:GL_FALSE,
|
|
|
|
(material.ColorMask & ECP_GREEN)?GL_TRUE:GL_FALSE,
|
|
|
|
(material.ColorMask & ECP_BLUE)?GL_TRUE:GL_FALSE,
|
|
|
|
(material.ColorMask & ECP_ALPHA)?GL_TRUE:GL_FALSE);
|
|
|
|
|
2014-05-10 14:47:14 -07:00
|
|
|
// Blend Equation
|
|
|
|
if (material.BlendOperation == EBO_NONE)
|
|
|
|
BridgeCalls->setBlend(false);
|
|
|
|
else
|
2011-06-05 14:50:36 -07:00
|
|
|
{
|
2014-05-10 14:47:14 -07:00
|
|
|
BridgeCalls->setBlend(true);
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-05-10 14:47:14 -07:00
|
|
|
switch (material.BlendOperation)
|
|
|
|
{
|
|
|
|
case EBO_ADD:
|
|
|
|
BridgeCalls->setBlendEquation(GL_FUNC_ADD);
|
|
|
|
break;
|
|
|
|
case EBO_SUBTRACT:
|
|
|
|
BridgeCalls->setBlendEquation(GL_FUNC_SUBTRACT);
|
|
|
|
break;
|
|
|
|
case EBO_REVSUBTRACT:
|
|
|
|
BridgeCalls->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2011-06-05 14:50:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-10 14:47:14 -07:00
|
|
|
// Blend Factor
|
2014-05-26 09:40:42 -07:00
|
|
|
if (IR(material.BlendFactor) & 0xFFFFFFFF)
|
2014-05-10 14:47:14 -07:00
|
|
|
{
|
|
|
|
E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
|
|
|
|
E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
|
|
|
|
E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
|
|
|
|
E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
|
|
|
|
E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
|
|
|
|
u32 alphaSource = 0;
|
|
|
|
|
|
|
|
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, material.BlendFactor);
|
|
|
|
|
|
|
|
BridgeCalls->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact),
|
|
|
|
getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact));
|
|
|
|
}
|
|
|
|
|
2014-07-28 10:49:05 -07:00
|
|
|
if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness)
|
|
|
|
glLineWidth(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedLine[0], DimAliasedLine[1]));
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// Anti aliasing
|
|
|
|
if (resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing)
|
2011-06-05 14:50:36 -07:00
|
|
|
{
|
2013-01-14 16:31:37 -08:00
|
|
|
if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE)
|
|
|
|
glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
|
|
|
|
else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE)
|
|
|
|
glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
|
2011-06-05 14:50:36 -07:00
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// Texture parameters
|
|
|
|
setTextureRenderStates(material, resetAllRenderStates);
|
|
|
|
}
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
|
|
|
|
void COGLES2Driver::setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_SET_RENDERSTATE_TEXTURE);)
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// Set textures to TU/TIU and apply filters to them
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
for (s32 i = MaxTextureUnits-1; i>= 0; --i)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2013-01-14 16:31:37 -08:00
|
|
|
const COGLES2Texture* tmpTexture = static_cast<const COGLES2Texture*>(CurrentTexture[i]);
|
2013-11-18 17:05:49 -08:00
|
|
|
GLenum tmpTextureType = (tmpTexture) ? tmpTexture->getOpenGLTextureType() : GL_TEXTURE_2D;
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2014-10-02 11:22:36 -07:00
|
|
|
BridgeCalls->setTexture(i, tmpTextureType);
|
|
|
|
|
|
|
|
if (!CurrentTexture[i])
|
2013-01-14 16:31:37 -08:00
|
|
|
continue;
|
|
|
|
|
2013-05-03 08:24:12 -07:00
|
|
|
if (resetAllRenderstates)
|
2013-01-14 16:31:37 -08:00
|
|
|
tmpTexture->getStatesCache().IsCached = false;
|
|
|
|
|
2013-05-03 08:24:12 -07:00
|
|
|
if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter ||
|
2013-01-14 16:31:37 -08:00
|
|
|
material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter)
|
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER,
|
2013-01-14 16:31:37 -08:00
|
|
|
(material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST);
|
|
|
|
|
|
|
|
tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter;
|
|
|
|
tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (material.UseMipMaps && CurrentTexture[i]->hasMipMaps())
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter ||
|
2013-01-14 16:31:37 -08:00
|
|
|
material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || !tmpTexture->getStatesCache().MipMapStatus)
|
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
|
2013-01-14 16:31:37 -08:00
|
|
|
material.TextureLayer[i].TrilinearFilter ? GL_LINEAR_MIPMAP_LINEAR :
|
|
|
|
material.TextureLayer[i].BilinearFilter ? GL_LINEAR_MIPMAP_NEAREST :
|
|
|
|
GL_NEAREST_MIPMAP_NEAREST);
|
|
|
|
|
|
|
|
tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter;
|
|
|
|
tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter;
|
|
|
|
tmpTexture->getStatesCache().MipMapStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter ||
|
2013-01-14 16:31:37 -08:00
|
|
|
material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || tmpTexture->getStatesCache().MipMapStatus)
|
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
|
2013-01-14 16:31:37 -08:00
|
|
|
(material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST);
|
|
|
|
|
|
|
|
tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter;
|
|
|
|
tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter;
|
|
|
|
tmpTexture->getStatesCache().MipMapStatus = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_EXT_texture_filter_anisotropic
|
|
|
|
if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic] &&
|
|
|
|
(!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter))
|
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
2013-01-14 16:31:37 -08:00
|
|
|
material.TextureLayer[i].AnisotropicFilter>1 ? core::min_(MaxAnisotropy, material.TextureLayer[i].AnisotropicFilter) : 1);
|
|
|
|
|
|
|
|
tmpTexture->getStatesCache().AnisotropicFilter = material.TextureLayer[i].AnisotropicFilter;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-03 08:24:12 -07:00
|
|
|
if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapU != tmpTexture->getStatesCache().WrapU)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayer[i].TextureWrapU));
|
2013-01-14 16:31:37 -08:00
|
|
|
tmpTexture->getStatesCache().WrapU = material.TextureLayer[i].TextureWrapU;
|
|
|
|
}
|
|
|
|
|
2013-05-03 08:24:12 -07:00
|
|
|
if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapV != tmpTexture->getStatesCache().WrapV)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayer[i].TextureWrapV));
|
2013-01-14 16:31:37 -08:00
|
|
|
tmpTexture->getStatesCache().WrapV = material.TextureLayer[i].TextureWrapV;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
|
|
|
|
tmpTexture->getStatesCache().IsCached = true;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode.
|
|
|
|
GLint COGLES2Driver::getTextureWrapMode(u8 clamp) const
|
|
|
|
{
|
|
|
|
switch (clamp)
|
|
|
|
{
|
|
|
|
case ETC_CLAMP:
|
|
|
|
case ETC_CLAMP_TO_EDGE:
|
|
|
|
case ETC_CLAMP_TO_BORDER:
|
|
|
|
return GL_CLAMP_TO_EDGE;
|
|
|
|
case ETC_MIRROR:
|
|
|
|
return GL_REPEAT;
|
|
|
|
default:
|
|
|
|
return GL_REPEAT;
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! sets the needed renderstates
|
|
|
|
void COGLES2Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_SET_RENDERSTATE_2D);)
|
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
if (CurrentRenderMode != ERM_2D)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
|
|
|
// unset last 3d material
|
|
|
|
if (CurrentRenderMode == ERM_3D)
|
|
|
|
{
|
|
|
|
if (static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
|
|
|
|
}
|
2011-06-06 08:00:50 -07:00
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
CurrentRenderMode = ERM_2D;
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
if (!OverrideMaterial2DEnabled)
|
|
|
|
Material = InitMaterial2D;
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
if (OverrideMaterial2DEnabled)
|
|
|
|
{
|
|
|
|
OverrideMaterial2D.Lighting=false;
|
2013-01-15 11:23:46 -08:00
|
|
|
OverrideMaterial2D.ZWriteEnable=false;
|
|
|
|
OverrideMaterial2D.ZBuffer=ECFN_NEVER; // it will be ECFN_DISABLED after merge
|
|
|
|
OverrideMaterial2D.Lighting=false;
|
|
|
|
|
|
|
|
Material = OverrideMaterial2D;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
if (texture)
|
|
|
|
MaterialRenderer2D->setTexture(CurrentTexture[0]);
|
|
|
|
else
|
|
|
|
MaterialRenderer2D->setTexture(0);
|
|
|
|
|
|
|
|
MaterialRenderer2D->OnSetMaterial(Material, LastMaterial, true, 0);
|
|
|
|
LastMaterial = Material;
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
// no alphaChannel without texture
|
|
|
|
alphaChannel &= texture;
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (alphaChannel || alpha)
|
|
|
|
{
|
2013-01-14 16:31:37 -08:00
|
|
|
BridgeCalls->setBlend(true);
|
2013-01-15 11:23:46 -08:00
|
|
|
BridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
else
|
2013-01-14 16:31:37 -08:00
|
|
|
BridgeCalls->setBlend(false);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2013-01-15 11:23:46 -08:00
|
|
|
MaterialRenderer2D->OnRender(this, video::EVT_STANDARD);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! \return Returns the name of the video driver.
|
|
|
|
const wchar_t* COGLES2Driver::getName() const
|
|
|
|
{
|
|
|
|
return Name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! deletes all dynamic lights there are
|
|
|
|
void COGLES2Driver::deleteAllDynamicLights()
|
|
|
|
{
|
|
|
|
RequestedLights.clear();
|
|
|
|
CNullDriver::deleteAllDynamicLights();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! adds a dynamic light
|
|
|
|
s32 COGLES2Driver::addDynamicLight(const SLight& light)
|
|
|
|
{
|
|
|
|
CNullDriver::addDynamicLight(light);
|
|
|
|
|
|
|
|
RequestedLights.push_back(RequestedLight(light));
|
|
|
|
|
|
|
|
u32 newLightIndex = RequestedLights.size() - 1;
|
|
|
|
|
|
|
|
return (s32)newLightIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Turns a dynamic light on or off
|
|
|
|
//! \param lightIndex: the index returned by addDynamicLight
|
|
|
|
//! \param turnOn: true to turn the light on, false to turn it off
|
|
|
|
void COGLES2Driver::turnLightOn(s32 lightIndex, bool turnOn)
|
|
|
|
{
|
|
|
|
if (lightIndex < 0 || lightIndex >= (s32)RequestedLights.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
RequestedLight & requestedLight = RequestedLights[lightIndex];
|
|
|
|
requestedLight.DesireToBeOn = turnOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! returns the maximal amount of dynamic lights the device can handle
|
|
|
|
u32 COGLES2Driver::getMaximalDynamicLightAmount() const
|
|
|
|
{
|
2013-03-19 08:54:47 -07:00
|
|
|
return 8;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// this code was sent in by Oliver Klems, thank you
|
|
|
|
void COGLES2Driver::setViewPort(const core::rect<s32>& area)
|
|
|
|
{
|
|
|
|
core::rect<s32> vp = area;
|
|
|
|
core::rect<s32> rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height);
|
|
|
|
vp.clipAgainst(rendert);
|
|
|
|
|
|
|
|
if (vp.getHeight() > 0 && vp.getWidth() > 0)
|
2013-03-19 08:54:47 -07:00
|
|
|
BridgeCalls->setViewport(core::rect<s32>(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight()));
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
ViewPort = vp;
|
|
|
|
testGLError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Draws a shadow volume into the stencil buffer.
|
2014-07-22 14:45:38 -07:00
|
|
|
void COGLES2Driver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_SHADOW);)
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
const u32 count=triangles.size();
|
2011-05-22 13:25:05 -07:00
|
|
|
if (!StencilBuffer || !count)
|
|
|
|
return;
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
bool fog = Material.FogEnable;
|
|
|
|
bool lighting = Material.Lighting;
|
|
|
|
E_MATERIAL_TYPE materialType = Material.MaterialType;
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
Material.FogEnable = false;
|
|
|
|
Material.Lighting = false;
|
|
|
|
Material.MaterialType = EMT_SOLID; // Dedicated material in future.
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
BridgeCalls->setDepthTest(true);
|
|
|
|
BridgeCalls->setDepthFunc(GL_LESS);
|
|
|
|
BridgeCalls->setDepthMask(false);
|
|
|
|
|
|
|
|
if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY)))
|
|
|
|
{
|
|
|
|
BridgeCalls->setColorMask(false, false, false, false);
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
2014-07-22 14:45:38 -07:00
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(core::vector3df), triangles.const_pointer());
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
glStencilMask(~0);
|
|
|
|
glStencilFunc(GL_ALWAYS, 0, ~0);
|
|
|
|
|
|
|
|
GLenum decr = GL_DECR;
|
|
|
|
GLenum incr = GL_INCR;
|
2014-07-22 14:45:38 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
#if defined(GL_OES_stencil_wrap)
|
|
|
|
if (FeatureAvailable[IRR_OES_stencil_wrap])
|
|
|
|
{
|
|
|
|
decr = GL_DECR_WRAP_OES;
|
|
|
|
incr = GL_INCR_WRAP_OES;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setCullFace(true);
|
|
|
|
|
|
|
|
if (zfail)
|
|
|
|
{
|
|
|
|
BridgeCalls->setCullFaceFunc(GL_FRONT);
|
|
|
|
glStencilOp(GL_KEEP, incr, GL_KEEP);
|
2011-05-22 13:25:05 -07:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, count);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setCullFaceFunc(GL_BACK);
|
|
|
|
glStencilOp(GL_KEEP, decr, GL_KEEP);
|
2011-05-22 13:25:05 -07:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, count);
|
|
|
|
}
|
2014-07-22 14:45:38 -07:00
|
|
|
else // zpass
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setCullFaceFunc(GL_BACK);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, incr);
|
2011-05-22 13:25:05 -07:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, count);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setCullFaceFunc(GL_FRONT);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, decr);
|
2011-05-22 13:25:05 -07:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, count);
|
|
|
|
}
|
|
|
|
|
2014-07-23 12:08:16 -07:00
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
2014-07-22 14:45:38 -07:00
|
|
|
|
|
|
|
Material.FogEnable = fog;
|
|
|
|
Material.Lighting = lighting;
|
|
|
|
Material.MaterialType = materialType;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-07 01:56:52 -07:00
|
|
|
void COGLES2Driver::drawStencilShadow(bool clearStencilBuffer,
|
|
|
|
video::SColor leftUpEdge, video::SColor rightUpEdge,
|
|
|
|
video::SColor leftDownEdge, video::SColor rightDownEdge)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_SHADOW);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (!StencilBuffer)
|
|
|
|
return;
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
setRenderStates2DMode(true, false, false);
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
disableTextures();
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthMask(false);
|
|
|
|
BridgeCalls->setColorMask(true, true, true, true);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setBlend(true);
|
|
|
|
BridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
glStencilFunc(GL_NOTEQUAL, 0, ~0);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
|
|
|
|
|
|
|
u16 indices[] = {0, 1, 2, 3};
|
|
|
|
S3DVertex vertices[4];
|
2014-07-22 14:45:38 -07:00
|
|
|
vertices[0] = S3DVertex(-1.f, 1.f, 0.9f, 0, 0, 1, leftDownEdge, 0, 0);
|
|
|
|
vertices[1] = S3DVertex(1.f, 1.f, 0.9f, 0, 0, 1, leftUpEdge, 0, 0);
|
|
|
|
vertices[2] = S3DVertex(1.f, -1.f, 0.9f, 0, 0, 1, rightUpEdge, 0, 0);
|
|
|
|
vertices[3] = S3DVertex(-1.f, -1.f, 0.9f, 0, 0, 1, rightDownEdge, 0, 0);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
2014-07-23 12:08:16 -07:00
|
|
|
if (clearStencilBuffer)
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Draws a 3d line.
|
|
|
|
void COGLES2Driver::draw3DLine(const core::vector3df& start,
|
|
|
|
const core::vector3df& end, SColor color)
|
|
|
|
{
|
2014-10-15 15:50:34 -07:00
|
|
|
IRR_PROFILE(CProfileScope p1(EPID_ES2_DRAW_3DLINE);)
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
u16 indices[] = {0, 1};
|
|
|
|
S3DVertex vertices[2];
|
|
|
|
vertices[0] = S3DVertex(start.X, start.Y, start.Z, 0, 0, 1, color, 0, 0);
|
|
|
|
vertices[1] = S3DVertex(end.X, end.Y, end.Z, 0, 0, 1, color, 0, 0);
|
2014-07-28 10:49:05 -07:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(EVA_POSITION);
|
|
|
|
glEnableVertexAttribArray(EVA_COLOR);
|
|
|
|
glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
|
|
|
|
glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
|
|
|
|
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, indices);
|
|
|
|
glDisableVertexAttribArray(EVA_COLOR);
|
|
|
|
glDisableVertexAttribArray(EVA_POSITION);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Only used by the internal engine. Used to notify the driver that
|
|
|
|
//! the window was resized.
|
|
|
|
void COGLES2Driver::OnResize(const core::dimension2d<u32>& size)
|
|
|
|
{
|
|
|
|
CNullDriver::OnResize(size);
|
2013-03-19 08:54:47 -07:00
|
|
|
BridgeCalls->setViewport(core::rect<s32>(0, 0, size.Width, size.Height));
|
2011-05-22 13:25:05 -07:00
|
|
|
testGLError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns type of video driver
|
|
|
|
E_DRIVER_TYPE COGLES2Driver::getDriverType() const
|
|
|
|
{
|
|
|
|
return EDT_OGLES2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! returns color format
|
|
|
|
ECOLOR_FORMAT COGLES2Driver::getColorFormat() const
|
|
|
|
{
|
|
|
|
return ColorFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-05 15:06:50 -07:00
|
|
|
//! Get a vertex shader constant index.
|
|
|
|
s32 COGLES2Driver::getVertexShaderConstantID(const c8* name)
|
|
|
|
{
|
|
|
|
return getPixelShaderConstantID(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get a pixel shader constant index.
|
|
|
|
s32 COGLES2Driver::getPixelShaderConstantID(const c8* name)
|
|
|
|
{
|
|
|
|
os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID().");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
//! Sets a vertex shader constant.
|
|
|
|
void COGLES2Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
|
|
|
|
{
|
2013-04-07 14:27:11 -07:00
|
|
|
os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a pixel shader constant.
|
|
|
|
void COGLES2Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
|
|
|
|
{
|
2013-04-07 14:27:11 -07:00
|
|
|
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
2013-04-05 15:06:50 -07:00
|
|
|
//! Sets a constant for the vertex shader based on an index.
|
|
|
|
bool COGLES2Driver::setVertexShaderConstant(s32 index, const f32* floats, int count)
|
|
|
|
{
|
|
|
|
//pass this along, as in GLSL the same routine is used for both vertex and fragment shaders
|
|
|
|
return setPixelShaderConstant(index, floats, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Int interface for the above.
|
|
|
|
bool COGLES2Driver::setVertexShaderConstant(s32 index, const s32* ints, int count)
|
|
|
|
{
|
|
|
|
return setPixelShaderConstant(index, ints, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a constant for the pixel shader based on an index.
|
|
|
|
bool COGLES2Driver::setPixelShaderConstant(s32 index, const f32* floats, int count)
|
|
|
|
{
|
|
|
|
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Int interface for the above.
|
|
|
|
bool COGLES2Driver::setPixelShaderConstant(s32 index, const s32* ints, int count)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2013-04-05 15:06:50 -07:00
|
|
|
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
2011-05-22 13:25:05 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Adds a new material renderer to the VideoDriver, using pixel and/or
|
|
|
|
//! vertex shaders to render geometry.
|
|
|
|
s32 COGLES2Driver::addShaderMaterial(const c8* vertexShaderProgram,
|
|
|
|
const c8* pixelShaderProgram,
|
|
|
|
IShaderConstantSetCallBack* callback,
|
|
|
|
E_MATERIAL_TYPE baseMaterial, s32 userData)
|
|
|
|
{
|
|
|
|
os::Printer::log("No shader support.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry.
|
|
|
|
s32 COGLES2Driver::addHighLevelShaderMaterial(
|
|
|
|
const c8* vertexShaderProgram,
|
|
|
|
const c8* vertexShaderEntryPointName,
|
|
|
|
E_VERTEX_SHADER_TYPE vsCompileTarget,
|
|
|
|
const c8* pixelShaderProgram,
|
|
|
|
const c8* pixelShaderEntryPointName,
|
|
|
|
E_PIXEL_SHADER_TYPE psCompileTarget,
|
|
|
|
const c8* geometryShaderProgram,
|
|
|
|
const c8* geometryShaderEntryPointName,
|
|
|
|
E_GEOMETRY_SHADER_TYPE gsCompileTarget,
|
|
|
|
scene::E_PRIMITIVE_TYPE inType,
|
|
|
|
scene::E_PRIMITIVE_TYPE outType,
|
|
|
|
u32 verticesOut,
|
|
|
|
IShaderConstantSetCallBack* callback,
|
|
|
|
E_MATERIAL_TYPE baseMaterial,
|
2012-12-11 17:26:39 -08:00
|
|
|
s32 userData, E_GPU_SHADING_LANGUAGE shadingLang)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
|
|
|
s32 nr = -1;
|
2013-01-14 16:31:37 -08:00
|
|
|
COGLES2MaterialRenderer* r = new COGLES2MaterialRenderer(
|
2011-05-22 13:25:05 -07:00
|
|
|
this, nr, vertexShaderProgram,
|
|
|
|
pixelShaderProgram,
|
2013-01-14 16:31:37 -08:00
|
|
|
callback, baseMaterial, userData);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
r->drop();
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns a pointer to the IVideoDriver interface. (Implementation for
|
|
|
|
//! IMaterialRendererServices)
|
|
|
|
IVideoDriver* COGLES2Driver::getVideoDriver()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns pointer to the IGPUProgrammingServices interface.
|
|
|
|
IGPUProgrammingServices* COGLES2Driver::getGPUProgrammingServices()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ITexture* COGLES2Driver::addRenderTargetTexture(
|
|
|
|
const core::dimension2d<u32>& size,
|
|
|
|
const io::path& name, const ECOLOR_FORMAT format)
|
|
|
|
{
|
|
|
|
//disable mip-mapping
|
|
|
|
const bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
|
|
|
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
|
|
|
|
|
|
|
|
video::ITexture* rtt = 0;
|
|
|
|
|
2013-03-19 08:54:47 -07:00
|
|
|
rtt = new COGLES2FBOTexture(size, name, this, format);
|
|
|
|
if (rtt)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2013-03-19 08:54:47 -07:00
|
|
|
bool success = false;
|
|
|
|
addTexture(rtt);
|
2011-06-06 05:17:27 -07:00
|
|
|
|
2013-03-19 08:54:47 -07:00
|
|
|
ITexture* tex = createDepthTexture(rtt);
|
|
|
|
if (tex)
|
|
|
|
{
|
|
|
|
success = static_cast<video::COGLES2FBODepthTexture*>(tex)->attach(rtt);
|
2011-06-06 05:17:27 -07:00
|
|
|
if (!success)
|
|
|
|
{
|
2013-03-19 08:54:47 -07:00
|
|
|
removeDepthTexture(tex);
|
2011-06-06 05:17:27 -07:00
|
|
|
}
|
2013-03-19 08:54:47 -07:00
|
|
|
tex->drop();
|
|
|
|
}
|
|
|
|
rtt->drop();
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
removeTexture(rtt);
|
|
|
|
rtt=0;
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//restore mip-mapping
|
|
|
|
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels);
|
|
|
|
|
|
|
|
return rtt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns the maximum amount of primitives
|
|
|
|
u32 COGLES2Driver::getMaximalPrimitiveCount() const
|
|
|
|
{
|
|
|
|
return 65535;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! set or reset render target
|
|
|
|
bool COGLES2Driver::setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
|
|
|
|
bool clearZBuffer, SColor color)
|
|
|
|
{
|
|
|
|
// check for right driver type
|
|
|
|
|
|
|
|
if (texture && texture->getDriverType() != EDT_OGLES2)
|
|
|
|
{
|
|
|
|
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we should set the previous RT back
|
|
|
|
|
2011-06-03 04:32:53 -07:00
|
|
|
setActiveTexture(0, 0);
|
2011-05-22 13:25:05 -07:00
|
|
|
ResetRenderStates = true;
|
|
|
|
if (RenderTargetTexture != 0)
|
|
|
|
{
|
|
|
|
RenderTargetTexture->unbindRTT();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
// we want to set a new target. so do this.
|
2013-03-19 08:54:47 -07:00
|
|
|
BridgeCalls->setViewport(core::rect<s32>(0, 0, texture->getSize().Width, texture->getSize().Height));
|
2011-05-22 13:25:05 -07:00
|
|
|
RenderTargetTexture = static_cast<COGLES2Texture*>(texture);
|
|
|
|
RenderTargetTexture->bindRTT();
|
|
|
|
CurrentRendertargetSize = texture->getSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-19 08:54:47 -07:00
|
|
|
BridgeCalls->setViewport(core::rect<s32>(0, 0, ScreenSize.Width, ScreenSize.Height));
|
2011-05-22 13:25:05 -07:00
|
|
|
RenderTargetTexture = 0;
|
|
|
|
CurrentRendertargetSize = core::dimension2d<u32>(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLbitfield mask = 0;
|
2014-07-22 14:45:38 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (clearBackBuffer)
|
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setColorMask(true, true, true, true);
|
2014-05-25 08:34:18 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
const f32 inv = 1.0f / 255.0f;
|
|
|
|
glClearColor(color.getRed() * inv, color.getGreen() * inv,
|
2011-06-07 01:56:52 -07:00
|
|
|
color.getBlue() * inv, color.getAlpha() * inv);
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
mask |= GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
2014-07-22 14:45:38 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
if (clearZBuffer)
|
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthMask(true);
|
2011-05-22 13:25:05 -07:00
|
|
|
mask |= GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
glClear(mask);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// returns the current size of the screen or rendertarget
|
|
|
|
const core::dimension2d<u32>& COGLES2Driver::getCurrentRenderTargetSize() const
|
|
|
|
{
|
|
|
|
if (CurrentRendertargetSize.Width == 0)
|
|
|
|
return ScreenSize;
|
|
|
|
else
|
|
|
|
return CurrentRendertargetSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-04 10:26:18 -08:00
|
|
|
ITexture* COGLES2Driver::getRenderTargetTexture() const
|
|
|
|
{
|
|
|
|
return RenderTargetTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
//! Clears the ZBuffer.
|
|
|
|
void COGLES2Driver::clearZBuffer()
|
|
|
|
{
|
2014-07-22 14:45:38 -07:00
|
|
|
BridgeCalls->setDepthMask(true);
|
2014-05-25 08:34:18 -07:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns an image created from the last rendered frame.
|
|
|
|
// We want to read the front buffer to get the latest render finished.
|
|
|
|
// This is not possible under ogl-es, though, so one has to call this method
|
|
|
|
// outside of the render loop only.
|
2011-06-09 01:47:45 -07:00
|
|
|
IImage* COGLES2Driver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2011-06-09 01:47:45 -07:00
|
|
|
if (target==video::ERT_MULTI_RENDER_TEXTURES || target==video::ERT_RENDER_TEXTURE || target==video::ERT_STEREO_BOTH_BUFFERS)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-09 07:52:15 -07:00
|
|
|
GLint internalformat = GL_RGBA;
|
|
|
|
GLint type = GL_UNSIGNED_BYTE;
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
2011-06-09 07:52:15 -07:00
|
|
|
// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat);
|
|
|
|
// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
|
2011-05-22 13:25:05 -07:00
|
|
|
// there's a format we don't support ATM
|
|
|
|
if (GL_UNSIGNED_SHORT_4_4_4_4 == type)
|
2011-06-09 07:52:15 -07:00
|
|
|
{
|
|
|
|
internalformat = GL_RGBA;
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
2011-05-22 13:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
IImage* newImage = 0;
|
2011-06-09 01:47:45 -07:00
|
|
|
if (GL_RGBA == internalformat)
|
2011-05-22 13:25:05 -07:00
|
|
|
{
|
|
|
|
if (GL_UNSIGNED_BYTE == type)
|
|
|
|
newImage = new CImage(ECF_A8R8G8B8, ScreenSize);
|
|
|
|
else
|
|
|
|
newImage = new CImage(ECF_A1R5G5B5, ScreenSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GL_UNSIGNED_BYTE == type)
|
|
|
|
newImage = new CImage(ECF_R8G8B8, ScreenSize);
|
|
|
|
else
|
|
|
|
newImage = new CImage(ECF_R5G6B5, ScreenSize);
|
|
|
|
}
|
|
|
|
|
2011-06-09 07:52:15 -07:00
|
|
|
if (!newImage)
|
|
|
|
return 0;
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
u8* pixels = static_cast<u8*>(newImage->lock());
|
|
|
|
if (!pixels)
|
|
|
|
{
|
2011-06-09 07:52:15 -07:00
|
|
|
newImage->unlock();
|
2011-05-22 13:25:05 -07:00
|
|
|
newImage->drop();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-09 01:47:45 -07:00
|
|
|
glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels);
|
2011-06-09 07:52:15 -07:00
|
|
|
testGLError();
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
// opengl images are horizontally flipped, so we have to fix that here.
|
|
|
|
const s32 pitch = newImage->getPitch();
|
|
|
|
u8* p2 = pixels + (ScreenSize.Height - 1) * pitch;
|
|
|
|
u8* tmpBuffer = new u8[pitch];
|
|
|
|
for (u32 i = 0; i < ScreenSize.Height; i += 2)
|
|
|
|
{
|
|
|
|
memcpy(tmpBuffer, pixels, pitch);
|
|
|
|
memcpy(pixels, p2, pitch);
|
|
|
|
memcpy(p2, tmpBuffer, pitch);
|
|
|
|
pixels += pitch;
|
|
|
|
p2 -= pitch;
|
|
|
|
}
|
|
|
|
delete [] tmpBuffer;
|
|
|
|
|
|
|
|
newImage->unlock();
|
|
|
|
|
|
|
|
if (testGLError())
|
|
|
|
{
|
|
|
|
newImage->drop();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
testGLError();
|
|
|
|
return newImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! get depth texture for the given render target texture
|
|
|
|
ITexture* COGLES2Driver::createDepthTexture(ITexture* texture, bool shared)
|
|
|
|
{
|
|
|
|
if ((texture->getDriverType() != EDT_OGLES2) || (!texture->isRenderTarget()))
|
|
|
|
return 0;
|
|
|
|
COGLES2Texture* tex = static_cast<COGLES2Texture*>(texture);
|
|
|
|
|
|
|
|
if (!tex->isFrameBufferObject())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (shared)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < DepthTextures.size(); ++i)
|
|
|
|
{
|
|
|
|
if (DepthTextures[i]->getSize() == texture->getSize())
|
|
|
|
{
|
|
|
|
DepthTextures[i]->grab();
|
|
|
|
return DepthTextures[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DepthTextures.push_back(new COGLES2FBODepthTexture(texture->getSize(), "depth1", this));
|
|
|
|
return DepthTextures.getLast();
|
|
|
|
}
|
|
|
|
return (new COGLES2FBODepthTexture(texture->getSize(), "depth1", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void COGLES2Driver::removeDepthTexture(ITexture* texture)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < DepthTextures.size(); ++i)
|
|
|
|
{
|
|
|
|
if (texture == DepthTextures[i])
|
|
|
|
{
|
|
|
|
DepthTextures.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:07:49 -07:00
|
|
|
void COGLES2Driver::removeTexture(ITexture* texture)
|
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CNullDriver::removeTexture(texture);
|
|
|
|
CurrentTexture.remove(texture);
|
|
|
|
}
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
void COGLES2Driver::deleteFramebuffers(s32 n, const u32 *framebuffers)
|
|
|
|
{
|
|
|
|
glDeleteFramebuffers(n, framebuffers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2Driver::deleteRenderbuffers(s32 n, const u32 *renderbuffers)
|
|
|
|
{
|
|
|
|
glDeleteRenderbuffers(n, renderbuffers);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Set/unset a clipping plane.
|
|
|
|
bool COGLES2Driver::setClipPlane(u32 index, const core::plane3df& plane, bool enable)
|
|
|
|
{
|
|
|
|
if (index >= UserClipPlane.size())
|
|
|
|
UserClipPlane.push_back(SUserClipPlane());
|
|
|
|
|
|
|
|
UserClipPlane[index].Plane = plane;
|
|
|
|
UserClipPlane[index].Enabled = enable;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Enable/disable a clipping plane.
|
|
|
|
void COGLES2Driver::enableClipPlane(u32 index, bool enable)
|
|
|
|
{
|
|
|
|
UserClipPlane[index].Enabled = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get the ClipPlane Count
|
|
|
|
u32 COGLES2Driver::getClipPlaneCount() const
|
|
|
|
{
|
|
|
|
return UserClipPlane.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const core::plane3df& COGLES2Driver::getClipPlane(irr::u32 index) const
|
|
|
|
{
|
|
|
|
if (index < UserClipPlane.size())
|
|
|
|
return UserClipPlane[index].Plane;
|
|
|
|
else
|
|
|
|
return *((core::plane3df*)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
core::dimension2du COGLES2Driver::getMaxTextureSize() const
|
|
|
|
{
|
|
|
|
return core::dimension2du(MaxTextureSize, MaxTextureSize);
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
GLenum COGLES2Driver::getGLBlend(E_BLEND_FACTOR factor) const
|
|
|
|
{
|
|
|
|
GLenum r = 0;
|
|
|
|
switch (factor)
|
|
|
|
{
|
|
|
|
case EBF_ZERO: r = GL_ZERO; break;
|
|
|
|
case EBF_ONE: r = GL_ONE; break;
|
|
|
|
case EBF_DST_COLOR: r = GL_DST_COLOR; break;
|
|
|
|
case EBF_ONE_MINUS_DST_COLOR: r = GL_ONE_MINUS_DST_COLOR; break;
|
|
|
|
case EBF_SRC_COLOR: r = GL_SRC_COLOR; break;
|
|
|
|
case EBF_ONE_MINUS_SRC_COLOR: r = GL_ONE_MINUS_SRC_COLOR; break;
|
|
|
|
case EBF_SRC_ALPHA: r = GL_SRC_ALPHA; break;
|
|
|
|
case EBF_ONE_MINUS_SRC_ALPHA: r = GL_ONE_MINUS_SRC_ALPHA; break;
|
|
|
|
case EBF_DST_ALPHA: r = GL_DST_ALPHA; break;
|
|
|
|
case EBF_ONE_MINUS_DST_ALPHA: r = GL_ONE_MINUS_DST_ALPHA; break;
|
|
|
|
case EBF_SRC_ALPHA_SATURATE: r = GL_SRC_ALPHA_SATURATE; break;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:54:47 -07:00
|
|
|
GLenum COGLES2Driver::getZBufferBits() const
|
|
|
|
{
|
|
|
|
/*#if defined(GL_OES_depth24)
|
|
|
|
if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_OES_depth24))
|
|
|
|
InternalFormat = GL_DEPTH_COMPONENT24_OES;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#if defined(GL_OES_depth32)
|
|
|
|
if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_OES_depth32))
|
|
|
|
InternalFormat = GL_DEPTH_COMPONENT32_OES;
|
|
|
|
else
|
|
|
|
#endif*/
|
|
|
|
|
|
|
|
GLenum bits = GL_DEPTH_COMPONENT16;//0;
|
|
|
|
/*switch (Params.ZBufferBits)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
bits = GL_DEPTH_COMPONENT16;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
bits = GL_DEPTH_COMPONENT24;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
bits = GL_DEPTH_COMPONENT32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bits = GL_DEPTH_COMPONENT;
|
|
|
|
break;
|
|
|
|
}*/
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
const SMaterial& COGLES2Driver::getCurrentMaterial() const
|
|
|
|
{
|
|
|
|
return Material;
|
|
|
|
}
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
COGLES2CallBridge* COGLES2Driver::getBridgeCalls() const
|
|
|
|
{
|
|
|
|
return BridgeCalls;
|
|
|
|
}
|
|
|
|
|
|
|
|
COGLES2CallBridge::COGLES2CallBridge(COGLES2Driver* driver) : Driver(driver),
|
2014-05-10 14:47:14 -07:00
|
|
|
BlendEquation(GL_FUNC_ADD), BlendSourceRGB(GL_ONE), BlendDestinationRGB(GL_ZERO),
|
|
|
|
BlendSourceAlpha(GL_ONE), BlendDestinationAlpha(GL_ZERO), Blend(false),
|
2013-01-14 16:31:37 -08:00
|
|
|
CullFaceMode(GL_BACK), CullFace(false),
|
|
|
|
DepthFunc(GL_LESS), DepthMask(true), DepthTest(false),
|
2013-03-19 08:54:47 -07:00
|
|
|
Program(0), ActiveTexture(GL_TEXTURE0), Viewport(core::rect<s32>(0, 0, 0, 0))
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
// Initial OpenGL values from specification.
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
for (u32 i = 0; i < 4; ++i)
|
|
|
|
ColorMask[i] = true;
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
|
2013-11-18 17:05:49 -08:00
|
|
|
{
|
2013-01-14 16:31:37 -08:00
|
|
|
Texture[i] = 0;
|
2013-11-18 17:05:49 -08:00
|
|
|
TextureType[i] = GL_TEXTURE_2D;
|
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
|
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glDisable(GL_CULL_FACE);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
|
2014-05-10 14:47:14 -07:00
|
|
|
void COGLES2CallBridge::setBlendEquation(GLenum mode)
|
|
|
|
{
|
|
|
|
if (BlendEquation != mode)
|
|
|
|
{
|
|
|
|
glBlendEquation(mode);
|
|
|
|
|
|
|
|
BlendEquation = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
void COGLES2CallBridge::setBlendFunc(GLenum source, GLenum destination)
|
|
|
|
{
|
2014-05-10 14:47:14 -07:00
|
|
|
if (BlendSourceRGB != source || BlendDestinationRGB != destination ||
|
|
|
|
BlendSourceAlpha != source || BlendDestinationAlpha != destination)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
glBlendFunc(source, destination);
|
|
|
|
|
2014-05-10 14:47:14 -07:00
|
|
|
BlendSourceRGB = source;
|
|
|
|
BlendDestinationRGB = destination;
|
|
|
|
BlendSourceAlpha = source;
|
|
|
|
BlendDestinationAlpha = destination;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2CallBridge::setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
|
|
|
|
{
|
|
|
|
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
|
|
|
|
{
|
|
|
|
if (BlendSourceRGB != sourceRGB || BlendDestinationRGB != destinationRGB ||
|
|
|
|
BlendSourceAlpha != sourceAlpha || BlendDestinationAlpha != destinationAlpha)
|
|
|
|
{
|
|
|
|
glBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
|
|
|
|
|
|
|
|
BlendSourceRGB = sourceRGB;
|
|
|
|
BlendDestinationRGB = destinationRGB;
|
|
|
|
BlendSourceAlpha = sourceAlpha;
|
|
|
|
BlendDestinationAlpha = destinationAlpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setBlendFunc(sourceRGB, destinationRGB);
|
2013-01-14 16:31:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2CallBridge::setBlend(bool enable)
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (Blend != enable)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
else
|
|
|
|
glDisable(GL_BLEND);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
Blend = enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 14:45:38 -07:00
|
|
|
void COGLES2CallBridge::setColorMask(bool red, bool green, bool blue, bool alpha)
|
|
|
|
{
|
|
|
|
if (ColorMask[0] != red || ColorMask[1] != green || ColorMask[2] != blue || ColorMask[3] != alpha)
|
|
|
|
{
|
|
|
|
glColorMask(red, green, blue, alpha);
|
|
|
|
|
|
|
|
ColorMask[0] = red;
|
|
|
|
ColorMask[1] = green;
|
|
|
|
ColorMask[2] = blue;
|
|
|
|
ColorMask[3] = alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
void COGLES2CallBridge::setCullFaceFunc(GLenum mode)
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (CullFaceMode != mode)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
glCullFace(mode);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
CullFaceMode = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2CallBridge::setCullFace(bool enable)
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (CullFace != enable)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
else
|
|
|
|
glDisable(GL_CULL_FACE);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
CullFace = enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2CallBridge::setDepthFunc(GLenum mode)
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (DepthFunc != mode)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
glDepthFunc(mode);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
DepthFunc = mode;
|
|
|
|
}
|
|
|
|
}
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
void COGLES2CallBridge::setDepthMask(bool enable)
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (DepthMask != enable)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
else
|
|
|
|
glDepthMask(GL_FALSE);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
DepthMask = enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2CallBridge::setDepthTest(bool enable)
|
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (DepthTest != enable)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
else
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
DepthTest = enable;
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 11:23:46 -08:00
|
|
|
|
|
|
|
void COGLES2CallBridge::setProgram(GLuint program)
|
|
|
|
{
|
|
|
|
if (Program != program)
|
|
|
|
{
|
|
|
|
glUseProgram(program);
|
|
|
|
Program = program;
|
|
|
|
}
|
|
|
|
}
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2014-05-22 10:07:49 -07:00
|
|
|
void COGLES2CallBridge::resetTexture(const ITexture* texture)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
|
|
|
|
{
|
|
|
|
if (Texture[i] == texture)
|
|
|
|
{
|
|
|
|
setActiveTexture(GL_TEXTURE0 + i);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
Texture[i] = 0;
|
|
|
|
TextureType[i] = GL_TEXTURE_2D;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:31:37 -08:00
|
|
|
void COGLES2CallBridge::setActiveTexture(GLenum texture)
|
|
|
|
{
|
|
|
|
if (ActiveTexture != texture)
|
|
|
|
{
|
|
|
|
glActiveTexture(texture);
|
|
|
|
ActiveTexture = texture;
|
|
|
|
}
|
|
|
|
}
|
2013-05-03 08:24:12 -07:00
|
|
|
|
2013-11-18 17:05:49 -08:00
|
|
|
void COGLES2CallBridge::getTexture(u32 stage, GLenum& type)
|
|
|
|
{
|
|
|
|
if (stage < MATERIAL_MAX_TEXTURES)
|
|
|
|
type = TextureType[stage];
|
|
|
|
}
|
|
|
|
|
|
|
|
void COGLES2CallBridge::setTexture(u32 stage, GLenum type)
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
|
|
|
if (stage < MATERIAL_MAX_TEXTURES)
|
|
|
|
{
|
2014-12-08 09:34:34 -08:00
|
|
|
setActiveTexture(GL_TEXTURE0 + stage);
|
|
|
|
|
2013-05-03 08:24:12 -07:00
|
|
|
if (Texture[stage] != Driver->CurrentTexture[stage])
|
2013-01-14 16:31:37 -08:00
|
|
|
{
|
2013-05-03 08:24:12 -07:00
|
|
|
if (Driver->CurrentTexture[stage])
|
2014-10-02 11:22:36 -07:00
|
|
|
{
|
2013-11-18 17:05:49 -08:00
|
|
|
glBindTexture(type, static_cast<const COGLES2Texture*>(Driver->CurrentTexture[stage])->getOpenGLTextureName());
|
2014-10-02 11:22:36 -07:00
|
|
|
|
|
|
|
TextureType[stage] = type;
|
|
|
|
}
|
2013-08-02 16:20:06 -07:00
|
|
|
else
|
2014-10-02 11:22:36 -07:00
|
|
|
{
|
|
|
|
glBindTexture(TextureType[stage], 0);
|
|
|
|
}
|
2013-01-14 16:31:37 -08:00
|
|
|
|
|
|
|
Texture[stage] = Driver->CurrentTexture[stage];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 10:26:18 -08:00
|
|
|
const core::rect<s32>& COGLES2CallBridge::getViewport() const
|
|
|
|
{
|
|
|
|
return Viewport;
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:54:47 -07:00
|
|
|
void COGLES2CallBridge::setViewport(const core::rect<s32>& viewport)
|
|
|
|
{
|
|
|
|
if (Viewport != viewport)
|
|
|
|
{
|
|
|
|
glViewport(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y);
|
|
|
|
Viewport = viewport;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_OGLES2_
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
#ifndef _IRR_COMPILE_WITH_OGLES2_
|
2013-10-26 05:13:26 -07:00
|
|
|
class IContextManager;
|
2010-08-08 10:46:48 -07:00
|
|
|
#endif
|
|
|
|
|
2013-10-20 13:38:20 -07:00
|
|
|
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params,
|
2013-11-13 15:20:30 -08:00
|
|
|
io::IFileSystem* io
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
, IContextManager* contextManager
|
2013-10-20 13:38:20 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
, CIrrDeviceIPhone* device
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2010-08-08 10:46:48 -07:00
|
|
|
#ifdef _IRR_COMPILE_WITH_OGLES2_
|
2013-11-13 15:20:30 -08:00
|
|
|
return new COGLES2Driver(params, io
|
2014-04-17 11:22:01 -07:00
|
|
|
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
|
2013-10-26 05:13:26 -07:00
|
|
|
, contextManager
|
2013-10-20 13:38:20 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
|
|
|
|
, device
|
|
|
|
#endif
|
|
|
|
);
|
2010-08-08 10:46:48 -07:00
|
|
|
#else
|
2013-10-20 13:38:20 -07:00
|
|
|
return 0;
|
|
|
|
#endif // _IRR_COMPILE_WITH_OGLES2_
|
|
|
|
}
|
2010-08-08 10:46:48 -07:00
|
|
|
|
2011-05-22 13:25:05 -07:00
|
|
|
} // end namespace
|
2010-08-08 10:46:48 -07:00
|
|
|
} // end namespace
|