void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture * _pTexture, bool _multisample)
{
	if (_pBuffer != NULL) {
		_pTexture->width = (uint32_t)(_pBuffer->m_pTexture->width);
		_pTexture->height = (uint32_t)(_pBuffer->m_pTexture->height);
		_pTexture->address = _pBuffer->m_startAddress;
		_pTexture->clampWidth = _pBuffer->m_width;
		_pTexture->clampHeight = _pBuffer->m_height;
	}
	else {
		_pTexture->width = video().getWidth();
		_pTexture->height = video().getHeight();
		_pTexture->address = gDP.depthImageAddress;
		_pTexture->clampWidth = VI.width;
		_pTexture->clampHeight = VI.height;
	}
	_pTexture->format = 0;
	_pTexture->size = 2;
	_pTexture->clampS = 1;
	_pTexture->clampT = 1;
	_pTexture->frameBufferTexture = CachedTexture::fbOneSample;
	_pTexture->maskS = 0;
	_pTexture->maskT = 0;
	_pTexture->mirrorS = 0;
	_pTexture->mirrorT = 0;
	_pTexture->realWidth = _pTexture->width;
	_pTexture->realHeight = _pTexture->height;
	_pTexture->textureBytes = _pTexture->realWidth * _pTexture->realHeight * fboFormats.depthFormatBytes;
	textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);

#ifdef GL_MULTISAMPLING_SUPPORT
	if (_multisample) {
		glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _pTexture->glName);
#if defined(HAVE_OPENGLES_3_1)
		if (_pBuffer != NULL)
			glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, false);
		else
			glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, video().getWidth(), video().getHeight(), false);
#else
		if (_pBuffer != NULL)
			glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, false);
		else
			glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, video().getWidth(), video().getHeight(), false);
#endif
		_pTexture->frameBufferTexture = CachedTexture::fbMultiSample;
	} else
#endif // GL_MULTISAMPLING_SUPPORT
	{
		glBindTexture(GL_TEXTURE_2D, _pTexture->glName);
		if (_pBuffer != NULL)
			glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);
		else
			glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, video().getWidth(), video().getHeight(), 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	}
	glBindTexture(GL_TEXTURE_2D, 0);
}
		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);
			}
		}
Ejemplo n.º 3
0
void QOpenGLTextureHelper::qt_TextureStorage2DMultisample(GLuint texture, GLenum target, GLenum bindingTarget, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations)
{
    GLint oldTexture;
    glGetIntegerv(bindingTarget, &oldTexture);
    glBindTexture(target, texture);
    glTexStorage2DMultisample(target, samples, internalFormat, width, height, fixedSampleLocations);
    glBindTexture(target, oldTexture);
}
Ejemplo n.º 4
0
/*
 *
 * Core in:
 * OpenGL    : 4.3
 * OpenGLES  : 3.1
 */
