Skip to content

Commit

Permalink
Fix for zero size textures and 1-source alpha blending
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Burgess committed Feb 16, 2016
1 parent f7cec38 commit 7f88038
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 29 deletions.
2 changes: 2 additions & 0 deletions +vis/draw.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
glBlendFunc(GL.DST_ALPHA, GL.ONE_MINUS_DST_ALPHA);
case {'src' 'source'}
glBlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
case {'1-src' '1-source'}
glBlendFunc(GL.ONE_MINUS_SRC_ALPHA, GL.SRC_ALPHA);
end
%glColorMask(layer.colourMask(1), layer.colourMask(2),...
% layer.colourMask(3), layer.colourMask(4));
Expand Down
27 changes: 1 addition & 26 deletions +vis/loadLayerTextures.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,12 @@
%VIS.LOADLAYERTEXTURES Summary of this function goes here
% Detailed explanation goes here

global GL;

gltex = glGenTextures(numel(layers)); % make the OGL texture names
for ii = 1:numel(layers)
% rgba = uint8(round(255*layers(ii).rgba));
% rgba = permute(rgba(end:-1:1,:,:), [3 2 1]);

w = layers(ii).rgbaSize(1);
h = layers(ii).rgbaSize(2);
glBindTexture(GL.TEXTURE_2D, gltex(ii)); % bind our texture name
glTexImage2D(GL.TEXTURE_2D, 0, GL.RGBA, w, h, 0,...
GL.RGBA, GL.UNSIGNED_BYTE, layers(ii).rgba);
switch layers(ii).interpolation
case 'linear'
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.LINEAR);
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR);
case 'nearest'
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR);
otherwise
error('Invalid interpolation method ''%s''', layers(ii).interpolation);
end

if layers(ii).isPeriodic
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.REPEAT);
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.REPEAT);
else
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_BORDER);
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_BORDER);
glTexParameterfv(GL.TEXTURE_2D, GL.TEXTURE_BORDER_COLOR, single([0 0 0 0]));
end
vis.reloadLayerTexture(layers(ii));
end

end
Expand Down
6 changes: 5 additions & 1 deletion +vis/reloadLayerTexture.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function reloadLayerTexture(layer, gltex)
else
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_BORDER);
glTexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_BORDER);
glTexParameterfv(GL.TEXTURE_2D, GL.TEXTURE_BORDER_COLOR, single([0 0 0 0]));
if any(strcmp(layer.blending, {'1-src' '1-source'}))
glTexParameterfv(GL.TEXTURE_2D, GL.TEXTURE_BORDER_COLOR, single([0 0 0 1]));
else
glTexParameterfv(GL.TEXTURE_2D, GL.TEXTURE_BORDER_COLOR, single([0 0 0 0]));
end
end

end
Expand Down
6 changes: 4 additions & 2 deletions +vis/slimshady.vert
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ void main()
/*mat4 view = rot3(yax, posRad.x)*rot3(zax, posRad.y)*rot3(xax, viewRad);*/
gl_Position = projection*view*model*vec4(vertexPos.xyz, 1.0f);

vec2 texScale = vec2(180.0/texSize.x, 180.0/texSize.y);
vec2 texTrans = vec2(-texOffset.x/texSize.x, -texOffset.y/texSize.y);
vec2 safeTexSize = vec2(texSize.x != 0.0f ? texSize.x : 1e-10,
texSize.y != 0.0f ? texSize.y : 1e-10);
vec2 texScale = vec2(180.0/safeTexSize.x, 180.0/safeTexSize.y);
vec2 texTrans = vec2(-texOffset.x/safeTexSize.x, -texOffset.y/safeTexSize.y);
mat3 uvTrans = trans2(vec2(0.5) + texTrans)*scale2(texScale)*
rot2(texAngle*pi/180)*scale2(vec2(2.0, 1.0))*trans2(vec2(-0.5));
UV = (uvTrans*vec3(vertexUV.xy, 1.0f)).xy;
Expand Down
Binary file modified java/VisualRenderer$1.class
Binary file not shown.
Binary file modified java/VisualRenderer.class
Binary file not shown.

0 comments on commit 7f88038

Please sign in to comment.