小编two*_*two的帖子

Haskell中类型参数的右类型签名

我有两种数据类型,并希望编写一个返回这些数据类型数据的类:

data D1 a = Da1 a | Db1 a 
data D2 a = Da2 a | Db2 a 

class D a where
    extract :: ??? a -> a

instance D (D1 a) where
    extract (Da1 a) = a
    extract (Db1 a) = a

instance D (D2 a) where
    extract (Da2 a) = a
    extract (Db2 a) = a
Run Code Online (Sandbox Code Playgroud)

如果我只有一个类型D1或D2,我可以在类型签名中命名,但在有多种可能性的情况下我该怎么办?这甚至可能吗?

polymorphism haskell types type-signature parametric-polymorphism

4
推荐指数
1
解决办法
81
查看次数

在 vhdl 中将固定转换为 std_logic_vector 的正确方法是什么?

我正在尝试将 sfixed(从 ieee.fixed_pkg)转换为 std_logic_vector,我想知道正确的语法是什么以及为什么以下是(显然是错误的)。我尝试编译以下 3 种架构:

library ieee;
    use ieee.std_logic_1164.all;
    use ieee.fixed_pkg.all;

entity test is
    port (input: in sfixed(0 downto -7) := x"00";
    output: out std_logic_vector(7 downto 0) := x"00");
end;    
Run Code Online (Sandbox Code Playgroud)

架构一:

architecture a of test is begin 
    output <= std_logic_vector(input);
end;
Run Code Online (Sandbox Code Playgroud)

架构b:

architecture b of test is begin 
    proc: process (input) begin 
        output <= std_logic_vector(input);
    end process;
end;
Run Code Online (Sandbox Code Playgroud)

架构 c:

architecture c of test is begin 
    proc: process (input) begin 
        if ('1' and '1') then
            output <= std_logic_vector(input);
        end …
Run Code Online (Sandbox Code Playgroud)

vhdl

2
推荐指数
1
解决办法
5836
查看次数

glTexImage2D读出界限

我试图用glTexImage2D将数据读入纹理.似乎无论我尝试什么,第一行纹素都被正确读取,但是进一步的行是从内存方式创建的,超出了给定std :: vector的边界:

GLuint renderedTexture;
glGenTextures(1, &renderedTexture);
glBindTexture(GL_TEXTURE_2D, renderedTexture);

int w = 8;
int h = 8;
std::vector<GLuint> emptyData(w*h, 0);

emptyData[0] = 0xFF<<8; //blue
emptyData[1] = 0xFF<<16; //green
emptyData[3] = 0xFF<<24; //red
emptyData[w] = 0xFF<<16; // <- should be in second row, but is not shown

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0,GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, emptyData.data());
Run Code Online (Sandbox Code Playgroud)

根据纹理的大小,代码段错误.我已经尝试过使用GLubytes的矢量,但这也不起作用.我也试过了glPixelStorei(GL_UNPACK_ALIGNMENT, 1),但那也没用.我在这里错过了什么?

编辑:进一步的实验表明,以像素读取时假设的最小宽度似乎是128px.因此,如果我创建一个大小为64*64且需要x = 10,y = 14的单个像素的纹理,我必须先写入emptyData[10 + 14*128]并且必须预先保留适当的内存量.有人知道这是否依赖于平台或为什么会这样?

opengl textures

1
推荐指数
1
解决办法
83
查看次数