示例#1
0
    virtual void startup()
    {
        static const GLubyte toon_tex_data[] =
        {
            0x44, 0x00, 0x00, 0x00,
            0x88, 0x00, 0x00, 0x00,
            0xCC, 0x00, 0x00, 0x00,
            0xFF, 0x00, 0x00, 0x00
        };

        glGenTextures(1, &tex_toon);
        glBindTexture(GL_TEXTURE_1D, tex_toon);
        glTexStorage1D(GL_TEXTURE_1D, 1, GL_RGB8, sizeof(toon_tex_data) / 4);
        glTexSubImage1D(GL_TEXTURE_1D, 0,
                        0, sizeof(toon_tex_data) / 4,
                        GL_RGBA, GL_UNSIGNED_BYTE,
                        toon_tex_data);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

        object.load("media/objects/torus_nrms_tc.sbm");

        load_shaders();

        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
    }
void GFXGLTextureObject::unlock(U32 mipLevel)
{
   if(!mLockedRect.bits)
      return;

   PRESERVE_TEXTURE(mBinding);
   glBindTexture(mBinding, mHandle);
   glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, mBuffer);
   glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * mBytesPerTexel, mFrameAllocatorPtr, GL_STREAM_DRAW);

   if(mBinding == GL_TEXTURE_2D)
	   glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, 
		  mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
   else if(mBinding == GL_TEXTURE_1D)
		glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y), 
		  (mLockedRectRect.extent.x > 1 ? mLockedRectRect.extent.x : mLockedRectRect.extent.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
   
   glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

   mLockedRect.bits = NULL;
#if TORQUE_DEBUG
   AssertFatal(mFrameAllocatorMarkGuard == FrameAllocator::getWaterMark(), "");
#endif
   FrameAllocator::setWaterMark(mFrameAllocatorMark);
   mFrameAllocatorMark = 0;
   mFrameAllocatorPtr = NULL;
}
示例#3
0
文件: trixel.c 项目: jckarter/Trixel
void
trixel_update_brick_textures(trixel_brick * brick)
{
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_3D, brick->voxmap_texture);
    /* Leopard nvidia driver bug seems to make glTexSubImage3D only update the z = 0 plane of the texture
    glTexSubImage3D(
        GL_TEXTURE_3D, 0,
        0, 0, 0,
        brick->v.dimensions.x, brick->v.dimensions.y, brick->v.dimensions.z,
        GL_LUMINANCE, GL_UNSIGNED_BYTE, brick->v.data
    );
    */
    glTexImage3D(
        GL_TEXTURE_3D, 0, GL_LUMINANCE8,
        brick->v.dimensions.x, brick->v.dimensions.y, brick->v.dimensions.z,
        0, GL_LUMINANCE, GL_UNSIGNED_BYTE, brick->v.data
    );

    _gl_report_error("trixel_update_brick_textures voxmap");

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_1D, brick->palette_texture);
    glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RGBA, GL_UNSIGNED_BYTE, brick->palette_data);

    _gl_report_error("trixel_update_brick_textures palette");

    _generate_normal_texture(brick);
    
    STATE(brick->t)->render_path->make_vertex_buffer_for_brick(brick->t, brick);
    glActiveTexture(GL_TEXTURE0);
}
示例#4
0
    void startup()
    {
        //		_renderingProgram.CreateAndLinkProgram("Shaders/Common/Default.vert", "Shaders/Common/Default.frag");
        _renderingProgram.CreateProgram();
        _renderingProgram.AttachShader("Shaders/Cellshading/Cellshading.vert");
        _renderingProgram.AttachShader("Shaders/Cellshading/Cellshading.frag");
        _renderingProgram.Link();
        projLocation = glGetUniformLocation(_renderingProgram.GetHandler(), "proj_matrix");
        mvLocation = glGetUniformLocation(_renderingProgram.GetHandler(), "mv_matrix");

        static const GLubyte tex[] =
        {
            0x44, 0x00, 0x00, 0x00,
            0x88, 0x00, 0x00, 0x00,
            0xCC, 0x00, 0x00, 0x00,
            0xFF, 0x00, 0x00, 0x00
        };

        glGenTextures(1, &_texToon);
        glBindTexture(GL_TEXTURE_1D, _texToon);
        glTexStorage1D(GL_TEXTURE_1D, 1, GL_RGB8, sizeof(tex) / 4);
        glTexSubImage1D(GL_TEXTURE_1D, 0, 0, sizeof(tex) / 4, GL_RGBA, GL_UNSIGNED_BYTE, tex);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        
        _object.load("media/objects/torus_nrms_tc.sbm");

        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        _renderingProgram.Use();
    }
