Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
Can you make from this function HLSL (High Level Shader Language) shader?

Buffers can be presented as texture.
I have 1 source texture (buffer) and 1 destination texture (buffer).

void stretch_memory_R8G8B8A8(int source_height,int source_width,void *source_memory,int destination_height,int destination_width,void *destination_memory)
{
    BYTE *destination_memory_BYTE = (BYTE *)destination_memory;
    BYTE *source_memory_BYTE = (BYTE *)source_memory;

    const double local_initial_value_width_0 = double(destination_width)/double(source_width);

    for(int local_height_counter_source=0;local_height_counter_source<source_height;local_height_counter_source++)
    {
        int local_check_value_height = local_height_counter_source*destination_height/source_height+1+destination_height/source_height;
        if(local_check_value_height>destination_height)
        {
            local_check_value_height = destination_height;
        }
        for(int local_height_counter_destination=local_height_counter_source*destination_height/source_height;
            local_height_counter_destination<local_check_value_height;
            local_height_counter_destination++)
        {
            for(int local_width_counter_source=0;local_width_counter_source<source_width;local_width_counter_source++)
            {
                int local_initial_value_width = local_width_counter_source*local_initial_value_width_0;
                int local_check_value_width = local_initial_value_width+1+local_initial_value_width_0;
                if(local_check_value_width>destination_width)
                {
                    local_check_value_width = destination_width;
                }
                for(int local_width_counter_destination=local_initial_value_width;
                    local_width_counter_destination<local_check_value_width;
                    local_width_counter_destination++)
                {
                    *(DWORD*)(&destination_memory_BYTE[(local_width_counter_destination+local_height_counter_destination*destination_width)<<2]) =
                        *(DWORD*)(&source_memory_BYTE[(local_width_counter_source+local_height_counter_source*source_width)<<2]);
                }
            }
        }
    }
}
Posted
Updated 27-Apr-11 23:56pm
v2

1 solution

yes, but with a different approach. A pixel shader from what I have read takes 1 pixel in and provides either none or some pixels out, whereas your function modifies a whole surface at once. The actual pixel shader function would effectively do one iteration of the outer loop; and global variables ( HLSL globals ) would maintain the state of the loop, next draw position and so-forth.
 
Share this answer
 
Comments
[no name] 28-Apr-11 9:29am    
Could you write shader code here?
[no name] 28-Apr-11 9:34am    
Here are 4 loops.
First - source height.
Second - destination height.
Third - source width.
Fourth - destination width.
chris4562 28-Apr-11 9:45am    
ahhh, now I understand. what the hoo I'll give it a crack, I'm about to transpose my app from DX9 to DX11 now that I have windows 7, so I need the practice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900