void rglTexStorage2DMultisample(GLenum target, GLsizei samples,
      GLenum internalformat, GLsizei width, GLsizei height,
      GLboolean fixedsamplelocations)
{
#if defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES_3_1)
   glTexStorage2DMultisample(target, samples, internalformat,
         width, height, fixedsamplelocations);
#endif
}
Ejemplo n.º 5
0
//--------------------------------------------------------------------------------------
// Name: InitTexture()
// Desc: Set up Texture
//--------------------------------------------------------------------------------------
BOOL CSample::InitTexture()
{
    GLint n_max_color_texture_samples = 0;

    DeleteTextures();

    glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, 1, &n_max_color_texture_samples);

    for (UINT32 n_texture = 0;n_texture < NO_MULTIMPLE_TEXTURES; ++n_texture)
    {
         UINT32 n_texture_samples = n_max_color_texture_samples * n_texture / (NO_MULTIMPLE_TEXTURES - 1);

         if (n_texture_samples == 0)
         {
             /* Requesting zero samples is not permitted */
             n_texture_samples = 1;
         }

         GLuint texture_id;
         glGenTextures( 1, &texture_id );

         g_textures[n_texture].n_samples = n_texture_samples;
         g_textures[n_texture].texture   = texture_id;

         glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,
                       g_textures[n_texture].texture);

         glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,
                                   n_texture_samples,
                                   GL_RGBA8,
                                   m_nWidth,
                                   m_nHeight,
                                   GL_FALSE);                /* fixedsamplelocations */

    } /* for (all multisample textures that need to be initialized) */

    return TRUE;
}
		void init2DTexture(const graphics::Context::InitTextureParams & _params) override
		{
			if (_params.msaaLevel == 0) {
				m_bind->bind(_params.textureUnitIndex, graphics::textureTarget::TEXTURE_2D, _params.handle);
				if (m_handle != _params.handle) {
					m_handle = _params.handle;
					glTexStorage2D(GL_TEXTURE_2D,
								   _params.mipMapLevels,
								   GLenum(_params.internalFormat),
								   _params.width,
								   _params.height);
				}

				if (_params.data != nullptr) {
					glTexSubImage2D(GL_TEXTURE_2D,
						_params.mipMapLevel,
						0, 0,
						_params.width,
						_params.height,
						GLuint(_params.format),
						GLenum(_params.dataType),
						_params.data);
				}
			}
			else {
				m_bind->bind(_params.textureUnitIndex, graphics::textureTarget::TEXTURE_2D_MULTISAMPLE, _params.handle);
				glTexStorage2DMultisample(
							GL_TEXTURE_2D_MULTISAMPLE,
							_params.msaaLevel,
							GLenum(_params.internalFormat),
							_params.width,
							_params.height,
							GL_FALSE);
			}

		}