void GFXGLTextureObject::reloadFromCache()
{
   if(!mZombieCache)
      return;
      
   if(mBinding == GL_TEXTURE_3D)
   {
      static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
      delete[] mZombieCache;
      mZombieCache = NULL;
      return;
   }
   
   PRESERVE_TEXTURE(mBinding);
   glBindTexture(mBinding, mHandle);

   if(mBinding == GL_TEXTURE_2D)
		glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
   else if(mBinding == GL_TEXTURE_1D)
		glTexSubImage1D(mBinding, 0, 0, (mTextureSize.x > 1 ? mTextureSize.x : mTextureSize.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
   
   if(GFX->getCardProfiler()->queryProfile("GL::Workaround::needsExplicitGenerateMipmap") && mMipLevels != 1)
      glGenerateMipmapEXT(mBinding);
      
   delete[] mZombieCache;
   mZombieCache = NULL;
   mIsZombie = false;
}
示例#6
0
//.......................................................................................
unsigned int Object::AsyncTextureUpload(unsigned int _nbytes)
{
	int offsetx = 0, offsety = 0, offsetz = 0;
	unsigned int uploadedBytes = m_nTextureBytes - m_nTextureBytesLeft;

	// prepare pixel data for upload
	if (_nbytes > m_nTextureBytesLeft)
		_nbytes = m_nTextureBytesLeft;

	// upload data
	glBindTexture(m_texture.m_eTextureType, m_texture.m_pTexture->TextureID());
	GLtextureFormat format = m_texture.m_pTexture->TextureFormat();

	// copy part of data destined for upload
	unsigned char *data = (unsigned char *)malloc(_nbytes);
	memcpy(data, &m_texture.m_pTexture->TextureData()[uploadedBytes], _nbytes);

	switch (m_texture.m_eTextureType)
	{
	case GL_TEXTURE_1D:
		glTexSubImage1D(m_texture.m_eTextureType,
			0,
			uploadedBytes,
			m_texture.m_pTexture->TexWidth(),
			format.texServerFormat,
			GL_UNSIGNED_BYTE,
			data);
		break;

	case GL_TEXTURE_2D:
		// caluclate offsets
		offsety = uploadedBytes / m_texture.m_pTexture->TexHeight();
		offsetx = uploadedBytes - (offsety * m_texture.m_pTexture->TexHeight());
		
		// upload
		glTexSubImage2D(m_texture.m_eTextureType,
			0,
			offsetx,
			offsety,
			m_texture.m_pTexture->TexWidth(),
			m_texture.m_pTexture->TexHeight(),
			format.texServerFormat,
			GL_UNSIGNED_BYTE,
			data);
		break;

	case GL_TEXTURE_3D:
		// calculate offsets
		//int z = m_texture.m_pTexture->TexDepth();
		//offsetz = uploadedBytes / (z * z);
		//offsety = (uploadedBytes - offsetz*offsetz) / y på nåt sätt 
		break;
	}
	
	// release tmp data
	free(data);

	return (_nbytes);

} // end Object::AsyncTextureUpload()
示例#7
0
文件: t.cpp 项目: soulik/luagl
	int gl_TexSubImage1D(State& state){
		size_t size = 0;
		unsigned char * data;
		vector<unsigned char> _data;

		if (state.stack->is<LUA_TLIGHTUSERDATA>(6)){
			data = (unsigned char *) state.stack->to<void*>(6);
		}else{
			if (state.stack->is<LUA_TTABLE>(6)){
				size = getArray<unsigned char>(state, 6, _data);
				data = _data.data();
			}else{
				data = nullptr;
			}
		}

		glTexSubImage1D(
			(GLenum) state.stack->to<int>(1),
			(GLint) state.stack->to<int>(2),
			(GLint) state.stack->to<int>(3),
			(GLsizei) state.stack->to<int>(4),
			(GLenum) state.stack->to<int>(5),
			(GLenum) GL_UNSIGNED_BYTE,
			(GLvoid*) data
			);
		return 0;
	}
示例#8
0
static void GLTexSubImage1DBase(
    GLenum                      target,
    std::uint32_t               mipLevel,
    std::int32_t                x,
    std::uint32_t               width,
    const SrcImageDescriptor&   imageDesc)
{
    if (IsCompressedFormat(imageDesc.format))
    {
        glCompressedTexSubImage1D(
            target,
            static_cast<GLint>(mipLevel),
            x,
            static_cast<GLsizei>(width),
            GLTypes::Map(imageDesc.format),
            static_cast<GLsizei>(imageDesc.dataSize),
            imageDesc.data
        );
    }
    else
    {
        glTexSubImage1D(
            target,
            static_cast<GLint>(mipLevel),
            x,
            static_cast<GLsizei>(width),
            GLTypes::Map(imageDesc.format),
            GLTypes::Map(imageDesc.dataType),
            imageDesc.data
        );
    }
}
示例#9
0
  bool UpdateR32Texture( Texture * tex, float * data )
  {
    glActiveTexture( GL_TEXTURE0 + ((GLTexture*)tex)->unit );
    glBindTexture( GL_TEXTURE_1D, ((GLTexture*)tex)->ID );
    glTexSubImage1D( GL_TEXTURE_1D, 0, 0, tex->width, GL_RED, GL_FLOAT, data );

    return true;
  }
示例#10
0
文件: ogl-lut.cpp 项目: rlk/thumb
void ogl::lut::blit(const GLvoid *P, GLsizei X, GLsizei W) const
{
    bind();
    {
        glTexSubImage1D(target, 0, X, W, form, type, P);
    }
    free();
}
void QOpenGLTextureHelper::qt_TextureSubImage1D(GLuint texture, GLenum target, GLenum bindingTarget, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels)
{
    GLint oldTexture;
    glGetIntegerv(bindingTarget, &oldTexture);
    glBindTexture(target, texture);
    glTexSubImage1D(target, level, xoffset, width, format, type, pixels);
    glBindTexture(target, oldTexture);
}
示例#12
0
文件: Texture.cpp 项目: naohisas/KVS
void Texture::setSubImage1D( GLsizei width, const GLvoid* data, GLint xoffset )
{
    KVS_ASSERT( m_target == GL_TEXTURE_1D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    KVS_GL_CALL( glTexSubImage1D( m_target, level, xoffset, width, m_external_format, m_external_type, data ) );
}
示例#13
0
void
ColorMapEditor::update_colors ()
{
    glBindTexture(GL_TEXTURE_1D,color_tex);
    glTexSubImage1D(
        GL_TEXTURE_1D, 0, 0, resolution,
        GL_RGBA, GL_UNSIGNED_BYTE, rgba
    );
}
示例#14
0
void VW_GL_SetVGAPalette(const uint8_t vgapal[16][3])
{
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_1D, palettetexture);
	glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 16, GL_RGB, GL_UNSIGNED_BYTE, &vgapal[0][0]);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glActiveTexture(GL_TEXTURE0);
}
示例#15
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglTexSubImage1D :: render(GemState *state) {
  if (!state)return;
  pixBlock*img=NULL;  state->get(GemState::_PIX, img);  if(!img || !&img->image)return;
  target=GL_TEXTURE_1D;
  glTexSubImage1D (target, level, xoffset, width,
		   img->image.format,
		   img->image.type,
		   img->image.data);
}
示例#16
0
void Texture1D::setSubImage(int level, int x, int w, TextureFormat f, PixelType t, const Buffer::Parameters &s, const Buffer &pixels)
{
    bindToTextureUnit();
    pixels.bind(GL_PIXEL_UNPACK_BUFFER);
    s.set();
    glTexSubImage1D(GL_TEXTURE_1D, level, x, w, getTextureFormat(f), getPixelType(t), pixels.data(0));
    s.unset();
    pixels.unbind(GL_PIXEL_UNPACK_BUFFER);
    assert(FrameBuffer::getError() == GL_NO_ERROR);
}
示例#17
0
static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
{
	void *pixels = MEM_callocN(sizeof(char)*4*w*h, "GPUTextureEmptyPixels");

	if (target == GL_TEXTURE_1D)
		glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
	else
		glTexSubImage2D(target, 0, x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
	
	MEM_freeN(pixels);
}
示例#18
0
void OpenGLTexture::updateHardwareTextureArea(
    const dim::vector3di &Pos, const dim::vector3di &Size, const void* ImageBuffer, s32 Level)
{
    switch (Type_)
    {
        case TEXTURE_1D:
        {
            glTexSubImage1D(
                GL_TEXTURE_1D, Level, Pos.X, Size.X, GLFormat_, GLType_, ImageBuffer
            );
        }
        break;
        
        case TEXTURE_1D_ARRAY:
        case TEXTURE_2D:
        case TEXTURE_RECTANGLE:
        {
            glTexSubImage2D(
                GLDimension_, Level, Pos.X, Pos.Y, Size.X, Size.Y, GLFormat_, GLType_, ImageBuffer
            );
        }
        break;
        
        case TEXTURE_2D_ARRAY:
        case TEXTURE_CUBEMAP_ARRAY:
        case TEXTURE_3D:
        {
            glTexSubImage3DEXT(
                GLDimension_, Level, Pos.X, Pos.Y, Pos.Z, Size.X, Size.Y, Size.Z, GLFormat_, GLType_, ImageBuffer
            );
        }
        break;
        
        case TEXTURE_CUBEMAP:
        {
            for (s32 i = 0; i < 6; ++i)
            {
                glTexSubImage2D(
                    GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Level,
                    Pos.X, Pos.Y, Size.X, Size.Y, GLFormat_, GLType_, ImageBuffer
                );
            }
        }
        break;
        
        case TEXTURE_BUFFER:
            // ignore that here
            break;
        
        default:
            io::Log::error("Unsupported texture dimension type for the OpenGL render system");
            break;
    }
}
示例#19
0
void Rect::UpdateTexData(int a_dataSize, float* a_data)
{	
	glUseProgram(m_programID);
	//uniform

	glBindTexture(GL_TEXTURE_1D, m_equaliserTex);
	glTexSubImage1D(GL_TEXTURE_1D, 0, 0, a_dataSize, GL_RED, GL_FLOAT, a_data);

	glUseProgram(0);
	
}
//==============================================================================
void cTexture1d::update(cRenderOptions& a_options)
{
#ifdef C_USE_OPENGL

    if (m_textureID[a_options.m_displayContext] == 0)
    {
        glGenTextures(1, &m_textureID[a_options.m_displayContext]);
        glBindTexture(GL_TEXTURE_2D, m_textureID[a_options.m_displayContext]);

        glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_WRAP_S, m_wrapSmode);
        glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_MAG_FILTER, m_magFunction);
        glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_MIN_FILTER, m_minFunction);

        glTexImage1D(GL_TEXTURE_1D,
            0,
            GL_RGBA,
            m_image->getWidth() * m_image->getHeight(),
            0,
            m_image->getFormat(),
            m_image->getType(),
            m_image->getData());
    }
    else
    {
        glBindTexture(GL_TEXTURE_2D, m_textureID[a_options.m_displayContext]);

        glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_WRAP_S, m_wrapSmode);
        glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_MAG_FILTER, m_magFunction);
        glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_MIN_FILTER, m_minFunction);

        glTexSubImage1D(GL_TEXTURE_2D, 
                        0, 
                        0, 
                        m_image->getWidth() * m_image->getHeight(), 
                        m_image->getFormat(), 
                        m_image->getType(), 
                        m_image->getData());
    }
    
    /*
    glPixelStorei(GL_UNPACK_ALIGNMENT,   4);
    glPixelStorei(GL_UNPACK_ROW_LENGTH,  0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,   0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    */

    if (m_useMipmaps)
    {
        glEnable (GL_TEXTURE_2D);
        glGenerateMipmap(GL_TEXTURE_2D);
    }

