简体   繁体   English

'texture2D':在正向兼容上下文中删除了功能

[英]'texture2D' : function is removed in Forward Compatibile context

I am trying to implement 5x5 convolution filter (Find Edges) using GLSL here is my code of .glsl source: 我正在尝试使用GLSL实现5x5卷积过滤器(查找边缘),这是我的.glsl源代码:

#version 150
#define SIZE 25

// A texture is expected
uniform sampler2D Texture;

// The vertex shader fill feed this input
in vec2 FragTexCoord;

// The final color
out vec4 FragmentColor;

float matr[25];
float matg[25];
float matb[25];

vec4 get_pixel(in vec2 coords, in float x, in float y) {
   return texture2D(Texture, coords + vec2(x, y));
}

float convolve(in float[SIZE] kernel, in float[SIZE] matrix) {
   float res = 0.0;
   for (int i = 0; i < 25; i++)
      res += kernel[i] * matrix[i];
   return clamp(res, 0.0, 1.0);
}

void fill_matrix() {
   float dxtex = 1.0 / float(textureSize(Texture, 0));
   float dytex = 1.0 / float(textureSize(Texture, 0));
   float[25] mat;
   for (int i = 0; i < 5; i++)
      for(int j = 0; j < 5; j++) {
        vec4 pixel = get_pixel(FragTexCoord,float(i - 2) * dxtex, float(j - 2) * dytex);
         matr[i * 5 + j] = pixel[0];
         matg[i * 5 + j] = pixel[1];
         matb[i * 5 + j] = pixel[2];
      }
}

void main() {

  float[SIZE] ker_edge_detection = float[SIZE] (
    .0,.0, -1., .0, .0,
    .0, .0,-1., .0, .0,
    .0, .0, 4., .0, .0,
    .0, .0, -1., .0,.0,
    .0, .0, -1., .0, .0
  );

  fill_matrix();

  FragmentColor = vec4(convolve(ker_edge_detection,matr), convolve(ker_edge_detection,matg), convolve(ker_edge_detection,matb), 1.0);
}

When I run my code it gives me errors: 当我运行代码时,它给了我错误:

Error Compiling Fragment Shader ...
ERROR: 0:17: 'texture2D' : function is removed in Forward Compatibile context
ERROR: 0:17: 'texture2D' : no matching overloaded function found (using implicit conversion)


Error Linking Shader Program ...
Attached fragment shader is not compiled.

Function is removed in Forward Compatibile context

Weird thing is, when I've tried to run code on other linux and then windows machines it just worked fine. 奇怪的是,当我尝试在其他Linux和Windows计算机上运行代码时,它运行良好。 Also when I changed texture2D in get_pixel() function to return texture only it worked like a charm. 另外,当我在get_pixel()函数中更改texture2D以返回texture它只能像魅力一样工作。 Could someone explain where is a problem? 有人可以解释哪里出了问题吗?

The error says everything you need to know. 该错误说明了您需要了解的所有内容。 texture2D is an old function from the GLSL 1.00 days. texture2D是GLSL 1.00天texture2D的旧功能。 It was removed and replaced with texture , which uses function overloading to work on most sampler types, rather than being restricted to sampler2D . 将其删除并替换为texture ,该texture使用函数重载在大多数采样器类型上工作,而不是仅限于sampler2D So in a core profile or forward compatibility context, you cannot call texture2D . 因此,在核心配置文件或前向兼容性上下文中,您不能调用texture2D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM