void resolveMultisampling()
	{
		glm::ivec2 WindowSize(this->getWindowSize());

		glViewport(0, 0, WindowSize.x, WindowSize.y);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		glBindTextures(0, 1, &TextureName[texture::MULTISAMPLE_COLORBUFFER]);
		glBindVertexArray(VertexArrayName);
		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], this->UniformBlockSize, this->UniformBlockSize);

		glEnable(GL_SCISSOR_TEST);

		// Box
		{
			glScissor(1, 1, WindowSize.x  / 2 - 2, WindowSize.y - 2);

			glBindProgramPipeline(PipelineName[program::RESOLVE_BOX]);
			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 5);
		}

		// Near
		{
			glScissor(WindowSize.x / 2 + 1, 1, WindowSize.x / 2 - 2, WindowSize.y - 2);

			glBindProgramPipeline(PipelineName[program::RESOLVE_NEAR]);
			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 5);
		}

		glDisable(GL_SCISSOR_TEST);
	}
示例#2
0
    bool render()
    {
        glm::vec2 WindowSize(this->getWindowSize());

        {
            float Aspect = (WindowSize.x * 0.33f) / (WindowSize.y * 0.50f);
            glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, Aspect, 0.1f, 100.0f);
            glm::mat4 MVP = Projection * this->view() * glm::mat4(1.0f);

            *UniformPointer = MVP;
        }

        glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

        glBindProgramPipeline(PipelineName);
        glBindBuffersBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, 1, &BufferName[buffer::TRANSFORM]);
        glBindTextures(semantic::sampler::DIFFUSE, 1, &TextureName);
        glBindVertexArray(VertexArrayName);
        glBindVertexBuffer(semantic::buffer::STATIC, BufferName[buffer::VERTEX], 0, GLsizei(sizeof(vertex)));

        for(std::size_t Index = 0; Index < viewport::MAX; ++Index)
        {
            glViewportIndexedf(0,
                               Viewport[Index].x,
                               Viewport[Index].y,
                               Viewport[Index].z,
                               Viewport[Index].w);

            glBindSamplers(0, 1, &SamplerName[Index]);
            glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
        }

        return true;
    }
示例#3
0
void guidedFilterAI_B(GLuint res, GLuint A, GLuint B, GLuint guide, GLsizei w, GLsizei h)
{
    GLenum buffers[] = {GL_COLOR_ATTACHMENT0};

    GLuint textures[3] = {A, B, guide};
    glBindTextures(0, ARRAY_SIZE(textures), textures);

    glUseProgram(programs[PRG_GUIDED_AI_B]);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, res, 0);
    glDrawBuffers(ARRAY_SIZE(buffers), buffers);
    glViewport(0, 0, w, h);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}
	Error operator()(GlCommandBuffer* commands)
	{
		Array<GLuint, MAX_BIND_TEXTURES> names;

		U count = m_texCount;
		U i = 0;
		while(count-- != 0)
		{
			names[i++] = m_texes[count]._get().getGlName();
		}

		glBindTextures(m_first, m_texCount, &names[0]);

		return ErrorCode::NONE;
	}
	void renderFBO()
	{
		static int SamplesPositionsIndex = 0;
		++SamplesPositionsIndex;
		SamplesPositionsIndex %= 2;

		{
			glm::mat4 Perspective = glm::perspective(glm::pi<float>() * 0.25f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Perspective * this->view() * Model;

			glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
			glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(MVP), GL_MAP_WRITE_BIT);
			*Pointer = MVP;
			glUnmapBuffer(GL_UNIFORM_BUFFER);
		}

		glViewportIndexedfv(0, &glm::vec4(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y)[0]);
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferRenderName);

		glm::vec2 SamplesPositions[2][4] =
		{
			{
				glm::vec2(0.75f, 0.25f),
				glm::vec2(1.00f, 0.75f),
				glm::vec2(0.25f, 1.00f),
				glm::vec2(0.00f, 0.25f)
			},
			{
				glm::vec2(0.25f, 0.25f),
				glm::vec2(1.00f, 0.25f),
				glm::vec2(0.75f, 1.00f),
				glm::vec2(0.00f, 0.75f)
			}
		};

		glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 0, &SamplesPositions[SamplesPositionsIndex][0][0]);
		glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 1, &SamplesPositions[SamplesPositionsIndex][1][0]);
		glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 2, &SamplesPositions[SamplesPositionsIndex][2][0]);
		glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 3, &SamplesPositions[SamplesPositionsIndex][3][0]);

		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

		glBindTextures(0, 1, &TextureName);
		glBindVertexArray(VertexArrayName);

		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);
	}
