void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } glUseProgram(MeshShader::ObjectPass2Shader::Program); MeshShader::ObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0, 1, 2, 3); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0); }
void drawCaustics(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } setTexture(1, getTextureGLuint(irr_driver->getTexture(file_manager->getAsset("textures/caustics.png").c_str())), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); setTexture(4, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } glUseProgram(MeshShader::CausticsShader::Program); MeshShader::CausticsShader::setUniforms(ModelViewProjectionMatrix, dir, dir2, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0, 2, 3, 4, 1); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0); }
void ParticleSystemProxy::setEmitter(scene::IParticleEmitter* emitter) { CParticleSystemSceneNode::setEmitter(emitter); if (!emitter || !isGPUParticleType(emitter->getType())) return; has_height_map = false; flip = false; count = emitter->getMaxParticlesPerSecond() * emitter->getMaxLifeTime() / 1000; switch (emitter->getType()) { case scene::EPET_POINT: generateParticlesFromPointEmitter(emitter); break; case scene::EPET_BOX: generateParticlesFromBoxEmitter(static_cast<scene::IParticleBoxEmitter *>(emitter)); break; case scene::EPET_SPHERE: generateParticlesFromSphereEmitter(static_cast<scene::IParticleSphereEmitter *>(emitter)); break; default: assert(0 && "Wrong particle type"); } glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); video::ITexture *tex = getMaterial(0).getTexture(0); compressTexture(tex, true, true); texture = getTextureGLuint(getMaterial(0).getTexture(0)); }
void draw2DVertexPrimitiveList(video::ITexture *tex, const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, video::E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, video::E_INDEX_TYPE iType) { if (!irr_driver->isGLSL()) { irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); return; } GLuint tmpvao, tmpvbo, tmpibo; primitiveCount += 2; glGenVertexArrays(1, &tmpvao); glBindVertexArray(tmpvao); glGenBuffers(1, &tmpvbo); glBindBuffer(GL_ARRAY_BUFFER, tmpvbo); glBufferData(GL_ARRAY_BUFFER, vertexCount * getVertexPitchFromType(vType), vertices, GL_STREAM_DRAW); glGenBuffers(1, &tmpibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tmpibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, primitiveCount * sizeof(u16), indexList, GL_STREAM_DRAW); VertexUtils::bindVertexArrayAttrib(vType); glUseProgram(UIShader::Primitive2DList::getInstance()->Program); UIShader::Primitive2DList::getInstance()->setUniforms(); const video::SOverrideMaterial &m = irr_driver->getVideoDriver()->getOverrideMaterial(); compressTexture(tex, false); UIShader::Primitive2DList::getInstance()->SetTextureUnits({ getTextureGLuint(tex) }); glDrawElements(GL_TRIANGLE_FAN, primitiveCount, GL_UNSIGNED_SHORT, 0); glDeleteVertexArrays(1, &tmpvao); glDeleteBuffers(1, &tmpvbo); glDeleteBuffers(1, &tmpibo); }
RainNode::RainNode(scene::ISceneManager* mgr, ITexture *tex) : GPUParticle(0, mgr, tex) { RenderProgram = LoadProgram(file_manager->getAsset("shaders/rain.vert").c_str(), file_manager->getAsset("shaders/rain.frag").c_str()); loc_screenw = glGetUniformLocation(RenderProgram, "screenw"); loc_screen = glGetUniformLocation(RenderProgram, "screen"); loc_invproj = glGetUniformLocation(RenderProgram, "invproj"); texloc_tex = glGetUniformLocation(RenderProgram, "tex"); texloc_normal_and_depths = glGetUniformLocation(RenderProgram, "normals_and_depth"); const char *varyings[] = { "currentPosition" }; SimulationProgram = LoadTFBProgram(file_manager->getAsset("shaders/rainsim.vert").c_str(), varyings, 1); loc_campos = glGetUniformLocation(SimulationProgram, "campos"); loc_viewm = glGetUniformLocation(SimulationProgram, "viewm"); loc_time = glGetUniformLocation(SimulationProgram, "time"); count = 2500; area = 3500; u32 i; float x, y, z, vertices[7500]; for (i = 0; i < count; i++) { x = ((rand() % area) - area / 2) / 100.0f; y = ((rand() % 2400)) / 100.0f; z = ((rand() % area) - area / 2) / 100.0f; vertices[3 * i] = x; vertices[3 * i + 1] = y; vertices[3 * i + 2] = z; } texture = getTextureGLuint(tex); normal_and_depth = getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); glGenBuffers(2, tfb_vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[0]); glBufferData(GL_ARRAY_BUFFER, 3 * count * sizeof(float), vertices, GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[1]); glBufferData(GL_ARRAY_BUFFER, 3 * count * sizeof(float), 0, GL_STREAM_DRAW); box.addInternalPoint(vector3df((float)(-area / 2))); box.addInternalPoint(vector3df((float)(area / 2))); }
void ParticleSystemProxy::setEmitter(scene::IParticleEmitter* emitter) { CParticleSystemSceneNode::setEmitter(emitter); if (!emitter || !isGPUParticleType(emitter->getType())) return; has_height_map = false; flip = false; // Pass a fake material type to force irrlicht to update its internal states on rendering setMaterialType(irr_driver->getShader(ES_RAIN)); setAutomaticCulling(0); count = emitter->getMaxParticlesPerSecond() * emitter->getMaxLifeTime() / 1000; switch (emitter->getType()) { case scene::EPET_POINT: generateParticlesFromPointEmitter(emitter); break; case scene::EPET_BOX: generateParticlesFromBoxEmitter(static_cast<scene::IParticleBoxEmitter *>(emitter)); break; case scene::EPET_SPHERE: generateParticlesFromSphereEmitter(static_cast<scene::IParticleSphereEmitter *>(emitter)); break; default: assert(0 && "Wrong particle type"); } glBindBuffer(GL_ARRAY_BUFFER, 0); texture = getTextureGLuint(getMaterial(0).getTexture(0)); normal_and_depth = getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); if (SimpleSimulationShader::Program && SimpleParticleRender::Program && FlipParticleRender::Program && HeightmapSimulationShader::Program) return; SimpleSimulationShader::init(); HeightmapSimulationShader::init(); SimpleParticleRender::init(); FlipParticleRender::init(); }
void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } glUseProgram(MeshShader::UntexturedObjectShader::Program); MeshShader::UntexturedObjectShader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0); }
static void SetTexture(GLMesh &mesh, unsigned i, bool isSrgb) { if (!mesh.textures[i]) mesh.textures[i] = getUnicolorTexture(video::SColor(255, 255, 255, 255)); compressTexture(mesh.textures[i], isSrgb); if (UserConfigParams::m_azdo) { if (!mesh.TextureHandles[i]) mesh.TextureHandles[i] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[i]), MeshShader::ObjectPass1Shader::getInstance()->SamplersId[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[i])) glMakeTextureHandleResidentARB(mesh.TextureHandles[i]); } }
void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) { DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE); GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; computeMVP(ModelViewProjectionMatrix); core::matrix4 ModelViewMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW); ModelViewMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD); // Generate displace mask // Use RTT_TMP4 as displace mask irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_TMP4), false, false); glUseProgram(MeshShader::DisplaceMaskShader::Program); MeshShader::DisplaceMaskShader::setUniforms(ModelViewProjectionMatrix); assert(mesh.vao_displace_mask_pass); glBindVertexArray(mesh.vao_displace_mask_pass); glDrawElements(ptype, count, itype, 0); // Render the effect if (!displaceTex) displaceTex = irr_driver->getTexture(FileManager::TEXTURE, "displace.png"); irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_DISPLACE), false, false); setTexture(0, getTextureGLuint(displaceTex), GL_LINEAR, GL_LINEAR, true); setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP4)), GL_LINEAR, GL_LINEAR, true); setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_COLOR)), GL_LINEAR, GL_LINEAR, true); glUseProgram(MeshShader::DisplaceShader::Program); MeshShader::DisplaceShader::setUniforms(ModelViewProjectionMatrix, ModelViewMatrix, core::vector2df(cb->getDirX(), cb->getDirY()), core::vector2df(cb->getDir2X(), cb->getDir2Y()), core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0, 1, 2); assert(mesh.vao_displace_pass); glBindVertexArray(mesh.vao_displace_pass); glDrawElements(ptype, count, itype, 0); }
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) { irr_driver->IncreaseObjectCount(); const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; float transparency = 1.; GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); MeshShader::BubbleShader::setUniforms(ModelViewProjectionMatrix, 0, time, transparency); glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); }
void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) { DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE); GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; computeMVP(ModelViewProjectionMatrix); core::matrix4 ModelViewMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW); ModelViewMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD); setTexture(0, getTextureGLuint(irr_driver->getTexture(FileManager::TEXTURE, "displace.png")), GL_LINEAR, GL_LINEAR, true); glUseProgram(MeshShader::DisplaceShader::Program); MeshShader::DisplaceShader::setUniforms(ModelViewProjectionMatrix, ModelViewMatrix, cb->getDirX(), cb->getDirY(), cb->getDir2X(), cb->getDir2Y(), 0); glBindVertexArray(mesh.vao_displace_pass); glDrawElements(ptype, count, itype, 0); }
void STKMeshSceneNode::render() { irr::video::IVideoDriver* driver = irr_driver->getVideoDriver(); if (!Mesh || !driver) return; ++PassCount; updateNoGL(); updateGL(); bool isTransparent; for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) { scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); if (!mb) continue; video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType; video::IMaterialRenderer* rnd = driver->getMaterialRenderer(type); isTransparent = rnd->isTransparent(); break; } if ((irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS) && immediate_draw && !isTransparent) { core::matrix4 invmodel; AbsoluteTransformation.getInverse(invmodel); glDisable(GL_CULL_FACE); if (update_each_frame) updatevbo(); glUseProgram(MeshShader::ObjectPass1Shader::getInstance()->Program); // Only untextured for (unsigned i = 0; i < GLmeshes.size(); i++) { irr_driver->IncreaseObjectCount(); GLMesh &mesh = GLmeshes[i]; GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); if (UserConfigParams::m_azdo) { if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::TransparentFogShader::getInstance()->SamplersId[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); MeshShader::ObjectPass1Shader::getInstance()->SetTextureHandles(createVector<uint64_t>(mesh.TextureHandles[0])); } else MeshShader::ObjectPass1Shader::getInstance()->SetTextureUnits(std::vector < GLuint > { getTextureGLuint(mesh.textures[0]) }); MeshShader::ObjectPass1Shader::getInstance()->setUniforms(AbsoluteTransformation, invmodel); assert(mesh.vao); glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); glBindVertexArray(0); } glEnable(GL_CULL_FACE); return; } if (irr_driver->getPhase() == SOLID_LIT_PASS && immediate_draw && !isTransparent) { core::matrix4 invmodel; AbsoluteTransformation.getInverse(invmodel); glDisable(GL_CULL_FACE); if (update_each_frame && !UserConfigParams::m_dynamic_lights) updatevbo(); glUseProgram(MeshShader::ObjectPass2Shader::getInstance()->Program); // Only untextured for (unsigned i = 0; i < GLmeshes.size(); i++) { irr_driver->IncreaseObjectCount(); GLMesh &mesh = GLmeshes[i]; GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; if (UserConfigParams::m_azdo) { GLuint64 DiffuseHandle = glGetTextureSamplerHandleARB(irr_driver->getRenderTargetTexture(RTT_DIFFUSE), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[0]); if (!glIsTextureHandleResidentARB(DiffuseHandle)) glMakeTextureHandleResidentARB(DiffuseHandle); GLuint64 SpecularHandle = glGetTextureSamplerHandleARB(irr_driver->getRenderTargetTexture(RTT_SPECULAR), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[1]); if (!glIsTextureHandleResidentARB(SpecularHandle)) glMakeTextureHandleResidentARB(SpecularHandle); GLuint64 SSAOHandle = glGetTextureSamplerHandleARB(irr_driver->getRenderTargetTexture(RTT_HALF1_R), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[2]); if (!glIsTextureHandleResidentARB(SSAOHandle)) glMakeTextureHandleResidentARB(SSAOHandle); if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::TransparentFogShader::getInstance()->SamplersId[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); MeshShader::ObjectPass2Shader::getInstance()->SetTextureHandles(createVector<uint64_t>(DiffuseHandle, SpecularHandle, SSAOHandle, mesh.TextureHandles[0])); } else MeshShader::ObjectPass2Shader::getInstance()->SetTextureUnits(createVector<GLuint>( irr_driver->getRenderTargetTexture(RTT_DIFFUSE), irr_driver->getRenderTargetTexture(RTT_SPECULAR), irr_driver->getRenderTargetTexture(RTT_HALF1_R), getTextureGLuint(mesh.textures[0]))); MeshShader::ObjectPass2Shader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix); assert(mesh.vao); glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); glBindVertexArray(0); } glEnable(GL_CULL_FACE); return; } if (irr_driver->getPhase() == GLOW_PASS) { glUseProgram(MeshShader::ColorizeShader::getInstance()->Program); for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) { scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); if (!mb) continue; if (irr_driver->hasARB_base_instance()) glBindVertexArray(VAOManager::getInstance()->getVAO(video::EVT_STANDARD)); else glBindVertexArray(GLmeshes[i].vao); drawGlow(GLmeshes[i]); } } if (irr_driver->getPhase() == TRANSPARENT_PASS && isTransparent) { ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); if (immediate_draw) { if (update_each_frame) updatevbo(); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); if (World::getWorld() && World::getWorld()->isFogEnabled()) { glUseProgram(MeshShader::TransparentFogShader::getInstance()->Program); for (unsigned i = 0; i < GLmeshes.size(); i++) { GLMesh &mesh = GLmeshes[i]; irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; const Track * const track = World::getWorld()->getTrack(); // This function is only called once per frame - thus no need for setters. const float fogmax = track->getFogMax(); const float startH = track->getFogStartHeight(); const float endH = track->getFogEndHeight(); const float start = track->getFogStart(); const float end = track->getFogEnd(); const video::SColor tmpcol = track->getFogColor(); video::SColorf col(tmpcol.getRed() / 255.0f, tmpcol.getGreen() / 255.0f, tmpcol.getBlue() / 255.0f); compressTexture(mesh.textures[0], true); if (UserConfigParams::m_azdo) { if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::TransparentFogShader::getInstance()->SamplersId[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); MeshShader::TransparentFogShader::getInstance()->SetTextureHandles(createVector<uint64_t>(mesh.TextureHandles[0])); } else MeshShader::TransparentFogShader::getInstance()->SetTextureUnits(std::vector<GLuint>{ getTextureGLuint(mesh.textures[0]) }); MeshShader::TransparentFogShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col); assert(mesh.vao); glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); glBindVertexArray(0); } } else { glUseProgram(MeshShader::TransparentShader::getInstance()->Program); for (unsigned i = 0; i < GLmeshes.size(); i++) { irr_driver->IncreaseObjectCount(); GLMesh &mesh = GLmeshes[i]; GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); if (UserConfigParams::m_azdo) { if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::TransparentShader::getInstance()->SamplersId[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); MeshShader::TransparentShader::getInstance()->SetTextureHandles(createVector<uint64_t>(mesh.TextureHandles[0])); } else MeshShader::TransparentShader::getInstance()->SetTextureUnits(std::vector<GLuint>{ getTextureGLuint(mesh.textures[0]) }); MeshShader::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix); assert(mesh.vao); glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); glBindVertexArray(0); } } return; } } }
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb) { GLMesh result = {}; if (!mb) return result; glBindVertexArray(0); glGenBuffers(1, &(result.vertex_buffer)); glGenBuffers(1, &(result.index_buffer)); glBindBuffer(GL_ARRAY_BUFFER, result.vertex_buffer); const void* vertices = mb->getVertices(); const u32 vertexCount = mb->getVertexCount(); const irr::video::E_VERTEX_TYPE vType = mb->getVertexType(); result.Stride = getVertexPitchFromType(vType); const c8* vbuf = static_cast<const c8*>(vertices); glBufferData(GL_ARRAY_BUFFER, vertexCount * result.Stride, vbuf, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.index_buffer); const void* indices = mb->getIndices(); u32 indexCount = mb->getIndexCount(); GLenum indexSize; switch (mb->getIndexType()) { case irr::video::EIT_16BIT: { indexSize = sizeof(u16); result.IndexType = GL_UNSIGNED_SHORT; break; } case irr::video::EIT_32BIT: { indexSize = sizeof(u32); result.IndexType = GL_UNSIGNED_INT; break; } default: { assert(0 && "Wrong index size"); } } glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); result.IndexCount = mb->getIndexCount(); switch (mb->getPrimitiveType()) { case scene::EPT_POINTS: result.PrimitiveType = GL_POINTS; break; case scene::EPT_TRIANGLE_STRIP: result.PrimitiveType = GL_TRIANGLE_STRIP; break; case scene::EPT_TRIANGLE_FAN: result.PrimitiveType = GL_TRIANGLE_FAN; break; case scene::EPT_LINES: result.PrimitiveType = GL_LINES; break; case scene::EPT_TRIANGLES: result.PrimitiveType = GL_TRIANGLES; break; case scene::EPT_POINT_SPRITES: case scene::EPT_LINE_LOOP: case scene::EPT_POLYGON: case scene::EPT_LINE_STRIP: case scene::EPT_QUAD_STRIP: case scene::EPT_QUADS: assert(0 && "Unsupported primitive type"); } ITexture *tex; for (unsigned i = 0; i < 6; i++) { tex = mb->getMaterial().getTexture(i); if (tex) result.textures[i] = getTextureGLuint(tex); else result.textures[i] = 0; } return result; }
void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; // Texlayout setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail0 setTexture(1, mesh.textures[2], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail1 setTexture(2, mesh.textures[3], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail2 setTexture(3, mesh.textures[4], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail3 setTexture(4, mesh.textures[5], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } // Diffuse setTexture(5, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); // Specular setTexture(6, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); // SSAO setTexture(7, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } glUseProgram(MeshShader::SplattingShader::Program); MeshShader::SplattingShader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3, 4, 5, 6, 7); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0); }
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha) { if (AlreadyTransformedTexture.find(tex) != AlreadyTransformedTexture.end()) return; AlreadyTransformedTexture.insert(tex); glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex)); std::string cached_file; if (CVS->isTextureCompressionEnabled()) { // Try to retrieve the compressed texture in cache std::string tex_name = irr_driver->getTextureName(tex); if (!tex_name.empty()) { cached_file = file_manager->getTextureCacheLocation(tex_name) + ".gltz"; if (!file_manager->fileIsNewer(tex_name, cached_file)) { if (loadCompressedTexture(cached_file)) return; } } } size_t w = tex->getSize().Width, h = tex->getSize().Height; unsigned char *data = new unsigned char[w * h * 4]; memcpy(data, tex->lock(), w * h * 4); tex->unlock(); unsigned internalFormat, Format; if (tex->hasAlpha()) Format = GL_BGRA; else Format = GL_BGR; if (premul_alpha) { for (unsigned i = 0; i < w * h; i++) { float alpha = data[4 * i + 3]; if (alpha > 0.) alpha = pow(alpha / 255.f, 1.f / 2.2f); data[4 * i] = (unsigned char)(data[4 * i] * alpha); data[4 * i + 1] = (unsigned char)(data[4 * i + 1] * alpha); data[4 * i + 2] = (unsigned char)(data[4 * i + 2] * alpha); } } if (!CVS->isTextureCompressionEnabled()) { if (srgb) internalFormat = (tex->hasAlpha()) ? GL_SRGB_ALPHA : GL_SRGB; else internalFormat = (tex->hasAlpha()) ? GL_RGBA : GL_RGB; } else { if (srgb) internalFormat = (tex->hasAlpha()) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_SRGB_S3TC_DXT1_EXT; else internalFormat = (tex->hasAlpha()) ? GL_COMPRESSED_RGBA_S3TC_DXT5_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT; } glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, Format, GL_UNSIGNED_BYTE, (GLvoid *)data); glGenerateMipmap(GL_TEXTURE_2D); delete[] data; if (CVS->isTextureCompressionEnabled() && !cached_file.empty()) { // Save the compressed texture in the cache for later use. saveCompressedTexture(cached_file); } }