#endif
}
示例#21
0
文件: Texture.cpp 项目: mutexre/Base
void GL::Texture::subImage1D(TextureTarget target, GLint level,
                             GLint xOffset,
                             GLsizei width,
                             PixelData::Format format, PixelData::Type type,
                             const void* data)
{
    glTexSubImage1D(GLenum(target), level,
                    xOffset,
                    width,
                    GLenum(format), GLenum(type),
                    data);
}
static void
load_texture_1d(void)
{
	float p[TEX_SIZE * 4];
	int x;

	for (x = 0; x < TEX_SIZE; x++) {
		int c = x / (TEX_SIZE/4);
		memcpy(&p[x*4], colors[c], sizeof(float) * 4);
	}

	glTexSubImage1D(GL_TEXTURE_1D, 0, 0, TEX_SIZE, GL_RGBA, GL_FLOAT, p);
}
示例#23
0
void CTexture::Update(CPixelBuffer *pBuffer, int nLevel)
{
	Bind();
	switch(m_nType)
	{
		case GL_TEXTURE_1D:
			glTexSubImage1D(GL_TEXTURE_1D, nLevel, 0, pBuffer->GetWidth(), pBuffer->GetFormat(), pBuffer->GetDataType(), pBuffer->GetBuffer());
			break;
		case GL_TEXTURE_2D:
			glTexSubImage2D(GL_TEXTURE_2D, nLevel, 0, 0, pBuffer->GetWidth(), pBuffer->GetHeight(), pBuffer->GetFormat(), pBuffer->GetDataType(), pBuffer->GetBuffer());
			break;
	}
}
示例#24
0
/*
 * update1DColorMap
 *
 * parameter dataItem - DataItem*
 */