Ejemplo n.º 7
0
FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int msaaSamples)
{
  m_xfbFramebuffer = 0;
  m_efbColor = 0;
  m_efbDepth = 0;
  m_efbColorSwap = 0;
  m_resolvedColorTexture = 0;
  m_resolvedDepthTexture = 0;

  m_targetWidth = targetWidth;
  m_targetHeight = targetHeight;

  m_msaaSamples = msaaSamples;

  // The EFB can be set to different pixel formats by the game through the
  // BPMEM_ZCOMPARE register (which should probably have a different name).
  // They are:
  // - 24-bit RGB (8-bit components) with 24-bit Z
  // - 24-bit RGBA (6-bit components) with 24-bit Z
  // - Multisampled 16-bit RGB (5-6-5 format) with 16-bit Z
  // We only use one EFB format here: 32-bit ARGB with 24-bit Z.
  // Multisampling depends on user settings.
  // The distinction becomes important for certain operations, i.e. the
  // alpha channel should be ignored if the EFB does not have one.

  glActiveTexture(GL_TEXTURE9);

  GLuint glObj[3];
  glGenTextures(3, glObj);
  m_efbColor = glObj[0];
  m_efbDepth = glObj[1];
  m_efbColorSwap = glObj[2];

  m_EFBLayers = (g_ActiveConfig.iStereoMode > 0) ? 2 : 1;
  m_efbFramebuffer.resize(m_EFBLayers);
  m_resolvedFramebuffer.resize(m_EFBLayers);

  // OpenGL MSAA textures are a different kind of texture type and must be allocated
  // with a different function, so we create them separately.
  if (m_msaaSamples <= 1)
  {
    m_textureType = GL_TEXTURE_2D_ARRAY;

    glBindTexture(m_textureType, m_efbColor);
    glTexParameteri(m_textureType, GL_TEXTURE_MAX_LEVEL, 0);
    glTexImage3D(m_textureType, 0, GL_RGBA, m_targetWidth, m_targetHeight, m_EFBLayers, 0, GL_RGBA,
                 GL_UNSIGNED_BYTE, nullptr);

    glBindTexture(m_textureType, m_efbDepth);
    glTexParameteri(m_textureType, GL_TEXTURE_MAX_LEVEL, 0);
    glTexImage3D(m_textureType, 0, GL_DEPTH_COMPONENT32F, m_targetWidth, m_targetHeight,
                 m_EFBLayers, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);

    glBindTexture(m_textureType, m_efbColorSwap);
    glTexParameteri(m_textureType, GL_TEXTURE_MAX_LEVEL, 0);
    glTexImage3D(m_textureType, 0, GL_RGBA, m_targetWidth, m_targetHeight, m_EFBLayers, 0, GL_RGBA,
                 GL_UNSIGNED_BYTE, nullptr);
  }
  else
  {
    GLenum resolvedType = GL_TEXTURE_2D_ARRAY;

    // Only use a layered multisample texture if needed. Some drivers
    // slow down significantly with single-layered multisample textures.
    if (m_EFBLayers > 1)
    {
      m_textureType = GL_TEXTURE_2D_MULTISAMPLE_ARRAY;

      if (g_ogl_config.bSupports3DTextureStorage)
      {
        glBindTexture(m_textureType, m_efbColor);
        glTexStorage3DMultisample(m_textureType, m_msaaSamples, GL_RGBA8, m_targetWidth,
                                  m_targetHeight, m_EFBLayers, false);

        glBindTexture(m_textureType, m_efbDepth);
        glTexStorage3DMultisample(m_textureType, m_msaaSamples, GL_DEPTH_COMPONENT32F,
                                  m_targetWidth, m_targetHeight, m_EFBLayers, false);

        glBindTexture(m_textureType, m_efbColorSwap);
        glTexStorage3DMultisample(m_textureType, m_msaaSamples, GL_RGBA8, m_targetWidth,
                                  m_targetHeight, m_EFBLayers, false);
        glBindTexture(m_textureType, 0);
      }
      else
      {
        glBindTexture(m_textureType, m_efbColor);
        glTexImage3DMultisample(m_textureType, m_msaaSamples, GL_RGBA, m_targetWidth,
                                m_targetHeight, m_EFBLayers, false);

        glBindTexture(m_textureType, m_efbDepth);
        glTexImage3DMultisample(m_textureType, m_msaaSamples, GL_DEPTH_COMPONENT32F, m_targetWidth,
                                m_targetHeight, m_EFBLayers, false);

        glBindTexture(m_textureType, m_efbColorSwap);
        glTexImage3DMultisample(m_textureType, m_msaaSamples, GL_RGBA, m_targetWidth,
                                m_targetHeight, m_EFBLayers, false);
        glBindTexture(m_textureType, 0);
      }
    }
    else
    {
      m_textureType = GL_TEXTURE_2D_MULTISAMPLE;

      if (g_ogl_config.bSupports2DTextureStorage)
      {
        glBindTexture(m_textureType, m_efbColor);
        glTexStorage2DMultisample(m_textureType, m_msaaSamples, GL_RGBA8, m_targetWidth,
                                  m_targetHeight, false);

        glBindTexture(m_textureType, m_efbDepth);
        glTexStorage2DMultisample(m_textureType, m_msaaSamples, GL_DEPTH_COMPONENT32F,
                                  m_targetWidth, m_targetHeight, false);

        glBindTexture(m_textureType, m_efbColorSwap);
        glTexStorage2DMultisample(m_textureType, m_msaaSamples, GL_RGBA8, m_targetWidth,
                                  m_targetHeight, false);
        glBindTexture(m_textureType, 0);
      }
      else
      {
        glBindTexture(m_textureType, m_efbColor);
        glTexImage2DMultisample(m_textureType, m_msaaSamples, GL_RGBA, m_targetWidth,
                                m_targetHeight, false);

        glBindTexture(m_textureType, m_efbDepth);
        glTexImage2DMultisample(m_textureType, m_msaaSamples, GL_DEPTH_COMPONENT32F, m_targetWidth,
                                m_targetHeight, false);

        glBindTexture(m_textureType, m_efbColorSwap);
        glTexImage2DMultisample(m_textureType, m_msaaSamples, GL_RGBA, m_targetWidth,
                                m_targetHeight, false);
        glBindTexture(m_textureType, 0);
      }
    }

    // Although we are able to access the multisampled texture directly, we don't do it everywhere.
    // The old way is to "resolve" this multisampled texture by copying it into a non-sampled
    // texture.
    // This would lead to an unneeded copy of the EFB, so we are going to avoid it.
    // But as this job isn't done right now, we do need that texture for resolving:
    glGenTextures(2, glObj);
    m_resolvedColorTexture = glObj[0];
    m_resolvedDepthTexture = glObj[1];

    glBindTexture(resolvedType, m_resolvedColorTexture);
    glTexParameteri(resolvedType, GL_TEXTURE_MAX_LEVEL, 0);
    glTexImage3D(resolvedType, 0, GL_RGBA, m_targetWidth, m_targetHeight, m_EFBLayers, 0, GL_RGBA,
                 GL_UNSIGNED_BYTE, nullptr);

    glBindTexture(resolvedType, m_resolvedDepthTexture);
    glTexParameteri(resolvedType, GL_TEXTURE_MAX_LEVEL, 0);
    glTexImage3D(resolvedType, 0, GL_DEPTH_COMPONENT32F, m_targetWidth, m_targetHeight, m_EFBLayers,
                 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);

    // Bind resolved textures to resolved framebuffer.
    glGenFramebuffers(m_EFBLayers, m_resolvedFramebuffer.data());
    glBindFramebuffer(GL_FRAMEBUFFER, m_resolvedFramebuffer[0]);
    FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, resolvedType, m_resolvedColorTexture,
                       0);
    FramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, resolvedType, m_resolvedDepthTexture,
                       0);

    // Bind all the other layers as separate FBOs for blitting.
    for (unsigned int i = 1; i < m_EFBLayers; i++)
    {
      glBindFramebuffer(GL_FRAMEBUFFER, m_resolvedFramebuffer[i]);
      glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_resolvedColorTexture, 0, i);
      glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_resolvedDepthTexture, 0, i);
    }
  }

  // Create XFB framebuffer; targets will be created elsewhere.
  glGenFramebuffers(1, &m_xfbFramebuffer);

  // Bind target textures to EFB framebuffer.
  glGenFramebuffers(m_EFBLayers, m_efbFramebuffer.data());
  glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer[0]);
  FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_textureType, m_efbColor, 0);
  FramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_textureType, m_efbDepth, 0);

  // Bind all the other layers as separate FBOs for blitting.
  for (unsigned int i = 1; i < m_EFBLayers; i++)
  {
    glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer[i]);
    glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_efbColor, 0, i);
    glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_efbDepth, 0, i);
  }

  // EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f
  glViewport(0, 0, m_targetWidth, m_targetHeight);
  glScissor(0, 0, m_targetWidth, m_targetHeight);
  glClearColor(0.f, 0.f, 0.f, 1.f);
  glClearDepthf(1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // reinterpret pixel format
  const char* vs = m_EFBLayers > 1 ? "void main(void) {\n"
                                     "	vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n"
                                     "	gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n"
                                     "}\n" :
                                     "flat out int layer;\n"
                                     "void main(void) {\n"
                                     "	layer = 0;\n"
                                     "	vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n"
                                     "	gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n"
                                     "}\n";

  // The way to sample the EFB is based on the on the current configuration.
  // As we use the same sampling way for both interpreting shaders, the sampling
  // shader are generated first:
  std::string sampler;
  if (m_msaaSamples <= 1)
  {
    // non-msaa, so just fetch the pixel
    sampler = "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
              "vec4 sampleEFB(ivec3 pos) {\n"
              "	return texelFetch(samp9, pos, 0);\n"
              "}\n";
  }
  else if (g_ActiveConfig.backend_info.bSupportsSSAA)
  {
    // msaa + sample shading available, so just fetch the sample
    // This will lead to sample shading, but it's the only way to not loose
    // the values of each sample.
    if (m_EFBLayers > 1)
    {
      sampler = "SAMPLER_BINDING(9) uniform sampler2DMSArray samp9;\n"
                "vec4 sampleEFB(ivec3 pos) {\n"
                "	return texelFetch(samp9, pos, gl_SampleID);\n"
                "}\n";
    }
    else
    {
      sampler = "SAMPLER_BINDING(9) uniform sampler2DMS samp9;\n"
                "vec4 sampleEFB(ivec3 pos) {\n"
                "	return texelFetch(samp9, pos.xy, gl_SampleID);\n"
                "}\n";
    }
  }
  else
  {
    // msaa without sample shading: calculate the mean value of the pixel
    std::stringstream samples;
    samples << m_msaaSamples;
    if (m_EFBLayers > 1)
    {
      sampler = "SAMPLER_BINDING(9) uniform sampler2DMSArray samp9;\n"
                "vec4 sampleEFB(ivec3 pos) {\n"
                "	vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n"
                "	for(int i=0; i<" +
                samples.str() + "; i++)\n"
                                "		color += texelFetch(samp9, pos, i);\n"
                                "	return color / " +
                samples.str() + ";\n"
                                "}\n";
    }
    else
    {
      sampler = "SAMPLER_BINDING(9) uniform sampler2DMS samp9;\n"
                "vec4 sampleEFB(ivec3 pos) {\n"
                "	vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n"
                "	for(int i=0; i<" +
                samples.str() + "; i++)\n"
                                "		color += texelFetch(samp9, pos.xy, i);\n"
                                "	return color / " +
                samples.str() + ";\n"
                                "}\n";
    }
  }

  std::string ps_rgba6_to_rgb8 =
      sampler + "flat in int layer;\n"
                "out vec4 ocol0;\n"
                "void main()\n"
                "{\n"
                "	ivec4 src6 = ivec4(round(sampleEFB(ivec3(gl_FragCoord.xy, layer)) * 63.f));\n"
                "	ivec4 dst8;\n"
                "	dst8.r = (src6.r << 2) | (src6.g >> 4);\n"
                "	dst8.g = ((src6.g & 0xF) << 4) | (src6.b >> 2);\n"
                "	dst8.b = ((src6.b & 0x3) << 6) | src6.a;\n"
                "	dst8.a = 255;\n"
                "	ocol0 = float4(dst8) / 255.f;\n"
                "}";

  std::string ps_rgb8_to_rgba6 =
      sampler + "flat in int layer;\n"
                "out vec4 ocol0;\n"
                "void main()\n"
                "{\n"
                "	ivec4 src8 = ivec4(round(sampleEFB(ivec3(gl_FragCoord.xy, layer)) * 255.f));\n"
                "	ivec4 dst6;\n"
                "	dst6.r = src8.r >> 2;\n"
                "	dst6.g = ((src8.r & 0x3) << 4) | (src8.g >> 4);\n"
                "	dst6.b = ((src8.g & 0xF) << 2) | (src8.b >> 6);\n"
                "	dst6.a = src8.b & 0x3F;\n"
                "	ocol0 = float4(dst6) / 63.f;\n"
                "}";

  std::stringstream vertices, layers;
  vertices << m_EFBLayers * 3;
  layers << m_EFBLayers;
  std::string gs = "layout(triangles) in;\n"
                   "layout(triangle_strip, max_vertices = " +
                   vertices.str() + ") out;\n"
                                    "flat out int layer;\n"
                                    "void main()\n"
                                    "{\n"
                                    "	for (int j = 0; j < " +
                   layers.str() + "; ++j) {\n"
                                  "		for (int i = 0; i < 3; ++i) {\n"
                                  "			layer = j;\n"
                                  "			gl_Layer = j;\n"
                                  "			gl_Position = gl_in[i].gl_Position;\n"
                                  "			EmitVertex();\n"
                                  "		}\n"
                                  "		EndPrimitive();\n"
                                  "	}\n"
                                  "}\n";

  ProgramShaderCache::CompileShader(m_pixel_format_shaders[0], vs, ps_rgb8_to_rgba6.c_str(),
                                    (m_EFBLayers > 1) ? gs : "");
  ProgramShaderCache::CompileShader(m_pixel_format_shaders[1], vs, ps_rgba6_to_rgb8.c_str(),
                                    (m_EFBLayers > 1) ? gs : "");

  ProgramShaderCache::CompileShader(
      m_EfbPokes,
      StringFromFormat("in vec2 rawpos;\n"
                       "in vec4 color0;\n"  // color
                       "in int color1;\n"   // depth
                       "out vec4 v_c;\n"
                       "out float v_z;\n"
                       "void main(void) {\n"
                       "	gl_Position = vec4(((rawpos + 0.5) / vec2(640.0, 528.0) * 2.0 - 1.0) * "
                       "vec2(1.0, -1.0), 0.0, 1.0);\n"
                       "	gl_PointSize = %d.0 / 640.0;\n"
                       "	v_c = color0.bgra;\n"
                       "	v_z = float(color1 & 0xFFFFFF) / 16777216.0;\n"
                       "}\n",
                       m_targetWidth),

      StringFromFormat("in vec4 %s_c;\n"
                       "in float %s_z;\n"
                       "out vec4 ocol0;\n"
                       "void main(void) {\n"
                       "	ocol0 = %s_c;\n"
                       "	gl_FragDepth = %s_z;\n"
                       "}\n",
                       m_EFBLayers > 1 ? "g" : "v", m_EFBLayers > 1 ? "g" : "v",
                       m_EFBLayers > 1 ? "g" : "v", m_EFBLayers > 1 ? "g" : "v"),

      m_EFBLayers > 1 ? StringFromFormat("layout(points) in;\n"
                                         "layout(points, max_vertices = %d) out;\n"
                                         "in vec4 v_c[1];\n"
                                         "in float v_z[1];\n"
                                         "out vec4 g_c;\n"
                                         "out float g_z;\n"
                                         "void main()\n"
                                         "{\n"
                                         "	for (int j = 0; j < %d; ++j) {\n"
                                         "		gl_Layer = j;\n"
                                         "		gl_Position = gl_in[0].gl_Position;\n"
                                         "		gl_PointSize = %d.0 / 640.0;\n"
                                         "		g_c = v_c[0];\n"
                                         "		g_z = v_z[0];\n"
                                         "		EmitVertex();\n"
                                         "		EndPrimitive();\n"
                                         "	}\n"
                                         "}\n",
                                         m_EFBLayers, m_EFBLayers, m_targetWidth) :
                        "");
  glGenBuffers(1, &m_EfbPokes_VBO);
  glGenVertexArrays(1, &m_EfbPokes_VAO);
  glBindBuffer(GL_ARRAY_BUFFER, m_EfbPokes_VBO);
  glBindVertexArray(m_EfbPokes_VAO);
  glEnableVertexAttribArray(SHADER_POSITION_ATTRIB);
  glVertexAttribPointer(SHADER_POSITION_ATTRIB, 2, GL_UNSIGNED_SHORT, 0, sizeof(EfbPokeData),
                        (void*)offsetof(EfbPokeData, x));
  glEnableVertexAttribArray(SHADER_COLOR0_ATTRIB);
  glVertexAttribPointer(SHADER_COLOR0_ATTRIB, 4, GL_UNSIGNED_BYTE, 1, sizeof(EfbPokeData),
                        (void*)offsetof(EfbPokeData, data));
  glEnableVertexAttribArray(SHADER_COLOR1_ATTRIB);
  glVertexAttribIPointer(SHADER_COLOR1_ATTRIB, 1, GL_INT, sizeof(EfbPokeData),
                         (void*)offsetof(EfbPokeData, data));

  if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
    glEnable(GL_PROGRAM_POINT_SIZE);
}
Ejemplo n.º 8
0
/**
 * Do error-check tests for texture targets
 */
