void OGLGraphicsBuffer::Unmap() { if (glloader_GL_EXT_direct_state_access()) { glUnmapNamedBufferEXT(vb_); } else { OGLRenderEngine& re = *checked_cast<OGLRenderEngine*>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance()); re.BindBuffer(target_, vb_); glUnmapBuffer(target_); } }
void resolveMultisampling() { { glm::mat4* Pointer = (glm::mat4*)glMapNamedBufferRangeEXT( BufferName[buffer::BLIT], 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT); glm::mat4 Perspective = glm::perspective(45.0f, float(Window.Size.x) / Window.Size.y, 0.1f, 100.0f); glm::mat4 ViewFlip = glm::scale(glm::mat4(1.0f), glm::vec3(1.0f,-1.0f, 1.0f)); glm::mat4 ViewTranslate = glm::translate(ViewFlip, glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0)); glm::mat4 View = glm::rotate(ViewTranslate,-15.f, glm::vec3(0.f, 0.f, 1.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Perspective * View * Model; *Pointer = MVP; glUnmapNamedBufferEXT(BufferName[buffer::BLIT]); //glNamedBufferSubDataEXT(BufferName[buffer::BLIT], 0, sizeof(glm::mat4), &MVP[0][0]); } glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y)); glEnable(GL_SCISSOR_TEST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::BLIT]); glBindMultiTextureEXT(GL_TEXTURE0, GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]); glBindSampler(0, SamplerName); glBindVertexArray(VertexArrayName); // Box { glScissorIndexed(0, 1, 1, Window.Size.x / 2 - 2, Window.Size.y - 2); glBindProgramPipeline(PipelineName[program::RESOLVE_BOX]); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 5, 0); } // Near { glScissorIndexed(0, Window.Size.x / 2 + 1, 1, Window.Size.x / 2 - 2, Window.Size.y - 2); glBindProgramPipeline(PipelineName[program::RESOLVE_NEAR]); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 5, 0); } glDisable(GL_SCISSOR_TEST); }
bool Buffer::unmap() { if (m_directStateAccess) { GLboolean success = glUnmapNamedBufferEXT(m_id); CheckGLError(); return success == GL_TRUE; } else { bind(); GLboolean success = glUnmapBuffer(m_target); CheckGLError(); return success == GL_TRUE; } }
void renderFBO() { { glm::mat4* Pointer = (glm::mat4*)glMapNamedBufferRangeEXT( BufferName[buffer::TRANSFORM], 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Perspective = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0 - 4.0)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Perspective * View * Model; *Pointer = MVP; glUnmapNamedBufferEXT(BufferName[buffer::TRANSFORM]); //glNamedBufferSubDataEXT(BufferName[buffer::TRANSFORM], 0, sizeof(glm::mat4), &MVP[0][0]); } glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y)); glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); float Depth(1.0f); glClearBufferfv(GL_DEPTH, 0, &Depth); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glBindProgramPipeline(PipelineName[program::THROUGH]); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindMultiTextureEXT(GL_TEXTURE0, GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glBindSampler(0, SamplerName); glBindVertexArray(VertexArrayName); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 5, 0); glDisable(GL_MULTISAMPLE); glDisable(GL_DEPTH_TEST); }
bool render() { { glm::uint8* Pointer = reinterpret_cast<glm::uint8*>(glMapNamedBufferRangeEXT(BufferName[buffer::TRANSFORM], 0, this->UniformBlockSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f); *reinterpret_cast<glm::mat4*>(Pointer + 0) = Projection * this->view() * glm::mat4(1); // Make sure the uniform buffer is uploaded glUnmapNamedBufferEXT(BufferName[buffer::TRANSFORM]); } glBindProgramPipeline(PipelineName); // Step 1: render the scene in a multisampled framebuffer renderFBO(); // Step 2: resolve MSAA glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferName[framebuffer::RESOLVE]); glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); // Step 3: Blit resolved colorbuffer. Resolve and blit can't be done in a single step glm::ivec2 const WindowSize(this->getWindowSize()); glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferName[framebuffer::RESOLVE]); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, WindowSize.x, WindowSize.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); return true; }
bool BufferImplementation_DirectStateAccessEXT::unmap(const Buffer * buffer) const { return GL_TRUE == glUnmapNamedBufferEXT(buffer->id()); }
void map_ptr::unmap() const { glUnmapNamedBufferEXT(this->Name); }
/* ============= GL_DrawAliasFrameLerp interpolates between two frames and origins FIXME: batch lerp all vertexes ============= */ void GL_DrawAliasFrameLerp (entity_t *e, dmdl_t *hdr, float backlerp) { int i; float frontlerp; float alpha; vec3_t delta, vectors[3]; daliasframe_t *currframe = (daliasframe_t *) ((byte *) hdr + hdr->ofs_frames + e->currframe * hdr->framesize); daliasframe_t *lastframe = (daliasframe_t *) ((byte *) hdr + hdr->ofs_frames + e->lastframe * hdr->framesize); meshubo_t *meshubo = NULL; GLbitfield access; if (e->flags & RF_TRANSLUCENT) alpha = e->alpha; else alpha = 1.0; frontlerp = 1.0 - backlerp; // move should be the delta back to the previous frame * backlerp VectorSubtract (e->lastorigin, e->currorigin, delta); AngleVectors (e->angles, vectors[0], vectors[1], vectors[2]); gl_meshuboupdate.move[0] = lastframe->translate[0] + DotProduct (delta, vectors[0]); // forward gl_meshuboupdate.move[1] = lastframe->translate[1] - DotProduct (delta, vectors[1]); // left gl_meshuboupdate.move[2] = lastframe->translate[2] + DotProduct (delta, vectors[2]); // up for (i = 0; i < 3; i++) { gl_meshuboupdate.move[i] = backlerp * gl_meshuboupdate.move[i] + frontlerp * currframe->translate[i]; gl_meshuboupdate.frontv[i] = frontlerp * currframe->scale[i]; gl_meshuboupdate.backv[i] = backlerp * lastframe->scale[i]; } if (!(e->flags & (RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE))) { if (gl_monolightmap->value) { float ntsc[] = {0.3f, 0.59f, 0.11f}; float gs = DotProduct (gl_meshuboupdate.shadelight, ntsc); gl_meshuboupdate.shadelight[0] = gl_meshuboupdate.shadelight[1] = gl_meshuboupdate.shadelight[2] = gs; } gl_meshuboupdate.shadelight[0] *= r_lightscale->value * 2.0f; gl_meshuboupdate.shadelight[1] *= r_lightscale->value * 2.0f; gl_meshuboupdate.shadelight[2] *= r_lightscale->value * 2.0f; gl_meshuboupdate.powersuitscale = 0.0f; gl_meshuboupdate.shellmix = 0.0f; } else { float scale = (e->flags & RF_WEAPONMODEL) ? WEAPONSHELL_SCALE : POWERSUIT_SCALE; gl_meshuboupdate.powersuitscale = scale; gl_meshuboupdate.shellmix = 1.0f; } gl_meshuboupdate.shadelight[3] = alpha; gl_meshuboupdate.lerpfrac = backlerp; if (e->model->lastcurrframe != e->currframe) { glVertexArrayVertexAttribOffsetEXT (e->model->meshvao, e->model->meshvbo, 0, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (posevert_t), VERTOFFSET (e->currframe)); e->model->lastcurrframe = e->currframe; } if (e->model->lastlastframe != e->lastframe) { glVertexArrayVertexAttribOffsetEXT (e->model->meshvao, e->model->meshvbo, 1, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (posevert_t), VERTOFFSET (e->lastframe)); e->model->lastlastframe = e->lastframe; } GL_BindVertexArray (e->model->meshvao); GL_Enable (DEPTHTEST_BIT | ((e->flags & RF_TRANSLUCENT) ? BLEND_BIT : DEPTHWRITE_BIT) | (gl_cull->value ? CULLFACE_BIT : 0)); GL_UseProgram (gl_meshprog); if (gl_meshubonumblocks + 1 >= MESH_UBO_MAX_BLOCKS) { access = BUFFER_DISCARD; gl_meshubonumblocks = 0; } else access = BUFFER_NO_OVERWRITE; if ((meshubo = glMapNamedBufferRangeEXT (gl_meshubo, gl_meshubonumblocks * gl_meshuboblocksize, sizeof (meshubo_t), access)) != NULL) { memcpy (meshubo, &gl_meshuboupdate, sizeof (meshubo_t)); glUnmapNamedBufferEXT (gl_meshubo); glBindBufferRange (GL_UNIFORM_BUFFER, gl_meshubobinding, gl_meshubo, gl_meshubonumblocks * gl_meshuboblocksize, sizeof (meshubo_t)); glDrawElements (GL_TRIANGLES, e->model->numindexes, GL_UNSIGNED_SHORT, NULL); gl_meshubonumblocks++; } }