void Scene::update1DColorMap(DataItem* dataItem) const {
    if (colorMapChanged) {
        unsigned char * texels = new unsigned char[256 * 4];
        for (int i = 0; i < 256; i++) {
            texels[4 * i + RED] = colormap[4 * (i * 256 + i) + RED];
            texels[4 * i + GREEN] = colormap[4 * (i * 256 + i) + GREEN];
            texels[4 * i + BLUE] = colormap[4 * (i * 256 + i) + BLUE];
            texels[4 * i + ALPHA] = colormap[4 * (i * 256 + i) + ALPHA];
        }
        glEnable(GL_TEXTURE_1D);
        glBindTexture(GL_TEXTURE_1D, dataItem->colormap1DName);
        glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RGBA, GL_UNSIGNED_BYTE, texels);
        glBindTexture(GL_TEXTURE_1D, 0);
        glDisable(GL_TEXTURE_1D);
        delete[] texels;
    }
} // end update1DColorMap()
示例#25
0
  * @param format int
  */
void GLTexture::putBuffer(float* floatArray, int format)
{
	if (tex[0] == 0)
    {
		initTexture((int)width, (int)height);
	}
	int glFormat = GL_RGBA; //format;  //GL_LUMINANCE, GL_RGB, GL_RGBA;
	glEnable(texTarget);
    glBindTexture(texTarget, tex[0]);
    if (texTarget == GL_TEXTURE_1D)
		glTexSubImage1D(texTarget, 0, 0, width, glFormat, GL_FLOAT, floatArray);
	else
		glTexSubImage2D(texTarget, 0, 0, 0, width, height, glFormat, type, floatArray);

	glBindTexture(texTarget, 0);
	glDisable(texTarget);
示例#26
0
	void OGLTexture1D::UpdateSubresource1D(uint32_t array_index, uint32_t level,
		uint32_t x_offset, uint32_t width,
		void const * data)
	{
		OGLRenderEngine& re = *checked_cast<OGLRenderEngine*>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance());

		GLint gl_internalFormat;
		GLenum gl_format;
		GLenum gl_type;
		OGLMapping::MappingFormat(gl_internalFormat, gl_format, gl_type, format_);

		re.BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
		re.BindTexture(0, target_type_, texture_);

		if (IsCompressedFormat(format_))
		{
			uint32_t const block_size = NumFormatBytes(format_) * 4;
			GLsizei const image_size = ((width + 3) / 4) * block_size;

			if (array_size_ > 1)
			{
				glCompressedTexSubImage2D(target_type_, level, x_offset, array_index,
					width, 1, gl_format, image_size, data);
			}
			else
			{
				glCompressedTexSubImage1D(target_type_, level, x_offset,
					width, gl_format, image_size, data);
			}
		}
		else
		{
			if (array_size_ > 1)
			{
				glTexSubImage2D(target_type_, level, x_offset, array_index, width, 1,
					gl_format, gl_type, data);
			}
			else
			{
				glTexSubImage1D(target_type_, level, x_offset, width,
					gl_format, gl_type, data);
			}
		}
	}
