2023-10-03 20:37:00 +02:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "COpenGLDriver.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include "CNullDriver.h"
|
|
|
|
#include "IContextManager.h"
|
|
|
|
|
|
|
|
#ifdef _IRR_COMPILE_WITH_OPENGL_
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
#include "COpenGLCacheHandler.h"
|
|
|
|
#include "COpenGLMaterialRenderer.h"
|
|
|
|
#include "COpenGLSLMaterialRenderer.h"
|
|
|
|
|
|
|
|
#include "COpenGLCoreTexture.h"
|
|
|
|
#include "COpenGLCoreRenderTarget.h"
|
|
|
|
|
|
|
|
#include "mt_opengl.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
|
|
|
|
|
|
|
// Statics variables
|
2024-03-20 19:35:52 +01:00
|
|
|
const u16 COpenGLDriver::Quad2DIndices[4] = {0, 1, 2, 3};
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) :
|
|
|
|
CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
|
|
|
|
Transformation3DChanged(true), AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE), Params(params),
|
|
|
|
ContextManager(contextManager)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("COpenGLDriver");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COpenGLDriver::initDriver()
|
|
|
|
{
|
|
|
|
ContextManager->generateSurface();
|
|
|
|
ContextManager->generateContext();
|
|
|
|
ExposedData = ContextManager->getContext();
|
|
|
|
ContextManager->activateContext(ExposedData, false);
|
2024-01-16 20:17:33 +01:00
|
|
|
GL.LoadAllProcedures(ContextManager);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
genericDriverInit();
|
|
|
|
|
2024-01-16 19:42:21 +01:00
|
|
|
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlSwapInterval(Params.Vsync ? 1 : 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
COpenGLDriver::~COpenGLDriver()
|
|
|
|
{
|
|
|
|
deleteMaterialRenders();
|
|
|
|
|
|
|
|
CacheHandler->getTextureCache().clear();
|
|
|
|
// I get a blue screen on my laptop, when I do not delete the
|
|
|
|
// textures manually before releasing the dc. Oh how I love this.
|
|
|
|
removeAllRenderTargets();
|
|
|
|
deleteAllTextures();
|
|
|
|
removeAllOcclusionQueries();
|
|
|
|
removeAllHardwareBuffers();
|
|
|
|
|
|
|
|
delete CacheHandler;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (ContextManager) {
|
2023-10-03 20:37:00 +02:00
|
|
|
ContextManager->destroyContext();
|
|
|
|
ContextManager->destroySurface();
|
|
|
|
ContextManager->terminate();
|
|
|
|
ContextManager->drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// METHODS
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool COpenGLDriver::genericDriverInit()
|
|
|
|
{
|
|
|
|
if (ContextManager)
|
|
|
|
ContextManager->grab();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
Name = "OpenGL ";
|
2023-10-03 20:37:00 +02:00
|
|
|
Name.append(glGetString(GL_VERSION));
|
2024-03-20 19:35:52 +01:00
|
|
|
s32 pos = Name.findNext(' ', 7);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (pos != -1)
|
2024-03-20 19:35:52 +01:00
|
|
|
Name = Name.subString(0, pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
printVersion();
|
|
|
|
|
|
|
|
// print renderer information
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLubyte *renderer = glGetString(GL_RENDERER);
|
|
|
|
const GLubyte *vendor = glGetString(GL_VENDOR);
|
|
|
|
if (renderer && vendor) {
|
|
|
|
os::Printer::log(reinterpret_cast<const c8 *>(renderer), reinterpret_cast<const c8 *>(vendor), ELL_INFORMATION);
|
|
|
|
VendorName = reinterpret_cast<const c8 *>(vendor);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
// load extensions
|
2024-02-17 00:30:32 +01:00
|
|
|
initExtensions(ContextManager, Params.Stencilbuffer);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// reset cache handler
|
|
|
|
delete CacheHandler;
|
|
|
|
CacheHandler = new COpenGLCacheHandler(this);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryFeature(EVDF_ARB_GLSL)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
char buf[32];
|
2024-03-20 19:35:52 +01:00
|
|
|
const u32 maj = ShaderLanguageVersion / 100;
|
|
|
|
snprintf_irr(buf, 32, "%u.%u", maj, ShaderLanguageVersion - maj * 100);
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("GLSL version", buf, ELL_INFORMATION);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("GLSL not available.", ELL_INFORMATION);
|
|
|
|
DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits);
|
|
|
|
DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits);
|
|
|
|
DriverAttributes->setAttribute("MaxLights", MaxLights);
|
|
|
|
DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy);
|
|
|
|
DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes);
|
|
|
|
DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers);
|
|
|
|
DriverAttributes->setAttribute("MaxMultipleRenderTargets", (s32)Feature.MultipleRenderTarget);
|
|
|
|
DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices);
|
|
|
|
DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize);
|
|
|
|
DriverAttributes->setAttribute("MaxGeometryVerticesOut", (s32)MaxGeometryVerticesOut);
|
|
|
|
DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias);
|
|
|
|
DriverAttributes->setAttribute("Version", Version);
|
|
|
|
DriverAttributes->setAttribute("ShaderLanguageVersion", ShaderLanguageVersion);
|
|
|
|
DriverAttributes->setAttribute("AntiAlias", AntiAlias);
|
|
|
|
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
|
|
|
|
|
|
UserClipPlanes.reallocate(MaxUserClipPlanes);
|
2024-03-20 19:35:52 +01:00
|
|
|
for (i = 0; i < MaxUserClipPlanes; ++i)
|
2023-10-03 20:37:00 +02:00
|
|
|
UserClipPlanes.push_back(SUserClipPlane());
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
for (i = 0; i < ETS_COUNT; ++i)
|
2023-10-03 20:37:00 +02:00
|
|
|
setTransform(static_cast<E_TRANSFORMATION_STATE>(i), core::IdentityMatrix);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f));
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_EXT_separate_specular_color
|
|
|
|
if (FeatureAvailable[IRR_EXT_separate_specular_color])
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
|
|
|
#endif
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// This is a fast replacement for NORMALIZE_NORMALS
|
|
|
|
// if ((Version>101) || FeatureAvailable[IRR_EXT_rescale_normal])
|
|
|
|
// glEnable(GL_RESCALE_NORMAL_EXT);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
glClearDepth(1.0);
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
|
|
glFrontFace(GL_CW);
|
|
|
|
// adjust flat coloring scheme to DirectX version
|
|
|
|
#if defined(GL_ARB_provoking_vertex) || defined(GL_EXT_provoking_vertex)
|
|
|
|
extGlProvokingVertex(GL_FIRST_VERTEX_CONVENTION_EXT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Create built-in 2D quad for 2D rendering (both quads and lines).
|
2024-03-20 19:35:52 +01:00
|
|
|
Quad2DVertices[0] = S3DVertex(core::vector3df(-1.0f, 1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(0.0f, 1.0f));
|
|
|
|
Quad2DVertices[1] = S3DVertex(core::vector3df(1.0f, 1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(1.0f, 1.0f));
|
|
|
|
Quad2DVertices[2] = S3DVertex(core::vector3df(1.0f, -1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(1.0f, 0.0f));
|
|
|
|
Quad2DVertices[3] = S3DVertex(core::vector3df(-1.0f, -1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(0.0f, 0.0f));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// create material renderers
|
|
|
|
createMaterialRenderers();
|
|
|
|
|
|
|
|
// set the renderstates
|
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
// set fog mode
|
|
|
|
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
|
|
|
|
|
|
|
|
// create matrix for flipping textures
|
2024-03-20 19:35:52 +01:00
|
|
|
TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::createMaterialRenderers()
|
|
|
|
{
|
|
|
|
addAndDropMaterialRenderer(new COpenGLMaterialRenderer_SOLID(this));
|
|
|
|
addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(this));
|
|
|
|
addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(this));
|
|
|
|
addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA(this));
|
|
|
|
addAndDropMaterialRenderer(new COpenGLMaterialRenderer_ONETEXTURE_BLEND(this));
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData &videoData, core::rect<s32> *sourceRect)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect);
|
|
|
|
|
|
|
|
if (ContextManager)
|
|
|
|
ContextManager->activateContext(videoData, true);
|
|
|
|
|
|
|
|
clearBuffers(clearFlag, clearColor, clearDepth, clearStencil);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COpenGLDriver::endScene()
|
|
|
|
{
|
|
|
|
CNullDriver::endScene();
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
|
|
|
|
bool status = false;
|
|
|
|
|
|
|
|
if (ContextManager)
|
|
|
|
status = ContextManager->swapBuffers();
|
|
|
|
|
|
|
|
// todo: console device present
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns the transformation set by setTransform
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::matrix4 &COpenGLDriver::getTransform(E_TRANSFORMATION_STATE state) const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return Matrices[state];
|
|
|
|
}
|
|
|
|
|
|
|
|
//! sets transformation
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
Matrices[state] = mat;
|
|
|
|
Transformation3DChanged = true;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (state) {
|
2023-10-03 20:37:00 +02:00
|
|
|
case ETS_VIEW:
|
2024-03-20 19:35:52 +01:00
|
|
|
case ETS_WORLD: {
|
|
|
|
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
|
|
|
|
CacheHandler->setMatrixMode(GL_MODELVIEW);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// first load the viewing transformation for user clip planes
|
|
|
|
glLoadMatrixf((Matrices[ETS_VIEW]).pointer());
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// we have to update the clip planes to the latest view matrix
|
|
|
|
for (u32 i = 0; i < MaxUserClipPlanes; ++i)
|
|
|
|
if (UserClipPlanes[i].Enabled)
|
|
|
|
uploadClipPlane(i);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// now the real model-view matrix
|
|
|
|
glMultMatrixf(Matrices[ETS_WORLD].pointer());
|
|
|
|
} break;
|
|
|
|
case ETS_PROJECTION: {
|
|
|
|
CacheHandler->setMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixf(mat.pointer());
|
|
|
|
} break;
|
2023-10-03 20:37:00 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
|
|
|
|
{
|
|
|
|
if (!HWBuffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_buffer_object])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#if defined(GL_ARB_vertex_buffer_object)
|
2024-03-20 19:35:52 +01:00
|
|
|
const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer;
|
|
|
|
const void *vertices = mb->getVertices();
|
|
|
|
const u32 vertexCount = mb->getVertexCount();
|
|
|
|
const E_VERTEX_TYPE vType = mb->getVertexType();
|
2023-10-03 20:37:00 +02:00
|
|
|
const u32 vertexSize = getVertexPitchFromType(vType);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const c8 *vbuf = static_cast<const c8 *>(vertices);
|
2023-10-03 20:37:00 +02:00
|
|
|
core::array<c8> buffer;
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) {
|
|
|
|
// buffer vertex data, and convert colors...
|
2023-10-03 20:37:00 +02:00
|
|
|
buffer.set_used(vertexSize * vertexCount);
|
|
|
|
memcpy(buffer.pointer(), vertices, vertexSize * vertexCount);
|
|
|
|
vbuf = buffer.const_pointer();
|
|
|
|
|
|
|
|
// in order to convert the colors into opengl format (RGBA)
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (vType) {
|
|
|
|
case EVT_STANDARD: {
|
|
|
|
S3DVertex *pb = reinterpret_cast<S3DVertex *>(buffer.pointer());
|
|
|
|
const S3DVertex *po = static_cast<const S3DVertex *>(vertices);
|
|
|
|
for (u32 i = 0; i < vertexCount; i++) {
|
|
|
|
po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} break;
|
|
|
|
case EVT_2TCOORDS: {
|
|
|
|
S3DVertex2TCoords *pb = reinterpret_cast<S3DVertex2TCoords *>(buffer.pointer());
|
|
|
|
const S3DVertex2TCoords *po = static_cast<const S3DVertex2TCoords *>(vertices);
|
|
|
|
for (u32 i = 0; i < vertexCount; i++) {
|
|
|
|
po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} break;
|
|
|
|
case EVT_TANGENTS: {
|
|
|
|
S3DVertexTangents *pb = reinterpret_cast<S3DVertexTangents *>(buffer.pointer());
|
|
|
|
const S3DVertexTangents *po = static_cast<const S3DVertexTangents *>(vertices);
|
|
|
|
for (u32 i = 0; i < vertexCount; i++) {
|
|
|
|
po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// get or create buffer
|
|
|
|
bool newBuffer = false;
|
|
|
|
if (!HWBuffer->vbo_verticesID) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlGenBuffers(1, &HWBuffer->vbo_verticesID);
|
|
|
|
if (!HWBuffer->vbo_verticesID)
|
|
|
|
return false;
|
2024-03-20 19:35:52 +01:00
|
|
|
newBuffer = true;
|
|
|
|
} else if (HWBuffer->vbo_verticesSize < vertexCount * vertexSize) {
|
|
|
|
newBuffer = true;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extGlBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID);
|
|
|
|
|
|
|
|
// copy data to graphics card
|
|
|
|
if (!newBuffer)
|
|
|
|
extGlBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, vbuf);
|
2024-03-20 19:35:52 +01:00
|
|
|
else {
|
|
|
|
HWBuffer->vbo_verticesSize = vertexCount * vertexSize;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_STATIC_DRAW);
|
2024-03-20 19:35:52 +01:00
|
|
|
else if (HWBuffer->Mapped_Vertex == scene::EHM_DYNAMIC)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_DYNAMIC_DRAW);
|
2024-03-20 19:35:52 +01:00
|
|
|
else // scene::EHM_STREAM
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_STREAM_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
extGlBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
return (!testGLError(__LINE__));
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
|
|
|
|
{
|
|
|
|
if (!HWBuffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_buffer_object])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#if defined(GL_ARB_vertex_buffer_object)
|
2024-03-20 19:35:52 +01:00
|
|
|
const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const void *indices = mb->getIndices();
|
|
|
|
u32 indexCount = mb->getIndexCount();
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
GLenum indexSize;
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (mb->getIndexType()) {
|
|
|
|
case EIT_16BIT: {
|
|
|
|
indexSize = sizeof(u16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EIT_32BIT: {
|
|
|
|
indexSize = sizeof(u32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// get or create buffer
|
|
|
|
bool newBuffer = false;
|
|
|
|
if (!HWBuffer->vbo_indicesID) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlGenBuffers(1, &HWBuffer->vbo_indicesID);
|
|
|
|
if (!HWBuffer->vbo_indicesID)
|
|
|
|
return false;
|
2024-03-20 19:35:52 +01:00
|
|
|
newBuffer = true;
|
|
|
|
} else if (HWBuffer->vbo_indicesSize < indexCount * indexSize) {
|
|
|
|
newBuffer = true;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID);
|
|
|
|
|
|
|
|
// copy data to graphics card
|
|
|
|
if (!newBuffer)
|
|
|
|
extGlBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices);
|
2024-03-20 19:35:52 +01:00
|
|
|
else {
|
|
|
|
HWBuffer->vbo_indicesSize = indexCount * indexSize;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Index == scene::EHM_STATIC)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW);
|
2024-03-20 19:35:52 +01:00
|
|
|
else if (HWBuffer->Mapped_Index == scene::EHM_DYNAMIC)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW);
|
2024-03-20 19:35:52 +01:00
|
|
|
else // scene::EHM_STREAM
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STREAM_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
return (!testGLError(__LINE__));
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//! updates hardware buffer if needed
|
|
|
|
bool COpenGLDriver::updateHardwareBuffer(SHWBufferLink *HWBuffer)
|
|
|
|
{
|
|
|
|
if (!HWBuffer)
|
|
|
|
return false;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) {
|
|
|
|
if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex() || !((SHWBufferLink_opengl *)HWBuffer)->vbo_verticesID) {
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!updateVertexHardwareBuffer((SHWBufferLink_opengl *)HWBuffer))
|
2023-10-03 20:37:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Index != scene::EHM_NEVER) {
|
|
|
|
if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() || !((SHWBufferLink_opengl *)HWBuffer)->vbo_indicesID) {
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!updateIndexHardwareBuffer((SHWBufferLink_opengl *)HWBuffer))
|
2023-10-03 20:37:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Create hardware buffer from meshbuffer
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::IMeshBuffer *mb)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
#if defined(GL_ARB_vertex_buffer_object)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER))
|
2023-10-03 20:37:00 +02:00
|
|
|
return 0;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// add to map
|
2023-10-03 20:37:00 +02:00
|
|
|
HWBuffer->listPosition = HWBufferList.insert(HWBufferList.end(), HWBuffer);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
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->vbo_verticesID = 0;
|
|
|
|
HWBuffer->vbo_indicesID = 0;
|
|
|
|
HWBuffer->vbo_verticesSize = 0;
|
|
|
|
HWBuffer->vbo_indicesSize = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!updateHardwareBuffer(HWBuffer)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
deleteHardwareBuffer(HWBuffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HWBuffer;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer)
|
|
|
|
{
|
|
|
|
if (!_HWBuffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if defined(GL_ARB_vertex_buffer_object)
|
2024-03-20 19:35:52 +01:00
|
|
|
SHWBufferLink_opengl *HWBuffer = (SHWBufferLink_opengl *)_HWBuffer;
|
|
|
|
if (HWBuffer->vbo_verticesID) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlDeleteBuffers(1, &HWBuffer->vbo_verticesID);
|
2024-03-20 19:35:52 +01:00
|
|
|
HWBuffer->vbo_verticesID = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->vbo_indicesID) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlDeleteBuffers(1, &HWBuffer->vbo_indicesID);
|
2024-03-20 19:35:52 +01:00
|
|
|
HWBuffer->vbo_indicesID = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CNullDriver::deleteHardwareBuffer(_HWBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Draw hardware buffer
|
|
|
|
void COpenGLDriver::drawHardwareBuffer(SHWBufferLink *_HWBuffer)
|
|
|
|
{
|
|
|
|
if (!_HWBuffer)
|
|
|
|
return;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
updateHardwareBuffer(_HWBuffer); // check if update is needed
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#if defined(GL_ARB_vertex_buffer_object)
|
2024-03-20 19:35:52 +01:00
|
|
|
SHWBufferLink_opengl *HWBuffer = (SHWBufferLink_opengl *)_HWBuffer;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer;
|
|
|
|
const void *vertices = mb->getVertices();
|
|
|
|
const void *indexList = mb->getIndices();
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID);
|
2024-03-20 19:35:52 +01:00
|
|
|
vertices = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Index != scene::EHM_NEVER) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID);
|
2024-03-20 19:35:52 +01:00
|
|
|
indexList = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType());
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBindBuffer(GL_ARRAY_BUFFER, 0);
|
2024-03-20 19:35:52 +01:00
|
|
|
if (HWBuffer->Mapped_Index != scene::EHM_NEVER)
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Create occlusion query.
|
|
|
|
/** Use node for identification and mesh for occlusion test. */
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::addOcclusionQuery(scene::ISceneNode *node,
|
|
|
|
const scene::IMesh *mesh)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (!queryFeature(EVDF_OCCLUSION_QUERY))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CNullDriver::addOcclusionQuery(node, mesh);
|
|
|
|
const s32 index = OcclusionQueries.linear_search(SOccQuery(node));
|
|
|
|
if ((index != -1) && (OcclusionQueries[index].UID == 0))
|
2024-03-20 19:35:52 +01:00
|
|
|
extGlGenQueries(1, reinterpret_cast<GLuint *>(&OcclusionQueries[index].UID));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Remove occlusion query.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::removeOcclusionQuery(scene::ISceneNode *node)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
const s32 index = OcclusionQueries.linear_search(SOccQuery(node));
|
2024-03-20 19:35:52 +01:00
|
|
|
if (index != -1) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (OcclusionQueries[index].UID != 0)
|
2024-03-20 19:35:52 +01:00
|
|
|
extGlDeleteQueries(1, reinterpret_cast<GLuint *>(&OcclusionQueries[index].UID));
|
2023-10-03 20:37:00 +02:00
|
|
|
CNullDriver::removeOcclusionQuery(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Run occlusion query. Draws mesh stored in query.
|
|
|
|
/** If the mesh shall not be rendered visible, use
|
|
|
|
overrideMaterial to disable the color and depth buffer. */
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::runOcclusionQuery(scene::ISceneNode *node, bool visible)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const s32 index = OcclusionQueries.linear_search(SOccQuery(node));
|
2024-03-20 19:35:52 +01:00
|
|
|
if (index != -1) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (OcclusionQueries[index].UID)
|
|
|
|
extGlBeginQuery(
|
|
|
|
#ifdef GL_ARB_occlusion_query
|
2024-03-20 19:35:52 +01:00
|
|
|
GL_SAMPLES_PASSED_ARB,
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
0,
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
OcclusionQueries[index].UID);
|
|
|
|
CNullDriver::runOcclusionQuery(node, visible);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (OcclusionQueries[index].UID)
|
|
|
|
extGlEndQuery(
|
|
|
|
#ifdef GL_ARB_occlusion_query
|
2024-03-20 19:35:52 +01:00
|
|
|
GL_SAMPLES_PASSED_ARB);
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
0);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
testGLError(__LINE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Update occlusion query. Retrieves results from GPU.
|
|
|
|
/** If the query shall not block, set the flag to false.
|
|
|
|
Update might not occur in this case, though */
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::updateOcclusionQuery(scene::ISceneNode *node, bool block)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
const s32 index = OcclusionQueries.linear_search(SOccQuery(node));
|
2024-03-20 19:35:52 +01:00
|
|
|
if (index != -1) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// not yet started
|
2024-03-20 19:35:52 +01:00
|
|
|
if (OcclusionQueries[index].Run == u32(~0))
|
2023-10-03 20:37:00 +02:00
|
|
|
return;
|
2024-03-20 19:35:52 +01:00
|
|
|
GLint available = block ? GL_TRUE : GL_FALSE;
|
|
|
|
if (!block) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlGetQueryObjectiv(OcclusionQueries[index].UID,
|
|
|
|
#ifdef GL_ARB_occlusion_query
|
2024-03-20 19:35:52 +01:00
|
|
|
GL_QUERY_RESULT_AVAILABLE_ARB,
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_NV_occlusion_query)
|
2024-03-20 19:35:52 +01:00
|
|
|
GL_PIXEL_COUNT_AVAILABLE_NV,
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
0,
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
&available);
|
2023-10-03 20:37:00 +02:00
|
|
|
testGLError(__LINE__);
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if (available == GL_TRUE) {
|
2023-10-03 20:37:00 +02:00
|
|
|
extGlGetQueryObjectiv(OcclusionQueries[index].UID,
|
|
|
|
#ifdef GL_ARB_occlusion_query
|
2024-03-20 19:35:52 +01:00
|
|
|
GL_QUERY_RESULT_ARB,
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_NV_occlusion_query)
|
2024-03-20 19:35:52 +01:00
|
|
|
GL_PIXEL_COUNT_NV,
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
0,
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
&available);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (queryFeature(EVDF_OCCLUSION_QUERY))
|
|
|
|
OcclusionQueries[index].Result = available;
|
|
|
|
}
|
|
|
|
testGLError(__LINE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Return query result.
|
|
|
|
/** Return value is the number of visible pixels/fragments.
|
|
|
|
The value is a safe approximation, i.e. can be larger than the
|
|
|
|
actual value of pixels. */
|
2024-03-20 19:35:52 +01:00
|
|
|
u32 COpenGLDriver::getOcclusionQueryResult(scene::ISceneNode *node) const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
const s32 index = OcclusionQueries.linear_search(SOccQuery(node));
|
|
|
|
if (index != -1)
|
|
|
|
return OcclusionQueries[index].Result;
|
|
|
|
else
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Create render target.
|
2024-03-20 19:35:52 +01:00
|
|
|
IRenderTarget *COpenGLDriver::addRenderTarget()
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLRenderTarget *renderTarget = new COpenGLRenderTarget(this);
|
2023-10-03 20:37:00 +02:00
|
|
|
RenderTargets.push_back(renderTarget);
|
|
|
|
|
|
|
|
return renderTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
// small helper function to create vertex buffer object address offsets
|
2024-03-20 19:35:52 +01:00
|
|
|
static inline const GLvoid *buffer_offset(const size_t offset)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return (const GLvoid *)offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! draws a vertex primitive list
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::drawVertexPrimitiveList(const void *vertices, u32 vertexCount,
|
|
|
|
const void *indexList, u32 primitiveCount,
|
2023-10-03 20:37:00 +02:00
|
|
|
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
|
|
|
|
{
|
|
|
|
if (!primitiveCount || !vertexCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!checkPrimitiveCount(primitiveCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType);
|
|
|
|
|
|
|
|
if (vertices && !FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(vertices, vertexCount, vType);
|
|
|
|
|
|
|
|
// draw everything
|
|
|
|
setRenderStates3DMode();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if ((pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES))
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setClientState(true, true, true, true);
|
|
|
|
else
|
|
|
|
CacheHandler->setClientState(true, false, true, false);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// due to missing defines in OSX headers, we have to be more specific with this check
|
|
|
|
// #if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
if (vertices) {
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) {
|
|
|
|
switch (vType) {
|
|
|
|
case EVT_STANDARD:
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].Color);
|
|
|
|
break;
|
|
|
|
case EVT_2TCOORDS:
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].Color);
|
|
|
|
break;
|
|
|
|
case EVT_TANGENTS:
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Color);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
// avoid passing broken pointer to OpenGL
|
2024-03-20 19:35:52 +01:00
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (vType) {
|
|
|
|
case EVT_STANDARD:
|
|
|
|
if (vertices) {
|
|
|
|
glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].Normal);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].TCoords);
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].Pos);
|
|
|
|
} else {
|
|
|
|
glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12));
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24));
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache()[1]) {
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (vertices)
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].TCoords);
|
2023-10-03 20:37:00 +02:00
|
|
|
else
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
|
2024-03-20 19:35:52 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVT_2TCOORDS:
|
|
|
|
if (vertices) {
|
|
|
|
glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].Normal);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].TCoords);
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].Pos);
|
|
|
|
} else {
|
|
|
|
glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12));
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24));
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28));
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Feature.MaxTextureUnits > 0) {
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (vertices)
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].TCoords2);
|
2023-10-03 20:37:00 +02:00
|
|
|
else
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVT_TANGENTS:
|
|
|
|
if (vertices) {
|
|
|
|
glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Normal);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].TCoords);
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Pos);
|
|
|
|
} else {
|
|
|
|
glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12));
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24));
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28));
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Feature.MaxTextureUnits > 0) {
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (vertices)
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Tangent);
|
2023-10-03 20:37:00 +02:00
|
|
|
else
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 2);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
if (vertices)
|
|
|
|
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Binormal);
|
|
|
|
else
|
|
|
|
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(48));
|
|
|
|
}
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderArray(indexList, primitiveCount, pType, iType);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Feature.MaxTextureUnits > 0) {
|
|
|
|
if (vType == EVT_TANGENTS) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 2);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache()[1]) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::getColorBuffer(const void *vertices, u32 vertexCount, E_VERTEX_TYPE vType)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
// convert colors to gl color format.
|
2024-03-20 19:35:52 +01:00
|
|
|
vertexCount *= 4; // reused as color component count
|
2023-10-03 20:37:00 +02:00
|
|
|
ColorBuffer.set_used(vertexCount);
|
|
|
|
u32 i;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (vType) {
|
|
|
|
case EVT_STANDARD: {
|
|
|
|
const S3DVertex *p = static_cast<const S3DVertex *>(vertices);
|
|
|
|
for (i = 0; i < vertexCount; i += 4) {
|
|
|
|
p->Color.toOpenGLColor(&ColorBuffer[i]);
|
|
|
|
++p;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} break;
|
|
|
|
case EVT_2TCOORDS: {
|
|
|
|
const S3DVertex2TCoords *p = static_cast<const S3DVertex2TCoords *>(vertices);
|
|
|
|
for (i = 0; i < vertexCount; i += 4) {
|
|
|
|
p->Color.toOpenGLColor(&ColorBuffer[i]);
|
|
|
|
++p;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} break;
|
|
|
|
case EVT_TANGENTS: {
|
|
|
|
const S3DVertexTangents *p = static_cast<const S3DVertexTangents *>(vertices);
|
|
|
|
for (i = 0; i < vertexCount; i += 4) {
|
|
|
|
p->Color.toOpenGLColor(&ColorBuffer[i]);
|
|
|
|
++p;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::renderArray(const void *indexList, u32 primitiveCount,
|
2023-10-03 20:37:00 +02:00
|
|
|
scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
GLenum indexSize = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (iType) {
|
|
|
|
case EIT_16BIT: {
|
|
|
|
indexSize = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EIT_32BIT: {
|
|
|
|
indexSize = GL_UNSIGNED_INT;
|
|
|
|
break;
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (pType) {
|
|
|
|
case scene::EPT_POINTS:
|
|
|
|
case scene::EPT_POINT_SPRITES: {
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_ARB_point_sprite
|
2024-03-20 19:35:52 +01:00
|
|
|
if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[IRR_ARB_point_sprite])
|
|
|
|
glEnable(GL_POINT_SPRITE_ARB);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// prepare size and attenuation (where supported)
|
|
|
|
GLfloat particleSize = Material.Thickness;
|
|
|
|
// if (AntiAlias)
|
|
|
|
// particleSize=core::clamp(particleSize, DimSmoothedPoint[0], DimSmoothedPoint[1]);
|
|
|
|
// else
|
|
|
|
particleSize = core::clamp(particleSize, DimAliasedPoint[0], DimAliasedPoint[1]);
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4) || defined(GL_ARB_point_parameters) || defined(GL_EXT_point_parameters) || defined(GL_SGIS_point_parameters)
|
2024-03-20 19:35:52 +01:00
|
|
|
const float att[] = {1.0f, 1.0f, 0.0f};
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
extGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att);
|
|
|
|
// extGlPointParameterf(GL_POINT_SIZE_MIN,1.f);
|
|
|
|
extGlPointParameterf(GL_POINT_SIZE_MAX, particleSize);
|
|
|
|
extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 1.0f);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_ARB_point_parameters)
|
2024-03-20 19:35:52 +01:00
|
|
|
extGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
|
|
|
|
// extGlPointParameterf(GL_POINT_SIZE_MIN_ARB,1.f);
|
|
|
|
extGlPointParameterf(GL_POINT_SIZE_MAX_ARB, particleSize);
|
|
|
|
extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0f);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_EXT_point_parameters)
|
2024-03-20 19:35:52 +01:00
|
|
|
extGlPointParameterfv(GL_DISTANCE_ATTENUATION_EXT, att);
|
|
|
|
// extGlPointParameterf(GL_POINT_SIZE_MIN_EXT,1.f);
|
|
|
|
extGlPointParameterf(GL_POINT_SIZE_MAX_EXT, particleSize);
|
|
|
|
extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1.0f);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_SGIS_point_parameters)
|
2024-03-20 19:35:52 +01:00
|
|
|
extGlPointParameterfv(GL_DISTANCE_ATTENUATION_SGIS, att);
|
|
|
|
// extGlPointParameterf(GL_POINT_SIZE_MIN_SGIS,1.f);
|
|
|
|
extGlPointParameterf(GL_POINT_SIZE_MAX_SGIS, particleSize);
|
|
|
|
extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_SGIS, 1.0f);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
glPointSize(particleSize);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_ARB_point_sprite
|
2024-03-20 19:35:52 +01:00
|
|
|
if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[IRR_ARB_point_sprite]) {
|
|
|
|
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB);
|
|
|
|
glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE, GL_TRUE);
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
glDrawArrays(GL_POINTS, 0, primitiveCount);
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_ARB_point_sprite
|
2024-03-20 19:35:52 +01:00
|
|
|
if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[IRR_ARB_point_sprite]) {
|
|
|
|
glDisable(GL_POINT_SPRITE_ARB);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB);
|
|
|
|
glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE, GL_FALSE);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
#endif
|
|
|
|
} break;
|
|
|
|
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(GL_TRIANGLES, primitiveCount * 3, indexSize, indexList);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! draws a vertex primitive list in 2d
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount,
|
|
|
|
const void *indexList, u32 primitiveCount,
|
2023-10-03 20:37:00 +02:00
|
|
|
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
|
|
|
|
{
|
|
|
|
if (!primitiveCount || !vertexCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!checkPrimitiveCount(primitiveCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CNullDriver::draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType);
|
|
|
|
|
|
|
|
if (vertices && !FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(vertices, vertexCount, vType);
|
|
|
|
|
|
|
|
// draw everything
|
|
|
|
CacheHandler->getTextureCache().set(0, Material.getTexture(0));
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Material.MaterialType == EMT_ONETEXTURE_BLEND) {
|
2023-10-03 20:37:00 +02:00
|
|
|
E_BLEND_FACTOR srcFact;
|
|
|
|
E_BLEND_FACTOR dstFact;
|
|
|
|
E_MODULATE_FUNC modulo;
|
|
|
|
u32 alphaSource;
|
2024-03-20 19:35:52 +01:00
|
|
|
unpack_textureBlendFunc(srcFact, dstFact, modulo, alphaSource, Material.MaterialTypeParam);
|
|
|
|
setRenderStates2DMode(alphaSource & video::EAS_VERTEX_COLOR, (Material.getTexture(0) != 0), (alphaSource & video::EAS_TEXTURE) != 0);
|
|
|
|
} else
|
|
|
|
setRenderStates2DMode(Material.MaterialType == EMT_TRANSPARENT_VERTEX_ALPHA, (Material.getTexture(0) != 0), Material.MaterialType == EMT_TRANSPARENT_ALPHA_CHANNEL);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if ((pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES))
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setClientState(true, false, true, true);
|
|
|
|
else
|
|
|
|
CacheHandler->setClientState(true, false, true, false);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// due to missing defines in OSX headers, we have to be more specific with this check
|
|
|
|
// #if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
if (vertices) {
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) {
|
|
|
|
switch (vType) {
|
|
|
|
case EVT_STANDARD:
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].Color);
|
|
|
|
break;
|
|
|
|
case EVT_2TCOORDS:
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].Color);
|
|
|
|
break;
|
|
|
|
case EVT_TANGENTS:
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Color);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
// avoid passing broken pointer to OpenGL
|
2024-03-20 19:35:52 +01:00
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (vType) {
|
|
|
|
case EVT_STANDARD:
|
|
|
|
if (vertices) {
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].TCoords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].Pos);
|
|
|
|
} else {
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24));
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), 0);
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache()[1]) {
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (vertices)
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(vertices))[0].TCoords);
|
2023-10-03 20:37:00 +02:00
|
|
|
else
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVT_2TCOORDS:
|
|
|
|
if (vertices) {
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].TCoords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].Pos);
|
|
|
|
} else {
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24));
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28));
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0));
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Feature.MaxTextureUnits > 0) {
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2023-10-03 20:37:00 +02:00
|
|
|
if (vertices)
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords *>(vertices))[0].TCoords2);
|
2023-10-03 20:37:00 +02:00
|
|
|
else
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVT_TANGENTS:
|
|
|
|
if (vertices) {
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].TCoords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents *>(vertices))[0].Pos);
|
|
|
|
} else {
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24));
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28));
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0));
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderArray(indexList, primitiveCount, pType, iType);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Feature.MaxTextureUnits > 0) {
|
|
|
|
if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache()[1]) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
CacheHandler->setClientActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw2DImage(const video::ITexture *texture, const core::position2d<s32> &destPos,
|
|
|
|
const core::rect<s32> &sourceRect, const core::rect<s32> *clipRect, SColor color,
|
|
|
|
bool useAlphaChannelOfTexture)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sourceRect.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// clip these coordinates
|
|
|
|
core::rect<s32> targetRect(destPos, sourceRect.getSize());
|
2024-03-20 19:35:52 +01:00
|
|
|
if (clipRect) {
|
2023-10-03 20:37:00 +02:00
|
|
|
targetRect.clipAgainst(*clipRect);
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetRect.getWidth() < 0 || targetRect.getHeight() < 0)
|
2023-10-03 20:37:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &renderTargetSize = getCurrentRenderTargetSize();
|
|
|
|
targetRect.clipAgainst(core::rect<s32>(0, 0, (s32)renderTargetSize.Width, (s32)renderTargetSize.Height));
|
|
|
|
if (targetRect.getWidth() < 0 || targetRect.getHeight() < 0)
|
|
|
|
return;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// ok, we've clipped everything.
|
|
|
|
// now draw it.
|
|
|
|
const core::dimension2d<s32> sourceSize(targetRect.getSize());
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::position2d<s32> sourcePos(sourceRect.UpperLeftCorner + (targetRect.UpperLeftCorner - destPos));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &ss = texture->getOriginalSize();
|
2023-10-03 20:37:00 +02:00
|
|
|
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(
|
2024-03-20 19:35:52 +01:00
|
|
|
sourcePos.X * invW,
|
|
|
|
sourcePos.Y * invH,
|
|
|
|
(sourcePos.X + sourceSize.Width) * invW,
|
|
|
|
(sourcePos.Y + sourceSize.Height) * invH);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
disableTextures(1);
|
|
|
|
if (!CacheHandler->getTextureCache().set(0, texture))
|
|
|
|
return;
|
2024-03-20 19:35:52 +01:00
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
Quad2DVertices[0].Color = color;
|
|
|
|
Quad2DVertices[1].Color = color;
|
|
|
|
Quad2DVertices[2].Color = color;
|
|
|
|
Quad2DVertices[3].Color = color;
|
|
|
|
|
|
|
|
Quad2DVertices[0].Pos = core::vector3df((f32)targetRect.UpperLeftCorner.X, (f32)targetRect.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[1].Pos = core::vector3df((f32)targetRect.LowerRightCorner.X, (f32)targetRect.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[2].Pos = core::vector3df((f32)targetRect.LowerRightCorner.X, (f32)targetRect.LowerRightCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[3].Pos = core::vector3df((f32)targetRect.UpperLeftCorner.X, (f32)targetRect.LowerRightCorner.Y, 0.0f);
|
|
|
|
|
|
|
|
Quad2DVertices[0].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
Quad2DVertices[1].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
Quad2DVertices[2].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
Quad2DVertices[3].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, true);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].TCoords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
|
|
|
#else
|
|
|
|
const GLint colorSize = 4;
|
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Color);
|
|
|
|
else {
|
2023-10-03 20:37:00 +02:00
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::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)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &ss = texture->getOriginalSize();
|
2023-10-03 20:37:00 +02:00
|
|
|
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(
|
2024-03-20 19:35:52 +01:00
|
|
|
sourceRect.UpperLeftCorner.X * invW,
|
|
|
|
sourceRect.UpperLeftCorner.Y * invH,
|
|
|
|
sourceRect.LowerRightCorner.X * invW,
|
|
|
|
sourceRect.LowerRightCorner.Y * invH);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-21 15:22:20 +01:00
|
|
|
const video::SColor temp[4] = {
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
};
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const video::SColor *const useColor = colors ? colors : temp;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
disableTextures(1);
|
|
|
|
if (!CacheHandler->getTextureCache().set(0, texture))
|
|
|
|
return;
|
2024-03-20 19:35:52 +01:00
|
|
|
setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 ||
|
|
|
|
useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255,
|
|
|
|
true, useAlphaChannelOfTexture);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (clipRect) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (!clipRect->isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &renderTargetSize = getCurrentRenderTargetSize();
|
2023-10-03 20:37:00 +02:00
|
|
|
glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y,
|
2024-03-20 19:35:52 +01:00
|
|
|
clipRect->getWidth(), clipRect->getHeight());
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Quad2DVertices[0].Color = useColor[0];
|
|
|
|
Quad2DVertices[1].Color = useColor[3];
|
|
|
|
Quad2DVertices[2].Color = useColor[2];
|
|
|
|
Quad2DVertices[3].Color = useColor[1];
|
|
|
|
|
|
|
|
Quad2DVertices[0].Pos = core::vector3df((f32)destRect.UpperLeftCorner.X, (f32)destRect.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[1].Pos = core::vector3df((f32)destRect.LowerRightCorner.X, (f32)destRect.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[2].Pos = core::vector3df((f32)destRect.LowerRightCorner.X, (f32)destRect.LowerRightCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[3].Pos = core::vector3df((f32)destRect.UpperLeftCorner.X, (f32)destRect.LowerRightCorner.Y, 0.0f);
|
|
|
|
|
|
|
|
Quad2DVertices[0].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
Quad2DVertices[1].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
Quad2DVertices[2].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
Quad2DVertices[3].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, true);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].TCoords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
|
|
|
#else
|
|
|
|
const GLint colorSize = 4;
|
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Color);
|
|
|
|
else {
|
2023-10-03 20:37:00 +02:00
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
|
|
|
|
if (clipRect)
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw2DImage(const video::ITexture *texture, u32 layer, bool flip)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (!texture || !CacheHandler->getTextureCache().set(0, texture))
|
|
|
|
return;
|
|
|
|
|
|
|
|
disableTextures(1);
|
|
|
|
|
|
|
|
setRenderStates2DMode(false, true, true);
|
|
|
|
|
|
|
|
CacheHandler->setMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
CacheHandler->setMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
Transformation3DChanged = true;
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, false, true);
|
|
|
|
|
|
|
|
const core::vector3df positionData[4] = {
|
2024-03-20 19:35:52 +01:00
|
|
|
core::vector3df(-1.f, 1.f, 0.f),
|
|
|
|
core::vector3df(1.f, 1.f, 0.f),
|
|
|
|
core::vector3df(1.f, -1.f, 0.f),
|
|
|
|
core::vector3df(-1.f, -1.f, 0.f)};
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(core::vector3df), positionData);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (texture && texture->getType() == ETT_CUBEMAP) {
|
2023-10-03 20:37:00 +02:00
|
|
|
const core::vector3df texcoordCubeData[6][4] = {
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// GL_TEXTURE_CUBE_MAP_POSITIVE_X
|
|
|
|
{
|
|
|
|
core::vector3df(1.f, 1.f, 1.f),
|
|
|
|
core::vector3df(1.f, 1.f, -1.f),
|
|
|
|
core::vector3df(1.f, -1.f, -1.f),
|
|
|
|
core::vector3df(1.f, -1.f, 1.f)},
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// GL_TEXTURE_CUBE_MAP_NEGATIVE_X
|
|
|
|
{
|
|
|
|
core::vector3df(-1.f, 1.f, -1.f),
|
|
|
|
core::vector3df(-1.f, 1.f, 1.f),
|
|
|
|
core::vector3df(-1.f, -1.f, 1.f),
|
|
|
|
core::vector3df(-1.f, -1.f, -1.f)},
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// GL_TEXTURE_CUBE_MAP_POSITIVE_Y
|
|
|
|
{
|
|
|
|
core::vector3df(-1.f, 1.f, -1.f),
|
|
|
|
core::vector3df(1.f, 1.f, -1.f),
|
|
|
|
core::vector3df(1.f, 1.f, 1.f),
|
|
|
|
core::vector3df(-1.f, 1.f, 1.f)},
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
|
|
|
|
{
|
|
|
|
core::vector3df(-1.f, -1.f, 1.f),
|
|
|
|
core::vector3df(-1.f, -1.f, -1.f),
|
|
|
|
core::vector3df(1.f, -1.f, -1.f),
|
|
|
|
core::vector3df(1.f, -1.f, 1.f)},
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// GL_TEXTURE_CUBE_MAP_POSITIVE_Z
|
|
|
|
{
|
|
|
|
core::vector3df(-1.f, 1.f, 1.f),
|
|
|
|
core::vector3df(-1.f, -1.f, 1.f),
|
|
|
|
core::vector3df(1.f, -1.f, 1.f),
|
|
|
|
core::vector3df(1.f, 1.f, 1.f)},
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
|
|
{
|
|
|
|
core::vector3df(1.f, 1.f, -1.f),
|
|
|
|
core::vector3df(-1.f, 1.f, -1.f),
|
|
|
|
core::vector3df(-1.f, -1.f, -1.f),
|
|
|
|
core::vector3df(1.f, -1.f, -1.f)}};
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
const core::vector3df texcoordData[4] = {
|
2024-03-20 19:35:52 +01:00
|
|
|
texcoordCubeData[layer][(flip) ? 3 : 0],
|
|
|
|
texcoordCubeData[layer][(flip) ? 2 : 1],
|
|
|
|
texcoordCubeData[layer][(flip) ? 1 : 2],
|
|
|
|
texcoordCubeData[layer][(flip) ? 0 : 3]};
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
glTexCoordPointer(3, GL_FLOAT, sizeof(core::vector3df), texcoordData);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
f32 modificator = (flip) ? 1.f : 0.f;
|
|
|
|
|
|
|
|
core::vector2df texcoordData[4] = {
|
2024-03-20 19:35:52 +01:00
|
|
|
core::vector2df(0.f, 0.f + modificator),
|
|
|
|
core::vector2df(1.f, 0.f + modificator),
|
|
|
|
core::vector2df(1.f, 1.f - modificator),
|
|
|
|
core::vector2df(0.f, 1.f - modificator)};
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(core::vector2df), texcoordData);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! draws a set of 2d images, using a color and the alpha channel of the
|
|
|
|
//! texture if desired.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::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)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const u32 drawCount = core::min_<u32>(positions.size(), sourceRects.size());
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &ss = texture->getOriginalSize();
|
2023-10-03 20:37:00 +02:00
|
|
|
const f32 invW = 1.f / static_cast<f32>(ss.Width);
|
|
|
|
const f32 invH = 1.f / static_cast<f32>(ss.Height);
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &renderTargetSize = getCurrentRenderTargetSize();
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
disableTextures(1);
|
|
|
|
if (!CacheHandler->getTextureCache().set(0, texture))
|
|
|
|
return;
|
2024-03-20 19:35:52 +01:00
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
Quad2DVertices[0].Color = color;
|
|
|
|
Quad2DVertices[1].Color = color;
|
|
|
|
Quad2DVertices[2].Color = color;
|
|
|
|
Quad2DVertices[3].Color = color;
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, true);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].TCoords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Color);
|
|
|
|
else {
|
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
for (u32 i = 0; i < drawCount; ++i) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (!sourceRects[i].isValid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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());
|
2024-03-20 19:35:52 +01:00
|
|
|
if (clipRect) {
|
|
|
|
if (targetPos.X < clipRect->UpperLeftCorner.X) {
|
2023-10-03 20:37:00 +02: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;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.Y < clipRect->UpperLeftCorner.Y) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;
|
|
|
|
targetPos.Y = clipRect->UpperLeftCorner.Y;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clip these coordinates
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.X < 0) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Width += targetPos.X;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sourcePos.X -= targetPos.X;
|
|
|
|
targetPos.X = 0;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
|
|
|
|
if (sourceSize.Width <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.Y < 0) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Height += targetPos.Y;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sourcePos.Y -= targetPos.Y;
|
|
|
|
targetPos.Y = 0;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height) {
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
|
|
|
|
if (sourceSize.Height <= 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok, we've clipped everything.
|
|
|
|
// now draw it.
|
|
|
|
|
|
|
|
const core::rect<f32> tcoords(
|
|
|
|
sourcePos.X * invW,
|
|
|
|
sourcePos.Y * invH,
|
|
|
|
(sourcePos.X + sourceSize.Width) * invW,
|
|
|
|
(sourcePos.Y + sourceSize.Height) * invH);
|
|
|
|
|
|
|
|
const core::rect<s32> poss(targetPos, sourceSize);
|
|
|
|
|
|
|
|
Quad2DVertices[0].Pos = core::vector3df((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[1].Pos = core::vector3df((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[2].Pos = core::vector3df((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[3].Pos = core::vector3df((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0.0f);
|
|
|
|
|
|
|
|
Quad2DVertices[0].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
Quad2DVertices[1].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
|
|
|
|
Quad2DVertices[2].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
Quad2DVertices[3].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! draw a 2d rectangle
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw2DRectangle(SColor color, const core::rect<s32> &position,
|
|
|
|
const core::rect<s32> *clip)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
disableTextures();
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, false, false);
|
|
|
|
|
|
|
|
core::rect<s32> pos = position;
|
|
|
|
|
|
|
|
if (clip)
|
|
|
|
pos.clipAgainst(*clip);
|
|
|
|
|
|
|
|
if (!pos.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
|
|
|
glRectf(GLfloat(pos.UpperLeftCorner.X), GLfloat(pos.UpperLeftCorner.Y),
|
2024-03-20 19:35:52 +01:00
|
|
|
GLfloat(pos.LowerRightCorner.X), GLfloat(pos.LowerRightCorner.Y));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//! draw an 2d rectangle
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw2DRectangle(const core::rect<s32> &position,
|
|
|
|
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
|
|
|
|
const core::rect<s32> *clip)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
core::rect<s32> pos = position;
|
|
|
|
|
|
|
|
if (clip)
|
|
|
|
pos.clipAgainst(*clip);
|
|
|
|
|
|
|
|
if (!pos.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
disableTextures();
|
|
|
|
|
|
|
|
setRenderStates2DMode(colorLeftUp.getAlpha() < 255 ||
|
2024-03-20 19:35:52 +01:00
|
|
|
colorRightUp.getAlpha() < 255 ||
|
|
|
|
colorLeftDown.getAlpha() < 255 ||
|
|
|
|
colorRightDown.getAlpha() < 255,
|
|
|
|
false, false);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
Quad2DVertices[0].Color = colorLeftUp;
|
|
|
|
Quad2DVertices[1].Color = colorRightUp;
|
|
|
|
Quad2DVertices[2].Color = colorRightDown;
|
|
|
|
Quad2DVertices[3].Color = colorLeftDown;
|
|
|
|
|
|
|
|
Quad2DVertices[0].Pos = core::vector3df((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[1].Pos = core::vector3df((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[2].Pos = core::vector3df((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0.0f);
|
|
|
|
Quad2DVertices[3].Pos = core::vector3df((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0.0f);
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, false);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Color);
|
|
|
|
else {
|
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Draws a 2d line.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw2DLine(const core::position2d<s32> &start,
|
|
|
|
const core::position2d<s32> &end, SColor color)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
disableTextures();
|
|
|
|
setRenderStates2DMode(color.getAlpha() < 255, false, false);
|
|
|
|
|
|
|
|
Quad2DVertices[0].Color = color;
|
|
|
|
Quad2DVertices[1].Color = color;
|
|
|
|
|
|
|
|
Quad2DVertices[0].Pos = core::vector3df((f32)start.X, (f32)start.Y, 0.0f);
|
|
|
|
Quad2DVertices[1].Pos = core::vector3df((f32)end.X, (f32)end.Y, 0.0f);
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(Quad2DVertices, 2, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, false);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Color);
|
|
|
|
else {
|
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
|
|
|
|
// Draw sometimes non-drawn first & last pixel (search for "diamond exit rule")
|
|
|
|
// HACK this messes with alpha blending
|
|
|
|
glDrawArrays(GL_POINTS, 0, 1);
|
|
|
|
glDrawArrays(GL_POINTS, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled.
|
|
|
|
//! Returns whether disabling was successful or not.
|
|
|
|
bool COpenGLDriver::disableTextures(u32 fromStage)
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
bool result = true;
|
|
|
|
for (u32 i = fromStage; i < Feature.MaxTextureUnits; ++i) {
|
2023-10-03 20:37:00 +02:00
|
|
|
result &= CacheHandler->getTextureCache().set(i, 0, EST_ACTIVE_ON_CHANGE);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! creates a matrix in supplied GLfloat array to pass to OpenGL
|
2024-03-20 19:35:52 +01:00
|
|
|
inline void COpenGLDriver::getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
memcpy(gl_matrix, m.pointer(), 16 * sizeof(f32));
|
|
|
|
}
|
|
|
|
|
|
|
|
//! creates a opengltexturematrix from a D3D style texture matrix
|
2024-03-20 19:35:52 +01:00
|
|
|
inline void COpenGLDriver::getGLTextureMatrix(GLfloat *o, const core::matrix4 &m)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
ITexture *COpenGLDriver::createDeviceDependentTexture(const io::path &name, IImage *image)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
core::array<IImage *> imageArray(1);
|
2023-10-03 20:37:00 +02:00
|
|
|
imageArray.push_back(image);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLTexture *texture = new COpenGLTexture(name, imageArray, ETT_2D, this);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
ITexture *COpenGLDriver::createDeviceDependentTextureCubemap(const io::path &name, const core::array<IImage *> &image)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLTexture *texture = new COpenGLTexture(name, image, ETT_CUBEMAP, this);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag)
|
|
|
|
{
|
|
|
|
CNullDriver::disableFeature(feature, flag);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (feature == EVDF_TEXTURE_CUBEMAP_SEAMLESS) {
|
|
|
|
if (queryFeature(feature))
|
2023-10-03 20:37:00 +02:00
|
|
|
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
|
|
|
else if (COpenGLExtensionHandler::queryFeature(feature))
|
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a material. All 3d drawing functions draw geometry now using this material.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::setMaterial(const SMaterial &material)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
Material = material;
|
|
|
|
OverrideMaterial.apply(Material);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) {
|
|
|
|
const ITexture *texture = Material.getTexture(i);
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->getTextureCache().set(i, texture, EST_ACTIVE_ON_CHANGE);
|
2024-03-20 19:35:52 +01:00
|
|
|
if (texture) {
|
2023-10-03 20:37:00 +02:00
|
|
|
setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! prints error if an error happened.
|
|
|
|
bool COpenGLDriver::testGLError(int code)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
GLenum g = glGetError();
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (g) {
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_NO_ERROR:
|
|
|
|
return false;
|
|
|
|
case GL_INVALID_ENUM:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_INVALID_VALUE:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_INVALID_OPERATION:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_STACK_OVERFLOW:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_STACK_OVERFLOW", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_STACK_UNDERFLOW:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_STACK_UNDERFLOW", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_OUT_OF_MEMORY:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
case GL_TABLE_TOO_LARGE:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_TABLE_TOO_LARGE", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_EXT_framebuffer_object)
|
|
|
|
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
|
2024-03-20 19:35:52 +01:00
|
|
|
os::Printer::log("GL_INVALID_FRAMEBUFFER_OPERATION", core::stringc(code).c_str(), ELL_ERROR);
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
};
|
2024-03-20 19:35:52 +01:00
|
|
|
// _IRR_DEBUG_BREAK_IF(true);
|
2023-10-03 20:37:00 +02:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//! sets the needed renderstates
|
|
|
|
void COpenGLDriver::setRenderStates3DMode()
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (CurrentRenderMode != ERM_3D) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// Reset Texture Stages
|
|
|
|
CacheHandler->setBlend(false);
|
|
|
|
CacheHandler->setAlphaTest(false);
|
|
|
|
CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
|
|
|
// switch back the matrices
|
|
|
|
CacheHandler->setMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
|
|
|
|
|
|
|
|
CacheHandler->setMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixf(Matrices[ETS_PROJECTION].pointer());
|
|
|
|
|
|
|
|
ResetRenderStates = true;
|
|
|
|
#ifdef GL_EXT_clip_volume_hint
|
|
|
|
if (FeatureAvailable[IRR_EXT_clip_volume_hint])
|
|
|
|
glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_NICEST);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (ResetRenderStates || LastMaterial != Material) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// unset old material
|
|
|
|
|
|
|
|
if (LastMaterial.MaterialType != Material.MaterialType &&
|
|
|
|
static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
|
|
|
|
|
|
|
|
// set new material.
|
|
|
|
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
|
2024-03-20 19:35:52 +01:00
|
|
|
Material, LastMaterial, ResetRenderStates, this);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
LastMaterial = Material;
|
|
|
|
CacheHandler->correctCacheMaterial(LastMaterial);
|
|
|
|
ResetRenderStates = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<u32>(Material.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD);
|
|
|
|
|
|
|
|
CurrentRenderMode = ERM_3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get native wrap mode value
|
|
|
|
GLint COpenGLDriver::getTextureWrapMode(const u8 clamp)
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
GLint mode = GL_REPEAT;
|
|
|
|
switch (clamp) {
|
|
|
|
case ETC_REPEAT:
|
|
|
|
mode = GL_REPEAT;
|
|
|
|
break;
|
|
|
|
case ETC_CLAMP:
|
|
|
|
mode = GL_CLAMP;
|
|
|
|
break;
|
|
|
|
case ETC_CLAMP_TO_EDGE:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_VERSION_1_2
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Version > 101)
|
|
|
|
mode = GL_CLAMP_TO_EDGE;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GL_SGIS_texture_edge_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_SGIS_texture_edge_clamp])
|
|
|
|
mode = GL_CLAMP_TO_EDGE_SGIS;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
// fallback
|
|
|
|
mode = GL_CLAMP;
|
|
|
|
break;
|
|
|
|
case ETC_CLAMP_TO_BORDER:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_VERSION_1_3
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Version > 102)
|
|
|
|
mode = GL_CLAMP_TO_BORDER;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GL_ARB_texture_border_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_ARB_texture_border_clamp])
|
|
|
|
mode = GL_CLAMP_TO_BORDER_ARB;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GL_SGIS_texture_border_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_SGIS_texture_border_clamp])
|
|
|
|
mode = GL_CLAMP_TO_BORDER_SGIS;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
// fallback
|
|
|
|
mode = GL_CLAMP;
|
|
|
|
break;
|
|
|
|
case ETC_MIRROR:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_VERSION_1_4
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Version > 103)
|
|
|
|
mode = GL_MIRRORED_REPEAT;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GL_ARB_texture_border_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_ARB_texture_mirrored_repeat])
|
|
|
|
mode = GL_MIRRORED_REPEAT_ARB;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GL_IBM_texture_mirrored_repeat
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_IBM_texture_mirrored_repeat])
|
|
|
|
mode = GL_MIRRORED_REPEAT_IBM;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
mode = GL_REPEAT;
|
|
|
|
break;
|
|
|
|
case ETC_MIRROR_CLAMP:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_EXT_texture_mirror_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_EXT_texture_mirror_clamp])
|
|
|
|
mode = GL_MIRROR_CLAMP_EXT;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#if defined(GL_ATI_texture_mirror_once)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_ATI_texture_mirror_once])
|
|
|
|
mode = GL_MIRROR_CLAMP_ATI;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
mode = GL_CLAMP;
|
|
|
|
break;
|
|
|
|
case ETC_MIRROR_CLAMP_TO_EDGE:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_EXT_texture_mirror_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_EXT_texture_mirror_clamp])
|
|
|
|
mode = GL_MIRROR_CLAMP_TO_EDGE_EXT;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#if defined(GL_ATI_texture_mirror_once)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_ATI_texture_mirror_once])
|
|
|
|
mode = GL_MIRROR_CLAMP_TO_EDGE_ATI;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
mode = GL_CLAMP;
|
|
|
|
break;
|
|
|
|
case ETC_MIRROR_CLAMP_TO_BORDER:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_EXT_texture_mirror_clamp
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_EXT_texture_mirror_clamp])
|
|
|
|
mode = GL_MIRROR_CLAMP_TO_BORDER_EXT;
|
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
mode = GL_CLAMP;
|
|
|
|
break;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Can be called by an IMaterialRenderer to make its work easier.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial,
|
|
|
|
bool resetAllRenderStates)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
// Fixed pipeline isn't important for shader based materials
|
|
|
|
|
|
|
|
E_OPENGL_FIXED_PIPELINE_STATE tempState = FixedPipelineState;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (resetAllRenderStates || tempState == EOFPS_ENABLE || tempState == EOFPS_DISABLE_TO_ENABLE) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// material colors
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.ColorMaterial != material.ColorMaterial) {
|
|
|
|
switch (material.ColorMaterial) {
|
2023-10-03 20:37:00 +02:00
|
|
|
case ECM_NONE:
|
|
|
|
glDisable(GL_COLOR_MATERIAL);
|
|
|
|
break;
|
|
|
|
case ECM_DIFFUSE:
|
|
|
|
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
|
|
|
break;
|
|
|
|
case ECM_AMBIENT:
|
|
|
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
|
|
|
|
break;
|
|
|
|
case ECM_EMISSIVE:
|
|
|
|
glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
|
|
|
|
break;
|
|
|
|
case ECM_SPECULAR:
|
|
|
|
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
|
|
|
|
break;
|
|
|
|
case ECM_DIFFUSE_AND_AMBIENT:
|
|
|
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (material.ColorMaterial != ECM_NONE)
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.AmbientColor != material.AmbientColor ||
|
|
|
|
lastmaterial.DiffuseColor != material.DiffuseColor ||
|
|
|
|
lastmaterial.EmissiveColor != material.EmissiveColor ||
|
|
|
|
lastmaterial.ColorMaterial != material.ColorMaterial) {
|
2023-10-03 20:37:00 +02:00
|
|
|
GLfloat color[4];
|
|
|
|
|
|
|
|
const f32 inv = 1.0f / 255.0f;
|
|
|
|
|
|
|
|
if ((material.ColorMaterial != video::ECM_AMBIENT) &&
|
2024-03-20 19:35:52 +01:00
|
|
|
(material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
color[0] = material.AmbientColor.getRed() * inv;
|
|
|
|
color[1] = material.AmbientColor.getGreen() * inv;
|
|
|
|
color[2] = material.AmbientColor.getBlue() * inv;
|
|
|
|
color[3] = material.AmbientColor.getAlpha() * inv;
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((material.ColorMaterial != video::ECM_DIFFUSE) &&
|
2024-03-20 19:35:52 +01:00
|
|
|
(material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
color[0] = material.DiffuseColor.getRed() * inv;
|
|
|
|
color[1] = material.DiffuseColor.getGreen() * inv;
|
|
|
|
color[2] = material.DiffuseColor.getBlue() * inv;
|
|
|
|
color[3] = material.DiffuseColor.getAlpha() * inv;
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (material.ColorMaterial != video::ECM_EMISSIVE) {
|
2023-10-03 20:37:00 +02:00
|
|
|
color[0] = material.EmissiveColor.getRed() * inv;
|
|
|
|
color[1] = material.EmissiveColor.getGreen() * inv;
|
|
|
|
color[2] = material.EmissiveColor.getBlue() * inv;
|
|
|
|
color[3] = material.EmissiveColor.getAlpha() * inv;
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.SpecularColor != material.SpecularColor ||
|
|
|
|
lastmaterial.Shininess != material.Shininess ||
|
|
|
|
lastmaterial.ColorMaterial != material.ColorMaterial) {
|
|
|
|
GLfloat color[4] = {0.f, 0.f, 0.f, 1.f};
|
2023-10-03 20:37:00 +02:00
|
|
|
const f32 inv = 1.0f / 255.0f;
|
|
|
|
|
|
|
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess);
|
|
|
|
// disable Specular colors if no shininess is set
|
|
|
|
if ((material.Shininess != 0.0f) &&
|
2024-03-20 19:35:52 +01:00
|
|
|
(material.ColorMaterial != video::ECM_SPECULAR)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_EXT_separate_specular_color
|
|
|
|
if (FeatureAvailable[IRR_EXT_separate_specular_color])
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
|
|
|
#endif
|
|
|
|
color[0] = material.SpecularColor.getRed() * inv;
|
|
|
|
color[1] = material.SpecularColor.getGreen() * inv;
|
|
|
|
color[2] = material.SpecularColor.getBlue() * inv;
|
|
|
|
color[3] = material.SpecularColor.getAlpha() * inv;
|
|
|
|
}
|
|
|
|
#ifdef GL_EXT_separate_specular_color
|
|
|
|
else if (FeatureAvailable[IRR_EXT_separate_specular_color])
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
|
|
|
|
#endif
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
// shademode
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.GouraudShading != material.GouraudShading) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (material.GouraudShading)
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
else
|
|
|
|
glShadeModel(GL_FLAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// lighting
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.Lighting != material.Lighting) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (material.Lighting)
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
else
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
// fog
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.FogEnable != material.FogEnable) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (material.FogEnable)
|
|
|
|
glEnable(GL_FOG);
|
|
|
|
else
|
|
|
|
glDisable(GL_FOG);
|
|
|
|
}
|
|
|
|
|
|
|
|
// normalization
|
|
|
|
if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.NormalizeNormals != material.NormalizeNormals) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (material.NormalizeNormals)
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
else
|
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set fixed pipeline as active.
|
|
|
|
tempState = EOFPS_ENABLE;
|
2024-03-20 19:35:52 +01:00
|
|
|
} else if (tempState == EOFPS_ENABLE_TO_DISABLE) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glDisable(GL_COLOR_MATERIAL);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_FOG);
|
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
|
|
|
|
// Set programmable pipeline as active.
|
|
|
|
tempState = EOFPS_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tempState == EOFPS_DISABLE - driver doesn't calls functions related to fixed pipeline.
|
|
|
|
|
|
|
|
// fillmode - fixed pipeline call, but it emulate GL_LINES behaviour in rendering, so it stay here.
|
|
|
|
if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud))
|
2024-03-20 19:35:52 +01:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud ? GL_POINT
|
|
|
|
: GL_FILL);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// ZBuffer
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (material.ZBuffer) {
|
2023-10-03 20:37:00 +02:00
|
|
|
case ECFN_DISABLED:
|
|
|
|
CacheHandler->setDepthTest(false);
|
|
|
|
break;
|
|
|
|
case ECFN_LESSEQUAL:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_LEQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_EQUAL:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_EQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_LESS:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_LESS);
|
|
|
|
break;
|
|
|
|
case ECFN_NOTEQUAL:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_NOTEQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_GREATEREQUAL:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_GEQUAL);
|
|
|
|
break;
|
|
|
|
case ECFN_GREATER:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_GREATER);
|
|
|
|
break;
|
|
|
|
case ECFN_ALWAYS:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_ALWAYS);
|
|
|
|
break;
|
|
|
|
case ECFN_NEVER:
|
|
|
|
CacheHandler->setDepthTest(true);
|
|
|
|
CacheHandler->setDepthFunc(GL_NEVER);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ZWrite
|
2024-03-20 19:35:52 +01:00
|
|
|
if (getWriteZBuffer(material)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setDepthMask(true);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setDepthMask(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Back face culling
|
2024-03-20 19:35:52 +01:00
|
|
|
if ((material.FrontfaceCulling) && (material.BackfaceCulling)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK);
|
|
|
|
CacheHandler->setCullFace(true);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else if (material.BackfaceCulling) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setCullFaceFunc(GL_BACK);
|
|
|
|
CacheHandler->setCullFace(true);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else if (material.FrontfaceCulling) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setCullFaceFunc(GL_FRONT);
|
|
|
|
CacheHandler->setCullFace(true);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setCullFace(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Color Mask
|
|
|
|
CacheHandler->setColorMask(material.ColorMask);
|
|
|
|
|
|
|
|
// Blend Equation
|
2024-03-20 19:35:52 +01:00
|
|
|
if (material.BlendOperation == EBO_NONE)
|
|
|
|
CacheHandler->setBlend(false);
|
|
|
|
else {
|
|
|
|
CacheHandler->setBlend(true);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#if defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op) || defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryFeature(EVDF_BLEND_OPERATIONS)) {
|
|
|
|
switch (material.BlendOperation) {
|
|
|
|
case EBO_SUBTRACT:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_EXT_blend_subtract)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT_EXT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
case EBO_REVSUBTRACT:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_EXT_blend_subtract)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_EXT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
case EBO_MIN:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_MIN);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_EXT_blend_minmax)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_MIN_EXT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
case EBO_MAX:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_MAX);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_EXT_blend_minmax)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_MAX_EXT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
case EBO_MIN_FACTOR:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_AMD_blend_minmax_factor)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_AMD_blend_minmax_factor])
|
|
|
|
CacheHandler->setBlendEquation(GL_FACTOR_MIN_AMD);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
// fallback in case of missing extension
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
|
|
|
#if defined(GL_AMD_blend_minmax_factor)
|
2024-03-20 19:35:52 +01:00
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_MIN);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
case EBO_MAX_FACTOR:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_AMD_blend_minmax_factor)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_AMD_blend_minmax_factor])
|
|
|
|
CacheHandler->setBlendEquation(GL_FACTOR_MAX_AMD);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
// fallback in case of missing extension
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
|
|
|
#if defined(GL_AMD_blend_minmax_factor)
|
2024-03-20 19:35:52 +01:00
|
|
|
else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_MAX);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
case EBO_MIN_ALPHA:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_SGIX_blend_alpha_minmax)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_SGIX_blend_alpha_minmax])
|
|
|
|
CacheHandler->setBlendEquation(GL_ALPHA_MIN_SGIX);
|
|
|
|
// fallback in case of missing extension
|
|
|
|
else if (FeatureAvailable[IRR_EXT_blend_minmax])
|
|
|
|
CacheHandler->setBlendEquation(GL_MIN_EXT);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case EBO_MAX_ALPHA:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_SGIX_blend_alpha_minmax)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_SGIX_blend_alpha_minmax])
|
|
|
|
CacheHandler->setBlendEquation(GL_ALPHA_MAX_SGIX);
|
|
|
|
// fallback in case of missing extension
|
|
|
|
else if (FeatureAvailable[IRR_EXT_blend_minmax])
|
|
|
|
CacheHandler->setBlendEquation(GL_MAX_EXT);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_VERSION_1_4)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_ADD);
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op)
|
2024-03-20 19:35:52 +01:00
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_ADD_EXT);
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// Blend Factor
|
|
|
|
if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF?
|
|
|
|
&& material.MaterialType != EMT_ONETEXTURE_BLEND) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (queryFeature(EVDF_BLEND_SEPARATE)) {
|
|
|
|
CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact),
|
|
|
|
getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact));
|
|
|
|
} else {
|
|
|
|
CacheHandler->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact));
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Polygon Offset
|
|
|
|
if (queryFeature(EVDF_POLYGON_OFFSET) && (resetAllRenderStates ||
|
2024-03-20 19:35:52 +01:00
|
|
|
lastmaterial.PolygonOffsetSlopeScale != material.PolygonOffsetSlopeScale ||
|
|
|
|
lastmaterial.PolygonOffsetDepthBias != material.PolygonOffsetDepthBias)) {
|
|
|
|
glDisable(lastmaterial.Wireframe ? GL_POLYGON_OFFSET_LINE : lastmaterial.PointCloud ? GL_POLYGON_OFFSET_POINT
|
|
|
|
: GL_POLYGON_OFFSET_FILL);
|
|
|
|
if (material.PolygonOffsetSlopeScale || material.PolygonOffsetDepthBias) {
|
|
|
|
glEnable(material.Wireframe ? GL_POLYGON_OFFSET_LINE : material.PointCloud ? GL_POLYGON_OFFSET_POINT
|
|
|
|
: GL_POLYGON_OFFSET_FILL);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
glPolygonOffset(material.PolygonOffsetSlopeScale, material.PolygonOffsetDepthBias);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
glPolygonOffset(0.0f, 0.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// thickness
|
2024-03-20 19:35:52 +01:00
|
|
|
if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) {
|
|
|
|
if (AntiAlias) {
|
|
|
|
// glPointSize(core::clamp(static_cast<GLfloat>(material.Thickness), DimSmoothedPoint[0], DimSmoothedPoint[1]));
|
2023-10-03 20:37:00 +02:00
|
|
|
// we don't use point smoothing
|
|
|
|
glPointSize(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1]));
|
|
|
|
glLineWidth(core::clamp(static_cast<GLfloat>(material.Thickness), DimSmoothedLine[0], DimSmoothedLine[1]));
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
glPointSize(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1]));
|
|
|
|
glLineWidth(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedLine[0], DimAliasedLine[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Anti aliasing
|
2024-03-20 19:35:52 +01:00
|
|
|
if ((resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing) && FeatureAvailable[IRR_ARB_multisample]) {
|
2024-02-17 22:01:37 +01:00
|
|
|
if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE)
|
|
|
|
glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
|
|
|
|
else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE)
|
|
|
|
glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if ((AntiAlias >= 2) && (material.AntiAliasing & (EAAM_SIMPLE | EAAM_QUALITY))) {
|
2024-02-17 22:01:37 +01:00
|
|
|
glEnable(GL_MULTISAMPLE_ARB);
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_NV_multisample_filter_hint
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_NV_multisample_filter_hint]) {
|
2024-02-17 22:01:37 +01:00
|
|
|
if ((material.AntiAliasing & EAAM_QUALITY) == EAAM_QUALITY)
|
|
|
|
glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
|
|
|
|
else
|
|
|
|
glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_FASTEST);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-02-17 22:01:37 +01:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2024-02-17 22:01:37 +01:00
|
|
|
glDisable(GL_MULTISAMPLE_ARB);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Texture parameters
|
|
|
|
setTextureRenderStates(material, resetAllRenderStates);
|
|
|
|
|
|
|
|
// set current fixed pipeline state
|
|
|
|
FixedPipelineState = tempState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
// Set textures to TU/TIU and apply filters to them
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
for (s32 i = Feature.MaxTextureUnits - 1; i >= 0; --i) {
|
2023-10-03 20:37:00 +02:00
|
|
|
bool fixedPipeline = false;
|
|
|
|
|
|
|
|
if (FixedPipelineState == EOFPS_ENABLE || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE)
|
|
|
|
fixedPipeline = true;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const COpenGLTexture *tmpTexture = CacheHandler->getTextureCache().get(i);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (tmpTexture) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setActiveTexture(GL_TEXTURE0 + i);
|
|
|
|
|
|
|
|
// Minetest uses the first texture matrix even with the programmable pipeline
|
2024-03-20 19:35:52 +01:00
|
|
|
if (fixedPipeline || i == 0) {
|
2023-10-03 20:37:00 +02:00
|
|
|
const bool isRTT = tmpTexture->isRenderTarget();
|
|
|
|
|
|
|
|
CacheHandler->setMatrixMode(GL_TEXTURE);
|
|
|
|
|
|
|
|
if (!isRTT && Matrices[ETS_TEXTURE_0 + i].isIdentity())
|
|
|
|
glLoadIdentity();
|
2024-03-20 19:35:52 +01:00
|
|
|
else {
|
2023-10-03 20:37:00 +02:00
|
|
|
GLfloat glmat[16];
|
|
|
|
if (isRTT)
|
|
|
|
getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i] * TextureFlipMatrix);
|
|
|
|
else
|
|
|
|
getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i]);
|
|
|
|
glLoadMatrixf(glmat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const GLenum tmpType = tmpTexture->getOpenGLTextureType();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLTexture::SStatesCache &statesCache = tmpTexture->getStatesCache();
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
if (resetAllRenderstates)
|
|
|
|
statesCache.IsCached = false;
|
|
|
|
|
|
|
|
#ifdef GL_VERSION_2_1
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Version >= 201) {
|
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].LODBias != statesCache.LODBias) {
|
|
|
|
if (material.TextureLayers[i].LODBias) {
|
2023-10-03 20:37:00 +02:00
|
|
|
const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
|
|
|
|
glTexParameterf(tmpType, GL_TEXTURE_LOD_BIAS, tmp);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexParameterf(tmpType, GL_TEXTURE_LOD_BIAS, 0.f);
|
|
|
|
|
|
|
|
statesCache.LODBias = material.TextureLayers[i].LODBias;
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else if (FeatureAvailable[IRR_EXT_texture_lod_bias]) {
|
|
|
|
if (material.TextureLayers[i].LODBias) {
|
2023-10-03 20:37:00 +02:00
|
|
|
const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
|
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f);
|
|
|
|
}
|
|
|
|
#elif defined(GL_EXT_texture_lod_bias)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_EXT_texture_lod_bias]) {
|
|
|
|
if (material.TextureLayers[i].LODBias) {
|
2023-10-03 20:37:00 +02:00
|
|
|
const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
|
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].MagFilter != statesCache.MagFilter) {
|
2023-10-03 20:37:00 +02:00
|
|
|
E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter;
|
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_MAG_FILTER,
|
2024-03-20 19:35:52 +01:00
|
|
|
magFilter == ETMAGF_NEAREST ? GL_NEAREST : (assert(magFilter == ETMAGF_LINEAR), GL_LINEAR));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
statesCache.MagFilter = magFilter;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (material.UseMipMaps && tmpTexture->hasMipMaps()) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter ||
|
2024-03-20 19:35:52 +01:00
|
|
|
!statesCache.MipMapStatus) {
|
2023-10-03 20:37:00 +02:00
|
|
|
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
|
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_MIN_FILTER,
|
2024-03-20 19:35:52 +01:00
|
|
|
minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST : minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST
|
2024-03-21 17:30:28 +01:00
|
|
|
: minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR
|
2024-03-20 19:35:52 +01:00
|
|
|
: (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
statesCache.MinFilter = minFilter;
|
|
|
|
statesCache.MipMapStatus = true;
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter ||
|
2024-03-20 19:35:52 +01:00
|
|
|
statesCache.MipMapStatus) {
|
2023-10-03 20:37:00 +02:00
|
|
|
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
|
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_MIN_FILTER,
|
2024-03-20 19:35:52 +01:00
|
|
|
(minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST : (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
statesCache.MinFilter = minFilter;
|
|
|
|
statesCache.MipMapStatus = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_EXT_texture_filter_anisotropic
|
|
|
|
if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic] &&
|
2024-03-20 19:35:52 +01:00
|
|
|
(!statesCache.IsCached || material.TextureLayers[i].AnisotropicFilter != statesCache.AnisotropicFilter)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
2024-03-20 19:35:52 +01:00
|
|
|
material.TextureLayers[i].AnisotropicFilter > 1 ? core::min_(MaxAnisotropy, material.TextureLayers[i].AnisotropicFilter) : 1);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
statesCache.AnisotropicFilter = material.TextureLayers[i].AnisotropicFilter;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapU != statesCache.WrapU) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU));
|
|
|
|
statesCache.WrapU = material.TextureLayers[i].TextureWrapU;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapV != statesCache.WrapV) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV));
|
|
|
|
statesCache.WrapV = material.TextureLayers[i].TextureWrapV;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapW != statesCache.WrapW) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexParameteri(tmpType, GL_TEXTURE_WRAP_R, getTextureWrapMode(material.TextureLayers[i].TextureWrapW));
|
|
|
|
statesCache.WrapW = material.TextureLayers[i].TextureWrapW;
|
|
|
|
}
|
|
|
|
|
|
|
|
statesCache.IsCached = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Enable the 2d override material
|
|
|
|
void COpenGLDriver::enableMaterial2D(bool enable)
|
|
|
|
{
|
|
|
|
if (!enable)
|
|
|
|
CurrentRenderMode = ERM_NONE;
|
|
|
|
CNullDriver::enableMaterial2D(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! sets the needed renderstates
|
|
|
|
void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
|
|
|
|
{
|
|
|
|
// 2d methods uses fixed pipeline
|
|
|
|
if (FixedPipelineState == COpenGLDriver::EOFPS_DISABLE)
|
|
|
|
FixedPipelineState = COpenGLDriver::EOFPS_DISABLE_TO_ENABLE;
|
|
|
|
else
|
|
|
|
FixedPipelineState = COpenGLDriver::EOFPS_ENABLE;
|
|
|
|
|
|
|
|
bool resetAllRenderStates = false;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (CurrentRenderMode != ERM_2D || Transformation3DChanged) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// unset last 3d material
|
2024-03-20 19:35:52 +01:00
|
|
|
if (CurrentRenderMode == ERM_3D) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
|
|
|
|
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Transformation3DChanged) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setMatrixMode(GL_PROJECTION);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const core::dimension2d<u32> &renderTargetSize = getCurrentRenderTargetSize();
|
2023-10-03 20:37:00 +02:00
|
|
|
core::matrix4 m(core::matrix4::EM4CONST_NOTHING);
|
|
|
|
m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f);
|
2024-03-20 19:35:52 +01:00
|
|
|
m.setTranslation(core::vector3df(-1, 1, 0));
|
2023-10-03 20:37:00 +02:00
|
|
|
glLoadMatrixf(m.pointer());
|
|
|
|
|
|
|
|
CacheHandler->setMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(0.375f, 0.375f, 0.0f);
|
|
|
|
|
|
|
|
Transformation3DChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
CacheHandler->setBlendEquation(GL_FUNC_ADD);
|
|
|
|
|
|
|
|
#ifdef GL_EXT_clip_volume_hint
|
|
|
|
if (FeatureAvailable[IRR_EXT_clip_volume_hint])
|
|
|
|
glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_FASTEST);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
resetAllRenderStates = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SMaterial currentMaterial = (!OverrideMaterial2DEnabled) ? InitMaterial2D : OverrideMaterial2D;
|
|
|
|
currentMaterial.Lighting = false;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (texture) {
|
2023-10-03 20:37:00 +02:00
|
|
|
setTransform(ETS_TEXTURE_0, core::IdentityMatrix);
|
|
|
|
|
|
|
|
// Due to the transformation change, the previous line would call a reset each frame
|
|
|
|
// but we can safely reset the variable as it was false before
|
|
|
|
Transformation3DChanged = false;
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->getTextureCache().set(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
setBasicRenderStates(currentMaterial, LastMaterial, resetAllRenderStates);
|
|
|
|
|
|
|
|
LastMaterial = currentMaterial;
|
|
|
|
CacheHandler->correctCacheMaterial(LastMaterial);
|
|
|
|
|
|
|
|
// no alphaChannel without texture
|
|
|
|
alphaChannel &= texture;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (alphaChannel || alpha) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setBlend(true);
|
|
|
|
CacheHandler->setAlphaTest(true);
|
|
|
|
CacheHandler->setAlphaFunc(GL_GREATER, 0.f);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setBlend(false);
|
|
|
|
CacheHandler->setAlphaTest(false);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (texture) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (alphaChannel) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// if alpha and alpha texture just modulate, otherwise use only the alpha channel
|
2024-03-20 19:35:52 +01:00
|
|
|
if (alpha) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_ARB_texture_env_combine) || defined(GL_EXT_texture_env_combine)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_ARB_texture_env_combine] || FeatureAvailable[IRR_EXT_texture_env_combine]) {
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_ARB_texture_env_combine
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
|
|
|
// rgb always modulates
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
#else
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
|
|
|
|
// rgb always modulates
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
|
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
|
|
|
if (alpha) {
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GL_ARB_texture_env_combine) || defined(GL_EXT_texture_env_combine)
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_ARB_texture_env_combine] || FeatureAvailable[IRR_EXT_texture_env_combine]) {
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_ARB_texture_env_combine
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
// rgb always modulates
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
#else
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
|
|
|
|
// rgb always modulates
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
|
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentRenderMode = ERM_2D;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! \return Returns the name of the video driver.
|
2024-03-20 19:35:52 +01:00
|
|
|
const char *COpenGLDriver::getName() const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return Name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the dynamic ambient light color. The default color is
|
|
|
|
//! (0,0,0,0) which means it is dark.
|
|
|
|
//! \param color: New color of the ambient light.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::setAmbientLight(const SColorf &color)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
CNullDriver::setAmbientLight(color);
|
|
|
|
GLfloat data[4] = {color.r, color.g, color.b, color.a};
|
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// this code was sent in by Oliver Klems, thank you! (I modified the glViewport
|
|
|
|
// method just a bit.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::setViewPort(const core::rect<s32> &area)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight());
|
|
|
|
|
|
|
|
ViewPort = vp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::setViewPortRaw(u32 width, u32 height)
|
|
|
|
{
|
|
|
|
CacheHandler->setViewport(0, 0, width, height);
|
|
|
|
ViewPort = core::recti(0, 0, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the fog mode.
|
|
|
|
void COpenGLDriver::setFog(SColor c, E_FOG_TYPE fogType, f32 start,
|
2024-03-20 19:35:52 +01:00
|
|
|
f32 end, f32 density, bool pixelFog, bool rangeFog)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glFogf(GL_FOG_MODE, GLfloat((fogType == EFT_FOG_LINEAR) ? GL_LINEAR : (fogType == EFT_FOG_EXP) ? GL_EXP
|
|
|
|
: GL_EXP2));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_EXT_fog_coord
|
|
|
|
if (FeatureAvailable[IRR_EXT_fog_coord])
|
|
|
|
glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH);
|
|
|
|
#endif
|
|
|
|
#ifdef GL_NV_fog_distance
|
2024-03-20 19:35:52 +01:00
|
|
|
if (FeatureAvailable[IRR_NV_fog_distance]) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (rangeFog)
|
|
|
|
glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
|
|
|
|
else
|
|
|
|
glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (fogType == EFT_FOG_LINEAR) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glFogf(GL_FOG_START, start);
|
|
|
|
glFogf(GL_FOG_END, end);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
glFogf(GL_FOG_DENSITY, density);
|
|
|
|
|
|
|
|
if (pixelFog)
|
|
|
|
glHint(GL_FOG_HINT, GL_NICEST);
|
|
|
|
else
|
|
|
|
glHint(GL_FOG_HINT, GL_FASTEST);
|
|
|
|
|
|
|
|
SColorf color(c);
|
|
|
|
GLfloat data[4] = {color.r, color.g, color.b, color.a};
|
|
|
|
glFogfv(GL_FOG_COLOR, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Draws a 3d box.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw3DBox(const core::aabbox3d<f32> &box, SColor color)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
core::vector3df edges[8];
|
|
|
|
box.getEdges(edges);
|
|
|
|
|
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
video::S3DVertex v[24];
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
for (u32 i = 0; i < 24; i++)
|
2023-10-03 20:37:00 +02:00
|
|
|
v[i].Color = color;
|
|
|
|
|
|
|
|
v[0].Pos = edges[5];
|
|
|
|
v[1].Pos = edges[1];
|
|
|
|
v[2].Pos = edges[1];
|
|
|
|
v[3].Pos = edges[3];
|
|
|
|
v[4].Pos = edges[3];
|
|
|
|
v[5].Pos = edges[7];
|
|
|
|
v[6].Pos = edges[7];
|
|
|
|
v[7].Pos = edges[5];
|
|
|
|
v[8].Pos = edges[0];
|
|
|
|
v[9].Pos = edges[2];
|
|
|
|
v[10].Pos = edges[2];
|
|
|
|
v[11].Pos = edges[6];
|
|
|
|
v[12].Pos = edges[6];
|
|
|
|
v[13].Pos = edges[4];
|
|
|
|
v[14].Pos = edges[4];
|
|
|
|
v[15].Pos = edges[0];
|
|
|
|
v[16].Pos = edges[1];
|
|
|
|
v[17].Pos = edges[0];
|
|
|
|
v[18].Pos = edges[3];
|
|
|
|
v[19].Pos = edges[2];
|
|
|
|
v[20].Pos = edges[7];
|
|
|
|
v[21].Pos = edges[6];
|
|
|
|
v[22].Pos = edges[5];
|
|
|
|
v[23].Pos = edges[4];
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(v, 24, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, false);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(v))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(v))[0].Color);
|
|
|
|
else {
|
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawArrays(GL_LINES, 0, 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Draws a 3d line.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::draw3DLine(const core::vector3df &start,
|
|
|
|
const core::vector3df &end, SColor color)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
setRenderStates3DMode();
|
|
|
|
|
|
|
|
Quad2DVertices[0].Color = color;
|
|
|
|
Quad2DVertices[1].Color = color;
|
|
|
|
|
|
|
|
Quad2DVertices[0].Pos = core::vector3df((f32)start.X, (f32)start.Y, (f32)start.Z);
|
|
|
|
Quad2DVertices[1].Pos = core::vector3df((f32)end.X, (f32)end.Y, (f32)end.Z);
|
|
|
|
|
|
|
|
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
|
|
|
getColorBuffer(Quad2DVertices, 2, EVT_STANDARD);
|
|
|
|
|
|
|
|
CacheHandler->setClientState(true, false, true, false);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Pos);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
#ifdef GL_BGRA
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
const GLint colorSize = 4;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
|
2024-03-20 19:35:52 +01:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex *>(Quad2DVertices))[0].Color);
|
|
|
|
else {
|
|
|
|
_IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0);
|
2023-10-03 20:37:00 +02:00
|
|
|
glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, Quad2DIndices);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Removes a texture from the texture cache and deletes it, freeing lot of memory.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::removeTexture(ITexture *texture)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
CacheHandler->getTextureCache().remove(texture);
|
|
|
|
CNullDriver::removeTexture(texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check if the driver supports creating textures with the given color format
|
|
|
|
bool COpenGLDriver::queryTextureFormat(ECOLOR_FORMAT format) const
|
|
|
|
{
|
|
|
|
GLint dummyInternalFormat;
|
|
|
|
GLenum dummyPixelFormat;
|
|
|
|
GLenum dummyPixelType;
|
2024-03-20 19:35:52 +01:00
|
|
|
void (*dummyConverter)(const void *, s32, void *);
|
2023-10-03 20:37:00 +02:00
|
|
|
return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::needsTransparentRenderPass(const irr::video::SMaterial &material) const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Only used by the internal engine. Used to notify the driver that
|
|
|
|
//! the window was resized.
|
2024-03-20 19:35:52 +01:00
|
|
|
void COpenGLDriver::OnResize(const core::dimension2d<u32> &size)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
CNullDriver::OnResize(size);
|
|
|
|
CacheHandler->setViewport(0, 0, size.Width, size.Height);
|
|
|
|
Transformation3DChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns type of video driver
|
|
|
|
E_DRIVER_TYPE COpenGLDriver::getDriverType() const
|
|
|
|
{
|
|
|
|
return EDT_OPENGL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! returns color format
|
|
|
|
ECOLOR_FORMAT COpenGLDriver::getColorFormat() const
|
|
|
|
{
|
|
|
|
return ColorFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get a vertex shader constant index.
|
2024-03-20 19:35:52 +01:00
|
|
|
s32 COpenGLDriver::getVertexShaderConstantID(const c8 *name)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return getPixelShaderConstantID(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get a pixel shader constant index.
|
2024-03-20 19:35:52 +01:00
|
|
|
s32 COpenGLDriver::getPixelShaderConstantID(const c8 *name)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID().");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a constant for the vertex shader based on an index.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setVertexShaderConstant(s32 index, const f32 *floats, int count)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
// pass this along, as in GLSL the same routine is used for both vertex and fragment shaders
|
2023-10-03 20:37:00 +02:00
|
|
|
return setPixelShaderConstant(index, floats, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Int interface for the above.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setVertexShaderConstant(s32 index, const s32 *ints, int count)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return setPixelShaderConstant(index, ints, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Uint interface for the above.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setVertexShaderConstant(s32 index, const u32 *ints, int count)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return setPixelShaderConstant(index, ints, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a constant for the pixel shader based on an index.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setPixelShaderConstant(s32 index, const f32 *floats, int count)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Int interface for the above.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setPixelShaderConstant(s32 index, const s32 *ints, int count)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setPixelShaderConstant(s32 index, const u32 *ints, int count)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry.
|
|
|
|
s32 COpenGLDriver::addHighLevelShaderMaterial(
|
2024-03-20 19:35:52 +01:00
|
|
|
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,
|
|
|
|
s32 userData)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
s32 nr = -1;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLSLMaterialRenderer *r = new COpenGLSLMaterialRenderer(
|
2023-10-03 20:37:00 +02:00
|
|
|
this, nr,
|
|
|
|
vertexShaderProgram, vertexShaderEntryPointName, vsCompileTarget,
|
|
|
|
pixelShaderProgram, pixelShaderEntryPointName, psCompileTarget,
|
|
|
|
geometryShaderProgram, geometryShaderEntryPointName, gsCompileTarget,
|
|
|
|
inType, outType, verticesOut,
|
2024-03-20 19:35:52 +01:00
|
|
|
callback, baseMaterial, userData);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
r->drop();
|
|
|
|
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns a pointer to the IVideoDriver interface. (Implementation for
|
|
|
|
//! IMaterialRendererServices)
|
2024-03-20 19:35:52 +01:00
|
|
|
IVideoDriver *COpenGLDriver::getVideoDriver()
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
ITexture *COpenGLDriver::addRenderTargetTexture(const core::dimension2d<u32> &size,
|
|
|
|
const io::path &name, const ECOLOR_FORMAT format)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (IImage::isCompressedFormat(format))
|
2023-10-03 20:37:00 +02:00
|
|
|
return 0;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// disable mip-mapping
|
2023-10-03 20:37:00 +02:00
|
|
|
bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
|
|
|
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
|
|
|
|
|
|
|
|
bool supportForFBO = (Feature.ColorAttachment > 0);
|
|
|
|
|
|
|
|
core::dimension2du destSize(size);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!supportForFBO) {
|
2023-10-03 20:37:00 +02:00
|
|
|
destSize = core::dimension2d<u32>(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height));
|
|
|
|
destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLTexture *renderTargetTexture = new COpenGLTexture(name, destSize, ETT_2D, format, this);
|
2023-10-03 20:37:00 +02:00
|
|
|
addTexture(renderTargetTexture);
|
|
|
|
renderTargetTexture->drop();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// restore mip-mapping
|
2023-10-03 20:37:00 +02:00
|
|
|
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels);
|
|
|
|
|
|
|
|
return renderTargetTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Creates a render target texture for a cubemap
|
2024-03-20 19:35:52 +01:00
|
|
|
ITexture *COpenGLDriver::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path &name, const ECOLOR_FORMAT format)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (IImage::isCompressedFormat(format))
|
2023-10-03 20:37:00 +02:00
|
|
|
return 0;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// disable mip-mapping
|
2023-10-03 20:37:00 +02:00
|
|
|
bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
|
|
|
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
|
|
|
|
|
|
|
|
bool supportForFBO = (Feature.ColorAttachment > 0);
|
|
|
|
|
|
|
|
const core::dimension2d<u32> size(sideLen, sideLen);
|
|
|
|
core::dimension2du destSize(size);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!supportForFBO) {
|
2023-10-03 20:37:00 +02:00
|
|
|
destSize = core::dimension2d<u32>(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height));
|
|
|
|
destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLTexture *renderTargetTexture = new COpenGLTexture(name, destSize, ETT_CUBEMAP, format, this);
|
2023-10-03 20:37:00 +02:00
|
|
|
addTexture(renderTargetTexture);
|
|
|
|
renderTargetTexture->drop();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// restore mip-mapping
|
2023-10-03 20:37:00 +02:00
|
|
|
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels);
|
|
|
|
|
|
|
|
return renderTargetTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns the maximum amount of primitives (mostly vertices) which
|
|
|
|
//! the device is able to render with one drawIndexedTriangleList
|
|
|
|
//! call.
|
|
|
|
u32 COpenGLDriver::getMaximalPrimitiveCount() const
|
|
|
|
{
|
|
|
|
return 0x7fffffff;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (target && target->getDriverType() != EDT_OPENGL) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Fatal Error: Tried to set a render target not owned by this driver.", ELL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool supportForFBO = (Feature.ColorAttachment > 0);
|
|
|
|
|
|
|
|
core::dimension2d<u32> destRenderTargetSize(0, 0);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (target) {
|
|
|
|
COpenGLRenderTarget *renderTarget = static_cast<COpenGLRenderTarget *>(target);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (supportForFBO) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setFBO(renderTarget->getBufferID());
|
|
|
|
renderTarget->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
destRenderTargetSize = renderTarget->getSize();
|
|
|
|
|
|
|
|
setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (supportForFBO)
|
|
|
|
CacheHandler->setFBO(0);
|
2024-03-20 19:35:52 +01:00
|
|
|
else {
|
|
|
|
COpenGLRenderTarget *prevRenderTarget = static_cast<COpenGLRenderTarget *>(CurrentRenderTarget);
|
|
|
|
COpenGLTexture *renderTargetTexture = static_cast<COpenGLTexture *>(prevRenderTarget->getTexture());
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (renderTargetTexture) {
|
|
|
|
const COpenGLTexture *prevTexture = CacheHandler->getTextureCache()[0];
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
CacheHandler->getTextureCache().set(0, renderTargetTexture);
|
|
|
|
|
|
|
|
const core::dimension2d<u32> size = renderTargetTexture->getSize();
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.Width, size.Height);
|
|
|
|
|
|
|
|
CacheHandler->getTextureCache().set(0, prevTexture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
destRenderTargetSize = core::dimension2d<u32>(0, 0);
|
|
|
|
|
|
|
|
setViewPortRaw(ScreenSize.Width, ScreenSize.Height);
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (CurrentRenderTargetSize != destRenderTargetSize) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CurrentRenderTargetSize = destRenderTargetSize;
|
|
|
|
|
|
|
|
Transformation3DChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentRenderTarget = target;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!supportForFBO) {
|
2023-10-03 20:37:00 +02:00
|
|
|
clearFlag |= ECBF_COLOR;
|
|
|
|
clearFlag |= ECBF_DEPTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearBuffers(clearFlag, clearColor, clearDepth, clearStencil);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil)
|
|
|
|
{
|
|
|
|
GLbitfield mask = 0;
|
|
|
|
u8 colorMask = 0;
|
|
|
|
bool depthMask = false;
|
|
|
|
|
|
|
|
CacheHandler->getColorMask(colorMask);
|
|
|
|
CacheHandler->getDepthMask(depthMask);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (flag & ECBF_COLOR) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setColorMask(ECP_ALL);
|
|
|
|
|
|
|
|
const f32 inv = 1.0f / 255.0f;
|
|
|
|
glClearColor(color.getRed() * inv, color.getGreen() * inv,
|
2024-03-20 19:35:52 +01:00
|
|
|
color.getBlue() * inv, color.getAlpha() * inv);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
mask |= GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (flag & ECBF_DEPTH) {
|
2023-10-03 20:37:00 +02:00
|
|
|
CacheHandler->setDepthMask(true);
|
|
|
|
glClearDepth(depth);
|
|
|
|
mask |= GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (flag & ECBF_STENCIL) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glClearStencil(stencil);
|
|
|
|
mask |= GL_STENCIL_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
glClear(mask);
|
|
|
|
|
|
|
|
CacheHandler->setColorMask(colorMask);
|
|
|
|
CacheHandler->setDepthMask(depthMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns an image created from the last rendered frame.
|
2024-03-20 19:35:52 +01:00
|
|
|
IImage *COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (target != video::ERT_FRAME_BUFFER)
|
|
|
|
return 0;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (format == video::ECF_UNKNOWN)
|
|
|
|
format = getColorFormat();
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// TODO: Maybe we could support more formats (floating point and some of those beyond ECF_R8), didn't really try yet
|
|
|
|
if (IImage::isCompressedFormat(format) || IImage::isDepthFormat(format) || IImage::isFloatingPointFormat(format) || format >= ECF_R8)
|
|
|
|
return 0;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
// allows to read pixels in top-to-bottom order
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_MESA_pack_invert
|
|
|
|
if (FeatureAvailable[IRR_MESA_pack_invert])
|
|
|
|
glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GLenum fmt;
|
|
|
|
GLenum type;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (format) {
|
2023-10-03 20:37:00 +02:00
|
|
|
case ECF_A1R5G5B5:
|
|
|
|
fmt = GL_BGRA;
|
|
|
|
type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
|
|
|
break;
|
|
|
|
case ECF_R5G6B5:
|
|
|
|
fmt = GL_RGB;
|
|
|
|
type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
break;
|
|
|
|
case ECF_R8G8B8:
|
|
|
|
fmt = GL_RGB;
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case ECF_A8R8G8B8:
|
|
|
|
fmt = GL_BGRA;
|
|
|
|
if (Version > 101)
|
|
|
|
type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
|
|
|
else
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fmt = GL_BGRA;
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
IImage *newImage = createImage(format, ScreenSize);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
u8 *pixels = 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
if (newImage)
|
2024-03-20 19:35:52 +01:00
|
|
|
pixels = static_cast<u8 *>(newImage->getData());
|
|
|
|
if (pixels) {
|
2023-10-03 20:37:00 +02:00
|
|
|
glReadBuffer(GL_FRONT);
|
|
|
|
glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, fmt, type, pixels);
|
|
|
|
testGLError(__LINE__);
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_MESA_pack_invert
|
|
|
|
if (FeatureAvailable[IRR_MESA_pack_invert])
|
|
|
|
glPixelStorei(GL_PACK_INVERT_MESA, GL_FALSE);
|
|
|
|
else
|
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
if (pixels && newImage) {
|
2023-10-03 20:37:00 +02:00
|
|
|
// opengl images are horizontally flipped, so we have to fix that here.
|
|
|
|
const s32 pitch = newImage->getPitch();
|
2024-03-20 19:35:52 +01:00
|
|
|
u8 *p2 = pixels + (ScreenSize.Height - 1) * pitch;
|
|
|
|
u8 *tmpBuffer = new u8[pitch];
|
|
|
|
for (u32 i = 0; i < ScreenSize.Height; i += 2) {
|
2023-10-03 20:37:00 +02:00
|
|
|
memcpy(tmpBuffer, pixels, pitch);
|
2024-03-20 19:35:52 +01:00
|
|
|
// for (u32 j=0; j<pitch; ++j)
|
|
|
|
// {
|
|
|
|
// pixels[j]=(u8)(p2[j]*255.f);
|
|
|
|
// }
|
2023-10-03 20:37:00 +02:00
|
|
|
memcpy(pixels, p2, pitch);
|
2024-03-20 19:35:52 +01:00
|
|
|
// for (u32 j=0; j<pitch; ++j)
|
|
|
|
// {
|
|
|
|
// p2[j]=(u8)(tmpBuffer[j]*255.f);
|
|
|
|
// }
|
2023-10-03 20:37:00 +02:00
|
|
|
memcpy(p2, tmpBuffer, pitch);
|
|
|
|
pixels += pitch;
|
|
|
|
p2 -= pitch;
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
delete[] tmpBuffer;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (newImage) {
|
|
|
|
if (testGLError(__LINE__) || !pixels) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("createScreenShot failed", ELL_ERROR);
|
|
|
|
newImage->drop();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Set/unset a clipping plane.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::setClipPlane(u32 index, const core::plane3df &plane, bool enable)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
if (index >= MaxUserClipPlanes)
|
|
|
|
return false;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
UserClipPlanes[index].Plane = plane;
|
2023-10-03 20:37:00 +02:00
|
|
|
enableClipPlane(index, enable);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::uploadClipPlane(u32 index)
|
|
|
|
{
|
|
|
|
// opengl needs an array of doubles for the plane equation
|
|
|
|
GLdouble clip_plane[4];
|
|
|
|
clip_plane[0] = UserClipPlanes[index].Plane.Normal.X;
|
|
|
|
clip_plane[1] = UserClipPlanes[index].Plane.Normal.Y;
|
|
|
|
clip_plane[2] = UserClipPlanes[index].Plane.Normal.Z;
|
|
|
|
clip_plane[3] = UserClipPlanes[index].Plane.D;
|
|
|
|
glClipPlane(GL_CLIP_PLANE0 + index, clip_plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Enable/disable a clipping plane.
|
|
|
|
void COpenGLDriver::enableClipPlane(u32 index, bool enable)
|
|
|
|
{
|
|
|
|
if (index >= MaxUserClipPlanes)
|
|
|
|
return;
|
2024-03-20 19:35:52 +01:00
|
|
|
if (enable) {
|
|
|
|
if (!UserClipPlanes[index].Enabled) {
|
2023-10-03 20:37:00 +02:00
|
|
|
uploadClipPlane(index);
|
|
|
|
glEnable(GL_CLIP_PLANE0 + index);
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
glDisable(GL_CLIP_PLANE0 + index);
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
UserClipPlanes[index].Enabled = enable;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
core::dimension2du COpenGLDriver::getMaxTextureSize() const
|
|
|
|
{
|
|
|
|
return core::dimension2du(MaxTextureSize, MaxTextureSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Convert E_PRIMITIVE_TYPE to OpenGL equivalent
|
|
|
|
GLenum COpenGLDriver::primitiveTypeToGL(scene::E_PRIMITIVE_TYPE type) const
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (type) {
|
|
|
|
case scene::EPT_POINTS:
|
|
|
|
return GL_POINTS;
|
|
|
|
case scene::EPT_LINE_STRIP:
|
|
|
|
return GL_LINE_STRIP;
|
|
|
|
case scene::EPT_LINE_LOOP:
|
|
|
|
return GL_LINE_LOOP;
|
|
|
|
case scene::EPT_LINES:
|
|
|
|
return GL_LINES;
|
|
|
|
case scene::EPT_TRIANGLE_STRIP:
|
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
case scene::EPT_TRIANGLE_FAN:
|
|
|
|
return GL_TRIANGLE_FAN;
|
|
|
|
case scene::EPT_TRIANGLES:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
case scene::EPT_POINT_SPRITES:
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef GL_ARB_point_sprite
|
2024-03-20 19:35:52 +01:00
|
|
|
return GL_POINT_SPRITE_ARB;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
return GL_POINTS;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum COpenGLDriver::getGLBlend(E_BLEND_FACTOR factor) const
|
|
|
|
{
|
|
|
|
GLenum r = 0;
|
2024-03-20 19:35:52 +01:00
|
|
|
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;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum COpenGLDriver::getZBufferBits() const
|
|
|
|
{
|
|
|
|
GLenum bits = 0;
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (Params.ZBufferBits) {
|
2023-10-03 20:37:00 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat,
|
|
|
|
GLenum &pixelType, void (**converter)(const void *, s32, void *)) const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
// NOTE: Converter variable not used here, but don't remove, it's used in the OGL-ES drivers.
|
|
|
|
|
|
|
|
bool supported = false;
|
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
pixelFormat = GL_RGBA;
|
|
|
|
pixelType = GL_UNSIGNED_BYTE;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
switch (format) {
|
2023-10-03 20:37:00 +02:00
|
|
|
case ECF_A1R5G5B5:
|
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
pixelFormat = GL_BGRA_EXT;
|
|
|
|
pixelType = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
|
|
|
break;
|
|
|
|
case ECF_R5G6B5:
|
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RGB;
|
|
|
|
pixelFormat = GL_RGB;
|
|
|
|
pixelType = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
break;
|
|
|
|
case ECF_R8G8B8:
|
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RGB;
|
|
|
|
pixelFormat = GL_RGB;
|
|
|
|
pixelType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case ECF_A8R8G8B8:
|
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
pixelFormat = GL_BGRA_EXT;
|
|
|
|
if (Version > 101)
|
|
|
|
pixelType = GL_UNSIGNED_INT_8_8_8_8_REV;
|
|
|
|
break;
|
|
|
|
case ECF_D16:
|
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_DEPTH_COMPONENT16;
|
|
|
|
pixelFormat = GL_DEPTH_COMPONENT;
|
|
|
|
pixelType = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
|
|
|
case ECF_D32:
|
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_DEPTH_COMPONENT32;
|
|
|
|
pixelFormat = GL_DEPTH_COMPONENT;
|
|
|
|
pixelType = GL_UNSIGNED_INT;
|
|
|
|
break;
|
|
|
|
case ECF_D24S8:
|
|
|
|
#ifdef GL_VERSION_3_0
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Version >= 300) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_DEPTH_STENCIL;
|
|
|
|
pixelFormat = GL_DEPTH_STENCIL;
|
|
|
|
pixelType = GL_UNSIGNED_INT_24_8;
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GL_EXT_packed_depth_stencil
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_EXT_packed_depth_stencil)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_DEPTH_STENCIL_EXT;
|
|
|
|
pixelFormat = GL_DEPTH_STENCIL_EXT;
|
|
|
|
pixelType = GL_UNSIGNED_INT_24_8_EXT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case ECF_R8:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_R8;
|
|
|
|
pixelFormat = GL_RED;
|
|
|
|
pixelType = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_R8G8:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RG8;
|
|
|
|
pixelFormat = GL_RG;
|
|
|
|
pixelType = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_R16:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_R16;
|
|
|
|
pixelFormat = GL_RED;
|
|
|
|
pixelType = GL_UNSIGNED_SHORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_R16G16:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RG16;
|
|
|
|
pixelFormat = GL_RG;
|
|
|
|
pixelType = GL_UNSIGNED_SHORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_R16F:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_R16F;
|
|
|
|
pixelFormat = GL_RED;
|
|
|
|
#ifdef GL_ARB_half_float_pixel
|
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_half_float_pixel))
|
|
|
|
pixelType = GL_HALF_FLOAT_ARB;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
pixelType = GL_FLOAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_G16R16F:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RG16F;
|
|
|
|
pixelFormat = GL_RG;
|
|
|
|
#ifdef GL_ARB_half_float_pixel
|
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_half_float_pixel))
|
|
|
|
pixelType = GL_HALF_FLOAT_ARB;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
pixelType = GL_FLOAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_A16B16G16R16F:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RGBA16F_ARB;
|
|
|
|
pixelFormat = GL_RGBA;
|
|
|
|
#ifdef GL_ARB_half_float_pixel
|
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_half_float_pixel))
|
|
|
|
pixelType = GL_HALF_FLOAT_ARB;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
pixelType = GL_FLOAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_R32F:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_R32F;
|
|
|
|
pixelFormat = GL_RED;
|
|
|
|
pixelType = GL_FLOAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_G32R32F:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RG32F;
|
|
|
|
pixelFormat = GL_RG;
|
|
|
|
pixelType = GL_FLOAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECF_A32B32G32R32F:
|
2024-03-20 19:35:52 +01:00
|
|
|
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
supported = true;
|
|
|
|
internalFormat = GL_RGBA32F_ARB;
|
|
|
|
pixelFormat = GL_RGBA;
|
|
|
|
pixelType = GL_FLOAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
COpenGLDriver::E_OPENGL_FIXED_PIPELINE_STATE COpenGLDriver::getFixedPipelineState() const
|
|
|
|
{
|
|
|
|
return FixedPipelineState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COpenGLDriver::setFixedPipelineState(COpenGLDriver::E_OPENGL_FIXED_PIPELINE_STATE state)
|
|
|
|
{
|
|
|
|
FixedPipelineState = state;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const SMaterial &COpenGLDriver::getCurrentMaterial() const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return Material;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLCacheHandler *COpenGLDriver::getCacheHandler() const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return CacheHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_OPENGL_
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager)
|
|
|
|
{
|
2023-10-03 20:37:00 +02:00
|
|
|
#ifdef _IRR_COMPILE_WITH_OPENGL_
|
2024-03-20 19:35:52 +01:00
|
|
|
COpenGLDriver *ogl = new COpenGLDriver(params, io, contextManager);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!ogl->initDriver()) {
|
|
|
|
ogl->drop();
|
|
|
|
ogl = 0;
|
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
return ogl;
|
2023-10-03 20:37:00 +02:00
|
|
|
#else
|
2024-03-20 19:35:52 +01:00
|
|
|
return 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
}
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
} // end namespace
|