VertexArrayObjectPtr VaoFactory::create(const VaoLayout& vao_layout) { auto vao = std::make_shared<VertexArrayObject>(); vao->bind(); for (const BufferUse &used_buffer : vao_layout.get_used_buffers()) { if (used_buffer.type != GL_ARRAY_BUFFER) { // activate used_buffer.name with type used_buffer.type used_buffer.buffer->bind_as(used_buffer.type); } } BufferObjectPtr active_buffer = nullptr; for (const BufferVertexAttribDefinition &def : vao_layout.get_definitions()) { if (active_buffer != def.buffer) { def.buffer->bind(); // or bind_as(GL_ARRAY_BUFFER)? active_buffer = def.buffer; } glVertexAttribPointer(def.index, def.size_per_index, def.data_type, def.normalized, def.stride, reinterpret_cast<const void*>(def.offset)); glEnableVertexAttribArray(def.index); if (def.divisor > 0) { glVertexAttribDivisor(def.index, def.divisor); } } vao->unbind(); for (const BufferUse &used_buffer : vao_layout.get_used_buffers()) { // deactivate used_buffer used_buffer.buffer->unbind(); } return vao; }
/// This method is called when the (remote) subscriber is being /// released. This method will return a 0 if the subscriber_id is /// successfully disassociated with the publisher_id *and* there /// are still other subscribers associated with the publisher_id. /// This method will return 1 if, after the disassociation, the /// publisher_id is no longer associated with any subscribers (which /// also means it's element was removed from our map_). int OpenDDS::DCPS::ReceiveListenerSetMap::release_subscriber(RepoId publisher_id, RepoId subscriber_id) { DBG_ENTRY_LVL("ReceiveListenerSetMap","release_subscriber",6); ReceiveListenerSet_rch listener_set; if (OpenDDS::DCPS::find(map_, publisher_id, listener_set) != 0) { GuidConverter converter(publisher_id); ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ReciveListenerSetMap::release_subscriber: ") ACE_TEXT("publisher %C not found in map_.\n"), OPENDDS_STRING(converter).c_str())); // Return 1 to indicate that the publisher_id is no longer associated // with any subscribers at all. return 1; } int result = listener_set->remove(subscriber_id); // Ignore the result ACE_UNUSED_ARG(result); if (listener_set->size() == 0) { if (unbind(map_, publisher_id) != 0) { GuidConverter converter(publisher_id); ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::release_subscriber: ") ACE_TEXT("failed to remove empty ReceiveListenerSet for ") ACE_TEXT("publisher %C.\n"), OPENDDS_STRING(converter).c_str())); } // We always return 1 if we know the publisher_id is no longer // associated with any ReceiveListeners. return 1; } // There are still ReceiveListeners associated with the publisher_id. // We return a 0 in this case. return 0; }
// simple support, only for rgba images PBO& PBO::setup(int nWidth, int nHeight, GLenum nColorType) { width = nWidth; height = nHeight; color_type = nColorType; buffer_size = width * height * 4; unbind(); // see note in header. glBindTexture(GL_TEXTURE_2D, texture_id); eglGetError(); glEnable(GL_TEXTURE_2D); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); eglGetError(); glTexImage2D( GL_TEXTURE_2D, 0 ,GL_RGBA, width, height, 0 ,color_type, GL_UNSIGNED_BYTE, NULL );eglGetError(); //unbind(); return *this; }
void Texture :: quad(Graphics& gl, double w, double h, double x0, double y0){ //Graphics::error(id(), "prebind quad texture"); bind(); Mesh& m = gl.mesh(); m.reset(); //Graphics::error(id(), "reset mesh quad texture"); m.primitive(gl.TRIANGLE_STRIP); m.texCoord ( 0, 0); m.vertex (x0, y0, 0); m.texCoord ( 1, 0); m.vertex (x0+w, y0, 0); m.texCoord ( 0, 1); m.vertex (x0, y0+h, 0); m.texCoord ( 1, 1); m.vertex (x0+w, y0+h, 0); //Graphics::error(id(), "set mesh quad texture"); gl.draw(m); //Graphics::error(id(), "draw mesh quad texture"); unbind(); }
//-------------------------------------------------------------- void ofVbo::drawElementsInstanced(int drawMode, int amt, int primCount) { if(bAllocated){ bool hadVAOChnaged = vaoChanged; bool wasBinded = bBound; if(!wasBinded) bind(); if(bUsingIndices){ if((supportVAOs && hadVAOChnaged) || !supportVAOs) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId); #ifdef TARGET_OPENGLES // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 // unfortunately there is currently no easy way within oF to query the current OpenGL version. // https://www.khronos.org/opengles/sdk/docs/man3/xhtml/glDrawElementsInstanced.xml ofLogWarning("ofVbo") << "drawElementsInstanced(): hardware instancing is not supported on OpenGL ES < 3.0"; // glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_SHORT, NULL, primCount); #else glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_INT, NULL, primCount); #endif } if(!wasBinded) unbind(); } }
FBO& FBO::addTexture(int nAttachmentPoint) { bind(); // we only use RGBA, 2D textures for now. GLuint tex_id; glGenTextures(1, &tex_id); eglGetError(); glBindTexture(GL_TEXTURE_2D, tex_id); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); eglGetError(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); eglGetError(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width , height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); eglGetError(); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 +nAttachmentPoint, GL_TEXTURE_2D, tex_id, 0); eglGetError(); eglCheckFramebufferStatus(); glBindTexture(GL_TEXTURE_2D,0); // unbind texture textures.insert(std::pair<int, GLuint>(nAttachmentPoint, tex_id)); unbind(); return *this; }
// This version removes an entire RepoIdSet from the map_. OpenDDS::DCPS::RepoIdSet* OpenDDS::DCPS::RepoIdSetMap::remove_set(RepoId key) { DBG_ENTRY_LVL("RepoIdSetMap","remove_set",6); RepoIdSet_rch value; if (unbind(map_, key, value) != 0) { if (DCPS_debug_level > 4) { RepoIdConverter converter(key); ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) RepeIdSetMap::remove_set: ") ACE_TEXT("RepoId %C not found in map.\n"), std::string(converter).c_str())); } return 0; } return value._retn(); }
bool GL_RenderBuffer::check() { bind(); setBufferState(); GLenum status; status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) { LogWarn("GL_RenderBuffer error: %s", glErrorString(status) ); return false; } unbind(); valid = true; return true; }
void commit(size_t plane_index) { if(plane_index >= buffers_.size()) return; auto buffer = std::move(buffers_[plane_index]); // Release buffer once done. if(!buffer) return; auto texture = textures_.at(plane_index); ogl_->begin_invoke([=] { buffer->unmap(); buffer->bind(); texture->begin_read(); buffer->unbind(); }, high_priority); }
Gre::RenderFramebufferHolder DarwinGlContext::iCreateFramebuffer(const std::string &name) const { // We create a DarwinGlRenderFramebuffer object here, using this object as the binded // RenderContext. This allows us to be sure the RenderFramebuffer is created under the // correct RenderContext , and not another RenderContext ( like the global one ). if ( iGetCurrentBindedContext() == iContext ) { return Gre::RenderFramebufferHolder ( new DarwinGlRenderFramebuffer(name) ); } else { bind(); Gre::RenderFramebufferHolder fbo ( new DarwinGlRenderFramebuffer(name) ); unbind(); return fbo; } }
void ShaderPhong::unsetAttributeColor() { m_vboColor = NULL; if (m_with_color) { m_with_color = false; // unbind the VA bind(); unbindVA("VertexColor"); unbind(); // recompile shader std::string gl3vert(GLSLShader::defines_gl()); gl3vert.append(vertexShaderText); std::string gl3frag(GLSLShader::defines_gl()); gl3frag.append(fragmentShaderText); loadShadersFromMemory(gl3vert.c_str(), gl3frag.c_str()); // and treat uniforms getLocations(); sendParams(); } }
void ofBufferObject::unmap(){ if(!this->data) return; #ifdef GLEW_ARB_direct_state_access if (GLEW_ARB_direct_state_access) { glUnmapNamedBuffer(data->id); return; } #endif /// --------| invariant: direct state access is not available if(!data->isBound){ glBindBuffer(data->lastTarget, data->id); } glUnmapBuffer(data->lastTarget); if(!data->isBound){ unbind(data->lastTarget); } }
void do_testing (int argc, char *argv[], int light) { ACE_Profile_Timer timer; ACE_Naming_Context ns_context; ACE_Name_Options *name_options = ns_context.name_options (); name_options->parse_args (argc, argv); if (light == 0) // Use SYNC { name_options->database (ACE::basename (name_options->process_name (), ACE_DIRECTORY_SEPARATOR_CHAR)); ns_context.open (ACE_Naming_Context::PROC_LOCAL); } else // Use NO-SYNC { const char *p = ACE::basename (name_options->process_name (), ACE_DIRECTORY_SEPARATOR_CHAR); char s[5 /* strlen ("light") */ + MAXNAMELEN + 1]; ACE_OS::sprintf (s, "light%s", p); name_options->database (s); ns_context.open (ACE_Naming_Context::PROC_LOCAL, 1); } // Add bindings to the database ACE_DEBUG ((LM_DEBUG, "Binding\n")); timer.start (); bind (&ns_context, 0); ACE_DEBUG ((LM_DEBUG, "Unbinding\n")); unbind (&ns_context, 0); timer.stop (); ACE_Profile_Timer::ACE_Elapsed_Time et; timer.elapsed_time (et); ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n", et.real_time, et.user_time, et.system_time)); }
bool RTexture::set(GLsizei width, GLsizei height, const GLvoid *pixels, int index, int level, GLint format, GLint border, GLenum type) { data_p().mWidth = width; data_p().mHeight = height; if (!this->data_p().create()) { return false; } bind(index); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); RCheckGLError(); glTexImage2D(GL_TEXTURE_2D, level, format, width, height, border, format, type, pixels); RCheckGLError(); GLenum error = glGetError(); if (error != GL_NO_ERROR) { rLogE() << "glGetError() " << error << std::endl; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, this->data_p().mMagFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, this->data_p().mMinFilter); if (this->data_p().mGenerateMipmap) { glGenerateMipmap(GL_TEXTURE_2D); } RCheckGLError(); unbind(); return true; }
// generates a red/green image mask: red = x-coordinate, gren = y-coordinate void Texture::genImageMask(GLsizei w, GLsizei h, bool linearFilter) { bind(); // generate image std::vector<float> image; image.resize(w*h*4); for (GLsizei y = 0; y < h; ++y) { for (GLsizei x = 0; x < w; ++x) { Gs::Vector4f color( static_cast<float>(x) / (w - 1), static_cast<float>(y) / (h - 1), 0.0f, 1.0f ); if (x == 0 || x + 1 == w || y == 0 || y + 1 == h) color = Gs::Vector4f(0.1f, 0.2f, 0.8f, 1); auto idx = (y*w + x)*4; image[idx ] = color.x; image[idx + 1] = color.y; image[idx + 2] = color.z; image[idx + 3] = color.w; } } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_FLOAT, image.data()); // setup texture parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (linearFilter ? GL_LINEAR : GL_NEAREST)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (linearFilter ? GL_LINEAR : GL_NEAREST)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); unbind(); }
int apply(int func, int args){ int symaddr,lamlis,body,res; symaddr = findsym(func); if(symaddr == 0) error(CANT_FIND_ERR, "apply", func); else { switch(GET_TAG(symaddr)){ case SUBR: return((GET_SUBR(symaddr))(args)); case FSUBR: return((GET_SUBR(symaddr))(args)); case LAMBDA: { lamlis = car(GET_BIND(symaddr)); body = cdr(GET_BIND(symaddr)); bindarg(lamlis,args); while(!(IS_NIL(body))){ res = eval(car(body)); body = cdr(body); } unbind(); return(res); } } } }
void GL_RenderBuffer::createRenderBuffer( RenderBufferType bufferComponents ) { // Render buffers are just objects which are used to support // offscreen rendering, often for sections of the framebuffer which // don’t have a texture format associated with them. if( !checkSize() ) return; GLuint renderBuffer; glGenRenderbuffersEXT(1, &renderBuffer); CheckLastErrorGL( "Could not generate renderbuffer object" ); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer); CheckLastErrorGL( "Could not bind renderbuffer object" ); bind(); if( BitwiseAnd(bufferComponents, RenderBufferType::Depth) ) { createRenderBufferStorage(renderBuffer, GL_DEPTH_COMPONENT, GL_DEPTH_ATTACHMENT_EXT); } if( BitwiseAnd(bufferComponents, RenderBufferType::Color) ) { createRenderBufferStorage(renderBuffer, GL_RGBA, GL_COLOR_ATTACHMENT0_EXT); colorAttach = true; } if( BitwiseAnd(bufferComponents, RenderBufferType::Stencil) ) { createRenderBufferStorage(renderBuffer, GL_STENCIL_INDEX, GL_STENCIL_ATTACHMENT_EXT); colorAttach = true; } glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); unbind(); }
void VAO::create() { if (m_vao) { destroy(); } glGenVertexArrays(1, &m_vao); bind(); for (int i = 0; i < m_buffers.size(); ++i) { glBindBuffer(m_buffers[i].m_desc.m_bufferType, m_buffers[i].m_obj->getId()); for (int j = 0; j < m_buffers[i].m_desc.m_attributes.size(); ++j) { glEnableVertexAttribArray(m_buffers[i].m_desc.m_attributes[j].m_index); glVertexAttribPointer( m_buffers[i].m_desc.m_attributes[j].m_index, m_buffers[i].m_desc.m_attributes[j].m_numComponents, m_buffers[i].m_desc.m_attributes[j].m_type, GL_FALSE, m_buffers[i].m_desc.m_attributes[j].m_interleave, (char*)0 + m_buffers[i].m_desc.m_attributes[j].m_offset); } } unbind(); //It seems like state dangles after this... for (int i = 0; i < m_buffers.size(); ++i) { glBindBuffer(m_buffers[i].m_desc.m_bufferType, 0); for (int j = 0; j < m_buffers[i].m_desc.m_attributes.size(); ++j) { glDisableVertexAttribArray(m_buffers[i].m_desc.m_attributes[j].m_index); } } }
void QtSignalForwarder::unbind(QObject* sender, const char* signal) { int signalIndex = qtObjectSignalIndex(sender, signal); QHash<QObject*,int>::iterator iter = m_senderSignalBindingIds.find(sender); while (iter != m_senderSignalBindingIds.end() && iter.key() == sender) { Q_ASSERT(m_signalBindings.contains(*iter)); const Binding& binding = m_signalBindings.value(*iter); if (binding.signalIndex == signalIndex) { m_freeSignalBindingIds << *iter; QObject* context = m_signalBindings.take(*iter).context; m_contextBindingIds.remove(context, *iter); iter = m_senderSignalBindingIds.erase(iter); } else { ++iter; } } if (!isConnected(sender)) { // disconnect destruction notifications unbind(sender); } }
int apply(char *symname, int args){ int symaddr,lamlis,body,res; symaddr = findsym(symname); if(symaddr == NIL) return(NIL); else { switch(GET_FTYPE(symaddr)){ case SUBR: return((heap[symaddr].subr)(args)); case FSUBR: return((heap[symaddr].subr)(args)); case LAMBDA: { lamlis = car(heap[symaddr].bind); body = cdr(heap[symaddr].bind); bind(lamlis,args); while(!(IS_NIL(body))){ res = eval(car(body)); body = cdr(body); } unbind(); return(res); } } } }
DepthTexture::DepthTexture(QSize& res, string name) { this->name = name; glGenTextures(1, &handle); bind(); LogDebug << "Creating FBO Depth texture #" << handle << " " << name; filterMinMag(GL_NEAREST, GL_NEAREST); // Specifies the texture comparison mode for currently bound depth textures. // That is, a texture whose internal format is GL_DEPTH_COMPONENT_* glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_NONE); // shadowmap // No need to force GL_DEPTH_COMPONENT24, // drivers usually give you the max precision if available glTexImage2D(target, 0, GL_DEPTH_COMPONENT32F, res.width(), res.height(), 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); unbind(); glError; }
void GLRenderTarget::recreate(math::vector2di newSize,EPixelFormat format,bool depthBuffer){ m_size=newSize; core::string tmpStr; bind(); for (int i{}i<m_ColorTex.size();++i) { if(m_ColorTex[i]){ //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i,GL_TEXTURE_2D, m_ColorTex[i]->getTextureID(),0); m_ColorTex[i]->recreate(format,newSize.x,newSize.y,m_numSamples); m_ColorTex[i]->bind(GL_COLOR_ATTACHMENT0_EXT+i); } else{ //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_RENDERBUFFER_EXT, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i,GL_RENDERBUFFER_EXT, 0,0); } } if(depthBuffer){ if(!m_DepthTex){ m_DepthTex=new RenderTextureBuffer(m_device,EPixel_DEPTH,m_size.x,m_size.y,m_numSamples); tmpStr=m_name+L"_DepthTex"; m_DepthTex->setResourceName(tmpStr.c_str()); }else m_DepthTex->recreate(EPixel_DEPTH,m_size.x,m_size.y,m_numSamples); m_DepthTex->bind(GL_DEPTH_ATTACHMENT_EXT); } else glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, 0); //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, 0,0); //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, 0,0); checkFrameBufferStatus(); unbind(); }
chaos::FBO::FBO(GLuint w, GLuint h, GLuint textureBuffersCount, std::initializer_list<std::pair<GLenum,GLenum> > rboList) :width(w), height(h) { for(GLuint i = 0; i < vecTextures.size(); i++) delete vecTextures[i]; vecRBO.clear(); vecTextures.clear(); glGenFramebuffers(1, &id); glBindFramebuffer(GL_FRAMEBUFFER, id); for(GLuint i = 0; i < textureBuffersCount; i++){ GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_TEXTURE_2D, textureId, 0); vecTextures.push_back(new chaos::Texture(textureId, width, height)); } for(auto rboIt: rboList){ GLuint rbo; glGenRenderbuffers(1, &rbo); glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbufferStorage(GL_RENDERBUFFER, rboIt.first, width, height); glBindRenderbuffer(GL_RENDERBUFFER, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, rboIt.second, GL_RENDERBUFFER, rbo); vecRBO.push_back(rbo); } /*if(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE){ } else{ }*/ unbind(); }
bool Texture::loadFromImage(const Image& img) { if(img.getSize().x > 0 && img.getSize().y > 0) { size = img.getSize(); bind(); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.getPixels())); glCheck(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); unbind(); created_ = true; } else { created_ = false; std::cerr << "Error loading texure from image: dimension of 0" << std::endl; } return created_; }
void nFrameBuffer::setTextureAttachment(nSRPointer<nTexture> t, uint slot) { if(!t) { attachments[slot] = 0; drawBuffers[slot] = GL_NONE; if(nGL::getState()->getFrameBufferBinding() == this) { glDrawBuffers(nGL::getState()->getHWInt(nGLState::MaxFboAttachements), drawBuffers); } setModified(); return; } nSRPointer<nTexture> attachment = attachments[slot]; if(attachment && attachment->getSize() != t->getSize()) { throw nInvalidSizeException(); } attachments[slot] = t; drawBuffers[slot] = GL_COLOR_ATTACHMENT0 + slot; bind(); t->bind(0, 0, true); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + slot, GL_TEXTURE_2D, t->getInternal()->getGLHandle(), 0); glDrawBuffers(nGL::getState()->getHWInt(nGLState::MaxFboAttachements), drawBuffers); setModified(); unbind(); }
void ShaderExplodeVolumesAlpha::restoreUniformsAttribs() { bind(); *m_unif_ambient = glGetUniformLocation(program_handler(),"ambient"); glUniform4fv(*m_unif_ambient, 1, m_ambient.data()); *m_unif_backColor = glGetUniformLocation(program_handler(),"backColor"); glUniform4fv(*m_unif_backColor, 1, m_backColor.data()); *m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition"); glUniform3fv(*m_unif_lightPos, 1, m_light_pos.data()); *m_unif_plane = glGetUniformLocation(program_handler(),"plane"); glUniform4fv(*m_unif_plane, 1, m_plane.data()); *m_unif_unit = glGetUniformLocation(program_handler(),"textureUnit"); glUniform1iARB(*m_unif_unit, 0); bindVA_VBO("VertexPosition", m_vboPos); bindVA_VBO("VertexColor", m_vboColors); unbind(); }
void VertexArray::drawInstanced(GLsizei primitiveCount, ePrimitives mode_) { bind(); GLenum mode = static_cast<GLenum>(mode_); if (mIndexBufferType == 0) glDrawArraysInstanced( mode, 0, mVertexBufferSize, primitiveCount ); else glDrawElementsInstanced( mode, mIndexBufferSize, mIndexBufferType, nullptr, primitiveCount ); unbind(); }
void gle::Texture::setData(const char* data, GLuint width, GLuint height, Target target, bool bindTexture) { if (bindTexture) bind(); if (width && height) { _width = width; _height = height; } glTexImage2D(target, // Texture type 0, // Level of detail (0 = max) _internalFormat, // Internal format _width, // Width _height, // Height 0, // This value must be 0 _internalFormat == Depth ? GL_DEPTH_COMPONENT : GL_RGBA, // Format of the pixel datas GL_UNSIGNED_BYTE, // Data type of the pixel datas data); gle::Exception::CheckOpenGLError("Texture::setData"); generateMipmap(); if (bindTexture) unbind(); }
void FBO::init(std::string depthTexName){ chkGLErr(); if(_isInit) return; _isInit = true; _depthTex = Texture::createTextureID(depthTexName); glBindTexture(GL_TEXTURE_2D, _depthTex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, _size.x, _size.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); glBindTexture(GL_TEXTURE_2D, 0); chkGLErr(); glGenFramebuffersEXT(1, &_fbo); bind(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _depthTex, 0); fboerror(); unbind(); chkGLErr(); LOG_INFO("FBO initzilized with size " << _size << " and depth buffer " << depthTexName); }
void Babar::go_down() { m_pos.y += 2 * BOX_SIZE; m_speed.y += BOX_SIZE; if (binded() ) { while (CollisionsManager::is_down_coll (m_bind->down_collision_type (m_rel_pos) ) ) { if (m_bind->double_collision (m_rel_pos) ) { m_rel_pos.y -= BOX_SIZE; break; } else { m_rel_pos.y += BOX_SIZE; } } } else { while (CollisionsManager::is_down_coll (gCollision->get_matrix()->down_collision_type (m_pos) ) ) { if (gCollision->get_matrix()->double_collision (m_pos) ) { m_pos.y -= BOX_SIZE; break; } else { m_pos.y += BOX_SIZE; } } } unbind(); PRINT_TRACE (1, "Descente d'une plateforme"); }