void init2DTexture(const graphics::Context::InitTextureParams & _params) override { if (_params.msaaLevel == 0) { if (m_handle != _params.handle) { m_handle = _params.handle; glTextureStorage2D(GLuint(_params.handle), _params.mipMapLevels, GLenum(_params.internalFormat), _params.width, _params.height); } if (_params.data != nullptr) { glTextureSubImage2D(GLuint(_params.handle), _params.mipMapLevel, 0, 0, _params.width, _params.height, GLuint(_params.format), GLenum(_params.dataType), _params.data); } } else { glTexStorage2DMultisample(GLuint(_params.handle), _params.msaaLevel, GLenum(_params.internalFormat), _params.width, _params.height, GL_FALSE); } }
void ClusteredLightManager::buildClustering() { GLuint index = 0; glm::uvec4 affected_tiles; glm::uvec3 frustrum_begin; glm::uvec3 frustrum_end; for (const world::PointLight* light : this->world.p_lights) { // calculate tiles effected by light if false then no tiles are affected // and it can be skipped if (this->projector.computeProjection(*light, this->view.camera, this->view.viewport, this->tile_size, affected_tiles)) { frustrum_begin.x = affected_tiles.x; frustrum_begin.y = affected_tiles.y; frustrum_end.x = affected_tiles.z; frustrum_end.y = affected_tiles.w; // calculate z_value of light in camera space glm::vec4 light_camera_pos = view.camera.getLookAt() * light->position; frustrum_begin.z = GLuint(std::max(int(floor(log(-(light_camera_pos.z + light->radius) / view.camera.getDepthrange().x) * this->k_inv_denominator)), 0)); frustrum_end.z = GLuint(std::max(int(floor(log(-(light_camera_pos.z - light->radius) / view.camera.getDepthrange().x) * this->k_inv_denominator)), 0)); this->light_clustering.incrementLight(frustrum_begin, frustrum_end, index); } index++; } }
void RevolverTool::DataItem::writeNumber(const Point& position,int number) { /* Convert the number to a string: */ char buffer[20]; snprintf(buffer,sizeof(buffer),"%d",number); /* Calculate the number's width: */ GLfloat width=-spacing; for(const char* bPtr=buffer;*bPtr!='\0';++bPtr) { int index=*bPtr=='-'?10:int(*bPtr)-int('0'); width+=digitWidths[index]; width+=spacing; } /* Write the number: */ glPushMatrix(); glTranslated(position[0]-width*0.5f,position[1],position[2]-digitHeight*0.5f); for(const char* bPtr=buffer;*bPtr!='\0';++bPtr) { GLuint index=*bPtr=='-'?GLuint(10):GLuint(*bPtr)-GLuint('0'); glCallList(digitListBase+index); glTranslatef(digitWidths[index]+spacing,0.0f,0.0f); } glPopMatrix(); }
uint QGLEngineShaderManager::getUniformLocation(Uniform id) { QVector<uint> &uniformLocations = currentShaderProg->uniformLocations; if (uniformLocations.isEmpty()) uniformLocations.fill(GLuint(-1), NumUniforms); static const char *uniformNames[] = { "imageTexture", "patternColor", "globalOpacity", "depth", "pmvMatrix", "maskTexture", "fragmentColor", "linearData", "angle", "halfViewportSize", "fmp", "fmp2_m_radius2", "inverse_2_fmp2_m_radius2", "invertedTextureSize", "brushTransform", "brushTexture" }; if (uniformLocations.at(id) == GLuint(-1)) uniformLocations[id] = currentShaderProg->program->uniformLocation(uniformNames[id]); return uniformLocations.at(id); }
/** * @glsymbols * @glfunref{VertexArrayVertexAttribIOffsetEXT} */ const ObjectOps& VertexAttribIOffset( BufferName buffer, VertexAttribSlot location, GLint values_per_vertex, DataType data_type, GLsizei stride, GLintptr offset ) const { OGLPLUS_GLFUNC(VertexArrayVertexAttribIOffsetEXT)( _name, GetGLName(buffer), GLuint(location), values_per_vertex, GLenum(data_type), stride, offset ); OGLPLUS_CHECK( VertexArrayVertexAttribIOffsetEXT, ObjectError, Object(*this). Index(GLuint(location)) ); return *this; }
SpectraDefaultRenderer::SpectraDefaultRenderer( SpectraApp& app, const std::shared_ptr<SpectraSharedObjects>& sh_obj, const std::shared_ptr<SpectraVisualisation>& doc_vis, wxGLCanvas* canvas ): SpectraRenderer(app, sh_obj, doc_vis, canvas) , doc_vis_prog(Common().BuildProgram("default_doc_vis.prog")) , doc_vis_projection_matrix(doc_vis_prog, "ProjectionMatrix") , doc_vis_camera_matrix(doc_vis_prog, "CameraMatrix") , doc_vis_stretch_matrix(doc_vis_prog, "StretchMatrix") , doc_vis_transf_matrix(doc_vis_prog, "TransfMatrix") , doc_vis_spectrum_tex(doc_vis_prog, "SpectrumTex") , doc_vis_spectrum_size(doc_vis_prog, "SpectrumSize") , doc_vis_samples_per_unit(doc_vis_prog, "SamplesPerUnit") , doc_vis_selected_time(doc_vis_prog, "SelectedTime") , doc_vis_selection_begin(doc_vis_prog, "SelectionBegin") , doc_vis_selection_end(doc_vis_prog, "SelectionEnd") , spectrum_plane_wrap( Common().SpectrumPlane( GLuint(DocVis().GridSamples()), GLuint(DocVis().SignalSpectrumSize()) ) ), spectrum_plane_vao(spectrum_plane_wrap.VAOForProgram(doc_vis_prog)) , vis_cue_prog(Common().BuildProgram("default_vis_cue.prog")) , vis_cue_projection_matrix(vis_cue_prog, "ProjectionMatrix") , vis_cue_camera_matrix(vis_cue_prog, "CameraMatrix") , vis_cue_stretch_matrix(vis_cue_prog, "StretchMatrix") , vis_cue_transf_matrix(vis_cue_prog, "TransfMatrix") , vis_cue_color(vis_cue_prog, "Color") , vis_cue_alpha(vis_cue_prog, "Alpha") , ground_grid_vao(Common().GroundUnitGrid().VAOForProgram(vis_cue_prog)) , wall_grid_vao(Common().WallUnitGrid().VAOForProgram(vis_cue_prog)) { CacheBgColor(); }
Object::~Object() { assert(this->vertex_array_handle == GLuint(-1)); assert(this->vertex_data_handle == GLuint(-1)); assert(this->normal_array_handle == GLuint(-1)); assert(this->normal_data_handle == GLuint(-1)); }
void gfx::BloomProgram::Render(){ //Do brightpass ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_BrightPassShader); prog->Apply(); const int WORK_GROUP_SIZE = 32; GLuint WorkGroupSizeX = GLuint((m_Width + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE)); GLuint WorkGroupSizeY = GLuint((m_Height + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE)); prog->SetUniformTextureHandle("g_Image", m_TargetTex, 1); prog->SetUniformVec2("g_ScreenSize", glm::vec2(m_Width, m_Height)); prog->SetUniformFloat("g_Threshold", 0.4f); prog->SetUniformFloat("g_Smoothness", 0.8f); glBindImageTexture(0, m_BloomTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8); glDispatchCompute(WorkGroupSizeX, WorkGroupSizeY, 1); //blur result m_BlurProgram->Render(); //add to final target prog = g_ShaderBank.GetProgramFromHandle(m_BloomShader); prog->Apply(); prog->SetUniformTextureHandle("g_BluredBloomTex", m_BlurProgram->GetBluredTexture(), 1); prog->SetUniformTextureHandle("g_ColorBuffer", m_TargetTex, 2); prog->SetUniformVec2("g_ScreenSize", glm::vec2(m_Width, m_Height)); glBindImageTexture(0, m_BloomTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8); glDispatchCompute(WorkGroupSizeX, WorkGroupSizeY, 1); }
/** * @see GetLocation * @see QueryLocation * * @glsymbols * @glfunref{BindFragDataLocation} */ static void BindLocation( ProgramName program, FragDataSlot location, StrCRef identifier) { OGLPLUS_GLFUNC(BindFragDataLocation) (GetGLName(program), GLuint(location), identifier.c_str()); OGLPLUS_CHECK( BindFragDataLocation, ProgVarError, Program(program).Identifier(identifier).Index(GLuint(location))); }
void Object::InternalInitialize() { this->vertex_array_handle = GLuint(-1); this->vertex_data_handle = GLuint(-1); this->vertex_indices_handle = GLuint(-1); this->vertex_indices_wire_frame_handle = GLuint(-1); /* TODO: Enable normals too */ this->normal_array_handle = this->normal_data_handle = this->normal_indices_handle = GLuint(-1); }
void Object::takeDown() { if (this->vertexArrayHandle != GLuint(-1)) { glDeleteVertexArrays(1, &this->vertexArrayHandle); } if (this->vertexBufferHandle != GLuint(-1)) { glDeleteBuffers(1, &this->vertexBufferHandle); } this->vertexArrayHandle = this->vertexBufferHandle = GLuint(-1); }
void run_loop( std::unique_ptr<Example>& example, GLuint width, GLuint height ) { GLuint mouse_x = width / 2; GLuint mouse_y = height / 2; os::steady_clock os_clock; ExampleClock clock; while(true) { clock.Update(os_clock.seconds()); if(!example->Continue(clock)) break; example->Render(clock); glfwSwapBuffers(); int new_x, new_y; glfwGetWindowSize(&new_x, &new_y); if((int(width) != new_x) || (int(height) != new_y)) { if(new_x <= 0) new_x = 1; if(new_y <= 0) new_y = 1; width = GLuint(new_x); height = GLuint(new_y); example->Reshape(width, height); } glfwGetMousePos(&new_x, &new_y); if((int(mouse_x) != new_x) || (int(mouse_y) != new_y)) { if(new_x <= 0) new_x = 1; if(new_y <= 0) new_y = 1; mouse_x = GLuint(new_x); mouse_y = GLuint(new_y); example->MouseMove( mouse_x, height- mouse_y, width, height ); } if(glfwGetKey(GLFW_KEY_ESC)) { glfwCloseWindow(); break; } if(!glfwGetWindowParam(GLFW_OPENED)) break; } }
void ComputeShaderChunk::changeFrom(DrawEnv *pEnv, StateChunk *pOther, UInt32 uiIdx) { ComputeShaderChunk *pOld = dynamic_cast<ComputeShaderChunk *>(pOther); // pOther can be a ShaderExecutableChunk, since we share the StateClass id // with it if(pOld != NULL) { Window *pWin = pEnv->getWindow(); GLuint uiProgId = GLuint(pWin->getGLObjectId(getGLId())); UInt32 uiDep = ShaderProcVariable::SHDObject; if(uiProgId != pEnv->getActiveShader()) { UInt32 uiValRes = pWin->validateGLObject(getGLId(), pEnv, KeepProgActive); uiProgId = GLuint(pWin->getGLObjectId(getGLId())); if(uiProgId == 0) return; pEnv->setActiveShader(uiProgId); if(0x0000 == (uiValRes & ProgActive)) { OSGGETGLFUNCBYID_GL3_ES(glUseProgram, osgGlUseProgram, ShaderProgram::getFuncIdUseProgram(), pWin); osgGlUseProgram(uiProgId); } uiDep = ShaderProcVariable::SHDAll; pEnv->incNumShaderChanges(); } updateProceduralVariables(pEnv, uiDep); } else { pOther->deactivate(pEnv, uiIdx); activate (pEnv, uiIdx); pEnv->incNumShaderChanges(); } }
/// Returns the instructions for rendering DrawingInstructions InstructionsWithAdjacency(void) const { const unsigned n = _divisions; DrawOperation operation; operation.method = DrawOperation::Method::DrawElements; operation.mode = PrimitiveType::TrianglesAdjacency; operation.first = GLuint(0); operation.count = GLuint(n*n*n*6*6); operation.restart_index = DrawOperation::NoRestartIndex(); operation.phase = 0; return this->MakeInstructions(operation); }
void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override { glTextureSubImage2D(GLuint(_params.handle), _params.mipMapLevel, _params.x, _params.y, _params.width, _params.height, GLuint(_params.format), GLenum(_params.dataType), _params.data); }
bool StGLMesh::computeNormals(size_t theDelta) { ST_DEBUG_ASSERT(theDelta > 0); myNormals.initArray(myVertices.size()); if(myVertices.isEmpty()) { return false; } // iterate over each triangle // for each node we compute summary of normals for all triangles where this node used // normals are NOT normalized per triangle - this allows to interpolate result normal // with respect to each triangle dimensions GLuint aV1, aV2, aV3; StGLVec3 aNorm; if(myIndices.size() >= 3) { size_t aLimit = myIndices.size() - 3; for(size_t anIndexId = 0; anIndexId <= aLimit; anIndexId += theDelta) { aV1 = myIndices[anIndexId]; aV2 = myIndices[anIndexId + 1]; aV3 = myIndices[anIndexId + 2]; const StGLVec3& aVert1 = myVertices[aV1]; const StGLVec3& aVert2 = myVertices[aV2]; const StGLVec3& aVert3 = myVertices[aV3]; aNorm = StGLVec3::cross(aVert2 - aVert1, aVert3 - aVert1); myNormals.changeValue(aV1) += aNorm; myNormals.changeValue(aV2) += aNorm; myNormals.changeValue(aV3) += aNorm; } } else if(myVertices.size() >= 3) { size_t aLimit = myVertices.size() - 3; for(size_t aVertId = 0; aVertId <= aLimit; aVertId += theDelta) { aV1 = GLuint(aVertId); aV2 = GLuint(aVertId + 1); aV3 = GLuint(aVertId + 2); const StGLVec3& aVert1 = myVertices[aV1]; const StGLVec3& aVert2 = myVertices[aV2]; const StGLVec3& aVert3 = myVertices[aV3]; aNorm = StGLVec3::cross(aVert2 - aVert1, aVert3 - aVert1); myNormals.changeValue(aV1) += aNorm; myNormals.changeValue(aV2) += aNorm; myNormals.changeValue(aV3) += aNorm; } } else { return false; } // normalize normals (important for OpenGL) for(size_t aNormId = 0; aNormId < myNormals.size(); ++aNormId) { myNormals.changeValue(aNormId).normalize(); } return true; }
void Terrain::drawOverWater(){ // bind textures material->use(); for (int i=0; i<TERRAIN_TEX_COUNT; i++){ textureManager->bindTexture(textureIds[i], GL_TEXTURE0+GLuint(i)); } textureManager->bindTexture(textureManager->shadowMapID, GL_TEXTURE0+GLuint(7)); shader->use(true); shader->setUniform4v(border_values_location, g_terrain_border_values); shader->setUniform4v(border_widths_location, g_terrain_border_widths); shader->setUniform2f(heightInterval_location, WATER_HEIGHT, 1000.f); shader->setBoolean(fastModeLoc, g_fastMode); shader->setBoolean(shadowMappingEnabledLoc, g_ShadowMappingEnabled); shader->setUniformMatrix(LCmatrixLoc, g_LightMVPCameraVInverseMatrix ); shader->setUniformMatrix(LMV_CVImatrixLoc, g_LightMVCameraVInverseMatrix ); shader->setUniformMatrix(LPmatrixLoc, g_LightPMatrix ); // bind index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,eboId); glBindBuffer(GL_ARRAY_BUFFER, vboId); // enable states glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); // draw VBOs... glVertexPointer(channels[VERTEX], glTypes[VERTEX], 0, BUFFER_OFFSET(offsets[VERTEX])); glNormalPointer(glTypes[NORMAL], 0, BUFFER_OFFSET( offsets[NORMAL] ) ); glActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(channels[TEXCOORD0], glTypes[TEXCOORD0], 0, BUFFER_OFFSET(offsets[TEXCOORD0])); glDrawElements(GL_TRIANGLE_STRIP, eboCount, GL_UNSIGNED_INT, BUFFER_OFFSET(offsets[INDEX])); // disable glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); // unbind buffers glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // unbind textures for (int i=0; i<TERRAIN_TEX_COUNT; i++){ textureManager->unbindTexture(textureIds[i]); } // turn off shader shader->use(false); flip = false; }
/** * @glsymbols * @glfunref{UniformBlockBinding} */ void Binding(UniformBufferBindingPoint binding) { OGLPLUS_GLFUNC(UniformBlockBinding)( this->_program, this->_location, GLuint(binding) ); OGLPLUS_VERIFY( UniformBlockBinding, ProgVarError, Program(ProgramName(this->_program)). Index(GLuint(binding)) ); }
/** * @glsymbols * @glfunref{DisableVertexArrayAttribEXT} */ const ObjectOps& DisableVertexAttrib(VertexAttribSlot location) { OGLPLUS_GLFUNC(DisableVertexArrayAttribEXT)( _name, GLuint(location) ); OGLPLUS_CHECK( DisableVertexArrayAttribEXT, ObjectError, Object(*this). Index(GLuint(location)) ); return *this; }
void SSAO::Update(const FrameBuffer *FBO, const Camera *camera) const { ssaoFBO.Bind(); glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); Shader *ssao = Manager::Shader->GetShader("ssao"); ssao->Use(); ssao->BindTexturesUnits(); ssaoFBO.SendResolution(ssao); camera->BindViewMatrix(ssao->loc_view_matrix); camera->BindProjectionMatrix(ssao->loc_projection_matrix); camera->BindProjectionDistances(ssao); glUniform1f(ssao->loc_u_rad, radius); glUniform1i(ssao->loc_kernel_size, kernelSize); glUniform3fv(ssao->loc_kernel, kernelSize * 3, glm::value_ptr(kernel[0])); FBO->BindTexture(3, GL_TEXTURE0); FBO->BindTexture(4, GL_TEXTURE1); FBO->BindDepthTexture(GL_TEXTURE2); RandomNoise1->BindToTextureUnit(GL_TEXTURE3); RandomNoise2->BindToTextureUnit(GL_TEXTURE4); ScreenQuad->Render(ssao); // Finish TASK glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); FrameBuffer::Unbind(); // -- COMPUTE SHADER int WORK_GROUP_SIZE = 16; auto res = ssaoFBO.GetResolution(); Shader *S = Manager::Shader->GetShader("ssaoBlur"); S->Use(); // First Pass ssaoFBO.BindTexture(0, GL_TEXTURE0); glBindImageTexture(1, computeTexture->GetTextureID(), 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA16F); glDispatchCompute(GLuint(UPPER_BOUND(res.x, WORK_GROUP_SIZE)), GLuint(UPPER_BOUND(res.y, WORK_GROUP_SIZE)), 1); glMemoryBarrier(GL_ALL_BARRIER_BITS); }
FboBinder(GLuint handle): prev(0), restore(false) { glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &prev ); if ( GLuint(prev) != handle ) { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, handle ); restore = true; } }
/** * @throws Error * * @glsymbols * @glfunref{Get} * @gldefref{MAX_VIEWPORTS} */ static GLuint MaxViewports(void) { GLint result = 0; OGLPLUS_GLFUNC(GetIntegerv)(GL_MAX_VIEWPORTS, &result); OGLPLUS_VERIFY_SIMPLE(GetIntegerv); return GLuint(result); }
int TextureManager::CreateRGBATexture( int width_, int height_, int textureSlot ) { GLuint colorTexture = GLuint( -1 ); // Activating the texture slot glActiveTexture( GL_TEXTURE0 + textureSlot ); // Generating the texture glGenTextures( 1, &colorTexture ); // Binding the texture glBindTexture( GL_TEXTURE_2D, colorTexture ); // Creating the texture glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); // Texture param glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); return colorTexture; }
int TextureManager::CreateDepthTexture( int width_, int height_, int textureSlot ) { GLuint depthTexture = GLuint( -1 ); // Activating the texture slot glActiveTexture( GL_TEXTURE0 + textureSlot ); // Generating the texture glGenTextures( 1, &depthTexture ); // Binding the texture glBindTexture( GL_TEXTURE_2D, depthTexture ); // Creating the texture glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width_, height_, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL ); // Texture param glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); // Binding the texture //glBindTexture( GL_TEXTURE_2D, depthTexture ); return depthTexture; }
/*! \internal */ QCLImage3D QCLContextGL::createTexture3D (QMacCompatGLenum type, QMacCompatGLuint texture, QMacCompatGLint mipmapLevel, QCLMemoryObject::Access access) { return createTexture3D(GLenum(type), GLuint(texture), GLint(mipmapLevel), access); }
static GLuint _query_limit(void) { GLint limit = 0; OGLPLUS_GLFUNC(GetIntegerv)(Query, &limit); OGLPLUS_VERIFY_SIMPLE(GetIntegerv); return GLuint(limit); }
TokenId KPboardView::Selection(const Camera &camera, int x, int y) const { GLuint buffer[BUF_SIZE]; // Set Up A Selection Buffer auto choose = TokenId::EMPTY; glSelectBuffer(BUF_SIZE, buffer); glRenderMode(GL_SELECT); // Change to Selection mode glInitNames(); glPushName(0); // Push 0 (At Least One Entry) Onto The Stack camera.Draw(x, y); Draw(true); // Draw the tokens (not the board) auto hits = glRenderMode(GL_RENDER); // Change back to render mode if (hits > 0) { choose = static_cast<TokenId>(buffer[3]); auto depth = buffer[1]; for (auto loop = 1; loop < hits; loop++) { if (buffer[loop * 4 + 1] < GLuint(depth)) { // store the closest object choose = static_cast<TokenId>(buffer[loop * 4 + 3]); depth = buffer[loop * 4 + 1]; } } } return choose; }
/// returns the selected face, NULL if nothing selected view::face* view::get_selected_face(int x, int y) { GLuint select_buf[SELECT_BUF_SIZE]; glSelectBuffer(SELECT_BUF_SIZE, select_buf); glRenderMode(GL_SELECT); glInitNames(); GLdouble projection_matrix[16]; glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix); glMatrixMode (GL_PROJECTION); glLoadIdentity (); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); gluPickMatrix (GLdouble(x), GLdouble(viewport[3] - y), SELECT_TOL, SELECT_TOL, viewport); glMultMatrixd(projection_matrix); basemesh_drawable->render_faces(); glMatrixMode(GL_PROJECTION); glLoadMatrixd(projection_matrix); glFlush(); GLint hits = glRenderMode(GL_RENDER); if (hits > 0) { int selected_face = select_buf[3]; int depth = select_buf[1]; for (int i = 1; i < hits; i++) { if (select_buf[i*4+1] < GLuint(depth)) { selected_face = select_buf[i*4+3]; depth = select_buf[i*4+1]; } } return (face*)selected_face; } return NULL; }
model obj(model::attrib_flag_t import_attribs){ model::attrib_flag_t attributes{model::POSITION | import_attribs}; std::vector<float> vertex_data; std::vector<unsigned> indecs; GLuint vertex_offset = 0; int count = 100000; // push back vertex attributes for (unsigned i = 0; i < count; ++i) { vertex_data.push_back((float)((float)(rand() % 100))/10); vertex_data.push_back((float)((float)(rand() % 150))/10 - 7.0f); vertex_data.push_back((float)((float)(rand() % 100))/10); } // add triangles for (unsigned i = 0; i < count; ++i) { indecs.push_back(rand() % 100); } vertex_offset += GLuint(count); return model{vertex_data, attributes, indecs}; }
void ComputeShaderChunk::activate(DrawEnv *pEnv, UInt32 uiIdx) { Window *pWin = pEnv->getWindow(); UInt32 uiValRes = pWin->validateGLObject(getGLId(), pEnv, KeepProgActive); GLuint uiProgId = GLuint(pWin->getGLObjectId(getGLId())); if(uiProgId == 0) return; pEnv->setActiveShader(uiProgId); if(0x0000 == (uiValRes & ProgActive)) { OSGGETGLFUNCBYID_GL3_ES(glUseProgram, osgGlUseProgram, ShaderProgram::getFuncIdUseProgram(), pWin); osgGlUseProgram(uiProgId); } pEnv->incNumShaderChanges(); updateProceduralVariables(pEnv, ShaderProcVariable::SHDAll); }