2016-10-17 3 views
2

私はここにGLSLを使用して(エッジを探す)5×5畳み込みフィルタを実装しようとしていますが、.glslソースの私のコードです:「にTexture2D」:関数はフォワードCompatibileコンテキストで削除され

#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); 
} 

私は私のコードを実行すると、それが与えます私のエラー:

奇妙なことは、私は他のLinux上でコードを実行しようとした後、それはちょうどうまく動作します。また、私がtexture2Dget_pixel()に変更したときには、textureという機能を返すだけで、それは魅力的だった。誰かがどこに問題があるのか​​説明できますか?

+0

実際には、 'texture2d'がフォワード互換のコンテキストで1台のマシンで動作している場合、ドライバーの問題が最もよく似ています。 –

答えて

5

エラーには、知る必要があることがすべて記載されています。 texture2Dは、GLSL 1.00日の旧機能です。これは削除され、sampler2Dに制限されるのではなく、ほとんどのサンプラータイプで機能するために関数オーバーロードを使用するtextureに置き換えられました。したがって、コアプロファイルまたはフォワード互換のコンテキストでは、texture2Dを呼び出すことはできません。

+0

Thx - 'textureCube'と同じ問題があり、' texture'の置き換えも同様です – Philipp

関連する問題