示例#6
0
文件: myGL.cpp 项目: sprunk/spring
void glSpringBindTextures(GLuint first, GLsizei count, const GLuint* textures)
{
#ifdef GLEW_ARB_multi_bind
	if (GLEW_ARB_multi_bind) {
		glBindTextures(first, count, textures);
	} else
#endif
	{
		for (int i = 0; i < count; ++i) {
			const GLuint texture = (textures == nullptr) ? 0 : textures[i];
			glActiveTexture(GL_TEXTURE0 + first + i);
			glBindTexture(GL_TEXTURE_2D, texture);
		}
		glActiveTexture(GL_TEXTURE0);

	}
}
示例#7
0
void guidedFilterPack(GLuint pI, GLuint pIII, GLuint src, GLuint guide, GLsizei w, GLsizei h)
{
    GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};

    GLuint textures[2] = {src, guide};
    glBindTextures(0, ARRAY_SIZE(textures), textures);

    glUseProgram(programs[PRG_GUIDED_PACK]);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pI,   0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, pIII, 0);
    glDrawBuffers(ARRAY_SIZE(buffers), buffers);
    glViewport(0, 0, w, h);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
}
示例#8
0
void guidedFilterAB(GLuint A, GLuint B, GLuint src, GLuint guide, float eps, GLsizei w, GLsizei h)
{
    GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};

    GLuint textures[2] = {src, guide};
    glBindTextures(0, ARRAY_SIZE(textures), textures);

    glUseProgram(programs[PRG_GUIDED_AB]);
    glUniform1f(0, eps);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, A, 0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, B, 0);
    glDrawBuffers(ARRAY_SIZE(buffers), buffers);
    glViewport(0, 0, w, h);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
}
示例#9
0
void display()
{
	{
		// Compute the MVP (Model View Projection matrix)
		float Aspect = (Window.Size.x * 0.33f) / (Window.Size.y * 0.50f);
		glm::mat4 Projection = glm::perspective(45.0f, Aspect, 0.1f, 100.0f);
		glm::mat4 ViewTranslateZ = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
		glm::mat4 ViewRotateX = glm::rotate(ViewTranslateZ, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
		glm::mat4 ViewRotateY = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
		glm::mat4 View = ViewRotateY;
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * View * Model;

		*UniformPointer = MVP;
	}

	glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4));

	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	glBindProgramPipeline(PipelineName);
	glBindBuffersBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, 1, &BufferName[buffer::TRANSFORM]);
	glBindTextures(glf::semantic::sampler::DIFFUSE, 1, &TextureName);
	glBindVertexArray(VertexArrayName);
	glBindVertexBuffer(glf::semantic::buffer::STATIC, BufferName[buffer::VERTEX], 0, GLsizei(sizeof(vertex)));

	for(std::size_t Index = 0; Index < viewport::MAX; ++Index)
	{
		glViewportIndexedf(0, 
			Viewport[Index].x, 
			Viewport[Index].y, 
			Viewport[Index].z, 
			Viewport[Index].w);

		glBindSamplers(0, 1, &SamplerName[Index]);
		glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
	}

	glf::checkError("display");
	glf::swapBuffers();
}
	void renderFB()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4 Perspective = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Perspective * this->view() * Model;

			glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
			glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(MVP), GL_MAP_WRITE_BIT);
			*Pointer = MVP;
			glUnmapBuffer(GL_UNIFORM_BUFFER);
		}

		glBindTextures(0, 1, &ColorTextureName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindVertexArray(VertexArrayName);

		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 3, 0);
	}
	void renderFBO(GLuint Framebuffer)
	{
		glEnable(GL_DEPTH_TEST);

		glBindProgramPipeline(PipelineName[program::THROUGH]);
		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, this->UniformBlockSize);

		glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y);

		glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
		float Depth(1.0f);
		glClearBufferfv(GL_DEPTH, 0, &Depth);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glBindTextures(0, 1, &TextureName[texture::DIFFUSE]);
		glBindVertexArray(VertexArrayName);

		glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 5);

		glDisable(GL_DEPTH_TEST);
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x * 0.5f / WindowSize.y, 0.1f, 1000.0f);
			glm::mat4 View = this->view();
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Projection * View * Model;
			glm::mat4 MV = View * Model;

			TransformPointer->MVP = Projection * View * Model;
			TransformPointer->MV = View * Model;
			TransformPointer->Camera = glm::vec3(0.0f, 0.0f, -this->cameraDistance());
		}

		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)[0]);

		glBindProgramPipeline(PipelineName);
		glBindTextures(semantic::sampler::DIFFUSE, 1, &TextureName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindVertexArray(VertexArrayName);

		// Left side: seamless cubemap filtering
		glViewportIndexedf(0, 0, 0, WindowSize.x * 0.5f, WindowSize.y);
		glBindSamplers(semantic::sampler::DIFFUSE, 1, &SamplerName[sampler::SEAMLESS]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0);

		// Right side: per face cubemap filtering
		glViewportIndexedf(0, WindowSize.x * 0.5f, 0, WindowSize.x * 0.5f, WindowSize.y);
		glBindSamplers(semantic::sampler::DIFFUSE, 1, &SamplerName[sampler::NON_SEAMLESS]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0);

		return true;
	}