static bool
test_target_errors(GLenum target)
{
	GLint width = 64, height = 14, depth = 8;
	const GLsizei levels = 1;
	GLuint tex;
	enum piglit_result pass = true;
	GLenum legalTargets[4];
	unsigned int numTargets, numIllegalTargets;
	GLenum illegalTargets[] = {
		GL_TEXTURE_1D,
		GL_TEXTURE_2D,
		GL_TEXTURE_3D,
		GL_TEXTURE_CUBE_MAP,
		GL_TEXTURE_RECTANGLE,
		GL_TEXTURE_1D_ARRAY,
		GL_TEXTURE_2D_ARRAY,
		GL_TEXTURE_CUBE_MAP_ARRAY,
		GL_TEXTURE_2D_MULTISAMPLE,
		GL_TEXTURE_2D_MULTISAMPLE_ARRAY
	};
	GLsizei texSamples;

	if (piglit_is_extension_supported("GL_ARB_texture_storage_multisample")) {
		numIllegalTargets = ARRAY_SIZE(illegalTargets);
		glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &texSamples);
	} else {
		numIllegalTargets =  ARRAY_SIZE(illegalTargets) -2;
		texSamples = 1;
	}

	glGenTextures(1, &tex);   /* orig tex */
	glBindTexture(target, tex);

	switch (target) {
	case GL_TEXTURE_1D:
		glTexStorage1D(target, levels, GL_RGBA8, width);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_1D, GL_TEXTURE_1D_ARRAY, 0);
		break;
	case GL_TEXTURE_1D_ARRAY:
		glTexStorage2D(target, levels, GL_RGBA8, width, height);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_1D, GL_TEXTURE_1D_ARRAY, 0);
		break;
	case GL_TEXTURE_2D:
		glTexStorage2D(target, levels, GL_RGBA8, width, height);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY, 0);
		break;
	case  GL_TEXTURE_RECTANGLE:
		glTexStorage2D(target, levels, GL_RGBA8, width, height);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_RECTANGLE, 0);
		break;
	case GL_TEXTURE_CUBE_MAP:
		width = height;
		glTexStorage2D(target, levels, GL_RGBA8, width, height);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_CUBE_MAP, GL_TEXTURE_2D,
				    GL_TEXTURE_2D_ARRAY,
				    GL_TEXTURE_CUBE_MAP_ARRAY, 0);
		break;
	case GL_TEXTURE_3D:
		glTexStorage3D(target, levels, GL_RGBA8, width, height, depth);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_3D, 0);
		break;
	case GL_TEXTURE_CUBE_MAP_ARRAY:
	case GL_TEXTURE_2D_ARRAY:
		height = width;
		glTexStorage3D(target, levels, GL_RGBA8, width, height, depth*6);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_CUBE_MAP, GL_TEXTURE_2D,
				    GL_TEXTURE_2D_ARRAY,
				    GL_TEXTURE_CUBE_MAP_ARRAY, 0);
		break;
	case GL_TEXTURE_2D_MULTISAMPLE:
		glTexStorage2DMultisample(target, texSamples, GL_RGBA8,
					  width, height, GL_TRUE);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_2D_MULTISAMPLE,
				    GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0);
		break;
	case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
		glTexStorage3DMultisample(target, texSamples, GL_RGBA8,
					  width, height, depth, GL_TRUE);
		numTargets = update_valid_arrays(legalTargets, illegalTargets,
				    numIllegalTargets,
				    GL_TEXTURE_2D_MULTISAMPLE,
				    GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0);
		break;
	default:
		assert(0);
		numTargets = 0;
		break;
	}

	if (!piglit_check_gl_error(GL_NO_ERROR)) {
		printf("%s Found gl errors prior to testing glTextureView\n",
				   TestName);
		pass = false;
		goto err_out;
	}

	/* ensure TextureView of legal targets  works without gl errors */
	pass = pass && check_target_array(GL_NO_ERROR, numTargets, legalTargets,
					  GL_RG16, tex, levels);
	/* ensure TextureView  of illegal targets returns an error */
	pass = pass && check_target_array(GL_INVALID_OPERATION,
					  numIllegalTargets,
					  illegalTargets,
					  GL_RG16, tex, levels);
err_out:
	glDeleteTextures(1, &tex);

	return pass;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglTexStorage2DMultisample(JNIEnv *__env, jclass clazz, jint target, jint samples, jint internalformat, jint width, jint height, jboolean fixedsamplelocations, jlong __functionAddress) {
	glTexStorage2DMultisamplePROC glTexStorage2DMultisample = (glTexStorage2DMultisamplePROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glTexStorage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
}
Ejemplo n.º 10
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_glTexStorage2DMultisample(JNIEnv *__env, jclass clazz, jint target, jint samples, jint internalformat, jint width, jint height, jboolean fixedsamplelocations) {
    glTexStorage2DMultisamplePROC glTexStorage2DMultisample = (glTexStorage2DMultisamplePROC)tlsGetFunction(904);
    UNUSED_PARAM(clazz)
    glTexStorage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglTexStorage2DMultisample(JNIEnv *env, jclass clazz, jint target, jint samples, jint internalformat, jint width, jint height, jboolean fixedsamplelocations, jlong function_pointer) {
	glTexStorage2DMultisamplePROC glTexStorage2DMultisample = (glTexStorage2DMultisamplePROC)((intptr_t)function_pointer);
	glTexStorage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
}