示例#27
0
文件: shPaint.c 项目: Chazzz/pyShiva
void shUpdateColorRampTexture(SHPaint *p)
{
  SHint s=0;
  SHStop *stop1, *stop2;
  SHfloat rgba[SH_GRADIENT_TEX_COORDSIZE];
  SHint x1=0, x2=0, dx, x;
  SHColor dc, c;
  SHfloat k;
  
  /* Write first pixel color */
  stop1 = &p->stops.items[0];
  CSTORE_RGBA1D_F(stop1->color, rgba, x1);
  
  /* Walk stops */
  for (s=1; s<p->stops.size; ++s, x1=x2, stop1=stop2) {
    
    /* Pick next stop */
    stop2 = &p->stops.items[s];
    x2 = (SHint)(stop2->offset * (SH_GRADIENT_TEX_SIZE-1));
    
    SH_ASSERT(x1 >= 0 && x1 < SH_GRADIENT_TEX_SIZE &&
              x2 >= 0 && x2 < SH_GRADIENT_TEX_SIZE &&
              x1 <= x2);
    
    dx = x2 - x1;
    CSUBCTO(stop2->color, stop1->color, dc);
    
    /* Interpolate inbetween */
    for (x=x1+1; x<=x2; ++x) {
      
      k = (SHfloat)(x-x1)/dx;
      CSETC(c, stop1->color);
      CADDCK(c, dc, k);
      CSTORE_RGBA1D_F(c, rgba, x);
    }
  }
  
  /* Update texture image */
  glBindTexture(GL_TEXTURE_1D, p->texture);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glTexSubImage1D(GL_TEXTURE_1D, 0, 0, SH_GRADIENT_TEX_SIZE,
                  GL_RGBA, GL_FLOAT, rgba);
}
示例#28
0
void djvOpenGlLut::copy(const djvPixelData & in)
{
    //DJV_DEBUG("djvOpenGlLut::copy");
    //DJV_DEBUG_PRINT("in = " << in);

    const djvPixelDataInfo & info = in.info();

    djvOpenGlImage::stateUnpack(in.info());

    DJV_DEBUG_OPEN_GL(
        glTexSubImage1D(
            GL_TEXTURE_1D,
            0,
            0,
            info.size.x,
            djvOpenGlUtil::format(info.pixel, info.bgr),
            djvOpenGlUtil::type(info.pixel),
            in.data()));
}
示例#29
0
PlatformTexture1d::PlatformTexture1d(const Texture1d *texture) :
    PlatformTexture(texture)
{
    // Bind newly created texture
    GLuint textureBindingPrevious = BindTexture(mTexturePtr->mType, mTextureObj);

    {
        glTexStorage1D(GL_TEXTURE_1D, 1, mFormatInternal, mDimension[0]);

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mBufferObj);

        {
            glTexSubImage1D(GL_TEXTURE_1D, 0, 0, mDimension[0], mFormat, mType, nullptr);
        }

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    }

    // Restore previous texture binding
    BindTexture(mTexturePtr->mType, textureBindingPrevious);
}
示例#30
0
void DaoxShader_MakeGradientSampler( DaoxShader *self, DaoxColorGradient *gradient, int fill )
{
	GLfloat data[2*DAOX_MAX_GRADIENT_STOPS*4];
	int width = 2*DAOX_MAX_GRADIENT_STOPS;
	int i, n, gradientType;

	if( gradient == NULL ){
		glUniform1i(self->uniforms.gradientType, 0 );
		return;
	}

	n = gradient->stops->size;
	if( n > DAOX_MAX_GRADIENT_STOPS ) n = DAOX_MAX_GRADIENT_STOPS;
	memset( data, 0, n*2*4*sizeof(GLfloat) );
	for(i=0; i<n; ++i){
		DaoxColor color = gradient->colors->pod.colors[i];
		GLfloat *stop = data + 4*i;
		GLfloat *rgba = data + 4*(i+n);
		stop[0] = gradient->stops->pod.floats[i];
		rgba[0] = color.red;
		rgba[1] = color.green;
		rgba[2] = color.blue;
		rgba[3] = color.alpha;
	}
	gradientType = fill ? gradient->gradient : DAOX_GRADIENT_STROKE;
	//printf( "DaoxShader_MakeGradientSampler..... %i %i\n", gradientType , self->textures.gradientSampler );

	glUniform1i(self->uniforms.gradientType, gradientType );
	glUniform1i(self->uniforms.gradientStops, n );
	glUniform1f(self->uniforms.gradientRadius, gradient->radius );
	glUniform2fv(self->uniforms.gradientPoint1, 1, & gradient->points[0].x );
	glUniform2fv(self->uniforms.gradientPoint2, 1, & gradient->points[1].x );

	glActiveTexture(GL_TEXTURE0 + DAOX_GRADIENT_SAMPLER );
	glBindTexture(GL_TEXTURE_1D, self->textures.gradientSampler);
	glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 2*n, GL_RGBA, GL_FLOAT, data);
	glUniform1i(self->uniforms.gradientSampler, DAOX_GRADIENT_SAMPLER );
}