示例#13
0
文件: main.c 项目: nlguillemot/glFast
i32 main(i32 ArgCount, char ** Args)
{
  char * path_exe = SDL_GetBasePath();
  for(u32 i = 0, size = sizeof(RESRC); i < size; i += MAX_STR)
  {
    char path_res[MAX_STR];
    SDL_memcpy(path_res, &RESRC.c[i], MAX_STR);
    SDL_snprintf(&RESRC.c[i], MAX_STR, "%s%s", path_exe, path_res);
  }
  
  SDL_Window  * sdl_window;
  SDL_GLContext sdl_glcontext;
  
  gfWindow(&sdl_window, &sdl_glcontext, 0, 0, "App", 1280, 720, 4);

  const char * bobs[] =
  {
    RESRC.monkey_bob,
    RESRC.sphere_bob,
    RESRC.teapot_bob,
  };

  bob_t meshes = gfBobCreate(countof(bobs), bobs);

  const char * bmps[] =
  {
    RESRC.texture_1,
    RESRC.texture_2,
    RESRC.texture_3,
  };

  gpu_texture_t textures = gfTextureCreateFromBmp(512, 512, 4, countof(bmps), bmps);
  
  const char * cubemap_px[] = { RESRC.cubemap_px };
  const char * cubemap_nx[] = { RESRC.cubemap_nx };
  const char * cubemap_py[] = { RESRC.cubemap_py };
  const char * cubemap_ny[] = { RESRC.cubemap_ny };
  const char * cubemap_pz[] = { RESRC.cubemap_pz };
  const char * cubemap_nz[] = { RESRC.cubemap_nz };
  
  gpu_texture_t cubemaps = gfCubemapCreateFromBmp(512, 512, 4, countof(cubemap_px),
    cubemap_px, cubemap_nx, cubemap_py, cubemap_ny, cubemap_pz, cubemap_nz
  );
  
  u32 vs_mesh = gfProgramCreateFromFile(GL_VERTEX_SHADER, RESRC.vs_mesh);
  u32 fs_mesh = gfProgramCreateFromFile(GL_FRAGMENT_SHADER, RESRC.fs_mesh);
  u32 pp_mesh = gfProgramPipelineCreate(vs_mesh, fs_mesh);
  
  u32 vs_quad = gfProgramCreateFromFile(GL_VERTEX_SHADER, RESRC.vs_quad);
  u32 fs_quad = gfProgramCreateFromFile(GL_FRAGMENT_SHADER, RESRC.fs_quad);
  u32 pp_quad = gfProgramPipelineCreate(vs_quad, fs_quad);
  
  u32 vs_cubemap = gfProgramCreateFromFile(GL_VERTEX_SHADER, RESRC.vs_cubemap);
  u32 fs_cubemap = gfProgramCreateFromFile(GL_FRAGMENT_SHADER, RESRC.fs_cubemap);
  u32 pp_cubemap = gfProgramPipelineCreate(vs_cubemap, fs_cubemap);
  
  gpu_cmd_t cmd[3] = {0};
  
  cmd[0].first = meshes.first.as_u32[0];
  cmd[1].first = meshes.first.as_u32[1];
  cmd[2].first = meshes.first.as_u32[2];
  
  cmd[0].count = meshes.count.as_u32[0];
  cmd[1].count = meshes.count.as_u32[1];
  cmd[2].count = meshes.count.as_u32[2];
  
  cmd[0].instance_first = 0;
  cmd[1].instance_first = 30;
  cmd[2].instance_first = 60;
  
  cmd[0].instance_count = 30;
  cmd[1].instance_count = 30;
  cmd[2].instance_count = 30;
  
  gpu_storage_t ins_first = gfStorageCreate(.format = x_u32, .count = countof(cmd));
  gpu_storage_t ins_pos = gfStorageCreate(.format = xyz_f32, .count = 90);
  
  for(u32 i = 0; i < ins_first.count; ++i)
  {
    ins_first.as_u32[i] = cmd[i].instance_first;
  }
  
  for(u32 i = 0, row = 10, space = 3; i < 90; ++i)
  {
    ins_pos.as_vec3[i].x = i * space - (i / row) * row * space;
    ins_pos.as_vec3[i].y = 0;
    ins_pos.as_vec3[i].z = (i / row) * space;
  }

  gpu_texture_t fbo_depth = gfTextureCreate(.w = 1280, 720, .format = depth_b32);
  gpu_texture_t fbo_color = gfTextureCreate(.w = 1280, 720, .format = srgba_b8);
  
  u32 fbo_colors[] =
  {
    [0] = fbo_color.id,
  };
  
  u32 fbo = gfFboCreate(fbo_depth.id, 0, countof(fbo_colors), fbo_colors, 0);
  
  gpu_sampler_t s_textures = gfSamplerCreate(4);
  gpu_sampler_t s_fbo = gfSamplerCreate(.min = GL_NEAREST, GL_NEAREST);
  
  u32 state_textures[16] =
  {
    [0] = meshes.mesh_id.id,
    [1] = meshes.attr_first.id,
    [2] = meshes.attr_id.id,
    [3] = meshes.pos.id,
    [4] = meshes.uv.id,
    [5] = meshes.normal.id,
    [6] = ins_first.id,
    [7] = ins_pos.id,
    [8] = textures.id,
    [9] = cubemaps.id,
   [10] = fbo_color.id,
  };
  
  u32 state_samplers[16] =
  {
    [8] = s_textures.id,
    [9] = s_textures.id,
   [10] = s_fbo.id,
  };
  
  glBindTextures(0, 16, state_textures);
  glBindSamplers(0, 16, state_samplers);
  
  vec3 cam_pos = {23.518875f, 5.673130f, 26.649000f};
  vec4 cam_rot = {-0.351835f, 0.231701f, 0.090335f, 0.902411f};
  vec4 cam_prj = {0.f};
  mat3 cam_mat = {0.f};

  Perspective(
    &cam_prj.x,
    Aspect(sdl_window),
    85.f * QFPC_TO_RAD,
    0.01f, 1000.f
  );
  
  SDL_SetRelativeMouseMode(1);
  u32 t_prev = SDL_GetTicks();

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);
  glEnable(GL_BLEND);

  while(1)
  {
    u32 t_curr = SDL_GetTicks();
    f64 dt = ((t_curr - t_prev) * 60.0) / 1000.0;
    
    SDL_PumpEvents();
    i32 mouse_x_rel = 0;
    i32 mouse_y_rel = 0;
    SDL_GetRelativeMouseState(&mouse_x_rel, &mouse_y_rel);
    const u8 * key = SDL_GetKeyboardState(NULL);
    
    quatFirstPersonCamera(
      &cam_pos.x,
      &cam_rot.x,
      &cam_mat.sd_x,
      0.10f,
      0.05f * (f32)dt,
      mouse_x_rel,
      mouse_y_rel,
      key[SDL_SCANCODE_W],
      key[SDL_SCANCODE_A],
      key[SDL_SCANCODE_S],
      key[SDL_SCANCODE_D],
      key[SDL_SCANCODE_E],
      key[SDL_SCANCODE_Q]
    );
    
    static int show_pass = 0;
    if(key[SDL_SCANCODE_1]) show_pass = 0;
    if(key[SDL_SCANCODE_2]) show_pass = 1;
    if(key[SDL_SCANCODE_3]) show_pass = 2;
    if(key[SDL_SCANCODE_4]) show_pass = 3;
    if(key[SDL_SCANCODE_5]) show_pass = 4;
    
    glProgramUniform3fv(vs_mesh, 0, 1, &cam_pos.x);
    glProgramUniform4fv(vs_mesh, 1, 1, &cam_rot.x);
    glProgramUniform4fv(vs_mesh, 2, 1, &cam_prj.x);
    glProgramUniform3fv(fs_mesh, 0, 1, &cam_pos.x);
    glProgramUniform1iv(fs_mesh, 1, 1, &show_pass);
    glProgramUniform4fv(vs_cubemap, 0, 1, &cam_rot.x);
    glProgramUniform4fv(vs_cubemap, 1, 1, &cam_prj.x);
    
    for(u32 i = 0; i < 90; ++i)
      ins_pos.as_vec3[i].y = (f32)sin((t_curr * 0.0015f) + (i * 0.5f)) * 0.3f;
    
    gfFboBind(fbo);
      gfClear();
      gfDraw(pp_mesh, countof(cmd), cmd);
    gfFboBind(0);
    
    gfClear();
    
    if(!show_pass)
    {
      glDisable(GL_DEPTH_TEST);
        gfFire(pp_cubemap, 36);
      glEnable(GL_DEPTH_TEST);
    }
    
    gfFire(pp_quad, 6);

    SDL_Event event;
    while(SDL_PollEvent(&event))
    {
      if(event.type == SDL_QUIT)
        goto exit;
    }
    
    SDL_GL_SwapWindow(sdl_window);
    glFinish();
    
    t_prev = t_curr;
  }

  exit: return 0;
}
void SpriteTexture::use(uint32_t texture_unit)
{
	assert(glIsTexture(mTextureId));
	glBindTextures(texture_unit, 1, &mTextureId);
}
//==============================================================================
void ResourceGroupImpl::bind(
	U slot, const DynamicBufferInfo& dynInfo, GlState& state)
{
	ANKI_ASSERT(slot < MAX_RESOURCE_GROUPS);

	// Bind textures
	if(m_textureNamesCount)
	{
		glBindTextures(MAX_TEXTURE_BINDINGS * slot,
			m_textureNamesCount,
			&m_textureNames[0]);

		if(m_allSamplersZero)
		{
			glBindSamplers(
				MAX_TEXTURE_BINDINGS * slot, m_textureNamesCount, nullptr);
		}
		else
		{
			glBindSamplers(MAX_TEXTURE_BINDINGS * slot,
				m_textureNamesCount,
				&m_samplerNames[0]);
		}
	}

	// Uniform buffers
	for(U i = 0; i < m_ubosCount; ++i)
	{
		const auto& binding = m_ubos[i];
		if(binding.m_name == MAX_U32)
		{
			// Dynamic
			DynamicBufferToken token = dynInfo.m_uniformBuffers[i];
			ANKI_ASSERT(token.m_range != 0);

			if(token.m_range != MAX_U32)
			{
				glBindBufferRange(GL_UNIFORM_BUFFER,
					MAX_UNIFORM_BUFFER_BINDINGS * slot + i,
					state.m_dynamicMemoryManager.getGlName(
						BufferUsage::UNIFORM),
					token.m_offset,
					token.m_range);
			}
			else
			{
				// It's invalid
			}
		}
		else if(binding.m_name != 0)
		{
			// Static
			glBindBufferRange(GL_UNIFORM_BUFFER,
				MAX_UNIFORM_BUFFER_BINDINGS * slot + i,
				binding.m_name,
				binding.m_offset,
				binding.m_range);
		}
	}

	// Storage buffers
	for(U i = 0; i < m_ssbosCount; ++i)
	{
		const auto& binding = m_ssbos[i];
		if(binding.m_name == MAX_U32)
		{
			// Dynamic
			DynamicBufferToken token = dynInfo.m_storageBuffers[i];
			ANKI_ASSERT(token.m_range != 0);

			if(token.m_range != MAX_U32)
			{
				glBindBufferRange(GL_SHADER_STORAGE_BUFFER,
					MAX_STORAGE_BUFFER_BINDINGS * slot + i,
					state.m_dynamicMemoryManager.getGlName(
						BufferUsage::STORAGE),
					token.m_offset,
					token.m_range);
			}
			else
			{
				// It's invalid
			}
		}
		else if(binding.m_name != 0)
		{
			// Static
			glBindBufferRange(GL_SHADER_STORAGE_BUFFER,
				MAX_STORAGE_BUFFER_BINDINGS * slot + i,
				binding.m_name,
				binding.m_offset,
				binding.m_range);
		}
	}

	// Atomic
	for(U i = 0; i < m_atomicsCount; ++i)
	{
		const auto& binding = m_atomics[i];
		if(binding.m_name == MAX_U32)
		{
			// Dynamic
			ANKI_ASSERT(0);
		}
		else if(binding.m_name != 0)
		{
			// Static
			glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER,
				MAX_ATOMIC_BUFFER_BINDINGS * slot + i,
				binding.m_name,
				binding.m_offset,
				binding.m_range);
		}
	}

	// Vertex buffers
	if(m_vertBindingsCount)
	{
		ANKI_ASSERT(slot == 0 && "Only slot 0 can have vertex buffers");

		if(!m_hasDynamicVertexBuff)
		{
			memcpy(&state.m_vertBuffOffsets[0],
				&m_vertBuffOffsets[0],
				sizeof(m_vertBuffOffsets[0]) * m_vertBindingsCount);
		}
		else
		{
			// Copy the offsets
			Array<GLintptr, MAX_VERTEX_ATTRIBUTES> offsets = m_vertBuffOffsets;
			for(U i = 0; i < MAX_VERTEX_ATTRIBUTES; ++i)
			{
				if(offsets[i] == MAX_U32)
				{
					// It's dynamic
					ANKI_ASSERT(dynInfo.m_vertexBuffers[i].m_range != 0);
					offsets[i] = dynInfo.m_vertexBuffers[i].m_offset;
				}
				else
				{
					ANKI_ASSERT(dynInfo.m_vertexBuffers[i].m_range == 0);
				}
			}

			// Bind to state
			memcpy(&state.m_vertBuffOffsets[0],
				&offsets[0],
				sizeof(offsets[0]) * m_vertBindingsCount);
		}

		memcpy(&state.m_vertBuffNames[0],
			&m_vertBuffNames[0],
			sizeof(m_vertBuffNames[0]) * m_vertBindingsCount);

		state.m_vertBindingCount = m_vertBindingsCount;
		state.m_vertBindingsDirty = true;
	}

	// Index buffer
	if(m_indexSize > 0)
	{
		ANKI_ASSERT(slot == 0 && "Only slot 0 can have index buffers");
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffName);
		state.m_indexSize = m_indexSize;
	}
}
示例#16
0
void graphics::texture::use(uint32_t texture_unit)
{
	assert(glIsTexture(m_TextureName));
	glBindTextures(texture_unit, 1, &m_TextureName);
}
示例#17
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL44_nglBindTextures(JNIEnv *env, jclass clazz, jint first, jint count, jlong textures, jlong function_pointer) {
	const GLuint *textures_address = (const GLuint *)(intptr_t)textures;
	glBindTexturesPROC glBindTextures = (glBindTexturesPROC)((intptr_t)function_pointer);
	glBindTextures(first, count, textures_address);
}